diff options
author | Kenneth Westfield <kwestfie@codeaurora.org> | 2015-02-05 15:53:40 -0500 |
---|---|---|
committer | Mark Brown <broonie@kernel.org> | 2015-02-06 17:12:13 -0500 |
commit | af5adf129369125bba8fa7ca594a7abaf226b27c (patch) | |
tree | c1c6e39ff436a20eb4d91e9f21e3f678bd1f10f1 /sound | |
parent | c028d4165fe56fc51efb53dd4b04aa157d005dc5 (diff) |
ASoC: max98357a: Add MAX98357A codec driver
Add codec driver for the Maxim MAX98357A DAC.
Signed-off-by: Kenneth Westfield <kwestfie@codeaurora.org>
Acked-by: Banajit Goswami <bgoswami@codeaurora.org>
Signed-off-by: Mark Brown <broonie@kernel.org>
Diffstat (limited to 'sound')
-rw-r--r-- | sound/soc/codecs/Kconfig | 4 | ||||
-rw-r--r-- | sound/soc/codecs/Makefile | 2 | ||||
-rw-r--r-- | sound/soc/codecs/max98357a.c | 138 |
3 files changed, 144 insertions, 0 deletions
diff --git a/sound/soc/codecs/Kconfig b/sound/soc/codecs/Kconfig index 8349f982a586..6ecac1e4428e 100644 --- a/sound/soc/codecs/Kconfig +++ b/sound/soc/codecs/Kconfig | |||
@@ -69,6 +69,7 @@ config SND_SOC_ALL_CODECS | |||
69 | select SND_SOC_MAX98088 if I2C | 69 | select SND_SOC_MAX98088 if I2C |
70 | select SND_SOC_MAX98090 if I2C | 70 | select SND_SOC_MAX98090 if I2C |
71 | select SND_SOC_MAX98095 if I2C | 71 | select SND_SOC_MAX98095 if I2C |
72 | select SND_SOC_MAX98357A | ||
72 | select SND_SOC_MAX9850 if I2C | 73 | select SND_SOC_MAX9850 if I2C |
73 | select SND_SOC_MAX9768 if I2C | 74 | select SND_SOC_MAX9768 if I2C |
74 | select SND_SOC_MAX9877 if I2C | 75 | select SND_SOC_MAX9877 if I2C |
@@ -456,6 +457,9 @@ config SND_SOC_MAX98090 | |||
456 | config SND_SOC_MAX98095 | 457 | config SND_SOC_MAX98095 |
457 | tristate | 458 | tristate |
458 | 459 | ||
460 | config SND_SOC_MAX98357A | ||
461 | tristate | ||
462 | |||
459 | config SND_SOC_MAX9850 | 463 | config SND_SOC_MAX9850 |
460 | tristate | 464 | tristate |
461 | 465 | ||
diff --git a/sound/soc/codecs/Makefile b/sound/soc/codecs/Makefile index bbdfd1e1c182..69b8666d187a 100644 --- a/sound/soc/codecs/Makefile +++ b/sound/soc/codecs/Makefile | |||
@@ -64,6 +64,7 @@ snd-soc-max9768-objs := max9768.o | |||
64 | snd-soc-max98088-objs := max98088.o | 64 | snd-soc-max98088-objs := max98088.o |
65 | snd-soc-max98090-objs := max98090.o | 65 | snd-soc-max98090-objs := max98090.o |
66 | snd-soc-max98095-objs := max98095.o | 66 | snd-soc-max98095-objs := max98095.o |
67 | snd-soc-max98357a-objs := max98357a.o | ||
67 | snd-soc-max9850-objs := max9850.o | 68 | snd-soc-max9850-objs := max9850.o |
68 | snd-soc-mc13783-objs := mc13783.o | 69 | snd-soc-mc13783-objs := mc13783.o |
69 | snd-soc-ml26124-objs := ml26124.o | 70 | snd-soc-ml26124-objs := ml26124.o |
@@ -245,6 +246,7 @@ obj-$(CONFIG_SND_SOC_MAX9768) += snd-soc-max9768.o | |||
245 | obj-$(CONFIG_SND_SOC_MAX98088) += snd-soc-max98088.o | 246 | obj-$(CONFIG_SND_SOC_MAX98088) += snd-soc-max98088.o |
246 | obj-$(CONFIG_SND_SOC_MAX98090) += snd-soc-max98090.o | 247 | obj-$(CONFIG_SND_SOC_MAX98090) += snd-soc-max98090.o |
247 | obj-$(CONFIG_SND_SOC_MAX98095) += snd-soc-max98095.o | 248 | obj-$(CONFIG_SND_SOC_MAX98095) += snd-soc-max98095.o |
249 | obj-$(CONFIG_SND_SOC_MAX98357A) += snd-soc-max98357a.o | ||
248 | obj-$(CONFIG_SND_SOC_MAX9850) += snd-soc-max9850.o | 250 | obj-$(CONFIG_SND_SOC_MAX9850) += snd-soc-max9850.o |
249 | obj-$(CONFIG_SND_SOC_MC13783) += snd-soc-mc13783.o | 251 | obj-$(CONFIG_SND_SOC_MC13783) += snd-soc-mc13783.o |
250 | obj-$(CONFIG_SND_SOC_ML26124) += snd-soc-ml26124.o | 252 | obj-$(CONFIG_SND_SOC_ML26124) += snd-soc-ml26124.o |
diff --git a/sound/soc/codecs/max98357a.c b/sound/soc/codecs/max98357a.c new file mode 100644 index 000000000000..98b915314d7a --- /dev/null +++ b/sound/soc/codecs/max98357a.c | |||
@@ -0,0 +1,138 @@ | |||
1 | /* Copyright (c) 2010-2011,2013-2015 The Linux Foundation. All rights reserved. | ||
2 | * | ||
3 | * This program is free software; you can redistribute it and/or modify | ||
4 | * it under the terms of the GNU General Public License version 2 and | ||
5 | * only version 2 as published by the Free Software Foundation. | ||
6 | * | ||
7 | * This program is distributed in the hope that it will be useful, | ||
8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
10 | * GNU General Public License for more details. | ||
11 | * | ||
12 | * max98357a.c -- MAX98357A ALSA SoC Codec driver | ||
13 | */ | ||
14 | |||
15 | #include <linux/module.h> | ||
16 | #include <linux/gpio.h> | ||
17 | #include <sound/soc.h> | ||
18 | |||
19 | #define DRV_NAME "max98357a" | ||
20 | |||
21 | static int max98357a_daiops_trigger(struct snd_pcm_substream *substream, | ||
22 | int cmd, struct snd_soc_dai *dai) | ||
23 | { | ||
24 | struct gpio_desc *sdmode = snd_soc_dai_get_drvdata(dai); | ||
25 | |||
26 | switch (cmd) { | ||
27 | case SNDRV_PCM_TRIGGER_START: | ||
28 | case SNDRV_PCM_TRIGGER_RESUME: | ||
29 | case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: | ||
30 | gpiod_set_value(sdmode, 1); | ||
31 | break; | ||
32 | case SNDRV_PCM_TRIGGER_STOP: | ||
33 | case SNDRV_PCM_TRIGGER_SUSPEND: | ||
34 | case SNDRV_PCM_TRIGGER_PAUSE_PUSH: | ||
35 | gpiod_set_value(sdmode, 0); | ||
36 | break; | ||
37 | } | ||
38 | |||
39 | return 0; | ||
40 | } | ||
41 | |||
42 | static const struct snd_soc_dapm_widget max98357a_dapm_widgets[] = { | ||
43 | SND_SOC_DAPM_DAC("SDMode", NULL, SND_SOC_NOPM, 0, 0), | ||
44 | SND_SOC_DAPM_OUTPUT("Speaker"), | ||
45 | }; | ||
46 | |||
47 | static const struct snd_soc_dapm_route max98357a_dapm_routes[] = { | ||
48 | {"Speaker", NULL, "SDMode"}, | ||
49 | }; | ||
50 | |||
51 | static int max98357a_codec_probe(struct snd_soc_codec *codec) | ||
52 | { | ||
53 | struct gpio_desc *sdmode; | ||
54 | |||
55 | sdmode = devm_gpiod_get(codec->dev, "sdmode"); | ||
56 | if (IS_ERR(sdmode)) { | ||
57 | dev_err(codec->dev, "%s() unable to get sdmode GPIO: %ld\n", | ||
58 | __func__, PTR_ERR(sdmode)); | ||
59 | return PTR_ERR(sdmode); | ||
60 | } | ||
61 | gpiod_direction_output(sdmode, 0); | ||
62 | snd_soc_codec_set_drvdata(codec, sdmode); | ||
63 | |||
64 | return 0; | ||
65 | } | ||
66 | |||
67 | static struct snd_soc_codec_driver max98357a_codec_driver = { | ||
68 | .probe = max98357a_codec_probe, | ||
69 | .dapm_widgets = max98357a_dapm_widgets, | ||
70 | .num_dapm_widgets = ARRAY_SIZE(max98357a_dapm_widgets), | ||
71 | .dapm_routes = max98357a_dapm_routes, | ||
72 | .num_dapm_routes = ARRAY_SIZE(max98357a_dapm_routes), | ||
73 | }; | ||
74 | |||
75 | static struct snd_soc_dai_ops max98357a_dai_ops = { | ||
76 | .trigger = max98357a_daiops_trigger, | ||
77 | }; | ||
78 | |||
79 | static struct snd_soc_dai_driver max98357a_dai_driver = { | ||
80 | .name = DRV_NAME, | ||
81 | .playback = { | ||
82 | .stream_name = DRV_NAME "-playback", | ||
83 | .formats = SNDRV_PCM_FMTBIT_S16 | | ||
84 | SNDRV_PCM_FMTBIT_S24 | | ||
85 | SNDRV_PCM_FMTBIT_S32, | ||
86 | .rates = SNDRV_PCM_RATE_8000 | | ||
87 | SNDRV_PCM_RATE_16000 | | ||
88 | SNDRV_PCM_RATE_48000 | | ||
89 | SNDRV_PCM_RATE_96000, | ||
90 | .rate_min = 8000, | ||
91 | .rate_max = 96000, | ||
92 | .channels_min = 1, | ||
93 | .channels_max = 2, | ||
94 | }, | ||
95 | .ops = &max98357a_dai_ops, | ||
96 | }; | ||
97 | |||
98 | static int max98357a_platform_probe(struct platform_device *pdev) | ||
99 | { | ||
100 | int ret; | ||
101 | |||
102 | ret = snd_soc_register_codec(&pdev->dev, &max98357a_codec_driver, | ||
103 | &max98357a_dai_driver, 1); | ||
104 | if (ret) | ||
105 | dev_err(&pdev->dev, "%s() error registering codec driver: %d\n", | ||
106 | __func__, ret); | ||
107 | |||
108 | return ret; | ||
109 | } | ||
110 | |||
111 | static int max98357a_platform_remove(struct platform_device *pdev) | ||
112 | { | ||
113 | snd_soc_unregister_codec(&pdev->dev); | ||
114 | |||
115 | return 0; | ||
116 | } | ||
117 | |||
118 | #ifdef CONFIG_OF | ||
119 | static const struct of_device_id max98357a_device_id[] = { | ||
120 | { .compatible = "maxim," DRV_NAME, }, | ||
121 | {} | ||
122 | }; | ||
123 | #endif | ||
124 | |||
125 | static struct platform_driver max98357a_platform_driver = { | ||
126 | .driver = { | ||
127 | .name = DRV_NAME, | ||
128 | .of_match_table = of_match_ptr(max98357a_device_id), | ||
129 | }, | ||
130 | .probe = max98357a_platform_probe, | ||
131 | .remove = max98357a_platform_remove, | ||
132 | }; | ||
133 | module_platform_driver(max98357a_platform_driver); | ||
134 | |||
135 | MODULE_DESCRIPTION("Maxim MAX98357A Codec Driver"); | ||
136 | MODULE_LICENSE("GPL v2"); | ||
137 | MODULE_ALIAS("platform:" DRV_NAME); | ||
138 | MODULE_DEVICE_TABLE(of, max98357a_device_id); | ||