Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- diff --git a/pci/hda/patch_nvhdmi.c b/pci/hda/patch_nvhdmi.c
- index 6afdab0..91fe3a2 100644
- --- a/pci/hda/patch_nvhdmi.c
- +++ b/pci/hda/patch_nvhdmi.c
- @@ -29,33 +29,236 @@
- #include "hda_codec.h"
- #include "hda_local.h"
- -/* define below to restrict the supported rates and formats */
- -/* #define LIMITED_RATE_FMT_SUPPORT */
- +enum HDACodec {
- + HDA_CODEC_NVIDIA_MCP7X,
- + HDA_CODEC_NVIDIA_MCP89,
- + HDA_CODEC_NVIDIA_GT21X,
- + HDA_CODEC_INVALID
- +};
- +
- +struct hdmi_audio_infoframe {
- + u8 type; /* 0x84 */
- + u8 ver; /* 0x01 */
- + u8 len; /* 0x0a */
- +
- + u8 checksum; /* PB0 */
- + u8 CC02_CT47; /* CC in bits 0:2, CT in 4:7 */
- + u8 SS01_SF24;
- + u8 CXT04;
- + u8 CA;
- + u8 LFEPBL01_LSV36_DM_INH7;
- +};
- +/*
- + * CEA speaker placement:
- + *
- + * FLH FCH FRH
- + * FLW FL FLC FC FRC FR FRW
- + *
- + * LFE
- + * TC
- + *
- + * RL RLC RC RRC RR
- + *
- + * The Left/Right Surround channel _notions_ LS/RS in SMPTE 320M corresponds to
- + * CEA RL/RR; The SMPTE channel _assignment_ C/LFE is swapped to CEA LFE/FC.
- + */
- +enum cea_speaker_placement {
- + FL = (1 << 0), /* Front Left */
- + FC = (1 << 1), /* Front Center */
- + FR = (1 << 2), /* Front Right */
- + FLC = (1 << 3), /* Front Left Center */
- + FRC = (1 << 4), /* Front Right Center */
- + RL = (1 << 5), /* Rear Left */
- + RC = (1 << 6), /* Rear Center */
- + RR = (1 << 7), /* Rear Right */
- + RLC = (1 << 8), /* Rear Left Center */
- + RRC = (1 << 9), /* Rear Right Center */
- + LFE = (1 << 10), /* Low Frequency Effect */
- + FLW = (1 << 11), /* Front Left Wide */
- + FRW = (1 << 12), /* Front Right Wide */
- + FLH = (1 << 13), /* Front Left High */
- + FCH = (1 << 14), /* Front Center High */
- + FRH = (1 << 15), /* Front Right High */
- + TC = (1 << 16), /* Top Center */
- +};
- +
- +/*
- + * ELD SA bits in the CEA Speaker Allocation data block
- + */
- +static int eld_speaker_allocation_bits[] = {
- + [0] = FL | FR,
- + [1] = LFE,
- + [2] = FC,
- + [3] = RL | RR,
- + [4] = RC,
- + [5] = FLC | FRC,
- + [6] = RLC | RRC,
- + /* the following are not defined in ELD yet */
- + [7] = FLW | FRW,
- + [8] = FLH | FRH,
- + [9] = TC,
- + [10] = FCH,
- +};
- +
- +struct cea_channel_speaker_allocation {
- + int ca_index;
- + int speakers[8];
- +
- + /* derived values, just for convenience */
- + int channels;
- + int spk_mask;
- +};
- +
- +/*
- + * This is an ordered list!
- + *
- + * The preceding ones have better chances to be selected by
- + * hdmi_setup_channel_allocation().
- + */
- +static struct cea_channel_speaker_allocation channel_allocations[] = {
- +/* channel: 8 7 6 5 4 3 2 1 */
- +{ .ca_index = 0x00, .speakers = { 0, 0, 0, 0, 0, 0, FR, FL } },
- + /* 2.1 */
- +{ .ca_index = 0x01, .speakers = { 0, 0, 0, 0, 0, LFE, FR, FL } },
- + /* Dolby Surround */
- +{ .ca_index = 0x02, .speakers = { 0, 0, 0, 0, FC, 0, FR, FL } },
- +{ .ca_index = 0x03, .speakers = { 0, 0, 0, 0, FC, LFE, FR, FL } },
- +{ .ca_index = 0x04, .speakers = { 0, 0, 0, RC, 0, 0, FR, FL } },
- +{ .ca_index = 0x05, .speakers = { 0, 0, 0, RC, 0, LFE, FR, FL } },
- +{ .ca_index = 0x06, .speakers = { 0, 0, 0, RC, FC, 0, FR, FL } },
- +{ .ca_index = 0x07, .speakers = { 0, 0, 0, RC, FC, LFE, FR, FL } },
- +{ .ca_index = 0x08, .speakers = { 0, 0, RR, RL, 0, 0, FR, FL } },
- +{ .ca_index = 0x09, .speakers = { 0, 0, RR, RL, 0, LFE, FR, FL } },
- +{ .ca_index = 0x0a, .speakers = { 0, 0, RR, RL, FC, 0, FR, FL } },
- + /* 5.1 */
- +{ .ca_index = 0x0b, .speakers = { 0, 0, RR, RL, FC, LFE, FR, FL } },
- +{ .ca_index = 0x0c, .speakers = { 0, RC, RR, RL, 0, 0, FR, FL } },
- +{ .ca_index = 0x0d, .speakers = { 0, RC, RR, RL, 0, LFE, FR, FL } },
- +{ .ca_index = 0x0e, .speakers = { 0, RC, RR, RL, FC, 0, FR, FL } },
- + /* 6.1 */
- +{ .ca_index = 0x0f, .speakers = { 0, RC, RR, RL, FC, LFE, FR, FL } },
- +{ .ca_index = 0x10, .speakers = { RRC, RLC, RR, RL, 0, 0, FR, FL } },
- +{ .ca_index = 0x11, .speakers = { RRC, RLC, RR, RL, 0, LFE, FR, FL } },
- +{ .ca_index = 0x12, .speakers = { RRC, RLC, RR, RL, FC, 0, FR, FL } },
- + /* 7.1 */
- +{ .ca_index = 0x13, .speakers = { RRC, RLC, RR, RL, FC, LFE, FR, FL } },
- +{ .ca_index = 0x14, .speakers = { FRC, FLC, 0, 0, 0, 0, FR, FL } },
- +{ .ca_index = 0x15, .speakers = { FRC, FLC, 0, 0, 0, LFE, FR, FL } },
- +{ .ca_index = 0x16, .speakers = { FRC, FLC, 0, 0, FC, 0, FR, FL } },
- +{ .ca_index = 0x17, .speakers = { FRC, FLC, 0, 0, FC, LFE, FR, FL } },
- +{ .ca_index = 0x18, .speakers = { FRC, FLC, 0, RC, 0, 0, FR, FL } },
- +{ .ca_index = 0x19, .speakers = { FRC, FLC, 0, RC, 0, LFE, FR, FL } },
- +{ .ca_index = 0x1a, .speakers = { FRC, FLC, 0, RC, FC, 0, FR, FL } },
- +{ .ca_index = 0x1b, .speakers = { FRC, FLC, 0, RC, FC, LFE, FR, FL } },
- +{ .ca_index = 0x1c, .speakers = { FRC, FLC, RR, RL, 0, 0, FR, FL } },
- +{ .ca_index = 0x1d, .speakers = { FRC, FLC, RR, RL, 0, LFE, FR, FL } },
- +{ .ca_index = 0x1e, .speakers = { FRC, FLC, RR, RL, FC, 0, FR, FL } },
- +{ .ca_index = 0x1f, .speakers = { FRC, FLC, RR, RL, FC, LFE, FR, FL } },
- +{ .ca_index = 0x20, .speakers = { 0, FCH, RR, RL, FC, 0, FR, FL } },
- +{ .ca_index = 0x21, .speakers = { 0, FCH, RR, RL, FC, LFE, FR, FL } },
- +{ .ca_index = 0x22, .speakers = { TC, 0, RR, RL, FC, 0, FR, FL } },
- +{ .ca_index = 0x23, .speakers = { TC, 0, RR, RL, FC, LFE, FR, FL } },
- +{ .ca_index = 0x24, .speakers = { FRH, FLH, RR, RL, 0, 0, FR, FL } },
- +{ .ca_index = 0x25, .speakers = { FRH, FLH, RR, RL, 0, LFE, FR, FL } },
- +{ .ca_index = 0x26, .speakers = { FRW, FLW, RR, RL, 0, 0, FR, FL } },
- +{ .ca_index = 0x27, .speakers = { FRW, FLW, RR, RL, 0, LFE, FR, FL } },
- +{ .ca_index = 0x28, .speakers = { TC, RC, RR, RL, FC, 0, FR, FL } },
- +{ .ca_index = 0x29, .speakers = { TC, RC, RR, RL, FC, LFE, FR, FL } },
- +{ .ca_index = 0x2a, .speakers = { FCH, RC, RR, RL, FC, 0, FR, FL } },
- +{ .ca_index = 0x2b, .speakers = { FCH, RC, RR, RL, FC, LFE, FR, FL } },
- +{ .ca_index = 0x2c, .speakers = { TC, FCH, RR, RL, FC, 0, FR, FL } },
- +{ .ca_index = 0x2d, .speakers = { TC, FCH, RR, RL, FC, LFE, FR, FL } },
- +{ .ca_index = 0x2e, .speakers = { FRH, FLH, RR, RL, FC, 0, FR, FL } },
- +{ .ca_index = 0x2f, .speakers = { FRH, FLH, RR, RL, FC, LFE, FR, FL } },
- +{ .ca_index = 0x30, .speakers = { FRW, FLW, RR, RL, FC, 0, FR, FL } },
- +{ .ca_index = 0x31, .speakers = { FRW, FLW, RR, RL, FC, LFE, FR, FL } },
- +};
- +
- +/*
- + * ELD: EDID Like Data
- + */
- +#define ELD_MAX_MNL 16
- +#define ELD_MAX_SAD 16
- +/*
- +struct hdmi_eld {
- + bool monitor_present;
- + bool eld_valid;
- + int eld_size;
- + int baseline_len;
- + int eld_ver;
- + int cea_edid_ver;
- + char monitor_name[ELD_MAX_MNL + 1];
- + int manufacture_id;
- + int product_id;
- + u64 port_id;
- + int support_hdcp;
- + int support_ai;
- + int conn_type;
- + int aud_synch_delay;
- + int spk_alloc;
- + int sad_count;
- +// struct cea_sad sad[ELD_MAX_SAD];
- +};
- +*/
- struct nvhdmi_spec {
- struct hda_multi_out multiout;
- struct hda_pcm pcm_rec;
- +
- + /*
- + * HDMI sink attached to each pin
- + */
- + struct hdmi_eld sink_eld[1];
- + unsigned int codec_type;
- };
- -#define Nv_VERB_SET_Channel_Allocation 0xF79
- -#define Nv_VERB_SET_Info_Frame_Checksum 0xF7A
- -#define Nv_VERB_SET_Audio_Protection_On 0xF98
- -#define Nv_VERB_SET_Audio_Protection_Off 0xF99
- +#define AC_DIPXMIT_DISABLE (0x0<<6)
- +#define AC_DIPXMIT_BEST (0x3<<6)
- +
- +#define AC_VERB_GET_CVT_CHAN_COUNT 0xf2d
- +#define AC_VERB_GET_HDMI_DIP_DATA 0xf31
- +#define AC_VERB_GET_HDMI_DIP_XMIT 0xf32
- +
- +#define AC_VERB_SET_CVT_CHAN_COUNT 0x72d
- +#define AC_VERB_SET_HDMI_DIP_INDEX 0x730
- +#define AC_VERB_SET_HDMI_DIP_DATA 0x731
- +#define AC_VERB_SET_HDMI_DIP_XMIT 0x732
- +#define AC_VERB_SET_HDMI_CHAN_SLOT 0x734
- -#define Nv_Master_Convert_nid 0x04
- -#define Nv_Master_Pin_nid 0x05
- +#define Nv_VERB_SET_Channel_Allocation 0xF79
- +#define Nv_VERB_SET_Info_Frame_Checksum 0xF7A
- +#define Nv_VERB_SET_Audio_Protection_On 0xF98
- +#define Nv_VERB_SET_Audio_Protection_Off 0xF99
- -static hda_nid_t nvhdmi_convert_nids[4] = {
- +#define Nv_Master_Convert_nid 0x04
- +#define Nv_Master_Pin_nid 0x05
- +
- +#define nvhdmi_convert_nids_89 0x04
- +#define nvhdmi_pin_nids_89 0x05
- +
- +static hda_nid_t nvhdmi_convert_nids_7x[4] = {
- /*front, rear, clfe, rear_surr */
- 0x6, 0x8, 0xa, 0xc,
- };
- -static struct hda_verb nvhdmi_basic_init[] = {
- +#if 0
- +static hda_nid_t nvhdmi_pin_nids_7x[4] = {
- + /*front, rear, clfe, rear_surr */
- + 0x7, 0x9, 0xb, 0xd,
- +};
- +#endif
- +
- +static struct hda_verb nvhdmi_basic_init_89[] = {
- + /* enable digital output on pin widget */
- + { 0x5, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
- + { 0x5, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
- + {} /* terminator */
- +};
- +static struct hda_verb nvhdmi_basic_init_7x[] = {
- /* set audio protect on */
- { 0x1, Nv_VERB_SET_Audio_Protection_On, 0x1},
- /* enable digital output on pin widget */
- - { 0x5, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT | 0x5 },
- { 0x7, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT | 0x5 },
- { 0x9, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT | 0x5 },
- { 0xb, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT | 0x5 },
- @@ -63,22 +266,330 @@ static struct hda_verb nvhdmi_basic_init[] = {
- {} /* terminator */
- };
- -#ifdef LIMITED_RATE_FMT_SUPPORT
- -/* support only the safe format and rate */
- -#define SUPPORTED_RATES SNDRV_PCM_RATE_48000
- -#define SUPPORTED_MAXBPS 16
- -#define SUPPORTED_FORMATS SNDRV_PCM_FMTBIT_S16_LE
- -#else
- -/* support all rates and formats */
- -#define SUPPORTED_RATES \
- - (SNDRV_PCM_RATE_22050 | SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000 |\
- - SNDRV_PCM_RATE_88200 | SNDRV_PCM_RATE_96000 | SNDRV_PCM_RATE_176400 |\
- - SNDRV_PCM_RATE_192000)
- -#define SUPPORTED_MAXBPS 24
- -#define SUPPORTED_FORMATS \
- - (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S32_LE)
- +static void hdmi_set_dip_index(struct hda_codec *codec, hda_nid_t pin_nid,
- + int packet_index, int byte_index)
- +{
- + int val;
- +
- + val = (packet_index << 5) | (byte_index & 0x1f);
- +
- + snd_hda_codec_write(codec, pin_nid, 0, AC_VERB_SET_HDMI_DIP_INDEX, val);
- +}
- +
- +static void hdmi_write_dip_byte(struct hda_codec *codec, hda_nid_t pin_nid,
- + unsigned char val)
- +{
- + snd_hda_codec_write(codec, pin_nid, 0, AC_VERB_SET_HDMI_DIP_DATA, val);
- +}
- +
- +static void hdmi_enable_output(struct hda_codec *codec, hda_nid_t pin_nid)
- +{
- + /* Unmute */
- + if (get_wcaps(codec, pin_nid) & AC_WCAP_OUT_AMP)
- + snd_hda_codec_write(codec, pin_nid, 0,
- + AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE);
- + /* Enable pin out */
- + snd_hda_codec_write(codec, pin_nid, 0,
- + AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
- +}
- +
- +/*
- + * Enable Audio InfoFrame Transmission
- + */
- +static void hdmi_start_infoframe_trans(struct hda_codec *codec,
- + hda_nid_t pin_nid)
- +{
- + hdmi_set_dip_index(codec, pin_nid, 0x0, 0x0);
- + snd_hda_codec_write(codec, pin_nid, 0, AC_VERB_SET_HDMI_DIP_XMIT,
- + AC_DIPXMIT_BEST);
- +}
- +
- +/*
- + * Disable Audio InfoFrame Transmission
- + */
- +static void hdmi_stop_infoframe_trans(struct hda_codec *codec,
- + hda_nid_t pin_nid)
- +{
- + hdmi_set_dip_index(codec, pin_nid, 0x0, 0x0);
- + snd_hda_codec_write(codec, pin_nid, 0, AC_VERB_SET_HDMI_DIP_XMIT,
- + AC_DIPXMIT_DISABLE);
- +}
- +
- +static int hdmi_get_channel_count(struct hda_codec *codec, hda_nid_t nid)
- +{
- + return 1 + snd_hda_codec_read(codec, nid, 0,
- + AC_VERB_GET_CVT_CHAN_COUNT, 0);
- +}
- +
- +static void hdmi_set_channel_count(struct hda_codec *codec,
- + hda_nid_t nid, int chs)
- +{
- + if (chs != hdmi_get_channel_count(codec, nid))
- + snd_hda_codec_write(codec, nid, 0,
- + AC_VERB_SET_CVT_CHAN_COUNT, chs - 1);
- +}
- +
- +static void hdmi_checksum_audio_infoframe(struct hdmi_audio_infoframe *ai)
- +{
- + u8 *bytes = (u8 *)ai;
- + ai->checksum = 0;
- +/*
- + u8 sum = 0;
- + int i;
- +
- + ai->checksum = 0;
- +
- + for (i = 0; i < sizeof(*ai); i++)
- + sum += bytes[i];
- +
- + ai->checksum = - sum;
- +*/
- +}
- +
- +static void hdmi_fill_audio_infoframe(struct hda_codec *codec,
- + hda_nid_t pin_nid,
- + struct hdmi_audio_infoframe *ai)
- +{
- + u8 *bytes = (u8 *)ai;
- + int i;
- +
- + hdmi_checksum_audio_infoframe(ai);
- +
- + hdmi_set_dip_index(codec, pin_nid, 0x0, 0x0);
- + for (i = 0; i < sizeof(*ai); i++)
- + hdmi_write_dip_byte(codec, pin_nid, bytes[i]);
- +}
- +
- +/*
- + * Compute derived values in channel_allocations[].
- + */
- +static void init_channel_allocations(void)
- +{
- + int i, j;
- + struct cea_channel_speaker_allocation *p;
- +
- + for (i = 0; i < ARRAY_SIZE(channel_allocations); i++) {
- + p = channel_allocations + i;
- + p->channels = 0;
- + p->spk_mask = 0;
- + for (j = 0; j < ARRAY_SIZE(p->speakers); j++)
- + if (p->speakers[j]) {
- + p->channels++;
- + p->spk_mask |= p->speakers[j];
- + }
- + }
- +}
- +
- +/*
- + * The transformation takes two steps:
- + *
- + * eld->spk_alloc => (eld_speaker_allocation_bits[]) => spk_mask
- + * spk_mask => (channel_allocations[]) => ai->CA
- + *
- + * TODO: it could select the wrong CA from multiple candidates.
- +*/
- +static int hdmi_setup_channel_allocation(struct hda_codec *codec, hda_nid_t nid,
- + struct hdmi_audio_infoframe *ai)
- +{
- + struct intel_hdmi_spec *spec = codec->spec;
- + struct hdmi_eld *eld;
- + int i;
- + int spk_mask = 0;
- + int channels = 1 + (ai->CC02_CT47 & 0x7);
- +
- + switch (channels)
- + {
- + default:
- + case 0:
- + case 2:
- + ai->CA = 0;
- + break;
- + case 4:
- + ai->CA = 0x08;
- +// ai->CA = 0x06;
- + break;
- + case 6:
- + ai->CA = 0x0b;
- + break;
- + case 8:
- + ai->CA = 0x13;
- +// ai->CA = 0x1A;
- + break;
- + }
- +#if 0
- + /*
- + * CA defaults to 0 for basic stereo audio
- + */
- + if (channels <= 2)
- + return 0;
- +
- + i = hda_node_index(spec->pin_cvt, nid);
- + if (i < 0)
- + return 0;
- + eld = &spec->sink_eld[i];
- +
- + /*
- + * HDMI sink's ELD info cannot always be retrieved for now, e.g.
- + * in console or for audio devices. Assume the highest speakers
- + * configuration, to _not_ prohibit multi-channel audio playback.
- + */
- + if (!eld->spk_alloc)
- + eld->spk_alloc = 0xffff;
- +
- + /*
- + * expand ELD's speaker allocation mask
- + *
- + * ELD tells the speaker mask in a compact(paired) form,
- + * expand ELD's notions to match the ones used by Audio InfoFrame.
- + */
- + for (i = 0; i < ARRAY_SIZE(eld_speaker_allocation_bits); i++) {
- + if (eld->spk_alloc & (1 << i))
- + spk_mask |= eld_speaker_allocation_bits[i];
- + }
- +
- + /* search for the first working match in the CA table */
- + for (i = 0; i < ARRAY_SIZE(channel_allocations); i++) {
- + if (channels == channel_allocations[i].channels &&
- + (spk_mask & channel_allocations[i].spk_mask) ==
- + channel_allocations[i].spk_mask) {
- + ai->CA = channel_allocations[i].ca_index;
- + break;
- + }
- + }
- #endif
- + return ai->CA;
- +}
- +
- +static void hdmi_setup_channel_mapping(struct hda_codec *codec, hda_nid_t nid,
- + struct hdmi_audio_infoframe *ai)
- +{
- + int i;
- + int channels = 1 + (ai->CC02_CT47 & 0x7);
- + unsigned char map[8] = {0x00, 0x11, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7};
- +
- + /*
- + * TODO: adjust channel mapping if necessary
- + * ALSA sequence is front/surr/clfe/side?
- + */
- +
- + switch (channels) {
- + case 2:
- + break;
- + case 4:
- + if (ai->CA == 0x08)
- + {
- + map[4] = 0x24;
- + map[5] = 0x35;
- + }
- + else if (ai->CA == 0x06)
- + {
- + map[4] = 0x23;
- + map[5] = 0x34;
- + }
- +
- + break;
- + case 6:
- + map[2] = 0x32;
- + map[3] = 0x23;
- + map[4] = 0x44;
- + map[5] = 0x55;
- + break;
- + case 8:
- + map[2] = 0x32;
- + map[3] = 0x23;
- + map[4] = 0x64;
- + map[5] = 0x75;
- + map[6] = 0x46;
- + map[7] = 0x57;
- + break;
- +
- + }
- +
- + for (i = 0; i < 8; i++)
- + {
- + snd_hda_codec_write(codec, nid, 0,
- + AC_VERB_SET_HDMI_CHAN_SLOT,
- + map[i]);
- + }
- +
- +}
- +
- +static bool hdmi_infoframe_uptodate(struct hda_codec *codec, hda_nid_t pin_nid,
- + struct hdmi_audio_infoframe *ai)
- +{
- + u8 *bytes = (u8 *)ai;
- + u8 val;
- + int i;
- +
- + if (snd_hda_codec_read(codec, pin_nid, 0, AC_VERB_GET_HDMI_DIP_XMIT, 0)
- + != AC_DIPXMIT_BEST)
- + return false;
- +
- + hdmi_set_dip_index(codec, pin_nid, 0x0, 0x0);
- + for (i = 0; i < sizeof(*ai); i++) {
- + val = snd_hda_codec_read(codec, pin_nid, 0,
- + AC_VERB_GET_HDMI_DIP_DATA, 0);
- + if (val != bytes[i])
- + return false;
- + }
- +
- + return true;
- +}
- +
- +static void hdmi_setup_audio_infoframe(struct hda_codec *codec, hda_nid_t nid,
- + struct snd_pcm_substream *substream)
- +{
- + struct intel_hdmi_spec *spec = codec->spec;
- + hda_nid_t pin_nid;
- + int i;
- + struct hdmi_audio_infoframe ai = {
- + .type = 0x84,
- + .ver = 0x01,
- + .len = 0x0a,
- + .CC02_CT47 = substream->runtime->channels - 1,
- + };
- +
- + hdmi_setup_channel_allocation(codec, nid, &ai);
- +
- + pin_nid = nvhdmi_pin_nids_89;
- + hdmi_setup_channel_mapping(codec, pin_nid, &ai);
- +
- + if (!hdmi_infoframe_uptodate(codec, pin_nid, &ai)) {
- + hdmi_stop_infoframe_trans(codec, pin_nid);
- + hdmi_fill_audio_infoframe(codec, pin_nid, &ai);
- + hdmi_start_infoframe_trans(codec, pin_nid);
- + }
- +}
- +
- +/*
- + * Callbacks
- + */
- +
- +static void hdmi_setup_stream(struct hda_codec *codec, hda_nid_t nid,
- + u32 stream_tag, int format)
- +{
- + int tag;
- + int fmt;
- +
- + tag = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_CONV, 0) >> 4;
- + fmt = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_STREAM_FORMAT, 0);
- +
- + snd_printdd("hdmi_setup_stream: "
- + "NID=0x%x, %sstream=0x%x, %sformat=0x%x\n",
- + nid,
- + tag == stream_tag ? "" : "new-",
- + stream_tag,
- + fmt == format ? "" : "new-",
- + format);
- + if (tag != stream_tag)
- + snd_hda_codec_write(codec, nid, 0,
- + AC_VERB_SET_CHANNEL_STREAMID, stream_tag << 4);
- + if (fmt != format)
- + snd_hda_codec_write(codec, nid, 0,
- + AC_VERB_SET_STREAM_FORMAT, format);
- +}
- +
- /*
- * Controls
- */
- @@ -96,7 +607,16 @@ static int nvhdmi_build_controls(struct hda_codec *codec)
- static int nvhdmi_init(struct hda_codec *codec)
- {
- - snd_hda_sequence_write(codec, nvhdmi_basic_init);
- + struct nvhdmi_spec *spec = codec->spec;
- + if ((spec->codec_type == HDA_CODEC_NVIDIA_MCP89)
- + || (spec->codec_type == HDA_CODEC_NVIDIA_GT21X))
- + {
- + snd_hda_sequence_write(codec, nvhdmi_basic_init_89);
- + }
- + else
- + {
- + snd_hda_sequence_write(codec, nvhdmi_basic_init_7x);
- + }
- return 0;
- }
- @@ -104,205 +624,169 @@ static int nvhdmi_init(struct hda_codec *codec)
- * Digital out
- */
- static int nvhdmi_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
- - struct hda_codec *codec,
- - struct snd_pcm_substream *substream)
- + struct hda_codec *codec,
- + struct snd_pcm_substream *substream)
- {
- struct nvhdmi_spec *spec = codec->spec;
- return snd_hda_multi_out_dig_open(codec, &spec->multiout);
- }
- -static int nvhdmi_dig_playback_pcm_close_8ch(struct hda_pcm_stream *hinfo,
- - struct hda_codec *codec,
- - struct snd_pcm_substream *substream)
- +static int nvhdmi_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
- + struct hda_codec *codec,
- + struct snd_pcm_substream *substream)
- {
- struct nvhdmi_spec *spec = codec->spec;
- int i;
- - snd_hda_codec_write(codec, Nv_Master_Convert_nid,
- - 0, AC_VERB_SET_CHANNEL_STREAMID, 0);
- - for (i = 0; i < 4; i++) {
- - /* set the stream id */
- - snd_hda_codec_write(codec, nvhdmi_convert_nids[i], 0,
- - AC_VERB_SET_CHANNEL_STREAMID, 0);
- - /* set the stream format */
- - snd_hda_codec_write(codec, nvhdmi_convert_nids[i], 0,
- - AC_VERB_SET_STREAM_FORMAT, 0);
- + if ((spec->codec_type == HDA_CODEC_NVIDIA_MCP89)
- + || (spec->codec_type == HDA_CODEC_NVIDIA_GT21X))
- + {
- + return 0;
- + }
- + else
- + {
- + mutex_lock(&codec->spdif_mutex);
- + (&spec->multiout)->dig_out_used = 0;
- +
- + snd_hda_codec_write(codec, Nv_Master_Convert_nid, 0, AC_VERB_SET_CHANNEL_STREAMID, 0);
- + for (i = 0; i < 4; i++)
- + {
- + /* set the stream id */
- + snd_hda_codec_write(codec, nvhdmi_convert_nids_7x[i], 0, AC_VERB_SET_CHANNEL_STREAMID, 0);
- + /* set the stream format */
- + snd_hda_codec_write(codec, nvhdmi_convert_nids_7x[i], 0, AC_VERB_SET_STREAM_FORMAT, 0);
- + }
- + mutex_unlock(&codec->spdif_mutex);
- + return 0;
- }
- -
- - return snd_hda_multi_out_dig_close(codec, &spec->multiout);
- }
- -static int nvhdmi_dig_playback_pcm_close_2ch(struct hda_pcm_stream *hinfo,
- - struct hda_codec *codec,
- - struct snd_pcm_substream *substream)
- +static int nvhdmi_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
- + struct hda_codec *codec,
- + unsigned int stream_tag,
- + unsigned int format,
- + struct snd_pcm_substream *substream)
- {
- struct nvhdmi_spec *spec = codec->spec;
- - return snd_hda_multi_out_dig_close(codec, &spec->multiout);
- -}
- -
- -static int nvhdmi_dig_playback_pcm_prepare_8ch(struct hda_pcm_stream *hinfo,
- - struct hda_codec *codec,
- - unsigned int stream_tag,
- - unsigned int format,
- - struct snd_pcm_substream *substream)
- -{
- int chs;
- unsigned int dataDCC1, dataDCC2, chan, chanmask, channel_id;
- int i;
- - mutex_lock(&codec->spdif_mutex);
- + if ((spec->codec_type == HDA_CODEC_NVIDIA_MCP89)
- + || (spec->codec_type == HDA_CODEC_NVIDIA_GT21X))
- + {
- + hdmi_set_channel_count(codec, hinfo->nid,
- + substream->runtime->channels);
- - chs = substream->runtime->channels;
- - chan = chs ? (chs - 1) : 1;
- + hdmi_setup_audio_infoframe(codec, hinfo->nid, substream);
- - switch (chs) {
- - default:
- - case 0:
- - case 2:
- - chanmask = 0x00;
- - break;
- - case 4:
- - chanmask = 0x08;
- - break;
- - case 6:
- - chanmask = 0x0b;
- - break;
- - case 8:
- - chanmask = 0x13;
- - break;
- + hdmi_setup_stream(codec, hinfo->nid, stream_tag, format);
- + return 0;
- }
- - dataDCC1 = AC_DIG1_ENABLE | AC_DIG1_COPYRIGHT;
- - dataDCC2 = 0x2;
- -
- - /* set the Audio InforFrame Channel Allocation */
- - snd_hda_codec_write(codec, 0x1, 0,
- - Nv_VERB_SET_Channel_Allocation, chanmask);
- -
- - /* turn off SPDIF once; otherwise the IEC958 bits won't be updated */
- - if (codec->spdif_status_reset && (codec->spdif_ctls & AC_DIG1_ENABLE))
- - snd_hda_codec_write(codec,
- - Nv_Master_Convert_nid,
- - 0,
- - AC_VERB_SET_DIGI_CONVERT_1,
- - codec->spdif_ctls & ~AC_DIG1_ENABLE & 0xff);
- + else
- + {
- + mutex_lock(&codec->spdif_mutex);
- +
- + chs = substream->runtime->channels;
- + chan = chs ? (chs - 1) : 1;
- +
- + switch (chs)
- + {
- + default:
- + case 0:
- + case 2:
- + chanmask = 0x00;
- + break;
- + case 4:
- + chanmask = 0x08;
- + break;
- + case 6:
- + chanmask = 0x0b;
- + break;
- + case 8:
- + chanmask = 0x13;
- + break;
- + }
- + dataDCC1 = AC_DIG1_ENABLE | AC_DIG1_COPYRIGHT;
- + dataDCC2 = 0x2;
- - /* set the stream id */
- - snd_hda_codec_write(codec, Nv_Master_Convert_nid, 0,
- - AC_VERB_SET_CHANNEL_STREAMID, (stream_tag << 4) | 0x0);
- -
- - /* set the stream format */
- - snd_hda_codec_write(codec, Nv_Master_Convert_nid, 0,
- - AC_VERB_SET_STREAM_FORMAT, format);
- -
- - /* turn on again (if needed) */
- - /* enable and set the channel status audio/data flag */
- - if (codec->spdif_status_reset && (codec->spdif_ctls & AC_DIG1_ENABLE)) {
- - snd_hda_codec_write(codec,
- - Nv_Master_Convert_nid,
- - 0,
- - AC_VERB_SET_DIGI_CONVERT_1,
- - codec->spdif_ctls & 0xff);
- - snd_hda_codec_write(codec,
- - Nv_Master_Convert_nid,
- - 0,
- - AC_VERB_SET_DIGI_CONVERT_2, dataDCC2);
- - }
- + /* set the Audio InforFrame Channel Allocation */
- + snd_hda_codec_write(codec, 0x1, 0, Nv_VERB_SET_Channel_Allocation, chanmask);
- - for (i = 0; i < 4; i++) {
- - if (chs == 2)
- - channel_id = 0;
- - else
- - channel_id = i * 2;
- -
- - /* turn off SPDIF once;
- - *otherwise the IEC958 bits won't be updated
- - */
- - if (codec->spdif_status_reset &&
- - (codec->spdif_ctls & AC_DIG1_ENABLE))
- - snd_hda_codec_write(codec,
- - nvhdmi_convert_nids[i],
- - 0,
- - AC_VERB_SET_DIGI_CONVERT_1,
- + if (codec->spdif_ctls & AC_DIG1_ENABLE)
- + snd_hda_codec_write(codec, Nv_Master_Convert_nid, 0, AC_VERB_SET_DIGI_CONVERT_1,
- codec->spdif_ctls & ~AC_DIG1_ENABLE & 0xff);
- +
- /* set the stream id */
- - snd_hda_codec_write(codec,
- - nvhdmi_convert_nids[i],
- - 0,
- - AC_VERB_SET_CHANNEL_STREAMID,
- - (stream_tag << 4) | channel_id);
- + snd_hda_codec_write(codec, Nv_Master_Convert_nid, 0, AC_VERB_SET_CHANNEL_STREAMID, (stream_tag << 4) | 0x0);
- /* set the stream format */
- - snd_hda_codec_write(codec,
- - nvhdmi_convert_nids[i],
- - 0,
- - AC_VERB_SET_STREAM_FORMAT,
- - format);
- - /* turn on again (if needed) */
- + snd_hda_codec_write(codec, Nv_Master_Convert_nid, 0, AC_VERB_SET_STREAM_FORMAT, format);
- /* enable and set the channel status audio/data flag */
- - if (codec->spdif_status_reset &&
- - (codec->spdif_ctls & AC_DIG1_ENABLE)) {
- - snd_hda_codec_write(codec,
- - nvhdmi_convert_nids[i],
- - 0,
- - AC_VERB_SET_DIGI_CONVERT_1,
- + if (codec->spdif_ctls & AC_DIG1_ENABLE)
- + snd_hda_codec_write(codec, Nv_Master_Convert_nid, 0, AC_VERB_SET_DIGI_CONVERT_1,
- + codec->spdif_ctls & 0xff);
- + /* enable and set the channel status audio/data flag */
- + snd_hda_codec_write(codec, Nv_Master_Convert_nid, 0, AC_VERB_SET_DIGI_CONVERT_2, dataDCC2);
- +
- + for (i = 0; i < 4; i++)
- + {
- + if (chs == 2)
- + channel_id = 0;
- + else
- + channel_id = i * 2;
- +
- + if (codec->spdif_ctls & AC_DIG1_ENABLE)
- + snd_hda_codec_write(codec, nvhdmi_convert_nids_7x[i], 0, AC_VERB_SET_DIGI_CONVERT_1,
- + codec->spdif_ctls & ~AC_DIG1_ENABLE & 0xff);
- + /* set the stream id */
- + snd_hda_codec_write(codec, nvhdmi_convert_nids_7x[i], 0, AC_VERB_SET_CHANNEL_STREAMID,
- + (stream_tag << 4) | channel_id);
- + /* set the stream format */
- + snd_hda_codec_write(codec, nvhdmi_convert_nids_7x[i], 0, AC_VERB_SET_STREAM_FORMAT, format);
- + /* enable and set the channel status audio/data flag */
- + if (codec->spdif_ctls & AC_DIG1_ENABLE)
- + snd_hda_codec_write(codec, nvhdmi_convert_nids_7x[i], 0, AC_VERB_SET_DIGI_CONVERT_1,
- codec->spdif_ctls & 0xff);
- - snd_hda_codec_write(codec,
- - nvhdmi_convert_nids[i],
- - 0,
- - AC_VERB_SET_DIGI_CONVERT_2, dataDCC2);
- + /* enable and set the channel status audio/data flag */
- + snd_hda_codec_write(codec, nvhdmi_convert_nids_7x[i], 0, AC_VERB_SET_DIGI_CONVERT_2, dataDCC2);
- }
- - }
- - /* set the Audio Info Frame Checksum */
- - snd_hda_codec_write(codec, 0x1, 0,
- - Nv_VERB_SET_Info_Frame_Checksum,
- - (0x71 - chan - chanmask));
- + /* set the Audio Info Frame Checksum */
- + snd_hda_codec_write(codec, 0x1, 0, Nv_VERB_SET_Info_Frame_Checksum, (0x71 - chan - chanmask));
- - mutex_unlock(&codec->spdif_mutex);
- - return 0;
- -}
- -
- -static int nvhdmi_dig_playback_pcm_prepare_2ch(struct hda_pcm_stream *hinfo,
- - struct hda_codec *codec,
- - unsigned int stream_tag,
- - unsigned int format,
- - struct snd_pcm_substream *substream)
- -{
- - struct nvhdmi_spec *spec = codec->spec;
- - return snd_hda_multi_out_dig_prepare(codec, &spec->multiout, stream_tag,
- - format, substream);
- + mutex_unlock(&codec->spdif_mutex);
- + return 0;
- + }
- }
- -static struct hda_pcm_stream nvhdmi_pcm_digital_playback_8ch = {
- +static struct hda_pcm_stream nvhdmi_pcm_digital_playback_89 = {
- .substreams = 1,
- .channels_min = 2,
- .channels_max = 8,
- - .nid = Nv_Master_Convert_nid,
- - .rates = SUPPORTED_RATES,
- - .maxbps = SUPPORTED_MAXBPS,
- - .formats = SUPPORTED_FORMATS,
- + .nid = nvhdmi_convert_nids_89,
- .ops = {
- .open = nvhdmi_dig_playback_pcm_open,
- - .close = nvhdmi_dig_playback_pcm_close_8ch,
- - .prepare = nvhdmi_dig_playback_pcm_prepare_8ch
- + .close = nvhdmi_dig_playback_pcm_close,
- + .prepare = nvhdmi_dig_playback_pcm_prepare
- },
- };
- -static struct hda_pcm_stream nvhdmi_pcm_digital_playback_2ch = {
- +static struct hda_pcm_stream nvhdmi_pcm_digital_playback = {
- .substreams = 1,
- .channels_min = 2,
- - .channels_max = 2,
- - .nid = Nv_Master_Convert_nid,
- - .rates = SUPPORTED_RATES,
- - .maxbps = SUPPORTED_MAXBPS,
- - .formats = SUPPORTED_FORMATS,
- + .channels_max = 8,
- + .nid = Nv_Master_Convert_nid, /* NID to query formats and rates and setup streams */
- +// .rates = SNDRV_PCM_RATE_48000,
- +// .maxbps = 16,
- +// .formats = SNDRV_PCM_FMTBIT_S16_LE,
- .ops = {
- .open = nvhdmi_dig_playback_pcm_open,
- - .close = nvhdmi_dig_playback_pcm_close_2ch,
- - .prepare = nvhdmi_dig_playback_pcm_prepare_2ch
- + .close = nvhdmi_dig_playback_pcm_close,
- + .prepare = nvhdmi_dig_playback_pcm_prepare
- },
- };
- -static int nvhdmi_build_pcms_8ch(struct hda_codec *codec)
- +static int nvhdmi_build_pcms(struct hda_codec *codec)
- {
- struct nvhdmi_spec *spec = codec->spec;
- struct hda_pcm *info = &spec->pcm_rec;
- @@ -312,24 +796,16 @@ static int nvhdmi_build_pcms_8ch(struct hda_codec *codec)
- info->name = "NVIDIA HDMI";
- info->pcm_type = HDA_PCM_TYPE_HDMI;
- - info->stream[SNDRV_PCM_STREAM_PLAYBACK]
- - = nvhdmi_pcm_digital_playback_8ch;
- - return 0;
- -}
- -
- -static int nvhdmi_build_pcms_2ch(struct hda_codec *codec)
- -{
- - struct nvhdmi_spec *spec = codec->spec;
- - struct hda_pcm *info = &spec->pcm_rec;
- -
- - codec->num_pcms = 1;
- - codec->pcm_info = info;
- -
- - info->name = "NVIDIA HDMI";
- - info->pcm_type = HDA_PCM_TYPE_HDMI;
- - info->stream[SNDRV_PCM_STREAM_PLAYBACK]
- - = nvhdmi_pcm_digital_playback_2ch;
- + if ((spec->codec_type == HDA_CODEC_NVIDIA_MCP89)
- + || (spec->codec_type == HDA_CODEC_NVIDIA_GT21X))
- + {
- + info->stream[SNDRV_PCM_STREAM_PLAYBACK] = nvhdmi_pcm_digital_playback_89;
- + }
- + else
- + {
- + info->stream[SNDRV_PCM_STREAM_PLAYBACK] = nvhdmi_pcm_digital_playback;
- + }
- return 0;
- }
- @@ -339,21 +815,14 @@ static void nvhdmi_free(struct hda_codec *codec)
- kfree(codec->spec);
- }
- -static struct hda_codec_ops nvhdmi_patch_ops_8ch = {
- +static struct hda_codec_ops nvhdmi_patch_ops = {
- .build_controls = nvhdmi_build_controls,
- - .build_pcms = nvhdmi_build_pcms_8ch,
- + .build_pcms = nvhdmi_build_pcms,
- .init = nvhdmi_init,
- .free = nvhdmi_free,
- };
- -static struct hda_codec_ops nvhdmi_patch_ops_2ch = {
- - .build_controls = nvhdmi_build_controls,
- - .build_pcms = nvhdmi_build_pcms_2ch,
- - .init = nvhdmi_init,
- - .free = nvhdmi_free,
- -};
- -
- -static int patch_nvhdmi_8ch(struct hda_codec *codec)
- +static int patch_nvhdmi(struct hda_codec *codec)
- {
- struct nvhdmi_spec *spec;
- @@ -367,26 +836,21 @@ static int patch_nvhdmi_8ch(struct hda_codec *codec)
- spec->multiout.max_channels = 8;
- spec->multiout.dig_out_nid = Nv_Master_Convert_nid;
- - codec->patch_ops = nvhdmi_patch_ops_8ch;
- -
- - return 0;
- -}
- -
- -static int patch_nvhdmi_2ch(struct hda_codec *codec)
- -{
- - struct nvhdmi_spec *spec;
- -
- - spec = kzalloc(sizeof(*spec), GFP_KERNEL);
- - if (spec == NULL)
- - return -ENOMEM;
- -
- - codec->spec = spec;
- -
- - spec->multiout.num_dacs = 0; /* no analog */
- - spec->multiout.max_channels = 2;
- - spec->multiout.dig_out_nid = Nv_Master_Convert_nid;
- + switch (codec->vendor_id) {
- + case 0x10de000c:
- + spec->codec_type = HDA_CODEC_NVIDIA_MCP89;
- + break;
- + case 0x10de000d:
- + case 0x10de000a:
- + case 0x10de000b:
- + spec->codec_type = HDA_CODEC_NVIDIA_GT21X;
- + break;
- + default:
- + spec->codec_type = HDA_CODEC_NVIDIA_MCP7X;
- + break;
- + }
- - codec->patch_ops = nvhdmi_patch_ops_2ch;
- + codec->patch_ops = nvhdmi_patch_ops;
- return 0;
- }
- @@ -394,41 +858,41 @@ static int patch_nvhdmi_2ch(struct hda_codec *codec)
- /*
- * patch entries
- */
- -static struct hda_codec_preset snd_hda_preset_nvhdmi[] = {
- - { .id = 0x10de0002, .name = "MCP78 HDMI", .patch = patch_nvhdmi_8ch },
- - { .id = 0x10de0003, .name = "MCP78 HDMI", .patch = patch_nvhdmi_8ch },
- - { .id = 0x10de0005, .name = "MCP78 HDMI", .patch = patch_nvhdmi_8ch },
- - { .id = 0x10de0006, .name = "MCP78 HDMI", .patch = patch_nvhdmi_8ch },
- - { .id = 0x10de0007, .name = "MCP7A HDMI", .patch = patch_nvhdmi_8ch },
- - { .id = 0x10de0067, .name = "MCP67 HDMI", .patch = patch_nvhdmi_2ch },
- - { .id = 0x10de8001, .name = "MCP73 HDMI", .patch = patch_nvhdmi_2ch },
- +struct hda_codec_preset snd_hda_preset_nvhdmi[] = {
- + { .id = 0x10de0002, .name = "NVIDIA MCP77/78 HDMI", .patch = patch_nvhdmi },
- + { .id = 0x10de0007, .name = "NVIDIA MCP79/7A HDMI", .patch = patch_nvhdmi },
- + { .id = 0x10de8001, .name = "NVIDIA MCP73 HDMI", .patch = patch_nvhdmi },
- + { .id = 0x10de000c, .name = "NVIDIA MCP89 HDMI", .patch = patch_nvhdmi },
- + { .id = 0x10de000d, .name = "NVIDIA GT240 HDMI", .patch = patch_nvhdmi },
- + { .id = 0x10de000a, .name = "NVIDIA GT220 HDMI", .patch = patch_nvhdmi },
- + { .id = 0x10de000b, .name = "NVIDIA G210 HDMI", .patch = patch_nvhdmi },
- {} /* terminator */
- };
- MODULE_ALIAS("snd-hda-codec-id:10de0002");
- -MODULE_ALIAS("snd-hda-codec-id:10de0003");
- -MODULE_ALIAS("snd-hda-codec-id:10de0005");
- -MODULE_ALIAS("snd-hda-codec-id:10de0006");
- MODULE_ALIAS("snd-hda-codec-id:10de0007");
- -MODULE_ALIAS("snd-hda-codec-id:10de0067");
- MODULE_ALIAS("snd-hda-codec-id:10de8001");
- +MODULE_ALIAS("snd-hda-codec-id:10de000c");
- +MODULE_ALIAS("snd-hda-codec-id:10de000d");
- +MODULE_ALIAS("snd-hda-codec-id:10de000a");
- +MODULE_ALIAS("snd-hda-codec-id:10de000b");
- MODULE_LICENSE("GPL");
- -MODULE_DESCRIPTION("Nvidia HDMI HD-audio codec");
- +MODULE_DESCRIPTION("NVIDIA HDMI HD-audio codec");
- static struct hda_codec_preset_list nvhdmi_list = {
- - .preset = snd_hda_preset_nvhdmi,
- - .owner = THIS_MODULE,
- + .preset = snd_hda_preset_nvhdmi,
- + .owner = THIS_MODULE,
- };
- static int __init patch_nvhdmi_init(void)
- {
- - return snd_hda_add_codec_preset(&nvhdmi_list);
- + return snd_hda_add_codec_preset(&nvhdmi_list);
- }
- static void __exit patch_nvhdmi_exit(void)
- {
- - snd_hda_delete_codec_preset(&nvhdmi_list);
- + snd_hda_delete_codec_preset(&nvhdmi_list);
- }
- module_init(patch_nvhdmi_init)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement