^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-or-later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * SiRF audio card driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright (c) 2011 Cambridge Silicon Radio Limited, a CSR plc group company.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #include <linux/platform_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/of.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/gpio.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/of_gpio.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <sound/core.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <sound/pcm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <sound/soc.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) struct sirf_audio_card {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) unsigned int gpio_hp_pa;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) unsigned int gpio_spk_pa;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) static int sirf_audio_hp_event(struct snd_soc_dapm_widget *w,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) struct snd_kcontrol *ctrl, int event)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) struct snd_soc_dapm_context *dapm = w->dapm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) struct snd_soc_card *card = dapm->card;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) struct sirf_audio_card *sirf_audio_card = snd_soc_card_get_drvdata(card);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) int on = !SND_SOC_DAPM_EVENT_OFF(event);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) if (gpio_is_valid(sirf_audio_card->gpio_hp_pa))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) gpio_set_value(sirf_audio_card->gpio_hp_pa, on);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) static int sirf_audio_spk_event(struct snd_soc_dapm_widget *w,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) struct snd_kcontrol *ctrl, int event)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) struct snd_soc_dapm_context *dapm = w->dapm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) struct snd_soc_card *card = dapm->card;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) struct sirf_audio_card *sirf_audio_card = snd_soc_card_get_drvdata(card);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) int on = !SND_SOC_DAPM_EVENT_OFF(event);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) if (gpio_is_valid(sirf_audio_card->gpio_spk_pa))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) gpio_set_value(sirf_audio_card->gpio_spk_pa, on);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) static const struct snd_soc_dapm_widget sirf_audio_dapm_widgets[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) SND_SOC_DAPM_HP("Hp", sirf_audio_hp_event),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) SND_SOC_DAPM_SPK("Ext Spk", sirf_audio_spk_event),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) SND_SOC_DAPM_MIC("Ext Mic", NULL),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) static const struct snd_soc_dapm_route intercon[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) {"Hp", NULL, "HPOUTL"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) {"Hp", NULL, "HPOUTR"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) {"Ext Spk", NULL, "SPKOUT"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) {"MICIN1", NULL, "Mic Bias"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) {"Mic Bias", NULL, "Ext Mic"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) /* Digital audio interface glue - connects codec <--> CPU */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) SND_SOC_DAILINK_DEFS(sirf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) DAILINK_COMP_ARRAY(COMP_EMPTY()),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) DAILINK_COMP_ARRAY(COMP_CODEC(NULL, "sirf-audio-codec")),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) DAILINK_COMP_ARRAY(COMP_EMPTY()));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) static struct snd_soc_dai_link sirf_audio_dai_link[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) .name = "SiRF audio card",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) .stream_name = "SiRF audio HiFi",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) SND_SOC_DAILINK_REG(sirf),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) /* Audio machine driver */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) static struct snd_soc_card snd_soc_sirf_audio_card = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) .name = "SiRF audio card",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) .owner = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) .dai_link = sirf_audio_dai_link,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) .num_links = ARRAY_SIZE(sirf_audio_dai_link),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) .dapm_widgets = sirf_audio_dapm_widgets,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) .num_dapm_widgets = ARRAY_SIZE(sirf_audio_dapm_widgets),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) .dapm_routes = intercon,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) .num_dapm_routes = ARRAY_SIZE(intercon),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) static int sirf_audio_probe(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) struct snd_soc_card *card = &snd_soc_sirf_audio_card;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) struct sirf_audio_card *sirf_audio_card;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) sirf_audio_card = devm_kzalloc(&pdev->dev, sizeof(struct sirf_audio_card),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) if (sirf_audio_card == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) sirf_audio_dai_link[0].cpus->of_node =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) of_parse_phandle(pdev->dev.of_node, "sirf,audio-platform", 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) sirf_audio_dai_link[0].platforms->of_node =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) of_parse_phandle(pdev->dev.of_node, "sirf,audio-platform", 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) sirf_audio_dai_link[0].codecs->of_node =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) of_parse_phandle(pdev->dev.of_node, "sirf,audio-codec", 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) sirf_audio_card->gpio_spk_pa = of_get_named_gpio(pdev->dev.of_node,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) "spk-pa-gpios", 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) sirf_audio_card->gpio_hp_pa = of_get_named_gpio(pdev->dev.of_node,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) "hp-pa-gpios", 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) if (gpio_is_valid(sirf_audio_card->gpio_spk_pa)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) ret = devm_gpio_request_one(&pdev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) sirf_audio_card->gpio_spk_pa,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) GPIOF_OUT_INIT_LOW, "SPA_PA_SD");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) dev_err(&pdev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) "Failed to request GPIO_%d for reset: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) sirf_audio_card->gpio_spk_pa, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) if (gpio_is_valid(sirf_audio_card->gpio_hp_pa)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) ret = devm_gpio_request_one(&pdev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) sirf_audio_card->gpio_hp_pa,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) GPIOF_OUT_INIT_LOW, "HP_PA_SD");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) dev_err(&pdev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) "Failed to request GPIO_%d for reset: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) sirf_audio_card->gpio_hp_pa, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) card->dev = &pdev->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) snd_soc_card_set_drvdata(card, sirf_audio_card);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) ret = devm_snd_soc_register_card(&pdev->dev, card);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) dev_err(&pdev->dev, "snd_soc_register_card() failed:%d\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) static const struct of_device_id sirf_audio_of_match[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) {.compatible = "sirf,sirf-audio-card", },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) { },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) MODULE_DEVICE_TABLE(of, sirf_audio_of_match);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) static struct platform_driver sirf_audio_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) .driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) .name = "sirf-audio-card",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) .pm = &snd_soc_pm_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) .of_match_table = sirf_audio_of_match,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) .probe = sirf_audio_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) module_platform_driver(sirf_audio_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) MODULE_AUTHOR("RongJun Ying <RongJun.Ying@csr.com>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) MODULE_DESCRIPTION("ALSA SoC SIRF audio card driver");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) MODULE_LICENSE("GPL v2");