Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^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)  * poodle.c  --  SoC audio for Poodle
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * Copyright 2005 Wolfson Microelectronics PLC.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  * Copyright 2005 Openedhand Ltd.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  * Authors: Liam Girdwood <lrg@slimlogic.co.uk>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  *          Richard Purdie <richard@openedhand.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/moduleparam.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/timer.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/i2c.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/interrupt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <linux/platform_device.h>
^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) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #include <asm/mach-types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) #include <asm/hardware/locomo.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) #include <mach/poodle.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) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) #include "../codecs/wm8731.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) #include "pxa2xx-i2s.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) #define POODLE_HP        1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) #define POODLE_HP_OFF    0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) #define POODLE_SPK_ON    1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) #define POODLE_SPK_OFF   0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35)  /* audio clock in Hz - rounded from 12.235MHz */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) #define POODLE_AUDIO_CLOCK 12288000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) static int poodle_jack_func;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) static int poodle_spk_func;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) static void poodle_ext_control(struct snd_soc_dapm_context *dapm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 	/* set up jack connection */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 	if (poodle_jack_func == POODLE_HP) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 		/* set = unmute headphone */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 		locomo_gpio_write(&poodle_locomo_device.dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 			POODLE_LOCOMO_GPIO_MUTE_L, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 		locomo_gpio_write(&poodle_locomo_device.dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 			POODLE_LOCOMO_GPIO_MUTE_R, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 		snd_soc_dapm_enable_pin(dapm, "Headphone Jack");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 		locomo_gpio_write(&poodle_locomo_device.dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 			POODLE_LOCOMO_GPIO_MUTE_L, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 		locomo_gpio_write(&poodle_locomo_device.dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 			POODLE_LOCOMO_GPIO_MUTE_R, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 		snd_soc_dapm_disable_pin(dapm, "Headphone Jack");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	/* set the endpoints to their new connection states */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	if (poodle_spk_func == POODLE_SPK_ON)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 		snd_soc_dapm_enable_pin(dapm, "Ext Spk");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 		snd_soc_dapm_disable_pin(dapm, "Ext Spk");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	/* signal a DAPM event */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	snd_soc_dapm_sync(dapm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) static int poodle_startup(struct snd_pcm_substream *substream)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	/* check the jack status at stream startup */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	poodle_ext_control(&rtd->card->dapm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) /* we need to unmute the HP at shutdown as the mute burns power on poodle */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) static void poodle_shutdown(struct snd_pcm_substream *substream)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	/* set = unmute headphone */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	locomo_gpio_write(&poodle_locomo_device.dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 		POODLE_LOCOMO_GPIO_MUTE_L, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	locomo_gpio_write(&poodle_locomo_device.dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 		POODLE_LOCOMO_GPIO_MUTE_R, 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) static int poodle_hw_params(struct snd_pcm_substream *substream,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	struct snd_pcm_hw_params *params)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	unsigned int clk = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	switch (params_rate(params)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	case 8000:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 	case 16000:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 	case 48000:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 	case 96000:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 		clk = 12288000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 	case 11025:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	case 22050:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	case 44100:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 		clk = 11289600;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 	/* set the codec system clock for DAC and ADC */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	ret = snd_soc_dai_set_sysclk(codec_dai, WM8731_SYSCLK_XTAL, clk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 		SND_SOC_CLOCK_IN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	/* set the I2S system clock as input (unused) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	ret = snd_soc_dai_set_sysclk(cpu_dai, PXA2XX_I2S_SYSCLK, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 		SND_SOC_CLOCK_IN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 	if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	return 0;
^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) static const struct snd_soc_ops poodle_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 	.startup = poodle_startup,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 	.hw_params = poodle_hw_params,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 	.shutdown = poodle_shutdown,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) static int poodle_get_jack(struct snd_kcontrol *kcontrol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 	struct snd_ctl_elem_value *ucontrol)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 	ucontrol->value.enumerated.item[0] = poodle_jack_func;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) static int poodle_set_jack(struct snd_kcontrol *kcontrol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 	struct snd_ctl_elem_value *ucontrol)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 	struct snd_soc_card *card =  snd_kcontrol_chip(kcontrol);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 	if (poodle_jack_func == ucontrol->value.enumerated.item[0])
^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) 	poodle_jack_func = ucontrol->value.enumerated.item[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 	poodle_ext_control(&card->dapm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 	return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) static int poodle_get_spk(struct snd_kcontrol *kcontrol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 	struct snd_ctl_elem_value *ucontrol)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 	ucontrol->value.enumerated.item[0] = poodle_spk_func;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) static int poodle_set_spk(struct snd_kcontrol *kcontrol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 	struct snd_ctl_elem_value *ucontrol)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 	struct snd_soc_card *card =  snd_kcontrol_chip(kcontrol);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 	if (poodle_spk_func == ucontrol->value.enumerated.item[0])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 	poodle_spk_func = ucontrol->value.enumerated.item[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 	poodle_ext_control(&card->dapm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 	return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) static int poodle_amp_event(struct snd_soc_dapm_widget *w,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 	struct snd_kcontrol *k, int event)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 	if (SND_SOC_DAPM_EVENT_ON(event))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 		locomo_gpio_write(&poodle_locomo_device.dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 			POODLE_LOCOMO_GPIO_AMP_ON, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 		locomo_gpio_write(&poodle_locomo_device.dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 			POODLE_LOCOMO_GPIO_AMP_ON, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 	return 0;
^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) /* poodle machine dapm widgets */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) static const struct snd_soc_dapm_widget wm8731_dapm_widgets[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) SND_SOC_DAPM_HP("Headphone Jack", NULL),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) SND_SOC_DAPM_SPK("Ext Spk", poodle_amp_event),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) SND_SOC_DAPM_MIC("Microphone", NULL),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) /* Corgi machine connections to the codec pins */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) static const struct snd_soc_dapm_route poodle_audio_map[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 	/* headphone connected to LHPOUT1, RHPOUT1 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 	{"Headphone Jack", NULL, "LHPOUT"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 	{"Headphone Jack", NULL, "RHPOUT"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 	/* speaker connected to LOUT, ROUT */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 	{"Ext Spk", NULL, "ROUT"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 	{"Ext Spk", NULL, "LOUT"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 	{"MICIN", NULL, "Microphone"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) static const char * const jack_function[] = {"Off", "Headphone"};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) static const char * const spk_function[] = {"Off", "On"};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) static const struct soc_enum poodle_enum[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 	SOC_ENUM_SINGLE_EXT(2, jack_function),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 	SOC_ENUM_SINGLE_EXT(2, spk_function),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) static const struct snd_kcontrol_new wm8731_poodle_controls[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 	SOC_ENUM_EXT("Jack Function", poodle_enum[0], poodle_get_jack,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 		poodle_set_jack),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 	SOC_ENUM_EXT("Speaker Function", poodle_enum[1], poodle_get_spk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 		poodle_set_spk),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) /* poodle digital audio interface glue - connects codec <--> CPU */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) SND_SOC_DAILINK_DEFS(wm8731,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 	DAILINK_COMP_ARRAY(COMP_CPU("pxa2xx-i2s")),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 	DAILINK_COMP_ARRAY(COMP_CODEC("wm8731.0-001b", "wm8731-hifi")),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 	DAILINK_COMP_ARRAY(COMP_PLATFORM("pxa-pcm-audio")));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) static struct snd_soc_dai_link poodle_dai = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 	.name = "WM8731",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 	.stream_name = "WM8731",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 	.dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 		   SND_SOC_DAIFMT_CBS_CFS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 	.ops = &poodle_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 	SND_SOC_DAILINK_REG(wm8731),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) /* poodle audio machine driver */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) static struct snd_soc_card poodle = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 	.name = "Poodle",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 	.dai_link = &poodle_dai,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 	.num_links = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 	.owner = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 	.controls = wm8731_poodle_controls,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 	.num_controls = ARRAY_SIZE(wm8731_poodle_controls),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 	.dapm_widgets = wm8731_dapm_widgets,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 	.num_dapm_widgets = ARRAY_SIZE(wm8731_dapm_widgets),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 	.dapm_routes = poodle_audio_map,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 	.num_dapm_routes = ARRAY_SIZE(poodle_audio_map),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 	.fully_routed = true,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) static int poodle_probe(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 	struct snd_soc_card *card = &poodle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 	locomo_gpio_set_dir(&poodle_locomo_device.dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 		POODLE_LOCOMO_GPIO_AMP_ON, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 	/* should we mute HP at startup - burning power ?*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 	locomo_gpio_set_dir(&poodle_locomo_device.dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 		POODLE_LOCOMO_GPIO_MUTE_L, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 	locomo_gpio_set_dir(&poodle_locomo_device.dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 		POODLE_LOCOMO_GPIO_MUTE_R, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 	card->dev = &pdev->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 	ret = devm_snd_soc_register_card(&pdev->dev, card);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 		dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 			ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) static struct platform_driver poodle_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 	.driver		= {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 		.name	= "poodle-audio",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 		.pm     = &snd_soc_pm_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 	.probe		= poodle_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) module_platform_driver(poodle_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) /* Module information */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) MODULE_AUTHOR("Richard Purdie");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) MODULE_DESCRIPTION("ALSA SoC Poodle");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) MODULE_ALIAS("platform:poodle-audio");