Jarkko Nikula | 9b351d4 | 2014-05-30 15:16:43 +0300 | [diff] [blame] | 1 | /* |
| 2 | * Intel Baytrail SST MAX98090 machine driver |
| 3 | * Copyright (c) 2014, Intel Corporation. |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify it |
| 6 | * under the terms and conditions of the GNU General Public License, |
| 7 | * version 2, as published by the Free Software Foundation. |
| 8 | * |
| 9 | * This program is distributed in the hope it will be useful, but WITHOUT |
| 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 12 | * more details. |
| 13 | */ |
| 14 | |
| 15 | #include <linux/init.h> |
| 16 | #include <linux/module.h> |
| 17 | #include <linux/platform_device.h> |
| 18 | #include <linux/acpi.h> |
| 19 | #include <linux/device.h> |
| 20 | #include <linux/gpio.h> |
| 21 | #include <linux/gpio/consumer.h> |
| 22 | #include <linux/slab.h> |
| 23 | #include <sound/pcm.h> |
| 24 | #include <sound/pcm_params.h> |
| 25 | #include <sound/soc.h> |
| 26 | #include <sound/jack.h> |
Jie Yang | e56c72d | 2015-04-02 15:37:02 +0800 | [diff] [blame] | 27 | #include "../../codecs/max98090.h" |
Jarkko Nikula | 9b351d4 | 2014-05-30 15:16:43 +0300 | [diff] [blame] | 28 | |
| 29 | struct byt_max98090_private { |
| 30 | struct snd_soc_jack jack; |
| 31 | }; |
| 32 | |
| 33 | static const struct snd_soc_dapm_widget byt_max98090_widgets[] = { |
| 34 | SND_SOC_DAPM_HP("Headphone", NULL), |
| 35 | SND_SOC_DAPM_MIC("Headset Mic", NULL), |
| 36 | SND_SOC_DAPM_MIC("Int Mic", NULL), |
| 37 | SND_SOC_DAPM_SPK("Ext Spk", NULL), |
| 38 | }; |
| 39 | |
| 40 | static const struct snd_soc_dapm_route byt_max98090_audio_map[] = { |
| 41 | {"IN34", NULL, "Headset Mic"}, |
Jarkko Nikula | a5b37bf | 2014-06-23 16:29:37 +0300 | [diff] [blame] | 42 | {"Headset Mic", NULL, "MICBIAS"}, |
Jarkko Nikula | 9b351d4 | 2014-05-30 15:16:43 +0300 | [diff] [blame] | 43 | {"DMICL", NULL, "Int Mic"}, |
| 44 | {"Headphone", NULL, "HPL"}, |
| 45 | {"Headphone", NULL, "HPR"}, |
| 46 | {"Ext Spk", NULL, "SPKL"}, |
| 47 | {"Ext Spk", NULL, "SPKR"}, |
| 48 | }; |
| 49 | |
| 50 | static const struct snd_kcontrol_new byt_max98090_controls[] = { |
| 51 | SOC_DAPM_PIN_SWITCH("Headphone"), |
| 52 | SOC_DAPM_PIN_SWITCH("Headset Mic"), |
| 53 | SOC_DAPM_PIN_SWITCH("Int Mic"), |
| 54 | SOC_DAPM_PIN_SWITCH("Ext Spk"), |
| 55 | }; |
| 56 | |
| 57 | static struct snd_soc_jack_pin hs_jack_pins[] = { |
| 58 | { |
| 59 | .pin = "Headphone", |
| 60 | .mask = SND_JACK_HEADPHONE, |
| 61 | }, |
| 62 | { |
| 63 | .pin = "Headset Mic", |
| 64 | .mask = SND_JACK_MICROPHONE, |
| 65 | }, |
Jarkko Nikula | 9b351d4 | 2014-05-30 15:16:43 +0300 | [diff] [blame] | 66 | }; |
| 67 | |
| 68 | static struct snd_soc_jack_gpio hs_jack_gpios[] = { |
| 69 | { |
Andy Shevchenko | 7c19788 | 2017-06-10 19:37:41 +0300 | [diff] [blame] | 70 | .name = "hp", |
Jarkko Nikula | 9b351d4 | 2014-05-30 15:16:43 +0300 | [diff] [blame] | 71 | .report = SND_JACK_HEADPHONE | SND_JACK_LINEOUT, |
| 72 | .debounce_time = 200, |
| 73 | }, |
| 74 | { |
Andy Shevchenko | 7c19788 | 2017-06-10 19:37:41 +0300 | [diff] [blame] | 75 | .name = "mic", |
Jarkko Nikula | 725a6df | 2014-06-23 16:29:38 +0300 | [diff] [blame] | 76 | .invert = 1, |
Jarkko Nikula | 6a0cdcc | 2014-06-23 16:29:39 +0300 | [diff] [blame] | 77 | .report = SND_JACK_MICROPHONE, |
Jarkko Nikula | 9b351d4 | 2014-05-30 15:16:43 +0300 | [diff] [blame] | 78 | .debounce_time = 200, |
| 79 | }, |
| 80 | }; |
| 81 | |
Andy Shevchenko | 7c19788 | 2017-06-10 19:37:41 +0300 | [diff] [blame] | 82 | static const struct acpi_gpio_params hp_gpios = { 0, 0, false }; |
| 83 | static const struct acpi_gpio_params mic_gpios = { 1, 0, false }; |
| 84 | |
| 85 | static const struct acpi_gpio_mapping acpi_byt_max98090_gpios[] = { |
| 86 | { "hp-gpios", &hp_gpios, 1 }, |
| 87 | { "mic-gpios", &mic_gpios, 1 }, |
| 88 | {}, |
| 89 | }; |
| 90 | |
Jarkko Nikula | 9b351d4 | 2014-05-30 15:16:43 +0300 | [diff] [blame] | 91 | static int byt_max98090_init(struct snd_soc_pcm_runtime *runtime) |
| 92 | { |
| 93 | int ret; |
Jarkko Nikula | 9b351d4 | 2014-05-30 15:16:43 +0300 | [diff] [blame] | 94 | struct snd_soc_card *card = runtime->card; |
| 95 | struct byt_max98090_private *drv = snd_soc_card_get_drvdata(card); |
| 96 | struct snd_soc_jack *jack = &drv->jack; |
| 97 | |
| 98 | card->dapm.idle_bias_off = true; |
| 99 | |
| 100 | ret = snd_soc_dai_set_sysclk(runtime->codec_dai, |
| 101 | M98090_REG_SYSTEM_CLOCK, |
| 102 | 25000000, SND_SOC_CLOCK_IN); |
| 103 | if (ret < 0) { |
| 104 | dev_err(card->dev, "Can't set codec clock %d\n", ret); |
| 105 | return ret; |
| 106 | } |
| 107 | |
| 108 | /* Enable jack detection */ |
Lars-Peter Clausen | e0f7dd9 | 2015-03-04 10:33:22 +0100 | [diff] [blame] | 109 | ret = snd_soc_card_jack_new(runtime->card, "Headset", |
| 110 | SND_JACK_LINEOUT | SND_JACK_HEADSET, jack, |
| 111 | hs_jack_pins, ARRAY_SIZE(hs_jack_pins)); |
Jarkko Nikula | 9b351d4 | 2014-05-30 15:16:43 +0300 | [diff] [blame] | 112 | if (ret) |
| 113 | return ret; |
| 114 | |
Jarkko Nikula | ab6f7d0 | 2014-06-23 16:29:42 +0300 | [diff] [blame] | 115 | return snd_soc_jack_add_gpiods(card->dev->parent, jack, |
| 116 | ARRAY_SIZE(hs_jack_gpios), |
| 117 | hs_jack_gpios); |
Jarkko Nikula | 9b351d4 | 2014-05-30 15:16:43 +0300 | [diff] [blame] | 118 | } |
| 119 | |
| 120 | static struct snd_soc_dai_link byt_max98090_dais[] = { |
| 121 | { |
| 122 | .name = "Baytrail Audio", |
| 123 | .stream_name = "Audio", |
| 124 | .cpu_dai_name = "baytrail-pcm-audio", |
| 125 | .codec_dai_name = "HiFi", |
| 126 | .codec_name = "i2c-193C9890:00", |
| 127 | .platform_name = "baytrail-pcm-audio", |
| 128 | .init = byt_max98090_init, |
| 129 | .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF | |
| 130 | SND_SOC_DAIFMT_CBS_CFS, |
| 131 | }, |
| 132 | }; |
| 133 | |
| 134 | static struct snd_soc_card byt_max98090_card = { |
| 135 | .name = "byt-max98090", |
Axel Lin | 54d8697 | 2015-08-21 20:59:21 +0800 | [diff] [blame] | 136 | .owner = THIS_MODULE, |
Jarkko Nikula | 9b351d4 | 2014-05-30 15:16:43 +0300 | [diff] [blame] | 137 | .dai_link = byt_max98090_dais, |
| 138 | .num_links = ARRAY_SIZE(byt_max98090_dais), |
| 139 | .dapm_widgets = byt_max98090_widgets, |
| 140 | .num_dapm_widgets = ARRAY_SIZE(byt_max98090_widgets), |
| 141 | .dapm_routes = byt_max98090_audio_map, |
| 142 | .num_dapm_routes = ARRAY_SIZE(byt_max98090_audio_map), |
| 143 | .controls = byt_max98090_controls, |
| 144 | .num_controls = ARRAY_SIZE(byt_max98090_controls), |
Jarkko Nikula | 969168e | 2014-09-26 16:25:38 +0300 | [diff] [blame] | 145 | .fully_routed = true, |
Jarkko Nikula | 9b351d4 | 2014-05-30 15:16:43 +0300 | [diff] [blame] | 146 | }; |
| 147 | |
| 148 | static int byt_max98090_probe(struct platform_device *pdev) |
| 149 | { |
Andy Shevchenko | 7c19788 | 2017-06-10 19:37:41 +0300 | [diff] [blame] | 150 | struct device *dev = &pdev->dev; |
Jarkko Nikula | 9b351d4 | 2014-05-30 15:16:43 +0300 | [diff] [blame] | 151 | struct byt_max98090_private *priv; |
Andy Shevchenko | 7c19788 | 2017-06-10 19:37:41 +0300 | [diff] [blame] | 152 | int ret_val; |
Jarkko Nikula | 9b351d4 | 2014-05-30 15:16:43 +0300 | [diff] [blame] | 153 | |
| 154 | priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_ATOMIC); |
| 155 | if (!priv) { |
| 156 | dev_err(&pdev->dev, "allocation failed\n"); |
| 157 | return -ENOMEM; |
| 158 | } |
| 159 | |
Andy Shevchenko | 7c19788 | 2017-06-10 19:37:41 +0300 | [diff] [blame] | 160 | ret_val = devm_acpi_dev_add_driver_gpios(dev->parent, acpi_byt_max98090_gpios); |
| 161 | if (ret_val) |
| 162 | dev_dbg(dev, "Unable to add GPIO mapping table\n"); |
| 163 | |
Jarkko Nikula | 9b351d4 | 2014-05-30 15:16:43 +0300 | [diff] [blame] | 164 | byt_max98090_card.dev = &pdev->dev; |
| 165 | snd_soc_card_set_drvdata(&byt_max98090_card, priv); |
| 166 | ret_val = devm_snd_soc_register_card(&pdev->dev, &byt_max98090_card); |
| 167 | if (ret_val) { |
| 168 | dev_err(&pdev->dev, |
| 169 | "snd_soc_register_card failed %d\n", ret_val); |
| 170 | return ret_val; |
| 171 | } |
| 172 | |
Andy Shevchenko | 7c19788 | 2017-06-10 19:37:41 +0300 | [diff] [blame] | 173 | return 0; |
Jarkko Nikula | 9b351d4 | 2014-05-30 15:16:43 +0300 | [diff] [blame] | 174 | } |
| 175 | |
| 176 | static int byt_max98090_remove(struct platform_device *pdev) |
| 177 | { |
| 178 | struct snd_soc_card *card = platform_get_drvdata(pdev); |
| 179 | struct byt_max98090_private *priv = snd_soc_card_get_drvdata(card); |
| 180 | |
| 181 | snd_soc_jack_free_gpios(&priv->jack, ARRAY_SIZE(hs_jack_gpios), |
| 182 | hs_jack_gpios); |
| 183 | |
| 184 | return 0; |
| 185 | } |
| 186 | |
| 187 | static struct platform_driver byt_max98090_driver = { |
| 188 | .probe = byt_max98090_probe, |
| 189 | .remove = byt_max98090_remove, |
| 190 | .driver = { |
| 191 | .name = "byt-max98090", |
Jarkko Nikula | 9b351d4 | 2014-05-30 15:16:43 +0300 | [diff] [blame] | 192 | .pm = &snd_soc_pm_ops, |
| 193 | }, |
| 194 | }; |
| 195 | module_platform_driver(byt_max98090_driver) |
| 196 | |
| 197 | MODULE_DESCRIPTION("ASoC Intel(R) Baytrail Machine driver"); |
| 198 | MODULE_AUTHOR("Omair Md Abdullah, Jarkko Nikula"); |
| 199 | MODULE_LICENSE("GPL v2"); |
| 200 | MODULE_ALIAS("platform:byt-max98090"); |