Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

ASoC: Cleanup MediaTek soundcard machine drivers

Merge series from AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>:

Changes in v5:
- Cleaned up MT8186 soundcard migration commit which erroneously
had leftovers from development
- Changed the mtk_pcm_constraints_data structure to hold pointers
to snd_pcm_hw_constraint_list, as to really reuse the const data
- Tested again on all of the listed MTK platforms.

Changes in v4:
- Rebased over next-20240409
- Dropped the first 4 patches from v3 as were already picked by Mark
- Fixed W=1 build issue

Changes in v3:
- Added audio-routing names in enum in all yaml files
- Added mention of disallowing old and new properties together in
commit message of bindings patches
- Fixed validation errors with sound-card-common.yaml inclusion
due to missing model property in examples
- Removed `else` enforcing headset-codec/speaker-codecs requirement
if xxx-dai-link not present to avoid future commit noise as the
deprecated statement will disallow deprecated properties as required

Changes in v2:
- Bindings: Changed link-name/codec/clk-provider to remove `items`
and leave just the enum
- Moved .*-dai-link pattern additionalProperties after `type: object`
- Added ref to sound-card-common.yaml
- Fixed dai-link-xxx -> xxx-dai-link typo in example comment

This series performs a cleanup of most of the MediaTek AFE drivers and
soundcard machine drivers, reducing code duplication and setting a base
to be consistent with their devicetree bindings, as many of those are
using different properties and nodes for no good reason.

Summarizing:
- Commonizes functions and ops where possible
- Adds a common probe mechanism, increasing maintainability of
soundcard drivers for older MediaTek SoCs
- Migrates all drivers to support the new bindings
- Obviously retains compatibility with old device trees
- Reduces machine-specific parameters hardcoding in drivers
- Can now set machine-specific params in device tree
- Uses the `audio-routing` and `dai-link` nodes like some
other non-MediaTek SoC sound drivers
- Imposes consistency between MediaTek ASoC machine soundcard
drivers bindings
- Reduces code size and greatly reduces the amount of code that
will be required for newer drivers (retaining compatibility with
the old bindings was costly in terms of code size, otherwise
this series would've removed ~1000 more lines, or something
along that line).

This series was (manually) tested on MT8173, MT8192, MT8195 and MT8186
Chromebooks.

AngeloGioacchino Del Regno (18):
ASoC: mediatek: Add common machine soundcard driver probe mechanism
ASoC: mediatek: common: Constify struct mtk_sof_priv
ASoC: mediatek: mt8188: Migrate to mtk_soundcard_common_probe
ASoC: mediatek: mt8195: Migrate to mtk_soundcard_common_probe
ASoC: mediatek: mt8192: Migrate to mtk_soundcard_common_probe
ASoC: mediatek: mt8186: Migrate to mtk_soundcard_common_probe
ASoC: mediatek: Add common snd_soc_ops .startup() callback
ASoC: mediatek: mt8195: Migrate to the common mtk_soundcard_startup
ASoC: mediatek: mt8192: Migrate to the common mtk_soundcard_startup
ASoC: mediatek: mt8186-rt1019: Migrate to the common
mtk_soundcard_startup
ASoC: mediatek: Add common mtk_afe_component_probe callback
ASoC: mediatek: Use common mtk_afe_pcm_platform with common probe cb
ASoC: mediatek: mt8186: Unify mt8186-mt6366 machine drivers
ASoC: dt-bindings: mt8195: Document audio-routing and dai-link subnode
ASoC: dt-bindings: mt8192: Document audio-routing and dai-link subnode
ASoC: dt-bindings: mt8186: Document audio-routing and dai-link subnode
arm64: dts: mediatek: mt8195-cherry: Specify sound DAI links and
routing
arm64: dts: mediatek: mt8186-corsola: Specify sound DAI links and
routing

.../sound/mt8186-mt6366-da7219-max98357.yaml | 131 +-
.../sound/mt8186-mt6366-rt1019-rt5682s.yaml | 120 +-
.../sound/mt8192-mt6359-rt1015-rt5682.yaml | 139 +-
.../bindings/sound/mt8195-mt6359.yaml | 134 ++
.../boot/dts/mediatek/mt8186-corsola.dtsi | 42 +-
.../boot/dts/mediatek/mt8195-cherry.dtsi | 45 +
sound/soc/mediatek/Kconfig | 24 +-
.../mediatek/common/mtk-afe-platform-driver.c | 18 +
.../soc/mediatek/common/mtk-dsp-sof-common.c | 15 +-
.../soc/mediatek/common/mtk-dsp-sof-common.h | 1 -
sound/soc/mediatek/common/mtk-soc-card.h | 7 +-
.../mediatek/common/mtk-soundcard-driver.c | 199 +++
.../mediatek/common/mtk-soundcard-driver.h | 42 +
sound/soc/mediatek/mt6797/mt6797-afe-pcm.c | 14 +-
sound/soc/mediatek/mt7986/mt7986-afe-pcm.c | 14 +-
sound/soc/mediatek/mt8183/mt8183-afe-pcm.c | 14 +-
sound/soc/mediatek/mt8186/Makefile | 3 +-
.../mt8186/mt8186-mt6366-da7219-max98357.c | 1189 -----------------
...t6366-rt1019-rt5682s.c => mt8186-mt6366.c} | 578 ++++----
sound/soc/mediatek/mt8188/mt8188-afe-pcm.c | 21 +-
sound/soc/mediatek/mt8188/mt8188-mt6359.c | 203 +--
sound/soc/mediatek/mt8192/mt8192-afe-pcm.c | 25 +-
.../mt8192/mt8192-mt6359-rt1015-rt5682.c | 301 ++---
sound/soc/mediatek/mt8195/mt8195-afe-pcm.c | 21 +-
sound/soc/mediatek/mt8195/mt8195-mt6359.c | 487 +++----
25 files changed, 1597 insertions(+), 2190 deletions(-)
delete mode 100644 sound/soc/mediatek/mt8186/mt8186-mt6366-da7219-max98357.c
rename sound/soc/mediatek/mt8186/{mt8186-mt6366-rt1019-rt5682s.c => mt8186-mt6366.c} (72%)

--
2.44.0

+1713 -2383
+122 -9
Documentation/devicetree/bindings/sound/mt8186-mt6366-da7219-max98357.yaml
··· 12 12 description: 13 13 This binding describes the MT8186 sound card. 14 14 15 + allOf: 16 + - $ref: sound-card-common.yaml# 17 + 15 18 properties: 16 19 compatible: 17 20 enum: 18 21 - mediatek,mt8186-mt6366-da7219-max98357-sound 22 + 23 + audio-routing: 24 + $ref: /schemas/types.yaml#/definitions/non-unique-string-array 25 + description: 26 + A list of the connections between audio components. Each entry is a 27 + pair of strings, the first being the connection's sink, the second 28 + being the connection's source. 29 + Valid names could be the input or output widgets of audio components, 30 + power supplies, MicBias of codec and the software switch. 31 + minItems: 2 32 + items: 33 + enum: 34 + # Sinks 35 + - HDMI1 36 + - Headphones 37 + - Line Out 38 + - MIC 39 + - Speakers 40 + 41 + # Sources 42 + - Headset Mic 43 + - HPL 44 + - HPR 45 + - Speaker 46 + - TX 19 47 20 48 mediatek,platform: 21 49 $ref: /schemas/types.yaml#/definitions/phandle ··· 51 23 52 24 headset-codec: 53 25 type: object 26 + deprecated: true 54 27 additionalProperties: false 55 28 properties: 56 29 sound-dai: ··· 61 32 62 33 playback-codecs: 63 34 type: object 35 + deprecated: true 64 36 additionalProperties: false 65 37 properties: 66 38 sound-dai: ··· 83 53 A list of the desired dai-links in the sound card. Each entry is a 84 54 name defined in the machine driver. 85 55 86 - additionalProperties: false 56 + patternProperties: 57 + ".*-dai-link$": 58 + type: object 59 + additionalProperties: false 60 + description: 61 + Container for dai-link level properties and CODEC sub-nodes. 62 + 63 + properties: 64 + link-name: 65 + description: Indicates dai-link name and PCM stream name 66 + items: 67 + enum: 68 + - I2S0 69 + - I2S1 70 + - I2S2 71 + - I2S3 72 + 73 + codec: 74 + description: Holds subnode which indicates codec dai. 75 + type: object 76 + additionalProperties: false 77 + properties: 78 + sound-dai: 79 + minItems: 1 80 + maxItems: 2 81 + required: 82 + - sound-dai 83 + 84 + dai-format: 85 + description: audio format 86 + items: 87 + enum: 88 + - i2s 89 + - right_j 90 + - left_j 91 + - dsp_a 92 + - dsp_b 93 + 94 + mediatek,clk-provider: 95 + $ref: /schemas/types.yaml#/definitions/string 96 + description: Indicates dai-link clock master. 97 + items: 98 + enum: 99 + - cpu 100 + - codec 101 + 102 + required: 103 + - link-name 104 + 105 + unevaluatedProperties: false 87 106 88 107 required: 89 108 - compatible 90 109 - mediatek,platform 91 - - headset-codec 92 - - playback-codecs 110 + 111 + # Disallow legacy properties if xxx-dai-link nodes are specified 112 + if: 113 + not: 114 + patternProperties: 115 + ".*-dai-link$": false 116 + then: 117 + properties: 118 + headset-codec: false 119 + speaker-codecs: false 93 120 94 121 examples: 95 122 - | 96 123 97 124 sound: mt8186-sound { 98 125 compatible = "mediatek,mt8186-mt6366-da7219-max98357-sound"; 99 - mediatek,platform = <&afe>; 126 + model = "mt8186_da7219_m98357"; 100 127 pinctrl-names = "aud_clk_mosi_off", 101 128 "aud_clk_mosi_on"; 102 129 pinctrl-0 = <&aud_clk_mosi_off>; 103 130 pinctrl-1 = <&aud_clk_mosi_on>; 131 + mediatek,platform = <&afe>; 104 132 105 - headset-codec { 106 - sound-dai = <&da7219>; 133 + audio-routing = 134 + "Headphones", "HPL", 135 + "Headphones", "HPR", 136 + "MIC", "Headset Mic", 137 + "Speakers", "Speaker", 138 + "HDMI1", "TX"; 139 + 140 + hs-playback-dai-link { 141 + link-name = "I2S0"; 142 + dai-format = "i2s"; 143 + mediatek,clk-provider = "cpu"; 144 + codec { 145 + sound-dai = <&da7219>; 146 + }; 107 147 }; 108 148 109 - playback-codecs { 110 - sound-dai = <&anx_bridge_dp>, 111 - <&max98357a>; 149 + hs-capture-dai-link { 150 + link-name = "I2S1"; 151 + dai-format = "i2s"; 152 + mediatek,clk-provider = "cpu"; 153 + codec { 154 + sound-dai = <&da7219>; 155 + }; 156 + }; 157 + 158 + spk-dp-playback-dai-link { 159 + link-name = "I2S3"; 160 + dai-format = "i2s"; 161 + mediatek,clk-provider = "cpu"; 162 + codec { 163 + sound-dai = <&anx_bridge_dp>, <&max98357a>; 164 + }; 112 165 }; 113 166 }; 114 167
+111 -9
Documentation/devicetree/bindings/sound/mt8186-mt6366-rt1019-rt5682s.yaml
··· 12 12 description: 13 13 This binding describes the MT8186 sound card. 14 14 15 + allOf: 16 + - $ref: sound-card-common.yaml# 17 + 15 18 properties: 16 19 compatible: 17 20 enum: 18 21 - mediatek,mt8186-mt6366-rt1019-rt5682s-sound 19 22 - mediatek,mt8186-mt6366-rt5682s-max98360-sound 20 23 - mediatek,mt8186-mt6366-rt5650-sound 24 + 25 + audio-routing: 26 + $ref: /schemas/types.yaml#/definitions/non-unique-string-array 27 + description: 28 + A list of the connections between audio components. Each entry is a 29 + pair of strings, the first being the connection's sink, the second 30 + being the connection's source. 31 + Valid names could be the input or output widgets of audio components, 32 + power supplies, MicBias of codec and the software switch. 33 + minItems: 2 34 + items: 35 + enum: 36 + # Sinks 37 + - HDMI1 38 + - Headphone 39 + - IN1P 40 + - IN1N 41 + - Line Out 42 + - Speakers 43 + 44 + # Sources 45 + - Headset Mic 46 + - HPOL 47 + - HPOR 48 + - Speaker 49 + - SPOL 50 + - SPOR 51 + - TX 21 52 22 53 mediatek,platform: 23 54 $ref: /schemas/types.yaml#/definitions/phandle ··· 63 32 64 33 headset-codec: 65 34 type: object 35 + deprecated: true 66 36 additionalProperties: false 67 37 properties: 68 38 sound-dai: ··· 73 41 74 42 playback-codecs: 75 43 type: object 44 + deprecated: true 76 45 additionalProperties: false 77 46 properties: 78 47 sound-dai: ··· 95 62 A list of the desired dai-links in the sound card. Each entry is a 96 63 name defined in the machine driver. 97 64 98 - additionalProperties: false 65 + patternProperties: 66 + ".*-dai-link$": 67 + type: object 68 + additionalProperties: false 69 + description: 70 + Container for dai-link level properties and CODEC sub-nodes. 71 + 72 + properties: 73 + link-name: 74 + description: Indicates dai-link name and PCM stream name 75 + enum: [ I2S0, I2S1, I2S2, I2S3 ] 76 + 77 + codec: 78 + description: Holds subnode which indicates codec dai. 79 + type: object 80 + additionalProperties: false 81 + properties: 82 + sound-dai: 83 + minItems: 1 84 + maxItems: 2 85 + required: 86 + - sound-dai 87 + 88 + dai-format: 89 + description: audio format 90 + enum: [ i2s, right_j, left_j, dsp_a, dsp_b ] 91 + 92 + mediatek,clk-provider: 93 + $ref: /schemas/types.yaml#/definitions/string 94 + description: Indicates dai-link clock master. 95 + enum: [ cpu, codec ] 96 + 97 + required: 98 + - link-name 99 + 100 + unevaluatedProperties: false 99 101 100 102 required: 101 103 - compatible 102 104 - mediatek,platform 103 - - headset-codec 104 - - playback-codecs 105 + 106 + # Disallow legacy properties if xxx-dai-link nodes are specified 107 + if: 108 + not: 109 + patternProperties: 110 + ".*-dai-link$": false 111 + then: 112 + properties: 113 + headset-codec: false 114 + speaker-codecs: false 105 115 106 116 examples: 107 117 - | ··· 152 76 153 77 sound: mt8186-sound { 154 78 compatible = "mediatek,mt8186-mt6366-rt1019-rt5682s-sound"; 155 - mediatek,platform = <&afe>; 79 + model = "mt8186_rt1019_rt5682s"; 156 80 pinctrl-names = "aud_clk_mosi_off", 157 81 "aud_clk_mosi_on", 158 82 "aud_gpio_dmic_sec"; 159 83 pinctrl-0 = <&aud_clk_mosi_off>; 160 84 pinctrl-1 = <&aud_clk_mosi_on>; 161 85 pinctrl-2 = <&aud_gpio_dmic_sec>; 86 + mediatek,platform = <&afe>; 162 87 163 88 dmic-gpios = <&pio 23 GPIO_ACTIVE_HIGH>; 164 89 165 - headset-codec { 166 - sound-dai = <&rt5682s>; 90 + audio-routing = 91 + "Headphone", "HPOL", 92 + "Headphone", "HPOR", 93 + "IN1P", "Headset Mic", 94 + "Speakers", "Speaker", 95 + "HDMI1", "TX"; 96 + 97 + hs-playback-dai-link { 98 + link-name = "I2S0"; 99 + dai-format = "i2s"; 100 + mediatek,clk-provider = "cpu"; 101 + codec { 102 + sound-dai = <&rt5682s 0>; 103 + }; 167 104 }; 168 105 169 - playback-codecs { 170 - sound-dai = <&it6505dptx>, 171 - <&rt1019p>; 106 + hs-capture-dai-link { 107 + link-name = "I2S1"; 108 + dai-format = "i2s"; 109 + mediatek,clk-provider = "cpu"; 110 + codec { 111 + sound-dai = <&rt5682s 0>; 112 + }; 113 + }; 114 + 115 + spk-hdmi-playback-dai-link { 116 + link-name = "I2S3"; 117 + dai-format = "i2s"; 118 + mediatek,clk-provider = "cpu"; 119 + codec { 120 + sound-dai = <&it6505dptx>, <&rt1019p>; 121 + }; 172 122 }; 173 123 }; 174 124
+129 -10
Documentation/devicetree/bindings/sound/mt8192-mt6359-rt1015-rt5682.yaml
··· 13 13 description: 14 14 This binding describes the MT8192 sound card. 15 15 16 + allOf: 17 + - $ref: sound-card-common.yaml# 18 + 16 19 properties: 17 20 compatible: 18 21 enum: 19 22 - mediatek,mt8192_mt6359_rt1015_rt5682 20 23 - mediatek,mt8192_mt6359_rt1015p_rt5682 21 24 - mediatek,mt8192_mt6359_rt1015p_rt5682s 25 + 26 + audio-routing: 27 + description: 28 + A list of the connections between audio components. Each entry is a 29 + pair of strings, the first being the connection's sink, the second 30 + being the connection's source. 31 + Valid names could be the input or output widgets of audio components, 32 + power supplies, MicBias of codec and the software switch. 33 + minItems: 2 34 + items: 35 + enum: 36 + # Sinks 37 + - Speakers 38 + - Headphone Jack 39 + - IN1P 40 + - Left Spk 41 + - Right Spk 42 + 43 + # Sources 44 + - Headset Mic 45 + - HPOL 46 + - HPOR 47 + - Left SPO 48 + - Right SPO 49 + - Speaker 22 50 23 51 mediatek,platform: 24 52 $ref: /schemas/types.yaml#/definitions/phandle ··· 55 27 mediatek,hdmi-codec: 56 28 $ref: /schemas/types.yaml#/definitions/phandle 57 29 description: The phandle of HDMI codec. 30 + deprecated: true 58 31 59 32 headset-codec: 60 33 type: object 61 34 additionalProperties: false 35 + deprecated: true 62 36 63 37 properties: 64 38 sound-dai: ··· 71 41 speaker-codecs: 72 42 type: object 73 43 additionalProperties: false 44 + deprecated: true 74 45 75 46 properties: 76 47 sound-dai: ··· 82 51 required: 83 52 - sound-dai 84 53 85 - additionalProperties: false 54 + patternProperties: 55 + ".*-dai-link$": 56 + type: object 57 + additionalProperties: false 58 + 59 + description: 60 + Container for dai-link level properties and CODEC sub-nodes. 61 + 62 + properties: 63 + link-name: 64 + description: Indicates dai-link name and PCM stream name 65 + enum: 66 + - I2S0 67 + - I2S1 68 + - I2S2 69 + - I2S3 70 + - I2S4 71 + - I2S5 72 + - I2S6 73 + - I2S7 74 + - I2S8 75 + - I2S9 76 + - TDM 77 + 78 + codec: 79 + description: Holds subnode which indicates codec dai. 80 + type: object 81 + additionalProperties: false 82 + properties: 83 + sound-dai: 84 + minItems: 1 85 + maxItems: 2 86 + required: 87 + - sound-dai 88 + 89 + dai-format: 90 + description: audio format 91 + enum: [ i2s, right_j, left_j, dsp_a, dsp_b ] 92 + 93 + mediatek,clk-provider: 94 + $ref: /schemas/types.yaml#/definitions/string 95 + description: Indicates dai-link clock master. 96 + enum: [ cpu, codec ] 97 + 98 + required: 99 + - link-name 100 + 101 + unevaluatedProperties: false 86 102 87 103 required: 88 104 - compatible 89 105 - mediatek,platform 90 - - headset-codec 91 - - speaker-codecs 106 + 107 + # Disallow legacy properties if xxx-dai-link nodes are specified 108 + if: 109 + not: 110 + patternProperties: 111 + ".*-dai-link$": false 112 + then: 113 + properties: 114 + headset-codec: false 115 + speaker-codecs: false 116 + mediatek,hdmi-codec: false 92 117 93 118 examples: 94 119 - | 95 120 96 121 sound: mt8192-sound { 97 122 compatible = "mediatek,mt8192_mt6359_rt1015_rt5682"; 98 - mediatek,platform = <&afe>; 99 - mediatek,hdmi-codec = <&anx_bridge_dp>; 123 + model = "mt8192_mt6359_rt1015_rt5682"; 100 124 pinctrl-names = "aud_clk_mosi_off", 101 125 "aud_clk_mosi_on"; 102 126 pinctrl-0 = <&aud_clk_mosi_off>; 103 127 pinctrl-1 = <&aud_clk_mosi_on>; 128 + mediatek,platform = <&afe>; 104 129 105 - headset-codec { 106 - sound-dai = <&rt5682>; 130 + audio-routing = 131 + "Headphone Jack", "HPOL", 132 + "Headphone Jack", "HPOR", 133 + "IN1P", "Headset Mic", 134 + "Speakers", "Speaker"; 135 + 136 + spk-playback-dai-link { 137 + link-name = "I2S3"; 138 + dai-format = "i2s"; 139 + mediatek,clk-provider = "cpu"; 140 + codec { 141 + sound-dai = <&rt1015p>; 142 + }; 107 143 }; 108 144 109 - speaker-codecs { 110 - sound-dai = <&rt1015_l>, 111 - <&rt1015_r>; 145 + hs-playback-dai-link { 146 + link-name = "I2S8"; 147 + dai-format = "i2s"; 148 + mediatek,clk-provider = "cpu"; 149 + codec { 150 + sound-dai = <&rt5682 0>; 151 + }; 152 + }; 153 + 154 + hs-capture-dai-link { 155 + link-name = "I2S9"; 156 + dai-format = "i2s"; 157 + mediatek,clk-provider = "cpu"; 158 + codec { 159 + sound-dai = <&rt5682 0>; 160 + }; 161 + }; 162 + 163 + displayport-dai-link { 164 + link-name = "TDM"; 165 + dai-format = "dsp_a"; 166 + codec { 167 + sound-dai = <&anx_bridge_dp>; 168 + }; 112 169 }; 113 170 }; 114 171
+134
Documentation/devicetree/bindings/sound/mt8195-mt6359.yaml
··· 12 12 description: 13 13 This binding describes the MT8195 sound card. 14 14 15 + allOf: 16 + - $ref: sound-card-common.yaml# 17 + 15 18 properties: 16 19 compatible: 17 20 enum: ··· 26 23 $ref: /schemas/types.yaml#/definitions/string 27 24 description: User specified audio sound card name 28 25 26 + audio-routing: 27 + description: 28 + A list of the connections between audio components. Each entry is a 29 + pair of strings, the first being the connection's sink, the second 30 + being the connection's source. 31 + Valid names could be the input or output widgets of audio components, 32 + power supplies, MicBias of codec and the software switch. 33 + minItems: 2 34 + items: 35 + enum: 36 + # Sinks 37 + - Ext Spk 38 + - Headphone 39 + - IN1P 40 + - Left Spk 41 + - Right Spk 42 + 43 + # Sources 44 + - Headset Mic 45 + - HPOL 46 + - HPOR 47 + - Left BE_OUT 48 + - Left SPO 49 + - Right BE_OUT 50 + - Right SPO 51 + - Speaker 52 + 29 53 mediatek,platform: 30 54 $ref: /schemas/types.yaml#/definitions/phandle 31 55 description: The phandle of MT8195 ASoC platform. ··· 60 30 mediatek,dptx-codec: 61 31 $ref: /schemas/types.yaml#/definitions/phandle 62 32 description: The phandle of MT8195 Display Port Tx codec node. 33 + deprecated: true 63 34 64 35 mediatek,hdmi-codec: 65 36 $ref: /schemas/types.yaml#/definitions/phandle 66 37 description: The phandle of MT8195 HDMI codec node. 38 + deprecated: true 67 39 68 40 mediatek,adsp: 69 41 $ref: /schemas/types.yaml#/definitions/phandle ··· 77 45 A list of the desired dai-links in the sound card. Each entry is a 78 46 name defined in the machine driver. 79 47 48 + patternProperties: 49 + ".*-dai-link$": 50 + type: object 51 + additionalProperties: false 52 + description: 53 + Container for dai-link level properties and CODEC sub-nodes. 54 + 55 + properties: 56 + link-name: 57 + description: Indicates dai-link name and PCM stream name 58 + enum: 59 + - DPTX_BE 60 + - ETDM1_IN_BE 61 + - ETDM2_IN_BE 62 + - ETDM1_OUT_BE 63 + - ETDM2_OUT_BE 64 + - ETDM3_OUT_BE 65 + - PCM1_BE 66 + 67 + codec: 68 + description: Holds subnode which indicates codec dai. 69 + type: object 70 + additionalProperties: false 71 + properties: 72 + sound-dai: 73 + minItems: 1 74 + maxItems: 2 75 + required: 76 + - sound-dai 77 + 78 + dai-format: 79 + description: audio format 80 + enum: [ i2s, right_j, left_j, dsp_a, dsp_b ] 81 + 82 + mediatek,clk-provider: 83 + $ref: /schemas/types.yaml#/definitions/string 84 + description: Indicates dai-link clock master. 85 + enum: [ cpu, codec ] 86 + 87 + required: 88 + - link-name 89 + 80 90 additionalProperties: false 81 91 82 92 required: 83 93 - compatible 84 94 - mediatek,platform 85 95 96 + # Disallow legacy properties if xxx-dai-link nodes are specified 97 + if: 98 + not: 99 + patternProperties: 100 + ".*-dai-link$": false 101 + then: 102 + properties: 103 + mediatek,dptx-codec: false 104 + mediatek,hdmi-codec: false 105 + 86 106 examples: 87 107 - | 88 108 89 109 sound: mt8195-sound { 90 110 compatible = "mediatek,mt8195_mt6359_rt1019_rt5682"; 111 + model = "mt8195_r1019_5682"; 91 112 mediatek,platform = <&afe>; 92 113 pinctrl-names = "default"; 93 114 pinctrl-0 = <&aud_pins_default>; 115 + 116 + audio-routing = 117 + "Headphone", "HPOL", 118 + "Headphone", "HPOR", 119 + "IN1P", "Headset Mic", 120 + "Ext Spk", "Speaker"; 121 + 122 + mm-dai-link { 123 + link-name = "ETDM1_IN_BE"; 124 + mediatek,clk-provider = "cpu"; 125 + }; 126 + 127 + hs-playback-dai-link { 128 + link-name = "ETDM1_OUT_BE"; 129 + mediatek,clk-provider = "cpu"; 130 + codec { 131 + sound-dai = <&headset_codec>; 132 + }; 133 + }; 134 + 135 + hs-capture-dai-link { 136 + link-name = "ETDM2_IN_BE"; 137 + mediatek,clk-provider = "cpu"; 138 + codec { 139 + sound-dai = <&headset_codec>; 140 + }; 141 + }; 142 + 143 + spk-playback-dai-link { 144 + link-name = "ETDM2_OUT_BE"; 145 + mediatek,clk-provider = "cpu"; 146 + codec { 147 + sound-dai = <&spk_amplifier>; 148 + }; 149 + }; 150 + 151 + hdmi-dai-link { 152 + link-name = "ETDM3_OUT_BE"; 153 + codec { 154 + sound-dai = <&hdmi_tx>; 155 + }; 156 + }; 157 + 158 + displayport-dai-link { 159 + link-name = "DPTX_BE"; 160 + codec { 161 + sound-dai = <&dp_tx>; 162 + }; 163 + }; 94 164 }; 95 165 96 166 ...
+4 -20
sound/soc/mediatek/Kconfig
··· 185 185 Select Y if you have such device. 186 186 If unsure select "N". 187 187 188 - config SND_SOC_MT8186_MT6366_DA7219_MAX98357 189 - tristate "ASoC Audio driver for MT8186 with DA7219 MAX98357A codec" 188 + config SND_SOC_MT8186_MT6366 189 + tristate "ASoC Audio driver for MT8186 with MT6366 and I2S codecs" 190 190 depends on I2C && GPIOLIB 191 191 depends on SND_SOC_MT8186 && MTK_PMIC_WRAP 192 - select SND_SOC_MT6358 193 - select SND_SOC_MAX98357A 194 192 select SND_SOC_DA7219 195 - select SND_SOC_BT_SCO 196 - select SND_SOC_DMIC 197 - select SND_SOC_HDMI_CODEC 198 - help 199 - This adds ASoC driver for Mediatek MT8186 boards 200 - with the MT6366(MT6358) DA7219 MAX98357A codecs. 201 - Select Y if you have such device. 202 - If unsure select "N". 203 - 204 - config SND_SOC_MT8186_MT6366_RT1019_RT5682S 205 - tristate "ASoC Audio driver for MT8186 with RT1019 RT5682S MAX98357A/MAX98360 codec" 206 - depends on I2C && GPIOLIB 207 - depends on SND_SOC_MT8186 && MTK_PMIC_WRAP 208 - select SND_SOC_MAX98357A 209 193 select SND_SOC_MT6358 210 194 select SND_SOC_MAX98357A 211 195 select SND_SOC_RT1015P ··· 199 215 select SND_SOC_DMIC 200 216 select SND_SOC_HDMI_CODEC 201 217 help 202 - This adds ASoC driver for Mediatek MT8186 boards 203 - with the MT6366(MT6358) RT1019 RT5682S codecs. 218 + This adds the ASoC machine driver for Mediatek MT8186 boards 219 + with the MT6366(MT6358) and other I2S audio codecs. 204 220 Select Y if you have such device. 205 221 If unsure select "N". 206 222
+18
sound/soc/mediatek/common/mtk-afe-platform-driver.c
··· 126 126 } 127 127 EXPORT_SYMBOL_GPL(mtk_afe_pcm_new); 128 128 129 + static int mtk_afe_component_probe(struct snd_soc_component *component) 130 + { 131 + struct mtk_base_afe *afe = snd_soc_component_get_drvdata(component); 132 + int ret; 133 + 134 + snd_soc_component_init_regmap(component, afe->regmap); 135 + 136 + /* If the list was never initialized there are no sub-DAIs */ 137 + if (afe->sub_dais.next && afe->sub_dais.prev) { 138 + ret = mtk_afe_add_sub_dai_control(component); 139 + if (ret) 140 + return ret; 141 + } 142 + 143 + return 0; 144 + } 145 + 129 146 const struct snd_soc_component_driver mtk_afe_pcm_platform = { 130 147 .name = AFE_PCM_NAME, 131 148 .pointer = mtk_afe_pcm_pointer, 132 149 .pcm_construct = mtk_afe_pcm_new, 150 + .probe = mtk_afe_component_probe, 133 151 }; 134 152 EXPORT_SYMBOL_GPL(mtk_afe_pcm_platform); 135 153
+7 -8
sound/soc/mediatek/common/mtk-dsp-sof-common.c
··· 15 15 { 16 16 struct snd_soc_card *card = rtd->card; 17 17 struct mtk_soc_card_data *soc_card_data = snd_soc_card_get_drvdata(card); 18 - struct mtk_sof_priv *sof_priv = soc_card_data->sof_priv; 18 + const struct mtk_sof_priv *sof_priv = soc_card_data->sof_priv; 19 19 int i, j, ret = 0; 20 20 21 21 for (i = 0; i < sof_priv->num_streams; i++) { ··· 55 55 int i; 56 56 struct snd_soc_dai_link *dai_link; 57 57 struct mtk_soc_card_data *soc_card_data = snd_soc_card_get_drvdata(card); 58 - struct mtk_sof_priv *sof_priv = soc_card_data->sof_priv; 59 58 60 59 /* Set stream_name to help sof bind widgets */ 61 60 for_each_card_prelinks(card, i, dai_link) { ··· 62 63 dai_link->stream_name = dai_link->name; 63 64 } 64 65 65 - INIT_LIST_HEAD(&sof_priv->dai_link_list); 66 + INIT_LIST_HEAD(&soc_card_data->sof_dai_link_list); 66 67 67 68 return 0; 68 69 } ··· 72 73 { 73 74 struct snd_soc_card *card = rtd->card; 74 75 struct mtk_soc_card_data *soc_card_data = snd_soc_card_get_drvdata(card); 75 - struct mtk_sof_priv *sof_priv = soc_card_data->sof_priv; 76 + const struct mtk_sof_priv *sof_priv = soc_card_data->sof_priv; 76 77 struct snd_soc_pcm_runtime *fe; 77 78 struct snd_soc_pcm_runtime *be; 78 79 struct snd_soc_dpcm *dpcm; ··· 112 113 { 113 114 struct snd_soc_card *card = rtd->card; 114 115 struct mtk_soc_card_data *soc_card_data = snd_soc_card_get_drvdata(card); 115 - struct mtk_sof_priv *sof_priv = soc_card_data->sof_priv; 116 + const struct mtk_sof_priv *sof_priv = soc_card_data->sof_priv; 116 117 struct snd_soc_pcm_runtime *sof_be; 117 118 struct mtk_dai_link *dai_link; 118 119 int ret = 0; ··· 124 125 else if (sof_be->dai_link->be_hw_params_fixup) 125 126 ret = sof_be->dai_link->be_hw_params_fixup(sof_be, params); 126 127 } else { 127 - list_for_each_entry(dai_link, &sof_priv->dai_link_list, list) { 128 + list_for_each_entry(dai_link, &soc_card_data->sof_dai_link_list, list) { 128 129 if (strcmp(dai_link->name, rtd->dai_link->name) == 0) { 129 130 if (dai_link->be_hw_params_fixup) 130 131 ret = dai_link->be_hw_params_fixup(rtd, params); ··· 143 144 struct snd_soc_component *sof_comp = NULL; 144 145 struct mtk_soc_card_data *soc_card_data = 145 146 snd_soc_card_get_drvdata(card); 146 - struct mtk_sof_priv *sof_priv = soc_card_data->sof_priv; 147 + const struct mtk_sof_priv *sof_priv = soc_card_data->sof_priv; 147 148 struct snd_soc_dai_link *dai_link; 148 149 struct mtk_dai_link *mtk_dai_link; 149 150 int i; ··· 172 173 mtk_dai_link->be_hw_params_fixup = dai_link->be_hw_params_fixup; 173 174 mtk_dai_link->name = dai_link->name; 174 175 175 - list_add(&mtk_dai_link->list, &sof_priv->dai_link_list); 176 + list_add(&mtk_dai_link->list, &soc_card_data->sof_dai_link_list); 176 177 } 177 178 178 179 if (dai_link->no_pcm)
-1
sound/soc/mediatek/common/mtk-dsp-sof-common.h
··· 30 30 int num_streams; 31 31 int (*sof_dai_link_fixup)(struct snd_soc_pcm_runtime *rtd, 32 32 struct snd_pcm_hw_params *params); 33 - struct list_head dai_link_list; 34 33 }; 35 34 36 35 int mtk_sof_dai_link_fixup(struct snd_soc_pcm_runtime *rtd,
+6 -1
sound/soc/mediatek/common/mtk-soc-card.h
··· 9 9 #ifndef _MTK_SOC_CARD_H_ 10 10 #define _MTK_SOC_CARD_H_ 11 11 12 + struct mtk_platform_card_data; 13 + struct mtk_sof_priv; 14 + 12 15 struct mtk_soc_card_data { 16 + const struct mtk_sof_priv *sof_priv; 17 + struct list_head sof_dai_link_list; 18 + struct mtk_platform_card_data *card_data; 13 19 void *mach_priv; 14 - void *sof_priv; 15 20 }; 16 21 17 22 #endif
+199
sound/soc/mediatek/common/mtk-soundcard-driver.c
··· 10 10 #include <linux/of.h> 11 11 #include <sound/soc.h> 12 12 13 + #include "mtk-dsp-sof-common.h" 14 + #include "mtk-soc-card.h" 13 15 #include "mtk-soundcard-driver.h" 14 16 15 17 static int set_card_codec_info(struct snd_soc_card *card, ··· 138 136 snd_soc_of_put_dai_link_codecs(dai_link); 139 137 } 140 138 EXPORT_SYMBOL_GPL(clean_card_reference); 139 + 140 + int mtk_soundcard_startup(struct snd_pcm_substream *substream, 141 + enum mtk_pcm_constraint_type ctype) 142 + { 143 + struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream); 144 + struct mtk_soc_card_data *soc_card = snd_soc_card_get_drvdata(rtd->card); 145 + const struct mtk_pcm_constraints_data *mpc = &soc_card->card_data->pcm_constraints[ctype]; 146 + int ret; 147 + 148 + if (unlikely(!mpc)) 149 + return -EINVAL; 150 + 151 + ret = snd_pcm_hw_constraint_list(substream->runtime, 0, 152 + SNDRV_PCM_HW_PARAM_RATE, 153 + mpc->rates); 154 + if (ret < 0) { 155 + dev_err(rtd->dev, "hw_constraint_list rate failed\n"); 156 + return ret; 157 + } 158 + 159 + ret = snd_pcm_hw_constraint_list(substream->runtime, 0, 160 + SNDRV_PCM_HW_PARAM_CHANNELS, 161 + mpc->channels); 162 + if (ret < 0) { 163 + dev_err(rtd->dev, "hw_constraint_list channel failed\n"); 164 + return ret; 165 + } 166 + 167 + return 0; 168 + } 169 + EXPORT_SYMBOL_GPL(mtk_soundcard_startup); 170 + 171 + static int mtk_soundcard_playback_startup(struct snd_pcm_substream *substream) 172 + { 173 + return mtk_soundcard_startup(substream, MTK_CONSTRAINT_PLAYBACK); 174 + } 175 + 176 + const struct snd_soc_ops mtk_soundcard_common_playback_ops = { 177 + .startup = mtk_soundcard_playback_startup, 178 + }; 179 + EXPORT_SYMBOL_GPL(mtk_soundcard_common_playback_ops); 180 + 181 + static int mtk_soundcard_capture_startup(struct snd_pcm_substream *substream) 182 + { 183 + return mtk_soundcard_startup(substream, MTK_CONSTRAINT_CAPTURE); 184 + } 185 + 186 + const struct snd_soc_ops mtk_soundcard_common_capture_ops = { 187 + .startup = mtk_soundcard_capture_startup, 188 + }; 189 + EXPORT_SYMBOL_GPL(mtk_soundcard_common_capture_ops); 190 + 191 + int mtk_soundcard_common_probe(struct platform_device *pdev) 192 + { 193 + struct device_node *platform_node, *adsp_node; 194 + const struct mtk_soundcard_pdata *pdata; 195 + struct mtk_soc_card_data *soc_card_data; 196 + struct snd_soc_dai_link *orig_dai_link, *dai_link; 197 + struct snd_soc_jack *jacks; 198 + struct snd_soc_card *card; 199 + int i, orig_num_links, ret; 200 + bool needs_legacy_probe; 201 + 202 + pdata = device_get_match_data(&pdev->dev); 203 + if (!pdata) 204 + return -EINVAL; 205 + 206 + card = pdata->card_data->card; 207 + card->dev = &pdev->dev; 208 + orig_dai_link = card->dai_link; 209 + orig_num_links = card->num_links; 210 + 211 + ret = snd_soc_of_parse_card_name(card, "model"); 212 + if (ret) 213 + return ret; 214 + 215 + if (!card->name) { 216 + if (!pdata->card_name) 217 + return -EINVAL; 218 + 219 + card->name = pdata->card_name; 220 + } 221 + 222 + needs_legacy_probe = !of_property_read_bool(pdev->dev.of_node, "audio-routing"); 223 + if (needs_legacy_probe) { 224 + /* 225 + * If we have no .soc_probe() callback there's no way of using 226 + * any legacy probe mechanism, as that cannot not be generic. 227 + */ 228 + if (!pdata->soc_probe) 229 + return -EINVAL; 230 + 231 + dev_info_once(&pdev->dev, "audio-routing not found: using legacy probe\n"); 232 + } else { 233 + ret = snd_soc_of_parse_audio_routing(card, "audio-routing"); 234 + if (ret) 235 + return ret; 236 + } 237 + 238 + soc_card_data = devm_kzalloc(&pdev->dev, sizeof(*soc_card_data), GFP_KERNEL); 239 + if (!soc_card_data) 240 + return -ENOMEM; 241 + 242 + soc_card_data->card_data = pdata->card_data; 243 + 244 + jacks = devm_kcalloc(card->dev, soc_card_data->card_data->num_jacks, 245 + sizeof(*jacks), GFP_KERNEL); 246 + if (!jacks) 247 + return -ENOMEM; 248 + 249 + soc_card_data->card_data->jacks = jacks; 250 + 251 + platform_node = of_parse_phandle(pdev->dev.of_node, "mediatek,platform", 0); 252 + if (!platform_node) 253 + return dev_err_probe(&pdev->dev, -EINVAL, 254 + "Property mediatek,platform missing or invalid\n"); 255 + 256 + /* Check if this SoC has an Audio DSP */ 257 + if (pdata->sof_priv) 258 + adsp_node = of_parse_phandle(pdev->dev.of_node, "mediatek,adsp", 0); 259 + else 260 + adsp_node = NULL; 261 + 262 + if (adsp_node) { 263 + if (of_property_read_bool(pdev->dev.of_node, "mediatek,dai-link")) { 264 + ret = mtk_sof_dailink_parse_of(card, pdev->dev.of_node, 265 + "mediatek,dai-link", 266 + card->dai_link, card->num_links); 267 + if (ret) { 268 + of_node_put(adsp_node); 269 + of_node_put(platform_node); 270 + return dev_err_probe(&pdev->dev, ret, 271 + "Cannot parse mediatek,dai-link\n"); 272 + } 273 + } 274 + 275 + soc_card_data->sof_priv = pdata->sof_priv; 276 + card->probe = mtk_sof_card_probe; 277 + card->late_probe = mtk_sof_card_late_probe; 278 + if (!card->topology_shortname_created) { 279 + snprintf(card->topology_shortname, 32, "sof-%s", card->name); 280 + card->topology_shortname_created = true; 281 + } 282 + card->name = card->topology_shortname; 283 + } 284 + 285 + /* 286 + * Regardless of whether the ADSP is wanted and/or present in a machine 287 + * specific device tree or not and regardless of whether any AFE_SOF 288 + * link is present, we have to make sure that the platforms->of_node 289 + * is not NULL, and set to either ADSP (adsp_node) or AFE (platform_node). 290 + */ 291 + for_each_card_prelinks(card, i, dai_link) { 292 + if (adsp_node && !strncmp(dai_link->name, "AFE_SOF", strlen("AFE_SOF"))) 293 + dai_link->platforms->of_node = adsp_node; 294 + else if (!dai_link->platforms->name && !dai_link->platforms->of_node) 295 + dai_link->platforms->of_node = platform_node; 296 + } 297 + 298 + if (!needs_legacy_probe) { 299 + ret = parse_dai_link_info(card); 300 + if (ret) 301 + goto err_restore_dais; 302 + } else { 303 + if (adsp_node) 304 + of_node_put(adsp_node); 305 + of_node_put(platform_node); 306 + } 307 + 308 + if (pdata->soc_probe) { 309 + ret = pdata->soc_probe(soc_card_data, needs_legacy_probe); 310 + if (ret) { 311 + if (!needs_legacy_probe) 312 + clean_card_reference(card); 313 + goto err_restore_dais; 314 + } 315 + } 316 + snd_soc_card_set_drvdata(card, soc_card_data); 317 + 318 + ret = devm_snd_soc_register_card(&pdev->dev, card); 319 + 320 + if (!needs_legacy_probe) 321 + clean_card_reference(card); 322 + 323 + if (ret) { 324 + dev_err_probe(&pdev->dev, ret, "Cannot register card\n"); 325 + goto err_restore_dais; 326 + } 327 + 328 + return 0; 329 + 330 + err_restore_dais: 331 + card->dai_link = orig_dai_link; 332 + card->num_links = orig_num_links; 333 + return ret; 334 + } 335 + EXPORT_SYMBOL_GPL(mtk_soundcard_common_probe);
+42
sound/soc/mediatek/common/mtk-soundcard-driver.h
··· 9 9 #ifndef _MTK_SOUNDCARD_DRIVER_H_ 10 10 #define _MTK_SOUNDCARD_DRIVER_H_ 11 11 12 + struct mtk_sof_priv; 13 + struct mtk_soc_card_data; 14 + struct snd_pcm_hw_constraint_list; 15 + 16 + enum mtk_pcm_constraint_type { 17 + MTK_CONSTRAINT_PLAYBACK, 18 + MTK_CONSTRAINT_CAPTURE, 19 + MTK_CONSTRAINT_HDMIDP, 20 + MTK_CONSTRAINT_MAX 21 + }; 22 + 23 + struct mtk_pcm_constraints_data { 24 + const struct snd_pcm_hw_constraint_list *channels; 25 + const struct snd_pcm_hw_constraint_list *rates; 26 + }; 27 + 28 + struct mtk_platform_card_data { 29 + struct snd_soc_card *card; 30 + struct snd_soc_jack *jacks; 31 + const struct mtk_pcm_constraints_data *pcm_constraints; 32 + u8 num_jacks; 33 + u8 num_pcm_constraints; 34 + u8 flags; 35 + }; 36 + 37 + struct mtk_soundcard_pdata { 38 + const char *card_name; 39 + struct mtk_platform_card_data *card_data; 40 + const struct mtk_sof_priv *sof_priv; 41 + 42 + int (*soc_probe)(struct mtk_soc_card_data *card_data, bool legacy); 43 + }; 44 + 45 + /* Common playback/capture card startup ops */ 46 + extern const struct snd_soc_ops mtk_soundcard_common_playback_ops; 47 + extern const struct snd_soc_ops mtk_soundcard_common_capture_ops; 48 + 49 + /* Exported for custom/extended soundcard startup ops */ 50 + int mtk_soundcard_startup(struct snd_pcm_substream *substream, 51 + enum mtk_pcm_constraint_type ctype); 52 + 12 53 int parse_dai_link_info(struct snd_soc_card *card); 13 54 void clean_card_reference(struct snd_soc_card *card); 55 + int mtk_soundcard_common_probe(struct platform_device *pdev); 14 56 #endif
+1 -13
sound/soc/mediatek/mt6797/mt6797-afe-pcm.c
··· 704 704 return 0; 705 705 } 706 706 707 - static int mt6797_afe_component_probe(struct snd_soc_component *component) 708 - { 709 - return mtk_afe_add_sub_dai_control(component); 710 - } 711 - 712 - static const struct snd_soc_component_driver mt6797_afe_component = { 713 - .name = AFE_PCM_NAME, 714 - .probe = mt6797_afe_component_probe, 715 - .pointer = mtk_afe_pcm_pointer, 716 - .pcm_construct = mtk_afe_pcm_new, 717 - }; 718 - 719 707 static int mt6797_dai_memif_register(struct mtk_base_afe *afe) 720 708 { 721 709 struct mtk_base_afe_dai *dai; ··· 840 852 pm_runtime_get_sync(&pdev->dev); 841 853 842 854 /* register component */ 843 - ret = devm_snd_soc_register_component(dev, &mt6797_afe_component, 855 + ret = devm_snd_soc_register_component(dev, &mtk_afe_pcm_platform, 844 856 NULL, 0); 845 857 if (ret) { 846 858 dev_warn(dev, "err_platform\n");
+1 -13
sound/soc/mediatek/mt7986/mt7986-afe-pcm.c
··· 429 429 return 0; 430 430 } 431 431 432 - static int mt7986_afe_component_probe(struct snd_soc_component *component) 433 - { 434 - return mtk_afe_add_sub_dai_control(component); 435 - } 436 - 437 - static const struct snd_soc_component_driver mt7986_afe_component = { 438 - .name = AFE_PCM_NAME, 439 - .probe = mt7986_afe_component_probe, 440 - .pointer = mtk_afe_pcm_pointer, 441 - .pcm_construct = mtk_afe_pcm_new, 442 - }; 443 - 444 432 static int mt7986_dai_memif_register(struct mtk_base_afe *afe) 445 433 { 446 434 struct mtk_base_afe_dai *dai; ··· 561 573 562 574 /* register component */ 563 575 ret = devm_snd_soc_register_component(&pdev->dev, 564 - &mt7986_afe_component, 576 + &mtk_afe_pcm_platform, 565 577 NULL, 0); 566 578 if (ret) 567 579 return dev_err_probe(dev, ret, "Cannot register AFE component\n");
+1 -13
sound/soc/mediatek/mt8183/mt8183-afe-pcm.c
··· 1042 1042 return 0; 1043 1043 } 1044 1044 1045 - static int mt8183_afe_component_probe(struct snd_soc_component *component) 1046 - { 1047 - return mtk_afe_add_sub_dai_control(component); 1048 - } 1049 - 1050 - static const struct snd_soc_component_driver mt8183_afe_component = { 1051 - .name = AFE_PCM_NAME, 1052 - .probe = mt8183_afe_component_probe, 1053 - .pointer = mtk_afe_pcm_pointer, 1054 - .pcm_construct = mtk_afe_pcm_new, 1055 - }; 1056 - 1057 1045 static int mt8183_dai_memif_register(struct mtk_base_afe *afe) 1058 1046 { 1059 1047 struct mtk_base_afe_dai *dai; ··· 1220 1232 1221 1233 /* register component */ 1222 1234 ret = devm_snd_soc_register_component(&pdev->dev, 1223 - &mt8183_afe_component, 1235 + &mtk_afe_pcm_platform, 1224 1236 NULL, 0); 1225 1237 if (ret) { 1226 1238 dev_warn(dev, "err_platform\n");
+1 -2
sound/soc/mediatek/mt8186/Makefile
··· 18 18 mt8186-mt6366-common.o 19 19 20 20 obj-$(CONFIG_SND_SOC_MT8186) += snd-soc-mt8186-afe.o 21 - obj-$(CONFIG_SND_SOC_MT8186_MT6366_DA7219_MAX98357) += mt8186-mt6366-da7219-max98357.o 22 - obj-$(CONFIG_SND_SOC_MT8186_MT6366_RT1019_RT5682S) += mt8186-mt6366-rt1019-rt5682s.o 21 + obj-$(CONFIG_SND_SOC_MT8186_MT6366) += mt8186-mt6366.o
+524 -315
sound/soc/mediatek/mt8186/mt8186-mt6366-da7219-max98357.c sound/soc/mediatek/mt8186/mt8186-mt6366.c
··· 1 1 // SPDX-License-Identifier: GPL-2.0 2 2 // 3 - // mt8186-mt6366-da7219-max98357.c 4 - // -- MT8186-MT6366-DA7219-MAX98357 ALSA SoC machine driver 3 + // mt8186-mt6366.c 4 + // -- MT8186-MT6366 ALSA SoC machine driver 5 5 // 6 6 // Copyright (c) 2022 MediaTek Inc. 7 7 // Author: Jiaxin Yu <jiaxin.yu@mediatek.com> 8 8 // 9 + // Copyright (c) 2024 Collabora Ltd. 10 + // AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com> 11 + // 9 12 13 + #include <linux/gpio/consumer.h> 10 14 #include <linux/input.h> 11 15 #include <linux/module.h> 12 16 #include <linux/of.h> 13 17 #include <sound/jack.h> 14 18 #include <sound/pcm_params.h> 19 + #include <sound/rt5682.h> 15 20 #include <sound/soc.h> 16 21 17 22 #include "../../codecs/da7219.h" 18 23 #include "../../codecs/mt6358.h" 24 + #include "../../codecs/rt5682.h" 19 25 #include "../common/mtk-afe-platform-driver.h" 20 26 #include "../common/mtk-dsp-sof-common.h" 21 27 #include "../common/mtk-soc-card.h" 28 + #include "../common/mtk-soundcard-driver.h" 22 29 #include "mt8186-afe-common.h" 23 30 #include "mt8186-afe-clk.h" 24 31 #include "mt8186-afe-gpio.h" 25 32 #include "mt8186-mt6366-common.h" 26 33 27 - #define DA7219_CODEC_DAI "da7219-hifi" 28 - #define DA7219_DEV_NAME "da7219.5-001a" 34 + #define RT1019_CODEC_DAI "HiFi" 35 + #define RT1019_DEV0_NAME "rt1019p" 36 + 37 + #define RT5682S_CODEC_DAI "rt5682s-aif1" 38 + #define RT5682S_DEV0_NAME "rt5682s.5-001a" 39 + 40 + #define DA7219_CODEC_DAI "da7219-hifi" 41 + #define DA7219_DEV_NAME "da7219.5-001a" 29 42 30 43 #define SOF_DMA_DL1 "SOF_DMA_DL1" 31 44 #define SOF_DMA_DL2 "SOF_DMA_DL2" 32 45 #define SOF_DMA_UL1 "SOF_DMA_UL1" 33 46 #define SOF_DMA_UL2 "SOF_DMA_UL2" 34 47 35 - struct mt8186_mt6366_da7219_max98357_priv { 36 - struct snd_soc_jack headset_jack, hdmi_jack; 48 + #define DA7219_CODEC_PRESENT BIT(0) 49 + 50 + struct mt8186_mt6366_rt1019_rt5682s_priv { 51 + struct gpio_desc *dmic_sel; 52 + int dmic_switch; 53 + }; 54 + 55 + enum mt8186_jacks { 56 + MT8186_JACK_HEADSET, 57 + MT8186_JACK_HDMI, 58 + MT8186_JACK_MAX, 37 59 }; 38 60 39 61 /* Headset jack detection DAPM pins */ 40 62 static struct snd_soc_jack_pin mt8186_jack_pins[] = { 41 63 { 42 - .pin = "Headphones", 64 + .pin = "Headphone", 43 65 .mask = SND_JACK_HEADPHONE, 44 66 }, 45 67 { 46 68 .pin = "Headset Mic", 47 69 .mask = SND_JACK_MICROPHONE, 48 70 }, 49 - { 50 - .pin = "Line Out", 51 - .mask = SND_JACK_LINEOUT, 52 - }, 53 71 }; 54 72 55 - static struct snd_soc_codec_conf mt8186_mt6366_da7219_max98357_codec_conf[] = { 73 + static struct snd_soc_codec_conf mt8186_mt6366_rt1019_rt5682s_codec_conf[] = { 56 74 { 57 75 .dlc = COMP_CODEC_CONF("mt6358-sound"), 58 76 .name_prefix = "Mt6366", ··· 85 67 }, 86 68 }; 87 69 88 - static int mt8186_da7219_init(struct snd_soc_pcm_runtime *rtd) 70 + static int dmic_get(struct snd_kcontrol *kcontrol, 71 + struct snd_ctl_elem_value *ucontrol) 72 + { 73 + struct snd_soc_dapm_context *dapm = snd_soc_dapm_kcontrol_dapm(kcontrol); 74 + struct mtk_soc_card_data *soc_card_data = 75 + snd_soc_card_get_drvdata(dapm->card); 76 + struct mt8186_mt6366_rt1019_rt5682s_priv *priv = soc_card_data->mach_priv; 77 + 78 + ucontrol->value.integer.value[0] = priv->dmic_switch; 79 + return 0; 80 + } 81 + 82 + static int dmic_set(struct snd_kcontrol *kcontrol, 83 + struct snd_ctl_elem_value *ucontrol) 84 + { 85 + struct snd_soc_dapm_context *dapm = snd_soc_dapm_kcontrol_dapm(kcontrol); 86 + struct mtk_soc_card_data *soc_card_data = 87 + snd_soc_card_get_drvdata(dapm->card); 88 + struct mt8186_mt6366_rt1019_rt5682s_priv *priv = soc_card_data->mach_priv; 89 + 90 + priv->dmic_switch = ucontrol->value.integer.value[0]; 91 + if (priv->dmic_sel) { 92 + gpiod_set_value(priv->dmic_sel, priv->dmic_switch); 93 + dev_dbg(dapm->card->dev, "dmic_set_value %d\n", 94 + priv->dmic_switch); 95 + } 96 + return 0; 97 + } 98 + 99 + static const char * const dmic_mux_text[] = { 100 + "Front Mic", 101 + "Rear Mic", 102 + }; 103 + 104 + static SOC_ENUM_SINGLE_DECL(mt8186_dmic_enum, 105 + SND_SOC_NOPM, 0, dmic_mux_text); 106 + 107 + static const struct snd_kcontrol_new mt8186_dmic_mux_control = 108 + SOC_DAPM_ENUM_EXT("DMIC Select Mux", mt8186_dmic_enum, 109 + dmic_get, dmic_set); 110 + 111 + static const struct snd_soc_dapm_widget dmic_widgets[] = { 112 + SND_SOC_DAPM_MIC("DMIC", NULL), 113 + SND_SOC_DAPM_MUX("Dmic Mux", SND_SOC_NOPM, 0, 0, &mt8186_dmic_mux_control), 114 + }; 115 + 116 + static const struct snd_soc_dapm_route dmic_map[] = { 117 + /* digital mics */ 118 + {"Dmic Mux", "Front Mic", "DMIC"}, 119 + {"Dmic Mux", "Rear Mic", "DMIC"}, 120 + }; 121 + 122 + static int primary_codec_init(struct snd_soc_pcm_runtime *rtd) 123 + { 124 + struct snd_soc_card *card = rtd->card; 125 + struct mtk_soc_card_data *soc_card_data = snd_soc_card_get_drvdata(card); 126 + struct mt8186_mt6366_rt1019_rt5682s_priv *priv = soc_card_data->mach_priv; 127 + int ret; 128 + 129 + ret = mt8186_mt6366_init(rtd); 130 + 131 + if (ret) { 132 + dev_err(card->dev, "mt8186_mt6366_init failed: %d\n", ret); 133 + return ret; 134 + } 135 + 136 + if (!priv->dmic_sel) { 137 + dev_dbg(card->dev, "dmic_sel is null\n"); 138 + return 0; 139 + } 140 + 141 + ret = snd_soc_dapm_new_controls(&card->dapm, dmic_widgets, 142 + ARRAY_SIZE(dmic_widgets)); 143 + if (ret) { 144 + dev_err(card->dev, "DMic widget addition failed: %d\n", ret); 145 + /* Don't need to add routes if widget addition failed */ 146 + return ret; 147 + } 148 + 149 + ret = snd_soc_dapm_add_routes(&card->dapm, dmic_map, 150 + ARRAY_SIZE(dmic_map)); 151 + 152 + if (ret) 153 + dev_err(card->dev, "DMic map addition failed: %d\n", ret); 154 + 155 + return ret; 156 + } 157 + 158 + static int mt8186_headset_codec_init(struct snd_soc_pcm_runtime *rtd) 89 159 { 90 160 struct snd_soc_component *cmpnt_afe = 91 161 snd_soc_rtdcom_lookup(rtd, AFE_PCM_NAME); 92 162 struct mtk_base_afe *afe = snd_soc_component_get_drvdata(cmpnt_afe); 93 163 struct mtk_soc_card_data *soc_card_data = 94 164 snd_soc_card_get_drvdata(rtd->card); 95 - struct mt8186_mt6366_da7219_max98357_priv *priv = soc_card_data->mach_priv; 96 - struct snd_soc_jack *jack = &priv->headset_jack; 165 + struct snd_soc_jack *jack = &soc_card_data->card_data->jacks[MT8186_JACK_HEADSET]; 97 166 struct snd_soc_component *cmpnt_codec = 98 167 snd_soc_rtd_to_codec(rtd, 0)->component; 168 + const int hs_keys_rt5682[] = { 169 + KEY_PLAYPAUSE, KEY_VOLUMEUP, KEY_VOLUMEDOWN, KEY_VOICECOMMAND 170 + }; 171 + const int hs_keys_da7219[] = { 172 + KEY_PLAYPAUSE, KEY_VOICECOMMAND, KEY_VOLUMEUP, KEY_VOLUMEDOWN 173 + }; 174 + const int *hs_keys; 99 175 int ret; 176 + int type; 100 177 101 178 ret = mt8186_dai_i2s_set_share(afe, "I2S1", "I2S0"); 102 179 if (ret) { ··· 199 86 return ret; 200 87 } 201 88 202 - /* Enable Headset and 4 Buttons Jack detection */ 203 89 ret = snd_soc_card_jack_new_pins(rtd->card, "Headset Jack", 204 90 SND_JACK_HEADSET | SND_JACK_BTN_0 | 205 91 SND_JACK_BTN_1 | SND_JACK_BTN_2 | 206 - SND_JACK_BTN_3 | SND_JACK_LINEOUT, 92 + SND_JACK_BTN_3, 207 93 jack, mt8186_jack_pins, 208 94 ARRAY_SIZE(mt8186_jack_pins)); 209 95 if (ret) { ··· 210 98 return ret; 211 99 } 212 100 213 - snd_jack_set_key(jack->jack, SND_JACK_BTN_0, KEY_PLAYPAUSE); 214 - snd_jack_set_key(jack->jack, SND_JACK_BTN_1, KEY_VOLUMEUP); 215 - snd_jack_set_key(jack->jack, SND_JACK_BTN_2, KEY_VOLUMEDOWN); 216 - snd_jack_set_key(jack->jack, SND_JACK_BTN_3, KEY_VOICECOMMAND); 101 + if (soc_card_data->card_data->flags & DA7219_CODEC_PRESENT) 102 + hs_keys = hs_keys_da7219; 103 + else 104 + hs_keys = hs_keys_rt5682; 217 105 218 - snd_soc_component_set_jack(cmpnt_codec, &priv->headset_jack, NULL); 106 + snd_jack_set_key(jack->jack, SND_JACK_BTN_0, hs_keys[0]); 107 + snd_jack_set_key(jack->jack, SND_JACK_BTN_1, hs_keys[1]); 108 + snd_jack_set_key(jack->jack, SND_JACK_BTN_2, hs_keys[2]); 109 + snd_jack_set_key(jack->jack, SND_JACK_BTN_3, hs_keys[3]); 219 110 220 - return 0; 111 + type = SND_JACK_HEADSET | SND_JACK_BTN_0 | SND_JACK_BTN_1 | SND_JACK_BTN_2 | SND_JACK_BTN_3; 112 + return snd_soc_component_set_jack(cmpnt_codec, jack, (void *)&type); 221 113 } 222 114 223 115 static int mt8186_da7219_i2s_hw_params(struct snd_pcm_substream *substream, 224 116 struct snd_pcm_hw_params *params) 225 117 { 226 118 struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream); 119 + struct snd_soc_dai *cpu_dai = snd_soc_rtd_to_cpu(rtd, 0); 227 120 struct snd_soc_dai *codec_dai; 228 121 unsigned int rate = params_rate(params); 229 122 unsigned int mclk_fs_ratio = 256; ··· 236 119 unsigned int freq; 237 120 int ret, j; 238 121 239 - ret = snd_soc_dai_set_sysclk(snd_soc_rtd_to_cpu(rtd, 0), 0, 240 - mclk_fs, SND_SOC_CLOCK_OUT); 122 + ret = snd_soc_dai_set_sysclk(cpu_dai, 0, mclk_fs, SND_SOC_CLOCK_OUT); 241 123 if (ret < 0) { 242 124 dev_err(rtd->dev, "failed to set cpu dai sysclk: %d\n", ret); 243 125 return ret; 244 126 } 245 127 246 128 for_each_rtd_codec_dais(rtd, j, codec_dai) { 247 - if (!strcmp(codec_dai->component->name, DA7219_DEV_NAME)) { 248 - ret = snd_soc_dai_set_sysclk(codec_dai, 249 - DA7219_CLKSRC_MCLK, 250 - mclk_fs, 251 - SND_SOC_CLOCK_IN); 252 - if (ret < 0) { 253 - dev_err(rtd->dev, "failed to set sysclk: %d\n", 254 - ret); 255 - return ret; 256 - } 129 + if (strcmp(codec_dai->component->name, DA7219_DEV_NAME)) 130 + continue; 257 131 258 - if ((rate % 8000) == 0) 259 - freq = DA7219_PLL_FREQ_OUT_98304; 260 - else 261 - freq = DA7219_PLL_FREQ_OUT_90316; 132 + ret = snd_soc_dai_set_sysclk(codec_dai, DA7219_CLKSRC_MCLK, 133 + mclk_fs, SND_SOC_CLOCK_IN); 134 + if (ret < 0) { 135 + dev_err(rtd->dev, "failed to set sysclk: %d\n", ret); 136 + return ret; 137 + } 262 138 263 - ret = snd_soc_dai_set_pll(codec_dai, 0, 264 - DA7219_SYSCLK_PLL_SRM, 265 - 0, freq); 266 - if (ret) { 267 - dev_err(rtd->dev, "failed to start PLL: %d\n", 268 - ret); 269 - return ret; 270 - } 139 + if ((rate % 8000) == 0) 140 + freq = DA7219_PLL_FREQ_OUT_98304; 141 + else 142 + freq = DA7219_PLL_FREQ_OUT_90316; 143 + 144 + ret = snd_soc_dai_set_pll(codec_dai, 0, DA7219_SYSCLK_PLL_SRM, 145 + 0, freq); 146 + if (ret) { 147 + dev_err(rtd->dev, "failed to start PLL: %d\n", ret); 148 + return ret; 271 149 } 272 150 } 273 151 ··· 273 161 { 274 162 struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream); 275 163 struct snd_soc_dai *codec_dai; 276 - int ret = 0, j; 164 + int j, ret; 277 165 278 166 for_each_rtd_codec_dais(rtd, j, codec_dai) { 279 - if (!strcmp(codec_dai->component->name, DA7219_DEV_NAME)) { 280 - ret = snd_soc_dai_set_pll(codec_dai, 281 - 0, DA7219_SYSCLK_MCLK, 0, 0); 282 - if (ret < 0) { 283 - dev_err(rtd->dev, "failed to stop PLL: %d\n", 284 - ret); 285 - return ret; 286 - } 167 + if (strcmp(codec_dai->component->name, DA7219_DEV_NAME)) 168 + continue; 169 + 170 + ret = snd_soc_dai_set_pll(codec_dai, 0, DA7219_SYSCLK_MCLK, 0, 0); 171 + if (ret < 0) { 172 + dev_err(rtd->dev, "failed to stop PLL: %d\n", ret); 173 + return ret; 287 174 } 288 175 } 289 176 ··· 294 183 .hw_free = mt8186_da7219_i2s_hw_free, 295 184 }; 296 185 297 - static int mt8186_mt6366_da7219_max98357_hdmi_init(struct snd_soc_pcm_runtime *rtd) 186 + static int mt8186_rt5682s_i2s_hw_params(struct snd_pcm_substream *substream, 187 + struct snd_pcm_hw_params *params) 188 + { 189 + struct snd_soc_pcm_runtime *rtd = substream->private_data; 190 + struct snd_soc_card *card = rtd->card; 191 + struct snd_soc_dai *cpu_dai = snd_soc_rtd_to_cpu(rtd, 0); 192 + struct snd_soc_dai *codec_dai = snd_soc_rtd_to_codec(rtd, 0); 193 + unsigned int rate = params_rate(params); 194 + unsigned int mclk_fs_ratio = 128; 195 + unsigned int mclk_fs = rate * mclk_fs_ratio; 196 + int bitwidth; 197 + int ret; 198 + 199 + bitwidth = snd_pcm_format_width(params_format(params)); 200 + if (bitwidth < 0) { 201 + dev_err(card->dev, "invalid bit width: %d\n", bitwidth); 202 + return bitwidth; 203 + } 204 + 205 + ret = snd_soc_dai_set_tdm_slot(codec_dai, 0x00, 0x0, 0x2, bitwidth); 206 + if (ret) { 207 + dev_err(card->dev, "failed to set tdm slot\n"); 208 + return ret; 209 + } 210 + 211 + ret = snd_soc_dai_set_pll(codec_dai, RT5682_PLL1, 212 + RT5682_PLL1_S_BCLK1, 213 + params_rate(params) * 64, 214 + params_rate(params) * 512); 215 + if (ret) { 216 + dev_err(card->dev, "failed to set pll\n"); 217 + return ret; 218 + } 219 + 220 + ret = snd_soc_dai_set_sysclk(codec_dai, 221 + RT5682_SCLK_S_PLL1, 222 + params_rate(params) * 512, 223 + SND_SOC_CLOCK_IN); 224 + if (ret) { 225 + dev_err(card->dev, "failed to set sysclk\n"); 226 + return ret; 227 + } 228 + 229 + return snd_soc_dai_set_sysclk(cpu_dai, 0, mclk_fs, SND_SOC_CLOCK_OUT); 230 + } 231 + 232 + static const struct snd_soc_ops mt8186_rt5682s_i2s_ops = { 233 + .hw_params = mt8186_rt5682s_i2s_hw_params, 234 + }; 235 + 236 + static int mt8186_mt6366_rt1019_rt5682s_hdmi_init(struct snd_soc_pcm_runtime *rtd) 298 237 { 299 238 struct snd_soc_component *cmpnt_afe = 300 239 snd_soc_rtdcom_lookup(rtd, AFE_PCM_NAME); ··· 353 192 snd_soc_rtd_to_codec(rtd, 0)->component; 354 193 struct mtk_soc_card_data *soc_card_data = 355 194 snd_soc_card_get_drvdata(rtd->card); 356 - struct mt8186_mt6366_da7219_max98357_priv *priv = soc_card_data->mach_priv; 195 + struct snd_soc_jack *jack = &soc_card_data->card_data->jacks[MT8186_JACK_HDMI]; 357 196 int ret; 358 197 359 198 ret = mt8186_dai_i2s_set_share(afe, "I2S2", "I2S3"); ··· 362 201 return ret; 363 202 } 364 203 365 - ret = snd_soc_card_jack_new(rtd->card, "HDMI Jack", SND_JACK_LINEOUT, &priv->hdmi_jack); 204 + ret = snd_soc_card_jack_new(rtd->card, "HDMI Jack", SND_JACK_LINEOUT, jack); 366 205 if (ret) { 367 206 dev_err(rtd->dev, "HDMI Jack creation failed: %d\n", ret); 368 207 return ret; 369 208 } 370 209 371 - return snd_soc_component_set_jack(cmpnt_codec, &priv->hdmi_jack, NULL); 210 + return snd_soc_component_set_jack(cmpnt_codec, jack, NULL); 372 211 } 373 212 374 213 static int mt8186_hw_params_fixup(struct snd_soc_pcm_runtime *rtd, ··· 393 232 return 0; 394 233 } 395 234 396 - static int mt8186_i2s_hw_params_fixup(struct snd_soc_pcm_runtime *rtd, 397 - struct snd_pcm_hw_params *params) 398 - { 399 - return mt8186_hw_params_fixup(rtd, params, SNDRV_PCM_FORMAT_S32_LE); 400 - } 401 - 402 - static int mt8186_anx7625_i2s_hw_params_fixup(struct snd_soc_pcm_runtime *rtd, 403 - struct snd_pcm_hw_params *params) 235 + static int mt8186_i2s_hw_params_24le_fixup(struct snd_soc_pcm_runtime *rtd, 236 + struct snd_pcm_hw_params *params) 404 237 { 405 238 return mt8186_hw_params_fixup(rtd, params, SNDRV_PCM_FORMAT_S24_LE); 239 + } 240 + 241 + static int mt8186_i2s_hw_params_32le_fixup(struct snd_soc_pcm_runtime *rtd, 242 + struct snd_pcm_hw_params *params) 243 + { 244 + return mt8186_hw_params_fixup(rtd, params, SNDRV_PCM_FORMAT_S32_LE); 406 245 } 407 246 408 247 /* fixup the BE DAI link to match any values from topology */ 409 248 static int mt8186_sof_dai_link_fixup(struct snd_soc_pcm_runtime *rtd, 410 249 struct snd_pcm_hw_params *params) 411 250 { 251 + struct mtk_soc_card_data *soc_card_data = snd_soc_card_get_drvdata(rtd->card); 412 252 int ret; 413 253 414 254 ret = mtk_sof_dai_link_fixup(rtd, params); 415 255 416 256 if (!strcmp(rtd->dai_link->name, "I2S0") || 417 257 !strcmp(rtd->dai_link->name, "I2S1") || 418 - !strcmp(rtd->dai_link->name, "I2S2")) 419 - mt8186_i2s_hw_params_fixup(rtd, params); 420 - else if (!strcmp(rtd->dai_link->name, "I2S3")) 421 - mt8186_anx7625_i2s_hw_params_fixup(rtd, params); 258 + !strcmp(rtd->dai_link->name, "I2S2")) { 259 + if (soc_card_data->card_data->flags & DA7219_CODEC_PRESENT) 260 + mt8186_i2s_hw_params_32le_fixup(rtd, params); 261 + else 262 + mt8186_i2s_hw_params_24le_fixup(rtd, params); 263 + } else if (!strcmp(rtd->dai_link->name, "I2S3")) { 264 + if (soc_card_data->card_data->flags & DA7219_CODEC_PRESENT) 265 + mt8186_i2s_hw_params_24le_fixup(rtd, params); 266 + else 267 + mt8186_i2s_hw_params_32le_fixup(rtd, params); 268 + } 422 269 423 270 return ret; 424 271 } 425 - 426 - static int mt8186_mt6366_da7219_max98357_playback_startup(struct snd_pcm_substream *substream) 427 - { 428 - static const unsigned int rates[] = { 429 - 48000 430 - }; 431 - static const unsigned int channels[] = { 432 - 2 433 - }; 434 - static const struct snd_pcm_hw_constraint_list constraints_rates = { 435 - .count = ARRAY_SIZE(rates), 436 - .list = rates, 437 - .mask = 0, 438 - }; 439 - static const struct snd_pcm_hw_constraint_list constraints_channels = { 440 - .count = ARRAY_SIZE(channels), 441 - .list = channels, 442 - .mask = 0, 443 - }; 444 - 445 - struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream); 446 - struct snd_pcm_runtime *runtime = substream->runtime; 447 - int ret; 448 - 449 - ret = snd_pcm_hw_constraint_list(runtime, 0, 450 - SNDRV_PCM_HW_PARAM_RATE, 451 - &constraints_rates); 452 - if (ret < 0) { 453 - dev_err(rtd->dev, "hw_constraint_list rate failed\n"); 454 - return ret; 455 - } 456 - 457 - ret = snd_pcm_hw_constraint_list(runtime, 0, 458 - SNDRV_PCM_HW_PARAM_CHANNELS, 459 - &constraints_channels); 460 - if (ret < 0) { 461 - dev_err(rtd->dev, "hw_constraint_list channel failed\n"); 462 - return ret; 463 - } 464 - 465 - return 0; 466 - } 467 - 468 - static const struct snd_soc_ops mt8186_mt6366_da7219_max98357_playback_ops = { 469 - .startup = mt8186_mt6366_da7219_max98357_playback_startup, 470 - }; 471 - 472 - static int mt8186_mt6366_da7219_max98357_capture_startup(struct snd_pcm_substream *substream) 473 - { 474 - static const unsigned int rates[] = { 475 - 48000 476 - }; 477 - static const unsigned int channels[] = { 478 - 1, 2 479 - }; 480 - static const struct snd_pcm_hw_constraint_list constraints_rates = { 481 - .count = ARRAY_SIZE(rates), 482 - .list = rates, 483 - .mask = 0, 484 - }; 485 - static const struct snd_pcm_hw_constraint_list constraints_channels = { 486 - .count = ARRAY_SIZE(channels), 487 - .list = channels, 488 - .mask = 0, 489 - }; 490 - 491 - struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream); 492 - struct snd_pcm_runtime *runtime = substream->runtime; 493 - int ret; 494 - 495 - ret = snd_pcm_hw_constraint_list(runtime, 0, 496 - SNDRV_PCM_HW_PARAM_RATE, 497 - &constraints_rates); 498 - if (ret < 0) { 499 - dev_err(rtd->dev, "hw_constraint_list rate failed\n"); 500 - return ret; 501 - } 502 - 503 - ret = snd_pcm_hw_constraint_list(runtime, 0, 504 - SNDRV_PCM_HW_PARAM_CHANNELS, 505 - &constraints_channels); 506 - if (ret < 0) { 507 - dev_err(rtd->dev, "hw_constraint_list channel failed\n"); 508 - return ret; 509 - } 510 - 511 - return 0; 512 - } 513 - 514 - static const struct snd_soc_ops mt8186_mt6366_da7219_max98357_capture_ops = { 515 - .startup = mt8186_mt6366_da7219_max98357_capture_startup, 516 - }; 517 272 518 273 /* FE */ 519 274 SND_SOC_DAILINK_DEFS(playback1, ··· 639 562 { "I2S0", "AFE_SOF_UL2", SOF_DMA_UL2, SNDRV_PCM_STREAM_CAPTURE}, 640 563 }; 641 564 642 - static struct snd_soc_dai_link mt8186_mt6366_da7219_max98357_dai_links[] = { 565 + static struct snd_soc_dai_link mt8186_mt6366_rt1019_rt5682s_dai_links[] = { 643 566 /* Front End DAI links */ 644 567 { 645 568 .name = "Playback_1", ··· 651 574 .dpcm_merged_format = 1, 652 575 .dpcm_merged_chan = 1, 653 576 .dpcm_merged_rate = 1, 654 - .ops = &mt8186_mt6366_da7219_max98357_playback_ops, 577 + .ops = &mtk_soundcard_common_playback_ops, 655 578 SND_SOC_DAILINK_REG(playback1), 656 579 }, 657 580 { ··· 685 608 .dpcm_merged_format = 1, 686 609 .dpcm_merged_chan = 1, 687 610 .dpcm_merged_rate = 1, 688 - .ops = &mt8186_mt6366_da7219_max98357_playback_ops, 611 + .ops = &mtk_soundcard_common_playback_ops, 689 612 SND_SOC_DAILINK_REG(playback3), 690 613 }, 691 614 { ··· 752 675 .dpcm_merged_format = 1, 753 676 .dpcm_merged_chan = 1, 754 677 .dpcm_merged_rate = 1, 755 - .ops = &mt8186_mt6366_da7219_max98357_capture_ops, 678 + .ops = &mtk_soundcard_common_capture_ops, 756 679 SND_SOC_DAILINK_REG(capture2), 757 680 }, 758 681 { ··· 774 697 .dpcm_merged_format = 1, 775 698 .dpcm_merged_chan = 1, 776 699 .dpcm_merged_rate = 1, 777 - .ops = &mt8186_mt6366_da7219_max98357_capture_ops, 700 + .ops = &mtk_soundcard_common_capture_ops, 778 701 SND_SOC_DAILINK_REG(capture4), 779 702 }, 780 703 { ··· 879 802 .dpcm_playback = 1, 880 803 .dpcm_capture = 1, 881 804 .ignore_suspend = 1, 882 - .init = mt8186_mt6366_init, 805 + .init = primary_codec_init, 883 806 SND_SOC_DAILINK_REG(adda), 884 807 }, 885 808 { ··· 890 813 SND_SOC_DAIFMT_CBM_CFM, 891 814 .dpcm_playback = 1, 892 815 .ignore_suspend = 1, 893 - .init = mt8186_mt6366_da7219_max98357_hdmi_init, 894 - .be_hw_params_fixup = mt8186_anx7625_i2s_hw_params_fixup, 816 + .init = mt8186_mt6366_rt1019_rt5682s_hdmi_init, 895 817 SND_SOC_DAILINK_REG(i2s3), 896 818 }, 897 819 { ··· 898 822 .no_pcm = 1, 899 823 .dpcm_capture = 1, 900 824 .ignore_suspend = 1, 901 - .be_hw_params_fixup = mt8186_i2s_hw_params_fixup, 902 - .ops = &mt8186_da7219_i2s_ops, 825 + .ops = &mt8186_rt5682s_i2s_ops, 903 826 SND_SOC_DAILINK_REG(i2s0), 904 827 }, 905 828 { ··· 906 831 .no_pcm = 1, 907 832 .dpcm_playback = 1, 908 833 .ignore_suspend = 1, 909 - .be_hw_params_fixup = mt8186_i2s_hw_params_fixup, 910 - .init = mt8186_da7219_init, 911 - .ops = &mt8186_da7219_i2s_ops, 834 + .init = mt8186_headset_codec_init, 912 835 SND_SOC_DAILINK_REG(i2s1), 913 836 }, 914 837 { ··· 914 841 .no_pcm = 1, 915 842 .dpcm_capture = 1, 916 843 .ignore_suspend = 1, 917 - .be_hw_params_fixup = mt8186_i2s_hw_params_fixup, 918 844 SND_SOC_DAILINK_REG(i2s2), 919 845 }, 920 846 { ··· 1041 969 SND_SOC_DAPM_HP("Headphones", NULL), 1042 970 SND_SOC_DAPM_MIC("Headset Mic", NULL), 1043 971 SND_SOC_DAPM_LINE("Line Out", NULL), 972 + SND_SOC_DAPM_LINE("HDMI1", NULL), 973 + SND_SOC_DAPM_MIXER(SOF_DMA_DL1, SND_SOC_NOPM, 0, 0, NULL, 0), 974 + SND_SOC_DAPM_MIXER(SOF_DMA_DL2, SND_SOC_NOPM, 0, 0, NULL, 0), 975 + SND_SOC_DAPM_MIXER(SOF_DMA_UL1, SND_SOC_NOPM, 0, 0, NULL, 0), 976 + SND_SOC_DAPM_MIXER(SOF_DMA_UL2, SND_SOC_NOPM, 0, 0, NULL, 0), 977 + }; 978 + 979 + static const struct snd_soc_dapm_widget 980 + mt8186_mt6366_rt1019_rt5682s_widgets[] = { 981 + SND_SOC_DAPM_SPK("Speakers", NULL), 982 + SND_SOC_DAPM_HP("Headphone", NULL), 983 + SND_SOC_DAPM_MIC("Headset Mic", NULL), 1044 984 SND_SOC_DAPM_OUTPUT("HDMI1"), 1045 985 SND_SOC_DAPM_MIXER(SOF_DMA_DL1, SND_SOC_NOPM, 0, 0, NULL, 0), 1046 986 SND_SOC_DAPM_MIXER(SOF_DMA_DL2, SND_SOC_NOPM, 0, 0, NULL, 0), ··· 1061 977 }; 1062 978 1063 979 static const struct snd_soc_dapm_route 1064 - mt8186_mt6366_da7219_max98357_routes[] = { 980 + mt8186_mt6366_rt1019_rt5682s_routes[] = { 1065 981 /* SPK */ 1066 - { "Speakers", NULL, "Speaker"}, 982 + { "Speakers", NULL, "Speaker" }, 1067 983 /* Headset */ 1068 - { "Headphones", NULL, "HPL" }, 1069 - { "Headphones", NULL, "HPR" }, 1070 - { "MIC", NULL, "Headset Mic" }, 984 + { "Headphone", NULL, "HPOL" }, 985 + { "Headphone", NULL, "HPOR" }, 986 + { "IN1P", NULL, "Headset Mic" }, 1071 987 /* HDMI */ 1072 - { "HDMI1", NULL, "TX"}, 988 + { "HDMI1", NULL, "TX" }, 1073 989 /* SOF Uplink */ 1074 990 {SOF_DMA_UL1, NULL, "UL1_CH1"}, 1075 991 {SOF_DMA_UL1, NULL, "UL1_CH2"}, ··· 1080 996 {"DSP_DL2_VIRT", NULL, SOF_DMA_DL2}, 1081 997 }; 1082 998 1083 - static const struct snd_kcontrol_new 1084 - mt8186_mt6366_da7219_max98357_controls[] = { 999 + static const struct snd_soc_dapm_route mt8186_mt6366_rt5650_routes[] = { 1000 + /* SPK */ 1001 + {"Speakers", NULL, "SPOL"}, 1002 + {"Speakers", NULL, "SPOR"}, 1003 + /* Headset */ 1004 + { "Headphone", NULL, "HPOL" }, 1005 + { "Headphone", NULL, "HPOR" }, 1006 + { "IN1P", NULL, "Headset Mic" }, 1007 + { "IN1N", NULL, "Headset Mic"}, 1008 + /* HDMI */ 1009 + { "HDMI1", NULL, "TX" }, 1010 + /* SOF Uplink */ 1011 + {SOF_DMA_UL1, NULL, "UL1_CH1"}, 1012 + {SOF_DMA_UL1, NULL, "UL1_CH2"}, 1013 + {SOF_DMA_UL2, NULL, "UL2_CH1"}, 1014 + {SOF_DMA_UL2, NULL, "UL2_CH2"}, 1015 + /* SOF Downlink */ 1016 + {"DSP_DL1_VIRT", NULL, SOF_DMA_DL1}, 1017 + {"DSP_DL2_VIRT", NULL, SOF_DMA_DL2}, 1018 + }; 1019 + 1020 + static const struct snd_kcontrol_new mt8186_mt6366_da7219_max98357_controls[] = { 1085 1021 SOC_DAPM_PIN_SWITCH("Speakers"), 1086 1022 SOC_DAPM_PIN_SWITCH("Headphones"), 1087 1023 SOC_DAPM_PIN_SWITCH("Headset Mic"), ··· 1109 1005 SOC_DAPM_PIN_SWITCH("HDMI1"), 1110 1006 }; 1111 1007 1008 + static const struct snd_kcontrol_new 1009 + mt8186_mt6366_rt1019_rt5682s_controls[] = { 1010 + SOC_DAPM_PIN_SWITCH("Speakers"), 1011 + SOC_DAPM_PIN_SWITCH("Headphone"), 1012 + SOC_DAPM_PIN_SWITCH("Headset Mic"), 1013 + SOC_DAPM_PIN_SWITCH("HDMI1"), 1014 + }; 1015 + 1112 1016 static struct snd_soc_card mt8186_mt6366_da7219_max98357_soc_card = { 1113 1017 .name = "mt8186_da7219_max98357", 1114 1018 .owner = THIS_MODULE, 1115 - .dai_link = mt8186_mt6366_da7219_max98357_dai_links, 1116 - .num_links = ARRAY_SIZE(mt8186_mt6366_da7219_max98357_dai_links), 1019 + .dai_link = mt8186_mt6366_rt1019_rt5682s_dai_links, 1020 + .num_links = ARRAY_SIZE(mt8186_mt6366_rt1019_rt5682s_dai_links), 1117 1021 .controls = mt8186_mt6366_da7219_max98357_controls, 1118 1022 .num_controls = ARRAY_SIZE(mt8186_mt6366_da7219_max98357_controls), 1119 1023 .dapm_widgets = mt8186_mt6366_da7219_max98357_widgets, 1120 1024 .num_dapm_widgets = ARRAY_SIZE(mt8186_mt6366_da7219_max98357_widgets), 1121 - .dapm_routes = mt8186_mt6366_da7219_max98357_routes, 1122 - .num_dapm_routes = ARRAY_SIZE(mt8186_mt6366_da7219_max98357_routes), 1123 - .codec_conf = mt8186_mt6366_da7219_max98357_codec_conf, 1124 - .num_configs = ARRAY_SIZE(mt8186_mt6366_da7219_max98357_codec_conf), 1025 + .dapm_routes = mt8186_mt6366_rt1019_rt5682s_routes, 1026 + .num_dapm_routes = ARRAY_SIZE(mt8186_mt6366_rt1019_rt5682s_routes), 1027 + .codec_conf = mt8186_mt6366_rt1019_rt5682s_codec_conf, 1028 + .num_configs = ARRAY_SIZE(mt8186_mt6366_rt1019_rt5682s_codec_conf), 1125 1029 }; 1126 1030 1127 - static int mt8186_mt6366_da7219_max98357_dev_probe(struct platform_device *pdev) 1031 + static struct snd_soc_card mt8186_mt6366_rt1019_rt5682s_soc_card = { 1032 + .name = "mt8186_rt1019_rt5682s", 1033 + .owner = THIS_MODULE, 1034 + .dai_link = mt8186_mt6366_rt1019_rt5682s_dai_links, 1035 + .num_links = ARRAY_SIZE(mt8186_mt6366_rt1019_rt5682s_dai_links), 1036 + .controls = mt8186_mt6366_rt1019_rt5682s_controls, 1037 + .num_controls = ARRAY_SIZE(mt8186_mt6366_rt1019_rt5682s_controls), 1038 + .dapm_widgets = mt8186_mt6366_rt1019_rt5682s_widgets, 1039 + .num_dapm_widgets = ARRAY_SIZE(mt8186_mt6366_rt1019_rt5682s_widgets), 1040 + .dapm_routes = mt8186_mt6366_rt1019_rt5682s_routes, 1041 + .num_dapm_routes = ARRAY_SIZE(mt8186_mt6366_rt1019_rt5682s_routes), 1042 + .codec_conf = mt8186_mt6366_rt1019_rt5682s_codec_conf, 1043 + .num_configs = ARRAY_SIZE(mt8186_mt6366_rt1019_rt5682s_codec_conf), 1044 + }; 1045 + 1046 + static struct snd_soc_card mt8186_mt6366_rt5682s_max98360_soc_card = { 1047 + .name = "mt8186_rt5682s_max98360", 1048 + .owner = THIS_MODULE, 1049 + .dai_link = mt8186_mt6366_rt1019_rt5682s_dai_links, 1050 + .num_links = ARRAY_SIZE(mt8186_mt6366_rt1019_rt5682s_dai_links), 1051 + .controls = mt8186_mt6366_rt1019_rt5682s_controls, 1052 + .num_controls = ARRAY_SIZE(mt8186_mt6366_rt1019_rt5682s_controls), 1053 + .dapm_widgets = mt8186_mt6366_rt1019_rt5682s_widgets, 1054 + .num_dapm_widgets = ARRAY_SIZE(mt8186_mt6366_rt1019_rt5682s_widgets), 1055 + .dapm_routes = mt8186_mt6366_rt1019_rt5682s_routes, 1056 + .num_dapm_routes = ARRAY_SIZE(mt8186_mt6366_rt1019_rt5682s_routes), 1057 + .codec_conf = mt8186_mt6366_rt1019_rt5682s_codec_conf, 1058 + .num_configs = ARRAY_SIZE(mt8186_mt6366_rt1019_rt5682s_codec_conf), 1059 + }; 1060 + 1061 + static struct snd_soc_card mt8186_mt6366_rt5650_soc_card = { 1062 + .name = "mt8186_rt5650", 1063 + .owner = THIS_MODULE, 1064 + .dai_link = mt8186_mt6366_rt1019_rt5682s_dai_links, 1065 + .num_links = ARRAY_SIZE(mt8186_mt6366_rt1019_rt5682s_dai_links), 1066 + .controls = mt8186_mt6366_rt1019_rt5682s_controls, 1067 + .num_controls = ARRAY_SIZE(mt8186_mt6366_rt1019_rt5682s_controls), 1068 + .dapm_widgets = mt8186_mt6366_rt1019_rt5682s_widgets, 1069 + .num_dapm_widgets = ARRAY_SIZE(mt8186_mt6366_rt1019_rt5682s_widgets), 1070 + .dapm_routes = mt8186_mt6366_rt5650_routes, 1071 + .num_dapm_routes = ARRAY_SIZE(mt8186_mt6366_rt5650_routes), 1072 + .codec_conf = mt8186_mt6366_rt1019_rt5682s_codec_conf, 1073 + .num_configs = ARRAY_SIZE(mt8186_mt6366_rt1019_rt5682s_codec_conf), 1074 + }; 1075 + 1076 + static int mt8186_mt6366_legacy_probe(struct mtk_soc_card_data *soc_card_data) 1128 1077 { 1129 - struct snd_soc_card *card; 1078 + struct mtk_platform_card_data *card_data = soc_card_data->card_data; 1079 + struct snd_soc_card *card = card_data->card; 1080 + struct device *dev = card->dev; 1130 1081 struct snd_soc_dai_link *dai_link; 1131 - struct mtk_soc_card_data *soc_card_data; 1132 - struct mt8186_mt6366_da7219_max98357_priv *mach_priv; 1133 - struct device_node *platform_node, *headset_codec, *playback_codec, *adsp_node; 1134 - int sof_on = 0; 1082 + struct device_node *headset_codec, *playback_codec; 1135 1083 int ret, i; 1136 1084 1137 - card = (struct snd_soc_card *)device_get_match_data(&pdev->dev); 1138 - if (!card) 1139 - return -EINVAL; 1140 - card->dev = &pdev->dev; 1085 + playback_codec = of_get_child_by_name(dev->of_node, "playback-codecs"); 1086 + if (!playback_codec) 1087 + return dev_err_probe(dev, -EINVAL, 1088 + "Property 'playback-codecs' missing or invalid\n"); 1141 1089 1142 - soc_card_data = devm_kzalloc(&pdev->dev, sizeof(*soc_card_data), GFP_KERNEL); 1143 - if (!soc_card_data) 1144 - return -ENOMEM; 1145 - mach_priv = devm_kzalloc(&pdev->dev, sizeof(*mach_priv), GFP_KERNEL); 1146 - if (!mach_priv) 1147 - return -ENOMEM; 1148 - 1149 - soc_card_data->mach_priv = mach_priv; 1150 - 1151 - adsp_node = of_parse_phandle(pdev->dev.of_node, "mediatek,adsp", 0); 1152 - if (adsp_node) { 1153 - struct mtk_sof_priv *sof_priv; 1154 - 1155 - sof_priv = devm_kzalloc(&pdev->dev, sizeof(*sof_priv), GFP_KERNEL); 1156 - if (!sof_priv) { 1157 - ret = -ENOMEM; 1158 - goto err_adsp_node; 1159 - } 1160 - sof_priv->conn_streams = g_sof_conn_streams; 1161 - sof_priv->num_streams = ARRAY_SIZE(g_sof_conn_streams); 1162 - sof_priv->sof_dai_link_fixup = mt8186_sof_dai_link_fixup; 1163 - soc_card_data->sof_priv = sof_priv; 1164 - card->probe = mtk_sof_card_probe; 1165 - card->late_probe = mtk_sof_card_late_probe; 1166 - if (!card->topology_shortname_created) { 1167 - snprintf(card->topology_shortname, 32, "sof-%s", card->name); 1168 - card->topology_shortname_created = true; 1169 - } 1170 - card->name = card->topology_shortname; 1171 - sof_on = 1; 1172 - } else { 1173 - dev_dbg(&pdev->dev, "Probe without adsp\n"); 1174 - } 1175 - 1176 - if (of_property_read_bool(pdev->dev.of_node, "mediatek,dai-link")) { 1177 - ret = mtk_sof_dailink_parse_of(card, pdev->dev.of_node, 1178 - "mediatek,dai-link", 1179 - mt8186_mt6366_da7219_max98357_dai_links, 1180 - ARRAY_SIZE(mt8186_mt6366_da7219_max98357_dai_links)); 1181 - if (ret) { 1182 - dev_dbg(&pdev->dev, "Parse dai-link fail\n"); 1183 - goto err_adsp_node; 1184 - } 1185 - } else { 1186 - if (!sof_on) 1187 - card->num_links = ARRAY_SIZE(mt8186_mt6366_da7219_max98357_dai_links) 1188 - - ARRAY_SIZE(g_sof_conn_streams); 1189 - } 1190 - 1191 - platform_node = of_parse_phandle(pdev->dev.of_node, "mediatek,platform", 0); 1192 - if (!platform_node) { 1193 - ret = -EINVAL; 1194 - dev_err_probe(&pdev->dev, ret, "Property 'platform' missing or invalid\n"); 1195 - goto err_platform_node; 1196 - } 1197 - 1198 - playback_codec = of_get_child_by_name(pdev->dev.of_node, "playback-codecs"); 1199 - if (!playback_codec) { 1200 - ret = -EINVAL; 1201 - dev_err_probe(&pdev->dev, ret, "Property 'speaker-codecs' missing or invalid\n"); 1202 - goto err_playback_codec; 1203 - } 1204 - 1205 - headset_codec = of_get_child_by_name(pdev->dev.of_node, "headset-codec"); 1090 + headset_codec = of_get_child_by_name(dev->of_node, "headset-codec"); 1206 1091 if (!headset_codec) { 1207 - ret = -EINVAL; 1208 - dev_err_probe(&pdev->dev, ret, "Property 'headset-codec' missing or invalid\n"); 1209 - goto err_headset_codec; 1092 + of_node_put(playback_codec); 1093 + return dev_err_probe(dev, -EINVAL, 1094 + "Property 'headset-codec' missing or invalid\n"); 1210 1095 } 1211 1096 1212 1097 for_each_card_prelinks(card, i, dai_link) { 1213 1098 ret = mt8186_mt6366_card_set_be_link(card, dai_link, playback_codec, "I2S3"); 1214 1099 if (ret) { 1215 - dev_err_probe(&pdev->dev, ret, "%s set speaker_codec fail\n", 1100 + dev_err_probe(dev, ret, "%s set playback_codec fail\n", 1216 1101 dai_link->name); 1217 - goto err_probe; 1102 + break; 1218 1103 } 1219 1104 1220 1105 ret = mt8186_mt6366_card_set_be_link(card, dai_link, headset_codec, "I2S0"); 1221 1106 if (ret) { 1222 - dev_err_probe(&pdev->dev, ret, "%s set headset_codec fail\n", 1107 + dev_err_probe(dev, ret, "%s set headset_codec fail\n", 1223 1108 dai_link->name); 1224 - goto err_probe; 1109 + break; 1225 1110 } 1226 1111 1227 1112 ret = mt8186_mt6366_card_set_be_link(card, dai_link, headset_codec, "I2S1"); 1228 1113 if (ret) { 1229 - dev_err_probe(&pdev->dev, ret, "%s set headset_codec fail\n", 1114 + dev_err_probe(dev, ret, "%s set headset_codec fail\n", 1230 1115 dai_link->name); 1231 - goto err_probe; 1116 + break; 1232 1117 } 1233 - 1234 - if (!strncmp(dai_link->name, "AFE_SOF", strlen("AFE_SOF")) && sof_on) 1235 - dai_link->platforms->of_node = adsp_node; 1236 - 1237 - if (!dai_link->platforms->name && !dai_link->platforms->of_node) 1238 - dai_link->platforms->of_node = platform_node; 1239 1118 } 1240 - 1241 - snd_soc_card_set_drvdata(card, soc_card_data); 1242 - 1243 - ret = mt8186_afe_gpio_init(&pdev->dev); 1244 - if (ret) { 1245 - dev_err_probe(&pdev->dev, ret, "%s init gpio error\n", __func__); 1246 - goto err_probe; 1247 - } 1248 - 1249 - ret = devm_snd_soc_register_card(&pdev->dev, card); 1250 - if (ret) 1251 - dev_err_probe(&pdev->dev, ret, "%s snd_soc_register_card fail\n", __func__); 1252 - 1253 - err_probe: 1254 1119 of_node_put(headset_codec); 1255 - err_headset_codec: 1256 1120 of_node_put(playback_codec); 1257 - err_playback_codec: 1258 - of_node_put(platform_node); 1259 - err_platform_node: 1260 - err_adsp_node: 1261 - of_node_put(adsp_node); 1262 1121 1263 1122 return ret; 1264 1123 } 1265 1124 1266 - #if IS_ENABLED(CONFIG_OF) 1267 - static const struct of_device_id mt8186_mt6366_da7219_max98357_dt_match[] = { 1268 - { .compatible = "mediatek,mt8186-mt6366-da7219-max98357-sound", 1269 - .data = &mt8186_mt6366_da7219_max98357_soc_card, 1270 - }, 1271 - {} 1125 + static int mt8186_mt6366_soc_card_probe(struct mtk_soc_card_data *soc_card_data, bool legacy) 1126 + { 1127 + struct mtk_platform_card_data *card_data = soc_card_data->card_data; 1128 + struct snd_soc_card *card = card_data->card; 1129 + struct snd_soc_dai_link *dai_link; 1130 + struct mt8186_mt6366_rt1019_rt5682s_priv *mach_priv; 1131 + int i, ret; 1132 + 1133 + mach_priv = devm_kzalloc(card->dev, sizeof(*mach_priv), GFP_KERNEL); 1134 + if (!mach_priv) 1135 + return -ENOMEM; 1136 + 1137 + soc_card_data->mach_priv = mach_priv; 1138 + 1139 + mach_priv->dmic_sel = devm_gpiod_get_optional(card->dev, 1140 + "dmic", GPIOD_OUT_LOW); 1141 + if (IS_ERR(mach_priv->dmic_sel)) 1142 + return dev_err_probe(card->dev, PTR_ERR(mach_priv->dmic_sel), 1143 + "DMIC gpio failed\n"); 1144 + 1145 + for_each_card_prelinks(card, i, dai_link) { 1146 + if (strcmp(dai_link->name, "I2S0") == 0 || 1147 + strcmp(dai_link->name, "I2S1") == 0 || 1148 + strcmp(dai_link->name, "I2S2") == 0) { 1149 + if (card_data->flags & DA7219_CODEC_PRESENT) { 1150 + dai_link->be_hw_params_fixup = mt8186_i2s_hw_params_32le_fixup; 1151 + dai_link->ops = &mt8186_da7219_i2s_ops; 1152 + } else { 1153 + dai_link->be_hw_params_fixup = mt8186_i2s_hw_params_24le_fixup; 1154 + dai_link->ops = &mt8186_rt5682s_i2s_ops; 1155 + } 1156 + } else if (strcmp(dai_link->name, "I2S3") == 0) { 1157 + if (card_data->flags & DA7219_CODEC_PRESENT) 1158 + dai_link->be_hw_params_fixup = mt8186_i2s_hw_params_24le_fixup; 1159 + else 1160 + dai_link->be_hw_params_fixup = mt8186_i2s_hw_params_32le_fixup; 1161 + } 1162 + } 1163 + 1164 + if (legacy) { 1165 + ret = mt8186_mt6366_legacy_probe(soc_card_data); 1166 + if (ret) 1167 + return ret; 1168 + } 1169 + 1170 + ret = mt8186_afe_gpio_init(card->dev); 1171 + if (ret) 1172 + return dev_err_probe(card->dev, ret, "init AFE gpio error\n"); 1173 + 1174 + return 0; 1175 + } 1176 + 1177 + static const unsigned int mt8186_pcm_playback_channels[] = { 2 }; 1178 + static const unsigned int mt8186_pcm_capture_channels[] = { 1, 2 }; 1179 + static const unsigned int mt8186_pcm_rates[] = { 48000 }; 1180 + 1181 + static const struct snd_pcm_hw_constraint_list mt8186_rate_constraint = { 1182 + .list = mt8186_pcm_rates, 1183 + .count = ARRAY_SIZE(mt8186_pcm_rates) 1272 1184 }; 1273 - MODULE_DEVICE_TABLE(of, mt8186_mt6366_da7219_max98357_dt_match); 1185 + 1186 + static const struct mtk_pcm_constraints_data mt8186_pcm_constraints[MTK_CONSTRAINT_CAPTURE + 1] = { 1187 + [MTK_CONSTRAINT_PLAYBACK] = { 1188 + .channels = &(const struct snd_pcm_hw_constraint_list) { 1189 + .list = mt8186_pcm_playback_channels, 1190 + .count = ARRAY_SIZE(mt8186_pcm_playback_channels) 1191 + }, 1192 + .rates = &mt8186_rate_constraint, 1193 + }, 1194 + [MTK_CONSTRAINT_CAPTURE] = { 1195 + .channels = &(const struct snd_pcm_hw_constraint_list) { 1196 + .list = mt8186_pcm_capture_channels, 1197 + .count = ARRAY_SIZE(mt8186_pcm_capture_channels) 1198 + }, 1199 + .rates = &mt8186_rate_constraint, 1200 + } 1201 + }; 1202 + 1203 + static const struct mtk_sof_priv mt8186_sof_priv = { 1204 + .conn_streams = g_sof_conn_streams, 1205 + .num_streams = ARRAY_SIZE(g_sof_conn_streams), 1206 + .sof_dai_link_fixup = mt8186_sof_dai_link_fixup 1207 + }; 1208 + 1209 + static const struct mtk_soundcard_pdata mt8186_mt6366_da7219_max98357_pdata = { 1210 + .card_data = &(struct mtk_platform_card_data) { 1211 + .card = &mt8186_mt6366_da7219_max98357_soc_card, 1212 + .num_jacks = MT8186_JACK_MAX, 1213 + .pcm_constraints = mt8186_pcm_constraints, 1214 + .num_pcm_constraints = ARRAY_SIZE(mt8186_pcm_constraints), 1215 + .flags = DA7219_CODEC_PRESENT, 1216 + }, 1217 + .sof_priv = &mt8186_sof_priv, 1218 + .soc_probe = mt8186_mt6366_soc_card_probe 1219 + }; 1220 + 1221 + static const struct mtk_soundcard_pdata mt8186_mt6366_rt1019_rt5682s_pdata = { 1222 + .card_data = &(struct mtk_platform_card_data) { 1223 + .card = &mt8186_mt6366_rt1019_rt5682s_soc_card, 1224 + .num_jacks = MT8186_JACK_MAX, 1225 + .pcm_constraints = mt8186_pcm_constraints, 1226 + .num_pcm_constraints = ARRAY_SIZE(mt8186_pcm_constraints), 1227 + }, 1228 + .sof_priv = &mt8186_sof_priv, 1229 + .soc_probe = mt8186_mt6366_soc_card_probe 1230 + }; 1231 + 1232 + static const struct mtk_soundcard_pdata mt8186_mt6366_rt5682s_max98360_pdata = { 1233 + .card_data = &(struct mtk_platform_card_data) { 1234 + .card = &mt8186_mt6366_rt5682s_max98360_soc_card, 1235 + .num_jacks = MT8186_JACK_MAX, 1236 + .pcm_constraints = mt8186_pcm_constraints, 1237 + .num_pcm_constraints = ARRAY_SIZE(mt8186_pcm_constraints), 1238 + }, 1239 + .sof_priv = &mt8186_sof_priv, 1240 + .soc_probe = mt8186_mt6366_soc_card_probe 1241 + }; 1242 + 1243 + static const struct mtk_soundcard_pdata mt8186_mt6366_rt5650_pdata = { 1244 + .card_data = &(struct mtk_platform_card_data) { 1245 + .card = &mt8186_mt6366_rt5650_soc_card, 1246 + .num_jacks = MT8186_JACK_MAX, 1247 + .pcm_constraints = mt8186_pcm_constraints, 1248 + .num_pcm_constraints = ARRAY_SIZE(mt8186_pcm_constraints), 1249 + }, 1250 + .sof_priv = &mt8186_sof_priv, 1251 + .soc_probe = mt8186_mt6366_soc_card_probe 1252 + }; 1253 + 1254 + #if IS_ENABLED(CONFIG_OF) 1255 + static const struct of_device_id mt8186_mt6366_dt_match[] = { 1256 + { 1257 + .compatible = "mediatek,mt8186-mt6366-rt1019-rt5682s-sound", 1258 + .data = &mt8186_mt6366_rt1019_rt5682s_pdata, 1259 + }, 1260 + { 1261 + .compatible = "mediatek,mt8186-mt6366-rt5682s-max98360-sound", 1262 + .data = &mt8186_mt6366_rt5682s_max98360_pdata, 1263 + }, 1264 + { 1265 + .compatible = "mediatek,mt8186-mt6366-rt5650-sound", 1266 + .data = &mt8186_mt6366_rt5650_pdata, 1267 + }, 1268 + { 1269 + .compatible = "mediatek,mt8186-mt6366-da7219-max98357-sound", 1270 + .data = &mt8186_mt6366_da7219_max98357_pdata, 1271 + }, 1272 + { /* sentinel */ } 1273 + }; 1274 + MODULE_DEVICE_TABLE(of, mt8186_mt6366_dt_match); 1274 1275 #endif 1275 1276 1276 - static struct platform_driver mt8186_mt6366_da7219_max98357_driver = { 1277 + static struct platform_driver mt8186_mt6366_driver = { 1277 1278 .driver = { 1278 - .name = "mt8186_mt6366_da7219_max98357", 1279 + .name = "mt8186_mt6366", 1279 1280 #if IS_ENABLED(CONFIG_OF) 1280 - .of_match_table = mt8186_mt6366_da7219_max98357_dt_match, 1281 + .of_match_table = mt8186_mt6366_dt_match, 1281 1282 #endif 1282 1283 .pm = &snd_soc_pm_ops, 1283 1284 }, 1284 - .probe = mt8186_mt6366_da7219_max98357_dev_probe, 1285 + .probe = mtk_soundcard_common_probe, 1285 1286 }; 1286 1287 1287 - module_platform_driver(mt8186_mt6366_da7219_max98357_driver); 1288 + module_platform_driver(mt8186_mt6366_driver); 1288 1289 1289 1290 /* Module information */ 1290 - MODULE_DESCRIPTION("MT8186-MT6366-DA7219-MAX98357 ALSA SoC machine driver"); 1291 + MODULE_DESCRIPTION("MT8186-MT6366 ALSA SoC machine driver"); 1291 1292 MODULE_AUTHOR("Jiaxin Yu <jiaxin.yu@mediatek.com>"); 1292 1293 MODULE_LICENSE("GPL v2"); 1293 - MODULE_ALIAS("mt8186_mt6366_da7219_max98357 soc card"); 1294 + MODULE_ALIAS("mt8186_mt6366 soc card");
-1320
sound/soc/mediatek/mt8186/mt8186-mt6366-rt1019-rt5682s.c
··· 1 - // SPDX-License-Identifier: GPL-2.0 2 - // 3 - // mt8186-mt6366-rt1019-rt5682s.c 4 - // -- MT8186-MT6366-RT1019-RT5682S ALSA SoC machine driver 5 - // 6 - // Copyright (c) 2022 MediaTek Inc. 7 - // Author: Jiaxin Yu <jiaxin.yu@mediatek.com> 8 - // 9 - 10 - #include <linux/gpio/consumer.h> 11 - #include <linux/input.h> 12 - #include <linux/module.h> 13 - #include <linux/of.h> 14 - #include <sound/jack.h> 15 - #include <sound/pcm_params.h> 16 - #include <sound/rt5682.h> 17 - #include <sound/soc.h> 18 - 19 - #include "../../codecs/mt6358.h" 20 - #include "../../codecs/rt5682.h" 21 - #include "../common/mtk-afe-platform-driver.h" 22 - #include "../common/mtk-dsp-sof-common.h" 23 - #include "../common/mtk-soc-card.h" 24 - #include "mt8186-afe-common.h" 25 - #include "mt8186-afe-clk.h" 26 - #include "mt8186-afe-gpio.h" 27 - #include "mt8186-mt6366-common.h" 28 - 29 - #define RT1019_CODEC_DAI "HiFi" 30 - #define RT1019_DEV0_NAME "rt1019p" 31 - 32 - #define RT5682S_CODEC_DAI "rt5682s-aif1" 33 - #define RT5682S_DEV0_NAME "rt5682s.5-001a" 34 - 35 - #define SOF_DMA_DL1 "SOF_DMA_DL1" 36 - #define SOF_DMA_DL2 "SOF_DMA_DL2" 37 - #define SOF_DMA_UL1 "SOF_DMA_UL1" 38 - #define SOF_DMA_UL2 "SOF_DMA_UL2" 39 - 40 - struct mt8186_mt6366_rt1019_rt5682s_priv { 41 - struct snd_soc_jack headset_jack, hdmi_jack; 42 - struct gpio_desc *dmic_sel; 43 - int dmic_switch; 44 - }; 45 - 46 - /* Headset jack detection DAPM pins */ 47 - static struct snd_soc_jack_pin mt8186_jack_pins[] = { 48 - { 49 - .pin = "Headphone", 50 - .mask = SND_JACK_HEADPHONE, 51 - }, 52 - { 53 - .pin = "Headset Mic", 54 - .mask = SND_JACK_MICROPHONE, 55 - }, 56 - }; 57 - 58 - static struct snd_soc_codec_conf mt8186_mt6366_rt1019_rt5682s_codec_conf[] = { 59 - { 60 - .dlc = COMP_CODEC_CONF("mt6358-sound"), 61 - .name_prefix = "Mt6366", 62 - }, 63 - { 64 - .dlc = COMP_CODEC_CONF("bt-sco"), 65 - .name_prefix = "Mt8186 bt", 66 - }, 67 - { 68 - .dlc = COMP_CODEC_CONF("hdmi-audio-codec"), 69 - .name_prefix = "Mt8186 hdmi", 70 - }, 71 - }; 72 - 73 - static int dmic_get(struct snd_kcontrol *kcontrol, 74 - struct snd_ctl_elem_value *ucontrol) 75 - { 76 - struct snd_soc_dapm_context *dapm = snd_soc_dapm_kcontrol_dapm(kcontrol); 77 - struct mtk_soc_card_data *soc_card_data = 78 - snd_soc_card_get_drvdata(dapm->card); 79 - struct mt8186_mt6366_rt1019_rt5682s_priv *priv = soc_card_data->mach_priv; 80 - 81 - ucontrol->value.integer.value[0] = priv->dmic_switch; 82 - return 0; 83 - } 84 - 85 - static int dmic_set(struct snd_kcontrol *kcontrol, 86 - struct snd_ctl_elem_value *ucontrol) 87 - { 88 - struct snd_soc_dapm_context *dapm = snd_soc_dapm_kcontrol_dapm(kcontrol); 89 - struct mtk_soc_card_data *soc_card_data = 90 - snd_soc_card_get_drvdata(dapm->card); 91 - struct mt8186_mt6366_rt1019_rt5682s_priv *priv = soc_card_data->mach_priv; 92 - 93 - priv->dmic_switch = ucontrol->value.integer.value[0]; 94 - if (priv->dmic_sel) { 95 - gpiod_set_value(priv->dmic_sel, priv->dmic_switch); 96 - dev_dbg(dapm->card->dev, "dmic_set_value %d\n", 97 - priv->dmic_switch); 98 - } 99 - return 0; 100 - } 101 - 102 - static const char * const dmic_mux_text[] = { 103 - "Front Mic", 104 - "Rear Mic", 105 - }; 106 - 107 - static SOC_ENUM_SINGLE_DECL(mt8186_dmic_enum, 108 - SND_SOC_NOPM, 0, dmic_mux_text); 109 - 110 - static const struct snd_kcontrol_new mt8186_dmic_mux_control = 111 - SOC_DAPM_ENUM_EXT("DMIC Select Mux", mt8186_dmic_enum, 112 - dmic_get, dmic_set); 113 - 114 - static const struct snd_soc_dapm_widget dmic_widgets[] = { 115 - SND_SOC_DAPM_MIC("DMIC", NULL), 116 - SND_SOC_DAPM_MUX("Dmic Mux", SND_SOC_NOPM, 0, 0, &mt8186_dmic_mux_control), 117 - }; 118 - 119 - static const struct snd_soc_dapm_route dmic_map[] = { 120 - /* digital mics */ 121 - {"Dmic Mux", "Front Mic", "DMIC"}, 122 - {"Dmic Mux", "Rear Mic", "DMIC"}, 123 - }; 124 - 125 - static int primary_codec_init(struct snd_soc_pcm_runtime *rtd) 126 - { 127 - struct snd_soc_card *card = rtd->card; 128 - struct mtk_soc_card_data *soc_card_data = snd_soc_card_get_drvdata(card); 129 - struct mt8186_mt6366_rt1019_rt5682s_priv *priv = soc_card_data->mach_priv; 130 - int ret; 131 - 132 - ret = mt8186_mt6366_init(rtd); 133 - 134 - if (ret) { 135 - dev_err(card->dev, "mt8186_mt6366_init failed: %d\n", ret); 136 - return ret; 137 - } 138 - 139 - if (!priv->dmic_sel) { 140 - dev_dbg(card->dev, "dmic_sel is null\n"); 141 - return 0; 142 - } 143 - 144 - ret = snd_soc_dapm_new_controls(&card->dapm, dmic_widgets, 145 - ARRAY_SIZE(dmic_widgets)); 146 - if (ret) { 147 - dev_err(card->dev, "DMic widget addition failed: %d\n", ret); 148 - /* Don't need to add routes if widget addition failed */ 149 - return ret; 150 - } 151 - 152 - ret = snd_soc_dapm_add_routes(&card->dapm, dmic_map, 153 - ARRAY_SIZE(dmic_map)); 154 - 155 - if (ret) 156 - dev_err(card->dev, "DMic map addition failed: %d\n", ret); 157 - 158 - return ret; 159 - } 160 - 161 - static int mt8186_rt5682s_init(struct snd_soc_pcm_runtime *rtd) 162 - { 163 - struct snd_soc_component *cmpnt_afe = 164 - snd_soc_rtdcom_lookup(rtd, AFE_PCM_NAME); 165 - struct mtk_base_afe *afe = snd_soc_component_get_drvdata(cmpnt_afe); 166 - struct mtk_soc_card_data *soc_card_data = 167 - snd_soc_card_get_drvdata(rtd->card); 168 - struct mt8186_mt6366_rt1019_rt5682s_priv *priv = soc_card_data->mach_priv; 169 - struct snd_soc_jack *jack = &priv->headset_jack; 170 - struct snd_soc_component *cmpnt_codec = 171 - snd_soc_rtd_to_codec(rtd, 0)->component; 172 - int ret; 173 - int type; 174 - 175 - ret = mt8186_dai_i2s_set_share(afe, "I2S1", "I2S0"); 176 - if (ret) { 177 - dev_err(rtd->dev, "Failed to set up shared clocks\n"); 178 - return ret; 179 - } 180 - 181 - ret = snd_soc_card_jack_new_pins(rtd->card, "Headset Jack", 182 - SND_JACK_HEADSET | SND_JACK_BTN_0 | 183 - SND_JACK_BTN_1 | SND_JACK_BTN_2 | 184 - SND_JACK_BTN_3, 185 - jack, mt8186_jack_pins, 186 - ARRAY_SIZE(mt8186_jack_pins)); 187 - if (ret) { 188 - dev_err(rtd->dev, "Headset Jack creation failed: %d\n", ret); 189 - return ret; 190 - } 191 - 192 - snd_jack_set_key(jack->jack, SND_JACK_BTN_0, KEY_PLAYPAUSE); 193 - snd_jack_set_key(jack->jack, SND_JACK_BTN_1, KEY_VOICECOMMAND); 194 - snd_jack_set_key(jack->jack, SND_JACK_BTN_2, KEY_VOLUMEUP); 195 - snd_jack_set_key(jack->jack, SND_JACK_BTN_3, KEY_VOLUMEDOWN); 196 - 197 - type = SND_JACK_HEADSET | SND_JACK_BTN_0 | SND_JACK_BTN_1 | SND_JACK_BTN_2 | SND_JACK_BTN_3; 198 - return snd_soc_component_set_jack(cmpnt_codec, jack, (void *)&type); 199 - } 200 - 201 - static int mt8186_rt5682s_i2s_hw_params(struct snd_pcm_substream *substream, 202 - struct snd_pcm_hw_params *params) 203 - { 204 - struct snd_soc_pcm_runtime *rtd = substream->private_data; 205 - struct snd_soc_card *card = rtd->card; 206 - struct snd_soc_dai *cpu_dai = snd_soc_rtd_to_cpu(rtd, 0); 207 - struct snd_soc_dai *codec_dai = snd_soc_rtd_to_codec(rtd, 0); 208 - unsigned int rate = params_rate(params); 209 - unsigned int mclk_fs_ratio = 128; 210 - unsigned int mclk_fs = rate * mclk_fs_ratio; 211 - int bitwidth; 212 - int ret; 213 - 214 - bitwidth = snd_pcm_format_width(params_format(params)); 215 - if (bitwidth < 0) { 216 - dev_err(card->dev, "invalid bit width: %d\n", bitwidth); 217 - return bitwidth; 218 - } 219 - 220 - ret = snd_soc_dai_set_tdm_slot(codec_dai, 0x00, 0x0, 0x2, bitwidth); 221 - if (ret) { 222 - dev_err(card->dev, "failed to set tdm slot\n"); 223 - return ret; 224 - } 225 - 226 - ret = snd_soc_dai_set_pll(codec_dai, RT5682_PLL1, 227 - RT5682_PLL1_S_BCLK1, 228 - params_rate(params) * 64, 229 - params_rate(params) * 512); 230 - if (ret) { 231 - dev_err(card->dev, "failed to set pll\n"); 232 - return ret; 233 - } 234 - 235 - ret = snd_soc_dai_set_sysclk(codec_dai, 236 - RT5682_SCLK_S_PLL1, 237 - params_rate(params) * 512, 238 - SND_SOC_CLOCK_IN); 239 - if (ret) { 240 - dev_err(card->dev, "failed to set sysclk\n"); 241 - return ret; 242 - } 243 - 244 - return snd_soc_dai_set_sysclk(cpu_dai, 0, mclk_fs, SND_SOC_CLOCK_OUT); 245 - } 246 - 247 - static const struct snd_soc_ops mt8186_rt5682s_i2s_ops = { 248 - .hw_params = mt8186_rt5682s_i2s_hw_params, 249 - }; 250 - 251 - static int mt8186_mt6366_rt1019_rt5682s_hdmi_init(struct snd_soc_pcm_runtime *rtd) 252 - { 253 - struct snd_soc_component *cmpnt_afe = 254 - snd_soc_rtdcom_lookup(rtd, AFE_PCM_NAME); 255 - struct mtk_base_afe *afe = snd_soc_component_get_drvdata(cmpnt_afe); 256 - struct snd_soc_component *cmpnt_codec = 257 - snd_soc_rtd_to_codec(rtd, 0)->component; 258 - struct mtk_soc_card_data *soc_card_data = 259 - snd_soc_card_get_drvdata(rtd->card); 260 - struct mt8186_mt6366_rt1019_rt5682s_priv *priv = soc_card_data->mach_priv; 261 - int ret; 262 - 263 - ret = mt8186_dai_i2s_set_share(afe, "I2S2", "I2S3"); 264 - if (ret) { 265 - dev_err(rtd->dev, "Failed to set up shared clocks\n"); 266 - return ret; 267 - } 268 - 269 - ret = snd_soc_card_jack_new(rtd->card, "HDMI Jack", SND_JACK_LINEOUT, &priv->hdmi_jack); 270 - if (ret) { 271 - dev_err(rtd->dev, "HDMI Jack creation failed: %d\n", ret); 272 - return ret; 273 - } 274 - 275 - return snd_soc_component_set_jack(cmpnt_codec, &priv->hdmi_jack, NULL); 276 - } 277 - 278 - static int mt8186_hw_params_fixup(struct snd_soc_pcm_runtime *rtd, 279 - struct snd_pcm_hw_params *params, 280 - snd_pcm_format_t fmt) 281 - { 282 - struct snd_interval *channels = hw_param_interval(params, 283 - SNDRV_PCM_HW_PARAM_CHANNELS); 284 - 285 - dev_dbg(rtd->dev, "%s(), fix format to %d\n", __func__, fmt); 286 - 287 - /* fix BE i2s channel to 2 channel */ 288 - channels->min = 2; 289 - channels->max = 2; 290 - 291 - /* clean param mask first */ 292 - snd_mask_reset_range(hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT), 293 - 0, (__force unsigned int)SNDRV_PCM_FORMAT_LAST); 294 - 295 - params_set_format(params, fmt); 296 - 297 - return 0; 298 - } 299 - 300 - static int mt8186_i2s_hw_params_fixup(struct snd_soc_pcm_runtime *rtd, 301 - struct snd_pcm_hw_params *params) 302 - { 303 - return mt8186_hw_params_fixup(rtd, params, SNDRV_PCM_FORMAT_S24_LE); 304 - } 305 - 306 - static int mt8186_it6505_i2s_hw_params_fixup(struct snd_soc_pcm_runtime *rtd, 307 - struct snd_pcm_hw_params *params) 308 - { 309 - return mt8186_hw_params_fixup(rtd, params, SNDRV_PCM_FORMAT_S32_LE); 310 - } 311 - 312 - /* fixup the BE DAI link to match any values from topology */ 313 - static int mt8186_sof_dai_link_fixup(struct snd_soc_pcm_runtime *rtd, 314 - struct snd_pcm_hw_params *params) 315 - { 316 - int ret; 317 - 318 - ret = mtk_sof_dai_link_fixup(rtd, params); 319 - 320 - if (!strcmp(rtd->dai_link->name, "I2S0") || 321 - !strcmp(rtd->dai_link->name, "I2S1") || 322 - !strcmp(rtd->dai_link->name, "I2S2")) 323 - mt8186_i2s_hw_params_fixup(rtd, params); 324 - else if (!strcmp(rtd->dai_link->name, "I2S3")) 325 - mt8186_it6505_i2s_hw_params_fixup(rtd, params); 326 - 327 - return ret; 328 - } 329 - 330 - static int mt8186_mt6366_rt1019_rt5682s_playback_startup(struct snd_pcm_substream *substream) 331 - { 332 - static const unsigned int rates[] = { 333 - 48000 334 - }; 335 - static const unsigned int channels[] = { 336 - 2 337 - }; 338 - static const struct snd_pcm_hw_constraint_list constraints_rates = { 339 - .count = ARRAY_SIZE(rates), 340 - .list = rates, 341 - .mask = 0, 342 - }; 343 - static const struct snd_pcm_hw_constraint_list constraints_channels = { 344 - .count = ARRAY_SIZE(channels), 345 - .list = channels, 346 - .mask = 0, 347 - }; 348 - 349 - struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream); 350 - struct snd_pcm_runtime *runtime = substream->runtime; 351 - int ret; 352 - 353 - ret = snd_pcm_hw_constraint_list(runtime, 0, 354 - SNDRV_PCM_HW_PARAM_RATE, 355 - &constraints_rates); 356 - if (ret < 0) { 357 - dev_err(rtd->dev, "hw_constraint_list rate failed\n"); 358 - return ret; 359 - } 360 - 361 - ret = snd_pcm_hw_constraint_list(runtime, 0, 362 - SNDRV_PCM_HW_PARAM_CHANNELS, 363 - &constraints_channels); 364 - if (ret < 0) { 365 - dev_err(rtd->dev, "hw_constraint_list channel failed\n"); 366 - return ret; 367 - } 368 - 369 - return 0; 370 - } 371 - 372 - static const struct snd_soc_ops mt8186_mt6366_rt1019_rt5682s_playback_ops = { 373 - .startup = mt8186_mt6366_rt1019_rt5682s_playback_startup, 374 - }; 375 - 376 - static int mt8186_mt6366_rt1019_rt5682s_capture_startup(struct snd_pcm_substream *substream) 377 - { 378 - static const unsigned int rates[] = { 379 - 48000 380 - }; 381 - static const unsigned int channels[] = { 382 - 1, 2 383 - }; 384 - static const struct snd_pcm_hw_constraint_list constraints_rates = { 385 - .count = ARRAY_SIZE(rates), 386 - .list = rates, 387 - .mask = 0, 388 - }; 389 - static const struct snd_pcm_hw_constraint_list constraints_channels = { 390 - .count = ARRAY_SIZE(channels), 391 - .list = channels, 392 - .mask = 0, 393 - }; 394 - 395 - struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream); 396 - struct snd_pcm_runtime *runtime = substream->runtime; 397 - int ret; 398 - 399 - ret = snd_pcm_hw_constraint_list(runtime, 0, 400 - SNDRV_PCM_HW_PARAM_RATE, 401 - &constraints_rates); 402 - if (ret < 0) { 403 - dev_err(rtd->dev, "hw_constraint_list rate failed\n"); 404 - return ret; 405 - } 406 - 407 - ret = snd_pcm_hw_constraint_list(runtime, 0, 408 - SNDRV_PCM_HW_PARAM_CHANNELS, 409 - &constraints_channels); 410 - if (ret < 0) { 411 - dev_err(rtd->dev, "hw_constraint_list channel failed\n"); 412 - return ret; 413 - } 414 - 415 - return 0; 416 - } 417 - 418 - static const struct snd_soc_ops mt8186_mt6366_rt1019_rt5682s_capture_ops = { 419 - .startup = mt8186_mt6366_rt1019_rt5682s_capture_startup, 420 - }; 421 - 422 - /* FE */ 423 - SND_SOC_DAILINK_DEFS(playback1, 424 - DAILINK_COMP_ARRAY(COMP_CPU("DL1")), 425 - DAILINK_COMP_ARRAY(COMP_DUMMY()), 426 - DAILINK_COMP_ARRAY(COMP_EMPTY())); 427 - 428 - SND_SOC_DAILINK_DEFS(playback12, 429 - DAILINK_COMP_ARRAY(COMP_CPU("DL12")), 430 - DAILINK_COMP_ARRAY(COMP_DUMMY()), 431 - DAILINK_COMP_ARRAY(COMP_EMPTY())); 432 - 433 - SND_SOC_DAILINK_DEFS(playback2, 434 - DAILINK_COMP_ARRAY(COMP_CPU("DL2")), 435 - DAILINK_COMP_ARRAY(COMP_DUMMY()), 436 - DAILINK_COMP_ARRAY(COMP_EMPTY())); 437 - 438 - SND_SOC_DAILINK_DEFS(playback3, 439 - DAILINK_COMP_ARRAY(COMP_CPU("DL3")), 440 - DAILINK_COMP_ARRAY(COMP_DUMMY()), 441 - DAILINK_COMP_ARRAY(COMP_EMPTY())); 442 - 443 - SND_SOC_DAILINK_DEFS(playback4, 444 - DAILINK_COMP_ARRAY(COMP_CPU("DL4")), 445 - DAILINK_COMP_ARRAY(COMP_DUMMY()), 446 - DAILINK_COMP_ARRAY(COMP_EMPTY())); 447 - 448 - SND_SOC_DAILINK_DEFS(playback5, 449 - DAILINK_COMP_ARRAY(COMP_CPU("DL5")), 450 - DAILINK_COMP_ARRAY(COMP_DUMMY()), 451 - DAILINK_COMP_ARRAY(COMP_EMPTY())); 452 - 453 - SND_SOC_DAILINK_DEFS(playback6, 454 - DAILINK_COMP_ARRAY(COMP_CPU("DL6")), 455 - DAILINK_COMP_ARRAY(COMP_DUMMY()), 456 - DAILINK_COMP_ARRAY(COMP_EMPTY())); 457 - 458 - SND_SOC_DAILINK_DEFS(playback7, 459 - DAILINK_COMP_ARRAY(COMP_CPU("DL7")), 460 - DAILINK_COMP_ARRAY(COMP_DUMMY()), 461 - DAILINK_COMP_ARRAY(COMP_EMPTY())); 462 - 463 - SND_SOC_DAILINK_DEFS(playback8, 464 - DAILINK_COMP_ARRAY(COMP_CPU("DL8")), 465 - DAILINK_COMP_ARRAY(COMP_DUMMY()), 466 - DAILINK_COMP_ARRAY(COMP_EMPTY())); 467 - 468 - SND_SOC_DAILINK_DEFS(capture1, 469 - DAILINK_COMP_ARRAY(COMP_CPU("UL1")), 470 - DAILINK_COMP_ARRAY(COMP_DUMMY()), 471 - DAILINK_COMP_ARRAY(COMP_EMPTY())); 472 - 473 - SND_SOC_DAILINK_DEFS(capture2, 474 - DAILINK_COMP_ARRAY(COMP_CPU("UL2")), 475 - DAILINK_COMP_ARRAY(COMP_DUMMY()), 476 - DAILINK_COMP_ARRAY(COMP_EMPTY())); 477 - 478 - SND_SOC_DAILINK_DEFS(capture3, 479 - DAILINK_COMP_ARRAY(COMP_CPU("UL3")), 480 - DAILINK_COMP_ARRAY(COMP_DUMMY()), 481 - DAILINK_COMP_ARRAY(COMP_EMPTY())); 482 - 483 - SND_SOC_DAILINK_DEFS(capture4, 484 - DAILINK_COMP_ARRAY(COMP_CPU("UL4")), 485 - DAILINK_COMP_ARRAY(COMP_DUMMY()), 486 - DAILINK_COMP_ARRAY(COMP_EMPTY())); 487 - 488 - SND_SOC_DAILINK_DEFS(capture5, 489 - DAILINK_COMP_ARRAY(COMP_CPU("UL5")), 490 - DAILINK_COMP_ARRAY(COMP_DUMMY()), 491 - DAILINK_COMP_ARRAY(COMP_EMPTY())); 492 - 493 - SND_SOC_DAILINK_DEFS(capture6, 494 - DAILINK_COMP_ARRAY(COMP_CPU("UL6")), 495 - DAILINK_COMP_ARRAY(COMP_DUMMY()), 496 - DAILINK_COMP_ARRAY(COMP_EMPTY())); 497 - 498 - SND_SOC_DAILINK_DEFS(capture7, 499 - DAILINK_COMP_ARRAY(COMP_CPU("UL7")), 500 - DAILINK_COMP_ARRAY(COMP_DUMMY()), 501 - DAILINK_COMP_ARRAY(COMP_EMPTY())); 502 - 503 - /* hostless */ 504 - SND_SOC_DAILINK_DEFS(hostless_lpbk, 505 - DAILINK_COMP_ARRAY(COMP_CPU("Hostless LPBK DAI")), 506 - DAILINK_COMP_ARRAY(COMP_DUMMY()), 507 - DAILINK_COMP_ARRAY(COMP_EMPTY())); 508 - SND_SOC_DAILINK_DEFS(hostless_fm, 509 - DAILINK_COMP_ARRAY(COMP_CPU("Hostless FM DAI")), 510 - DAILINK_COMP_ARRAY(COMP_DUMMY()), 511 - DAILINK_COMP_ARRAY(COMP_EMPTY())); 512 - SND_SOC_DAILINK_DEFS(hostless_src1, 513 - DAILINK_COMP_ARRAY(COMP_CPU("Hostless_SRC_1_DAI")), 514 - DAILINK_COMP_ARRAY(COMP_DUMMY()), 515 - DAILINK_COMP_ARRAY(COMP_EMPTY())); 516 - SND_SOC_DAILINK_DEFS(hostless_src_bargein, 517 - DAILINK_COMP_ARRAY(COMP_CPU("Hostless_SRC_Bargein_DAI")), 518 - DAILINK_COMP_ARRAY(COMP_DUMMY()), 519 - DAILINK_COMP_ARRAY(COMP_EMPTY())); 520 - 521 - /* BE */ 522 - SND_SOC_DAILINK_DEFS(adda, 523 - DAILINK_COMP_ARRAY(COMP_CPU("ADDA")), 524 - DAILINK_COMP_ARRAY(COMP_CODEC("mt6358-sound", 525 - "mt6358-snd-codec-aif1"), 526 - COMP_CODEC("dmic-codec", 527 - "dmic-hifi")), 528 - DAILINK_COMP_ARRAY(COMP_EMPTY())); 529 - SND_SOC_DAILINK_DEFS(i2s0, 530 - DAILINK_COMP_ARRAY(COMP_CPU("I2S0")), 531 - DAILINK_COMP_ARRAY(COMP_EMPTY()), 532 - DAILINK_COMP_ARRAY(COMP_EMPTY())); 533 - SND_SOC_DAILINK_DEFS(i2s1, 534 - DAILINK_COMP_ARRAY(COMP_CPU("I2S1")), 535 - DAILINK_COMP_ARRAY(COMP_EMPTY()), 536 - DAILINK_COMP_ARRAY(COMP_EMPTY())); 537 - SND_SOC_DAILINK_DEFS(i2s2, 538 - DAILINK_COMP_ARRAY(COMP_CPU("I2S2")), 539 - DAILINK_COMP_ARRAY(COMP_DUMMY()), 540 - DAILINK_COMP_ARRAY(COMP_EMPTY())); 541 - SND_SOC_DAILINK_DEFS(i2s3, 542 - DAILINK_COMP_ARRAY(COMP_CPU("I2S3")), 543 - DAILINK_COMP_ARRAY(COMP_EMPTY()), 544 - DAILINK_COMP_ARRAY(COMP_EMPTY())); 545 - SND_SOC_DAILINK_DEFS(hw_gain1, 546 - DAILINK_COMP_ARRAY(COMP_CPU("HW Gain 1")), 547 - DAILINK_COMP_ARRAY(COMP_DUMMY()), 548 - DAILINK_COMP_ARRAY(COMP_EMPTY())); 549 - SND_SOC_DAILINK_DEFS(hw_gain2, 550 - DAILINK_COMP_ARRAY(COMP_CPU("HW Gain 2")), 551 - DAILINK_COMP_ARRAY(COMP_DUMMY()), 552 - DAILINK_COMP_ARRAY(COMP_EMPTY())); 553 - SND_SOC_DAILINK_DEFS(hw_src1, 554 - DAILINK_COMP_ARRAY(COMP_CPU("HW_SRC_1")), 555 - DAILINK_COMP_ARRAY(COMP_DUMMY()), 556 - DAILINK_COMP_ARRAY(COMP_EMPTY())); 557 - SND_SOC_DAILINK_DEFS(hw_src2, 558 - DAILINK_COMP_ARRAY(COMP_CPU("HW_SRC_2")), 559 - DAILINK_COMP_ARRAY(COMP_DUMMY()), 560 - DAILINK_COMP_ARRAY(COMP_EMPTY())); 561 - SND_SOC_DAILINK_DEFS(connsys_i2s, 562 - DAILINK_COMP_ARRAY(COMP_CPU("CONNSYS_I2S")), 563 - DAILINK_COMP_ARRAY(COMP_DUMMY()), 564 - DAILINK_COMP_ARRAY(COMP_EMPTY())); 565 - SND_SOC_DAILINK_DEFS(pcm1, 566 - DAILINK_COMP_ARRAY(COMP_CPU("PCM 1")), 567 - DAILINK_COMP_ARRAY(COMP_CODEC("bt-sco", "bt-sco-pcm-wb")), 568 - DAILINK_COMP_ARRAY(COMP_EMPTY())); 569 - SND_SOC_DAILINK_DEFS(tdm_in, 570 - DAILINK_COMP_ARRAY(COMP_CPU("TDM IN")), 571 - DAILINK_COMP_ARRAY(COMP_DUMMY()), 572 - DAILINK_COMP_ARRAY(COMP_EMPTY())); 573 - 574 - /* hostless */ 575 - SND_SOC_DAILINK_DEFS(hostless_ul1, 576 - DAILINK_COMP_ARRAY(COMP_CPU("Hostless_UL1 DAI")), 577 - DAILINK_COMP_ARRAY(COMP_DUMMY()), 578 - DAILINK_COMP_ARRAY(COMP_EMPTY())); 579 - SND_SOC_DAILINK_DEFS(hostless_ul2, 580 - DAILINK_COMP_ARRAY(COMP_CPU("Hostless_UL2 DAI")), 581 - DAILINK_COMP_ARRAY(COMP_DUMMY()), 582 - DAILINK_COMP_ARRAY(COMP_EMPTY())); 583 - SND_SOC_DAILINK_DEFS(hostless_ul3, 584 - DAILINK_COMP_ARRAY(COMP_CPU("Hostless_UL3 DAI")), 585 - DAILINK_COMP_ARRAY(COMP_DUMMY()), 586 - DAILINK_COMP_ARRAY(COMP_EMPTY())); 587 - SND_SOC_DAILINK_DEFS(hostless_ul5, 588 - DAILINK_COMP_ARRAY(COMP_CPU("Hostless_UL5 DAI")), 589 - DAILINK_COMP_ARRAY(COMP_DUMMY()), 590 - DAILINK_COMP_ARRAY(COMP_EMPTY())); 591 - SND_SOC_DAILINK_DEFS(hostless_ul6, 592 - DAILINK_COMP_ARRAY(COMP_CPU("Hostless_UL6 DAI")), 593 - DAILINK_COMP_ARRAY(COMP_DUMMY()), 594 - DAILINK_COMP_ARRAY(COMP_EMPTY())); 595 - SND_SOC_DAILINK_DEFS(hostless_hw_gain_aaudio, 596 - DAILINK_COMP_ARRAY(COMP_CPU("Hostless HW Gain AAudio DAI")), 597 - DAILINK_COMP_ARRAY(COMP_DUMMY()), 598 - DAILINK_COMP_ARRAY(COMP_EMPTY())); 599 - SND_SOC_DAILINK_DEFS(hostless_src_aaudio, 600 - DAILINK_COMP_ARRAY(COMP_CPU("Hostless SRC AAudio DAI")), 601 - DAILINK_COMP_ARRAY(COMP_DUMMY()), 602 - DAILINK_COMP_ARRAY(COMP_EMPTY())); 603 - SND_SOC_DAILINK_DEFS(AFE_SOF_DL1, 604 - DAILINK_COMP_ARRAY(COMP_CPU("SOF_DL1")), 605 - DAILINK_COMP_ARRAY(COMP_DUMMY()), 606 - DAILINK_COMP_ARRAY(COMP_EMPTY())); 607 - 608 - SND_SOC_DAILINK_DEFS(AFE_SOF_DL2, 609 - DAILINK_COMP_ARRAY(COMP_CPU("SOF_DL2")), 610 - DAILINK_COMP_ARRAY(COMP_DUMMY()), 611 - DAILINK_COMP_ARRAY(COMP_EMPTY())); 612 - 613 - SND_SOC_DAILINK_DEFS(AFE_SOF_UL1, 614 - DAILINK_COMP_ARRAY(COMP_CPU("SOF_UL1")), 615 - DAILINK_COMP_ARRAY(COMP_DUMMY()), 616 - DAILINK_COMP_ARRAY(COMP_EMPTY())); 617 - 618 - SND_SOC_DAILINK_DEFS(AFE_SOF_UL2, 619 - DAILINK_COMP_ARRAY(COMP_CPU("SOF_UL2")), 620 - DAILINK_COMP_ARRAY(COMP_DUMMY()), 621 - DAILINK_COMP_ARRAY(COMP_EMPTY())); 622 - 623 - static const struct sof_conn_stream g_sof_conn_streams[] = { 624 - { "I2S1", "AFE_SOF_DL1", SOF_DMA_DL1, SNDRV_PCM_STREAM_PLAYBACK}, 625 - { "I2S3", "AFE_SOF_DL2", SOF_DMA_DL2, SNDRV_PCM_STREAM_PLAYBACK}, 626 - { "Primary Codec", "AFE_SOF_UL1", SOF_DMA_UL1, SNDRV_PCM_STREAM_CAPTURE}, 627 - { "I2S0", "AFE_SOF_UL2", SOF_DMA_UL2, SNDRV_PCM_STREAM_CAPTURE}, 628 - }; 629 - 630 - static struct snd_soc_dai_link mt8186_mt6366_rt1019_rt5682s_dai_links[] = { 631 - /* Front End DAI links */ 632 - { 633 - .name = "Playback_1", 634 - .stream_name = "Playback_1", 635 - .trigger = {SND_SOC_DPCM_TRIGGER_PRE, 636 - SND_SOC_DPCM_TRIGGER_PRE}, 637 - .dynamic = 1, 638 - .dpcm_playback = 1, 639 - .dpcm_merged_format = 1, 640 - .dpcm_merged_chan = 1, 641 - .dpcm_merged_rate = 1, 642 - .ops = &mt8186_mt6366_rt1019_rt5682s_playback_ops, 643 - SND_SOC_DAILINK_REG(playback1), 644 - }, 645 - { 646 - .name = "Playback_12", 647 - .stream_name = "Playback_12", 648 - .trigger = {SND_SOC_DPCM_TRIGGER_PRE, 649 - SND_SOC_DPCM_TRIGGER_PRE}, 650 - .dynamic = 1, 651 - .dpcm_playback = 1, 652 - SND_SOC_DAILINK_REG(playback12), 653 - }, 654 - { 655 - .name = "Playback_2", 656 - .stream_name = "Playback_2", 657 - .trigger = {SND_SOC_DPCM_TRIGGER_PRE, 658 - SND_SOC_DPCM_TRIGGER_PRE}, 659 - .dynamic = 1, 660 - .dpcm_playback = 1, 661 - .dpcm_merged_format = 1, 662 - .dpcm_merged_chan = 1, 663 - .dpcm_merged_rate = 1, 664 - SND_SOC_DAILINK_REG(playback2), 665 - }, 666 - { 667 - .name = "Playback_3", 668 - .stream_name = "Playback_3", 669 - .trigger = {SND_SOC_DPCM_TRIGGER_PRE, 670 - SND_SOC_DPCM_TRIGGER_PRE}, 671 - .dynamic = 1, 672 - .dpcm_playback = 1, 673 - .dpcm_merged_format = 1, 674 - .dpcm_merged_chan = 1, 675 - .dpcm_merged_rate = 1, 676 - .ops = &mt8186_mt6366_rt1019_rt5682s_playback_ops, 677 - SND_SOC_DAILINK_REG(playback3), 678 - }, 679 - { 680 - .name = "Playback_4", 681 - .stream_name = "Playback_4", 682 - .trigger = {SND_SOC_DPCM_TRIGGER_PRE, 683 - SND_SOC_DPCM_TRIGGER_PRE}, 684 - .dynamic = 1, 685 - .dpcm_playback = 1, 686 - SND_SOC_DAILINK_REG(playback4), 687 - }, 688 - { 689 - .name = "Playback_5", 690 - .stream_name = "Playback_5", 691 - .trigger = {SND_SOC_DPCM_TRIGGER_PRE, 692 - SND_SOC_DPCM_TRIGGER_PRE}, 693 - .dynamic = 1, 694 - .dpcm_playback = 1, 695 - SND_SOC_DAILINK_REG(playback5), 696 - }, 697 - { 698 - .name = "Playback_6", 699 - .stream_name = "Playback_6", 700 - .trigger = {SND_SOC_DPCM_TRIGGER_PRE, 701 - SND_SOC_DPCM_TRIGGER_PRE}, 702 - .dynamic = 1, 703 - .dpcm_playback = 1, 704 - SND_SOC_DAILINK_REG(playback6), 705 - }, 706 - { 707 - .name = "Playback_7", 708 - .stream_name = "Playback_7", 709 - .trigger = {SND_SOC_DPCM_TRIGGER_PRE, 710 - SND_SOC_DPCM_TRIGGER_PRE}, 711 - .dynamic = 1, 712 - .dpcm_playback = 1, 713 - SND_SOC_DAILINK_REG(playback7), 714 - }, 715 - { 716 - .name = "Playback_8", 717 - .stream_name = "Playback_8", 718 - .trigger = {SND_SOC_DPCM_TRIGGER_PRE, 719 - SND_SOC_DPCM_TRIGGER_PRE}, 720 - .dynamic = 1, 721 - .dpcm_playback = 1, 722 - SND_SOC_DAILINK_REG(playback8), 723 - }, 724 - { 725 - .name = "Capture_1", 726 - .stream_name = "Capture_1", 727 - .trigger = {SND_SOC_DPCM_TRIGGER_PRE, 728 - SND_SOC_DPCM_TRIGGER_PRE}, 729 - .dynamic = 1, 730 - .dpcm_capture = 1, 731 - SND_SOC_DAILINK_REG(capture1), 732 - }, 733 - { 734 - .name = "Capture_2", 735 - .stream_name = "Capture_2", 736 - .trigger = {SND_SOC_DPCM_TRIGGER_PRE, 737 - SND_SOC_DPCM_TRIGGER_PRE}, 738 - .dynamic = 1, 739 - .dpcm_capture = 1, 740 - .dpcm_merged_format = 1, 741 - .dpcm_merged_chan = 1, 742 - .dpcm_merged_rate = 1, 743 - .ops = &mt8186_mt6366_rt1019_rt5682s_capture_ops, 744 - SND_SOC_DAILINK_REG(capture2), 745 - }, 746 - { 747 - .name = "Capture_3", 748 - .stream_name = "Capture_3", 749 - .trigger = {SND_SOC_DPCM_TRIGGER_PRE, 750 - SND_SOC_DPCM_TRIGGER_PRE}, 751 - .dynamic = 1, 752 - .dpcm_capture = 1, 753 - SND_SOC_DAILINK_REG(capture3), 754 - }, 755 - { 756 - .name = "Capture_4", 757 - .stream_name = "Capture_4", 758 - .trigger = {SND_SOC_DPCM_TRIGGER_PRE, 759 - SND_SOC_DPCM_TRIGGER_PRE}, 760 - .dynamic = 1, 761 - .dpcm_capture = 1, 762 - .dpcm_merged_format = 1, 763 - .dpcm_merged_chan = 1, 764 - .dpcm_merged_rate = 1, 765 - .ops = &mt8186_mt6366_rt1019_rt5682s_capture_ops, 766 - SND_SOC_DAILINK_REG(capture4), 767 - }, 768 - { 769 - .name = "Capture_5", 770 - .stream_name = "Capture_5", 771 - .trigger = {SND_SOC_DPCM_TRIGGER_PRE, 772 - SND_SOC_DPCM_TRIGGER_PRE}, 773 - .dynamic = 1, 774 - .dpcm_capture = 1, 775 - SND_SOC_DAILINK_REG(capture5), 776 - }, 777 - { 778 - .name = "Capture_6", 779 - .stream_name = "Capture_6", 780 - .trigger = {SND_SOC_DPCM_TRIGGER_PRE, 781 - SND_SOC_DPCM_TRIGGER_PRE}, 782 - .dynamic = 1, 783 - .dpcm_capture = 1, 784 - .dpcm_merged_format = 1, 785 - .dpcm_merged_chan = 1, 786 - .dpcm_merged_rate = 1, 787 - SND_SOC_DAILINK_REG(capture6), 788 - }, 789 - { 790 - .name = "Capture_7", 791 - .stream_name = "Capture_7", 792 - .trigger = {SND_SOC_DPCM_TRIGGER_PRE, 793 - SND_SOC_DPCM_TRIGGER_PRE}, 794 - .dynamic = 1, 795 - .dpcm_capture = 1, 796 - SND_SOC_DAILINK_REG(capture7), 797 - }, 798 - { 799 - .name = "Hostless_LPBK", 800 - .stream_name = "Hostless_LPBK", 801 - .trigger = {SND_SOC_DPCM_TRIGGER_PRE, 802 - SND_SOC_DPCM_TRIGGER_PRE}, 803 - .dynamic = 1, 804 - .dpcm_playback = 1, 805 - .dpcm_capture = 1, 806 - .ignore_suspend = 1, 807 - SND_SOC_DAILINK_REG(hostless_lpbk), 808 - }, 809 - { 810 - .name = "Hostless_FM", 811 - .stream_name = "Hostless_FM", 812 - .trigger = {SND_SOC_DPCM_TRIGGER_PRE, 813 - SND_SOC_DPCM_TRIGGER_PRE}, 814 - .dynamic = 1, 815 - .dpcm_playback = 1, 816 - .dpcm_capture = 1, 817 - .ignore_suspend = 1, 818 - SND_SOC_DAILINK_REG(hostless_fm), 819 - }, 820 - { 821 - .name = "Hostless_SRC_1", 822 - .stream_name = "Hostless_SRC_1", 823 - .trigger = {SND_SOC_DPCM_TRIGGER_PRE, 824 - SND_SOC_DPCM_TRIGGER_PRE}, 825 - .dynamic = 1, 826 - .dpcm_playback = 1, 827 - .dpcm_capture = 1, 828 - .ignore_suspend = 1, 829 - SND_SOC_DAILINK_REG(hostless_src1), 830 - }, 831 - { 832 - .name = "Hostless_SRC_Bargein", 833 - .stream_name = "Hostless_SRC_Bargein", 834 - .trigger = {SND_SOC_DPCM_TRIGGER_PRE, 835 - SND_SOC_DPCM_TRIGGER_PRE}, 836 - .dynamic = 1, 837 - .dpcm_playback = 1, 838 - .dpcm_capture = 1, 839 - .ignore_suspend = 1, 840 - SND_SOC_DAILINK_REG(hostless_src_bargein), 841 - }, 842 - { 843 - .name = "Hostless_HW_Gain_AAudio", 844 - .stream_name = "Hostless_HW_Gain_AAudio", 845 - .trigger = {SND_SOC_DPCM_TRIGGER_PRE, 846 - SND_SOC_DPCM_TRIGGER_PRE}, 847 - .dynamic = 1, 848 - .dpcm_capture = 1, 849 - .ignore_suspend = 1, 850 - SND_SOC_DAILINK_REG(hostless_hw_gain_aaudio), 851 - }, 852 - { 853 - .name = "Hostless_SRC_AAudio", 854 - .stream_name = "Hostless_SRC_AAudio", 855 - .trigger = {SND_SOC_DPCM_TRIGGER_PRE, 856 - SND_SOC_DPCM_TRIGGER_PRE}, 857 - .dynamic = 1, 858 - .dpcm_playback = 1, 859 - .dpcm_capture = 1, 860 - .ignore_suspend = 1, 861 - SND_SOC_DAILINK_REG(hostless_src_aaudio), 862 - }, 863 - /* Back End DAI links */ 864 - { 865 - .name = "Primary Codec", 866 - .no_pcm = 1, 867 - .dpcm_playback = 1, 868 - .dpcm_capture = 1, 869 - .ignore_suspend = 1, 870 - .init = primary_codec_init, 871 - SND_SOC_DAILINK_REG(adda), 872 - }, 873 - { 874 - .name = "I2S3", 875 - .no_pcm = 1, 876 - .dai_fmt = SND_SOC_DAIFMT_I2S | 877 - SND_SOC_DAIFMT_IB_IF | 878 - SND_SOC_DAIFMT_CBM_CFM, 879 - .dpcm_playback = 1, 880 - .ignore_suspend = 1, 881 - .init = mt8186_mt6366_rt1019_rt5682s_hdmi_init, 882 - .be_hw_params_fixup = mt8186_it6505_i2s_hw_params_fixup, 883 - SND_SOC_DAILINK_REG(i2s3), 884 - }, 885 - { 886 - .name = "I2S0", 887 - .no_pcm = 1, 888 - .dpcm_capture = 1, 889 - .ignore_suspend = 1, 890 - .be_hw_params_fixup = mt8186_i2s_hw_params_fixup, 891 - .ops = &mt8186_rt5682s_i2s_ops, 892 - SND_SOC_DAILINK_REG(i2s0), 893 - }, 894 - { 895 - .name = "I2S1", 896 - .no_pcm = 1, 897 - .dpcm_playback = 1, 898 - .ignore_suspend = 1, 899 - .be_hw_params_fixup = mt8186_i2s_hw_params_fixup, 900 - .init = mt8186_rt5682s_init, 901 - .ops = &mt8186_rt5682s_i2s_ops, 902 - SND_SOC_DAILINK_REG(i2s1), 903 - }, 904 - { 905 - .name = "I2S2", 906 - .no_pcm = 1, 907 - .dpcm_capture = 1, 908 - .ignore_suspend = 1, 909 - .be_hw_params_fixup = mt8186_i2s_hw_params_fixup, 910 - SND_SOC_DAILINK_REG(i2s2), 911 - }, 912 - { 913 - .name = "HW Gain 1", 914 - .no_pcm = 1, 915 - .dpcm_playback = 1, 916 - .dpcm_capture = 1, 917 - .ignore_suspend = 1, 918 - SND_SOC_DAILINK_REG(hw_gain1), 919 - }, 920 - { 921 - .name = "HW Gain 2", 922 - .no_pcm = 1, 923 - .dpcm_playback = 1, 924 - .dpcm_capture = 1, 925 - .ignore_suspend = 1, 926 - SND_SOC_DAILINK_REG(hw_gain2), 927 - }, 928 - { 929 - .name = "HW_SRC_1", 930 - .no_pcm = 1, 931 - .dpcm_playback = 1, 932 - .dpcm_capture = 1, 933 - .ignore_suspend = 1, 934 - SND_SOC_DAILINK_REG(hw_src1), 935 - }, 936 - { 937 - .name = "HW_SRC_2", 938 - .no_pcm = 1, 939 - .dpcm_playback = 1, 940 - .dpcm_capture = 1, 941 - .ignore_suspend = 1, 942 - SND_SOC_DAILINK_REG(hw_src2), 943 - }, 944 - { 945 - .name = "CONNSYS_I2S", 946 - .no_pcm = 1, 947 - .dpcm_capture = 1, 948 - .ignore_suspend = 1, 949 - SND_SOC_DAILINK_REG(connsys_i2s), 950 - }, 951 - { 952 - .name = "PCM 1", 953 - .dai_fmt = SND_SOC_DAIFMT_I2S | 954 - SND_SOC_DAIFMT_NB_IF, 955 - .no_pcm = 1, 956 - .dpcm_playback = 1, 957 - .dpcm_capture = 1, 958 - .ignore_suspend = 1, 959 - SND_SOC_DAILINK_REG(pcm1), 960 - }, 961 - { 962 - .name = "TDM IN", 963 - .no_pcm = 1, 964 - .dpcm_capture = 1, 965 - .ignore_suspend = 1, 966 - SND_SOC_DAILINK_REG(tdm_in), 967 - }, 968 - /* dummy BE for ul memif to record from dl memif */ 969 - { 970 - .name = "Hostless_UL1", 971 - .no_pcm = 1, 972 - .dpcm_capture = 1, 973 - .ignore_suspend = 1, 974 - SND_SOC_DAILINK_REG(hostless_ul1), 975 - }, 976 - { 977 - .name = "Hostless_UL2", 978 - .no_pcm = 1, 979 - .dpcm_capture = 1, 980 - .ignore_suspend = 1, 981 - SND_SOC_DAILINK_REG(hostless_ul2), 982 - }, 983 - { 984 - .name = "Hostless_UL3", 985 - .no_pcm = 1, 986 - .dpcm_capture = 1, 987 - .ignore_suspend = 1, 988 - SND_SOC_DAILINK_REG(hostless_ul3), 989 - }, 990 - { 991 - .name = "Hostless_UL5", 992 - .no_pcm = 1, 993 - .dpcm_capture = 1, 994 - .ignore_suspend = 1, 995 - SND_SOC_DAILINK_REG(hostless_ul5), 996 - }, 997 - { 998 - .name = "Hostless_UL6", 999 - .no_pcm = 1, 1000 - .dpcm_capture = 1, 1001 - .ignore_suspend = 1, 1002 - SND_SOC_DAILINK_REG(hostless_ul6), 1003 - }, 1004 - /* SOF BE */ 1005 - { 1006 - .name = "AFE_SOF_DL1", 1007 - .no_pcm = 1, 1008 - .dpcm_playback = 1, 1009 - SND_SOC_DAILINK_REG(AFE_SOF_DL1), 1010 - }, 1011 - { 1012 - .name = "AFE_SOF_DL2", 1013 - .no_pcm = 1, 1014 - .dpcm_playback = 1, 1015 - SND_SOC_DAILINK_REG(AFE_SOF_DL2), 1016 - }, 1017 - { 1018 - .name = "AFE_SOF_UL1", 1019 - .no_pcm = 1, 1020 - .dpcm_capture = 1, 1021 - SND_SOC_DAILINK_REG(AFE_SOF_UL1), 1022 - }, 1023 - { 1024 - .name = "AFE_SOF_UL2", 1025 - .no_pcm = 1, 1026 - .dpcm_capture = 1, 1027 - SND_SOC_DAILINK_REG(AFE_SOF_UL2), 1028 - }, 1029 - }; 1030 - 1031 - static const struct snd_soc_dapm_widget 1032 - mt8186_mt6366_rt1019_rt5682s_widgets[] = { 1033 - SND_SOC_DAPM_SPK("Speakers", NULL), 1034 - SND_SOC_DAPM_HP("Headphone", NULL), 1035 - SND_SOC_DAPM_MIC("Headset Mic", NULL), 1036 - SND_SOC_DAPM_OUTPUT("HDMI1"), 1037 - SND_SOC_DAPM_MIXER(SOF_DMA_DL1, SND_SOC_NOPM, 0, 0, NULL, 0), 1038 - SND_SOC_DAPM_MIXER(SOF_DMA_DL2, SND_SOC_NOPM, 0, 0, NULL, 0), 1039 - SND_SOC_DAPM_MIXER(SOF_DMA_UL1, SND_SOC_NOPM, 0, 0, NULL, 0), 1040 - SND_SOC_DAPM_MIXER(SOF_DMA_UL2, SND_SOC_NOPM, 0, 0, NULL, 0), 1041 - }; 1042 - 1043 - static const struct snd_soc_dapm_route 1044 - mt8186_mt6366_rt1019_rt5682s_routes[] = { 1045 - /* SPK */ 1046 - { "Speakers", NULL, "Speaker" }, 1047 - /* Headset */ 1048 - { "Headphone", NULL, "HPOL" }, 1049 - { "Headphone", NULL, "HPOR" }, 1050 - { "IN1P", NULL, "Headset Mic" }, 1051 - /* HDMI */ 1052 - { "HDMI1", NULL, "TX" }, 1053 - /* SOF Uplink */ 1054 - {SOF_DMA_UL1, NULL, "UL1_CH1"}, 1055 - {SOF_DMA_UL1, NULL, "UL1_CH2"}, 1056 - {SOF_DMA_UL2, NULL, "UL2_CH1"}, 1057 - {SOF_DMA_UL2, NULL, "UL2_CH2"}, 1058 - /* SOF Downlink */ 1059 - {"DSP_DL1_VIRT", NULL, SOF_DMA_DL1}, 1060 - {"DSP_DL2_VIRT", NULL, SOF_DMA_DL2}, 1061 - }; 1062 - 1063 - static const struct snd_soc_dapm_route mt8186_mt6366_rt5650_routes[] = { 1064 - /* SPK */ 1065 - {"Speakers", NULL, "SPOL"}, 1066 - {"Speakers", NULL, "SPOR"}, 1067 - /* Headset */ 1068 - { "Headphone", NULL, "HPOL" }, 1069 - { "Headphone", NULL, "HPOR" }, 1070 - { "IN1P", NULL, "Headset Mic" }, 1071 - { "IN1N", NULL, "Headset Mic"}, 1072 - /* HDMI */ 1073 - { "HDMI1", NULL, "TX" }, 1074 - /* SOF Uplink */ 1075 - {SOF_DMA_UL1, NULL, "UL1_CH1"}, 1076 - {SOF_DMA_UL1, NULL, "UL1_CH2"}, 1077 - {SOF_DMA_UL2, NULL, "UL2_CH1"}, 1078 - {SOF_DMA_UL2, NULL, "UL2_CH2"}, 1079 - /* SOF Downlink */ 1080 - {"DSP_DL1_VIRT", NULL, SOF_DMA_DL1}, 1081 - {"DSP_DL2_VIRT", NULL, SOF_DMA_DL2}, 1082 - }; 1083 - 1084 - static const struct snd_kcontrol_new 1085 - mt8186_mt6366_rt1019_rt5682s_controls[] = { 1086 - SOC_DAPM_PIN_SWITCH("Speakers"), 1087 - SOC_DAPM_PIN_SWITCH("Headphone"), 1088 - SOC_DAPM_PIN_SWITCH("Headset Mic"), 1089 - SOC_DAPM_PIN_SWITCH("HDMI1"), 1090 - }; 1091 - 1092 - static struct snd_soc_card mt8186_mt6366_rt1019_rt5682s_soc_card = { 1093 - .name = "mt8186_rt1019_rt5682s", 1094 - .owner = THIS_MODULE, 1095 - .dai_link = mt8186_mt6366_rt1019_rt5682s_dai_links, 1096 - .num_links = ARRAY_SIZE(mt8186_mt6366_rt1019_rt5682s_dai_links), 1097 - .controls = mt8186_mt6366_rt1019_rt5682s_controls, 1098 - .num_controls = ARRAY_SIZE(mt8186_mt6366_rt1019_rt5682s_controls), 1099 - .dapm_widgets = mt8186_mt6366_rt1019_rt5682s_widgets, 1100 - .num_dapm_widgets = ARRAY_SIZE(mt8186_mt6366_rt1019_rt5682s_widgets), 1101 - .dapm_routes = mt8186_mt6366_rt1019_rt5682s_routes, 1102 - .num_dapm_routes = ARRAY_SIZE(mt8186_mt6366_rt1019_rt5682s_routes), 1103 - .codec_conf = mt8186_mt6366_rt1019_rt5682s_codec_conf, 1104 - .num_configs = ARRAY_SIZE(mt8186_mt6366_rt1019_rt5682s_codec_conf), 1105 - }; 1106 - 1107 - static struct snd_soc_card mt8186_mt6366_rt5682s_max98360_soc_card = { 1108 - .name = "mt8186_rt5682s_max98360", 1109 - .owner = THIS_MODULE, 1110 - .dai_link = mt8186_mt6366_rt1019_rt5682s_dai_links, 1111 - .num_links = ARRAY_SIZE(mt8186_mt6366_rt1019_rt5682s_dai_links), 1112 - .controls = mt8186_mt6366_rt1019_rt5682s_controls, 1113 - .num_controls = ARRAY_SIZE(mt8186_mt6366_rt1019_rt5682s_controls), 1114 - .dapm_widgets = mt8186_mt6366_rt1019_rt5682s_widgets, 1115 - .num_dapm_widgets = ARRAY_SIZE(mt8186_mt6366_rt1019_rt5682s_widgets), 1116 - .dapm_routes = mt8186_mt6366_rt1019_rt5682s_routes, 1117 - .num_dapm_routes = ARRAY_SIZE(mt8186_mt6366_rt1019_rt5682s_routes), 1118 - .codec_conf = mt8186_mt6366_rt1019_rt5682s_codec_conf, 1119 - .num_configs = ARRAY_SIZE(mt8186_mt6366_rt1019_rt5682s_codec_conf), 1120 - }; 1121 - 1122 - static struct snd_soc_card mt8186_mt6366_rt5650_soc_card = { 1123 - .name = "mt8186_rt5650", 1124 - .owner = THIS_MODULE, 1125 - .dai_link = mt8186_mt6366_rt1019_rt5682s_dai_links, 1126 - .num_links = ARRAY_SIZE(mt8186_mt6366_rt1019_rt5682s_dai_links), 1127 - .controls = mt8186_mt6366_rt1019_rt5682s_controls, 1128 - .num_controls = ARRAY_SIZE(mt8186_mt6366_rt1019_rt5682s_controls), 1129 - .dapm_widgets = mt8186_mt6366_rt1019_rt5682s_widgets, 1130 - .num_dapm_widgets = ARRAY_SIZE(mt8186_mt6366_rt1019_rt5682s_widgets), 1131 - .dapm_routes = mt8186_mt6366_rt5650_routes, 1132 - .num_dapm_routes = ARRAY_SIZE(mt8186_mt6366_rt5650_routes), 1133 - .codec_conf = mt8186_mt6366_rt1019_rt5682s_codec_conf, 1134 - .num_configs = ARRAY_SIZE(mt8186_mt6366_rt1019_rt5682s_codec_conf), 1135 - }; 1136 - 1137 - static int mt8186_mt6366_rt1019_rt5682s_dev_probe(struct platform_device *pdev) 1138 - { 1139 - struct snd_soc_card *card; 1140 - struct snd_soc_dai_link *dai_link; 1141 - struct mtk_soc_card_data *soc_card_data; 1142 - struct mt8186_mt6366_rt1019_rt5682s_priv *mach_priv; 1143 - struct device_node *platform_node, *headset_codec, *playback_codec, *adsp_node; 1144 - int sof_on = 0; 1145 - int ret, i; 1146 - 1147 - card = (struct snd_soc_card *)device_get_match_data(&pdev->dev); 1148 - if (!card) 1149 - return -EINVAL; 1150 - card->dev = &pdev->dev; 1151 - 1152 - soc_card_data = devm_kzalloc(&pdev->dev, sizeof(*soc_card_data), GFP_KERNEL); 1153 - if (!soc_card_data) 1154 - return -ENOMEM; 1155 - mach_priv = devm_kzalloc(&pdev->dev, sizeof(*mach_priv), GFP_KERNEL); 1156 - if (!mach_priv) 1157 - return -ENOMEM; 1158 - 1159 - soc_card_data->mach_priv = mach_priv; 1160 - 1161 - mach_priv->dmic_sel = devm_gpiod_get_optional(&pdev->dev, 1162 - "dmic", GPIOD_OUT_LOW); 1163 - if (IS_ERR(mach_priv->dmic_sel)) { 1164 - dev_err(&pdev->dev, "DMIC gpio failed err=%ld\n", 1165 - PTR_ERR(mach_priv->dmic_sel)); 1166 - return PTR_ERR(mach_priv->dmic_sel); 1167 - } 1168 - 1169 - adsp_node = of_parse_phandle(pdev->dev.of_node, "mediatek,adsp", 0); 1170 - if (adsp_node) { 1171 - struct mtk_sof_priv *sof_priv; 1172 - 1173 - sof_priv = devm_kzalloc(&pdev->dev, sizeof(*sof_priv), GFP_KERNEL); 1174 - if (!sof_priv) { 1175 - ret = -ENOMEM; 1176 - goto err_adsp_node; 1177 - } 1178 - sof_priv->conn_streams = g_sof_conn_streams; 1179 - sof_priv->num_streams = ARRAY_SIZE(g_sof_conn_streams); 1180 - sof_priv->sof_dai_link_fixup = mt8186_sof_dai_link_fixup; 1181 - soc_card_data->sof_priv = sof_priv; 1182 - card->probe = mtk_sof_card_probe; 1183 - card->late_probe = mtk_sof_card_late_probe; 1184 - if (!card->topology_shortname_created) { 1185 - snprintf(card->topology_shortname, 32, "sof-%s", card->name); 1186 - card->topology_shortname_created = true; 1187 - } 1188 - card->name = card->topology_shortname; 1189 - sof_on = 1; 1190 - } else { 1191 - dev_dbg(&pdev->dev, "Probe without adsp\n"); 1192 - } 1193 - 1194 - if (of_property_read_bool(pdev->dev.of_node, "mediatek,dai-link")) { 1195 - ret = mtk_sof_dailink_parse_of(card, pdev->dev.of_node, 1196 - "mediatek,dai-link", 1197 - mt8186_mt6366_rt1019_rt5682s_dai_links, 1198 - ARRAY_SIZE(mt8186_mt6366_rt1019_rt5682s_dai_links)); 1199 - if (ret) { 1200 - dev_dbg(&pdev->dev, "Parse dai-link fail\n"); 1201 - goto err_adsp_node; 1202 - } 1203 - } else { 1204 - if (!sof_on) 1205 - card->num_links = ARRAY_SIZE(mt8186_mt6366_rt1019_rt5682s_dai_links) 1206 - - ARRAY_SIZE(g_sof_conn_streams); 1207 - } 1208 - 1209 - platform_node = of_parse_phandle(pdev->dev.of_node, "mediatek,platform", 0); 1210 - if (!platform_node) { 1211 - ret = -EINVAL; 1212 - dev_err_probe(&pdev->dev, ret, "Property 'platform' missing or invalid\n"); 1213 - goto err_platform_node; 1214 - } 1215 - 1216 - playback_codec = of_get_child_by_name(pdev->dev.of_node, "playback-codecs"); 1217 - if (!playback_codec) { 1218 - ret = -EINVAL; 1219 - dev_err_probe(&pdev->dev, ret, "Property 'playback-codecs' missing or invalid\n"); 1220 - goto err_playback_codec; 1221 - } 1222 - 1223 - headset_codec = of_get_child_by_name(pdev->dev.of_node, "headset-codec"); 1224 - if (!headset_codec) { 1225 - ret = -EINVAL; 1226 - dev_err_probe(&pdev->dev, ret, "Property 'headset-codec' missing or invalid\n"); 1227 - goto err_headset_codec; 1228 - } 1229 - 1230 - for_each_card_prelinks(card, i, dai_link) { 1231 - ret = mt8186_mt6366_card_set_be_link(card, dai_link, playback_codec, "I2S3"); 1232 - if (ret) { 1233 - dev_err_probe(&pdev->dev, ret, "%s set playback_codec fail\n", 1234 - dai_link->name); 1235 - goto err_probe; 1236 - } 1237 - 1238 - ret = mt8186_mt6366_card_set_be_link(card, dai_link, headset_codec, "I2S0"); 1239 - if (ret) { 1240 - dev_err_probe(&pdev->dev, ret, "%s set headset_codec fail\n", 1241 - dai_link->name); 1242 - goto err_probe; 1243 - } 1244 - 1245 - ret = mt8186_mt6366_card_set_be_link(card, dai_link, headset_codec, "I2S1"); 1246 - if (ret) { 1247 - dev_err_probe(&pdev->dev, ret, "%s set headset_codec fail\n", 1248 - dai_link->name); 1249 - goto err_probe; 1250 - } 1251 - 1252 - if (!strncmp(dai_link->name, "AFE_SOF", strlen("AFE_SOF")) && sof_on) 1253 - dai_link->platforms->of_node = adsp_node; 1254 - 1255 - if (!dai_link->platforms->name && !dai_link->platforms->of_node) 1256 - dai_link->platforms->of_node = platform_node; 1257 - } 1258 - 1259 - snd_soc_card_set_drvdata(card, soc_card_data); 1260 - 1261 - ret = mt8186_afe_gpio_init(&pdev->dev); 1262 - if (ret) { 1263 - dev_err_probe(&pdev->dev, ret, "%s init gpio error\n", __func__); 1264 - goto err_probe; 1265 - } 1266 - 1267 - ret = devm_snd_soc_register_card(&pdev->dev, card); 1268 - if (ret) 1269 - dev_err_probe(&pdev->dev, ret, "%s snd_soc_register_card fail\n", __func__); 1270 - 1271 - err_probe: 1272 - of_node_put(headset_codec); 1273 - err_headset_codec: 1274 - of_node_put(playback_codec); 1275 - err_playback_codec: 1276 - of_node_put(platform_node); 1277 - err_platform_node: 1278 - err_adsp_node: 1279 - of_node_put(adsp_node); 1280 - 1281 - return ret; 1282 - } 1283 - 1284 - #if IS_ENABLED(CONFIG_OF) 1285 - static const struct of_device_id mt8186_mt6366_rt1019_rt5682s_dt_match[] = { 1286 - { 1287 - .compatible = "mediatek,mt8186-mt6366-rt1019-rt5682s-sound", 1288 - .data = &mt8186_mt6366_rt1019_rt5682s_soc_card, 1289 - }, 1290 - { 1291 - .compatible = "mediatek,mt8186-mt6366-rt5682s-max98360-sound", 1292 - .data = &mt8186_mt6366_rt5682s_max98360_soc_card, 1293 - }, 1294 - { 1295 - .compatible = "mediatek,mt8186-mt6366-rt5650-sound", 1296 - .data = &mt8186_mt6366_rt5650_soc_card, 1297 - }, 1298 - {} 1299 - }; 1300 - MODULE_DEVICE_TABLE(of, mt8186_mt6366_rt1019_rt5682s_dt_match); 1301 - #endif 1302 - 1303 - static struct platform_driver mt8186_mt6366_rt1019_rt5682s_driver = { 1304 - .driver = { 1305 - .name = "mt8186_mt6366_rt1019_rt5682s", 1306 - #if IS_ENABLED(CONFIG_OF) 1307 - .of_match_table = mt8186_mt6366_rt1019_rt5682s_dt_match, 1308 - #endif 1309 - .pm = &snd_soc_pm_ops, 1310 - }, 1311 - .probe = mt8186_mt6366_rt1019_rt5682s_dev_probe, 1312 - }; 1313 - 1314 - module_platform_driver(mt8186_mt6366_rt1019_rt5682s_driver); 1315 - 1316 - /* Module information */ 1317 - MODULE_DESCRIPTION("MT8186-MT6366-RT1019-RT5682S ALSA SoC machine driver"); 1318 - MODULE_AUTHOR("Jiaxin Yu <jiaxin.yu@mediatek.com>"); 1319 - MODULE_LICENSE("GPL v2"); 1320 - MODULE_ALIAS("mt8186_mt6366_rt1019_rt5682s soc card");
+1 -20
sound/soc/mediatek/mt8188/mt8188-afe-pcm.c
··· 3030 3030 return 0; 3031 3031 } 3032 3032 3033 - static int mt8188_afe_component_probe(struct snd_soc_component *component) 3034 - { 3035 - struct mtk_base_afe *afe = snd_soc_component_get_drvdata(component); 3036 - int ret; 3037 - 3038 - snd_soc_component_init_regmap(component, afe->regmap); 3039 - 3040 - ret = mtk_afe_add_sub_dai_control(component); 3041 - 3042 - return ret; 3043 - } 3044 - 3045 - static const struct snd_soc_component_driver mt8188_afe_component = { 3046 - .name = AFE_PCM_NAME, 3047 - .pointer = mtk_afe_pcm_pointer, 3048 - .pcm_construct = mtk_afe_pcm_new, 3049 - .probe = mt8188_afe_component_probe, 3050 - }; 3051 - 3052 3033 static int init_memif_priv_data(struct mtk_base_afe *afe) 3053 3034 { 3054 3035 struct mt8188_afe_private *afe_priv = afe->platform_priv; ··· 3331 3350 } 3332 3351 3333 3352 /* register component */ 3334 - ret = devm_snd_soc_register_component(dev, &mt8188_afe_component, 3353 + ret = devm_snd_soc_register_component(dev, &mtk_afe_pcm_platform, 3335 3354 afe->dai_drivers, afe->num_dai_drivers); 3336 3355 if (ret) { 3337 3356 dev_warn(dev, "err_platform\n");
+64 -139
sound/soc/mediatek/mt8188/mt8188-mt6359.c
··· 236 236 }, 237 237 }; 238 238 239 - struct mt8188_mt6359_priv { 240 - struct snd_soc_jack dp_jack; 241 - struct snd_soc_jack hdmi_jack; 242 - struct snd_soc_jack headset_jack; 243 - void *private_data; 239 + enum mt8188_jacks { 240 + MT8188_JACK_HEADSET, 241 + MT8188_JACK_DP, 242 + MT8188_JACK_HDMI, 243 + MT8188_JACK_MAX, 244 244 }; 245 245 246 246 static struct snd_soc_jack_pin mt8188_hdmi_jack_pins[] = { ··· 266 266 .pin = "Headset Mic", 267 267 .mask = SND_JACK_MICROPHONE, 268 268 }, 269 - }; 270 - 271 - struct mt8188_card_data { 272 - const char *name; 273 - unsigned long quirk; 274 269 }; 275 270 276 271 static const struct snd_kcontrol_new mt8188_dumb_spk_controls[] = { ··· 585 590 static int mt8188_hdmi_codec_init(struct snd_soc_pcm_runtime *rtd) 586 591 { 587 592 struct mtk_soc_card_data *soc_card_data = snd_soc_card_get_drvdata(rtd->card); 588 - struct mt8188_mt6359_priv *priv = soc_card_data->mach_priv; 593 + struct snd_soc_jack *jack = &soc_card_data->card_data->jacks[MT8188_JACK_HDMI]; 589 594 struct snd_soc_component *component = snd_soc_rtd_to_codec(rtd, 0)->component; 590 595 int ret = 0; 591 596 592 597 ret = snd_soc_card_jack_new_pins(rtd->card, "HDMI Jack", 593 - SND_JACK_LINEOUT, &priv->hdmi_jack, 598 + SND_JACK_LINEOUT, jack, 594 599 mt8188_hdmi_jack_pins, 595 600 ARRAY_SIZE(mt8188_hdmi_jack_pins)); 596 601 if (ret) { ··· 598 603 return ret; 599 604 } 600 605 601 - ret = snd_soc_component_set_jack(component, &priv->hdmi_jack, NULL); 606 + ret = snd_soc_component_set_jack(component, jack, NULL); 602 607 if (ret) { 603 608 dev_err(rtd->dev, "%s, set jack failed on %s (ret=%d)\n", 604 609 __func__, component->name, ret); ··· 611 616 static int mt8188_dptx_codec_init(struct snd_soc_pcm_runtime *rtd) 612 617 { 613 618 struct mtk_soc_card_data *soc_card_data = snd_soc_card_get_drvdata(rtd->card); 614 - struct mt8188_mt6359_priv *priv = soc_card_data->mach_priv; 619 + struct snd_soc_jack *jack = &soc_card_data->card_data->jacks[MT8188_JACK_DP]; 615 620 struct snd_soc_component *component = snd_soc_rtd_to_codec(rtd, 0)->component; 616 621 int ret = 0; 617 622 618 623 ret = snd_soc_card_jack_new_pins(rtd->card, "DP Jack", SND_JACK_LINEOUT, 619 - &priv->dp_jack, mt8188_dp_jack_pins, 624 + jack, mt8188_dp_jack_pins, 620 625 ARRAY_SIZE(mt8188_dp_jack_pins)); 621 626 if (ret) { 622 627 dev_err(rtd->dev, "%s, new jack failed: %d\n", __func__, ret); 623 628 return ret; 624 629 } 625 630 626 - ret = snd_soc_component_set_jack(component, &priv->dp_jack, NULL); 631 + ret = snd_soc_component_set_jack(component, jack, NULL); 627 632 if (ret) { 628 633 dev_err(rtd->dev, "%s, set jack failed on %s (ret=%d)\n", 629 634 __func__, component->name, ret); ··· 731 736 static int mt8188_headset_codec_init(struct snd_soc_pcm_runtime *rtd) 732 737 { 733 738 struct snd_soc_card *card = rtd->card; 734 - struct mtk_soc_card_data *soc_card_data = snd_soc_card_get_drvdata(card); 735 - struct mt8188_mt6359_priv *priv = soc_card_data->mach_priv; 739 + struct mtk_soc_card_data *soc_card_data = snd_soc_card_get_drvdata(rtd->card); 740 + struct snd_soc_jack *jack = &soc_card_data->card_data->jacks[MT8188_JACK_HEADSET]; 736 741 struct snd_soc_component *component = snd_soc_rtd_to_codec(rtd, 0)->component; 737 - struct snd_soc_jack *jack = &priv->headset_jack; 738 742 int ret; 739 743 740 744 ret = snd_soc_dapm_new_controls(&card->dapm, mt8188_nau8825_widgets, ··· 1218 1224 static void mt8188_fixup_controls(struct snd_soc_card *card) 1219 1225 { 1220 1226 struct mtk_soc_card_data *soc_card_data = snd_soc_card_get_drvdata(card); 1221 - struct mt8188_mt6359_priv *priv = soc_card_data->mach_priv; 1222 - struct mt8188_card_data *card_data = (struct mt8188_card_data *)priv->private_data; 1227 + struct mtk_platform_card_data *card_data = soc_card_data->card_data; 1223 1228 struct snd_kcontrol *kctl; 1224 1229 1225 - if (card_data->quirk & (NAU8825_HS_PRESENT | RT5682S_HS_PRESENT | ES8326_HS_PRESENT)) { 1230 + if (card_data->flags & (NAU8825_HS_PRESENT | RT5682S_HS_PRESENT | ES8326_HS_PRESENT)) { 1226 1231 struct snd_soc_dapm_widget *w, *next_w; 1227 1232 1228 1233 for_each_card_widgets_safe(card, w, next_w) { ··· 1252 1259 .fixup_controls = mt8188_fixup_controls, 1253 1260 }; 1254 1261 1255 - static int mt8188_mt6359_dev_probe(struct platform_device *pdev) 1262 + static int mt8188_mt6359_soc_card_probe(struct mtk_soc_card_data *soc_card_data, bool legacy) 1256 1263 { 1257 - struct snd_soc_card *card = &mt8188_mt6359_soc_card; 1258 - struct device_node *platform_node; 1259 - struct device_node *adsp_node; 1260 - struct mtk_soc_card_data *soc_card_data; 1261 - struct mt8188_mt6359_priv *priv; 1262 - struct mt8188_card_data *card_data; 1264 + struct mtk_platform_card_data *card_data = soc_card_data->card_data; 1265 + struct snd_soc_card *card = soc_card_data->card_data->card; 1263 1266 struct snd_soc_dai_link *dai_link; 1264 1267 bool init_mt6359 = false; 1265 1268 bool init_es8326 = false; ··· 1263 1274 bool init_rt5682s = false; 1264 1275 bool init_max98390 = false; 1265 1276 bool init_dumb = false; 1266 - int ret, i; 1277 + int i; 1267 1278 1268 - card_data = (struct mt8188_card_data *)of_device_get_match_data(&pdev->dev); 1269 - card->dev = &pdev->dev; 1270 - 1271 - ret = snd_soc_of_parse_card_name(card, "model"); 1272 - if (ret) 1273 - return dev_err_probe(&pdev->dev, ret, "%s new card name parsing error\n", 1274 - __func__); 1275 - 1276 - if (!card->name) 1277 - card->name = card_data->name; 1278 - 1279 - if (of_property_read_bool(pdev->dev.of_node, "audio-routing")) { 1280 - ret = snd_soc_of_parse_audio_routing(card, "audio-routing"); 1281 - if (ret) 1282 - return ret; 1283 - } 1284 - 1285 - priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); 1286 - if (!priv) 1287 - return -ENOMEM; 1288 - 1289 - soc_card_data = devm_kzalloc(&pdev->dev, sizeof(*card_data), GFP_KERNEL); 1290 - if (!soc_card_data) 1291 - return -ENOMEM; 1292 - 1293 - soc_card_data->mach_priv = priv; 1294 - 1295 - adsp_node = of_parse_phandle(pdev->dev.of_node, "mediatek,adsp", 0); 1296 - if (adsp_node) { 1297 - struct mtk_sof_priv *sof_priv; 1298 - 1299 - sof_priv = devm_kzalloc(&pdev->dev, sizeof(*sof_priv), GFP_KERNEL); 1300 - if (!sof_priv) { 1301 - ret = -ENOMEM; 1302 - goto err_adsp_node; 1303 - } 1304 - sof_priv->conn_streams = g_sof_conn_streams; 1305 - sof_priv->num_streams = ARRAY_SIZE(g_sof_conn_streams); 1306 - soc_card_data->sof_priv = sof_priv; 1307 - card->probe = mtk_sof_card_probe; 1308 - card->late_probe = mtk_sof_card_late_probe; 1309 - if (!card->topology_shortname_created) { 1310 - snprintf(card->topology_shortname, 32, "sof-%s", card->name); 1311 - card->topology_shortname_created = true; 1312 - } 1313 - card->name = card->topology_shortname; 1314 - } 1315 - 1316 - if (of_property_read_bool(pdev->dev.of_node, "mediatek,dai-link")) { 1317 - ret = mtk_sof_dailink_parse_of(card, pdev->dev.of_node, 1318 - "mediatek,dai-link", 1319 - mt8188_mt6359_dai_links, 1320 - ARRAY_SIZE(mt8188_mt6359_dai_links)); 1321 - if (ret) { 1322 - dev_err_probe(&pdev->dev, ret, "Parse dai-link fail\n"); 1323 - goto err_adsp_node; 1324 - } 1325 - } else { 1326 - if (!adsp_node) 1327 - card->num_links = DAI_LINK_REGULAR_NUM; 1328 - } 1329 - 1330 - platform_node = of_parse_phandle(pdev->dev.of_node, 1331 - "mediatek,platform", 0); 1332 - if (!platform_node) { 1333 - ret = dev_err_probe(&pdev->dev, -EINVAL, 1334 - "Property 'platform' missing or invalid\n"); 1335 - goto err_adsp_node; 1336 - 1337 - } 1338 - 1339 - ret = parse_dai_link_info(card); 1340 - if (ret) 1341 - goto err; 1279 + if (legacy) 1280 + return -EINVAL; 1342 1281 1343 1282 for_each_card_prelinks(card, i, dai_link) { 1344 - if (!dai_link->platforms->name) { 1345 - if (!strncmp(dai_link->name, "AFE_SOF", strlen("AFE_SOF")) && adsp_node) 1346 - dai_link->platforms->of_node = adsp_node; 1347 - else 1348 - dai_link->platforms->of_node = platform_node; 1349 - } 1350 - 1351 1283 if (strcmp(dai_link->name, "DPTX_BE") == 0) { 1352 1284 if (strcmp(dai_link->codecs->dai_name, "snd-soc-dummy-dai")) 1353 1285 dai_link->init = mt8188_dptx_codec_init; ··· 1291 1381 * mt8188_max98390_ops. Two amps is I2S mode, 1292 1382 * SOC and codec don't require TDM settings. 1293 1383 */ 1294 - if (!(card_data->quirk & MAX98390_TWO_AMP)) { 1384 + if (!(card_data->flags & MAX98390_TWO_AMP)) { 1295 1385 dai_link->ops = &mt8188_max98390_ops; 1296 1386 } 1297 1387 if (!init_max98390) { ··· 1330 1420 } 1331 1421 } 1332 1422 1333 - priv->private_data = card_data; 1334 - snd_soc_card_set_drvdata(card, soc_card_data); 1335 - 1336 - ret = devm_snd_soc_register_card(&pdev->dev, card); 1337 - if (ret) 1338 - dev_err_probe(&pdev->dev, ret, "%s snd_soc_register_card fail\n", 1339 - __func__); 1340 - err: 1341 - of_node_put(platform_node); 1342 - clean_card_reference(card); 1343 - 1344 - err_adsp_node: 1345 - of_node_put(adsp_node); 1346 - 1347 - return ret; 1423 + return 0; 1348 1424 } 1349 1425 1350 - static struct mt8188_card_data mt8188_evb_card = { 1351 - .name = "mt8188_mt6359", 1426 + static const struct mtk_sof_priv mt8188_sof_priv = { 1427 + .conn_streams = g_sof_conn_streams, 1428 + .num_streams = ARRAY_SIZE(g_sof_conn_streams), 1352 1429 }; 1353 1430 1354 - static struct mt8188_card_data mt8188_nau8825_card = { 1355 - .name = "mt8188_nau8825", 1356 - .quirk = NAU8825_HS_PRESENT, 1431 + static const struct mtk_soundcard_pdata mt8188_evb_card = { 1432 + .card_name = "mt8188_mt6359", 1433 + .card_data = &(struct mtk_platform_card_data) { 1434 + .card = &mt8188_mt6359_soc_card, 1435 + .num_jacks = MT8188_JACK_MAX, 1436 + }, 1437 + .sof_priv = &mt8188_sof_priv, 1438 + .soc_probe = mt8188_mt6359_soc_card_probe, 1357 1439 }; 1358 1440 1359 - static struct mt8188_card_data mt8188_rt5682s_card = { 1360 - .name = "mt8188_rt5682s", 1361 - .quirk = RT5682S_HS_PRESENT | MAX98390_TWO_AMP, 1441 + static const struct mtk_soundcard_pdata mt8188_nau8825_card = { 1442 + .card_name = "mt8188_nau8825", 1443 + .card_data = &(struct mtk_platform_card_data) { 1444 + .card = &mt8188_mt6359_soc_card, 1445 + .num_jacks = MT8188_JACK_MAX, 1446 + .flags = NAU8825_HS_PRESENT 1447 + }, 1448 + .sof_priv = &mt8188_sof_priv, 1449 + .soc_probe = mt8188_mt6359_soc_card_probe, 1362 1450 }; 1363 1451 1364 - static struct mt8188_card_data mt8188_es8326_card = { 1365 - .name = "mt8188_es8326", 1366 - .quirk = ES8326_HS_PRESENT | MAX98390_TWO_AMP, 1452 + static const struct mtk_soundcard_pdata mt8188_rt5682s_card = { 1453 + .card_name = "mt8188_rt5682s", 1454 + .card_data = &(struct mtk_platform_card_data) { 1455 + .card = &mt8188_mt6359_soc_card, 1456 + .num_jacks = MT8188_JACK_MAX, 1457 + .flags = RT5682S_HS_PRESENT | MAX98390_TWO_AMP 1458 + }, 1459 + .sof_priv = &mt8188_sof_priv, 1460 + .soc_probe = mt8188_mt6359_soc_card_probe, 1461 + }; 1462 + 1463 + static const struct mtk_soundcard_pdata mt8188_es8326_card = { 1464 + .card_name = "mt8188_es8326", 1465 + .card_data = &(struct mtk_platform_card_data) { 1466 + .card = &mt8188_mt6359_soc_card, 1467 + .num_jacks = MT8188_JACK_MAX, 1468 + .flags = ES8326_HS_PRESENT | MAX98390_TWO_AMP 1469 + }, 1470 + .sof_priv = &mt8188_sof_priv, 1471 + .soc_probe = mt8188_mt6359_soc_card_probe, 1367 1472 }; 1368 1473 1369 1474 static const struct of_device_id mt8188_mt6359_dt_match[] = { ··· 1396 1471 .of_match_table = mt8188_mt6359_dt_match, 1397 1472 .pm = &snd_soc_pm_ops, 1398 1473 }, 1399 - .probe = mt8188_mt6359_dev_probe, 1474 + .probe = mtk_soundcard_common_probe, 1400 1475 }; 1401 1476 1402 1477 module_platform_driver(mt8188_mt6359_driver);
+2 -23
sound/soc/mediatek/mt8192/mt8192-afe-pcm.c
··· 2125 2125 return 0; 2126 2126 } 2127 2127 2128 - static int mt8192_afe_component_probe(struct snd_soc_component *component) 2129 - { 2130 - return mtk_afe_add_sub_dai_control(component); 2131 - } 2132 - 2133 - static const struct snd_soc_component_driver mt8192_afe_component = { 2134 - .name = AFE_PCM_NAME, 2135 - .probe = mt8192_afe_component_probe, 2136 - .pointer = mtk_afe_pcm_pointer, 2137 - .pcm_construct = mtk_afe_pcm_new, 2138 - }; 2139 - 2140 - static const struct snd_soc_component_driver mt8192_afe_pcm_component = { 2141 - .name = "mt8192-afe-pcm-dai", 2142 - }; 2143 - 2144 2128 static int mt8192_dai_memif_register(struct mtk_base_afe *afe) 2145 2129 { 2146 2130 struct mtk_base_afe_dai *dai; ··· 2286 2302 2287 2303 /* register platform */ 2288 2304 ret = devm_snd_soc_register_component(&pdev->dev, 2289 - &mt8192_afe_component, NULL, 0); 2290 - if (ret) 2291 - return dev_err_probe(dev, ret, "Couldn't register AFE component\n"); 2292 - 2293 - ret = devm_snd_soc_register_component(&pdev->dev, 2294 - &mt8192_afe_pcm_component, 2305 + &mtk_afe_pcm_platform, 2295 2306 afe->dai_drivers, 2296 2307 afe->num_dai_drivers); 2297 2308 if (ret) 2298 - return dev_err_probe(dev, ret, "Couldn't register AFE-PCM component\n"); 2309 + return dev_err_probe(dev, ret, "Couldn't register AFE component\n"); 2299 2310 2300 2311 return 0; 2301 2312 }
+131 -170
sound/soc/mediatek/mt8192/mt8192-mt6359-rt1015-rt5682.c
··· 20 20 #include "../../codecs/rt1015.h" 21 21 #include "../../codecs/rt5682.h" 22 22 #include "../common/mtk-afe-platform-driver.h" 23 + #include "../common/mtk-soc-card.h" 24 + #include "../common/mtk-soundcard-driver.h" 23 25 #include "mt8192-afe-common.h" 24 26 #include "mt8192-afe-clk.h" 25 27 #include "mt8192-afe-gpio.h" ··· 40 38 #define RT1015P_RT5682_OF_NAME "mediatek,mt8192_mt6359_rt1015p_rt5682" 41 39 #define RT1015P_RT5682S_OF_NAME "mediatek,mt8192_mt6359_rt1015p_rt5682s" 42 40 43 - struct mt8192_mt6359_priv { 44 - struct snd_soc_jack headset_jack; 45 - struct snd_soc_jack hdmi_jack; 41 + enum mt8192_jacks { 42 + MT8192_JACK_HEADSET, 43 + MT8192_JACK_HDMI, 44 + MT8192_JACK_MAX, 46 45 }; 47 46 48 47 /* Headset jack detection DAPM pins */ ··· 326 323 327 324 static int mt8192_rt5682_init(struct snd_soc_pcm_runtime *rtd) 328 325 { 326 + struct mtk_soc_card_data *soc_card_data = snd_soc_card_get_drvdata(rtd->card); 327 + struct snd_soc_jack *jack = &soc_card_data->card_data->jacks[MT8192_JACK_HEADSET]; 329 328 struct snd_soc_component *cmpnt_afe = 330 329 snd_soc_rtdcom_lookup(rtd, AFE_PCM_NAME); 331 330 struct mtk_base_afe *afe = snd_soc_component_get_drvdata(cmpnt_afe); 332 331 struct snd_soc_component *cmpnt_codec = 333 332 snd_soc_rtd_to_codec(rtd, 0)->component; 334 - struct mt8192_mt6359_priv *priv = snd_soc_card_get_drvdata(rtd->card); 335 - struct snd_soc_jack *jack = &priv->headset_jack; 336 333 int ret; 337 334 338 335 ret = mt8192_dai_i2s_set_share(afe, "I2S8", "I2S9"); ··· 362 359 363 360 static int mt8192_mt6359_hdmi_init(struct snd_soc_pcm_runtime *rtd) 364 361 { 362 + struct mtk_soc_card_data *soc_card_data = snd_soc_card_get_drvdata(rtd->card); 363 + struct snd_soc_jack *jack = &soc_card_data->card_data->jacks[MT8192_JACK_HDMI]; 365 364 struct snd_soc_component *cmpnt_codec = 366 365 snd_soc_rtd_to_codec(rtd, 0)->component; 367 - struct mt8192_mt6359_priv *priv = snd_soc_card_get_drvdata(rtd->card); 368 366 int ret; 369 367 370 - ret = snd_soc_card_jack_new(rtd->card, "HDMI Jack", SND_JACK_LINEOUT, 371 - &priv->hdmi_jack); 368 + ret = snd_soc_card_jack_new(rtd->card, "HDMI Jack", SND_JACK_LINEOUT, jack); 372 369 if (ret) { 373 370 dev_err(rtd->dev, "HDMI Jack creation failed: %d\n", ret); 374 371 return ret; 375 372 } 376 373 377 - return snd_soc_component_set_jack(cmpnt_codec, &priv->hdmi_jack, NULL); 374 + return snd_soc_component_set_jack(cmpnt_codec, jack, NULL); 378 375 } 379 376 380 377 static int mt8192_i2s_hw_params_fixup(struct snd_soc_pcm_runtime *rtd, ··· 388 385 389 386 return 0; 390 387 } 391 - 392 - static int 393 - mt8192_mt6359_cap1_startup(struct snd_pcm_substream *substream) 394 - { 395 - static const unsigned int channels[] = { 396 - 1, 2, 4 397 - }; 398 - static const struct snd_pcm_hw_constraint_list constraints_channels = { 399 - .count = ARRAY_SIZE(channels), 400 - .list = channels, 401 - .mask = 0, 402 - }; 403 - static const unsigned int rates[] = { 404 - 8000, 16000, 32000, 48000, 96000, 192000 405 - }; 406 - static const struct snd_pcm_hw_constraint_list constraints_rates = { 407 - .count = ARRAY_SIZE(rates), 408 - .list = rates, 409 - .mask = 0, 410 - }; 411 - 412 - struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream); 413 - struct snd_pcm_runtime *runtime = substream->runtime; 414 - int ret; 415 - 416 - ret = snd_pcm_hw_constraint_list(runtime, 0, 417 - SNDRV_PCM_HW_PARAM_CHANNELS, 418 - &constraints_channels); 419 - if (ret < 0) { 420 - dev_err(rtd->dev, "hw_constraint_list channels failed\n"); 421 - return ret; 422 - } 423 - 424 - ret = snd_pcm_hw_constraint_list(runtime, 0, 425 - SNDRV_PCM_HW_PARAM_RATE, 426 - &constraints_rates); 427 - if (ret < 0) { 428 - dev_err(rtd->dev, "hw_constraint_list rate failed\n"); 429 - return ret; 430 - } 431 - 432 - return 0; 433 - } 434 - 435 - static const struct snd_soc_ops mt8192_mt6359_capture1_ops = { 436 - .startup = mt8192_mt6359_cap1_startup, 437 - }; 438 - 439 - static int 440 - mt8192_mt6359_rt5682_startup(struct snd_pcm_substream *substream) 441 - { 442 - static const unsigned int channels[] = { 443 - 1, 2 444 - }; 445 - static const struct snd_pcm_hw_constraint_list constraints_channels = { 446 - .count = ARRAY_SIZE(channels), 447 - .list = channels, 448 - .mask = 0, 449 - }; 450 - static const unsigned int rates[] = { 451 - 48000 452 - }; 453 - static const struct snd_pcm_hw_constraint_list constraints_rates = { 454 - .count = ARRAY_SIZE(rates), 455 - .list = rates, 456 - .mask = 0, 457 - }; 458 - 459 - struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream); 460 - struct snd_pcm_runtime *runtime = substream->runtime; 461 - int ret; 462 - 463 - ret = snd_pcm_hw_constraint_list(runtime, 0, 464 - SNDRV_PCM_HW_PARAM_CHANNELS, 465 - &constraints_channels); 466 - if (ret < 0) { 467 - dev_err(rtd->dev, "hw_constraint_list channels failed\n"); 468 - return ret; 469 - } 470 - 471 - ret = snd_pcm_hw_constraint_list(runtime, 0, 472 - SNDRV_PCM_HW_PARAM_RATE, 473 - &constraints_rates); 474 - if (ret < 0) { 475 - dev_err(rtd->dev, "hw_constraint_list rate failed\n"); 476 - return ret; 477 - } 478 - 479 - return 0; 480 - } 481 - 482 - static const struct snd_soc_ops mt8192_mt6359_rt5682_ops = { 483 - .startup = mt8192_mt6359_rt5682_startup, 484 - }; 485 388 486 389 /* FE */ 487 390 SND_SOC_DAILINK_DEFS(playback1, ··· 626 717 SND_SOC_DPCM_TRIGGER_PRE}, 627 718 .dynamic = 1, 628 719 .dpcm_playback = 1, 629 - .ops = &mt8192_mt6359_rt5682_ops, 720 + .ops = &mtk_soundcard_common_playback_ops, 630 721 SND_SOC_DAILINK_REG(playback3), 631 722 }, 632 723 { ··· 690 781 SND_SOC_DPCM_TRIGGER_PRE}, 691 782 .dynamic = 1, 692 783 .dpcm_capture = 1, 693 - .ops = &mt8192_mt6359_capture1_ops, 784 + .ops = &mtk_soundcard_common_capture_ops, 694 785 SND_SOC_DAILINK_REG(capture1), 695 786 }, 696 787 { ··· 700 791 SND_SOC_DPCM_TRIGGER_PRE}, 701 792 .dynamic = 1, 702 793 .dpcm_capture = 1, 703 - .ops = &mt8192_mt6359_rt5682_ops, 794 + .ops = &mtk_soundcard_common_playback_ops, 704 795 SND_SOC_DAILINK_REG(capture2), 705 796 }, 706 797 { ··· 1045 1136 return 0; 1046 1137 } 1047 1138 1048 - static int mt8192_mt6359_dev_probe(struct platform_device *pdev) 1139 + static int mt8192_mt6359_legacy_probe(struct mtk_soc_card_data *soc_card_data) 1049 1140 { 1050 - struct snd_soc_card *card; 1051 - struct device_node *platform_node, *hdmi_codec, *headset_codec, *speaker_codec; 1052 - int ret, i; 1141 + struct mtk_platform_card_data *card_data = soc_card_data->card_data; 1142 + struct snd_soc_card *card = card_data->card; 1143 + struct device *dev = card->dev; 1144 + struct device_node *hdmi_codec, *headset_codec, *speaker_codec; 1053 1145 struct snd_soc_dai_link *dai_link; 1054 - struct mt8192_mt6359_priv *priv; 1146 + int i, ret = 0; 1055 1147 1056 - card = (struct snd_soc_card *)of_device_get_match_data(&pdev->dev); 1057 - if (!card) 1058 - return -EINVAL; 1059 - card->dev = &pdev->dev; 1060 - 1061 - if (of_device_is_compatible(pdev->dev.of_node, RT1015P_RT5682_OF_NAME)) 1062 - card->name = RT1015P_RT5682_CARD_NAME; 1063 - else if (of_device_is_compatible(pdev->dev.of_node, RT1015P_RT5682S_OF_NAME)) 1064 - card->name = RT1015P_RT5682S_CARD_NAME; 1065 - else 1066 - dev_dbg(&pdev->dev, "No need to set card name\n"); 1067 - 1068 - hdmi_codec = of_parse_phandle(pdev->dev.of_node, "mediatek,hdmi-codec", 0); 1148 + hdmi_codec = of_parse_phandle(dev->of_node, "mediatek,hdmi-codec", 0); 1069 1149 if (!hdmi_codec) 1070 - dev_dbg(&pdev->dev, "The machine has no hdmi-codec\n"); 1150 + dev_dbg(dev, "The machine has no hdmi-codec\n"); 1071 1151 1072 - platform_node = of_parse_phandle(pdev->dev.of_node, "mediatek,platform", 0); 1073 - if (!platform_node) { 1074 - ret = -EINVAL; 1075 - dev_err_probe(&pdev->dev, ret, "Property 'platform' missing or invalid\n"); 1076 - goto err_platform_node; 1077 - } 1078 - 1079 - speaker_codec = of_get_child_by_name(pdev->dev.of_node, "speaker-codecs"); 1152 + speaker_codec = of_get_child_by_name(dev->of_node, "speaker-codecs"); 1080 1153 if (!speaker_codec) { 1081 1154 ret = -EINVAL; 1082 - dev_err_probe(&pdev->dev, ret, "Property 'speaker-codecs' missing or invalid\n"); 1155 + dev_err_probe(dev, ret, "Property 'speaker-codecs' missing or invalid\n"); 1083 1156 goto err_speaker_codec; 1084 1157 } 1085 1158 1086 - headset_codec = of_get_child_by_name(pdev->dev.of_node, "headset-codec"); 1159 + headset_codec = of_get_child_by_name(dev->of_node, "headset-codec"); 1087 1160 if (!headset_codec) { 1088 1161 ret = -EINVAL; 1089 - dev_err_probe(&pdev->dev, ret, "Property 'headset-codec' missing or invalid\n"); 1162 + dev_err_probe(dev, ret, "Property 'headset-codec' missing or invalid\n"); 1090 1163 goto err_headset_codec; 1091 1164 } 1092 1165 1093 1166 for_each_card_prelinks(card, i, dai_link) { 1094 1167 ret = mt8192_mt6359_card_set_be_link(card, dai_link, speaker_codec, "I2S3"); 1095 1168 if (ret) { 1096 - dev_err_probe(&pdev->dev, ret, "%s set speaker_codec fail\n", 1169 + dev_err_probe(dev, ret, "%s set speaker_codec fail\n", 1097 1170 dai_link->name); 1098 - goto err_probe; 1171 + break; 1099 1172 } 1100 1173 1101 1174 ret = mt8192_mt6359_card_set_be_link(card, dai_link, headset_codec, "I2S8"); 1102 1175 if (ret) { 1103 - dev_err_probe(&pdev->dev, ret, "%s set headset_codec fail\n", 1176 + dev_err_probe(dev, ret, "%s set headset_codec fail\n", 1104 1177 dai_link->name); 1105 - goto err_probe; 1178 + break; 1106 1179 } 1107 1180 1108 1181 ret = mt8192_mt6359_card_set_be_link(card, dai_link, headset_codec, "I2S9"); 1109 1182 if (ret) { 1110 - dev_err_probe(&pdev->dev, ret, "%s set headset_codec fail\n", 1183 + dev_err_probe(dev, ret, "%s set headset_codec fail\n", 1111 1184 dai_link->name); 1112 - goto err_probe; 1185 + break; 1113 1186 } 1114 1187 1115 1188 if (hdmi_codec && strcmp(dai_link->name, "TDM") == 0) { ··· 1102 1211 if (dai_link->num_codecs && dai_link->codecs[0].dai_name && 1103 1212 strcmp(dai_link->codecs[0].dai_name, RT1015_CODEC_DAI) == 0) 1104 1213 dai_link->ops = &mt8192_rt1015_i2s_ops; 1105 - 1106 - if (!dai_link->platforms->name) 1107 - dai_link->platforms->of_node = platform_node; 1108 1214 } 1109 1215 1110 - priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); 1111 - if (!priv) { 1112 - ret = -ENOMEM; 1113 - goto err_probe; 1114 - } 1115 - snd_soc_card_set_drvdata(card, priv); 1116 - 1117 - ret = mt8192_afe_gpio_init(&pdev->dev); 1118 - if (ret) { 1119 - dev_err_probe(&pdev->dev, ret, "%s init gpio error\n", __func__); 1120 - goto err_probe; 1121 - } 1122 - 1123 - ret = devm_snd_soc_register_card(&pdev->dev, card); 1124 - if (ret) 1125 - dev_err_probe(&pdev->dev, ret, "%s snd_soc_register_card fail\n", __func__); 1126 - 1127 - err_probe: 1128 1216 of_node_put(headset_codec); 1129 1217 err_headset_codec: 1130 1218 of_node_put(speaker_codec); 1131 1219 err_speaker_codec: 1132 - of_node_put(platform_node); 1133 - err_platform_node: 1134 - of_node_put(hdmi_codec); 1220 + if (hdmi_codec) 1221 + of_node_put(hdmi_codec); 1222 + 1135 1223 return ret; 1136 1224 } 1225 + 1226 + static int mt8192_mt6359_soc_card_probe(struct mtk_soc_card_data *soc_card_data, bool legacy) 1227 + { 1228 + struct mtk_platform_card_data *card_data = soc_card_data->card_data; 1229 + struct snd_soc_card *card = card_data->card; 1230 + int ret; 1231 + 1232 + if (legacy) { 1233 + ret = mt8192_mt6359_legacy_probe(soc_card_data); 1234 + if (ret) 1235 + return ret; 1236 + } else { 1237 + struct snd_soc_dai_link *dai_link; 1238 + int i; 1239 + 1240 + for_each_card_prelinks(card, i, dai_link) 1241 + if (dai_link->num_codecs && dai_link->codecs[0].dai_name && 1242 + strcmp(dai_link->codecs[0].dai_name, RT1015_CODEC_DAI) == 0) 1243 + dai_link->ops = &mt8192_rt1015_i2s_ops; 1244 + } 1245 + 1246 + ret = mt8192_afe_gpio_init(card->dev); 1247 + if (ret) 1248 + return dev_err_probe(card->dev, ret, "%s init gpio error\n", __func__); 1249 + 1250 + return 0; 1251 + } 1252 + 1253 + static const unsigned int mt8192_pcm_playback_channels[] = { 1, 2 }; 1254 + static const unsigned int mt8192_pcm_playback_rates[] = { 48000 }; 1255 + 1256 + static const unsigned int mt8192_pcm_capture_channels[] = { 1, 2, 4 }; 1257 + static const unsigned int mt8192_pcm_capture_rates[] = { 1258 + 8000, 16000, 32000, 48000, 96000, 192000 1259 + }; 1260 + 1261 + static const struct mtk_pcm_constraints_data mt8192_pcm_constraints[MTK_CONSTRAINT_CAPTURE + 1] = { 1262 + [MTK_CONSTRAINT_PLAYBACK] = { 1263 + .channels = &(const struct snd_pcm_hw_constraint_list) { 1264 + .list = mt8192_pcm_playback_channels, 1265 + .count = ARRAY_SIZE(mt8192_pcm_playback_channels) 1266 + }, 1267 + .rates = &(const struct snd_pcm_hw_constraint_list) { 1268 + .list = mt8192_pcm_playback_rates, 1269 + .count = ARRAY_SIZE(mt8192_pcm_playback_rates) 1270 + } 1271 + }, 1272 + [MTK_CONSTRAINT_CAPTURE] = { 1273 + .channels = &(const struct snd_pcm_hw_constraint_list) { 1274 + .list = mt8192_pcm_capture_channels, 1275 + .count = ARRAY_SIZE(mt8192_pcm_capture_channels) 1276 + }, 1277 + .rates = &(const struct snd_pcm_hw_constraint_list) { 1278 + .list = mt8192_pcm_capture_rates, 1279 + .count = ARRAY_SIZE(mt8192_pcm_capture_rates) 1280 + } 1281 + } 1282 + }; 1283 + 1284 + static const struct mtk_soundcard_pdata mt8192_mt6359_rt1015_rt5682_pdata = { 1285 + .card_name = RT1015_RT5682_CARD_NAME, 1286 + .card_data = &(struct mtk_platform_card_data) { 1287 + .card = &mt8192_mt6359_rt1015_rt5682_card, 1288 + .num_jacks = MT8192_JACK_MAX, 1289 + .pcm_constraints = mt8192_pcm_constraints, 1290 + .num_pcm_constraints = ARRAY_SIZE(mt8192_pcm_constraints), 1291 + }, 1292 + .soc_probe = mt8192_mt6359_soc_card_probe 1293 + }; 1294 + 1295 + static const struct mtk_soundcard_pdata mt8192_mt6359_rt1015p_rt5682_pdata = { 1296 + .card_name = RT1015P_RT5682_CARD_NAME, 1297 + .card_data = &(struct mtk_platform_card_data) { 1298 + .card = &mt8192_mt6359_rt1015p_rt5682x_card, 1299 + .num_jacks = MT8192_JACK_MAX, 1300 + .pcm_constraints = mt8192_pcm_constraints, 1301 + .num_pcm_constraints = ARRAY_SIZE(mt8192_pcm_constraints), 1302 + }, 1303 + .soc_probe = mt8192_mt6359_soc_card_probe 1304 + }; 1305 + 1306 + static const struct mtk_soundcard_pdata mt8192_mt6359_rt1015p_rt5682s_pdata = { 1307 + .card_name = RT1015P_RT5682S_CARD_NAME, 1308 + .card_data = &(struct mtk_platform_card_data) { 1309 + .card = &mt8192_mt6359_rt1015p_rt5682x_card, 1310 + .num_jacks = MT8192_JACK_MAX, 1311 + .pcm_constraints = mt8192_pcm_constraints, 1312 + .num_pcm_constraints = ARRAY_SIZE(mt8192_pcm_constraints), 1313 + }, 1314 + .soc_probe = mt8192_mt6359_soc_card_probe 1315 + }; 1137 1316 1138 1317 #ifdef CONFIG_OF 1139 1318 static const struct of_device_id mt8192_mt6359_dt_match[] = { 1140 1319 { 1141 1320 .compatible = RT1015_RT5682_OF_NAME, 1142 - .data = &mt8192_mt6359_rt1015_rt5682_card, 1321 + .data = &mt8192_mt6359_rt1015_rt5682_pdata, 1143 1322 }, 1144 1323 { 1145 1324 .compatible = RT1015P_RT5682_OF_NAME, 1146 - .data = &mt8192_mt6359_rt1015p_rt5682x_card, 1325 + .data = &mt8192_mt6359_rt1015p_rt5682_pdata, 1147 1326 }, 1148 1327 { 1149 1328 .compatible = RT1015P_RT5682S_OF_NAME, 1150 - .data = &mt8192_mt6359_rt1015p_rt5682x_card, 1329 + .data = &mt8192_mt6359_rt1015p_rt5682s_pdata, 1151 1330 }, 1152 1331 {} 1153 1332 }; ··· 1237 1276 #endif 1238 1277 .pm = &mt8192_mt6359_pm_ops, 1239 1278 }, 1240 - .probe = mt8192_mt6359_dev_probe, 1279 + .probe = mtk_soundcard_common_probe, 1241 1280 }; 1242 1281 1243 1282 module_platform_driver(mt8192_mt6359_driver);
+1 -20
sound/soc/mediatek/mt8195/mt8195-afe-pcm.c
··· 2944 2944 return 0; 2945 2945 } 2946 2946 2947 - static int mt8195_afe_component_probe(struct snd_soc_component *component) 2948 - { 2949 - struct mtk_base_afe *afe = snd_soc_component_get_drvdata(component); 2950 - int ret = 0; 2951 - 2952 - snd_soc_component_init_regmap(component, afe->regmap); 2953 - 2954 - ret = mtk_afe_add_sub_dai_control(component); 2955 - 2956 - return ret; 2957 - } 2958 - 2959 - static const struct snd_soc_component_driver mt8195_afe_component = { 2960 - .name = AFE_PCM_NAME, 2961 - .pointer = mtk_afe_pcm_pointer, 2962 - .pcm_construct = mtk_afe_pcm_new, 2963 - .probe = mt8195_afe_component_probe, 2964 - }; 2965 - 2966 2947 static int init_memif_priv_data(struct mtk_base_afe *afe) 2967 2948 { 2968 2949 struct mt8195_afe_private *afe_priv = afe->platform_priv; ··· 3145 3164 } 3146 3165 3147 3166 /* register component */ 3148 - ret = devm_snd_soc_register_component(dev, &mt8195_afe_component, 3167 + ret = devm_snd_soc_register_component(dev, &mtk_afe_pcm_platform, 3149 3168 afe->dai_drivers, afe->num_dai_drivers); 3150 3169 if (ret) { 3151 3170 dev_warn(dev, "err_platform\n");
+214 -277
sound/soc/mediatek/mt8195/mt8195-mt6359.c
··· 22 22 #include "../common/mtk-afe-platform-driver.h" 23 23 #include "../common/mtk-dsp-sof-common.h" 24 24 #include "../common/mtk-soc-card.h" 25 + #include "../common/mtk-soundcard-driver.h" 25 26 #include "mt8195-afe-clk.h" 26 27 #include "mt8195-afe-common.h" 27 28 28 29 #define RT1011_SPEAKER_AMP_PRESENT BIT(0) 29 30 #define RT1019_SPEAKER_AMP_PRESENT BIT(1) 30 31 #define MAX98390_SPEAKER_AMP_PRESENT BIT(2) 32 + 33 + #define DUMB_CODEC_INIT BIT(0) 34 + #define MT6359_CODEC_INIT BIT(1) 35 + #define RT1011_CODEC_INIT BIT(2) 36 + #define RT1019_CODEC_INIT BIT(3) 37 + #define MAX98390_CODEC_INIT BIT(4) 38 + #define RT5682_CODEC_INIT BIT(5) 31 39 32 40 #define RT1011_CODEC_DAI "rt1011-aif" 33 41 #define RT1011_DEV0_NAME "rt1011.2-0038" ··· 59 51 #define SOF_DMA_UL4 "SOF_DMA_UL4" 60 52 #define SOF_DMA_UL5 "SOF_DMA_UL5" 61 53 62 - struct mt8195_card_data { 63 - const char *name; 64 - unsigned long quirk; 54 + struct mt8195_mt6359_priv { 55 + struct clk *i2so1_mclk; 65 56 }; 66 57 67 - struct mt8195_mt6359_priv { 68 - struct snd_soc_jack headset_jack; 69 - struct snd_soc_jack dp_jack; 70 - struct snd_soc_jack hdmi_jack; 71 - struct clk *i2so1_mclk; 58 + enum mt8195_jacks { 59 + MT8195_JACK_HEADSET, 60 + MT8195_JACK_DP, 61 + MT8195_JACK_HDMI, 62 + MT8195_JACK_MAX, 72 63 }; 73 64 74 65 /* Headset jack detection DAPM pins */ ··· 328 321 329 322 static int mt8195_hdmitx_dptx_startup(struct snd_pcm_substream *substream) 330 323 { 331 - static const unsigned int rates[] = { 332 - 48000 333 - }; 334 - static const unsigned int channels[] = { 335 - 2, 4, 6, 8 336 - }; 337 - static const struct snd_pcm_hw_constraint_list constraints_rates = { 338 - .count = ARRAY_SIZE(rates), 339 - .list = rates, 340 - .mask = 0, 341 - }; 342 - static const struct snd_pcm_hw_constraint_list constraints_channels = { 343 - .count = ARRAY_SIZE(channels), 344 - .list = channels, 345 - .mask = 0, 346 - }; 347 - 348 - struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream); 349 - struct snd_pcm_runtime *runtime = substream->runtime; 350 - int ret; 351 - 352 - ret = snd_pcm_hw_constraint_list(runtime, 0, 353 - SNDRV_PCM_HW_PARAM_RATE, 354 - &constraints_rates); 355 - if (ret < 0) { 356 - dev_err(rtd->dev, "hw_constraint_list rate failed\n"); 357 - return ret; 358 - } 359 - 360 - ret = snd_pcm_hw_constraint_list(runtime, 0, 361 - SNDRV_PCM_HW_PARAM_CHANNELS, 362 - &constraints_channels); 363 - if (ret < 0) { 364 - dev_err(rtd->dev, "hw_constraint_list channel failed\n"); 365 - return ret; 366 - } 367 - 368 - return 0; 324 + return mtk_soundcard_startup(substream, MTK_CONSTRAINT_HDMIDP); 369 325 } 370 326 371 327 static const struct snd_soc_ops mt8195_hdmitx_dptx_playback_ops = { ··· 352 382 static int mt8195_dptx_codec_init(struct snd_soc_pcm_runtime *rtd) 353 383 { 354 384 struct mtk_soc_card_data *soc_card_data = snd_soc_card_get_drvdata(rtd->card); 355 - struct mt8195_mt6359_priv *priv = soc_card_data->mach_priv; 385 + struct snd_soc_jack *jack = &soc_card_data->card_data->jacks[MT8195_JACK_DP]; 356 386 struct snd_soc_component *cmpnt_codec = 357 387 snd_soc_rtd_to_codec(rtd, 0)->component; 358 388 int ret; 359 389 360 - ret = snd_soc_card_jack_new(rtd->card, "DP Jack", SND_JACK_LINEOUT, 361 - &priv->dp_jack); 390 + ret = snd_soc_card_jack_new(rtd->card, "DP Jack", SND_JACK_LINEOUT, jack); 362 391 if (ret) 363 392 return ret; 364 393 365 - return snd_soc_component_set_jack(cmpnt_codec, &priv->dp_jack, NULL); 394 + return snd_soc_component_set_jack(cmpnt_codec, jack, NULL); 366 395 } 367 396 368 397 static int mt8195_hdmi_codec_init(struct snd_soc_pcm_runtime *rtd) 369 398 { 370 399 struct mtk_soc_card_data *soc_card_data = snd_soc_card_get_drvdata(rtd->card); 371 - struct mt8195_mt6359_priv *priv = soc_card_data->mach_priv; 400 + struct snd_soc_jack *jack = &soc_card_data->card_data->jacks[MT8195_JACK_HDMI]; 372 401 struct snd_soc_component *cmpnt_codec = 373 402 snd_soc_rtd_to_codec(rtd, 0)->component; 374 403 int ret; 375 404 376 - ret = snd_soc_card_jack_new(rtd->card, "HDMI Jack", SND_JACK_LINEOUT, 377 - &priv->hdmi_jack); 405 + ret = snd_soc_card_jack_new(rtd->card, "HDMI Jack", SND_JACK_LINEOUT, jack); 378 406 if (ret) 379 407 return ret; 380 408 381 - return snd_soc_component_set_jack(cmpnt_codec, &priv->hdmi_jack, NULL); 409 + return snd_soc_component_set_jack(cmpnt_codec, jack, NULL); 382 410 } 383 411 384 412 static int mt8195_dptx_hw_params_fixup(struct snd_soc_pcm_runtime *rtd, ··· 390 422 391 423 return 0; 392 424 } 393 - 394 - static int mt8195_playback_startup(struct snd_pcm_substream *substream) 395 - { 396 - static const unsigned int rates[] = { 397 - 48000 398 - }; 399 - static const unsigned int channels[] = { 400 - 2 401 - }; 402 - static const struct snd_pcm_hw_constraint_list constraints_rates = { 403 - .count = ARRAY_SIZE(rates), 404 - .list = rates, 405 - .mask = 0, 406 - }; 407 - static const struct snd_pcm_hw_constraint_list constraints_channels = { 408 - .count = ARRAY_SIZE(channels), 409 - .list = channels, 410 - .mask = 0, 411 - }; 412 - 413 - struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream); 414 - struct snd_pcm_runtime *runtime = substream->runtime; 415 - int ret; 416 - 417 - ret = snd_pcm_hw_constraint_list(runtime, 0, 418 - SNDRV_PCM_HW_PARAM_RATE, 419 - &constraints_rates); 420 - if (ret < 0) { 421 - dev_err(rtd->dev, "hw_constraint_list rate failed\n"); 422 - return ret; 423 - } 424 - 425 - ret = snd_pcm_hw_constraint_list(runtime, 0, 426 - SNDRV_PCM_HW_PARAM_CHANNELS, 427 - &constraints_channels); 428 - if (ret < 0) { 429 - dev_err(rtd->dev, "hw_constraint_list channel failed\n"); 430 - return ret; 431 - } 432 - 433 - return 0; 434 - } 435 - 436 - static const struct snd_soc_ops mt8195_playback_ops = { 437 - .startup = mt8195_playback_startup, 438 - }; 439 - 440 - static int mt8195_capture_startup(struct snd_pcm_substream *substream) 441 - { 442 - static const unsigned int rates[] = { 443 - 48000 444 - }; 445 - static const unsigned int channels[] = { 446 - 1, 2 447 - }; 448 - static const struct snd_pcm_hw_constraint_list constraints_rates = { 449 - .count = ARRAY_SIZE(rates), 450 - .list = rates, 451 - .mask = 0, 452 - }; 453 - static const struct snd_pcm_hw_constraint_list constraints_channels = { 454 - .count = ARRAY_SIZE(channels), 455 - .list = channels, 456 - .mask = 0, 457 - }; 458 - 459 - struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream); 460 - struct snd_pcm_runtime *runtime = substream->runtime; 461 - int ret; 462 - 463 - ret = snd_pcm_hw_constraint_list(runtime, 0, 464 - SNDRV_PCM_HW_PARAM_RATE, 465 - &constraints_rates); 466 - if (ret < 0) { 467 - dev_err(rtd->dev, "hw_constraint_list rate failed\n"); 468 - return ret; 469 - } 470 - 471 - ret = snd_pcm_hw_constraint_list(runtime, 0, 472 - SNDRV_PCM_HW_PARAM_CHANNELS, 473 - &constraints_channels); 474 - if (ret < 0) { 475 - dev_err(rtd->dev, "hw_constraint_list channel failed\n"); 476 - return ret; 477 - } 478 - 479 - return 0; 480 - } 481 - 482 - static const struct snd_soc_ops mt8195_capture_ops = { 483 - .startup = mt8195_capture_startup, 484 - }; 485 425 486 426 static int mt8195_rt5682_etdm_hw_params(struct snd_pcm_substream *substream, 487 427 struct snd_pcm_hw_params *params) ··· 442 566 snd_soc_rtd_to_codec(rtd, 0)->component; 443 567 struct mtk_soc_card_data *soc_card_data = snd_soc_card_get_drvdata(rtd->card); 444 568 struct mt8195_mt6359_priv *priv = soc_card_data->mach_priv; 445 - struct snd_soc_jack *jack = &priv->headset_jack; 569 + struct snd_soc_jack *jack = &soc_card_data->card_data->jacks[MT8195_JACK_HEADSET]; 446 570 struct snd_soc_component *cmpnt_afe = 447 571 snd_soc_rtdcom_lookup(rtd, AFE_PCM_NAME); 448 572 struct mtk_base_afe *afe = snd_soc_component_get_drvdata(cmpnt_afe); ··· 563 687 return ret; 564 688 } 565 689 566 - static int mt8195_rt1019_init(struct snd_soc_pcm_runtime *rtd) 690 + static int mt8195_dumb_amp_init(struct snd_soc_pcm_runtime *rtd) 567 691 { 568 692 struct snd_soc_card *card = rtd->card; 569 693 int ret; ··· 582 706 dev_err(rtd->dev, "unable to add card controls, ret %d\n", ret); 583 707 return ret; 584 708 } 709 + 710 + return 0; 711 + } 712 + 713 + static int mt8195_rt1019_init(struct snd_soc_pcm_runtime *rtd) 714 + { 715 + struct snd_soc_card *card = rtd->card; 716 + int ret; 717 + 718 + ret = mt8195_dumb_amp_init(rtd); 719 + if (ret) 720 + return ret; 585 721 586 722 ret = snd_soc_dapm_add_routes(&card->dapm, mt8195_rt1019_routes, 587 723 ARRAY_SIZE(mt8195_rt1019_routes)); ··· 913 1025 }, 914 1026 .dynamic = 1, 915 1027 .dpcm_playback = 1, 916 - .ops = &mt8195_playback_ops, 1028 + .ops = &mtk_soundcard_common_playback_ops, 917 1029 SND_SOC_DAILINK_REG(DL2_FE), 918 1030 }, 919 1031 [DAI_LINK_DL3_FE] = { ··· 925 1037 }, 926 1038 .dynamic = 1, 927 1039 .dpcm_playback = 1, 928 - .ops = &mt8195_playback_ops, 1040 + .ops = &mtk_soundcard_common_playback_ops, 929 1041 SND_SOC_DAILINK_REG(DL3_FE), 930 1042 }, 931 1043 [DAI_LINK_DL6_FE] = { ··· 937 1049 }, 938 1050 .dynamic = 1, 939 1051 .dpcm_playback = 1, 940 - .ops = &mt8195_playback_ops, 1052 + .ops = &mtk_soundcard_common_playback_ops, 941 1053 SND_SOC_DAILINK_REG(DL6_FE), 942 1054 }, 943 1055 [DAI_LINK_DL7_FE] = { ··· 960 1072 }, 961 1073 .dynamic = 1, 962 1074 .dpcm_playback = 1, 963 - .ops = &mt8195_playback_ops, 1075 + .ops = &mtk_soundcard_common_playback_ops, 964 1076 SND_SOC_DAILINK_REG(DL8_FE), 965 1077 }, 966 1078 [DAI_LINK_DL10_FE] = { ··· 984 1096 }, 985 1097 .dynamic = 1, 986 1098 .dpcm_playback = 1, 987 - .ops = &mt8195_playback_ops, 1099 + .ops = &mtk_soundcard_common_playback_ops, 988 1100 SND_SOC_DAILINK_REG(DL11_FE), 989 1101 }, 990 1102 [DAI_LINK_UL1_FE] = { ··· 1007 1119 }, 1008 1120 .dynamic = 1, 1009 1121 .dpcm_capture = 1, 1010 - .ops = &mt8195_capture_ops, 1122 + .ops = &mtk_soundcard_common_capture_ops, 1011 1123 SND_SOC_DAILINK_REG(UL2_FE), 1012 1124 }, 1013 1125 [DAI_LINK_UL3_FE] = { ··· 1019 1131 }, 1020 1132 .dynamic = 1, 1021 1133 .dpcm_capture = 1, 1022 - .ops = &mt8195_capture_ops, 1134 + .ops = &mtk_soundcard_common_capture_ops, 1023 1135 SND_SOC_DAILINK_REG(UL3_FE), 1024 1136 }, 1025 1137 [DAI_LINK_UL4_FE] = { ··· 1031 1143 }, 1032 1144 .dynamic = 1, 1033 1145 .dpcm_capture = 1, 1034 - .ops = &mt8195_capture_ops, 1146 + .ops = &mtk_soundcard_common_capture_ops, 1035 1147 SND_SOC_DAILINK_REG(UL4_FE), 1036 1148 }, 1037 1149 [DAI_LINK_UL5_FE] = { ··· 1043 1155 }, 1044 1156 .dynamic = 1, 1045 1157 .dpcm_capture = 1, 1046 - .ops = &mt8195_capture_ops, 1158 + .ops = &mtk_soundcard_common_capture_ops, 1047 1159 SND_SOC_DAILINK_REG(UL5_FE), 1048 1160 }, 1049 1161 [DAI_LINK_UL6_FE] = { ··· 1066 1178 }, 1067 1179 .dynamic = 1, 1068 1180 .dpcm_capture = 1, 1069 - .ops = &mt8195_capture_ops, 1181 + .ops = &mtk_soundcard_common_capture_ops, 1070 1182 SND_SOC_DAILINK_REG(UL8_FE), 1071 1183 }, 1072 1184 [DAI_LINK_UL9_FE] = { ··· 1078 1190 }, 1079 1191 .dynamic = 1, 1080 1192 .dpcm_capture = 1, 1081 - .ops = &mt8195_capture_ops, 1193 + .ops = &mtk_soundcard_common_capture_ops, 1082 1194 SND_SOC_DAILINK_REG(UL9_FE), 1083 1195 }, 1084 1196 [DAI_LINK_UL10_FE] = { ··· 1090 1202 }, 1091 1203 .dynamic = 1, 1092 1204 .dpcm_capture = 1, 1093 - .ops = &mt8195_capture_ops, 1205 + .ops = &mtk_soundcard_common_capture_ops, 1094 1206 SND_SOC_DAILINK_REG(UL10_FE), 1095 1207 }, 1096 1208 /* BE */ ··· 1259 1371 return ret; 1260 1372 } 1261 1373 1262 - static int mt8195_mt6359_dev_probe(struct platform_device *pdev) 1374 + static int mt8195_mt6359_legacy_probe(struct mtk_soc_card_data *soc_card_data) 1263 1375 { 1264 - struct snd_soc_card *card = &mt8195_mt6359_soc_card; 1376 + struct mtk_platform_card_data *card_data = soc_card_data->card_data; 1377 + struct snd_soc_card *card = card_data->card; 1378 + struct device_node *codec_node, *dp_node, *hdmi_node; 1265 1379 struct snd_soc_dai_link *dai_link; 1266 - struct mtk_soc_card_data *soc_card_data; 1267 - struct mt8195_mt6359_priv *mach_priv; 1268 - struct device_node *platform_node, *adsp_node, *codec_node, *dp_node, *hdmi_node; 1269 - struct mt8195_card_data *card_data; 1270 - int is5682s = 0; 1271 - int init6359 = 0; 1272 - int sof_on = 0; 1273 - int ret, i; 1274 - 1275 - card_data = (struct mt8195_card_data *)of_device_get_match_data(&pdev->dev); 1276 - card->dev = &pdev->dev; 1277 - 1278 - ret = snd_soc_of_parse_card_name(card, "model"); 1279 - if (ret) { 1280 - dev_err(&pdev->dev, "%s new card name parsing error %d\n", 1281 - __func__, ret); 1282 - return ret; 1283 - } 1284 - 1285 - if (!card->name) 1286 - card->name = card_data->name; 1380 + struct device *dev = card->dev; 1381 + bool is5682s, init6359 = false; 1382 + int i; 1287 1383 1288 1384 if (strstr(card->name, "_5682s")) { 1289 1385 codec_node = of_find_compatible_node(NULL, NULL, "realtek,rt5682s"); 1290 - is5682s = 1; 1291 - } else 1292 - codec_node = of_find_compatible_node(NULL, NULL, "realtek,rt5682i"); 1293 - 1294 - soc_card_data = devm_kzalloc(&pdev->dev, sizeof(*card_data), GFP_KERNEL); 1295 - if (!soc_card_data) 1296 - return -ENOMEM; 1297 - 1298 - mach_priv = devm_kzalloc(&pdev->dev, sizeof(*mach_priv), GFP_KERNEL); 1299 - if (!mach_priv) 1300 - return -ENOMEM; 1301 - 1302 - soc_card_data->mach_priv = mach_priv; 1303 - 1304 - adsp_node = of_parse_phandle(pdev->dev.of_node, "mediatek,adsp", 0); 1305 - if (adsp_node) { 1306 - struct mtk_sof_priv *sof_priv; 1307 - 1308 - sof_priv = devm_kzalloc(&pdev->dev, sizeof(*sof_priv), GFP_KERNEL); 1309 - if (!sof_priv) { 1310 - ret = -ENOMEM; 1311 - goto err_kzalloc; 1312 - } 1313 - sof_priv->conn_streams = g_sof_conn_streams; 1314 - sof_priv->num_streams = ARRAY_SIZE(g_sof_conn_streams); 1315 - sof_priv->sof_dai_link_fixup = mt8195_dai_link_fixup; 1316 - soc_card_data->sof_priv = sof_priv; 1317 - card->probe = mtk_sof_card_probe; 1318 - card->late_probe = mtk_sof_card_late_probe; 1319 - if (!card->topology_shortname_created) { 1320 - snprintf(card->topology_shortname, 32, "sof-%s", card->name); 1321 - card->topology_shortname_created = true; 1322 - } 1323 - card->name = card->topology_shortname; 1324 - sof_on = 1; 1325 - } 1326 - 1327 - if (of_property_read_bool(pdev->dev.of_node, "mediatek,dai-link")) { 1328 - ret = mtk_sof_dailink_parse_of(card, pdev->dev.of_node, 1329 - "mediatek,dai-link", 1330 - mt8195_mt6359_dai_links, 1331 - ARRAY_SIZE(mt8195_mt6359_dai_links)); 1332 - if (ret) { 1333 - dev_dbg(&pdev->dev, "Parse dai-link fail\n"); 1334 - goto err_parse_of; 1335 - } 1386 + is5682s = true; 1336 1387 } else { 1337 - if (!sof_on) 1338 - card->num_links = DAI_LINK_REGULAR_NUM; 1388 + codec_node = of_find_compatible_node(NULL, NULL, "realtek,rt5682i"); 1389 + is5682s = false; 1339 1390 } 1340 1391 1341 - platform_node = of_parse_phandle(pdev->dev.of_node, 1342 - "mediatek,platform", 0); 1343 - if (!platform_node) { 1344 - dev_dbg(&pdev->dev, "Property 'platform' missing or invalid\n"); 1345 - ret = -EINVAL; 1346 - goto err_platform_node; 1347 - } 1348 - 1349 - dp_node = of_parse_phandle(pdev->dev.of_node, "mediatek,dptx-codec", 0); 1350 - hdmi_node = of_parse_phandle(pdev->dev.of_node, 1351 - "mediatek,hdmi-codec", 0); 1392 + dp_node = of_parse_phandle(dev->of_node, "mediatek,dptx-codec", 0); 1393 + hdmi_node = of_parse_phandle(dev->of_node, "mediatek,hdmi-codec", 0); 1352 1394 1353 1395 for_each_card_prelinks(card, i, dai_link) { 1354 - if (!dai_link->platforms->name) { 1355 - if (!strncmp(dai_link->name, "AFE_SOF", strlen("AFE_SOF")) && sof_on) 1356 - dai_link->platforms->of_node = adsp_node; 1357 - else 1358 - dai_link->platforms->of_node = platform_node; 1359 - } 1360 - 1361 1396 if (strcmp(dai_link->name, "DPTX_BE") == 0) { 1362 1397 if (!dp_node) { 1363 - dev_dbg(&pdev->dev, "No property 'dptx-codec'\n"); 1398 + dev_dbg(dev, "No property 'dptx-codec'\n"); 1364 1399 } else { 1365 1400 dai_link->codecs->of_node = dp_node; 1366 1401 dai_link->codecs->name = NULL; ··· 1292 1481 } 1293 1482 } else if (strcmp(dai_link->name, "ETDM3_OUT_BE") == 0) { 1294 1483 if (!hdmi_node) { 1295 - dev_dbg(&pdev->dev, "No property 'hdmi-codec'\n"); 1484 + dev_dbg(dev, "No property 'hdmi-codec'\n"); 1296 1485 } else { 1297 1486 dai_link->codecs->of_node = hdmi_node; 1298 1487 dai_link->codecs->name = NULL; ··· 1301 1490 } 1302 1491 } else if (strcmp(dai_link->name, "ETDM1_OUT_BE") == 0) { 1303 1492 if (!codec_node) { 1304 - dev_err(&pdev->dev, "Codec not found!\n"); 1493 + dev_err(dev, "Codec not found!\n"); 1305 1494 } else { 1306 1495 dai_link->codecs->of_node = codec_node; 1307 1496 dai_link->codecs->name = NULL; ··· 1312 1501 } 1313 1502 } else if (strcmp(dai_link->name, "ETDM2_IN_BE") == 0) { 1314 1503 if (!codec_node) { 1315 - dev_err(&pdev->dev, "Codec not found!\n"); 1504 + dev_err(dev, "Codec not found!\n"); 1316 1505 } else { 1317 1506 dai_link->codecs->of_node = codec_node; 1318 1507 dai_link->codecs->name = NULL; ··· 1325 1514 strcmp(dai_link->name, "UL_SRC2_BE") == 0) { 1326 1515 if (!init6359) { 1327 1516 dai_link->init = mt8195_mt6359_init; 1328 - init6359 = 1; 1517 + init6359 = true; 1329 1518 } 1330 1519 } else if (strcmp(dai_link->name, "ETDM2_OUT_BE") == 0) { 1331 - switch (card_data->quirk) { 1520 + switch (card_data->flags) { 1332 1521 case RT1011_SPEAKER_AMP_PRESENT: 1333 1522 dai_link->codecs = rt1011_comps; 1334 1523 dai_link->num_codecs = ARRAY_SIZE(rt1011_comps); ··· 1356 1545 } 1357 1546 } 1358 1547 1359 - snd_soc_card_set_drvdata(card, soc_card_data); 1360 - 1361 - ret = devm_snd_soc_register_card(&pdev->dev, card); 1362 - 1363 - of_node_put(platform_node); 1364 - of_node_put(dp_node); 1365 - of_node_put(hdmi_node); 1366 - err_kzalloc: 1367 - err_parse_of: 1368 - err_platform_node: 1369 - of_node_put(adsp_node); 1370 - return ret; 1548 + return 0; 1371 1549 } 1372 1550 1373 - static struct mt8195_card_data mt8195_mt6359_rt1019_rt5682_card = { 1374 - .name = "mt8195_r1019_5682", 1375 - .quirk = RT1019_SPEAKER_AMP_PRESENT, 1551 + static int mt8195_mt6359_soc_card_probe(struct mtk_soc_card_data *soc_card_data, bool legacy) 1552 + { 1553 + struct mtk_platform_card_data *card_data = soc_card_data->card_data; 1554 + struct snd_soc_card *card = card_data->card; 1555 + struct mt8195_mt6359_priv *mach_priv; 1556 + struct snd_soc_dai_link *dai_link; 1557 + u8 codec_init = 0; 1558 + int i; 1559 + 1560 + mach_priv = devm_kzalloc(card->dev, sizeof(*mach_priv), GFP_KERNEL); 1561 + if (!mach_priv) 1562 + return -ENOMEM; 1563 + 1564 + soc_card_data->mach_priv = mach_priv; 1565 + 1566 + if (legacy) 1567 + return mt8195_mt6359_legacy_probe(soc_card_data); 1568 + 1569 + for_each_card_prelinks(card, i, dai_link) { 1570 + if (strcmp(dai_link->name, "DPTX_BE") == 0) { 1571 + if (strcmp(dai_link->codecs->dai_name, "snd-soc-dummy-dai")) 1572 + dai_link->init = mt8195_dptx_codec_init; 1573 + } else if (strcmp(dai_link->name, "ETDM3_OUT_BE") == 0) { 1574 + if (strcmp(dai_link->codecs->dai_name, "snd-soc-dummy-dai")) 1575 + dai_link->init = mt8195_hdmi_codec_init; 1576 + } else if (strcmp(dai_link->name, "DL_SRC_BE") == 0 || 1577 + strcmp(dai_link->name, "UL_SRC1_BE") == 0 || 1578 + strcmp(dai_link->name, "UL_SRC2_BE") == 0) { 1579 + if (!(codec_init & MT6359_CODEC_INIT)) { 1580 + dai_link->init = mt8195_mt6359_init; 1581 + codec_init |= MT6359_CODEC_INIT; 1582 + } 1583 + } else if (strcmp(dai_link->name, "ETDM1_OUT_BE") == 0 || 1584 + strcmp(dai_link->name, "ETDM2_OUT_BE") == 0 || 1585 + strcmp(dai_link->name, "ETDM1_IN_BE") == 0 || 1586 + strcmp(dai_link->name, "ETDM2_IN_BE") == 0) { 1587 + if (!strcmp(dai_link->codecs->dai_name, MAX98390_CODEC_DAI)) { 1588 + if (!(codec_init & MAX98390_CODEC_INIT)) { 1589 + dai_link->init = mt8195_max98390_init; 1590 + codec_init |= MAX98390_CODEC_INIT; 1591 + } 1592 + } else if (!strcmp(dai_link->codecs->dai_name, RT1011_CODEC_DAI)) { 1593 + dai_link->ops = &mt8195_rt1011_etdm_ops; 1594 + if (!(codec_init & RT1011_CODEC_INIT)) { 1595 + dai_link->init = mt8195_rt1011_init; 1596 + codec_init |= RT1011_CODEC_INIT; 1597 + } 1598 + } else if (!strcmp(dai_link->codecs->dai_name, RT1019_CODEC_DAI)) { 1599 + if (!(codec_init & RT1019_CODEC_INIT)) { 1600 + dai_link->init = mt8195_rt1019_init; 1601 + codec_init |= RT1019_CODEC_INIT; 1602 + } 1603 + } else if (!strcmp(dai_link->codecs->dai_name, RT5682_CODEC_DAI) || 1604 + !strcmp(dai_link->codecs->dai_name, RT5682S_CODEC_DAI)) { 1605 + dai_link->ops = &mt8195_rt5682_etdm_ops; 1606 + if (!(codec_init & RT5682_CODEC_INIT)) { 1607 + dai_link->init = mt8195_rt5682_init; 1608 + codec_init |= RT5682_CODEC_INIT; 1609 + } 1610 + } else { 1611 + if (strcmp(dai_link->codecs->dai_name, "snd-soc-dummy-dai")) { 1612 + if (!(codec_init & DUMB_CODEC_INIT)) { 1613 + dai_link->init = mt8195_dumb_amp_init; 1614 + codec_init |= DUMB_CODEC_INIT; 1615 + } 1616 + } 1617 + } 1618 + } 1619 + } 1620 + 1621 + return 0; 1622 + } 1623 + 1624 + static const unsigned int mt8195_pcm_playback_channels[] = { 2 }; 1625 + static const unsigned int mt8195_pcm_capture_channels[] = { 1, 2 }; 1626 + static const unsigned int mt8195_pcm_hdmidp_channels[] = { 2, 4, 6, 8 }; 1627 + static const unsigned int mt8195_pcm_rates[] = { 48000 }; 1628 + 1629 + static const struct snd_pcm_hw_constraint_list mt8195_rate_constraint = { 1630 + .list = mt8195_pcm_rates, 1631 + .count = ARRAY_SIZE(mt8195_pcm_rates) 1376 1632 }; 1377 1633 1378 - static struct mt8195_card_data mt8195_mt6359_rt1011_rt5682_card = { 1379 - .name = "mt8195_r1011_5682", 1380 - .quirk = RT1011_SPEAKER_AMP_PRESENT, 1634 + static const struct mtk_pcm_constraints_data mt8195_pcm_constraints[MTK_CONSTRAINT_HDMIDP + 1] = { 1635 + [MTK_CONSTRAINT_PLAYBACK] = { 1636 + .channels = &(const struct snd_pcm_hw_constraint_list) { 1637 + .list = mt8195_pcm_playback_channels, 1638 + .count = ARRAY_SIZE(mt8195_pcm_playback_channels) 1639 + }, 1640 + .rates = &mt8195_rate_constraint, 1641 + }, 1642 + [MTK_CONSTRAINT_CAPTURE] = { 1643 + .channels = &(const struct snd_pcm_hw_constraint_list) { 1644 + .list = mt8195_pcm_capture_channels, 1645 + .count = ARRAY_SIZE(mt8195_pcm_capture_channels) 1646 + }, 1647 + .rates = &mt8195_rate_constraint, 1648 + }, 1649 + [MTK_CONSTRAINT_HDMIDP] = { 1650 + .channels = &(const struct snd_pcm_hw_constraint_list) { 1651 + .list = mt8195_pcm_hdmidp_channels, 1652 + .count = ARRAY_SIZE(mt8195_pcm_hdmidp_channels) 1653 + }, 1654 + .rates = &mt8195_rate_constraint, 1655 + }, 1381 1656 }; 1382 1657 1383 - static struct mt8195_card_data mt8195_mt6359_max98390_rt5682_card = { 1384 - .name = "mt8195_m98390_r5682", 1385 - .quirk = MAX98390_SPEAKER_AMP_PRESENT, 1658 + static const struct mtk_sof_priv mt8195_sof_priv = { 1659 + .conn_streams = g_sof_conn_streams, 1660 + .num_streams = ARRAY_SIZE(g_sof_conn_streams), 1661 + .sof_dai_link_fixup = mt8195_dai_link_fixup 1662 + }; 1663 + 1664 + static const struct mtk_soundcard_pdata mt8195_mt6359_rt1019_rt5682_card = { 1665 + .card_name = "mt8195_r1019_5682", 1666 + .card_data = &(struct mtk_platform_card_data) { 1667 + .card = &mt8195_mt6359_soc_card, 1668 + .num_jacks = MT8195_JACK_MAX, 1669 + .pcm_constraints = mt8195_pcm_constraints, 1670 + .num_pcm_constraints = ARRAY_SIZE(mt8195_pcm_constraints), 1671 + .flags = RT1019_SPEAKER_AMP_PRESENT 1672 + }, 1673 + .sof_priv = &mt8195_sof_priv, 1674 + .soc_probe = mt8195_mt6359_soc_card_probe 1675 + }; 1676 + 1677 + static const struct mtk_soundcard_pdata mt8195_mt6359_rt1011_rt5682_card = { 1678 + .card_name = "mt8195_r1011_5682", 1679 + .card_data = &(struct mtk_platform_card_data) { 1680 + .card = &mt8195_mt6359_soc_card, 1681 + .num_jacks = MT8195_JACK_MAX, 1682 + .pcm_constraints = mt8195_pcm_constraints, 1683 + .num_pcm_constraints = ARRAY_SIZE(mt8195_pcm_constraints), 1684 + .flags = RT1011_SPEAKER_AMP_PRESENT 1685 + }, 1686 + .sof_priv = &mt8195_sof_priv, 1687 + .soc_probe = mt8195_mt6359_soc_card_probe 1688 + }; 1689 + 1690 + static const struct mtk_soundcard_pdata mt8195_mt6359_max98390_rt5682_card = { 1691 + .card_name = "mt8195_m98390_r5682", 1692 + .card_data = &(struct mtk_platform_card_data) { 1693 + .card = &mt8195_mt6359_soc_card, 1694 + .num_jacks = MT8195_JACK_MAX, 1695 + .pcm_constraints = mt8195_pcm_constraints, 1696 + .num_pcm_constraints = ARRAY_SIZE(mt8195_pcm_constraints), 1697 + .flags = MAX98390_SPEAKER_AMP_PRESENT 1698 + }, 1699 + .sof_priv = &mt8195_sof_priv, 1700 + .soc_probe = mt8195_mt6359_soc_card_probe 1386 1701 }; 1387 1702 1388 1703 static const struct of_device_id mt8195_mt6359_dt_match[] = { ··· 1534 1597 .of_match_table = mt8195_mt6359_dt_match, 1535 1598 .pm = &snd_soc_pm_ops, 1536 1599 }, 1537 - .probe = mt8195_mt6359_dev_probe, 1600 + .probe = mtk_soundcard_common_probe, 1538 1601 }; 1539 1602 1540 1603 module_platform_driver(mt8195_mt6359_driver);