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

ASoC: Some issues about loongson i2s

Merge series from Binbin Zhou <zhoubinbin@loongson.cn>:

This patch set is mainly about Loongson i2s related issues.

Please allow me to briefly explain this patch set:
Patch 1-2: Add ES8323 codec required on Loongson-2K2000
Patch 3-4: Add uda1342 codec required on Loongson-2K1000
Patch 5: Fix the problem of unable to detect codec under FDT system.
Patch 6-7: Add Loongson i2s platform device support

+1638 -15
+3 -1
Documentation/devicetree/bindings/sound/everest,es8316.yaml
··· 4 4 $id: http://devicetree.org/schemas/sound/everest,es8316.yaml# 5 5 $schema: http://devicetree.org/meta-schemas/core.yaml# 6 6 7 - title: Everest ES8311 and ES8316 audio CODECs 7 + title: Everest ES8311, ES8316 and ES8323 audio CODECs 8 8 9 9 maintainers: 10 10 - Daniel Drake <drake@endlessm.com> 11 11 - Katsuhiro Suzuki <katsuhiro@katsuster.net> 12 12 - Matteo Martelli <matteomartelli3@gmail.com> 13 + - Binbin Zhou <zhoubinbin@loongson.cn> 13 14 14 15 allOf: 15 16 - $ref: dai-common.yaml# ··· 20 19 enum: 21 20 - everest,es8311 22 21 - everest,es8316 22 + - everest,es8323 23 23 24 24 reg: 25 25 maxItems: 1
+68
Documentation/devicetree/bindings/sound/loongson,ls2k1000-i2s.yaml
··· 1 + # SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) 2 + %YAML 1.2 3 + --- 4 + $id: http://devicetree.org/schemas/sound/loongson,ls2k1000-i2s.yaml# 5 + $schema: http://devicetree.org/meta-schemas/core.yaml# 6 + 7 + title: Loongson-2K1000 I2S controller 8 + 9 + maintainers: 10 + - Binbin Zhou <zhoubinbin@loongson.cn> 11 + 12 + allOf: 13 + - $ref: dai-common.yaml# 14 + 15 + properties: 16 + compatible: 17 + const: loongson,ls2k1000-i2s 18 + 19 + reg: 20 + items: 21 + - description: Loongson I2S controller Registers. 22 + - description: APB DMA config register for Loongson I2S controller. 23 + 24 + interrupts: 25 + maxItems: 1 26 + 27 + clocks: 28 + maxItems: 1 29 + 30 + dmas: 31 + maxItems: 2 32 + 33 + dma-names: 34 + items: 35 + - const: tx 36 + - const: rx 37 + 38 + '#sound-dai-cells': 39 + const: 0 40 + 41 + required: 42 + - compatible 43 + - reg 44 + - interrupts 45 + - clocks 46 + - dmas 47 + - dma-names 48 + - '#sound-dai-cells' 49 + 50 + unevaluatedProperties: false 51 + 52 + examples: 53 + - | 54 + #include <dt-bindings/clock/loongson,ls2k-clk.h> 55 + #include <dt-bindings/interrupt-controller/irq.h> 56 + 57 + i2s@1fe2d000 { 58 + compatible = "loongson,ls2k1000-i2s"; 59 + reg = <0x1fe2d000 0x14>, 60 + <0x1fe00438 0x8>; 61 + interrupt-parent = <&liointc0>; 62 + interrupts = <5 IRQ_TYPE_LEVEL_HIGH>; 63 + clocks = <&clk LOONGSON2_APB_CLK>; 64 + dmas = <&apbdma2 0>, <&apbdma3 0>; 65 + dma-names = "tx", "rx"; 66 + #sound-dai-cells = <0>; 67 + }; 68 + ...
+42
Documentation/devicetree/bindings/sound/nxp,uda1342.yaml
··· 1 + # SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) 2 + %YAML 1.2 3 + --- 4 + $id: http://devicetree.org/schemas/sound/nxp,uda1342.yaml# 5 + $schema: http://devicetree.org/meta-schemas/core.yaml# 6 + 7 + title: NXP uda1342 audio CODECs 8 + 9 + maintainers: 10 + - Binbin Zhou <zhoubinbin@loongson.cn> 11 + 12 + allOf: 13 + - $ref: dai-common.yaml# 14 + 15 + properties: 16 + compatible: 17 + const: nxp,uda1342 18 + 19 + reg: 20 + maxItems: 1 21 + 22 + '#sound-dai-cells': 23 + const: 0 24 + 25 + required: 26 + - compatible 27 + - reg 28 + - '#sound-dai-cells' 29 + 30 + unevaluatedProperties: false 31 + 32 + examples: 33 + - | 34 + i2c { 35 + #address-cells = <1>; 36 + #size-cells = <0>; 37 + codec@1a { 38 + compatible = "nxp,uda1342"; 39 + reg = <0x1a>; 40 + #sound-dai-cells = <0>; 41 + }; 42 + };
+13
sound/soc/codecs/Kconfig
··· 112 112 imply SND_SOC_DA9055 113 113 imply SND_SOC_DMIC 114 114 imply SND_SOC_ES8316 115 + imply SND_SOC_ES8323 115 116 imply SND_SOC_ES8326 116 117 imply SND_SOC_ES8328_SPI 117 118 imply SND_SOC_ES8328_I2C ··· 283 282 imply SND_SOC_TWL4030 284 283 imply SND_SOC_TWL6040 285 284 imply SND_SOC_UDA1334 285 + imply SND_SOC_UDA1342 286 286 imply SND_SOC_UDA1380 287 287 imply SND_SOC_WCD9335 288 288 imply SND_SOC_WCD934X ··· 1144 1142 1145 1143 config SND_SOC_ES8316 1146 1144 tristate "Everest Semi ES8316 CODEC" 1145 + depends on I2C 1146 + 1147 + config SND_SOC_ES8323 1148 + tristate "Everest Semi ES8323 CODEC" 1147 1149 depends on I2C 1148 1150 1149 1151 config SND_SOC_ES8326 ··· 2131 2125 The UDA1334 is an NXP audio codec, supports the I2S-bus data format 2132 2126 and has basic features such as de-emphasis (at 44.1 kHz sampling 2133 2127 rate) and mute. 2128 + 2129 + config SND_SOC_UDA1342 2130 + tristate "NXP UDA1342 CODEC" 2131 + depends on I2C 2132 + help 2133 + The UDA1342 is an NXP audio codec, support 2x Stereo audio ADC (4x PGA 2134 + mic inputs), stereo audio DAC, with basic audio processing. 2134 2135 2135 2136 config SND_SOC_UDA1380 2136 2137 tristate
+4
sound/soc/codecs/Makefile
··· 125 125 snd-soc-es83xx-dsm-common-y := es83xx-dsm-common.o 126 126 snd-soc-es8311-y := es8311.o 127 127 snd-soc-es8316-y := es8316.o 128 + snd-soc-es8323-y := es8323.o 128 129 snd-soc-es8326-y := es8326.o 129 130 snd-soc-es8328-y := es8328.o 130 131 snd-soc-es8328-i2c-y := es8328-i2c.o ··· 325 324 snd-soc-twl4030-y := twl4030.o 326 325 snd-soc-twl6040-y := twl6040.o 327 326 snd-soc-uda1334-y := uda1334.o 327 + snd-soc-uda1342-y := uda1342.o 328 328 snd-soc-uda1380-y := uda1380.o 329 329 snd-soc-wcd-classh-y := wcd-clsh-v2.o 330 330 snd-soc-wcd-mbhc-y := wcd-mbhc-v2.o ··· 539 537 obj-$(CONFIG_SND_SOC_ES83XX_DSM_COMMON) += snd-soc-es83xx-dsm-common.o 540 538 obj-$(CONFIG_SND_SOC_ES8311) += snd-soc-es8311.o 541 539 obj-$(CONFIG_SND_SOC_ES8316) += snd-soc-es8316.o 540 + obj-$(CONFIG_SND_SOC_ES8323) += snd-soc-es8323.o 542 541 obj-$(CONFIG_SND_SOC_ES8326) += snd-soc-es8326.o 543 542 obj-$(CONFIG_SND_SOC_ES8328) += snd-soc-es8328.o 544 543 obj-$(CONFIG_SND_SOC_ES8328_I2C)+= snd-soc-es8328-i2c.o ··· 736 733 obj-$(CONFIG_SND_SOC_TWL4030) += snd-soc-twl4030.o 737 734 obj-$(CONFIG_SND_SOC_TWL6040) += snd-soc-twl6040.o 738 735 obj-$(CONFIG_SND_SOC_UDA1334) += snd-soc-uda1334.o 736 + obj-$(CONFIG_SND_SOC_UDA1342) += snd-soc-uda1342.o 739 737 obj-$(CONFIG_SND_SOC_UDA1380) += snd-soc-uda1380.o 740 738 obj-$(CONFIG_SND_SOC_WCD_CLASSH) += snd-soc-wcd-classh.o 741 739 obj-$(CONFIG_SND_SOC_WCD_MBHC) += snd-soc-wcd-mbhc.o
+792
sound/soc/codecs/es8323.c
··· 1 + // SPDX-License-Identifier: GPL-2.0-only 2 + // 3 + // es8323.c -- es8323 ALSA SoC audio driver 4 + // 5 + // Copyright 2024 Rockchip Electronics Co. Ltd. 6 + // Copyright 2024 Everest Semiconductor Co.,Ltd. 7 + // Copyright 2024 Loongson Technology Co.,Ltd. 8 + // 9 + // Author: Mark Brown <broonie@kernel.org> 10 + // Jianqun Xu <jay.xu@rock-chips.com> 11 + // Nickey Yang <nickey.yang@rock-chips.com> 12 + // Further cleanup and restructuring by: 13 + // Binbin Zhou <zhoubinbin@loongson.cn> 14 + 15 + #include <linux/module.h> 16 + #include <linux/acpi.h> 17 + #include <linux/clk.h> 18 + #include <linux/delay.h> 19 + #include <linux/i2c.h> 20 + #include <linux/mod_devicetable.h> 21 + #include <linux/regmap.h> 22 + #include <sound/pcm.h> 23 + #include <sound/pcm_params.h> 24 + #include <sound/soc.h> 25 + #include <sound/soc-dapm.h> 26 + #include <sound/tlv.h> 27 + 28 + #include "es8323.h" 29 + 30 + struct es8323_priv { 31 + unsigned int sysclk; 32 + struct clk *mclk; 33 + struct regmap *regmap; 34 + struct snd_pcm_hw_constraint_list *sysclk_constraints; 35 + struct snd_soc_component *component; 36 + }; 37 + 38 + /* es8323 register cache */ 39 + static const struct reg_default es8323_reg_defaults[] = { 40 + { ES8323_CONTROL1, 0x06 }, 41 + { ES8323_CONTROL2, 0x1c }, 42 + { ES8323_CHIPPOWER, 0xc3 }, 43 + { ES8323_ADCPOWER, 0xfc }, 44 + { ES8323_DACPOWER, 0xc0 }, 45 + { ES8323_CHIPLOPOW1, 0x00 }, 46 + { ES8323_CHIPLOPOW2, 0x00 }, 47 + { ES8323_ANAVOLMANAG, 0x7c }, 48 + { ES8323_MASTERMODE, 0x80 }, 49 + { ES8323_ADCCONTROL1, 0x00 }, 50 + { ES8323_ADCCONTROL2, 0x00 }, 51 + { ES8323_ADCCONTROL3, 0x06 }, 52 + { ES8323_ADCCONTROL4, 0x00 }, 53 + { ES8323_ADCCONTROL5, 0x06 }, 54 + { ES8323_ADCCONTROL6, 0x30 }, 55 + { ES8323_ADC_MUTE, 0x30 }, 56 + { ES8323_LADC_VOL, 0xc0 }, 57 + { ES8323_RADC_VOL, 0xc0 }, 58 + { ES8323_ADCCONTROL10, 0x38 }, 59 + { ES8323_ADCCONTROL11, 0xb0 }, 60 + { ES8323_ADCCONTROL12, 0x32 }, 61 + { ES8323_ADCCONTROL13, 0x06 }, 62 + { ES8323_ADCCONTROL14, 0x00 }, 63 + { ES8323_DACCONTROL1, 0x00 }, 64 + { ES8323_DACCONTROL2, 0x06 }, 65 + { ES8323_DAC_MUTE, 0x30 }, 66 + { ES8323_LDAC_VOL, 0xc0 }, 67 + { ES8323_RDAC_VOL, 0xc0 }, 68 + { ES8323_DACCONTROL6, 0x08 }, 69 + { ES8323_DACCONTROL7, 0x06 }, 70 + { ES8323_DACCONTROL8, 0x1f }, 71 + { ES8323_DACCONTROL9, 0xf7 }, 72 + { ES8323_DACCONTROL10, 0xfd }, 73 + { ES8323_DACCONTROL11, 0xff }, 74 + { ES8323_DACCONTROL12, 0x1f }, 75 + { ES8323_DACCONTROL13, 0xf7 }, 76 + { ES8323_DACCONTROL14, 0xfd }, 77 + { ES8323_DACCONTROL15, 0xff }, 78 + { ES8323_DACCONTROL16, 0x00 }, 79 + { ES8323_DACCONTROL17, 0x38 }, 80 + { ES8323_DACCONTROL18, 0x38 }, 81 + { ES8323_DACCONTROL19, 0x38 }, 82 + { ES8323_DACCONTROL20, 0x38 }, 83 + { ES8323_DACCONTROL21, 0x38 }, 84 + { ES8323_DACCONTROL22, 0x38 }, 85 + { ES8323_DACCONTROL23, 0x00 }, 86 + { ES8323_LOUT1_VOL, 0x00 }, 87 + { ES8323_ROUT1_VOL, 0x00 }, 88 + }; 89 + 90 + static const char *const es8323_stereo_3d_texts[] = { "No 3D ", "Level 1", "Level 2", "Level 3", 91 + "Level 4", "Level 5", "Level 6", "Level 7" }; 92 + static SOC_ENUM_SINGLE_DECL(es8323_stereo_3d_enum, ES8323_DACCONTROL7, 2, es8323_stereo_3d_texts); 93 + 94 + static const char *const es8323_alc_func_texts[] = { "Off", "Right", "Left", "Stereo" }; 95 + static SOC_ENUM_SINGLE_DECL(es8323_alc_function_enum, 96 + ES8323_ADCCONTROL10, 6, es8323_alc_func_texts); 97 + 98 + static const char *const es8323_ng_type_texts[] = { "Constant PGA Gain", "Mute ADC Output" }; 99 + static SOC_ENUM_SINGLE_DECL(es8323_alc_ng_type_enum, ES8323_ADCCONTROL14, 1, es8323_ng_type_texts); 100 + 101 + static const char *const es8323_deemph_texts[] = { "None", "32Khz", "44.1Khz", "48Khz" }; 102 + static SOC_ENUM_SINGLE_DECL(es8323_playback_deemphasis_enum, 103 + ES8323_DACCONTROL6, 6, es8323_deemph_texts); 104 + 105 + static const char *const es8323_adcpol_texts[] = { "Normal", "L Invert", 106 + "R Invert", "L + R Invert" }; 107 + static SOC_ENUM_SINGLE_DECL(es8323_capture_polarity_enum, 108 + ES8323_ADCCONTROL6, 6, es8323_adcpol_texts); 109 + 110 + static const DECLARE_TLV_DB_SCALE(es8323_adc_tlv, -9600, 50, 1); 111 + static const DECLARE_TLV_DB_SCALE(es8323_dac_tlv, -9600, 50, 1); 112 + static const DECLARE_TLV_DB_SCALE(es8323_out_tlv, -4500, 150, 0); 113 + static const DECLARE_TLV_DB_SCALE(es8323_bypass_tlv, 0, 300, 0); 114 + static const DECLARE_TLV_DB_SCALE(es8323_bypass_tlv2, -15, 300, 0); 115 + 116 + static const struct snd_kcontrol_new es8323_snd_controls[] = { 117 + SOC_ENUM("3D Mode", es8323_stereo_3d_enum), 118 + SOC_ENUM("ALC Capture Function", es8323_alc_function_enum), 119 + SOC_ENUM("ALC Capture NG Type", es8323_alc_ng_type_enum), 120 + SOC_ENUM("Playback De-emphasis", es8323_playback_deemphasis_enum), 121 + SOC_ENUM("Capture Polarity", es8323_capture_polarity_enum), 122 + SOC_SINGLE("ALC Capture ZC Switch", ES8323_ADCCONTROL13, 6, 1, 0), 123 + SOC_SINGLE("ALC Capture Decay Time", ES8323_ADCCONTROL12, 4, 15, 0), 124 + SOC_SINGLE("ALC Capture Attack Time", ES8323_ADCCONTROL12, 0, 15, 0), 125 + SOC_SINGLE("ALC Capture NG Threshold", ES8323_ADCCONTROL14, 3, 31, 0), 126 + SOC_SINGLE("ALC Capture NG Switch", ES8323_ADCCONTROL14, 0, 1, 0), 127 + SOC_SINGLE("ZC Timeout Switch", ES8323_ADCCONTROL13, 6, 1, 0), 128 + SOC_SINGLE("Capture Mute Switch", ES8323_ADC_MUTE, 2, 1, 0), 129 + SOC_SINGLE_TLV("Left Channel Capture Volume", ES8323_ADCCONTROL1, 4, 8, 130 + 0, es8323_bypass_tlv), 131 + SOC_SINGLE_TLV("Right Channel Capture Volume", ES8323_ADCCONTROL1, 0, 132 + 8, 0, es8323_bypass_tlv), 133 + SOC_SINGLE_TLV("Left Mixer Left Bypass Volume", ES8323_DACCONTROL17, 3, 134 + 7, 1, es8323_bypass_tlv2), 135 + SOC_SINGLE_TLV("Right Mixer Right Bypass Volume", ES8323_DACCONTROL20, 136 + 3, 7, 1, es8323_bypass_tlv2), 137 + SOC_DOUBLE_R_TLV("PCM Volume", ES8323_LDAC_VOL, ES8323_RDAC_VOL, 138 + 0, 192, 1, es8323_dac_tlv), 139 + SOC_DOUBLE_R_TLV("Capture Digital Volume", ES8323_LADC_VOL, 140 + ES8323_RADC_VOL, 0, 192, 1, es8323_adc_tlv), 141 + SOC_DOUBLE_R_TLV("Output 1 Playback Volume", ES8323_LOUT1_VOL, 142 + ES8323_ROUT1_VOL, 0, 33, 0, es8323_out_tlv), 143 + SOC_DOUBLE_R_TLV("Output 2 Playback Volume", ES8323_LOUT2_VOL, 144 + ES8323_ROUT2_VOL, 0, 33, 0, es8323_out_tlv), 145 + }; 146 + 147 + /* Left DAC Route */ 148 + static const char *const es8323_pga_sell[] = { "Line 1L", "Line 2L", "NC", "DifferentialL" }; 149 + static SOC_ENUM_SINGLE_DECL(es8323_left_dac_enum, ES8323_ADCCONTROL2, 6, es8323_pga_sell); 150 + static const struct snd_kcontrol_new es8323_left_dac_mux_controls = 151 + SOC_DAPM_ENUM("Left DAC Route", es8323_left_dac_enum); 152 + 153 + /* Right DAC Route */ 154 + static const char *const es8323_pga_selr[] = { "Line 1R", "Line 2R", "NC", "DifferentialR" }; 155 + static SOC_ENUM_SINGLE_DECL(es8323_right_dac_enum, ES8323_ADCCONTROL2, 4, es8323_pga_selr); 156 + static const struct snd_kcontrol_new es8323_right_dac_mux_controls = 157 + SOC_DAPM_ENUM("Right DAC Route", es8323_right_dac_enum); 158 + 159 + /* Left Line Mux */ 160 + static const char *const es8323_lin_sell[] = { "Line 1L", "Line 2L", "NC", "MicL" }; 161 + static SOC_ENUM_SINGLE_DECL(es8323_llin_enum, ES8323_DACCONTROL16, 3, es8323_lin_sell); 162 + static const struct snd_kcontrol_new es8323_left_line_controls = 163 + SOC_DAPM_ENUM("LLIN Mux", es8323_llin_enum); 164 + 165 + /* Right Line Mux */ 166 + static const char *const es8323_lin_selr[] = { "Line 1R", "Line 2R", "NC", "MicR" }; 167 + static SOC_ENUM_SINGLE_DECL(es8323_rlin_enum, ES8323_DACCONTROL16, 0, es8323_lin_selr); 168 + static const struct snd_kcontrol_new es8323_right_line_controls = 169 + SOC_DAPM_ENUM("RLIN Mux", es8323_rlin_enum); 170 + 171 + /* Differential Mux */ 172 + static const char *const es8323_diffmux_sel[] = { "Line 1", "Line 2" }; 173 + static SOC_ENUM_SINGLE_DECL(es8323_diffmux_enum, ES8323_ADCCONTROL3, 7, es8323_diffmux_sel); 174 + static const struct snd_kcontrol_new es8323_diffmux_controls = 175 + SOC_DAPM_ENUM("Route2", es8323_diffmux_enum); 176 + 177 + /* Mono ADC Mux */ 178 + static const char *const es8323_mono_adc_mux[] = { "Stereo", "Mono (Left)", "Mono (Right)" }; 179 + static SOC_ENUM_SINGLE_DECL(es8323_mono_adc_mux_enum, ES8323_ADCCONTROL3, 3, es8323_mono_adc_mux); 180 + static const struct snd_kcontrol_new es8323_mono_adc_mux_controls = 181 + SOC_DAPM_ENUM("Mono Mux", es8323_mono_adc_mux_enum); 182 + 183 + /* Left Mixer */ 184 + static const struct snd_kcontrol_new es8323_left_mixer_controls[] = { 185 + SOC_DAPM_SINGLE("Left Playback Switch", SND_SOC_NOPM, 7, 1, 1), 186 + SOC_DAPM_SINGLE("Left Bypass Switch", ES8323_DACCONTROL17, 6, 1, 0), 187 + }; 188 + 189 + /* Right Mixer */ 190 + static const struct snd_kcontrol_new es8323_right_mixer_controls[] = { 191 + SOC_DAPM_SINGLE("Right Playback Switch", SND_SOC_NOPM, 6, 1, 1), 192 + SOC_DAPM_SINGLE("Right Bypass Switch", ES8323_DACCONTROL20, 6, 1, 0), 193 + }; 194 + 195 + static const struct snd_soc_dapm_widget es8323_dapm_widgets[] = { 196 + SND_SOC_DAPM_INPUT("LINPUT1"), 197 + SND_SOC_DAPM_INPUT("LINPUT2"), 198 + SND_SOC_DAPM_INPUT("RINPUT1"), 199 + SND_SOC_DAPM_INPUT("RINPUT2"), 200 + 201 + SND_SOC_DAPM_MICBIAS("Mic Bias", SND_SOC_NOPM, 3, 1), 202 + 203 + /* Muxes */ 204 + SND_SOC_DAPM_MUX("Left PGA Mux", SND_SOC_NOPM, 0, 0, &es8323_left_dac_mux_controls), 205 + SND_SOC_DAPM_MUX("Right PGA Mux", SND_SOC_NOPM, 0, 0, &es8323_right_dac_mux_controls), 206 + SND_SOC_DAPM_MUX("Differential Mux", SND_SOC_NOPM, 0, 0, &es8323_diffmux_controls), 207 + SND_SOC_DAPM_MUX("Left ADC Mux", SND_SOC_NOPM, 0, 0, &es8323_mono_adc_mux_controls), 208 + SND_SOC_DAPM_MUX("Right ADC Mux", SND_SOC_NOPM, 0, 0, &es8323_mono_adc_mux_controls), 209 + SND_SOC_DAPM_MUX("Left Line Mux", SND_SOC_NOPM, 0, 0, &es8323_left_line_controls), 210 + SND_SOC_DAPM_MUX("Right Line Mux", SND_SOC_NOPM, 0, 0, &es8323_right_line_controls), 211 + 212 + SND_SOC_DAPM_ADC("Right ADC", "Right Capture", SND_SOC_NOPM, 4, 1), 213 + SND_SOC_DAPM_ADC("Left ADC", "Left Capture", SND_SOC_NOPM, 5, 1), 214 + SND_SOC_DAPM_DAC("Right DAC", "Right Playback", SND_SOC_NOPM, 6, 1), 215 + SND_SOC_DAPM_DAC("Left DAC", "Left Playback", SND_SOC_NOPM, 7, 1), 216 + 217 + SND_SOC_DAPM_MIXER("Left Mixer", SND_SOC_NOPM, 0, 0, 218 + &es8323_left_mixer_controls[0], 219 + ARRAY_SIZE(es8323_left_mixer_controls)), 220 + SND_SOC_DAPM_MIXER("Right Mixer", SND_SOC_NOPM, 0, 0, 221 + &es8323_right_mixer_controls[0], 222 + ARRAY_SIZE(es8323_right_mixer_controls)), 223 + 224 + SND_SOC_DAPM_PGA("Right ADC Power", SND_SOC_NOPM, 6, 1, NULL, 0), 225 + SND_SOC_DAPM_PGA("Left ADC Power", SND_SOC_NOPM, 7, 1, NULL, 0), 226 + SND_SOC_DAPM_PGA("Right Out 2", SND_SOC_NOPM, 2, 0, NULL, 0), 227 + SND_SOC_DAPM_PGA("Left Out 2", SND_SOC_NOPM, 3, 0, NULL, 0), 228 + SND_SOC_DAPM_PGA("Right Out 1", SND_SOC_NOPM, 4, 0, NULL, 0), 229 + SND_SOC_DAPM_PGA("Left Out 1", SND_SOC_NOPM, 5, 0, NULL, 0), 230 + SND_SOC_DAPM_PGA("LAMP", ES8323_ADCCONTROL1, 4, 0, NULL, 0), 231 + SND_SOC_DAPM_PGA("RAMP", ES8323_ADCCONTROL1, 0, 0, NULL, 0), 232 + 233 + SND_SOC_DAPM_OUTPUT("LOUT1"), 234 + SND_SOC_DAPM_OUTPUT("ROUT1"), 235 + SND_SOC_DAPM_OUTPUT("LOUT2"), 236 + SND_SOC_DAPM_OUTPUT("ROUT2"), 237 + SND_SOC_DAPM_OUTPUT("VREF"), 238 + }; 239 + 240 + static const struct snd_soc_dapm_route es8323_dapm_routes[] = { 241 + /*12.22*/ 242 + {"Left PGA Mux", "Line 1L", "LINPUT1"}, 243 + {"Left PGA Mux", "Line 2L", "LINPUT2"}, 244 + {"Left PGA Mux", "DifferentialL", "Differential Mux"}, 245 + 246 + {"Right PGA Mux", "Line 1R", "RINPUT1"}, 247 + {"Right PGA Mux", "Line 2R", "RINPUT2"}, 248 + {"Right PGA Mux", "DifferentialR", "Differential Mux"}, 249 + 250 + {"Differential Mux", "Line 1", "LINPUT1"}, 251 + {"Differential Mux", "Line 1", "RINPUT1"}, 252 + {"Differential Mux", "Line 2", "LINPUT2"}, 253 + {"Differential Mux", "Line 2", "RINPUT2"}, 254 + 255 + {"Left ADC Mux", "Stereo", "Right PGA Mux"}, 256 + {"Left ADC Mux", "Stereo", "Left PGA Mux"}, 257 + {"Left ADC Mux", "Mono (Left)", "Left PGA Mux"}, 258 + 259 + {"Right ADC Mux", "Stereo", "Left PGA Mux"}, 260 + {"Right ADC Mux", "Stereo", "Right PGA Mux"}, 261 + {"Right ADC Mux", "Mono (Right)", "Right PGA Mux"}, 262 + 263 + {"Left ADC Power", NULL, "Left ADC Mux"}, 264 + {"Right ADC Power", NULL, "Right ADC Mux"}, 265 + {"Left ADC", NULL, "Left ADC Power"}, 266 + {"Right ADC", NULL, "Right ADC Power"}, 267 + 268 + {"Left Line Mux", "Line 1L", "LINPUT1"}, 269 + {"Left Line Mux", "Line 2L", "LINPUT2"}, 270 + {"Left Line Mux", "MicL", "Left PGA Mux"}, 271 + 272 + {"Right Line Mux", "Line 1R", "RINPUT1"}, 273 + {"Right Line Mux", "Line 2R", "RINPUT2"}, 274 + {"Right Line Mux", "MicR", "Right PGA Mux"}, 275 + 276 + {"Left Mixer", "Left Playback Switch", "Left DAC"}, 277 + {"Left Mixer", "Left Bypass Switch", "Left Line Mux"}, 278 + 279 + {"Right Mixer", "Right Playback Switch", "Right DAC"}, 280 + {"Right Mixer", "Right Bypass Switch", "Right Line Mux"}, 281 + 282 + {"Left Out 1", NULL, "Left Mixer"}, 283 + {"LOUT1", NULL, "Left Out 1"}, 284 + {"Right Out 1", NULL, "Right Mixer"}, 285 + {"ROUT1", NULL, "Right Out 1"}, 286 + 287 + {"Left Out 2", NULL, "Left Mixer"}, 288 + {"LOUT2", NULL, "Left Out 2"}, 289 + {"Right Out 2", NULL, "Right Mixer"}, 290 + {"ROUT2", NULL, "Right Out 2"}, 291 + }; 292 + 293 + struct coeff_div { 294 + u32 mclk; 295 + u32 rate; 296 + u16 fs; 297 + u8 sr:4; 298 + u8 usb:1; 299 + }; 300 + 301 + /* codec hifi mclk clock divider coefficients */ 302 + static const struct coeff_div es8323_coeff_div[] = { 303 + /* 8k */ 304 + {12288000, 8000, 1536, 0xa, 0x0}, 305 + {11289600, 8000, 1408, 0x9, 0x0}, 306 + {18432000, 8000, 2304, 0xc, 0x0}, 307 + {16934400, 8000, 2112, 0xb, 0x0}, 308 + {12000000, 8000, 1500, 0xb, 0x1}, 309 + 310 + /* 11.025k */ 311 + {11289600, 11025, 1024, 0x7, 0x0}, 312 + {16934400, 11025, 1536, 0xa, 0x0}, 313 + {12000000, 11025, 1088, 0x9, 0x1}, 314 + 315 + /* 16k */ 316 + {12288000, 16000, 768, 0x6, 0x0}, 317 + {18432000, 16000, 1152, 0x8, 0x0}, 318 + {12000000, 16000, 750, 0x7, 0x1}, 319 + 320 + /* 22.05k */ 321 + {11289600, 22050, 512, 0x4, 0x0}, 322 + {16934400, 22050, 768, 0x6, 0x0}, 323 + {12000000, 22050, 544, 0x6, 0x1}, 324 + 325 + /* 32k */ 326 + {12288000, 32000, 384, 0x3, 0x0}, 327 + {18432000, 32000, 576, 0x5, 0x0}, 328 + {12000000, 32000, 375, 0x4, 0x1}, 329 + 330 + /* 44.1k */ 331 + {11289600, 44100, 256, 0x2, 0x0}, 332 + {16934400, 44100, 384, 0x3, 0x0}, 333 + {12000000, 44100, 272, 0x3, 0x1}, 334 + 335 + /* 48k */ 336 + {12288000, 48000, 256, 0x2, 0x0}, 337 + {18432000, 48000, 384, 0x3, 0x0}, 338 + {12000000, 48000, 250, 0x2, 0x1}, 339 + 340 + /* 88.2k */ 341 + {11289600, 88200, 128, 0x0, 0x0}, 342 + {16934400, 88200, 192, 0x1, 0x0}, 343 + {12000000, 88200, 136, 0x1, 0x1}, 344 + 345 + /* 96k */ 346 + {12288000, 96000, 128, 0x0, 0x0}, 347 + {18432000, 96000, 192, 0x1, 0x0}, 348 + {12000000, 96000, 125, 0x0, 0x1}, 349 + }; 350 + 351 + static unsigned int rates_12288[] = { 352 + 8000, 12000, 16000, 24000, 24000, 32000, 48000, 96000, 353 + }; 354 + 355 + static struct snd_pcm_hw_constraint_list constraints_12288 = { 356 + .count = ARRAY_SIZE(rates_12288), 357 + .list = rates_12288, 358 + }; 359 + 360 + static unsigned int rates_112896[] = { 361 + 8000, 11025, 22050, 44100, 362 + }; 363 + 364 + static struct snd_pcm_hw_constraint_list constraints_112896 = { 365 + .count = ARRAY_SIZE(rates_112896), 366 + .list = rates_112896, 367 + }; 368 + 369 + static unsigned int rates_12[] = { 370 + 8000, 11025, 12000, 16000, 22050, 24000, 371 + 32000, 44100, 48000, 48000, 88235, 96000, 372 + }; 373 + 374 + static struct snd_pcm_hw_constraint_list constraints_12 = { 375 + .count = ARRAY_SIZE(rates_12), 376 + .list = rates_12, 377 + }; 378 + 379 + static inline int get_coeff(int mclk, int rate) 380 + { 381 + int i; 382 + 383 + for (i = 0; i < ARRAY_SIZE(es8323_coeff_div); i++) { 384 + if (es8323_coeff_div[i].rate == rate && 385 + es8323_coeff_div[i].mclk == mclk) 386 + return i; 387 + } 388 + 389 + return -EINVAL; 390 + } 391 + 392 + static int es8323_set_dai_sysclk(struct snd_soc_dai *codec_dai, 393 + int clk_id, unsigned int freq, int dir) 394 + { 395 + struct snd_soc_component *component = codec_dai->component; 396 + struct es8323_priv *es8323 = snd_soc_component_get_drvdata(component); 397 + 398 + switch (freq) { 399 + case 11289600: 400 + case 18432000: 401 + case 22579200: 402 + case 36864000: 403 + es8323->sysclk_constraints = &constraints_112896; 404 + break; 405 + case 12288000: 406 + case 16934400: 407 + case 24576000: 408 + case 33868800: 409 + es8323->sysclk_constraints = &constraints_12288; 410 + break; 411 + case 12000000: 412 + case 24000000: 413 + es8323->sysclk_constraints = &constraints_12; 414 + break; 415 + default: 416 + return -EINVAL; 417 + } 418 + 419 + es8323->sysclk = freq; 420 + return 0; 421 + } 422 + 423 + static int es8323_set_dai_fmt(struct snd_soc_dai *codec_dai, unsigned int fmt) 424 + { 425 + struct snd_soc_component *component = codec_dai->component; 426 + u8 iface = snd_soc_component_read(component, ES8323_MASTERMODE); 427 + u8 adciface = snd_soc_component_read(component, ES8323_ADC_IFACE); 428 + u8 daciface = snd_soc_component_read(component, ES8323_DAC_IFACE); 429 + 430 + switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) { 431 + case SND_SOC_DAIFMT_BC_FP: 432 + iface |= 0x80; 433 + break; 434 + case SND_SOC_DAIFMT_BC_FC: 435 + iface &= 0x7f; 436 + break; 437 + default: 438 + return -EINVAL; 439 + } 440 + 441 + /* interface format */ 442 + switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) { 443 + case SND_SOC_DAIFMT_I2S: 444 + adciface &= 0xfc; 445 + daciface &= 0xf8; 446 + break; 447 + case SND_SOC_DAIFMT_LEFT_J: 448 + adciface &= 0xfd; 449 + daciface &= 0xf9; 450 + break; 451 + case SND_SOC_DAIFMT_RIGHT_J: 452 + adciface &= 0xfe; 453 + daciface &= 0xfa; 454 + break; 455 + case SND_SOC_DAIFMT_DSP_A: 456 + case SND_SOC_DAIFMT_DSP_B: 457 + adciface &= 0xff; 458 + daciface &= 0xfb; 459 + break; 460 + default: 461 + return -EINVAL; 462 + } 463 + 464 + /* clock inversion */ 465 + switch (fmt & SND_SOC_DAIFMT_INV_MASK) { 466 + case SND_SOC_DAIFMT_NB_NF: 467 + iface &= 0xdf; 468 + adciface &= 0xdf; 469 + daciface &= 0xbf; 470 + break; 471 + case SND_SOC_DAIFMT_IB_IF: 472 + iface |= 0x20; 473 + adciface |= 0x20; 474 + daciface |= 0x40; 475 + break; 476 + case SND_SOC_DAIFMT_IB_NF: 477 + iface |= 0x20; 478 + adciface &= 0xdf; 479 + daciface &= 0xbf; 480 + break; 481 + case SND_SOC_DAIFMT_NB_IF: 482 + iface &= 0xdf; 483 + adciface |= 0x20; 484 + daciface |= 0x40; 485 + break; 486 + default: 487 + return -EINVAL; 488 + } 489 + 490 + snd_soc_component_write(component, ES8323_MASTERMODE, iface); 491 + snd_soc_component_write(component, ES8323_ADC_IFACE, adciface); 492 + snd_soc_component_write(component, ES8323_DAC_IFACE, daciface); 493 + 494 + return 0; 495 + } 496 + 497 + static int es8323_pcm_startup(struct snd_pcm_substream *substream, 498 + struct snd_soc_dai *dai) 499 + { 500 + struct snd_soc_component *component = dai->component; 501 + struct es8323_priv *es8323 = snd_soc_component_get_drvdata(component); 502 + 503 + if (es8323->sysclk) { 504 + snd_pcm_hw_constraint_list(substream->runtime, 0, 505 + SNDRV_PCM_HW_PARAM_RATE, 506 + es8323->sysclk_constraints); 507 + } 508 + 509 + return 0; 510 + } 511 + 512 + static int es8323_pcm_hw_params(struct snd_pcm_substream *substream, 513 + struct snd_pcm_hw_params *params, 514 + struct snd_soc_dai *dai) 515 + { 516 + struct snd_soc_component *component = dai->component; 517 + struct es8323_priv *es8323 = snd_soc_component_get_drvdata(component); 518 + u16 srate = snd_soc_component_read(component, ES8323_MASTERMODE) & 0x80; 519 + u16 adciface = snd_soc_component_read(component, ES8323_ADC_IFACE) & 0xe3; 520 + u16 daciface = snd_soc_component_read(component, ES8323_DAC_IFACE) & 0xc7; 521 + int coeff; 522 + 523 + coeff = get_coeff(es8323->sysclk, params_rate(params)); 524 + if (coeff < 0) { 525 + coeff = get_coeff(es8323->sysclk / 2, params_rate(params)); 526 + srate |= 0x40; 527 + } 528 + 529 + if (coeff < 0) { 530 + dev_err(component->dev, 531 + "Unable to configure sample rate %dHz with %dHz MCLK\n", 532 + params_rate(params), es8323->sysclk); 533 + return coeff; 534 + } 535 + 536 + /* bit size */ 537 + switch (params_format(params)) { 538 + case SNDRV_PCM_FORMAT_S16_LE: 539 + adciface |= 0xc; 540 + daciface |= 0x18; 541 + break; 542 + case SNDRV_PCM_FORMAT_S20_3LE: 543 + adciface |= 0x4; 544 + daciface |= 0x8; 545 + break; 546 + case SNDRV_PCM_FORMAT_S24_LE: 547 + break; 548 + case SNDRV_PCM_FORMAT_S32_LE: 549 + adciface |= 0x10; 550 + daciface |= 0x20; 551 + break; 552 + } 553 + 554 + snd_soc_component_write(component, ES8323_DAC_IFACE, daciface); 555 + snd_soc_component_write(component, ES8323_ADC_IFACE, adciface); 556 + 557 + snd_soc_component_write(component, ES8323_MASTERMODE, srate); 558 + snd_soc_component_write(component, ES8323_ADCCONTROL5, 559 + es8323_coeff_div[coeff].sr | 560 + (es8323_coeff_div[coeff].usb) << 4); 561 + snd_soc_component_write(component, ES8323_DACCONTROL2, 562 + es8323_coeff_div[coeff].sr | 563 + (es8323_coeff_div[coeff].usb) << 4); 564 + 565 + snd_soc_component_write(component, ES8323_DACPOWER, 0x3c); 566 + 567 + return 0; 568 + } 569 + 570 + static int es8323_mute_stream(struct snd_soc_dai *dai, int mute, int stream) 571 + { 572 + struct snd_soc_component *component = dai->component; 573 + u32 val = mute ? 0x6 : 0x2; 574 + 575 + snd_soc_component_write(component, ES8323_DAC_MUTE, val); 576 + 577 + return 0; 578 + } 579 + 580 + static const struct snd_soc_dai_ops es8323_ops = { 581 + .startup = es8323_pcm_startup, 582 + .hw_params = es8323_pcm_hw_params, 583 + .set_fmt = es8323_set_dai_fmt, 584 + .set_sysclk = es8323_set_dai_sysclk, 585 + .mute_stream = es8323_mute_stream, 586 + }; 587 + 588 + #define ES8323_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE |\ 589 + SNDRV_PCM_FMTBIT_S24_LE) 590 + 591 + static struct snd_soc_dai_driver es8323_dai = { 592 + .name = "ES8323 HiFi", 593 + .playback = { 594 + .stream_name = "Playback", 595 + .channels_min = 1, 596 + .channels_max = 2, 597 + .rates = SNDRV_PCM_RATE_8000_96000, 598 + .formats = ES8323_FORMATS, 599 + }, 600 + .capture = { 601 + .stream_name = "Capture", 602 + .channels_min = 1, 603 + .channels_max = 2, 604 + .rates = SNDRV_PCM_RATE_8000_96000, 605 + .formats = ES8323_FORMATS, 606 + }, 607 + .ops = &es8323_ops, 608 + .symmetric_rate = 1, 609 + }; 610 + 611 + static int es8323_probe(struct snd_soc_component *component) 612 + { 613 + struct es8323_priv *es8323 = snd_soc_component_get_drvdata(component); 614 + int ret; 615 + 616 + es8323->component = component; 617 + 618 + es8323->mclk = devm_clk_get_optional(component->dev, "mclk"); 619 + if (IS_ERR(es8323->mclk)) { 620 + dev_err(component->dev, "unable to get mclk\n"); 621 + return PTR_ERR(es8323->mclk); 622 + } 623 + 624 + if (!es8323->mclk) 625 + dev_warn(component->dev, "assuming static mclk\n"); 626 + 627 + ret = clk_prepare_enable(es8323->mclk); 628 + if (ret) { 629 + dev_err(component->dev, "unable to enable mclk\n"); 630 + return ret; 631 + } 632 + 633 + snd_soc_component_write(component, ES8323_CONTROL2, 0x60); 634 + snd_soc_component_write(component, ES8323_CHIPPOWER, 0x00); 635 + snd_soc_component_write(component, ES8323_DACCONTROL17, 0xB8); 636 + 637 + return 0; 638 + } 639 + 640 + static int es8323_set_bias_level(struct snd_soc_component *component, 641 + enum snd_soc_bias_level level) 642 + { 643 + struct es8323_priv *es8323 = snd_soc_component_get_drvdata(component); 644 + int ret; 645 + 646 + switch (level) { 647 + case SND_SOC_BIAS_ON: 648 + ret = clk_prepare_enable(es8323->mclk); 649 + if (ret) 650 + return ret; 651 + 652 + snd_soc_component_write(component, ES8323_CHIPPOWER, 0xf0); 653 + usleep_range(18000, 20000); 654 + snd_soc_component_write(component, ES8323_DACPOWER, 0x3c); 655 + snd_soc_component_write(component, ES8323_ANAVOLMANAG, 0x7c); 656 + snd_soc_component_write(component, ES8323_CHIPLOPOW1, 0x00); 657 + snd_soc_component_write(component, ES8323_CHIPLOPOW2, 0x00); 658 + snd_soc_component_write(component, ES8323_CHIPPOWER, 0x00); 659 + snd_soc_component_write(component, ES8323_ADCPOWER, 0x09); 660 + snd_soc_component_write(component, ES8323_ADCCONTROL14, 0x00); 661 + break; 662 + case SND_SOC_BIAS_PREPARE: 663 + break; 664 + case SND_SOC_BIAS_STANDBY: 665 + snd_soc_component_write(component, ES8323_ANAVOLMANAG, 0x7c); 666 + snd_soc_component_write(component, ES8323_CHIPLOPOW1, 0x00); 667 + snd_soc_component_write(component, ES8323_CHIPLOPOW2, 0x00); 668 + snd_soc_component_write(component, ES8323_CHIPPOWER, 0x00); 669 + snd_soc_component_write(component, ES8323_ADCPOWER, 0x59); 670 + break; 671 + case SND_SOC_BIAS_OFF: 672 + clk_disable_unprepare(es8323->mclk); 673 + snd_soc_component_write(component, ES8323_ADCPOWER, 0xff); 674 + snd_soc_component_write(component, ES8323_DACPOWER, 0xC0); 675 + snd_soc_component_write(component, ES8323_CHIPLOPOW1, 0xff); 676 + snd_soc_component_write(component, ES8323_CHIPLOPOW2, 0xff); 677 + snd_soc_component_write(component, ES8323_CHIPPOWER, 0xff); 678 + snd_soc_component_write(component, ES8323_ANAVOLMANAG, 0x7b); 679 + break; 680 + } 681 + 682 + return 0; 683 + } 684 + 685 + static void es8323_remove(struct snd_soc_component *component) 686 + { 687 + struct es8323_priv *es8323 = snd_soc_component_get_drvdata(component); 688 + 689 + clk_disable_unprepare(es8323->mclk); 690 + es8323_set_bias_level(component, SND_SOC_BIAS_OFF); 691 + } 692 + 693 + static int es8323_suspend(struct snd_soc_component *component) 694 + { 695 + struct es8323_priv *es8323 = snd_soc_component_get_drvdata(component); 696 + 697 + regcache_cache_only(es8323->regmap, true); 698 + regcache_mark_dirty(es8323->regmap); 699 + 700 + return 0; 701 + } 702 + 703 + static int es8323_resume(struct snd_soc_component *component) 704 + { 705 + struct es8323_priv *es8323 = snd_soc_component_get_drvdata(component); 706 + 707 + regcache_cache_only(es8323->regmap, false); 708 + regcache_sync(es8323->regmap); 709 + 710 + return 0; 711 + } 712 + 713 + static const struct snd_soc_component_driver soc_component_dev_es8323 = { 714 + .probe = es8323_probe, 715 + .remove = es8323_remove, 716 + .suspend = es8323_suspend, 717 + .resume = es8323_resume, 718 + .set_bias_level = es8323_set_bias_level, 719 + .controls = es8323_snd_controls, 720 + .num_controls = ARRAY_SIZE(es8323_snd_controls), 721 + .dapm_widgets = es8323_dapm_widgets, 722 + .num_dapm_widgets = ARRAY_SIZE(es8323_dapm_widgets), 723 + .dapm_routes = es8323_dapm_routes, 724 + .num_dapm_routes = ARRAY_SIZE(es8323_dapm_routes), 725 + .use_pmdown_time = 1, 726 + .endianness = 1, 727 + }; 728 + 729 + static const struct regmap_config es8323_regmap = { 730 + .reg_bits = 8, 731 + .val_bits = 8, 732 + .use_single_read = true, 733 + .use_single_write = true, 734 + .max_register = 0x53, 735 + .reg_defaults = es8323_reg_defaults, 736 + .num_reg_defaults = ARRAY_SIZE(es8323_reg_defaults), 737 + .cache_type = REGCACHE_MAPLE, 738 + }; 739 + 740 + static int es8323_i2c_probe(struct i2c_client *i2c_client) 741 + { 742 + struct es8323_priv *es8323; 743 + struct device *dev = &i2c_client->dev; 744 + 745 + es8323 = devm_kzalloc(dev, sizeof(*es8323), GFP_KERNEL); 746 + if (IS_ERR(es8323)) 747 + return -ENOMEM; 748 + 749 + i2c_set_clientdata(i2c_client, es8323); 750 + 751 + es8323->regmap = devm_regmap_init_i2c(i2c_client, &es8323_regmap); 752 + if (IS_ERR(es8323->regmap)) 753 + return PTR_ERR(es8323->regmap); 754 + 755 + return devm_snd_soc_register_component(dev, 756 + &soc_component_dev_es8323, 757 + &es8323_dai, 1); 758 + } 759 + 760 + static const struct i2c_device_id es8323_i2c_id[] = { 761 + { "es8323", 0 }, 762 + { } 763 + }; 764 + MODULE_DEVICE_TABLE(i2c, es8323_i2c_id); 765 + 766 + static const struct acpi_device_id es8323_acpi_match[] = { 767 + { "ESSX8323", 0 }, 768 + { } 769 + }; 770 + MODULE_DEVICE_TABLE(acpi, es8323_acpi_match); 771 + 772 + static const struct of_device_id es8323_of_match[] = { 773 + { .compatible = "everest,es8323" }, 774 + { } 775 + }; 776 + MODULE_DEVICE_TABLE(of, es8323_of_match); 777 + 778 + static struct i2c_driver es8323_i2c_driver = { 779 + .driver = { 780 + .name = "ES8323", 781 + .acpi_match_table = es8323_acpi_match, 782 + .of_match_table = es8323_of_match, 783 + }, 784 + .probe = es8323_i2c_probe, 785 + .id_table = es8323_i2c_id, 786 + }; 787 + module_i2c_driver(es8323_i2c_driver); 788 + 789 + MODULE_DESCRIPTION("Everest Semi ES8323 ALSA SoC Codec Driver"); 790 + MODULE_AUTHOR("Mark Brown <broonie@kernel.org>"); 791 + MODULE_AUTHOR("Binbin Zhou <zhoubinbin@loongson.cn>"); 792 + MODULE_LICENSE("GPL");
+78
sound/soc/codecs/es8323.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0-only */ 2 + /* 3 + * Copyright Openedhand Ltd. 4 + * 5 + * Author: Richard Purdie <richard@openedhand.com> 6 + * Binbin Zhou <zhoubinbin@loongson.cn> 7 + * 8 + */ 9 + 10 + #ifndef _ES8323_H 11 + #define _ES8323_H 12 + 13 + /* ES8323 register space */ 14 + 15 + /* Chip Control and Power Management */ 16 + #define ES8323_CONTROL1 0x00 17 + #define ES8323_CONTROL2 0x01 18 + #define ES8323_CHIPPOWER 0x02 19 + #define ES8323_ADCPOWER 0x03 20 + #define ES8323_DACPOWER 0x04 21 + #define ES8323_CHIPLOPOW1 0x05 22 + #define ES8323_CHIPLOPOW2 0x06 23 + #define ES8323_ANAVOLMANAG 0x07 24 + #define ES8323_MASTERMODE 0x08 25 + 26 + /* ADC Control */ 27 + #define ES8323_ADCCONTROL1 0x09 28 + #define ES8323_ADCCONTROL2 0x0a 29 + #define ES8323_ADCCONTROL3 0x0b 30 + #define ES8323_ADCCONTROL4 0x0c 31 + #define ES8323_ADCCONTROL5 0x0d 32 + #define ES8323_ADCCONTROL6 0x0e 33 + #define ES8323_ADC_MUTE 0x0f 34 + #define ES8323_LADC_VOL 0x10 35 + #define ES8323_RADC_VOL 0x11 36 + #define ES8323_ADCCONTROL10 0x12 37 + #define ES8323_ADCCONTROL11 0x13 38 + #define ES8323_ADCCONTROL12 0x14 39 + #define ES8323_ADCCONTROL13 0x15 40 + #define ES8323_ADCCONTROL14 0x16 41 + 42 + /* DAC Control */ 43 + #define ES8323_DACCONTROL1 0x17 44 + #define ES8323_DACCONTROL2 0x18 45 + #define ES8323_DAC_MUTE 0x19 46 + #define ES8323_LDAC_VOL 0x1a 47 + #define ES8323_RDAC_VOL 0x1b 48 + #define ES8323_DACCONTROL6 0x1c 49 + #define ES8323_DACCONTROL7 0x1d 50 + #define ES8323_DACCONTROL8 0x1e 51 + #define ES8323_DACCONTROL9 0x1f 52 + #define ES8323_DACCONTROL10 0x20 53 + #define ES8323_DACCONTROL11 0x21 54 + #define ES8323_DACCONTROL12 0x22 55 + #define ES8323_DACCONTROL13 0x23 56 + #define ES8323_DACCONTROL14 0x24 57 + #define ES8323_DACCONTROL15 0x25 58 + #define ES8323_DACCONTROL16 0x26 59 + #define ES8323_DACCONTROL17 0x27 60 + #define ES8323_DACCONTROL18 0x28 61 + #define ES8323_DACCONTROL19 0x29 62 + #define ES8323_DACCONTROL20 0x2a 63 + #define ES8323_DACCONTROL21 0x2b 64 + #define ES8323_DACCONTROL22 0x2c 65 + #define ES8323_DACCONTROL23 0x2d 66 + #define ES8323_LOUT1_VOL 0x2e 67 + #define ES8323_ROUT1_VOL 0x2f 68 + #define ES8323_LOUT2_VOL 0x30 69 + #define ES8323_ROUT2_VOL 0x31 70 + #define ES8323_DACCONTROL28 0x32 71 + #define ES8323_DACCONTROL29 0x33 72 + #define ES8323_DACCONTROL30 0x34 73 + 74 + #define ES8323_ADC_IFACE ES8323_ADCCONTROL4 75 + #define ES8323_ADC_SRATE ES8323_ADCCONTROL5 76 + #define ES8323_DAC_IFACE ES8323_DACCONTROL1 77 + #define ES8323_DAC_SRATE ES8323_DACCONTROL2 78 + #endif
+347
sound/soc/codecs/uda1342.c
··· 1 + // SPDX-License-Identifier: GPL-2.0-only 2 + // 3 + // uda1342.c -- UDA1342 ALSA SoC Codec driver 4 + // Based on the WM87xx drivers by Liam Girdwood and Richard Purdie 5 + // 6 + // Copyright 2007 Dension Audio Systems Ltd. 7 + // Copyright 2024 Loongson Technology Co.,Ltd. 8 + // 9 + // Modifications by Christian Pellegrin <chripell@evolware.org> 10 + // Further cleanup and restructuring by: 11 + // Binbin Zhou <zhoubinbin@loongson.cn> 12 + 13 + #include <linux/module.h> 14 + #include <linux/i2c.h> 15 + #include <sound/core.h> 16 + #include <sound/pcm.h> 17 + #include <sound/pcm_params.h> 18 + #include <linux/pm_runtime.h> 19 + #include <sound/soc.h> 20 + #include <sound/tlv.h> 21 + 22 + #include "uda1342.h" 23 + 24 + #define UDA134X_FORMATS (SNDRV_PCM_FMTBIT_S8 | SNDRV_PCM_FMTBIT_S16_LE | \ 25 + SNDRV_PCM_FMTBIT_S18_3LE | SNDRV_PCM_FMTBIT_S20_3LE) 26 + 27 + struct uda1342_priv { 28 + int sysclk; 29 + int dai_fmt; 30 + 31 + struct snd_pcm_substream *provider_substream; 32 + struct snd_pcm_substream *consumer_substream; 33 + 34 + struct regmap *regmap; 35 + struct i2c_client *i2c; 36 + }; 37 + 38 + static const struct reg_default uda1342_reg_defaults[] = { 39 + { 0x00, 0x1042 }, 40 + { 0x01, 0x0000 }, 41 + { 0x10, 0x0088 }, 42 + { 0x11, 0x0000 }, 43 + { 0x12, 0x0000 }, 44 + { 0x20, 0x0080 }, 45 + { 0x21, 0x0080 }, 46 + }; 47 + 48 + static int uda1342_mute(struct snd_soc_dai *dai, int mute, int direction) 49 + { 50 + struct snd_soc_component *component = dai->component; 51 + struct uda1342_priv *uda1342 = snd_soc_component_get_drvdata(component); 52 + unsigned int mask; 53 + unsigned int val = 0; 54 + 55 + /* Master mute */ 56 + mask = BIT(5); 57 + if (mute) 58 + val = mask; 59 + 60 + return regmap_update_bits(uda1342->regmap, 0x10, mask, val); 61 + } 62 + 63 + static int uda1342_startup(struct snd_pcm_substream *substream, 64 + struct snd_soc_dai *dai) 65 + { 66 + struct snd_soc_component *component = dai->component; 67 + struct uda1342_priv *uda1342 = snd_soc_component_get_drvdata(component); 68 + struct snd_pcm_runtime *provider_runtime; 69 + 70 + if (uda1342->provider_substream) { 71 + provider_runtime = uda1342->provider_substream->runtime; 72 + 73 + snd_pcm_hw_constraint_single(substream->runtime, 74 + SNDRV_PCM_HW_PARAM_RATE, provider_runtime->rate); 75 + snd_pcm_hw_constraint_single(substream->runtime, 76 + SNDRV_PCM_HW_PARAM_SAMPLE_BITS, 77 + provider_runtime->sample_bits); 78 + 79 + uda1342->consumer_substream = substream; 80 + } else { 81 + uda1342->provider_substream = substream; 82 + } 83 + 84 + return 0; 85 + } 86 + 87 + static void uda1342_shutdown(struct snd_pcm_substream *substream, 88 + struct snd_soc_dai *dai) 89 + { 90 + struct snd_soc_component *component = dai->component; 91 + struct uda1342_priv *uda1342 = snd_soc_component_get_drvdata(component); 92 + 93 + if (uda1342->provider_substream == substream) 94 + uda1342->provider_substream = uda1342->consumer_substream; 95 + 96 + uda1342->consumer_substream = NULL; 97 + } 98 + 99 + static int uda1342_hw_params(struct snd_pcm_substream *substream, 100 + struct snd_pcm_hw_params *params, struct snd_soc_dai *dai) 101 + { 102 + struct snd_soc_component *component = dai->component; 103 + struct uda1342_priv *uda1342 = snd_soc_component_get_drvdata(component); 104 + struct device *dev = &uda1342->i2c->dev; 105 + unsigned int hw_params = 0; 106 + 107 + if (substream == uda1342->consumer_substream) 108 + return 0; 109 + 110 + /* set SYSCLK / fs ratio */ 111 + switch (uda1342->sysclk / params_rate(params)) { 112 + case 512: 113 + break; 114 + case 384: 115 + hw_params |= BIT(4); 116 + break; 117 + case 256: 118 + hw_params |= BIT(5); 119 + break; 120 + default: 121 + dev_err(dev, "unsupported frequency\n"); 122 + return -EINVAL; 123 + } 124 + 125 + /* set DAI format and word length */ 126 + switch (uda1342->dai_fmt & SND_SOC_DAIFMT_FORMAT_MASK) { 127 + case SND_SOC_DAIFMT_I2S: 128 + break; 129 + case SND_SOC_DAIFMT_RIGHT_J: 130 + switch (params_width(params)) { 131 + case 16: 132 + hw_params |= BIT(1); 133 + break; 134 + case 18: 135 + hw_params |= BIT(2); 136 + break; 137 + case 20: 138 + hw_params |= BIT(2) | BIT(1); 139 + break; 140 + default: 141 + dev_err(dev, "unsupported format (right)\n"); 142 + return -EINVAL; 143 + } 144 + break; 145 + case SND_SOC_DAIFMT_LEFT_J: 146 + hw_params |= BIT(3); 147 + break; 148 + default: 149 + dev_err(dev, "unsupported format\n"); 150 + return -EINVAL; 151 + } 152 + 153 + return regmap_update_bits(uda1342->regmap, 0x0, 154 + STATUS0_DAIFMT_MASK | STATUS0_SYSCLK_MASK, hw_params); 155 + } 156 + 157 + static int uda1342_set_dai_sysclk(struct snd_soc_dai *codec_dai, 158 + int clk_id, unsigned int freq, int dir) 159 + { 160 + struct snd_soc_component *component = codec_dai->component; 161 + struct uda1342_priv *uda1342 = snd_soc_component_get_drvdata(component); 162 + struct device *dev = &uda1342->i2c->dev; 163 + 164 + /* 165 + * Anything between 256fs*8Khz and 512fs*48Khz should be acceptable 166 + * because the codec is slave. Of course limitations of the clock 167 + * master (the IIS controller) apply. 168 + * We'll error out on set_hw_params if it's not OK 169 + */ 170 + if ((freq >= (256 * 8000)) && (freq <= (512 * 48000))) { 171 + uda1342->sysclk = freq; 172 + return 0; 173 + } 174 + 175 + dev_err(dev, "unsupported sysclk\n"); 176 + 177 + return -EINVAL; 178 + } 179 + 180 + static int uda1342_set_dai_fmt(struct snd_soc_dai *codec_dai, unsigned int fmt) 181 + { 182 + struct snd_soc_component *component = codec_dai->component; 183 + struct uda1342_priv *uda1342 = snd_soc_component_get_drvdata(component); 184 + 185 + /* codec supports only full consumer mode */ 186 + if ((fmt & SND_SOC_DAIFMT_MASTER_MASK) != SND_SOC_DAIFMT_BC_FC) { 187 + dev_err(&uda1342->i2c->dev, "unsupported consumer mode.\n"); 188 + return -EINVAL; 189 + } 190 + 191 + /* We can't setup DAI format here as it depends on the word bit num */ 192 + /* so let's just store the value for later */ 193 + uda1342->dai_fmt = fmt; 194 + 195 + return 0; 196 + } 197 + 198 + static const struct snd_kcontrol_new uda1342_snd_controls[] = { 199 + SOC_SINGLE("Master Playback Volume", 0x11, 0, 0x3F, 1), 200 + SOC_SINGLE("Analog1 Volume", 0x12, 0, 0x1F, 1), 201 + }; 202 + 203 + /* Common DAPM widgets */ 204 + static const struct snd_soc_dapm_widget uda1342_dapm_widgets[] = { 205 + SND_SOC_DAPM_INPUT("VINL1"), 206 + SND_SOC_DAPM_INPUT("VINR1"), 207 + SND_SOC_DAPM_INPUT("VINL2"), 208 + SND_SOC_DAPM_INPUT("VINR2"), 209 + 210 + SND_SOC_DAPM_DAC("DAC", "Playback", 0, 1, 0), 211 + SND_SOC_DAPM_ADC("ADC", "Capture", 0, 9, 0), 212 + 213 + SND_SOC_DAPM_OUTPUT("VOUTL"), 214 + SND_SOC_DAPM_OUTPUT("VOUTR"), 215 + }; 216 + 217 + static const struct snd_soc_dapm_route uda1342_dapm_routes[] = { 218 + { "ADC", NULL, "VINL1" }, 219 + { "ADC", NULL, "VINR1" }, 220 + { "ADC", NULL, "VINL2" }, 221 + { "ADC", NULL, "VINR2" }, 222 + { "VOUTL", NULL, "DAC" }, 223 + { "VOUTR", NULL, "DAC" }, 224 + }; 225 + 226 + static const struct snd_soc_dai_ops uda1342_dai_ops = { 227 + .startup = uda1342_startup, 228 + .shutdown = uda1342_shutdown, 229 + .hw_params = uda1342_hw_params, 230 + .mute_stream = uda1342_mute, 231 + .set_sysclk = uda1342_set_dai_sysclk, 232 + .set_fmt = uda1342_set_dai_fmt, 233 + }; 234 + 235 + static struct snd_soc_dai_driver uda1342_dai = { 236 + .name = "uda1342-hifi", 237 + /* playback capabilities */ 238 + .playback = { 239 + .stream_name = "Playback", 240 + .channels_min = 1, 241 + .channels_max = 2, 242 + .rates = SNDRV_PCM_RATE_8000_48000, 243 + .formats = UDA134X_FORMATS, 244 + }, 245 + /* capture capabilities */ 246 + .capture = { 247 + .stream_name = "Capture", 248 + .channels_min = 1, 249 + .channels_max = 2, 250 + .rates = SNDRV_PCM_RATE_8000_48000, 251 + .formats = UDA134X_FORMATS, 252 + }, 253 + /* pcm operations */ 254 + .ops = &uda1342_dai_ops, 255 + }; 256 + 257 + static const struct snd_soc_component_driver soc_component_dev_uda1342 = { 258 + .controls = uda1342_snd_controls, 259 + .num_controls = ARRAY_SIZE(uda1342_snd_controls), 260 + .dapm_widgets = uda1342_dapm_widgets, 261 + .num_dapm_widgets = ARRAY_SIZE(uda1342_dapm_widgets), 262 + .dapm_routes = uda1342_dapm_routes, 263 + .num_dapm_routes = ARRAY_SIZE(uda1342_dapm_routes), 264 + .suspend_bias_off = 1, 265 + .idle_bias_on = 1, 266 + .use_pmdown_time = 1, 267 + .endianness = 1, 268 + }; 269 + 270 + static const struct regmap_config uda1342_regmap = { 271 + .reg_bits = 8, 272 + .val_bits = 16, 273 + .max_register = 0x21, 274 + .reg_defaults = uda1342_reg_defaults, 275 + .num_reg_defaults = ARRAY_SIZE(uda1342_reg_defaults), 276 + .cache_type = REGCACHE_MAPLE, 277 + }; 278 + 279 + static int uda1342_i2c_probe(struct i2c_client *i2c) 280 + { 281 + struct uda1342_priv *uda1342; 282 + 283 + uda1342 = devm_kzalloc(&i2c->dev, sizeof(*uda1342), GFP_KERNEL); 284 + if (!uda1342) 285 + return -ENOMEM; 286 + 287 + uda1342->regmap = devm_regmap_init_i2c(i2c, &uda1342_regmap); 288 + if (IS_ERR(uda1342->regmap)) 289 + return PTR_ERR(uda1342->regmap); 290 + 291 + i2c_set_clientdata(i2c, uda1342); 292 + uda1342->i2c = i2c; 293 + 294 + return devm_snd_soc_register_component(&i2c->dev, 295 + &soc_component_dev_uda1342, 296 + &uda1342_dai, 1); 297 + } 298 + 299 + static int uda1342_suspend(struct device *dev) 300 + { 301 + struct uda1342_priv *uda1342 = dev_get_drvdata(dev); 302 + 303 + regcache_cache_only(uda1342->regmap, true); 304 + 305 + return 0; 306 + } 307 + 308 + static int uda1342_resume(struct device *dev) 309 + { 310 + struct uda1342_priv *uda1342 = dev_get_drvdata(dev); 311 + 312 + regcache_mark_dirty(uda1342->regmap); 313 + regcache_sync(uda1342->regmap); 314 + 315 + return 0; 316 + } 317 + 318 + static DEFINE_RUNTIME_DEV_PM_OPS(uda1342_pm_ops, 319 + uda1342_suspend, uda1342_resume, NULL); 320 + 321 + static const struct i2c_device_id uda1342_i2c_id[] = { 322 + { "uda1342", 0 }, 323 + { } 324 + }; 325 + MODULE_DEVICE_TABLE(i2c, uda1342_i2c_id); 326 + 327 + static const struct of_device_id uda1342_of_match[] = { 328 + { .compatible = "nxp,uda1342" }, 329 + { } 330 + }; 331 + MODULE_DEVICE_TABLE(of, uda1342_of_match); 332 + 333 + static struct i2c_driver uda1342_i2c_driver = { 334 + .driver = { 335 + .name = "uda1342", 336 + .of_match_table = uda1342_of_match, 337 + .pm = pm_sleep_ptr(&uda1342_pm_ops), 338 + }, 339 + .probe = uda1342_i2c_probe, 340 + .id_table = uda1342_i2c_id, 341 + }; 342 + module_i2c_driver(uda1342_i2c_driver); 343 + 344 + MODULE_DESCRIPTION("UDA1342 ALSA soc codec driver"); 345 + MODULE_AUTHOR("Zoltan Devai, Christian Pellegrin <chripell@evolware.org>"); 346 + MODULE_AUTHOR("Binbin Zhou <zhoubinbin@loongson.cn>"); 347 + MODULE_LICENSE("GPL");
+78
sound/soc/codecs/uda1342.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0-only */ 2 + /* 3 + * Audio support for NXP UDA1342 4 + * 5 + * Copyright (c) 2005 Giorgio Padrin <giorgio@mandarinlogiq.org> 6 + * Copyright (c) 2024 Binbin Zhou <zhoubinbin@loongson.cn> 7 + */ 8 + 9 + #ifndef _UDA1342_H 10 + #define _UDA1342_H 11 + 12 + #define UDA1342_CLK 0x00 13 + #define UDA1342_IFACE 0x01 14 + #define UDA1342_PM 0x02 15 + #define UDA1342_AMIX 0x03 16 + #define UDA1342_HP 0x04 17 + #define UDA1342_MVOL 0x11 18 + #define UDA1342_MIXVOL 0x12 19 + #define UDA1342_MODE 0x12 20 + #define UDA1342_DEEMP 0x13 21 + #define UDA1342_MIXER 0x14 22 + #define UDA1342_INTSTAT 0x18 23 + #define UDA1342_DEC 0x20 24 + #define UDA1342_PGA 0x21 25 + #define UDA1342_ADC 0x22 26 + #define UDA1342_AGC 0x23 27 + #define UDA1342_DECSTAT 0x28 28 + #define UDA1342_RESET 0x7f 29 + 30 + /* Register flags */ 31 + #define R00_EN_ADC 0x0800 32 + #define R00_EN_DEC 0x0400 33 + #define R00_EN_DAC 0x0200 34 + #define R00_EN_INT 0x0100 35 + #define R00_DAC_CLK 0x0010 36 + #define R01_SFORI_I2S 0x0000 37 + #define R01_SFORI_LSB16 0x0100 38 + #define R01_SFORI_LSB18 0x0200 39 + #define R01_SFORI_LSB20 0x0300 40 + #define R01_SFORI_MSB 0x0500 41 + #define R01_SFORI_MASK 0x0700 42 + #define R01_SFORO_I2S 0x0000 43 + #define R01_SFORO_LSB16 0x0001 44 + #define R01_SFORO_LSB18 0x0002 45 + #define R01_SFORO_LSB20 0x0003 46 + #define R01_SFORO_LSB24 0x0004 47 + #define R01_SFORO_MSB 0x0005 48 + #define R01_SFORO_MASK 0x0007 49 + #define R01_SEL_SOURCE 0x0040 50 + #define R01_SIM 0x0010 51 + #define R02_PON_PLL 0x8000 52 + #define R02_PON_HP 0x2000 53 + #define R02_PON_DAC 0x0400 54 + #define R02_PON_BIAS 0x0100 55 + #define R02_EN_AVC 0x0080 56 + #define R02_PON_AVC 0x0040 57 + #define R02_PON_LNA 0x0010 58 + #define R02_PON_PGAL 0x0008 59 + #define R02_PON_ADCL 0x0004 60 + #define R02_PON_PGAR 0x0002 61 + #define R02_PON_ADCR 0x0001 62 + #define R13_MTM 0x4000 63 + #define R14_SILENCE 0x0080 64 + #define R14_SDET_ON 0x0040 65 + #define R21_MT_ADC 0x8000 66 + #define R22_SEL_LNA 0x0008 67 + #define R22_SEL_MIC 0x0004 68 + #define R22_SKIP_DCFIL 0x0002 69 + #define R23_AGC_EN 0x0001 70 + 71 + #define UDA1342_DAI_DUPLEX 0 /* playback and capture on single DAI */ 72 + #define UDA1342_DAI_PLAYBACK 1 /* playback DAI */ 73 + #define UDA1342_DAI_CAPTURE 2 /* capture DAI */ 74 + 75 + #define STATUS0_DAIFMT_MASK (~(7 << 1)) 76 + #define STATUS0_SYSCLK_MASK (~(3 << 4)) 77 + 78 + #endif /* _UDA1342_H */
+25 -14
sound/soc/loongson/Kconfig
··· 1 1 # SPDX-License-Identifier: GPL-2.0 2 2 menu "SoC Audio for Loongson CPUs" 3 - depends on LOONGARCH || COMPILE_TEST 4 - 5 - config SND_SOC_LOONGSON_I2S_PCI 6 - tristate "Loongson I2S-PCI Device Driver" 7 - select REGMAP_MMIO 8 - depends on PCI 9 - help 10 - Say Y or M if you want to add support for I2S driver for 11 - Loongson I2S controller. 12 - 13 - The controller is found in loongson bridge chips or SoCs, 14 - and work as a PCI device. 15 3 16 4 config SND_SOC_LOONGSON_CARD 17 5 tristate "Loongson Sound Card Driver" 18 - select SND_SOC_LOONGSON_I2S_PCI 19 - depends on PCI 6 + depends on LOONGARCH || COMPILE_TEST 7 + select SND_SOC_LOONGSON_I2S_PCI if PCI 8 + select SND_SOC_LOONGSON_I2S_PLATFORM if OF 20 9 help 21 10 Say Y or M if you want to add support for SoC audio using 22 11 loongson I2S controller. ··· 13 24 The driver add support for ALSA SoC Audio support using 14 25 loongson I2S controller. 15 26 27 + config SND_SOC_LOONGSON_I2S_PCI 28 + tristate "Loongson I2S-PCI Device Driver" 29 + depends on LOONGARCH || COMPILE_TEST 30 + select REGMAP_MMIO 31 + help 32 + Say Y or M if you want to add support for I2S driver for 33 + Loongson I2S controller. 34 + 35 + The controller is found in loongson bridge chips or SoCs, 36 + and work as a PCI device. 37 + 38 + config SND_SOC_LOONGSON_I2S_PLATFORM 39 + tristate "Loongson I2S-PLAT Device Driver" 40 + depends on LOONGARCH || COMPILE_TEST 41 + select REGMAP_MMIO 42 + select SND_SOC_GENERIC_DMAENGINE_PCM 43 + help 44 + Say Y or M if you want to add support for I2S driver for 45 + Loongson I2S controller. 46 + 47 + The controller work as a platform device, we can found it in 48 + Loongson-2K1000 SoCs. 16 49 endmenu
+3
sound/soc/loongson/Makefile
··· 3 3 snd-soc-loongson-i2s-pci-y := loongson_i2s_pci.o loongson_i2s.o loongson_dma.o 4 4 obj-$(CONFIG_SND_SOC_LOONGSON_I2S_PCI) += snd-soc-loongson-i2s-pci.o 5 5 6 + snd-soc-loongson-i2s-plat-y := loongson_i2s_plat.o loongson_i2s.o 7 + obj-$(CONFIG_SND_SOC_LOONGSON_I2S_PLATFORM) += snd-soc-loongson-i2s-plat.o 8 + 6 9 #Machine Support 7 10 snd-soc-loongson-card-y := loongson_card.o 8 11 obj-$(CONFIG_SND_SOC_LOONGSON_CARD) += snd-soc-loongson-card.o
+185
sound/soc/loongson/loongson_i2s_plat.c
··· 1 + // SPDX-License-Identifier: GPL-2.0 2 + // 3 + // Loongson I2S controller master mode dirver(platform device) 4 + // 5 + // Copyright (C) 2023-2024 Loongson Technology Corporation Limited 6 + // 7 + // Author: Yingkun Meng <mengyingkun@loongson.cn> 8 + // Binbin Zhou <zhoubinbin@loongson.cn> 9 + 10 + #include <linux/clk.h> 11 + #include <linux/dma-mapping.h> 12 + #include <linux/module.h> 13 + #include <linux/of_dma.h> 14 + #include <linux/platform_device.h> 15 + #include <linux/pm_runtime.h> 16 + #include <sound/dmaengine_pcm.h> 17 + #include <sound/pcm.h> 18 + #include <sound/pcm_params.h> 19 + #include <sound/soc.h> 20 + 21 + #include "loongson_i2s.h" 22 + 23 + #define LOONGSON_I2S_RX_DMA_OFFSET 21 24 + #define LOONGSON_I2S_TX_DMA_OFFSET 18 25 + 26 + #define LOONGSON_DMA0_CONF 0x0 27 + #define LOONGSON_DMA1_CONF 0x1 28 + #define LOONGSON_DMA2_CONF 0x2 29 + #define LOONGSON_DMA3_CONF 0x3 30 + #define LOONGSON_DMA4_CONF 0x4 31 + 32 + /* periods_max = PAGE_SIZE / sizeof(struct ls_dma_chan_reg) */ 33 + static const struct snd_pcm_hardware loongson_pcm_hardware = { 34 + .info = SNDRV_PCM_INFO_MMAP | 35 + SNDRV_PCM_INFO_INTERLEAVED | 36 + SNDRV_PCM_INFO_MMAP_VALID | 37 + SNDRV_PCM_INFO_RESUME | 38 + SNDRV_PCM_INFO_PAUSE, 39 + .formats = SNDRV_PCM_FMTBIT_S16_LE | 40 + SNDRV_PCM_FMTBIT_S20_3LE | 41 + SNDRV_PCM_FMTBIT_S24_LE, 42 + .period_bytes_min = 128, 43 + .period_bytes_max = 128 * 1024, 44 + .periods_min = 1, 45 + .periods_max = 64, 46 + .buffer_bytes_max = 1024 * 1024, 47 + }; 48 + 49 + static const struct snd_dmaengine_pcm_config loongson_dmaengine_pcm_config = { 50 + .pcm_hardware = &loongson_pcm_hardware, 51 + .prepare_slave_config = snd_dmaengine_pcm_prepare_slave_config, 52 + .prealloc_buffer_size = 128 * 1024, 53 + }; 54 + 55 + static int loongson_pcm_open(struct snd_soc_component *component, 56 + struct snd_pcm_substream *substream) 57 + { 58 + struct snd_pcm_runtime *runtime = substream->runtime; 59 + 60 + if (substream->pcm->device & 1) { 61 + runtime->hw.info &= ~SNDRV_PCM_INFO_INTERLEAVED; 62 + runtime->hw.info |= SNDRV_PCM_INFO_NONINTERLEAVED; 63 + } 64 + 65 + if (substream->pcm->device & 2) 66 + runtime->hw.info &= ~(SNDRV_PCM_INFO_MMAP | 67 + SNDRV_PCM_INFO_MMAP_VALID); 68 + /* 69 + * For mysterious reasons (and despite what the manual says) 70 + * playback samples are lost if the DMA count is not a multiple 71 + * of the DMA burst size. Let's add a rule to enforce that. 72 + */ 73 + snd_pcm_hw_constraint_step(runtime, 0, 74 + SNDRV_PCM_HW_PARAM_PERIOD_BYTES, 128); 75 + snd_pcm_hw_constraint_step(runtime, 0, 76 + SNDRV_PCM_HW_PARAM_BUFFER_BYTES, 128); 77 + snd_pcm_hw_constraint_integer(substream->runtime, 78 + SNDRV_PCM_HW_PARAM_PERIODS); 79 + 80 + return 0; 81 + } 82 + 83 + static const struct snd_soc_component_driver loongson_i2s_component_driver = { 84 + .name = LS_I2S_DRVNAME, 85 + .open = loongson_pcm_open, 86 + }; 87 + 88 + static const struct regmap_config loongson_i2s_regmap_config = { 89 + .reg_bits = 32, 90 + .reg_stride = 4, 91 + .val_bits = 32, 92 + .max_register = 0x14, 93 + .cache_type = REGCACHE_FLAT, 94 + }; 95 + 96 + static int loongson_i2s_apbdma_config(struct platform_device *pdev) 97 + { 98 + int val; 99 + void __iomem *regs; 100 + 101 + regs = devm_platform_ioremap_resource(pdev, 1); 102 + if (IS_ERR(regs)) 103 + return PTR_ERR(regs); 104 + 105 + val = readl(regs); 106 + val |= LOONGSON_DMA2_CONF << LOONGSON_I2S_TX_DMA_OFFSET; 107 + val |= LOONGSON_DMA3_CONF << LOONGSON_I2S_RX_DMA_OFFSET; 108 + writel(val, regs); 109 + 110 + return 0; 111 + } 112 + 113 + static int loongson_i2s_plat_probe(struct platform_device *pdev) 114 + { 115 + struct device *dev = &pdev->dev; 116 + struct loongson_i2s *i2s; 117 + struct resource *res; 118 + struct clk *i2s_clk; 119 + int ret; 120 + 121 + i2s = devm_kzalloc(dev, sizeof(*i2s), GFP_KERNEL); 122 + if (!i2s) 123 + return -ENOMEM; 124 + 125 + ret = loongson_i2s_apbdma_config(pdev); 126 + if (ret) 127 + return ret; 128 + 129 + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 130 + i2s->reg_base = devm_ioremap_resource(&pdev->dev, res); 131 + if (IS_ERR(i2s->reg_base)) 132 + return dev_err_probe(dev, PTR_ERR(i2s->reg_base), 133 + "devm_ioremap_resource failed\n"); 134 + 135 + i2s->regmap = devm_regmap_init_mmio(dev, i2s->reg_base, 136 + &loongson_i2s_regmap_config); 137 + if (IS_ERR(i2s->regmap)) 138 + return dev_err_probe(dev, PTR_ERR(i2s->regmap), 139 + "devm_regmap_init_mmio failed\n"); 140 + 141 + i2s->playback_dma_data.addr = res->start + LS_I2S_TX_DATA; 142 + i2s->playback_dma_data.addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES; 143 + i2s->playback_dma_data.maxburst = 4; 144 + 145 + i2s->capture_dma_data.addr = res->start + LS_I2S_RX_DATA; 146 + i2s->capture_dma_data.addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES; 147 + i2s->capture_dma_data.maxburst = 4; 148 + 149 + i2s_clk = devm_clk_get_enabled(dev, NULL); 150 + if (IS_ERR(i2s_clk)) 151 + return dev_err_probe(dev, PTR_ERR(i2s_clk), "clock property invalid\n"); 152 + i2s->clk_rate = clk_get_rate(i2s_clk); 153 + 154 + dma_set_mask_and_coherent(dev, DMA_BIT_MASK(64)); 155 + dev_set_name(dev, LS_I2S_DRVNAME); 156 + dev_set_drvdata(dev, i2s); 157 + 158 + ret = devm_snd_soc_register_component(dev, &loongson_i2s_component_driver, 159 + &loongson_i2s_dai, 1); 160 + if (ret) 161 + return dev_err_probe(dev, ret, "failed to register DAI\n"); 162 + 163 + return devm_snd_dmaengine_pcm_register(dev, &loongson_dmaengine_pcm_config, 164 + SND_DMAENGINE_PCM_FLAG_COMPAT); 165 + } 166 + 167 + static const struct of_device_id loongson_i2s_ids[] = { 168 + { .compatible = "loongson,ls2k1000-i2s" }, 169 + { /* sentinel */ }, 170 + }; 171 + MODULE_DEVICE_TABLE(of, loongson_i2s_ids); 172 + 173 + static struct platform_driver loongson_i2s_driver = { 174 + .probe = loongson_i2s_plat_probe, 175 + .driver = { 176 + .name = "loongson-i2s-plat", 177 + .pm = pm_sleep_ptr(&loongson_i2s_pm), 178 + .of_match_table = loongson_i2s_ids, 179 + }, 180 + }; 181 + module_platform_driver(loongson_i2s_driver); 182 + 183 + MODULE_DESCRIPTION("Loongson I2S Master Mode ASoC Driver"); 184 + MODULE_AUTHOR("Loongson Technology Corporation Limited"); 185 + MODULE_LICENSE("GPL");