0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014 #include <linux/init.h>
0015 #include <linux/slab.h>
0016 #include <linux/module.h>
0017 #include <linux/kernel.h>
0018 #include <linux/device.h>
0019 #include <linux/regulator/consumer.h>
0020 #include <sound/core.h>
0021 #include <sound/pcm.h>
0022 #include <sound/ac97_codec.h>
0023 #include <sound/initval.h>
0024 #include <sound/soc.h>
0025
0026 static const struct snd_soc_dapm_widget wm8782_dapm_widgets[] = {
0027 SND_SOC_DAPM_INPUT("AINL"),
0028 SND_SOC_DAPM_INPUT("AINR"),
0029 };
0030
0031 static const struct snd_soc_dapm_route wm8782_dapm_routes[] = {
0032 { "Capture", NULL, "AINL" },
0033 { "Capture", NULL, "AINR" },
0034 };
0035
0036 static struct snd_soc_dai_driver wm8782_dai = {
0037 .name = "wm8782",
0038 .capture = {
0039 .stream_name = "Capture",
0040 .channels_min = 2,
0041 .channels_max = 2,
0042
0043 .rates = SNDRV_PCM_RATE_8000_48000,
0044 .formats = SNDRV_PCM_FMTBIT_S16_LE |
0045 SNDRV_PCM_FMTBIT_S20_3LE |
0046 SNDRV_PCM_FMTBIT_S24_LE,
0047 },
0048 };
0049
0050
0051 static const char *supply_names[] = {
0052 "Vdda",
0053 "Vdd",
0054 };
0055
0056 struct wm8782_priv {
0057 struct regulator_bulk_data supplies[ARRAY_SIZE(supply_names)];
0058 };
0059
0060 static int wm8782_soc_probe(struct snd_soc_component *component)
0061 {
0062 struct wm8782_priv *priv = snd_soc_component_get_drvdata(component);
0063 return regulator_bulk_enable(ARRAY_SIZE(priv->supplies), priv->supplies);
0064 }
0065
0066 static void wm8782_soc_remove(struct snd_soc_component *component)
0067 {
0068 struct wm8782_priv *priv = snd_soc_component_get_drvdata(component);
0069 regulator_bulk_disable(ARRAY_SIZE(priv->supplies), priv->supplies);
0070 }
0071
0072 #ifdef CONFIG_PM
0073 static int wm8782_soc_suspend(struct snd_soc_component *component)
0074 {
0075 struct wm8782_priv *priv = snd_soc_component_get_drvdata(component);
0076 regulator_bulk_disable(ARRAY_SIZE(priv->supplies), priv->supplies);
0077 return 0;
0078 }
0079
0080 static int wm8782_soc_resume(struct snd_soc_component *component)
0081 {
0082 struct wm8782_priv *priv = snd_soc_component_get_drvdata(component);
0083 return regulator_bulk_enable(ARRAY_SIZE(priv->supplies), priv->supplies);
0084 }
0085 #else
0086 #define wm8782_soc_suspend NULL
0087 #define wm8782_soc_resume NULL
0088 #endif
0089
0090 static const struct snd_soc_component_driver soc_component_dev_wm8782 = {
0091 .probe = wm8782_soc_probe,
0092 .remove = wm8782_soc_remove,
0093 .suspend = wm8782_soc_suspend,
0094 .resume = wm8782_soc_resume,
0095 .dapm_widgets = wm8782_dapm_widgets,
0096 .num_dapm_widgets = ARRAY_SIZE(wm8782_dapm_widgets),
0097 .dapm_routes = wm8782_dapm_routes,
0098 .num_dapm_routes = ARRAY_SIZE(wm8782_dapm_routes),
0099 .idle_bias_on = 1,
0100 .use_pmdown_time = 1,
0101 .endianness = 1,
0102 };
0103
0104 static int wm8782_probe(struct platform_device *pdev)
0105 {
0106 struct device *dev = &pdev->dev;
0107 struct wm8782_priv *priv;
0108 int ret, i;
0109
0110 priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
0111 if (!priv)
0112 return -ENOMEM;
0113
0114 dev_set_drvdata(dev, priv);
0115
0116 for (i = 0; i < ARRAY_SIZE(supply_names); i++)
0117 priv->supplies[i].supply = supply_names[i];
0118
0119 ret = devm_regulator_bulk_get(dev, ARRAY_SIZE(priv->supplies),
0120 priv->supplies);
0121 if (ret < 0)
0122 return ret;
0123
0124 return devm_snd_soc_register_component(&pdev->dev,
0125 &soc_component_dev_wm8782, &wm8782_dai, 1);
0126 }
0127
0128 #ifdef CONFIG_OF
0129 static const struct of_device_id wm8782_of_match[] = {
0130 { .compatible = "wlf,wm8782", },
0131 { }
0132 };
0133 MODULE_DEVICE_TABLE(of, wm8782_of_match);
0134 #endif
0135
0136 static struct platform_driver wm8782_codec_driver = {
0137 .driver = {
0138 .name = "wm8782",
0139 .of_match_table = of_match_ptr(wm8782_of_match),
0140 },
0141 .probe = wm8782_probe,
0142 };
0143
0144 module_platform_driver(wm8782_codec_driver);
0145
0146 MODULE_DESCRIPTION("ASoC WM8782 driver");
0147 MODULE_AUTHOR("Johannes Stezenbach <js@sig21.net>");
0148 MODULE_LICENSE("GPL");