^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) * snappercl15.c -- SoC audio for Bluewater Systems Snapper CL15 module
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright (C) 2008 Bluewater Systems Ltd
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * Author: Ryan Mallon
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include <linux/platform_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/soc/cirrus/ep93xx.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <sound/core.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <sound/pcm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <sound/soc.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <asm/mach-types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include "../codecs/tlv320aic23.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #define CODEC_CLOCK 5644800
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) static int snappercl15_hw_params(struct snd_pcm_substream *substream,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) struct snd_pcm_hw_params *params)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) err = snd_soc_dai_set_sysclk(codec_dai, 0, CODEC_CLOCK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) SND_SOC_CLOCK_IN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) err = snd_soc_dai_set_sysclk(cpu_dai, 0, CODEC_CLOCK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) SND_SOC_CLOCK_OUT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) static const struct snd_soc_ops snappercl15_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) .hw_params = snappercl15_hw_params,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) static const struct snd_soc_dapm_widget tlv320aic23_dapm_widgets[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) SND_SOC_DAPM_HP("Headphone Jack", NULL),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) SND_SOC_DAPM_LINE("Line In", NULL),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) SND_SOC_DAPM_MIC("Mic Jack", NULL),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) static const struct snd_soc_dapm_route audio_map[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) {"Headphone Jack", NULL, "LHPOUT"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) {"Headphone Jack", NULL, "RHPOUT"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) {"LLINEIN", NULL, "Line In"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) {"RLINEIN", NULL, "Line In"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) {"MICIN", NULL, "Mic Jack"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) SND_SOC_DAILINK_DEFS(aic23,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) DAILINK_COMP_ARRAY(COMP_CPU("ep93xx-i2s")),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) DAILINK_COMP_ARRAY(COMP_CODEC("tlv320aic23-codec.0-001a",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) "tlv320aic23-hifi")),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) DAILINK_COMP_ARRAY(COMP_PLATFORM("ep93xx-i2s")));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) static struct snd_soc_dai_link snappercl15_dai = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) .name = "tlv320aic23",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) .stream_name = "AIC23",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) SND_SOC_DAIFMT_CBS_CFS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) .ops = &snappercl15_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) SND_SOC_DAILINK_REG(aic23),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) static struct snd_soc_card snd_soc_snappercl15 = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) .name = "Snapper CL15",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) .owner = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) .dai_link = &snappercl15_dai,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) .num_links = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) .dapm_widgets = tlv320aic23_dapm_widgets,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) .num_dapm_widgets = ARRAY_SIZE(tlv320aic23_dapm_widgets),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) .dapm_routes = audio_map,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) .num_dapm_routes = ARRAY_SIZE(audio_map),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) static int snappercl15_probe(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) struct snd_soc_card *card = &snd_soc_snappercl15;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) ret = ep93xx_i2s_acquire();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) card->dev = &pdev->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) ret = snd_soc_register_card(card);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) ep93xx_i2s_release();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) static int snappercl15_remove(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) struct snd_soc_card *card = platform_get_drvdata(pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) snd_soc_unregister_card(card);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) ep93xx_i2s_release();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) static struct platform_driver snappercl15_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) .driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) .name = "snappercl15-audio",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) .probe = snappercl15_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) .remove = snappercl15_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) module_platform_driver(snappercl15_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) MODULE_AUTHOR("Ryan Mallon");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) MODULE_DESCRIPTION("ALSA SoC Snapper CL15");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) MODULE_ALIAS("platform:snappercl15-audio");