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)  * Universal Interface for Intel High Definition Audio Codec
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * HD audio interface patch for C-Media CMI9880
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  * Copyright (c) 2004 Takashi Iwai <tiwai@suse.de>
^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/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/slab.h>
^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 <sound/core.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <sound/hda_codec.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include "hda_local.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include "hda_auto_parser.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include "hda_jack.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include "hda_generic.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) struct cmi_spec {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) 	struct hda_gen_spec gen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25)  * stuff for auto-parser
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) static const struct hda_codec_ops cmi_auto_patch_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 	.build_controls = snd_hda_gen_build_controls,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 	.build_pcms = snd_hda_gen_build_pcms,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 	.init = snd_hda_gen_init,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 	.free = snd_hda_gen_free,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 	.unsol_event = snd_hda_jack_unsol_event,
^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 patch_cmi9880(struct hda_codec *codec)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 	struct cmi_spec *spec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 	struct auto_pin_cfg *cfg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 	spec = kzalloc(sizeof(*spec), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 	if (spec == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 	codec->spec = spec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 	codec->patch_ops = cmi_auto_patch_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 	cfg = &spec->gen.autocfg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	snd_hda_gen_spec_init(&spec->gen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	err = snd_hda_parse_pin_defcfg(codec, cfg, NULL, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 		goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	err = snd_hda_gen_parse_auto_config(codec, cfg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 		goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59)  error:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	snd_hda_gen_free(codec);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) static int patch_cmi8888(struct hda_codec *codec)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	struct cmi_spec *spec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	struct auto_pin_cfg *cfg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	spec = kzalloc(sizeof(*spec), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	if (!spec)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	codec->spec = spec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	codec->patch_ops = cmi_auto_patch_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	cfg = &spec->gen.autocfg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	snd_hda_gen_spec_init(&spec->gen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	/* mask NID 0x10 from the playback volume selection;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	 * it's a headphone boost volume handled manually below
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	spec->gen.out_vol_mask = (1ULL << 0x10);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 	err = snd_hda_parse_pin_defcfg(codec, cfg, NULL, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 		goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	err = snd_hda_gen_parse_auto_config(codec, cfg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 		goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	if (get_defcfg_device(snd_hda_codec_get_pincfg(codec, 0x10)) ==
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	    AC_JACK_HP_OUT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 		static const struct snd_kcontrol_new amp_kctl =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 			HDA_CODEC_VOLUME("Headphone Amp Playback Volume",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 					 0x10, 0, HDA_OUTPUT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 		if (!snd_hda_gen_add_kctl(&spec->gen, NULL, &amp_kctl)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 			err = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 			goto error;
^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) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104)  error:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 	snd_hda_gen_free(codec);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110)  * patch entries
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) static const struct hda_device_id snd_hda_id_cmedia[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	HDA_CODEC_ENTRY(0x13f68888, "CMI8888", patch_cmi8888),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	HDA_CODEC_ENTRY(0x13f69880, "CMI9880", patch_cmi9880),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	HDA_CODEC_ENTRY(0x434d4980, "CMI9880", patch_cmi9880),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	{} /* terminator */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) MODULE_DEVICE_TABLE(hdaudio, snd_hda_id_cmedia);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) MODULE_DESCRIPTION("C-Media HD-audio codec");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) static struct hda_codec_driver cmedia_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	.id = snd_hda_id_cmedia,
^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) module_hda_codec_driver(cmedia_driver);