Thomas Gleixner | 2874c5f | 2019-05-27 08:55:01 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
Johannes Stezenbach | ec3ea54 | 2011-06-22 14:59:25 +0200 | [diff] [blame] | 2 | /* |
| 3 | * sound/soc/codecs/wm8782.c |
| 4 | * simple, strap-pin configured 24bit 2ch ADC |
| 5 | * |
| 6 | * Copyright: 2011 Raumfeld GmbH |
| 7 | * Author: Johannes Stezenbach <js@sig21.net> |
| 8 | * |
| 9 | * based on ad73311.c |
| 10 | * Copyright: Analog Device Inc. |
| 11 | * Author: Cliff Cai <cliff.cai@analog.com> |
Johannes Stezenbach | ec3ea54 | 2011-06-22 14:59:25 +0200 | [diff] [blame] | 12 | */ |
| 13 | |
| 14 | #include <linux/init.h> |
| 15 | #include <linux/slab.h> |
| 16 | #include <linux/module.h> |
| 17 | #include <linux/kernel.h> |
| 18 | #include <linux/device.h> |
Daniel Mack | 7454a21 | 2018-10-03 21:34:36 +0200 | [diff] [blame] | 19 | #include <linux/regulator/consumer.h> |
Johannes Stezenbach | ec3ea54 | 2011-06-22 14:59:25 +0200 | [diff] [blame] | 20 | #include <sound/core.h> |
| 21 | #include <sound/pcm.h> |
| 22 | #include <sound/ac97_codec.h> |
| 23 | #include <sound/initval.h> |
| 24 | #include <sound/soc.h> |
| 25 | |
Mark Brown | 226059e | 2013-08-18 18:36:06 +0100 | [diff] [blame] | 26 | static const struct snd_soc_dapm_widget wm8782_dapm_widgets[] = { |
| 27 | SND_SOC_DAPM_INPUT("AINL"), |
| 28 | SND_SOC_DAPM_INPUT("AINR"), |
| 29 | }; |
| 30 | |
| 31 | static const struct snd_soc_dapm_route wm8782_dapm_routes[] = { |
| 32 | { "Capture", NULL, "AINL" }, |
| 33 | { "Capture", NULL, "AINR" }, |
| 34 | }; |
| 35 | |
Johannes Stezenbach | ec3ea54 | 2011-06-22 14:59:25 +0200 | [diff] [blame] | 36 | static struct snd_soc_dai_driver wm8782_dai = { |
| 37 | .name = "wm8782", |
| 38 | .capture = { |
| 39 | .stream_name = "Capture", |
| 40 | .channels_min = 2, |
| 41 | .channels_max = 2, |
| 42 | /* For configurations with FSAMPEN=0 */ |
| 43 | .rates = SNDRV_PCM_RATE_8000_48000, |
| 44 | .formats = SNDRV_PCM_FMTBIT_S16_LE | |
| 45 | SNDRV_PCM_FMTBIT_S20_3LE | |
| 46 | SNDRV_PCM_FMTBIT_S24_LE, |
| 47 | }, |
| 48 | }; |
| 49 | |
Daniel Mack | 7454a21 | 2018-10-03 21:34:36 +0200 | [diff] [blame] | 50 | /* regulator power supply names */ |
| 51 | static const char *supply_names[] = { |
| 52 | "Vdda", /* analog supply, 2.7V - 3.6V */ |
| 53 | "Vdd", /* digital supply, 2.7V - 5.5V */ |
| 54 | }; |
| 55 | |
| 56 | struct wm8782_priv { |
| 57 | struct regulator_bulk_data supplies[ARRAY_SIZE(supply_names)]; |
| 58 | }; |
| 59 | |
| 60 | static int wm8782_soc_probe(struct snd_soc_component *component) |
| 61 | { |
| 62 | struct wm8782_priv *priv = snd_soc_component_get_drvdata(component); |
| 63 | return regulator_bulk_enable(ARRAY_SIZE(priv->supplies), priv->supplies); |
| 64 | } |
| 65 | |
| 66 | static void wm8782_soc_remove(struct snd_soc_component *component) |
| 67 | { |
| 68 | struct wm8782_priv *priv = snd_soc_component_get_drvdata(component); |
| 69 | regulator_bulk_disable(ARRAY_SIZE(priv->supplies), priv->supplies); |
| 70 | } |
| 71 | |
| 72 | #ifdef CONFIG_PM |
| 73 | static int wm8782_soc_suspend(struct snd_soc_component *component) |
| 74 | { |
| 75 | struct wm8782_priv *priv = snd_soc_component_get_drvdata(component); |
| 76 | regulator_bulk_disable(ARRAY_SIZE(priv->supplies), priv->supplies); |
| 77 | return 0; |
| 78 | } |
| 79 | |
| 80 | static int wm8782_soc_resume(struct snd_soc_component *component) |
| 81 | { |
| 82 | struct wm8782_priv *priv = snd_soc_component_get_drvdata(component); |
| 83 | return regulator_bulk_enable(ARRAY_SIZE(priv->supplies), priv->supplies); |
| 84 | } |
| 85 | #else |
| 86 | #define wm8782_soc_suspend NULL |
| 87 | #define wm8782_soc_resume NULL |
| 88 | #endif /* CONFIG_PM */ |
| 89 | |
Kuninori Morimoto | d6ae5c1 | 2018-01-29 03:03:17 +0000 | [diff] [blame] | 90 | static const struct snd_soc_component_driver soc_component_dev_wm8782 = { |
Daniel Mack | 7454a21 | 2018-10-03 21:34:36 +0200 | [diff] [blame] | 91 | .probe = wm8782_soc_probe, |
| 92 | .remove = wm8782_soc_remove, |
| 93 | .suspend = wm8782_soc_suspend, |
| 94 | .resume = wm8782_soc_resume, |
Kuninori Morimoto | d6ae5c1 | 2018-01-29 03:03:17 +0000 | [diff] [blame] | 95 | .dapm_widgets = wm8782_dapm_widgets, |
| 96 | .num_dapm_widgets = ARRAY_SIZE(wm8782_dapm_widgets), |
| 97 | .dapm_routes = wm8782_dapm_routes, |
| 98 | .num_dapm_routes = ARRAY_SIZE(wm8782_dapm_routes), |
| 99 | .idle_bias_on = 1, |
| 100 | .use_pmdown_time = 1, |
| 101 | .endianness = 1, |
| 102 | .non_legacy_dai_naming = 1, |
Mark Brown | 226059e | 2013-08-18 18:36:06 +0100 | [diff] [blame] | 103 | }; |
Johannes Stezenbach | ec3ea54 | 2011-06-22 14:59:25 +0200 | [diff] [blame] | 104 | |
Bill Pemberton | 7a79e94 | 2012-12-07 09:26:37 -0500 | [diff] [blame] | 105 | static int wm8782_probe(struct platform_device *pdev) |
Johannes Stezenbach | ec3ea54 | 2011-06-22 14:59:25 +0200 | [diff] [blame] | 106 | { |
Daniel Mack | 7454a21 | 2018-10-03 21:34:36 +0200 | [diff] [blame] | 107 | struct device *dev = &pdev->dev; |
| 108 | struct wm8782_priv *priv; |
| 109 | int ret, i; |
| 110 | |
| 111 | priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); |
| 112 | if (!priv) |
| 113 | return -ENOMEM; |
| 114 | |
| 115 | dev_set_drvdata(dev, priv); |
| 116 | |
| 117 | for (i = 0; i < ARRAY_SIZE(supply_names); i++) |
| 118 | priv->supplies[i].supply = supply_names[i]; |
| 119 | |
| 120 | ret = devm_regulator_bulk_get(dev, ARRAY_SIZE(priv->supplies), |
| 121 | priv->supplies); |
| 122 | if (ret < 0) |
| 123 | return ret; |
| 124 | |
Kuninori Morimoto | d6ae5c1 | 2018-01-29 03:03:17 +0000 | [diff] [blame] | 125 | return devm_snd_soc_register_component(&pdev->dev, |
| 126 | &soc_component_dev_wm8782, &wm8782_dai, 1); |
Johannes Stezenbach | ec3ea54 | 2011-06-22 14:59:25 +0200 | [diff] [blame] | 127 | } |
| 128 | |
Daniel Mack | 9e2a877 | 2018-05-21 23:54:49 +0200 | [diff] [blame] | 129 | #ifdef CONFIG_OF |
| 130 | static const struct of_device_id wm8782_of_match[] = { |
| 131 | { .compatible = "wlf,wm8782", }, |
| 132 | { } |
| 133 | }; |
| 134 | MODULE_DEVICE_TABLE(of, wm8782_of_match); |
| 135 | #endif |
| 136 | |
Johannes Stezenbach | ec3ea54 | 2011-06-22 14:59:25 +0200 | [diff] [blame] | 137 | static struct platform_driver wm8782_codec_driver = { |
| 138 | .driver = { |
| 139 | .name = "wm8782", |
Daniel Mack | 9e2a877 | 2018-05-21 23:54:49 +0200 | [diff] [blame] | 140 | .of_match_table = of_match_ptr(wm8782_of_match), |
Johannes Stezenbach | ec3ea54 | 2011-06-22 14:59:25 +0200 | [diff] [blame] | 141 | }, |
| 142 | .probe = wm8782_probe, |
Johannes Stezenbach | ec3ea54 | 2011-06-22 14:59:25 +0200 | [diff] [blame] | 143 | }; |
| 144 | |
Mark Brown | 5bbcc3c | 2011-11-23 22:52:08 +0000 | [diff] [blame] | 145 | module_platform_driver(wm8782_codec_driver); |
Johannes Stezenbach | ec3ea54 | 2011-06-22 14:59:25 +0200 | [diff] [blame] | 146 | |
| 147 | MODULE_DESCRIPTION("ASoC WM8782 driver"); |
| 148 | MODULE_AUTHOR("Johannes Stezenbach <js@sig21.net>"); |
| 149 | MODULE_LICENSE("GPL"); |