xref: /OK3568_Linux_fs/kernel/sound/soc/codecs/cq93vc.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun // SPDX-License-Identifier: GPL-2.0-or-later
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun  * ALSA SoC CQ0093 Voice Codec Driver for DaVinci platforms
4*4882a593Smuzhiyun  *
5*4882a593Smuzhiyun  * Copyright (C) 2010 Texas Instruments, Inc
6*4882a593Smuzhiyun  *
7*4882a593Smuzhiyun  * Author: Miguel Aguilar <miguel.aguilar@ridgerun.com>
8*4882a593Smuzhiyun  */
9*4882a593Smuzhiyun #include <linux/module.h>
10*4882a593Smuzhiyun #include <linux/moduleparam.h>
11*4882a593Smuzhiyun #include <linux/init.h>
12*4882a593Smuzhiyun #include <linux/io.h>
13*4882a593Smuzhiyun #include <linux/delay.h>
14*4882a593Smuzhiyun #include <linux/pm.h>
15*4882a593Smuzhiyun #include <linux/platform_device.h>
16*4882a593Smuzhiyun #include <linux/device.h>
17*4882a593Smuzhiyun #include <linux/slab.h>
18*4882a593Smuzhiyun #include <linux/clk.h>
19*4882a593Smuzhiyun #include <linux/mfd/davinci_voicecodec.h>
20*4882a593Smuzhiyun #include <linux/spi/spi.h>
21*4882a593Smuzhiyun 
22*4882a593Smuzhiyun #include <sound/core.h>
23*4882a593Smuzhiyun #include <sound/pcm.h>
24*4882a593Smuzhiyun #include <sound/pcm_params.h>
25*4882a593Smuzhiyun #include <sound/soc.h>
26*4882a593Smuzhiyun #include <sound/initval.h>
27*4882a593Smuzhiyun 
28*4882a593Smuzhiyun static const struct snd_kcontrol_new cq93vc_snd_controls[] = {
29*4882a593Smuzhiyun 	SOC_SINGLE("PGA Capture Volume", DAVINCI_VC_REG05, 0, 0x03, 0),
30*4882a593Smuzhiyun 	SOC_SINGLE("Mono DAC Playback Volume", DAVINCI_VC_REG09, 0, 0x3f, 0),
31*4882a593Smuzhiyun };
32*4882a593Smuzhiyun 
cq93vc_mute(struct snd_soc_dai * dai,int mute,int direction)33*4882a593Smuzhiyun static int cq93vc_mute(struct snd_soc_dai *dai, int mute, int direction)
34*4882a593Smuzhiyun {
35*4882a593Smuzhiyun 	struct snd_soc_component *component = dai->component;
36*4882a593Smuzhiyun 	u8 reg;
37*4882a593Smuzhiyun 
38*4882a593Smuzhiyun 	if (mute)
39*4882a593Smuzhiyun 		reg = DAVINCI_VC_REG09_MUTE;
40*4882a593Smuzhiyun 	else
41*4882a593Smuzhiyun 		reg = 0;
42*4882a593Smuzhiyun 
43*4882a593Smuzhiyun 	snd_soc_component_update_bits(component, DAVINCI_VC_REG09, DAVINCI_VC_REG09_MUTE,
44*4882a593Smuzhiyun 			    reg);
45*4882a593Smuzhiyun 
46*4882a593Smuzhiyun 	return 0;
47*4882a593Smuzhiyun }
48*4882a593Smuzhiyun 
cq93vc_set_dai_sysclk(struct snd_soc_dai * codec_dai,int clk_id,unsigned int freq,int dir)49*4882a593Smuzhiyun static int cq93vc_set_dai_sysclk(struct snd_soc_dai *codec_dai,
50*4882a593Smuzhiyun 				 int clk_id, unsigned int freq, int dir)
51*4882a593Smuzhiyun {
52*4882a593Smuzhiyun 	switch (freq) {
53*4882a593Smuzhiyun 	case 22579200:
54*4882a593Smuzhiyun 	case 27000000:
55*4882a593Smuzhiyun 	case 33868800:
56*4882a593Smuzhiyun 		return 0;
57*4882a593Smuzhiyun 	}
58*4882a593Smuzhiyun 
59*4882a593Smuzhiyun 	return -EINVAL;
60*4882a593Smuzhiyun }
61*4882a593Smuzhiyun 
cq93vc_set_bias_level(struct snd_soc_component * component,enum snd_soc_bias_level level)62*4882a593Smuzhiyun static int cq93vc_set_bias_level(struct snd_soc_component *component,
63*4882a593Smuzhiyun 				enum snd_soc_bias_level level)
64*4882a593Smuzhiyun {
65*4882a593Smuzhiyun 	switch (level) {
66*4882a593Smuzhiyun 	case SND_SOC_BIAS_ON:
67*4882a593Smuzhiyun 		snd_soc_component_write(component, DAVINCI_VC_REG12,
68*4882a593Smuzhiyun 			     DAVINCI_VC_REG12_POWER_ALL_ON);
69*4882a593Smuzhiyun 		break;
70*4882a593Smuzhiyun 	case SND_SOC_BIAS_PREPARE:
71*4882a593Smuzhiyun 		break;
72*4882a593Smuzhiyun 	case SND_SOC_BIAS_STANDBY:
73*4882a593Smuzhiyun 		snd_soc_component_write(component, DAVINCI_VC_REG12,
74*4882a593Smuzhiyun 			     DAVINCI_VC_REG12_POWER_ALL_OFF);
75*4882a593Smuzhiyun 		break;
76*4882a593Smuzhiyun 	case SND_SOC_BIAS_OFF:
77*4882a593Smuzhiyun 		/* force all power off */
78*4882a593Smuzhiyun 		snd_soc_component_write(component, DAVINCI_VC_REG12,
79*4882a593Smuzhiyun 			     DAVINCI_VC_REG12_POWER_ALL_OFF);
80*4882a593Smuzhiyun 		break;
81*4882a593Smuzhiyun 	}
82*4882a593Smuzhiyun 
83*4882a593Smuzhiyun 	return 0;
84*4882a593Smuzhiyun }
85*4882a593Smuzhiyun 
86*4882a593Smuzhiyun #define CQ93VC_RATES	(SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000)
87*4882a593Smuzhiyun #define CQ93VC_FORMATS	(SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE)
88*4882a593Smuzhiyun 
89*4882a593Smuzhiyun static const struct snd_soc_dai_ops cq93vc_dai_ops = {
90*4882a593Smuzhiyun 	.mute_stream	= cq93vc_mute,
91*4882a593Smuzhiyun 	.set_sysclk	= cq93vc_set_dai_sysclk,
92*4882a593Smuzhiyun 	.no_capture_mute = 1,
93*4882a593Smuzhiyun };
94*4882a593Smuzhiyun 
95*4882a593Smuzhiyun static struct snd_soc_dai_driver cq93vc_dai = {
96*4882a593Smuzhiyun 	.name = "cq93vc-hifi",
97*4882a593Smuzhiyun 	.playback = {
98*4882a593Smuzhiyun 		.stream_name = "Playback",
99*4882a593Smuzhiyun 		.channels_min = 1,
100*4882a593Smuzhiyun 		.channels_max = 2,
101*4882a593Smuzhiyun 		.rates = CQ93VC_RATES,
102*4882a593Smuzhiyun 		.formats = CQ93VC_FORMATS,},
103*4882a593Smuzhiyun 	.capture = {
104*4882a593Smuzhiyun 		.stream_name = "Capture",
105*4882a593Smuzhiyun 		.channels_min = 1,
106*4882a593Smuzhiyun 		.channels_max = 2,
107*4882a593Smuzhiyun 		.rates = CQ93VC_RATES,
108*4882a593Smuzhiyun 		.formats = CQ93VC_FORMATS,},
109*4882a593Smuzhiyun 	.ops = &cq93vc_dai_ops,
110*4882a593Smuzhiyun };
111*4882a593Smuzhiyun 
cq93vc_probe(struct snd_soc_component * component)112*4882a593Smuzhiyun static int cq93vc_probe(struct snd_soc_component *component)
113*4882a593Smuzhiyun {
114*4882a593Smuzhiyun 	struct davinci_vc *davinci_vc = component->dev->platform_data;
115*4882a593Smuzhiyun 
116*4882a593Smuzhiyun 	snd_soc_component_init_regmap(component, davinci_vc->regmap);
117*4882a593Smuzhiyun 
118*4882a593Smuzhiyun 	return 0;
119*4882a593Smuzhiyun }
120*4882a593Smuzhiyun 
121*4882a593Smuzhiyun static const struct snd_soc_component_driver soc_component_dev_cq93vc = {
122*4882a593Smuzhiyun 	.set_bias_level		= cq93vc_set_bias_level,
123*4882a593Smuzhiyun 	.probe			= cq93vc_probe,
124*4882a593Smuzhiyun 	.controls		= cq93vc_snd_controls,
125*4882a593Smuzhiyun 	.num_controls		= ARRAY_SIZE(cq93vc_snd_controls),
126*4882a593Smuzhiyun 	.idle_bias_on		= 1,
127*4882a593Smuzhiyun 	.use_pmdown_time	= 1,
128*4882a593Smuzhiyun 	.endianness		= 1,
129*4882a593Smuzhiyun 	.non_legacy_dai_naming	= 1,
130*4882a593Smuzhiyun };
131*4882a593Smuzhiyun 
cq93vc_platform_probe(struct platform_device * pdev)132*4882a593Smuzhiyun static int cq93vc_platform_probe(struct platform_device *pdev)
133*4882a593Smuzhiyun {
134*4882a593Smuzhiyun 	return devm_snd_soc_register_component(&pdev->dev,
135*4882a593Smuzhiyun 			&soc_component_dev_cq93vc, &cq93vc_dai, 1);
136*4882a593Smuzhiyun }
137*4882a593Smuzhiyun 
cq93vc_platform_remove(struct platform_device * pdev)138*4882a593Smuzhiyun static int cq93vc_platform_remove(struct platform_device *pdev)
139*4882a593Smuzhiyun {
140*4882a593Smuzhiyun 	return 0;
141*4882a593Smuzhiyun }
142*4882a593Smuzhiyun 
143*4882a593Smuzhiyun static struct platform_driver cq93vc_codec_driver = {
144*4882a593Smuzhiyun 	.driver = {
145*4882a593Smuzhiyun 			.name = "cq93vc-codec",
146*4882a593Smuzhiyun 	},
147*4882a593Smuzhiyun 
148*4882a593Smuzhiyun 	.probe = cq93vc_platform_probe,
149*4882a593Smuzhiyun 	.remove = cq93vc_platform_remove,
150*4882a593Smuzhiyun };
151*4882a593Smuzhiyun 
152*4882a593Smuzhiyun module_platform_driver(cq93vc_codec_driver);
153*4882a593Smuzhiyun 
154*4882a593Smuzhiyun MODULE_DESCRIPTION("Texas Instruments DaVinci ASoC CQ0093 Voice Codec Driver");
155*4882a593Smuzhiyun MODULE_AUTHOR("Miguel Aguilar");
156*4882a593Smuzhiyun MODULE_LICENSE("GPL");
157