| 1 |
// SPDX-License-Identifier: GPL-2.0-or-later |
| 2 |
/* |
| 3 |
* Universal codec driver for Intel High Definition Audio Codec |
| 4 |
* |
| 5 |
* HD audio codec driver for C-Media CMI9880 |
| 6 |
* |
| 7 |
* Copyright (c) 2004 Takashi Iwai <[email protected]> |
| 8 |
*/ |
| 9 |
|
| 10 |
#include <linux/init.h> |
| 11 |
#include <linux/slab.h> |
| 12 |
#include <linux/module.h> |
| 13 |
#include <sound/core.h> |
| 14 |
#include <sound/hda_codec.h> |
| 15 |
#include "hda_local.h" |
| 16 |
#include "hda_auto_parser.h" |
| 17 |
#include "hda_jack.h" |
| 18 |
#include "generic.h" |
| 19 |
|
| 20 |
static int cmedia_probe(struct hda_codec *codec, const struct hda_device_id *id) |
| 21 |
{ |
| 22 |
struct hda_gen_spec *spec; |
| 23 |
struct auto_pin_cfg *cfg; |
| 24 |
bool is_cmi8888 = id->vendor_id == 0x13f68888; |
| 25 |
int err; |
| 26 |
|
| 27 |
spec = kzalloc_obj(*spec); |
| 28 |
if (spec == NULL) |
| 29 |
return -ENOMEM; |
| 30 |
|
| 31 |
codec->spec = spec; |
| 32 |
cfg = &spec->autocfg; |
| 33 |
snd_hda_gen_spec_init(spec); |
| 34 |
|
| 35 |
if (is_cmi8888) { |
| 36 |
/* mask NID 0x10 from the playback volume selection; |
| 37 |
* it's a headphone boost volume handled manually below |
| 38 |
*/ |
| 39 |
spec->out_vol_mask = (1ULL << 0x10); |
| 40 |
} |
| 41 |
|
| 42 |
err = snd_hda_parse_pin_defcfg(codec, cfg, NULL, 0); |
| 43 |
if (err < 0) |
| 44 |
goto error; |
| 45 |
err = snd_hda_gen_parse_auto_config(codec, cfg); |
| 46 |
if (err < 0) |
| 47 |
goto error; |
| 48 |
|
| 49 |
if (is_cmi8888) { |
| 50 |
if (get_defcfg_device(snd_hda_codec_get_pincfg(codec, 0x10)) == |
| 51 |
AC_JACK_HP_OUT) { |
| 52 |
static const struct snd_kcontrol_new amp_kctl = |
| 53 |
HDA_CODEC_VOLUME("Headphone Amp Playback Volume", |
| 54 |
0x10, 0, HDA_OUTPUT); |
| 55 |
if (!snd_hda_gen_add_kctl(spec, NULL, &_kctl)) { |
| 56 |
err = -ENOMEM; |
| 57 |
goto error; |
| 58 |
} |
| 59 |
} |
| 60 |
} |
| 61 |
|
| 62 |
return 0; |
| 63 |
|
| 64 |
error: |
| 65 |
snd_hda_gen_remove(codec); |
| 66 |
return err; |
| 67 |
} |
| 68 |
|
| 69 |
static const struct hda_codec_ops cmedia_codec_ops = { |
| 70 |
.probe = cmedia_probe, |
| 71 |
.remove = snd_hda_gen_remove, |
| 72 |
.build_controls = snd_hda_gen_build_controls, |
| 73 |
.build_pcms = snd_hda_gen_build_pcms, |
| 74 |
.init = snd_hda_gen_init, |
| 75 |
.unsol_event = snd_hda_jack_unsol_event, |
| 76 |
.check_power_status = snd_hda_gen_check_power_status, |
| 77 |
.stream_pm = snd_hda_gen_stream_pm, |
| 78 |
}; |
| 79 |
|
| 80 |
/* |
| 81 |
* driver entries |
| 82 |
*/ |
| 83 |
static const struct hda_device_id snd_hda_id_cmedia[] = { |
| 84 |
HDA_CODEC_ID(0x13f68888, "CMI8888"), |
| 85 |
HDA_CODEC_ID(0x13f69880, "CMI9880"), |
| 86 |
HDA_CODEC_ID(0x434d4980, "CMI9880"), |
| 87 |
{} /* terminator */ |
| 88 |
}; |
| 89 |
MODULE_DEVICE_TABLE(hdaudio, snd_hda_id_cmedia); |
| 90 |
|
| 91 |
MODULE_LICENSE("GPL"); |
| 92 |
MODULE_DESCRIPTION("C-Media HD-audio codec"); |
| 93 |
|
| 94 |
static struct hda_codec_driver cmedia_driver = { |
| 95 |
.id = snd_hda_id_cmedia, |
| 96 |
.ops = &cmedia_codec_ops, |
| 97 |
}; |
| 98 |
|
| 99 |
module_hda_codec_driver(cmedia_driver); |