14 #include <linux/kernel.h>
15 #include <linux/module.h>
17 #include <linux/slab.h>
28 #define JZ4740_REG_CODEC_1 0x0
29 #define JZ4740_REG_CODEC_2 0x1
31 #define JZ4740_CODEC_1_LINE_ENABLE BIT(29)
32 #define JZ4740_CODEC_1_MIC_ENABLE BIT(28)
33 #define JZ4740_CODEC_1_SW1_ENABLE BIT(27)
34 #define JZ4740_CODEC_1_ADC_ENABLE BIT(26)
35 #define JZ4740_CODEC_1_SW2_ENABLE BIT(25)
36 #define JZ4740_CODEC_1_DAC_ENABLE BIT(24)
37 #define JZ4740_CODEC_1_VREF_DISABLE BIT(20)
38 #define JZ4740_CODEC_1_VREF_AMP_DISABLE BIT(19)
39 #define JZ4740_CODEC_1_VREF_PULLDOWN BIT(18)
40 #define JZ4740_CODEC_1_VREF_LOW_CURRENT BIT(17)
41 #define JZ4740_CODEC_1_VREF_HIGH_CURRENT BIT(16)
42 #define JZ4740_CODEC_1_HEADPHONE_DISABLE BIT(14)
43 #define JZ4740_CODEC_1_HEADPHONE_AMP_CHANGE_ANY BIT(13)
44 #define JZ4740_CODEC_1_HEADPHONE_CHARGE BIT(12)
45 #define JZ4740_CODEC_1_HEADPHONE_PULLDOWN (BIT(11) | BIT(10))
46 #define JZ4740_CODEC_1_HEADPHONE_POWERDOWN_M BIT(9)
47 #define JZ4740_CODEC_1_HEADPHONE_POWERDOWN BIT(8)
48 #define JZ4740_CODEC_1_SUSPEND BIT(1)
49 #define JZ4740_CODEC_1_RESET BIT(0)
51 #define JZ4740_CODEC_1_LINE_ENABLE_OFFSET 29
52 #define JZ4740_CODEC_1_MIC_ENABLE_OFFSET 28
53 #define JZ4740_CODEC_1_SW1_ENABLE_OFFSET 27
54 #define JZ4740_CODEC_1_ADC_ENABLE_OFFSET 26
55 #define JZ4740_CODEC_1_SW2_ENABLE_OFFSET 25
56 #define JZ4740_CODEC_1_DAC_ENABLE_OFFSET 24
57 #define JZ4740_CODEC_1_HEADPHONE_DISABLE_OFFSET 14
58 #define JZ4740_CODEC_1_HEADPHONE_POWERDOWN_OFFSET 8
60 #define JZ4740_CODEC_2_INPUT_VOLUME_MASK 0x1f0000
61 #define JZ4740_CODEC_2_SAMPLE_RATE_MASK 0x000f00
62 #define JZ4740_CODEC_2_MIC_BOOST_GAIN_MASK 0x000030
63 #define JZ4740_CODEC_2_HEADPHONE_VOLUME_MASK 0x000003
65 #define JZ4740_CODEC_2_INPUT_VOLUME_OFFSET 16
66 #define JZ4740_CODEC_2_SAMPLE_RATE_OFFSET 8
67 #define JZ4740_CODEC_2_MIC_BOOST_GAIN_OFFSET 4
68 #define JZ4740_CODEC_2_HEADPHONE_VOLUME_OFFSET 0
70 static const uint32_t jz4740_codec_regs[] = {
71 0x021b2302, 0x00170803,
83 return readl(jz4740_codec->
base + (reg << 2));
131 jz4740_codec_output_controls,
135 jz4740_codec_input_controls,
148 {
"Line Input",
NULL,
"LIN"},
149 {
"Line Input",
NULL,
"RIN"},
151 {
"Input Mixer",
"Line Capture Switch",
"Line Input"},
152 {
"Input Mixer",
"Mic Capture Switch",
"MIC"},
154 {
"ADC",
NULL,
"Input Mixer"},
156 {
"Output Mixer",
"Bypass Switch",
"Input Mixer"},
157 {
"Output Mixer",
"DAC Switch",
"DAC"},
159 {
"LOUT",
NULL,
"Output Mixer"},
160 {
"ROUT",
NULL,
"Output Mixer"},
210 .hw_params = jz4740_codec_hw_params,
214 .name =
"jz4740-hifi",
216 .stream_name =
"Playback",
223 .stream_name =
"Capture",
229 .ops = &jz4740_codec_dai_ops,
230 .symmetric_rates = 1,
245 for (i = 0; i <
ARRAY_SIZE(jz4740_codec_regs); ++
i)
246 jz4740_codec_write(codec, i, cache[i]);
249 static int jz4740_codec_set_bias_level(
struct snd_soc_codec *codec,
269 jz4740_codec_wakeup(codec);
295 static int jz4740_codec_dev_probe(
struct snd_soc_codec *codec)
305 static int jz4740_codec_dev_remove(
struct snd_soc_codec *codec)
312 #ifdef CONFIG_PM_SLEEP
325 #define jz4740_codec_suspend NULL
326 #define jz4740_codec_resume NULL
330 .probe = jz4740_codec_dev_probe,
331 .remove = jz4740_codec_dev_remove,
334 .read = jz4740_codec_read,
335 .write = jz4740_codec_write,
336 .set_bias_level = jz4740_codec_set_bias_level,
337 .reg_cache_default = jz4740_codec_regs,
338 .reg_word_size =
sizeof(
u32),
343 .dapm_widgets = jz4740_codec_dapm_widgets,
344 .num_dapm_widgets =
ARRAY_SIZE(jz4740_codec_dapm_widgets),
345 .dapm_routes = jz4740_codec_dapm_routes,
346 .num_dapm_routes =
ARRAY_SIZE(jz4740_codec_dapm_routes),
362 dev_err(&pdev->
dev,
"Failed to get mmio memory resource\n");
369 dev_err(&pdev->
dev,
"Failed to request mmio memory region\n");
375 if (!jz4740_codec->
base) {
376 dev_err(&pdev->
dev,
"Failed to ioremap mmio memory\n");
378 goto err_release_mem_region;
382 platform_set_drvdata(pdev, jz4740_codec);
385 &soc_codec_dev_jz4740_codec, &jz4740_codec_dai, 1);
387 dev_err(&pdev->
dev,
"Failed to register codec\n");
395 err_release_mem_region:
403 struct jz4740_codec *jz4740_codec = platform_get_drvdata(pdev);
411 platform_set_drvdata(pdev,
NULL);
417 .probe = jz4740_codec_probe,
420 .name =
"jz4740-codec",