^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * linux/sound/soc/pxa/z2.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * SoC Audio driver for Aeronix Zipit Z2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * Copyright (C) 2009 Ken McGuire <kenm@desertweyr.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) * Copyright (C) 2010 Marek Vasut <marek.vasut@gmail.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/moduleparam.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/timer.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/interrupt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/platform_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <linux/gpio.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <sound/core.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <sound/pcm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <sound/soc.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #include <sound/jack.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #include <asm/mach-types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #include <mach/hardware.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #include <mach/audio.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #include <mach/z2.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) #include "../codecs/wm8750.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) #include "pxa2xx-i2s.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) static struct snd_soc_card snd_soc_z2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) static int z2_hw_params(struct snd_pcm_substream *substream,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) struct snd_pcm_hw_params *params)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) unsigned int clk = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) switch (params_rate(params)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) case 8000:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) case 16000:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) case 48000:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) case 96000:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) clk = 12288000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) case 11025:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) case 22050:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) case 44100:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) clk = 11289600;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) /* set the codec system clock for DAC and ADC */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) ret = snd_soc_dai_set_sysclk(codec_dai, WM8750_SYSCLK, clk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) SND_SOC_CLOCK_IN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) /* set the I2S system clock as input (unused) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) ret = snd_soc_dai_set_sysclk(cpu_dai, PXA2XX_I2S_SYSCLK, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) SND_SOC_CLOCK_IN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) static struct snd_soc_jack hs_jack;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) /* Headset jack detection DAPM pins */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) static struct snd_soc_jack_pin hs_jack_pins[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) .pin = "Mic Jack",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) .mask = SND_JACK_MICROPHONE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) .pin = "Headphone Jack",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) .mask = SND_JACK_HEADPHONE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) .pin = "Ext Spk",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) .mask = SND_JACK_HEADPHONE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) .invert = 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) },
^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) /* Headset jack detection gpios */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) static struct snd_soc_jack_gpio hs_jack_gpios[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) .gpio = GPIO37_ZIPITZ2_HEADSET_DETECT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) .name = "hsdet-gpio",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) .report = SND_JACK_HEADSET,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) .debounce_time = 200,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) .invert = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) /* z2 machine dapm widgets */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) static const struct snd_soc_dapm_widget wm8750_dapm_widgets[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) SND_SOC_DAPM_HP("Headphone Jack", NULL),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) SND_SOC_DAPM_MIC("Mic Jack", NULL),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) SND_SOC_DAPM_SPK("Ext Spk", NULL),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) /* headset is a mic and mono headphone */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) SND_SOC_DAPM_HP("Headset Jack", NULL),
^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) /* Z2 machine audio_map */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) static const struct snd_soc_dapm_route z2_audio_map[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) /* headphone connected to LOUT1, ROUT1 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) {"Headphone Jack", NULL, "LOUT1"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) {"Headphone Jack", NULL, "ROUT1"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) /* ext speaker connected to LOUT2, ROUT2 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) {"Ext Spk", NULL, "ROUT2"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) {"Ext Spk", NULL, "LOUT2"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) /* mic is connected to R input 2 - with bias */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) {"RINPUT2", NULL, "Mic Bias"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) {"Mic Bias", NULL, "Mic Jack"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) * Logic for a wm8750 as connected on a Z2 Device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) static int z2_wm8750_init(struct snd_soc_pcm_runtime *rtd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) /* Jack detection API stuff */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) ret = snd_soc_card_jack_new(rtd->card, "Headset Jack", SND_JACK_HEADSET,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) &hs_jack, hs_jack_pins,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) ARRAY_SIZE(hs_jack_pins));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) ret = snd_soc_jack_add_gpios(&hs_jack, ARRAY_SIZE(hs_jack_gpios),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) hs_jack_gpios);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) static const struct snd_soc_ops z2_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) .hw_params = z2_hw_params,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) /* z2 digital audio interface glue - connects codec <--> CPU */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) SND_SOC_DAILINK_DEFS(wm8750,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) DAILINK_COMP_ARRAY(COMP_CPU("pxa2xx-i2s")),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) DAILINK_COMP_ARRAY(COMP_CODEC("wm8750.0-001b", "wm8750-hifi")),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) DAILINK_COMP_ARRAY(COMP_PLATFORM("pxa-pcm-audio")));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) static struct snd_soc_dai_link z2_dai = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) .name = "wm8750",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) .stream_name = "WM8750",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) .init = z2_wm8750_init,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) SND_SOC_DAIFMT_CBS_CFS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) .ops = &z2_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) SND_SOC_DAILINK_REG(wm8750),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) /* z2 audio machine driver */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) static struct snd_soc_card snd_soc_z2 = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) .name = "Z2",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) .owner = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) .dai_link = &z2_dai,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) .num_links = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) .dapm_widgets = wm8750_dapm_widgets,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) .num_dapm_widgets = ARRAY_SIZE(wm8750_dapm_widgets),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) .dapm_routes = z2_audio_map,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) .num_dapm_routes = ARRAY_SIZE(z2_audio_map),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) .fully_routed = true,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) static struct platform_device *z2_snd_device;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) static int __init z2_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) if (!machine_is_zipit2())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) z2_snd_device = platform_device_alloc("soc-audio", -1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) if (!z2_snd_device)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) platform_set_drvdata(z2_snd_device, &snd_soc_z2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) ret = platform_device_add(z2_snd_device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) platform_device_put(z2_snd_device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) static void __exit z2_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) platform_device_unregister(z2_snd_device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) module_init(z2_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) module_exit(z2_exit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) MODULE_AUTHOR("Ken McGuire <kenm@desertweyr.com>, "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) "Marek Vasut <marek.vasut@gmail.com>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) MODULE_DESCRIPTION("ALSA SoC ZipitZ2");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) MODULE_LICENSE("GPL");