Thomas Gleixner | 1802d0b | 2019-05-27 08:55:21 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
Jyri Sarha | 0918411 | 2016-03-31 16:36:00 +0300 | [diff] [blame] | 2 | /* |
| 3 | * ALSA SoC codec for HDMI encoder drivers |
Alexander A. Klimov | 5856d8b | 2020-07-19 17:38:22 +0200 | [diff] [blame] | 4 | * Copyright (C) 2015 Texas Instruments Incorporated - https://www.ti.com/ |
Jyri Sarha | 0918411 | 2016-03-31 16:36:00 +0300 | [diff] [blame] | 5 | * Author: Jyri Sarha <jsarha@ti.com> |
Jyri Sarha | 0918411 | 2016-03-31 16:36:00 +0300 | [diff] [blame] | 6 | */ |
| 7 | #include <linux/module.h> |
| 8 | #include <linux/string.h> |
| 9 | #include <sound/core.h> |
Cheng-Yi Chiang | 6fa5963 | 2019-07-17 16:33:23 +0800 | [diff] [blame] | 10 | #include <sound/jack.h> |
Jyri Sarha | 0918411 | 2016-03-31 16:36:00 +0300 | [diff] [blame] | 11 | #include <sound/pcm.h> |
| 12 | #include <sound/pcm_params.h> |
| 13 | #include <sound/soc.h> |
Arnaud Pouliquen | cd6111b | 2017-01-03 16:52:52 +0100 | [diff] [blame] | 14 | #include <sound/tlv.h> |
Jyri Sarha | 0918411 | 2016-03-31 16:36:00 +0300 | [diff] [blame] | 15 | #include <sound/pcm_drm_eld.h> |
| 16 | #include <sound/hdmi-codec.h> |
| 17 | #include <sound/pcm_iec958.h> |
| 18 | |
| 19 | #include <drm/drm_crtc.h> /* This is only to get MAX_ELD_BYTES */ |
| 20 | |
Arnaud Pouliquen | cd6111b | 2017-01-03 16:52:52 +0100 | [diff] [blame] | 21 | #define HDMI_CODEC_CHMAP_IDX_UNKNOWN -1 |
| 22 | |
| 23 | struct hdmi_codec_channel_map_table { |
| 24 | unsigned char map; /* ALSA API channel map position */ |
Arnaud Pouliquen | cd6111b | 2017-01-03 16:52:52 +0100 | [diff] [blame] | 25 | }; |
| 26 | |
| 27 | /* |
| 28 | * CEA speaker placement for HDMI 1.4: |
| 29 | * |
| 30 | * FL FLC FC FRC FR FRW |
| 31 | * |
| 32 | * LFE |
| 33 | * |
| 34 | * RL RLC RC RRC RR |
| 35 | * |
| 36 | * Speaker placement has to be extended to support HDMI 2.0 |
| 37 | */ |
| 38 | enum hdmi_codec_cea_spk_placement { |
| 39 | FL = BIT(0), /* Front Left */ |
| 40 | FC = BIT(1), /* Front Center */ |
| 41 | FR = BIT(2), /* Front Right */ |
| 42 | FLC = BIT(3), /* Front Left Center */ |
| 43 | FRC = BIT(4), /* Front Right Center */ |
| 44 | RL = BIT(5), /* Rear Left */ |
| 45 | RC = BIT(6), /* Rear Center */ |
| 46 | RR = BIT(7), /* Rear Right */ |
| 47 | RLC = BIT(8), /* Rear Left Center */ |
| 48 | RRC = BIT(9), /* Rear Right Center */ |
| 49 | LFE = BIT(10), /* Low Frequency Effect */ |
| 50 | }; |
| 51 | |
| 52 | /* |
| 53 | * cea Speaker allocation structure |
| 54 | */ |
| 55 | struct hdmi_codec_cea_spk_alloc { |
| 56 | const int ca_id; |
| 57 | unsigned int n_ch; |
| 58 | unsigned long mask; |
| 59 | }; |
| 60 | |
| 61 | /* Channel maps stereo HDMI */ |
Colin Ian King | 3013c75 | 2017-08-12 23:50:28 +0100 | [diff] [blame] | 62 | static const struct snd_pcm_chmap_elem hdmi_codec_stereo_chmaps[] = { |
Arnaud Pouliquen | cd6111b | 2017-01-03 16:52:52 +0100 | [diff] [blame] | 63 | { .channels = 2, |
| 64 | .map = { SNDRV_CHMAP_FL, SNDRV_CHMAP_FR } }, |
| 65 | { } |
| 66 | }; |
| 67 | |
| 68 | /* Channel maps for multi-channel playbacks, up to 8 n_ch */ |
Colin Ian King | 3013c75 | 2017-08-12 23:50:28 +0100 | [diff] [blame] | 69 | static const struct snd_pcm_chmap_elem hdmi_codec_8ch_chmaps[] = { |
Arnaud Pouliquen | cd6111b | 2017-01-03 16:52:52 +0100 | [diff] [blame] | 70 | { .channels = 2, /* CA_ID 0x00 */ |
| 71 | .map = { SNDRV_CHMAP_FL, SNDRV_CHMAP_FR } }, |
| 72 | { .channels = 4, /* CA_ID 0x01 */ |
| 73 | .map = { SNDRV_CHMAP_FL, SNDRV_CHMAP_FR, SNDRV_CHMAP_LFE, |
| 74 | SNDRV_CHMAP_NA } }, |
| 75 | { .channels = 4, /* CA_ID 0x02 */ |
| 76 | .map = { SNDRV_CHMAP_FL, SNDRV_CHMAP_FR, SNDRV_CHMAP_NA, |
| 77 | SNDRV_CHMAP_FC } }, |
| 78 | { .channels = 4, /* CA_ID 0x03 */ |
| 79 | .map = { SNDRV_CHMAP_FL, SNDRV_CHMAP_FR, SNDRV_CHMAP_LFE, |
| 80 | SNDRV_CHMAP_FC } }, |
| 81 | { .channels = 6, /* CA_ID 0x04 */ |
| 82 | .map = { SNDRV_CHMAP_FL, SNDRV_CHMAP_FR, SNDRV_CHMAP_NA, |
| 83 | SNDRV_CHMAP_NA, SNDRV_CHMAP_RC, SNDRV_CHMAP_NA } }, |
| 84 | { .channels = 6, /* CA_ID 0x05 */ |
| 85 | .map = { SNDRV_CHMAP_FL, SNDRV_CHMAP_FR, SNDRV_CHMAP_LFE, |
| 86 | SNDRV_CHMAP_NA, SNDRV_CHMAP_RC, SNDRV_CHMAP_NA } }, |
| 87 | { .channels = 6, /* CA_ID 0x06 */ |
| 88 | .map = { SNDRV_CHMAP_FL, SNDRV_CHMAP_FR, SNDRV_CHMAP_NA, |
| 89 | SNDRV_CHMAP_FC, SNDRV_CHMAP_RC, SNDRV_CHMAP_NA } }, |
| 90 | { .channels = 6, /* CA_ID 0x07 */ |
| 91 | .map = { SNDRV_CHMAP_FL, SNDRV_CHMAP_FR, SNDRV_CHMAP_LFE, |
| 92 | SNDRV_CHMAP_FC, SNDRV_CHMAP_RC, SNDRV_CHMAP_NA } }, |
| 93 | { .channels = 6, /* CA_ID 0x08 */ |
| 94 | .map = { SNDRV_CHMAP_FL, SNDRV_CHMAP_FR, SNDRV_CHMAP_NA, |
| 95 | SNDRV_CHMAP_NA, SNDRV_CHMAP_RL, SNDRV_CHMAP_RR } }, |
| 96 | { .channels = 6, /* CA_ID 0x09 */ |
| 97 | .map = { SNDRV_CHMAP_FL, SNDRV_CHMAP_FR, SNDRV_CHMAP_LFE, |
| 98 | SNDRV_CHMAP_NA, SNDRV_CHMAP_RL, SNDRV_CHMAP_RR } }, |
| 99 | { .channels = 6, /* CA_ID 0x0A */ |
| 100 | .map = { SNDRV_CHMAP_FL, SNDRV_CHMAP_FR, SNDRV_CHMAP_NA, |
| 101 | SNDRV_CHMAP_FC, SNDRV_CHMAP_RL, SNDRV_CHMAP_RR } }, |
| 102 | { .channels = 6, /* CA_ID 0x0B */ |
| 103 | .map = { SNDRV_CHMAP_FL, SNDRV_CHMAP_FR, SNDRV_CHMAP_LFE, |
| 104 | SNDRV_CHMAP_FC, SNDRV_CHMAP_RL, SNDRV_CHMAP_RR } }, |
| 105 | { .channels = 8, /* CA_ID 0x0C */ |
| 106 | .map = { SNDRV_CHMAP_FL, SNDRV_CHMAP_FR, SNDRV_CHMAP_NA, |
| 107 | SNDRV_CHMAP_NA, SNDRV_CHMAP_RL, SNDRV_CHMAP_RR, |
| 108 | SNDRV_CHMAP_RC, SNDRV_CHMAP_NA } }, |
| 109 | { .channels = 8, /* CA_ID 0x0D */ |
| 110 | .map = { SNDRV_CHMAP_FL, SNDRV_CHMAP_FR, SNDRV_CHMAP_LFE, |
| 111 | SNDRV_CHMAP_NA, SNDRV_CHMAP_RL, SNDRV_CHMAP_RR, |
| 112 | SNDRV_CHMAP_RC, SNDRV_CHMAP_NA } }, |
| 113 | { .channels = 8, /* CA_ID 0x0E */ |
| 114 | .map = { SNDRV_CHMAP_FL, SNDRV_CHMAP_FR, SNDRV_CHMAP_NA, |
| 115 | SNDRV_CHMAP_FC, SNDRV_CHMAP_RL, SNDRV_CHMAP_RR, |
| 116 | SNDRV_CHMAP_RC, SNDRV_CHMAP_NA } }, |
| 117 | { .channels = 8, /* CA_ID 0x0F */ |
| 118 | .map = { SNDRV_CHMAP_FL, SNDRV_CHMAP_FR, SNDRV_CHMAP_LFE, |
| 119 | SNDRV_CHMAP_FC, SNDRV_CHMAP_RL, SNDRV_CHMAP_RR, |
| 120 | SNDRV_CHMAP_RC, SNDRV_CHMAP_NA } }, |
| 121 | { .channels = 8, /* CA_ID 0x10 */ |
| 122 | .map = { SNDRV_CHMAP_FL, SNDRV_CHMAP_FR, SNDRV_CHMAP_NA, |
| 123 | SNDRV_CHMAP_NA, SNDRV_CHMAP_RL, SNDRV_CHMAP_RR, |
| 124 | SNDRV_CHMAP_RLC, SNDRV_CHMAP_RRC } }, |
| 125 | { .channels = 8, /* CA_ID 0x11 */ |
| 126 | .map = { SNDRV_CHMAP_FL, SNDRV_CHMAP_FR, SNDRV_CHMAP_LFE, |
| 127 | SNDRV_CHMAP_NA, SNDRV_CHMAP_RL, SNDRV_CHMAP_RR, |
| 128 | SNDRV_CHMAP_RLC, SNDRV_CHMAP_RRC } }, |
| 129 | { .channels = 8, /* CA_ID 0x12 */ |
| 130 | .map = { SNDRV_CHMAP_FL, SNDRV_CHMAP_FR, SNDRV_CHMAP_NA, |
| 131 | SNDRV_CHMAP_FC, SNDRV_CHMAP_RL, SNDRV_CHMAP_RR, |
| 132 | SNDRV_CHMAP_RLC, SNDRV_CHMAP_RRC } }, |
| 133 | { .channels = 8, /* CA_ID 0x13 */ |
| 134 | .map = { SNDRV_CHMAP_FL, SNDRV_CHMAP_FR, SNDRV_CHMAP_LFE, |
| 135 | SNDRV_CHMAP_FC, SNDRV_CHMAP_RL, SNDRV_CHMAP_RR, |
| 136 | SNDRV_CHMAP_RLC, SNDRV_CHMAP_RRC } }, |
| 137 | { .channels = 8, /* CA_ID 0x14 */ |
| 138 | .map = { SNDRV_CHMAP_FL, SNDRV_CHMAP_FR, SNDRV_CHMAP_NA, |
| 139 | SNDRV_CHMAP_NA, SNDRV_CHMAP_NA, SNDRV_CHMAP_NA, |
| 140 | SNDRV_CHMAP_FLC, SNDRV_CHMAP_FRC } }, |
| 141 | { .channels = 8, /* CA_ID 0x15 */ |
| 142 | .map = { SNDRV_CHMAP_FL, SNDRV_CHMAP_FR, SNDRV_CHMAP_LFE, |
| 143 | SNDRV_CHMAP_NA, SNDRV_CHMAP_NA, SNDRV_CHMAP_NA, |
| 144 | SNDRV_CHMAP_FLC, SNDRV_CHMAP_FRC } }, |
| 145 | { .channels = 8, /* CA_ID 0x16 */ |
| 146 | .map = { SNDRV_CHMAP_FL, SNDRV_CHMAP_FR, SNDRV_CHMAP_NA, |
| 147 | SNDRV_CHMAP_FC, SNDRV_CHMAP_NA, SNDRV_CHMAP_NA, |
| 148 | SNDRV_CHMAP_FLC, SNDRV_CHMAP_FRC } }, |
| 149 | { .channels = 8, /* CA_ID 0x17 */ |
| 150 | .map = { SNDRV_CHMAP_FL, SNDRV_CHMAP_FR, SNDRV_CHMAP_LFE, |
| 151 | SNDRV_CHMAP_FC, SNDRV_CHMAP_NA, SNDRV_CHMAP_NA, |
| 152 | SNDRV_CHMAP_FLC, SNDRV_CHMAP_FRC } }, |
| 153 | { .channels = 8, /* CA_ID 0x18 */ |
| 154 | .map = { SNDRV_CHMAP_FL, SNDRV_CHMAP_FR, SNDRV_CHMAP_NA, |
| 155 | SNDRV_CHMAP_NA, SNDRV_CHMAP_NA, SNDRV_CHMAP_NA, |
| 156 | SNDRV_CHMAP_FLC, SNDRV_CHMAP_FRC } }, |
| 157 | { .channels = 8, /* CA_ID 0x19 */ |
| 158 | .map = { SNDRV_CHMAP_FL, SNDRV_CHMAP_FR, SNDRV_CHMAP_LFE, |
| 159 | SNDRV_CHMAP_NA, SNDRV_CHMAP_NA, SNDRV_CHMAP_NA, |
| 160 | SNDRV_CHMAP_FLC, SNDRV_CHMAP_FRC } }, |
| 161 | { .channels = 8, /* CA_ID 0x1A */ |
| 162 | .map = { SNDRV_CHMAP_FL, SNDRV_CHMAP_FR, SNDRV_CHMAP_NA, |
| 163 | SNDRV_CHMAP_FC, SNDRV_CHMAP_NA, SNDRV_CHMAP_NA, |
| 164 | SNDRV_CHMAP_FLC, SNDRV_CHMAP_FRC } }, |
| 165 | { .channels = 8, /* CA_ID 0x1B */ |
| 166 | .map = { SNDRV_CHMAP_FL, SNDRV_CHMAP_FR, SNDRV_CHMAP_LFE, |
| 167 | SNDRV_CHMAP_FC, SNDRV_CHMAP_NA, SNDRV_CHMAP_NA, |
| 168 | SNDRV_CHMAP_FLC, SNDRV_CHMAP_FRC } }, |
| 169 | { .channels = 8, /* CA_ID 0x1C */ |
| 170 | .map = { SNDRV_CHMAP_FL, SNDRV_CHMAP_FR, SNDRV_CHMAP_NA, |
| 171 | SNDRV_CHMAP_NA, SNDRV_CHMAP_NA, SNDRV_CHMAP_NA, |
| 172 | SNDRV_CHMAP_FLC, SNDRV_CHMAP_FRC } }, |
| 173 | { .channels = 8, /* CA_ID 0x1D */ |
| 174 | .map = { SNDRV_CHMAP_FL, SNDRV_CHMAP_FR, SNDRV_CHMAP_LFE, |
| 175 | SNDRV_CHMAP_NA, SNDRV_CHMAP_NA, SNDRV_CHMAP_NA, |
| 176 | SNDRV_CHMAP_FLC, SNDRV_CHMAP_FRC } }, |
| 177 | { .channels = 8, /* CA_ID 0x1E */ |
| 178 | .map = { SNDRV_CHMAP_FL, SNDRV_CHMAP_FR, SNDRV_CHMAP_NA, |
| 179 | SNDRV_CHMAP_FC, SNDRV_CHMAP_NA, SNDRV_CHMAP_NA, |
| 180 | SNDRV_CHMAP_FLC, SNDRV_CHMAP_FRC } }, |
| 181 | { .channels = 8, /* CA_ID 0x1F */ |
| 182 | .map = { SNDRV_CHMAP_FL, SNDRV_CHMAP_FR, SNDRV_CHMAP_LFE, |
| 183 | SNDRV_CHMAP_FC, SNDRV_CHMAP_NA, SNDRV_CHMAP_NA, |
| 184 | SNDRV_CHMAP_FLC, SNDRV_CHMAP_FRC } }, |
| 185 | { } |
| 186 | }; |
| 187 | |
| 188 | /* |
| 189 | * hdmi_codec_channel_alloc: speaker configuration available for CEA |
| 190 | * |
| 191 | * This is an ordered list that must match with hdmi_codec_8ch_chmaps struct |
| 192 | * The preceding ones have better chances to be selected by |
| 193 | * hdmi_codec_get_ch_alloc_table_idx(). |
| 194 | */ |
| 195 | static const struct hdmi_codec_cea_spk_alloc hdmi_codec_channel_alloc[] = { |
| 196 | { .ca_id = 0x00, .n_ch = 2, |
| 197 | .mask = FL | FR}, |
| 198 | /* 2.1 */ |
| 199 | { .ca_id = 0x01, .n_ch = 4, |
| 200 | .mask = FL | FR | LFE}, |
| 201 | /* Dolby Surround */ |
| 202 | { .ca_id = 0x02, .n_ch = 4, |
| 203 | .mask = FL | FR | FC }, |
| 204 | /* surround51 */ |
| 205 | { .ca_id = 0x0b, .n_ch = 6, |
| 206 | .mask = FL | FR | LFE | FC | RL | RR}, |
| 207 | /* surround40 */ |
| 208 | { .ca_id = 0x08, .n_ch = 6, |
| 209 | .mask = FL | FR | RL | RR }, |
| 210 | /* surround41 */ |
| 211 | { .ca_id = 0x09, .n_ch = 6, |
| 212 | .mask = FL | FR | LFE | RL | RR }, |
| 213 | /* surround50 */ |
| 214 | { .ca_id = 0x0a, .n_ch = 6, |
| 215 | .mask = FL | FR | FC | RL | RR }, |
| 216 | /* 6.1 */ |
| 217 | { .ca_id = 0x0f, .n_ch = 8, |
| 218 | .mask = FL | FR | LFE | FC | RL | RR | RC }, |
| 219 | /* surround71 */ |
| 220 | { .ca_id = 0x13, .n_ch = 8, |
| 221 | .mask = FL | FR | LFE | FC | RL | RR | RLC | RRC }, |
| 222 | /* others */ |
| 223 | { .ca_id = 0x03, .n_ch = 8, |
| 224 | .mask = FL | FR | LFE | FC }, |
| 225 | { .ca_id = 0x04, .n_ch = 8, |
| 226 | .mask = FL | FR | RC}, |
| 227 | { .ca_id = 0x05, .n_ch = 8, |
| 228 | .mask = FL | FR | LFE | RC }, |
| 229 | { .ca_id = 0x06, .n_ch = 8, |
| 230 | .mask = FL | FR | FC | RC }, |
| 231 | { .ca_id = 0x07, .n_ch = 8, |
| 232 | .mask = FL | FR | LFE | FC | RC }, |
| 233 | { .ca_id = 0x0c, .n_ch = 8, |
| 234 | .mask = FL | FR | RC | RL | RR }, |
| 235 | { .ca_id = 0x0d, .n_ch = 8, |
| 236 | .mask = FL | FR | LFE | RL | RR | RC }, |
| 237 | { .ca_id = 0x0e, .n_ch = 8, |
| 238 | .mask = FL | FR | FC | RL | RR | RC }, |
| 239 | { .ca_id = 0x10, .n_ch = 8, |
| 240 | .mask = FL | FR | RL | RR | RLC | RRC }, |
| 241 | { .ca_id = 0x11, .n_ch = 8, |
| 242 | .mask = FL | FR | LFE | RL | RR | RLC | RRC }, |
| 243 | { .ca_id = 0x12, .n_ch = 8, |
| 244 | .mask = FL | FR | FC | RL | RR | RLC | RRC }, |
| 245 | { .ca_id = 0x14, .n_ch = 8, |
| 246 | .mask = FL | FR | FLC | FRC }, |
| 247 | { .ca_id = 0x15, .n_ch = 8, |
| 248 | .mask = FL | FR | LFE | FLC | FRC }, |
| 249 | { .ca_id = 0x16, .n_ch = 8, |
| 250 | .mask = FL | FR | FC | FLC | FRC }, |
| 251 | { .ca_id = 0x17, .n_ch = 8, |
| 252 | .mask = FL | FR | LFE | FC | FLC | FRC }, |
| 253 | { .ca_id = 0x18, .n_ch = 8, |
| 254 | .mask = FL | FR | RC | FLC | FRC }, |
| 255 | { .ca_id = 0x19, .n_ch = 8, |
| 256 | .mask = FL | FR | LFE | RC | FLC | FRC }, |
| 257 | { .ca_id = 0x1a, .n_ch = 8, |
| 258 | .mask = FL | FR | RC | FC | FLC | FRC }, |
| 259 | { .ca_id = 0x1b, .n_ch = 8, |
| 260 | .mask = FL | FR | LFE | RC | FC | FLC | FRC }, |
| 261 | { .ca_id = 0x1c, .n_ch = 8, |
| 262 | .mask = FL | FR | RL | RR | FLC | FRC }, |
| 263 | { .ca_id = 0x1d, .n_ch = 8, |
| 264 | .mask = FL | FR | LFE | RL | RR | FLC | FRC }, |
| 265 | { .ca_id = 0x1e, .n_ch = 8, |
| 266 | .mask = FL | FR | FC | RL | RR | FLC | FRC }, |
| 267 | { .ca_id = 0x1f, .n_ch = 8, |
| 268 | .mask = FL | FR | LFE | FC | RL | RR | FLC | FRC }, |
| 269 | }; |
| 270 | |
Jyri Sarha | 0918411 | 2016-03-31 16:36:00 +0300 | [diff] [blame] | 271 | struct hdmi_codec_priv { |
| 272 | struct hdmi_codec_pdata hcd; |
Jyri Sarha | 0918411 | 2016-03-31 16:36:00 +0300 | [diff] [blame] | 273 | uint8_t eld[MAX_ELD_BYTES]; |
Arnaud Pouliquen | cd6111b | 2017-01-03 16:52:52 +0100 | [diff] [blame] | 274 | struct snd_pcm_chmap *chmap_info; |
| 275 | unsigned int chmap_idx; |
Jerome Brunet | 1442842 | 2019-12-06 11:35:42 +0100 | [diff] [blame] | 276 | struct mutex lock; |
| 277 | bool busy; |
Cheng-Yi Chiang | 6fa5963 | 2019-07-17 16:33:23 +0800 | [diff] [blame] | 278 | struct snd_soc_jack *jack; |
| 279 | unsigned int jack_status; |
Maxime Ripard | 7a8e1d4 | 2021-05-25 15:23:46 +0200 | [diff] [blame^] | 280 | u8 iec_status[5]; |
Jyri Sarha | 0918411 | 2016-03-31 16:36:00 +0300 | [diff] [blame] | 281 | }; |
| 282 | |
| 283 | static const struct snd_soc_dapm_widget hdmi_widgets[] = { |
| 284 | SND_SOC_DAPM_OUTPUT("TX"), |
Shengjiu Wang | 144f836 | 2020-11-26 14:36:48 +0800 | [diff] [blame] | 285 | SND_SOC_DAPM_OUTPUT("RX"), |
Jyri Sarha | 0918411 | 2016-03-31 16:36:00 +0300 | [diff] [blame] | 286 | }; |
| 287 | |
Jyri Sarha | 0918411 | 2016-03-31 16:36:00 +0300 | [diff] [blame] | 288 | enum { |
| 289 | DAI_ID_I2S = 0, |
| 290 | DAI_ID_SPDIF, |
| 291 | }; |
| 292 | |
Philipp Zabel | 81151cf | 2016-04-20 10:59:58 +0200 | [diff] [blame] | 293 | static int hdmi_eld_ctl_info(struct snd_kcontrol *kcontrol, |
| 294 | struct snd_ctl_elem_info *uinfo) |
| 295 | { |
Philipp Zabel | 81151cf | 2016-04-20 10:59:58 +0200 | [diff] [blame] | 296 | uinfo->type = SNDRV_CTL_ELEM_TYPE_BYTES; |
Pankaj Bharadiya | c593642 | 2019-12-09 10:31:43 -0800 | [diff] [blame] | 297 | uinfo->count = sizeof_field(struct hdmi_codec_priv, eld); |
Philipp Zabel | 81151cf | 2016-04-20 10:59:58 +0200 | [diff] [blame] | 298 | |
| 299 | return 0; |
| 300 | } |
| 301 | |
| 302 | static int hdmi_eld_ctl_get(struct snd_kcontrol *kcontrol, |
| 303 | struct snd_ctl_elem_value *ucontrol) |
| 304 | { |
| 305 | struct snd_soc_component *component = snd_kcontrol_chip(kcontrol); |
| 306 | struct hdmi_codec_priv *hcp = snd_soc_component_get_drvdata(component); |
| 307 | |
Philipp Zabel | 81151cf | 2016-04-20 10:59:58 +0200 | [diff] [blame] | 308 | memcpy(ucontrol->value.bytes.data, hcp->eld, sizeof(hcp->eld)); |
Philipp Zabel | 81151cf | 2016-04-20 10:59:58 +0200 | [diff] [blame] | 309 | |
| 310 | return 0; |
| 311 | } |
| 312 | |
Arnaud Pouliquen | cd6111b | 2017-01-03 16:52:52 +0100 | [diff] [blame] | 313 | static unsigned long hdmi_codec_spk_mask_from_alloc(int spk_alloc) |
| 314 | { |
| 315 | int i; |
Colin Ian King | 1d6463a | 2017-07-11 15:08:55 +0100 | [diff] [blame] | 316 | static const unsigned long hdmi_codec_eld_spk_alloc_bits[] = { |
Arnaud Pouliquen | cd6111b | 2017-01-03 16:52:52 +0100 | [diff] [blame] | 317 | [0] = FL | FR, [1] = LFE, [2] = FC, [3] = RL | RR, |
| 318 | [4] = RC, [5] = FLC | FRC, [6] = RLC | RRC, |
| 319 | }; |
| 320 | unsigned long spk_mask = 0; |
| 321 | |
| 322 | for (i = 0; i < ARRAY_SIZE(hdmi_codec_eld_spk_alloc_bits); i++) { |
| 323 | if (spk_alloc & (1 << i)) |
| 324 | spk_mask |= hdmi_codec_eld_spk_alloc_bits[i]; |
| 325 | } |
| 326 | |
| 327 | return spk_mask; |
| 328 | } |
| 329 | |
Colin Ian King | 3013c75 | 2017-08-12 23:50:28 +0100 | [diff] [blame] | 330 | static void hdmi_codec_eld_chmap(struct hdmi_codec_priv *hcp) |
Arnaud Pouliquen | cd6111b | 2017-01-03 16:52:52 +0100 | [diff] [blame] | 331 | { |
| 332 | u8 spk_alloc; |
| 333 | unsigned long spk_mask; |
| 334 | |
| 335 | spk_alloc = drm_eld_get_spk_alloc(hcp->eld); |
| 336 | spk_mask = hdmi_codec_spk_mask_from_alloc(spk_alloc); |
| 337 | |
| 338 | /* Detect if only stereo supported, else return 8 channels mappings */ |
| 339 | if ((spk_mask & ~(FL | FR)) && hcp->chmap_info->max_channels > 2) |
| 340 | hcp->chmap_info->chmap = hdmi_codec_8ch_chmaps; |
| 341 | else |
| 342 | hcp->chmap_info->chmap = hdmi_codec_stereo_chmaps; |
| 343 | } |
| 344 | |
| 345 | static int hdmi_codec_get_ch_alloc_table_idx(struct hdmi_codec_priv *hcp, |
| 346 | unsigned char channels) |
| 347 | { |
| 348 | int i; |
| 349 | u8 spk_alloc; |
| 350 | unsigned long spk_mask; |
| 351 | const struct hdmi_codec_cea_spk_alloc *cap = hdmi_codec_channel_alloc; |
| 352 | |
| 353 | spk_alloc = drm_eld_get_spk_alloc(hcp->eld); |
| 354 | spk_mask = hdmi_codec_spk_mask_from_alloc(spk_alloc); |
| 355 | |
| 356 | for (i = 0; i < ARRAY_SIZE(hdmi_codec_channel_alloc); i++, cap++) { |
| 357 | /* If spk_alloc == 0, HDMI is unplugged return stereo config*/ |
| 358 | if (!spk_alloc && cap->ca_id == 0) |
| 359 | return i; |
| 360 | if (cap->n_ch != channels) |
| 361 | continue; |
| 362 | if (!(cap->mask == (spk_mask & cap->mask))) |
| 363 | continue; |
| 364 | return i; |
| 365 | } |
| 366 | |
| 367 | return -EINVAL; |
| 368 | } |
| 369 | static int hdmi_codec_chmap_ctl_get(struct snd_kcontrol *kcontrol, |
| 370 | struct snd_ctl_elem_value *ucontrol) |
| 371 | { |
| 372 | unsigned const char *map; |
| 373 | unsigned int i; |
| 374 | struct snd_pcm_chmap *info = snd_kcontrol_chip(kcontrol); |
| 375 | struct hdmi_codec_priv *hcp = info->private_data; |
| 376 | |
| 377 | map = info->chmap[hcp->chmap_idx].map; |
| 378 | |
| 379 | for (i = 0; i < info->max_channels; i++) { |
| 380 | if (hcp->chmap_idx == HDMI_CODEC_CHMAP_IDX_UNKNOWN) |
| 381 | ucontrol->value.integer.value[i] = 0; |
| 382 | else |
| 383 | ucontrol->value.integer.value[i] = map[i]; |
| 384 | } |
| 385 | |
| 386 | return 0; |
| 387 | } |
| 388 | |
Maxime Ripard | 7a8e1d4 | 2021-05-25 15:23:46 +0200 | [diff] [blame^] | 389 | static int hdmi_codec_iec958_info(struct snd_kcontrol *kcontrol, |
| 390 | struct snd_ctl_elem_info *uinfo) |
| 391 | { |
| 392 | uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958; |
| 393 | uinfo->count = 1; |
| 394 | return 0; |
| 395 | } |
| 396 | |
| 397 | static int hdmi_codec_iec958_default_get(struct snd_kcontrol *kcontrol, |
| 398 | struct snd_ctl_elem_value *ucontrol) |
| 399 | { |
| 400 | struct snd_soc_component *component = snd_kcontrol_chip(kcontrol); |
| 401 | struct hdmi_codec_priv *hcp = snd_soc_component_get_drvdata(component); |
| 402 | |
| 403 | memcpy(ucontrol->value.iec958.status, hcp->iec_status, |
| 404 | sizeof(hcp->iec_status)); |
| 405 | |
| 406 | return 0; |
| 407 | } |
| 408 | |
| 409 | static int hdmi_codec_iec958_default_put(struct snd_kcontrol *kcontrol, |
| 410 | struct snd_ctl_elem_value *ucontrol) |
| 411 | { |
| 412 | struct snd_soc_component *component = snd_kcontrol_chip(kcontrol); |
| 413 | struct hdmi_codec_priv *hcp = snd_soc_component_get_drvdata(component); |
| 414 | |
| 415 | memcpy(hcp->iec_status, ucontrol->value.iec958.status, |
| 416 | sizeof(hcp->iec_status)); |
| 417 | |
| 418 | return 0; |
| 419 | } |
| 420 | |
| 421 | static int hdmi_codec_iec958_mask_get(struct snd_kcontrol *kcontrol, |
| 422 | struct snd_ctl_elem_value *ucontrol) |
| 423 | { |
| 424 | memset(ucontrol->value.iec958.status, 0xff, |
| 425 | sizeof_field(struct hdmi_codec_priv, iec_status)); |
| 426 | |
| 427 | return 0; |
| 428 | } |
| 429 | |
Jyri Sarha | 0918411 | 2016-03-31 16:36:00 +0300 | [diff] [blame] | 430 | static int hdmi_codec_startup(struct snd_pcm_substream *substream, |
| 431 | struct snd_soc_dai *dai) |
| 432 | { |
| 433 | struct hdmi_codec_priv *hcp = snd_soc_dai_get_drvdata(dai); |
Shengjiu Wang | 144f836 | 2020-11-26 14:36:48 +0800 | [diff] [blame] | 434 | bool tx = substream->stream == SNDRV_PCM_STREAM_PLAYBACK; |
Jyri Sarha | 0918411 | 2016-03-31 16:36:00 +0300 | [diff] [blame] | 435 | int ret = 0; |
| 436 | |
Jerome Brunet | 1442842 | 2019-12-06 11:35:42 +0100 | [diff] [blame] | 437 | mutex_lock(&hcp->lock); |
| 438 | if (hcp->busy) { |
Jerome Brunet | 3fcf94e | 2019-05-06 11:58:13 +0200 | [diff] [blame] | 439 | dev_err(dai->dev, "Only one simultaneous stream supported!\n"); |
Jerome Brunet | 1442842 | 2019-12-06 11:35:42 +0100 | [diff] [blame] | 440 | mutex_unlock(&hcp->lock); |
Jerome Brunet | 3fcf94e | 2019-05-06 11:58:13 +0200 | [diff] [blame] | 441 | return -EINVAL; |
| 442 | } |
Jyri Sarha | 0918411 | 2016-03-31 16:36:00 +0300 | [diff] [blame] | 443 | |
| 444 | if (hcp->hcd.ops->audio_startup) { |
Kuninori Morimoto | efc9194 | 2016-06-24 02:47:55 +0000 | [diff] [blame] | 445 | ret = hcp->hcd.ops->audio_startup(dai->dev->parent, hcp->hcd.data); |
Jerome Brunet | 3fcf94e | 2019-05-06 11:58:13 +0200 | [diff] [blame] | 446 | if (ret) |
| 447 | goto err; |
Jyri Sarha | 0918411 | 2016-03-31 16:36:00 +0300 | [diff] [blame] | 448 | } |
| 449 | |
Shengjiu Wang | 144f836 | 2020-11-26 14:36:48 +0800 | [diff] [blame] | 450 | if (tx && hcp->hcd.ops->get_eld) { |
Kuninori Morimoto | efc9194 | 2016-06-24 02:47:55 +0000 | [diff] [blame] | 451 | ret = hcp->hcd.ops->get_eld(dai->dev->parent, hcp->hcd.data, |
| 452 | hcp->eld, sizeof(hcp->eld)); |
Jerome Brunet | 1442842 | 2019-12-06 11:35:42 +0100 | [diff] [blame] | 453 | if (ret) |
| 454 | goto err; |
Jyri Sarha | 0918411 | 2016-03-31 16:36:00 +0300 | [diff] [blame] | 455 | |
Jerome Brunet | 1442842 | 2019-12-06 11:35:42 +0100 | [diff] [blame] | 456 | ret = snd_pcm_hw_constraint_eld(substream->runtime, hcp->eld); |
| 457 | if (ret) |
| 458 | goto err; |
| 459 | |
Arnaud Pouliquen | cd6111b | 2017-01-03 16:52:52 +0100 | [diff] [blame] | 460 | /* Select chmap supported */ |
| 461 | hdmi_codec_eld_chmap(hcp); |
Jyri Sarha | 0918411 | 2016-03-31 16:36:00 +0300 | [diff] [blame] | 462 | } |
Jerome Brunet | 1442842 | 2019-12-06 11:35:42 +0100 | [diff] [blame] | 463 | |
| 464 | hcp->busy = true; |
Jerome Brunet | 3fcf94e | 2019-05-06 11:58:13 +0200 | [diff] [blame] | 465 | |
| 466 | err: |
Jerome Brunet | 1442842 | 2019-12-06 11:35:42 +0100 | [diff] [blame] | 467 | mutex_unlock(&hcp->lock); |
Jerome Brunet | 3fcf94e | 2019-05-06 11:58:13 +0200 | [diff] [blame] | 468 | return ret; |
Jyri Sarha | 0918411 | 2016-03-31 16:36:00 +0300 | [diff] [blame] | 469 | } |
| 470 | |
| 471 | static void hdmi_codec_shutdown(struct snd_pcm_substream *substream, |
| 472 | struct snd_soc_dai *dai) |
| 473 | { |
| 474 | struct hdmi_codec_priv *hcp = snd_soc_dai_get_drvdata(dai); |
| 475 | |
Arnaud Pouliquen | cd6111b | 2017-01-03 16:52:52 +0100 | [diff] [blame] | 476 | hcp->chmap_idx = HDMI_CODEC_CHMAP_IDX_UNKNOWN; |
Kuninori Morimoto | efc9194 | 2016-06-24 02:47:55 +0000 | [diff] [blame] | 477 | hcp->hcd.ops->audio_shutdown(dai->dev->parent, hcp->hcd.data); |
Jyri Sarha | 0918411 | 2016-03-31 16:36:00 +0300 | [diff] [blame] | 478 | |
Jerome Brunet | 1442842 | 2019-12-06 11:35:42 +0100 | [diff] [blame] | 479 | mutex_lock(&hcp->lock); |
| 480 | hcp->busy = false; |
| 481 | mutex_unlock(&hcp->lock); |
Jyri Sarha | 0918411 | 2016-03-31 16:36:00 +0300 | [diff] [blame] | 482 | } |
| 483 | |
| 484 | static int hdmi_codec_hw_params(struct snd_pcm_substream *substream, |
| 485 | struct snd_pcm_hw_params *params, |
| 486 | struct snd_soc_dai *dai) |
| 487 | { |
| 488 | struct hdmi_codec_priv *hcp = snd_soc_dai_get_drvdata(dai); |
Jerome Brunet | 0cf4610 | 2019-05-06 11:58:15 +0200 | [diff] [blame] | 489 | struct hdmi_codec_daifmt *cf = dai->playback_dma_data; |
Jyri Sarha | 0918411 | 2016-03-31 16:36:00 +0300 | [diff] [blame] | 490 | struct hdmi_codec_params hp = { |
| 491 | .iec = { |
| 492 | .status = { 0 }, |
| 493 | .subcode = { 0 }, |
| 494 | .pad = 0, |
| 495 | .dig_subframe = { 0 }, |
| 496 | } |
| 497 | }; |
Arnaud Pouliquen | cd6111b | 2017-01-03 16:52:52 +0100 | [diff] [blame] | 498 | int ret, idx; |
Jyri Sarha | 0918411 | 2016-03-31 16:36:00 +0300 | [diff] [blame] | 499 | |
| 500 | dev_dbg(dai->dev, "%s() width %d rate %d channels %d\n", __func__, |
| 501 | params_width(params), params_rate(params), |
| 502 | params_channels(params)); |
| 503 | |
Maxime Ripard | 7a8e1d4 | 2021-05-25 15:23:46 +0200 | [diff] [blame^] | 504 | memcpy(hp.iec.status, hcp->iec_status, sizeof(hp.iec.status)); |
| 505 | ret = snd_pcm_fill_iec958_consumer_hw_params(params, hp.iec.status, |
| 506 | sizeof(hp.iec.status)); |
Jyri Sarha | 0918411 | 2016-03-31 16:36:00 +0300 | [diff] [blame] | 507 | if (ret < 0) { |
| 508 | dev_err(dai->dev, "Creating IEC958 channel status failed %d\n", |
| 509 | ret); |
| 510 | return ret; |
| 511 | } |
| 512 | |
Jyri Sarha | 0918411 | 2016-03-31 16:36:00 +0300 | [diff] [blame] | 513 | hdmi_audio_infoframe_init(&hp.cea); |
| 514 | hp.cea.channels = params_channels(params); |
| 515 | hp.cea.coding_type = HDMI_AUDIO_CODING_TYPE_STREAM; |
| 516 | hp.cea.sample_size = HDMI_AUDIO_SAMPLE_SIZE_STREAM; |
| 517 | hp.cea.sample_frequency = HDMI_AUDIO_SAMPLE_FREQUENCY_STREAM; |
| 518 | |
Arnaud Pouliquen | cd6111b | 2017-01-03 16:52:52 +0100 | [diff] [blame] | 519 | /* Select a channel allocation that matches with ELD and pcm channels */ |
| 520 | idx = hdmi_codec_get_ch_alloc_table_idx(hcp, hp.cea.channels); |
| 521 | if (idx < 0) { |
| 522 | dev_err(dai->dev, "Not able to map channels to speakers (%d)\n", |
| 523 | idx); |
| 524 | hcp->chmap_idx = HDMI_CODEC_CHMAP_IDX_UNKNOWN; |
| 525 | return idx; |
| 526 | } |
| 527 | hp.cea.channel_allocation = hdmi_codec_channel_alloc[idx].ca_id; |
| 528 | hcp->chmap_idx = hdmi_codec_channel_alloc[idx].ca_id; |
| 529 | |
Jyri Sarha | 0918411 | 2016-03-31 16:36:00 +0300 | [diff] [blame] | 530 | hp.sample_width = params_width(params); |
| 531 | hp.sample_rate = params_rate(params); |
| 532 | hp.channels = params_channels(params); |
| 533 | |
Sia Jee Heng | 28785f5 | 2021-02-04 09:42:55 +0800 | [diff] [blame] | 534 | cf->bit_fmt = params_format(params); |
Kuninori Morimoto | efc9194 | 2016-06-24 02:47:55 +0000 | [diff] [blame] | 535 | return hcp->hcd.ops->hw_params(dai->dev->parent, hcp->hcd.data, |
Jerome Brunet | 0cf4610 | 2019-05-06 11:58:15 +0200 | [diff] [blame] | 536 | cf, &hp); |
Jyri Sarha | 0918411 | 2016-03-31 16:36:00 +0300 | [diff] [blame] | 537 | } |
| 538 | |
Jerome Brunet | 0cf4610 | 2019-05-06 11:58:15 +0200 | [diff] [blame] | 539 | static int hdmi_codec_i2s_set_fmt(struct snd_soc_dai *dai, |
| 540 | unsigned int fmt) |
Jyri Sarha | 0918411 | 2016-03-31 16:36:00 +0300 | [diff] [blame] | 541 | { |
Jerome Brunet | 0cf4610 | 2019-05-06 11:58:15 +0200 | [diff] [blame] | 542 | struct hdmi_codec_daifmt *cf = dai->playback_dma_data; |
Jyri Sarha | 0918411 | 2016-03-31 16:36:00 +0300 | [diff] [blame] | 543 | |
Jerome Brunet | 0cf4610 | 2019-05-06 11:58:15 +0200 | [diff] [blame] | 544 | /* Reset daifmt */ |
| 545 | memset(cf, 0, sizeof(*cf)); |
Jyri Sarha | 0918411 | 2016-03-31 16:36:00 +0300 | [diff] [blame] | 546 | |
Russell King | 2e95f98 | 2019-02-28 15:30:34 +0000 | [diff] [blame] | 547 | switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) { |
| 548 | case SND_SOC_DAIFMT_CBM_CFM: |
Jerome Brunet | 0cf4610 | 2019-05-06 11:58:15 +0200 | [diff] [blame] | 549 | cf->bit_clk_master = 1; |
| 550 | cf->frame_clk_master = 1; |
Russell King | 2e95f98 | 2019-02-28 15:30:34 +0000 | [diff] [blame] | 551 | break; |
| 552 | case SND_SOC_DAIFMT_CBS_CFM: |
Jerome Brunet | 0cf4610 | 2019-05-06 11:58:15 +0200 | [diff] [blame] | 553 | cf->frame_clk_master = 1; |
Russell King | 2e95f98 | 2019-02-28 15:30:34 +0000 | [diff] [blame] | 554 | break; |
| 555 | case SND_SOC_DAIFMT_CBM_CFS: |
Jerome Brunet | 0cf4610 | 2019-05-06 11:58:15 +0200 | [diff] [blame] | 556 | cf->bit_clk_master = 1; |
Russell King | 2e95f98 | 2019-02-28 15:30:34 +0000 | [diff] [blame] | 557 | break; |
| 558 | case SND_SOC_DAIFMT_CBS_CFS: |
| 559 | break; |
| 560 | default: |
| 561 | return -EINVAL; |
| 562 | } |
Jyri Sarha | 0918411 | 2016-03-31 16:36:00 +0300 | [diff] [blame] | 563 | |
Russell King | 2e95f98 | 2019-02-28 15:30:34 +0000 | [diff] [blame] | 564 | switch (fmt & SND_SOC_DAIFMT_INV_MASK) { |
| 565 | case SND_SOC_DAIFMT_NB_NF: |
| 566 | break; |
| 567 | case SND_SOC_DAIFMT_NB_IF: |
Jerome Brunet | 0cf4610 | 2019-05-06 11:58:15 +0200 | [diff] [blame] | 568 | cf->frame_clk_inv = 1; |
Russell King | 2e95f98 | 2019-02-28 15:30:34 +0000 | [diff] [blame] | 569 | break; |
| 570 | case SND_SOC_DAIFMT_IB_NF: |
Jerome Brunet | 0cf4610 | 2019-05-06 11:58:15 +0200 | [diff] [blame] | 571 | cf->bit_clk_inv = 1; |
Russell King | 2e95f98 | 2019-02-28 15:30:34 +0000 | [diff] [blame] | 572 | break; |
| 573 | case SND_SOC_DAIFMT_IB_IF: |
Jerome Brunet | 0cf4610 | 2019-05-06 11:58:15 +0200 | [diff] [blame] | 574 | cf->frame_clk_inv = 1; |
| 575 | cf->bit_clk_inv = 1; |
Russell King | 2e95f98 | 2019-02-28 15:30:34 +0000 | [diff] [blame] | 576 | break; |
| 577 | } |
| 578 | |
| 579 | switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) { |
| 580 | case SND_SOC_DAIFMT_I2S: |
Jerome Brunet | 0cf4610 | 2019-05-06 11:58:15 +0200 | [diff] [blame] | 581 | cf->fmt = HDMI_I2S; |
Russell King | 2e95f98 | 2019-02-28 15:30:34 +0000 | [diff] [blame] | 582 | break; |
| 583 | case SND_SOC_DAIFMT_DSP_A: |
Jerome Brunet | 0cf4610 | 2019-05-06 11:58:15 +0200 | [diff] [blame] | 584 | cf->fmt = HDMI_DSP_A; |
Russell King | 2e95f98 | 2019-02-28 15:30:34 +0000 | [diff] [blame] | 585 | break; |
| 586 | case SND_SOC_DAIFMT_DSP_B: |
Jerome Brunet | 0cf4610 | 2019-05-06 11:58:15 +0200 | [diff] [blame] | 587 | cf->fmt = HDMI_DSP_B; |
Russell King | 2e95f98 | 2019-02-28 15:30:34 +0000 | [diff] [blame] | 588 | break; |
| 589 | case SND_SOC_DAIFMT_RIGHT_J: |
Jerome Brunet | 0cf4610 | 2019-05-06 11:58:15 +0200 | [diff] [blame] | 590 | cf->fmt = HDMI_RIGHT_J; |
Russell King | 2e95f98 | 2019-02-28 15:30:34 +0000 | [diff] [blame] | 591 | break; |
| 592 | case SND_SOC_DAIFMT_LEFT_J: |
Jerome Brunet | 0cf4610 | 2019-05-06 11:58:15 +0200 | [diff] [blame] | 593 | cf->fmt = HDMI_LEFT_J; |
Russell King | 2e95f98 | 2019-02-28 15:30:34 +0000 | [diff] [blame] | 594 | break; |
| 595 | case SND_SOC_DAIFMT_AC97: |
Jerome Brunet | 0cf4610 | 2019-05-06 11:58:15 +0200 | [diff] [blame] | 596 | cf->fmt = HDMI_AC97; |
Russell King | 2e95f98 | 2019-02-28 15:30:34 +0000 | [diff] [blame] | 597 | break; |
| 598 | default: |
| 599 | dev_err(dai->dev, "Invalid DAI interface format\n"); |
| 600 | return -EINVAL; |
Jyri Sarha | 0918411 | 2016-03-31 16:36:00 +0300 | [diff] [blame] | 601 | } |
| 602 | |
Russell King | 2e95f98 | 2019-02-28 15:30:34 +0000 | [diff] [blame] | 603 | return 0; |
Jyri Sarha | 0918411 | 2016-03-31 16:36:00 +0300 | [diff] [blame] | 604 | } |
| 605 | |
Kuninori Morimoto | d789710 | 2020-07-09 10:55:45 +0900 | [diff] [blame] | 606 | static int hdmi_codec_mute(struct snd_soc_dai *dai, int mute, int direction) |
Jyri Sarha | 0918411 | 2016-03-31 16:36:00 +0300 | [diff] [blame] | 607 | { |
| 608 | struct hdmi_codec_priv *hcp = snd_soc_dai_get_drvdata(dai); |
| 609 | |
Kuninori Morimoto | d789710 | 2020-07-09 10:55:45 +0900 | [diff] [blame] | 610 | /* |
| 611 | * ignore if direction was CAPTURE |
| 612 | * and it had .no_capture_mute flag |
| 613 | * see |
| 614 | * snd_soc_dai_digital_mute() |
| 615 | */ |
| 616 | if (hcp->hcd.ops->mute_stream && |
| 617 | (direction == SNDRV_PCM_STREAM_PLAYBACK || |
| 618 | !hcp->hcd.ops->no_capture_mute)) |
| 619 | return hcp->hcd.ops->mute_stream(dai->dev->parent, |
| 620 | hcp->hcd.data, |
| 621 | mute, direction); |
Jyri Sarha | 0918411 | 2016-03-31 16:36:00 +0300 | [diff] [blame] | 622 | |
Kuninori Morimoto | e07e49c | 2020-07-09 10:55:36 +0900 | [diff] [blame] | 623 | return -ENOTSUPP; |
Jyri Sarha | 0918411 | 2016-03-31 16:36:00 +0300 | [diff] [blame] | 624 | } |
| 625 | |
Jerome Brunet | 0cf4610 | 2019-05-06 11:58:15 +0200 | [diff] [blame] | 626 | static const struct snd_soc_dai_ops hdmi_codec_i2s_dai_ops = { |
Jyri Sarha | 0918411 | 2016-03-31 16:36:00 +0300 | [diff] [blame] | 627 | .startup = hdmi_codec_startup, |
| 628 | .shutdown = hdmi_codec_shutdown, |
| 629 | .hw_params = hdmi_codec_hw_params, |
Jerome Brunet | 0cf4610 | 2019-05-06 11:58:15 +0200 | [diff] [blame] | 630 | .set_fmt = hdmi_codec_i2s_set_fmt, |
Kuninori Morimoto | d789710 | 2020-07-09 10:55:45 +0900 | [diff] [blame] | 631 | .mute_stream = hdmi_codec_mute, |
Jyri Sarha | 0918411 | 2016-03-31 16:36:00 +0300 | [diff] [blame] | 632 | }; |
| 633 | |
Jerome Brunet | 0cf4610 | 2019-05-06 11:58:15 +0200 | [diff] [blame] | 634 | static const struct snd_soc_dai_ops hdmi_codec_spdif_dai_ops = { |
| 635 | .startup = hdmi_codec_startup, |
| 636 | .shutdown = hdmi_codec_shutdown, |
| 637 | .hw_params = hdmi_codec_hw_params, |
Kuninori Morimoto | d789710 | 2020-07-09 10:55:45 +0900 | [diff] [blame] | 638 | .mute_stream = hdmi_codec_mute, |
Jerome Brunet | 0cf4610 | 2019-05-06 11:58:15 +0200 | [diff] [blame] | 639 | }; |
Jyri Sarha | 0918411 | 2016-03-31 16:36:00 +0300 | [diff] [blame] | 640 | |
| 641 | #define HDMI_RATES (SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 |\ |
| 642 | SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_88200 |\ |
| 643 | SNDRV_PCM_RATE_96000 | SNDRV_PCM_RATE_176400 |\ |
| 644 | SNDRV_PCM_RATE_192000) |
| 645 | |
| 646 | #define SPDIF_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S16_BE |\ |
| 647 | SNDRV_PCM_FMTBIT_S20_3LE | SNDRV_PCM_FMTBIT_S20_3BE |\ |
| 648 | SNDRV_PCM_FMTBIT_S24_3LE | SNDRV_PCM_FMTBIT_S24_3BE |\ |
| 649 | SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S24_BE) |
| 650 | |
| 651 | /* |
| 652 | * This list is only for formats allowed on the I2S bus. So there is |
| 653 | * some formats listed that are not supported by HDMI interface. For |
| 654 | * instance allowing the 32-bit formats enables 24-precision with CPU |
| 655 | * DAIs that do not support 24-bit formats. If the extra formats cause |
| 656 | * problems, we should add the video side driver an option to disable |
| 657 | * them. |
| 658 | */ |
| 659 | #define I2S_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S16_BE |\ |
| 660 | SNDRV_PCM_FMTBIT_S20_3LE | SNDRV_PCM_FMTBIT_S20_3BE |\ |
| 661 | SNDRV_PCM_FMTBIT_S24_3LE | SNDRV_PCM_FMTBIT_S24_3BE |\ |
| 662 | SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S24_BE |\ |
Sia Jee Heng | 28785f5 | 2021-02-04 09:42:55 +0800 | [diff] [blame] | 663 | SNDRV_PCM_FMTBIT_S32_LE | SNDRV_PCM_FMTBIT_S32_BE |\ |
| 664 | SNDRV_PCM_FMTBIT_IEC958_SUBFRAME_LE) |
Jyri Sarha | 0918411 | 2016-03-31 16:36:00 +0300 | [diff] [blame] | 665 | |
Maxime Ripard | 366b45b | 2021-05-25 15:23:45 +0200 | [diff] [blame] | 666 | struct snd_kcontrol_new hdmi_codec_controls[] = { |
| 667 | { |
Maxime Ripard | 7a8e1d4 | 2021-05-25 15:23:46 +0200 | [diff] [blame^] | 668 | .access = SNDRV_CTL_ELEM_ACCESS_READ, |
| 669 | .iface = SNDRV_CTL_ELEM_IFACE_PCM, |
| 670 | .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, MASK), |
| 671 | .info = hdmi_codec_iec958_info, |
| 672 | .get = hdmi_codec_iec958_mask_get, |
| 673 | }, |
| 674 | { |
| 675 | .iface = SNDRV_CTL_ELEM_IFACE_PCM, |
| 676 | .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, DEFAULT), |
| 677 | .info = hdmi_codec_iec958_info, |
| 678 | .get = hdmi_codec_iec958_default_get, |
| 679 | .put = hdmi_codec_iec958_default_put, |
| 680 | }, |
| 681 | { |
Maxime Ripard | 366b45b | 2021-05-25 15:23:45 +0200 | [diff] [blame] | 682 | .access = (SNDRV_CTL_ELEM_ACCESS_READ | |
| 683 | SNDRV_CTL_ELEM_ACCESS_VOLATILE), |
| 684 | .iface = SNDRV_CTL_ELEM_IFACE_PCM, |
| 685 | .name = "ELD", |
| 686 | .info = hdmi_eld_ctl_info, |
| 687 | .get = hdmi_eld_ctl_get, |
| 688 | }, |
| 689 | }; |
| 690 | |
Arnaud Pouliquen | cd6111b | 2017-01-03 16:52:52 +0100 | [diff] [blame] | 691 | static int hdmi_codec_pcm_new(struct snd_soc_pcm_runtime *rtd, |
| 692 | struct snd_soc_dai *dai) |
| 693 | { |
| 694 | struct snd_soc_dai_driver *drv = dai->driver; |
| 695 | struct hdmi_codec_priv *hcp = snd_soc_dai_get_drvdata(dai); |
Maxime Ripard | 366b45b | 2021-05-25 15:23:45 +0200 | [diff] [blame] | 696 | unsigned int i; |
Arnaud Pouliquen | cd6111b | 2017-01-03 16:52:52 +0100 | [diff] [blame] | 697 | int ret; |
| 698 | |
Arnaud Pouliquen | cd6111b | 2017-01-03 16:52:52 +0100 | [diff] [blame] | 699 | ret = snd_pcm_add_chmap_ctls(rtd->pcm, SNDRV_PCM_STREAM_PLAYBACK, |
| 700 | NULL, drv->playback.channels_max, 0, |
| 701 | &hcp->chmap_info); |
| 702 | if (ret < 0) |
| 703 | return ret; |
| 704 | |
| 705 | /* override handlers */ |
| 706 | hcp->chmap_info->private_data = hcp; |
| 707 | hcp->chmap_info->kctl->get = hdmi_codec_chmap_ctl_get; |
| 708 | |
| 709 | /* default chmap supported is stereo */ |
| 710 | hcp->chmap_info->chmap = hdmi_codec_stereo_chmaps; |
| 711 | hcp->chmap_idx = HDMI_CODEC_CHMAP_IDX_UNKNOWN; |
| 712 | |
Maxime Ripard | 366b45b | 2021-05-25 15:23:45 +0200 | [diff] [blame] | 713 | for (i = 0; i < ARRAY_SIZE(hdmi_codec_controls); i++) { |
| 714 | struct snd_kcontrol *kctl; |
Kuninori Morimoto | ecbb1b8 | 2017-07-06 00:39:29 +0000 | [diff] [blame] | 715 | |
Maxime Ripard | 366b45b | 2021-05-25 15:23:45 +0200 | [diff] [blame] | 716 | /* add ELD ctl with the device number corresponding to the PCM stream */ |
| 717 | kctl = snd_ctl_new1(&hdmi_codec_controls[i], dai->component); |
| 718 | if (!kctl) |
| 719 | return -ENOMEM; |
| 720 | |
| 721 | kctl->id.device = rtd->pcm->device; |
| 722 | ret = snd_ctl_add(rtd->card->snd_card, kctl); |
| 723 | if (ret < 0) |
| 724 | return ret; |
| 725 | } |
| 726 | |
| 727 | return 0; |
Arnaud Pouliquen | cd6111b | 2017-01-03 16:52:52 +0100 | [diff] [blame] | 728 | } |
| 729 | |
Russell King | d30e23d | 2018-07-14 16:01:06 +0100 | [diff] [blame] | 730 | static int hdmi_dai_probe(struct snd_soc_dai *dai) |
| 731 | { |
| 732 | struct snd_soc_dapm_context *dapm; |
Jerome Brunet | 0cf4610 | 2019-05-06 11:58:15 +0200 | [diff] [blame] | 733 | struct hdmi_codec_daifmt *daifmt; |
Shengjiu Wang | 144f836 | 2020-11-26 14:36:48 +0800 | [diff] [blame] | 734 | struct snd_soc_dapm_route route[] = { |
| 735 | { |
| 736 | .sink = "TX", |
| 737 | .source = dai->driver->playback.stream_name, |
| 738 | }, |
| 739 | { |
| 740 | .sink = dai->driver->capture.stream_name, |
| 741 | .source = "RX", |
| 742 | }, |
Russell King | d30e23d | 2018-07-14 16:01:06 +0100 | [diff] [blame] | 743 | }; |
Jerome Brunet | 0cf4610 | 2019-05-06 11:58:15 +0200 | [diff] [blame] | 744 | int ret; |
Russell King | d30e23d | 2018-07-14 16:01:06 +0100 | [diff] [blame] | 745 | |
| 746 | dapm = snd_soc_component_get_dapm(dai->component); |
Shengjiu Wang | 144f836 | 2020-11-26 14:36:48 +0800 | [diff] [blame] | 747 | ret = snd_soc_dapm_add_routes(dapm, route, 2); |
Jerome Brunet | 0cf4610 | 2019-05-06 11:58:15 +0200 | [diff] [blame] | 748 | if (ret) |
| 749 | return ret; |
Russell King | d30e23d | 2018-07-14 16:01:06 +0100 | [diff] [blame] | 750 | |
Jerome Brunet | 0cf4610 | 2019-05-06 11:58:15 +0200 | [diff] [blame] | 751 | daifmt = kzalloc(sizeof(*daifmt), GFP_KERNEL); |
| 752 | if (!daifmt) |
| 753 | return -ENOMEM; |
| 754 | |
| 755 | dai->playback_dma_data = daifmt; |
| 756 | return 0; |
| 757 | } |
| 758 | |
Cheng-Yi Chiang | 6fa5963 | 2019-07-17 16:33:23 +0800 | [diff] [blame] | 759 | static void hdmi_codec_jack_report(struct hdmi_codec_priv *hcp, |
| 760 | unsigned int jack_status) |
| 761 | { |
| 762 | if (hcp->jack && jack_status != hcp->jack_status) { |
| 763 | snd_soc_jack_report(hcp->jack, jack_status, SND_JACK_LINEOUT); |
| 764 | hcp->jack_status = jack_status; |
| 765 | } |
| 766 | } |
| 767 | |
| 768 | static void plugged_cb(struct device *dev, bool plugged) |
| 769 | { |
| 770 | struct hdmi_codec_priv *hcp = dev_get_drvdata(dev); |
| 771 | |
Cheng-Yi Chiang | 25ce4f2 | 2020-11-18 12:38:52 +0800 | [diff] [blame] | 772 | if (plugged) { |
| 773 | if (hcp->hcd.ops->get_eld) { |
| 774 | hcp->hcd.ops->get_eld(dev->parent, hcp->hcd.data, |
| 775 | hcp->eld, sizeof(hcp->eld)); |
| 776 | } |
Cheng-Yi Chiang | 6fa5963 | 2019-07-17 16:33:23 +0800 | [diff] [blame] | 777 | hdmi_codec_jack_report(hcp, SND_JACK_LINEOUT); |
Cheng-Yi Chiang | 25ce4f2 | 2020-11-18 12:38:52 +0800 | [diff] [blame] | 778 | } else { |
Cheng-Yi Chiang | 6fa5963 | 2019-07-17 16:33:23 +0800 | [diff] [blame] | 779 | hdmi_codec_jack_report(hcp, 0); |
Cheng-Yi Chiang | 25ce4f2 | 2020-11-18 12:38:52 +0800 | [diff] [blame] | 780 | memset(hcp->eld, 0, sizeof(hcp->eld)); |
| 781 | } |
Cheng-Yi Chiang | 6fa5963 | 2019-07-17 16:33:23 +0800 | [diff] [blame] | 782 | } |
| 783 | |
Cheng-Yi Chiang | 55c5cc63 | 2020-09-22 14:23:16 +0800 | [diff] [blame] | 784 | static int hdmi_codec_set_jack(struct snd_soc_component *component, |
| 785 | struct snd_soc_jack *jack, |
| 786 | void *data) |
Cheng-Yi Chiang | 6fa5963 | 2019-07-17 16:33:23 +0800 | [diff] [blame] | 787 | { |
| 788 | struct hdmi_codec_priv *hcp = snd_soc_component_get_drvdata(component); |
Stephan Gerhold | 2a0435d | 2021-01-07 17:51:31 +0100 | [diff] [blame] | 789 | int ret = -ENOTSUPP; |
Cheng-Yi Chiang | 6fa5963 | 2019-07-17 16:33:23 +0800 | [diff] [blame] | 790 | |
| 791 | if (hcp->hcd.ops->hook_plugged_cb) { |
| 792 | hcp->jack = jack; |
| 793 | ret = hcp->hcd.ops->hook_plugged_cb(component->dev->parent, |
| 794 | hcp->hcd.data, |
| 795 | plugged_cb, |
| 796 | component->dev); |
| 797 | if (ret) |
| 798 | hcp->jack = NULL; |
| 799 | } |
| 800 | return ret; |
| 801 | } |
Cheng-Yi Chiang | 6fa5963 | 2019-07-17 16:33:23 +0800 | [diff] [blame] | 802 | |
Jerome Brunet | 0cf4610 | 2019-05-06 11:58:15 +0200 | [diff] [blame] | 803 | static int hdmi_dai_spdif_probe(struct snd_soc_dai *dai) |
| 804 | { |
Pierre-Louis Bossart | 3c011ef | 2021-03-12 12:22:33 -0600 | [diff] [blame] | 805 | struct hdmi_codec_daifmt *cf; |
Jerome Brunet | 0cf4610 | 2019-05-06 11:58:15 +0200 | [diff] [blame] | 806 | int ret; |
| 807 | |
| 808 | ret = hdmi_dai_probe(dai); |
| 809 | if (ret) |
| 810 | return ret; |
| 811 | |
| 812 | cf = dai->playback_dma_data; |
| 813 | cf->fmt = HDMI_SPDIF; |
| 814 | |
| 815 | return 0; |
| 816 | } |
| 817 | |
| 818 | static int hdmi_codec_dai_remove(struct snd_soc_dai *dai) |
| 819 | { |
| 820 | kfree(dai->playback_dma_data); |
| 821 | return 0; |
Russell King | d30e23d | 2018-07-14 16:01:06 +0100 | [diff] [blame] | 822 | } |
| 823 | |
Bhumika Goyal | 6e37f93 | 2017-08-16 22:45:09 +0530 | [diff] [blame] | 824 | static const struct snd_soc_dai_driver hdmi_i2s_dai = { |
Kuninori Morimoto | 24069b5 | 2017-05-18 01:40:02 +0000 | [diff] [blame] | 825 | .name = "i2s-hifi", |
Jyri Sarha | 0918411 | 2016-03-31 16:36:00 +0300 | [diff] [blame] | 826 | .id = DAI_ID_I2S, |
Russell King | d30e23d | 2018-07-14 16:01:06 +0100 | [diff] [blame] | 827 | .probe = hdmi_dai_probe, |
Jerome Brunet | 0cf4610 | 2019-05-06 11:58:15 +0200 | [diff] [blame] | 828 | .remove = hdmi_codec_dai_remove, |
Jyri Sarha | 0918411 | 2016-03-31 16:36:00 +0300 | [diff] [blame] | 829 | .playback = { |
Jeffy Chen | 943fa02 | 2017-08-12 08:40:38 +0800 | [diff] [blame] | 830 | .stream_name = "I2S Playback", |
Jyri Sarha | 0918411 | 2016-03-31 16:36:00 +0300 | [diff] [blame] | 831 | .channels_min = 2, |
| 832 | .channels_max = 8, |
| 833 | .rates = HDMI_RATES, |
| 834 | .formats = I2S_FORMATS, |
| 835 | .sig_bits = 24, |
| 836 | }, |
Shengjiu Wang | 144f836 | 2020-11-26 14:36:48 +0800 | [diff] [blame] | 837 | .capture = { |
| 838 | .stream_name = "Capture", |
| 839 | .channels_min = 2, |
| 840 | .channels_max = 8, |
| 841 | .rates = HDMI_RATES, |
| 842 | .formats = I2S_FORMATS, |
| 843 | .sig_bits = 24, |
| 844 | }, |
Jerome Brunet | 0cf4610 | 2019-05-06 11:58:15 +0200 | [diff] [blame] | 845 | .ops = &hdmi_codec_i2s_dai_ops, |
Arnaud Pouliquen | cd6111b | 2017-01-03 16:52:52 +0100 | [diff] [blame] | 846 | .pcm_new = hdmi_codec_pcm_new, |
Jyri Sarha | 0918411 | 2016-03-31 16:36:00 +0300 | [diff] [blame] | 847 | }; |
| 848 | |
| 849 | static const struct snd_soc_dai_driver hdmi_spdif_dai = { |
Kuninori Morimoto | 24069b5 | 2017-05-18 01:40:02 +0000 | [diff] [blame] | 850 | .name = "spdif-hifi", |
Jyri Sarha | 0918411 | 2016-03-31 16:36:00 +0300 | [diff] [blame] | 851 | .id = DAI_ID_SPDIF, |
Jerome Brunet | 0cf4610 | 2019-05-06 11:58:15 +0200 | [diff] [blame] | 852 | .probe = hdmi_dai_spdif_probe, |
| 853 | .remove = hdmi_codec_dai_remove, |
Jyri Sarha | 0918411 | 2016-03-31 16:36:00 +0300 | [diff] [blame] | 854 | .playback = { |
Jeffy Chen | 943fa02 | 2017-08-12 08:40:38 +0800 | [diff] [blame] | 855 | .stream_name = "SPDIF Playback", |
Jyri Sarha | 0918411 | 2016-03-31 16:36:00 +0300 | [diff] [blame] | 856 | .channels_min = 2, |
| 857 | .channels_max = 2, |
| 858 | .rates = HDMI_RATES, |
| 859 | .formats = SPDIF_FORMATS, |
| 860 | }, |
Shengjiu Wang | 144f836 | 2020-11-26 14:36:48 +0800 | [diff] [blame] | 861 | .capture = { |
| 862 | .stream_name = "Capture", |
| 863 | .channels_min = 2, |
| 864 | .channels_max = 2, |
| 865 | .rates = HDMI_RATES, |
| 866 | .formats = SPDIF_FORMATS, |
| 867 | }, |
Jerome Brunet | 0cf4610 | 2019-05-06 11:58:15 +0200 | [diff] [blame] | 868 | .ops = &hdmi_codec_spdif_dai_ops, |
Arnaud Pouliquen | cd6111b | 2017-01-03 16:52:52 +0100 | [diff] [blame] | 869 | .pcm_new = hdmi_codec_pcm_new, |
Jyri Sarha | 0918411 | 2016-03-31 16:36:00 +0300 | [diff] [blame] | 870 | }; |
| 871 | |
Kuninori Morimoto | 96203fb | 2017-05-18 01:40:20 +0000 | [diff] [blame] | 872 | static int hdmi_of_xlate_dai_id(struct snd_soc_component *component, |
| 873 | struct device_node *endpoint) |
| 874 | { |
| 875 | struct hdmi_codec_priv *hcp = snd_soc_component_get_drvdata(component); |
| 876 | int ret = -ENOTSUPP; /* see snd_soc_get_dai_id() */ |
| 877 | |
| 878 | if (hcp->hcd.ops->get_dai_id) |
| 879 | ret = hcp->hcd.ops->get_dai_id(component, endpoint); |
| 880 | |
| 881 | return ret; |
| 882 | } |
| 883 | |
Tzung-Bi Shih | 4aadf4b | 2020-02-17 11:16:52 +0800 | [diff] [blame] | 884 | static void hdmi_remove(struct snd_soc_component *component) |
| 885 | { |
| 886 | struct hdmi_codec_priv *hcp = snd_soc_component_get_drvdata(component); |
| 887 | |
| 888 | if (hcp->hcd.ops->hook_plugged_cb) |
| 889 | hcp->hcd.ops->hook_plugged_cb(component->dev->parent, |
| 890 | hcp->hcd.data, NULL, NULL); |
| 891 | } |
| 892 | |
Kuninori Morimoto | d20aa60 | 2018-01-29 04:34:21 +0000 | [diff] [blame] | 893 | static const struct snd_soc_component_driver hdmi_driver = { |
Tzung-Bi Shih | 4aadf4b | 2020-02-17 11:16:52 +0800 | [diff] [blame] | 894 | .remove = hdmi_remove, |
Kuninori Morimoto | d20aa60 | 2018-01-29 04:34:21 +0000 | [diff] [blame] | 895 | .dapm_widgets = hdmi_widgets, |
| 896 | .num_dapm_widgets = ARRAY_SIZE(hdmi_widgets), |
Kuninori Morimoto | d20aa60 | 2018-01-29 04:34:21 +0000 | [diff] [blame] | 897 | .of_xlate_dai_id = hdmi_of_xlate_dai_id, |
| 898 | .idle_bias_on = 1, |
| 899 | .use_pmdown_time = 1, |
| 900 | .endianness = 1, |
| 901 | .non_legacy_dai_naming = 1, |
Cheng-Yi Chiang | 55c5cc63 | 2020-09-22 14:23:16 +0800 | [diff] [blame] | 902 | .set_jack = hdmi_codec_set_jack, |
Jyri Sarha | 0918411 | 2016-03-31 16:36:00 +0300 | [diff] [blame] | 903 | }; |
| 904 | |
| 905 | static int hdmi_codec_probe(struct platform_device *pdev) |
| 906 | { |
| 907 | struct hdmi_codec_pdata *hcd = pdev->dev.platform_data; |
Jerome Brunet | 1de005d | 2019-05-06 11:58:14 +0200 | [diff] [blame] | 908 | struct snd_soc_dai_driver *daidrv; |
Jyri Sarha | 0918411 | 2016-03-31 16:36:00 +0300 | [diff] [blame] | 909 | struct device *dev = &pdev->dev; |
| 910 | struct hdmi_codec_priv *hcp; |
| 911 | int dai_count, i = 0; |
| 912 | int ret; |
| 913 | |
Jyri Sarha | 0918411 | 2016-03-31 16:36:00 +0300 | [diff] [blame] | 914 | if (!hcd) { |
Colin Ian King | 7b6531c | 2019-04-17 17:26:28 +0100 | [diff] [blame] | 915 | dev_err(dev, "%s: No platform data\n", __func__); |
Jyri Sarha | 0918411 | 2016-03-31 16:36:00 +0300 | [diff] [blame] | 916 | return -EINVAL; |
| 917 | } |
| 918 | |
| 919 | dai_count = hcd->i2s + hcd->spdif; |
| 920 | if (dai_count < 1 || !hcd->ops || !hcd->ops->hw_params || |
| 921 | !hcd->ops->audio_shutdown) { |
| 922 | dev_err(dev, "%s: Invalid parameters\n", __func__); |
| 923 | return -EINVAL; |
| 924 | } |
| 925 | |
| 926 | hcp = devm_kzalloc(dev, sizeof(*hcp), GFP_KERNEL); |
| 927 | if (!hcp) |
| 928 | return -ENOMEM; |
| 929 | |
| 930 | hcp->hcd = *hcd; |
Jerome Brunet | 1442842 | 2019-12-06 11:35:42 +0100 | [diff] [blame] | 931 | mutex_init(&hcp->lock); |
| 932 | |
Maxime Ripard | 7a8e1d4 | 2021-05-25 15:23:46 +0200 | [diff] [blame^] | 933 | ret = snd_pcm_create_iec958_consumer_default(hcp->iec_status, |
| 934 | sizeof(hcp->iec_status)); |
| 935 | if (ret < 0) |
| 936 | return ret; |
| 937 | |
Jerome Brunet | 1de005d | 2019-05-06 11:58:14 +0200 | [diff] [blame] | 938 | daidrv = devm_kcalloc(dev, dai_count, sizeof(*daidrv), GFP_KERNEL); |
| 939 | if (!daidrv) |
Jyri Sarha | 0918411 | 2016-03-31 16:36:00 +0300 | [diff] [blame] | 940 | return -ENOMEM; |
| 941 | |
| 942 | if (hcd->i2s) { |
Jerome Brunet | 1de005d | 2019-05-06 11:58:14 +0200 | [diff] [blame] | 943 | daidrv[i] = hdmi_i2s_dai; |
| 944 | daidrv[i].playback.channels_max = hcd->max_i2s_channels; |
Jyri Sarha | 0918411 | 2016-03-31 16:36:00 +0300 | [diff] [blame] | 945 | i++; |
| 946 | } |
| 947 | |
Jerome Brunet | 0cf4610 | 2019-05-06 11:58:15 +0200 | [diff] [blame] | 948 | if (hcd->spdif) |
Jerome Brunet | 1de005d | 2019-05-06 11:58:14 +0200 | [diff] [blame] | 949 | daidrv[i] = hdmi_spdif_dai; |
Jyri Sarha | 0918411 | 2016-03-31 16:36:00 +0300 | [diff] [blame] | 950 | |
Russell King | 0ce23d6 | 2019-01-17 17:32:05 +0000 | [diff] [blame] | 951 | dev_set_drvdata(dev, hcp); |
| 952 | |
Jerome Brunet | 1de005d | 2019-05-06 11:58:14 +0200 | [diff] [blame] | 953 | ret = devm_snd_soc_register_component(dev, &hdmi_driver, daidrv, |
| 954 | dai_count); |
Jyri Sarha | 0918411 | 2016-03-31 16:36:00 +0300 | [diff] [blame] | 955 | if (ret) { |
Kuninori Morimoto | d20aa60 | 2018-01-29 04:34:21 +0000 | [diff] [blame] | 956 | dev_err(dev, "%s: snd_soc_register_component() failed (%d)\n", |
Jyri Sarha | 0918411 | 2016-03-31 16:36:00 +0300 | [diff] [blame] | 957 | __func__, ret); |
| 958 | return ret; |
| 959 | } |
Jyri Sarha | 0918411 | 2016-03-31 16:36:00 +0300 | [diff] [blame] | 960 | return 0; |
| 961 | } |
| 962 | |
Jyri Sarha | 0918411 | 2016-03-31 16:36:00 +0300 | [diff] [blame] | 963 | static struct platform_driver hdmi_codec_driver = { |
| 964 | .driver = { |
| 965 | .name = HDMI_CODEC_DRV_NAME, |
| 966 | }, |
| 967 | .probe = hdmi_codec_probe, |
Jyri Sarha | 0918411 | 2016-03-31 16:36:00 +0300 | [diff] [blame] | 968 | }; |
| 969 | |
| 970 | module_platform_driver(hdmi_codec_driver); |
| 971 | |
| 972 | MODULE_AUTHOR("Jyri Sarha <jsarha@ti.com>"); |
| 973 | MODULE_DESCRIPTION("HDMI Audio Codec Driver"); |
| 974 | MODULE_LICENSE("GPL"); |
| 975 | MODULE_ALIAS("platform:" HDMI_CODEC_DRV_NAME); |