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-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * n810.c  --  SoC audio for Nokia N810
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * Copyright (C) 2008 Nokia Corporation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  * Contact: Jarkko Nikula <jarkko.nikula@bitmer.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <linux/clk.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/i2c.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/platform_device.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) #include <asm/mach-types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <linux/gpio.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #include <linux/platform_data/asoc-ti-mcbsp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #include "omap-mcbsp.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) #define N810_HEADSET_AMP_GPIO	10
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) #define N810_SPEAKER_AMP_GPIO	101
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) enum {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 	N810_JACK_DISABLED,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 	N810_JACK_HP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 	N810_JACK_HS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 	N810_JACK_MIC,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) static struct clk *sys_clkout2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) static struct clk *sys_clkout2_src;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) static struct clk *func96m_clk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) static int n810_spk_func;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) static int n810_jack_func;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) static int n810_dmic_func;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) static void n810_ext_control(struct snd_soc_dapm_context *dapm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 	int hp = 0, line1l = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 	switch (n810_jack_func) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 	case N810_JACK_HS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 		line1l = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 		fallthrough;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	case N810_JACK_HP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 		hp = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	case N810_JACK_MIC:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 		line1l = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	snd_soc_dapm_mutex_lock(dapm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	if (n810_spk_func)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 		snd_soc_dapm_enable_pin_unlocked(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_unlocked(dapm, "Ext Spk");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	if (hp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 		snd_soc_dapm_enable_pin_unlocked(dapm, "Headphone Jack");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 		snd_soc_dapm_disable_pin_unlocked(dapm, "Headphone Jack");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	if (line1l)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 		snd_soc_dapm_enable_pin_unlocked(dapm, "HS Mic");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 		snd_soc_dapm_disable_pin_unlocked(dapm, "HS Mic");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	if (n810_dmic_func)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 		snd_soc_dapm_enable_pin_unlocked(dapm, "DMic");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 		snd_soc_dapm_disable_pin_unlocked(dapm, "DMic");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	snd_soc_dapm_sync_unlocked(dapm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	snd_soc_dapm_mutex_unlock(dapm);
^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) static int n810_startup(struct snd_pcm_substream *substream)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	struct snd_pcm_runtime *runtime = substream->runtime;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	snd_pcm_hw_constraint_single(runtime, SNDRV_PCM_HW_PARAM_CHANNELS, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	n810_ext_control(&rtd->card->dapm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	return clk_prepare_enable(sys_clkout2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) static void n810_shutdown(struct snd_pcm_substream *substream)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	clk_disable_unprepare(sys_clkout2);
^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) static int n810_hw_params(struct snd_pcm_substream *substream,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 	struct snd_pcm_hw_params *params)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	/* Set the codec system clock for DAC and ADC */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	err = snd_soc_dai_set_sysclk(codec_dai, 0, 12000000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 					    SND_SOC_CLOCK_IN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) static const struct snd_soc_ops n810_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	.startup = n810_startup,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	.hw_params = n810_hw_params,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	.shutdown = n810_shutdown,
^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) static int n810_get_spk(struct snd_kcontrol *kcontrol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 			struct snd_ctl_elem_value *ucontrol)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	ucontrol->value.enumerated.item[0] = n810_spk_func;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	return 0;
^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) static int n810_set_spk(struct snd_kcontrol *kcontrol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 			struct snd_ctl_elem_value *ucontrol)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 	struct snd_soc_card *card =  snd_kcontrol_chip(kcontrol);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	if (n810_spk_func == ucontrol->value.enumerated.item[0])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 	n810_spk_func = ucontrol->value.enumerated.item[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	n810_ext_control(&card->dapm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 	return 1;
^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 int n810_get_jack(struct snd_kcontrol *kcontrol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 			 struct snd_ctl_elem_value *ucontrol)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 	ucontrol->value.enumerated.item[0] = n810_jack_func;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) static int n810_set_jack(struct snd_kcontrol *kcontrol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 			 struct snd_ctl_elem_value *ucontrol)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 	struct snd_soc_card *card =  snd_kcontrol_chip(kcontrol);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 	if (n810_jack_func == ucontrol->value.enumerated.item[0])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 	n810_jack_func = ucontrol->value.enumerated.item[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 	n810_ext_control(&card->dapm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 	return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) static int n810_get_input(struct snd_kcontrol *kcontrol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 			  struct snd_ctl_elem_value *ucontrol)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 	ucontrol->value.enumerated.item[0] = n810_dmic_func;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 	return 0;
^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) static int n810_set_input(struct snd_kcontrol *kcontrol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 			  struct snd_ctl_elem_value *ucontrol)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 	struct snd_soc_card *card =  snd_kcontrol_chip(kcontrol);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 	if (n810_dmic_func == ucontrol->value.enumerated.item[0])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 	n810_dmic_func = ucontrol->value.enumerated.item[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 	n810_ext_control(&card->dapm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 	return 1;
^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 int n810_spk_event(struct snd_soc_dapm_widget *w,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 			  struct snd_kcontrol *k, int event)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 	if (SND_SOC_DAPM_EVENT_ON(event))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 		gpio_set_value(N810_SPEAKER_AMP_GPIO, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 		gpio_set_value(N810_SPEAKER_AMP_GPIO, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) static int n810_jack_event(struct snd_soc_dapm_widget *w,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 			   struct snd_kcontrol *k, int event)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 	if (SND_SOC_DAPM_EVENT_ON(event))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 		gpio_set_value(N810_HEADSET_AMP_GPIO, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 		gpio_set_value(N810_HEADSET_AMP_GPIO, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 	return 0;
^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 const struct snd_soc_dapm_widget aic33_dapm_widgets[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 	SND_SOC_DAPM_SPK("Ext Spk", n810_spk_event),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 	SND_SOC_DAPM_HP("Headphone Jack", n810_jack_event),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 	SND_SOC_DAPM_MIC("DMic", NULL),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 	SND_SOC_DAPM_MIC("HS Mic", NULL),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) static const struct snd_soc_dapm_route audio_map[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 	{"Headphone Jack", NULL, "HPLOUT"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 	{"Headphone Jack", NULL, "HPROUT"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 	{"Ext Spk", NULL, "LLOUT"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 	{"Ext Spk", NULL, "RLOUT"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 	{"DMic Rate 64", NULL, "DMic"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 	{"DMic", NULL, "Mic Bias"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 	 * Note that the mic bias is coming from Retu/Vilma and we don't have
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 	 * control over it atm. The analog HS mic is not working. <- TODO
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 	{"LINE1L", NULL, "HS Mic"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) static const char *spk_function[] = {"Off", "On"};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) static const char *jack_function[] = {"Off", "Headphone", "Headset", "Mic"};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) static const char *input_function[] = {"ADC", "Digital Mic"};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) static const struct soc_enum n810_enum[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 	SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(spk_function), spk_function),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 	SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(jack_function), jack_function),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 	SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(input_function), input_function),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) static const struct snd_kcontrol_new aic33_n810_controls[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 	SOC_ENUM_EXT("Speaker Function", n810_enum[0],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 		     n810_get_spk, n810_set_spk),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 	SOC_ENUM_EXT("Jack Function", n810_enum[1],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 		     n810_get_jack, n810_set_jack),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 	SOC_ENUM_EXT("Input Select",  n810_enum[2],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 		     n810_get_input, n810_set_input),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) /* Digital audio interface glue - connects codec <--> CPU */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) SND_SOC_DAILINK_DEFS(aic33,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 	DAILINK_COMP_ARRAY(COMP_CPU("48076000.mcbsp")),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 	DAILINK_COMP_ARRAY(COMP_CODEC("tlv320aic3x-codec.1-0018",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 				      "tlv320aic3x-hifi")),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 	DAILINK_COMP_ARRAY(COMP_PLATFORM("48076000.mcbsp")));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) static struct snd_soc_dai_link n810_dai = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 	.name = "TLV320AIC33",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 	.stream_name = "AIC33",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 	.dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 		   SND_SOC_DAIFMT_CBM_CFM,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 	.ops = &n810_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 	SND_SOC_DAILINK_REG(aic33),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) /* Audio machine driver */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) static struct snd_soc_card snd_soc_n810 = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 	.name = "N810",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 	.owner = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 	.dai_link = &n810_dai,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 	.num_links = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 	.controls = aic33_n810_controls,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 	.num_controls = ARRAY_SIZE(aic33_n810_controls),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 	.dapm_widgets = aic33_dapm_widgets,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 	.num_dapm_widgets = ARRAY_SIZE(aic33_dapm_widgets),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 	.dapm_routes = audio_map,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 	.num_dapm_routes = ARRAY_SIZE(audio_map),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 	.fully_routed = true,
^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) static struct platform_device *n810_snd_device;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) static int __init n810_soc_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 	struct device *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 	if (!of_have_populated_dt() ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 	    (!of_machine_is_compatible("nokia,n810") &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 	     !of_machine_is_compatible("nokia,n810-wimax")))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 	n810_snd_device = platform_device_alloc("soc-audio", -1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 	if (!n810_snd_device)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 	platform_set_drvdata(n810_snd_device, &snd_soc_n810);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 	err = platform_device_add(n810_snd_device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 		goto err1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 	dev = &n810_snd_device->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 	sys_clkout2_src = clk_get(dev, "sys_clkout2_src");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 	if (IS_ERR(sys_clkout2_src)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 		dev_err(dev, "Could not get sys_clkout2_src clock\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 		err = PTR_ERR(sys_clkout2_src);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 		goto err2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 	sys_clkout2 = clk_get(dev, "sys_clkout2");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 	if (IS_ERR(sys_clkout2)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 		dev_err(dev, "Could not get sys_clkout2\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 		err = PTR_ERR(sys_clkout2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 		goto err3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 	 * Configure 12 MHz output on SYS_CLKOUT2. Therefore we must use
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 	 * 96 MHz as its parent in order to get 12 MHz
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 	func96m_clk = clk_get(dev, "func_96m_ck");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 	if (IS_ERR(func96m_clk)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 		dev_err(dev, "Could not get func 96M clock\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 		err = PTR_ERR(func96m_clk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 		goto err4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 	clk_set_parent(sys_clkout2_src, func96m_clk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 	clk_set_rate(sys_clkout2, 12000000);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 	if (WARN_ON((gpio_request(N810_HEADSET_AMP_GPIO, "hs_amp") < 0) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 		    (gpio_request(N810_SPEAKER_AMP_GPIO, "spk_amp") < 0))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 		err = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 		goto err4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 	gpio_direction_output(N810_HEADSET_AMP_GPIO, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 	gpio_direction_output(N810_SPEAKER_AMP_GPIO, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) err4:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 	clk_put(sys_clkout2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) err3:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 	clk_put(sys_clkout2_src);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) err2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 	platform_device_del(n810_snd_device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) err1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 	platform_device_put(n810_snd_device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) static void __exit n810_soc_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 	gpio_free(N810_SPEAKER_AMP_GPIO);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 	gpio_free(N810_HEADSET_AMP_GPIO);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) 	clk_put(sys_clkout2_src);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) 	clk_put(sys_clkout2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 	clk_put(func96m_clk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 	platform_device_unregister(n810_snd_device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) module_init(n810_soc_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) module_exit(n810_soc_exit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) MODULE_AUTHOR("Jarkko Nikula <jarkko.nikula@bitmer.com>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) MODULE_DESCRIPTION("ALSA SoC Nokia N810");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) MODULE_LICENSE("GPL");