2019-05-29 08:17:59 -06:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
2015-11-10 06:12:06 -07:00
|
|
|
/*
|
|
|
|
* hdac_hdmi.c - ASoc HDA-HDMI codec driver for Intel platforms
|
|
|
|
*
|
|
|
|
* Copyright (C) 2014-2015 Intel Corp
|
|
|
|
* Author: Samreen Nilofer <samreen.nilofer@intel.com>
|
|
|
|
* Subhransu S. Prusty <subhransu.s.prusty@intel.com>
|
|
|
|
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
*
|
|
|
|
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
*/
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/delay.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/pm_runtime.h>
|
2015-11-10 06:12:09 -07:00
|
|
|
#include <linux/hdmi.h>
|
2016-02-11 19:16:02 -07:00
|
|
|
#include <drm/drm_edid.h>
|
2015-11-10 06:12:06 -07:00
|
|
|
#include <sound/pcm_params.h>
|
2016-02-11 19:16:06 -07:00
|
|
|
#include <sound/jack.h>
|
2015-11-10 06:12:06 -07:00
|
|
|
#include <sound/soc.h>
|
|
|
|
#include <sound/hdaudio_ext.h>
|
2015-11-10 06:12:10 -07:00
|
|
|
#include <sound/hda_i915.h>
|
2016-02-11 19:16:02 -07:00
|
|
|
#include <sound/pcm_drm_eld.h>
|
2016-04-13 22:37:30 -06:00
|
|
|
#include <sound/hda_chmap.h>
|
2015-11-10 06:12:06 -07:00
|
|
|
#include "../../hda/local.h"
|
2016-02-11 19:16:06 -07:00
|
|
|
#include "hdac_hdmi.h"
|
2015-11-10 06:12:06 -07:00
|
|
|
|
2016-02-11 19:16:04 -07:00
|
|
|
#define NAME_SIZE 32
|
|
|
|
|
2015-11-10 06:12:08 -07:00
|
|
|
#define AMP_OUT_MUTE 0xb080
|
|
|
|
#define AMP_OUT_UNMUTE 0xb000
|
2015-11-10 06:12:06 -07:00
|
|
|
#define PIN_OUT (AC_PINCTL_OUT_EN)
|
2015-11-10 06:12:08 -07:00
|
|
|
|
2015-11-10 06:12:06 -07:00
|
|
|
#define HDA_MAX_CONNECTIONS 32
|
|
|
|
|
2016-02-11 19:16:07 -07:00
|
|
|
#define HDA_MAX_CVTS 3
|
2017-02-05 23:39:14 -07:00
|
|
|
#define HDA_MAX_PORTS 3
|
2016-02-11 19:16:07 -07:00
|
|
|
|
2016-02-11 19:16:01 -07:00
|
|
|
#define ELD_MAX_SIZE 256
|
|
|
|
#define ELD_FIXED_BYTES 20
|
|
|
|
|
2017-01-18 09:04:41 -07:00
|
|
|
#define ELD_VER_CEA_861D 2
|
|
|
|
#define ELD_VER_PARTIAL 31
|
|
|
|
#define ELD_MAX_MNL 16
|
|
|
|
|
2015-11-10 06:12:06 -07:00
|
|
|
struct hdac_hdmi_cvt_params {
|
|
|
|
unsigned int channels_min;
|
|
|
|
unsigned int channels_max;
|
|
|
|
u32 rates;
|
|
|
|
u64 formats;
|
|
|
|
unsigned int maxbps;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct hdac_hdmi_cvt {
|
2015-12-09 09:16:10 -07:00
|
|
|
struct list_head head;
|
2015-11-10 06:12:06 -07:00
|
|
|
hda_nid_t nid;
|
2016-02-11 19:16:06 -07:00
|
|
|
const char *name;
|
2015-11-10 06:12:06 -07:00
|
|
|
struct hdac_hdmi_cvt_params params;
|
|
|
|
};
|
|
|
|
|
2016-04-13 22:37:28 -06:00
|
|
|
/* Currently only spk_alloc, more to be added */
|
|
|
|
struct hdac_hdmi_parsed_eld {
|
|
|
|
u8 spk_alloc;
|
|
|
|
};
|
|
|
|
|
2016-02-11 19:16:01 -07:00
|
|
|
struct hdac_hdmi_eld {
|
|
|
|
bool monitor_present;
|
|
|
|
bool eld_valid;
|
|
|
|
int eld_size;
|
|
|
|
char eld_buffer[ELD_MAX_SIZE];
|
2016-04-13 22:37:28 -06:00
|
|
|
struct hdac_hdmi_parsed_eld info;
|
2016-02-11 19:16:01 -07:00
|
|
|
};
|
|
|
|
|
2015-11-10 06:12:06 -07:00
|
|
|
struct hdac_hdmi_pin {
|
2015-12-09 09:16:10 -07:00
|
|
|
struct list_head head;
|
2015-11-10 06:12:06 -07:00
|
|
|
hda_nid_t nid;
|
2017-02-05 23:39:18 -07:00
|
|
|
bool mst_capable;
|
2017-02-05 23:39:14 -07:00
|
|
|
struct hdac_hdmi_port *ports;
|
|
|
|
int num_ports;
|
2018-06-01 21:53:49 -06:00
|
|
|
struct hdac_device *hdev;
|
2017-02-05 23:39:14 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
struct hdac_hdmi_port {
|
2017-02-07 06:39:48 -07:00
|
|
|
struct list_head head;
|
2017-02-05 23:39:14 -07:00
|
|
|
int id;
|
|
|
|
struct hdac_hdmi_pin *pin;
|
2015-11-10 06:12:06 -07:00
|
|
|
int num_mux_nids;
|
|
|
|
hda_nid_t mux_nids[HDA_MAX_CONNECTIONS];
|
2016-02-11 19:16:01 -07:00
|
|
|
struct hdac_hdmi_eld eld;
|
2017-02-07 06:39:55 -07:00
|
|
|
const char *jack_pin;
|
2019-08-09 09:15:31 -06:00
|
|
|
bool is_connect;
|
2017-02-07 06:39:55 -07:00
|
|
|
struct snd_soc_dapm_context *dapm;
|
|
|
|
const char *output_pin;
|
2019-08-09 09:15:31 -06:00
|
|
|
struct work_struct dapm_work;
|
2015-11-10 06:12:06 -07:00
|
|
|
};
|
|
|
|
|
2016-02-11 19:16:06 -07:00
|
|
|
struct hdac_hdmi_pcm {
|
|
|
|
struct list_head head;
|
|
|
|
int pcm_id;
|
2017-02-07 06:39:48 -07:00
|
|
|
struct list_head port_list;
|
2016-02-11 19:16:06 -07:00
|
|
|
struct hdac_hdmi_cvt *cvt;
|
2017-02-07 06:39:49 -07:00
|
|
|
struct snd_soc_jack *jack;
|
2017-01-24 09:19:03 -07:00
|
|
|
int stream_tag;
|
|
|
|
int channels;
|
|
|
|
int format;
|
2017-01-24 09:19:05 -07:00
|
|
|
bool chmap_set;
|
|
|
|
unsigned char chmap[8]; /* ALSA API channel-map */
|
|
|
|
struct mutex lock;
|
2017-02-07 06:39:48 -07:00
|
|
|
int jack_event;
|
2016-02-11 19:16:06 -07:00
|
|
|
};
|
|
|
|
|
2017-02-05 23:39:14 -07:00
|
|
|
struct hdac_hdmi_dai_port_map {
|
2015-11-10 06:12:06 -07:00
|
|
|
int dai_id;
|
2017-02-05 23:39:14 -07:00
|
|
|
struct hdac_hdmi_port *port;
|
2015-12-09 09:16:10 -07:00
|
|
|
struct hdac_hdmi_cvt *cvt;
|
2015-11-10 06:12:06 -07:00
|
|
|
};
|
|
|
|
|
2018-11-10 14:18:46 -07:00
|
|
|
/*
|
|
|
|
* pin to port mapping table where the value indicate the pin number and
|
|
|
|
* the index indicate the port number with 1 base.
|
|
|
|
*/
|
|
|
|
static const int icl_pin2port_map[] = {0x4, 0x6, 0x8, 0xa, 0xb};
|
|
|
|
|
2017-07-20 00:10:56 -06:00
|
|
|
struct hdac_hdmi_drv_data {
|
|
|
|
unsigned int vendor_nid;
|
2018-11-10 14:18:46 -07:00
|
|
|
const int *port_map; /* pin to port mapping table */
|
|
|
|
int port_num;
|
2017-07-20 00:10:56 -06:00
|
|
|
};
|
|
|
|
|
2015-11-10 06:12:06 -07:00
|
|
|
struct hdac_hdmi_priv {
|
2018-06-01 21:53:49 -06:00
|
|
|
struct hdac_device *hdev;
|
|
|
|
struct snd_soc_component *component;
|
|
|
|
struct snd_card *card;
|
2017-02-05 23:39:14 -07:00
|
|
|
struct hdac_hdmi_dai_port_map dai_map[HDA_MAX_CVTS];
|
2015-12-09 09:16:10 -07:00
|
|
|
struct list_head pin_list;
|
|
|
|
struct list_head cvt_list;
|
2016-02-11 19:16:06 -07:00
|
|
|
struct list_head pcm_list;
|
2015-12-09 09:16:10 -07:00
|
|
|
int num_pin;
|
|
|
|
int num_cvt;
|
2017-02-05 23:39:14 -07:00
|
|
|
int num_ports;
|
2016-02-11 19:16:06 -07:00
|
|
|
struct mutex pin_mutex;
|
2016-04-13 22:37:30 -06:00
|
|
|
struct hdac_chmap chmap;
|
2017-07-20 00:10:56 -06:00
|
|
|
struct hdac_hdmi_drv_data *drv_data;
|
2017-12-19 18:48:13 -07:00
|
|
|
struct snd_soc_dai_driver *dai_drv;
|
2015-11-10 06:12:06 -07:00
|
|
|
};
|
|
|
|
|
2018-06-01 21:53:49 -06:00
|
|
|
#define hdev_to_hdmi_priv(_hdev) dev_get_drvdata(&(_hdev)->dev)
|
2017-12-01 02:13:17 -07:00
|
|
|
|
2017-01-24 09:19:03 -07:00
|
|
|
static struct hdac_hdmi_pcm *
|
|
|
|
hdac_hdmi_get_pcm_from_cvt(struct hdac_hdmi_priv *hdmi,
|
|
|
|
struct hdac_hdmi_cvt *cvt)
|
|
|
|
{
|
|
|
|
struct hdac_hdmi_pcm *pcm = NULL;
|
|
|
|
|
|
|
|
list_for_each_entry(pcm, &hdmi->pcm_list, head) {
|
|
|
|
if (pcm->cvt == cvt)
|
|
|
|
break;
|
|
|
|
}
|
2017-01-10 05:27:48 -07:00
|
|
|
|
2017-01-24 09:19:03 -07:00
|
|
|
return pcm;
|
|
|
|
}
|
2017-01-10 05:27:48 -07:00
|
|
|
|
2017-02-07 06:39:48 -07:00
|
|
|
static void hdac_hdmi_jack_report(struct hdac_hdmi_pcm *pcm,
|
|
|
|
struct hdac_hdmi_port *port, bool is_connect)
|
|
|
|
{
|
2018-06-01 21:53:49 -06:00
|
|
|
struct hdac_device *hdev = port->pin->hdev;
|
2017-02-07 06:39:48 -07:00
|
|
|
|
2019-08-09 09:15:31 -06:00
|
|
|
port->is_connect = is_connect;
|
2017-02-07 06:39:48 -07:00
|
|
|
if (is_connect) {
|
|
|
|
/*
|
|
|
|
* Report Jack connect event when a device is connected
|
|
|
|
* for the first time where same PCM is attached to multiple
|
|
|
|
* ports.
|
|
|
|
*/
|
|
|
|
if (pcm->jack_event == 0) {
|
2018-06-01 21:53:49 -06:00
|
|
|
dev_dbg(&hdev->dev,
|
2017-02-07 06:39:48 -07:00
|
|
|
"jack report for pcm=%d\n",
|
|
|
|
pcm->pcm_id);
|
2017-02-07 06:39:49 -07:00
|
|
|
snd_soc_jack_report(pcm->jack, SND_JACK_AVOUT,
|
|
|
|
SND_JACK_AVOUT);
|
2017-02-07 06:39:48 -07:00
|
|
|
}
|
|
|
|
pcm->jack_event++;
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* Report Jack disconnect event when a device is disconnected
|
|
|
|
* is the only last connected device when same PCM is attached
|
|
|
|
* to multiple ports.
|
|
|
|
*/
|
|
|
|
if (pcm->jack_event == 1)
|
2017-02-07 06:39:49 -07:00
|
|
|
snd_soc_jack_report(pcm->jack, 0, SND_JACK_AVOUT);
|
2017-02-07 06:39:48 -07:00
|
|
|
if (pcm->jack_event > 0)
|
|
|
|
pcm->jack_event--;
|
|
|
|
}
|
2019-08-09 09:15:31 -06:00
|
|
|
}
|
2017-02-07 06:39:55 -07:00
|
|
|
|
2019-08-09 09:15:31 -06:00
|
|
|
static void hdac_hdmi_port_dapm_update(struct hdac_hdmi_port *port)
|
|
|
|
{
|
|
|
|
if (port->is_connect)
|
|
|
|
snd_soc_dapm_enable_pin(port->dapm, port->jack_pin);
|
|
|
|
else
|
|
|
|
snd_soc_dapm_disable_pin(port->dapm, port->jack_pin);
|
2017-02-07 06:39:55 -07:00
|
|
|
snd_soc_dapm_sync(port->dapm);
|
2017-02-07 06:39:48 -07:00
|
|
|
}
|
|
|
|
|
2019-08-09 09:15:31 -06:00
|
|
|
static void hdac_hdmi_jack_dapm_work(struct work_struct *work)
|
|
|
|
{
|
|
|
|
struct hdac_hdmi_port *port;
|
|
|
|
|
|
|
|
port = container_of(work, struct hdac_hdmi_port, dapm_work);
|
|
|
|
hdac_hdmi_port_dapm_update(port);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void hdac_hdmi_jack_report_sync(struct hdac_hdmi_pcm *pcm,
|
|
|
|
struct hdac_hdmi_port *port, bool is_connect)
|
|
|
|
{
|
|
|
|
hdac_hdmi_jack_report(pcm, port, is_connect);
|
|
|
|
hdac_hdmi_port_dapm_update(port);
|
|
|
|
}
|
|
|
|
|
2017-02-07 06:39:45 -07:00
|
|
|
/* MST supported verbs */
|
|
|
|
/*
|
|
|
|
* Get the no devices that can be connected to a port on the Pin widget.
|
|
|
|
*/
|
2018-06-01 21:53:49 -06:00
|
|
|
static int hdac_hdmi_get_port_len(struct hdac_device *hdev, hda_nid_t nid)
|
2017-02-07 06:39:45 -07:00
|
|
|
{
|
|
|
|
unsigned int caps;
|
|
|
|
unsigned int type, param;
|
|
|
|
|
2018-06-01 21:53:49 -06:00
|
|
|
caps = get_wcaps(hdev, nid);
|
2017-02-07 06:39:45 -07:00
|
|
|
type = get_wcaps_type(caps);
|
|
|
|
|
|
|
|
if (!(caps & AC_WCAP_DIGITAL) || (type != AC_WID_PIN))
|
|
|
|
return 0;
|
|
|
|
|
2018-06-01 21:53:49 -06:00
|
|
|
param = snd_hdac_read_parm_uncached(hdev, nid, AC_PAR_DEVLIST_LEN);
|
2017-02-07 06:39:45 -07:00
|
|
|
if (param == -1)
|
|
|
|
return param;
|
|
|
|
|
|
|
|
return param & AC_DEV_LIST_LEN_MASK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Get the port entry select on the pin. Return the port entry
|
|
|
|
* id selected on the pin. Return 0 means the first port entry
|
|
|
|
* is selected or MST is not supported.
|
|
|
|
*/
|
2018-06-01 21:53:49 -06:00
|
|
|
static int hdac_hdmi_port_select_get(struct hdac_device *hdev,
|
2017-02-07 06:39:45 -07:00
|
|
|
struct hdac_hdmi_port *port)
|
|
|
|
{
|
2018-06-01 21:53:49 -06:00
|
|
|
return snd_hdac_codec_read(hdev, port->pin->nid,
|
2017-02-07 06:39:45 -07:00
|
|
|
0, AC_VERB_GET_DEVICE_SEL, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Sets the selected port entry for the configuring Pin widget verb.
|
|
|
|
* returns error if port set is not equal to port get otherwise success
|
|
|
|
*/
|
2018-06-01 21:53:49 -06:00
|
|
|
static int hdac_hdmi_port_select_set(struct hdac_device *hdev,
|
2017-02-07 06:39:45 -07:00
|
|
|
struct hdac_hdmi_port *port)
|
|
|
|
{
|
|
|
|
int num_ports;
|
|
|
|
|
|
|
|
if (!port->pin->mst_capable)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* AC_PAR_DEVLIST_LEN is 0 based. */
|
2018-06-01 21:53:49 -06:00
|
|
|
num_ports = hdac_hdmi_get_port_len(hdev, port->pin->nid);
|
2017-02-07 06:39:45 -07:00
|
|
|
if (num_ports < 0)
|
|
|
|
return -EIO;
|
|
|
|
/*
|
|
|
|
* Device List Length is a 0 based integer value indicating the
|
|
|
|
* number of sink device that a MST Pin Widget can support.
|
|
|
|
*/
|
|
|
|
if (num_ports + 1 < port->id)
|
|
|
|
return 0;
|
|
|
|
|
2018-06-01 21:53:49 -06:00
|
|
|
snd_hdac_codec_write(hdev, port->pin->nid, 0,
|
2017-02-07 06:39:45 -07:00
|
|
|
AC_VERB_SET_DEVICE_SEL, port->id);
|
|
|
|
|
2018-06-01 21:53:49 -06:00
|
|
|
if (port->id != hdac_hdmi_port_select_get(hdev, port))
|
2017-02-07 06:39:45 -07:00
|
|
|
return -EIO;
|
|
|
|
|
2018-06-01 21:53:49 -06:00
|
|
|
dev_dbg(&hdev->dev, "Selected the port=%d\n", port->id);
|
2017-02-07 06:39:45 -07:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-04-13 22:37:34 -06:00
|
|
|
static struct hdac_hdmi_pcm *get_hdmi_pcm_from_id(struct hdac_hdmi_priv *hdmi,
|
|
|
|
int pcm_idx)
|
|
|
|
{
|
|
|
|
struct hdac_hdmi_pcm *pcm;
|
|
|
|
|
|
|
|
list_for_each_entry(pcm, &hdmi->pcm_list, head) {
|
|
|
|
if (pcm->pcm_id == pcm_idx)
|
|
|
|
return pcm;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2016-02-11 19:16:02 -07:00
|
|
|
static unsigned int sad_format(const u8 *sad)
|
|
|
|
{
|
|
|
|
return ((sad[0] >> 0x3) & 0x1f);
|
|
|
|
}
|
|
|
|
|
|
|
|
static unsigned int sad_sample_bits_lpcm(const u8 *sad)
|
|
|
|
{
|
|
|
|
return (sad[2] & 7);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int hdac_hdmi_eld_limit_formats(struct snd_pcm_runtime *runtime,
|
|
|
|
void *eld)
|
|
|
|
{
|
|
|
|
u64 formats = SNDRV_PCM_FMTBIT_S16;
|
|
|
|
int i;
|
|
|
|
const u8 *sad, *eld_buf = eld;
|
|
|
|
|
|
|
|
sad = drm_eld_sad(eld_buf);
|
|
|
|
if (!sad)
|
|
|
|
goto format_constraint;
|
|
|
|
|
|
|
|
for (i = drm_eld_sad_count(eld_buf); i > 0; i--, sad += 3) {
|
|
|
|
if (sad_format(sad) == 1) { /* AUDIO_CODING_TYPE_LPCM */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* the controller support 20 and 24 bits in 32 bit
|
|
|
|
* container so we set S32
|
|
|
|
*/
|
|
|
|
if (sad_sample_bits_lpcm(sad) & 0x6)
|
|
|
|
formats |= SNDRV_PCM_FMTBIT_S32;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
format_constraint:
|
|
|
|
return snd_pcm_hw_constraint_mask64(runtime, SNDRV_PCM_HW_PARAM_FORMAT,
|
|
|
|
formats);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-11-10 06:12:09 -07:00
|
|
|
static void
|
2018-06-01 21:53:49 -06:00
|
|
|
hdac_hdmi_set_dip_index(struct hdac_device *hdev, hda_nid_t pin_nid,
|
2015-11-10 06:12:09 -07:00
|
|
|
int packet_index, int byte_index)
|
|
|
|
{
|
|
|
|
int val;
|
|
|
|
|
|
|
|
val = (packet_index << 5) | (byte_index & 0x1f);
|
2018-06-01 21:53:49 -06:00
|
|
|
snd_hdac_codec_write(hdev, pin_nid, 0, AC_VERB_SET_HDMI_DIP_INDEX, val);
|
2015-11-10 06:12:09 -07:00
|
|
|
}
|
|
|
|
|
2016-02-11 19:16:09 -07:00
|
|
|
struct dp_audio_infoframe {
|
|
|
|
u8 type; /* 0x84 */
|
|
|
|
u8 len; /* 0x1b */
|
|
|
|
u8 ver; /* 0x11 << 2 */
|
|
|
|
|
|
|
|
u8 CC02_CT47; /* match with HDMI infoframe from this on */
|
|
|
|
u8 SS01_SF24;
|
|
|
|
u8 CXT04;
|
|
|
|
u8 CA;
|
|
|
|
u8 LFEPBL01_LSV36_DM_INH7;
|
|
|
|
};
|
|
|
|
|
2018-06-01 21:53:49 -06:00
|
|
|
static int hdac_hdmi_setup_audio_infoframe(struct hdac_device *hdev,
|
2017-02-05 23:39:14 -07:00
|
|
|
struct hdac_hdmi_pcm *pcm, struct hdac_hdmi_port *port)
|
2015-11-10 06:12:09 -07:00
|
|
|
{
|
|
|
|
uint8_t buffer[HDMI_INFOFRAME_HEADER_SIZE + HDMI_AUDIO_INFOFRAME_SIZE];
|
|
|
|
struct hdmi_audio_infoframe frame;
|
2017-02-05 23:39:14 -07:00
|
|
|
struct hdac_hdmi_pin *pin = port->pin;
|
2016-02-11 19:16:09 -07:00
|
|
|
struct dp_audio_infoframe dp_ai;
|
2018-06-01 21:53:49 -06:00
|
|
|
struct hdac_hdmi_priv *hdmi = hdev_to_hdmi_priv(hdev);
|
2017-01-24 09:19:05 -07:00
|
|
|
struct hdac_hdmi_cvt *cvt = pcm->cvt;
|
2016-02-11 19:16:09 -07:00
|
|
|
u8 *dip;
|
2015-11-10 06:12:09 -07:00
|
|
|
int ret;
|
|
|
|
int i;
|
2016-02-11 19:16:09 -07:00
|
|
|
const u8 *eld_buf;
|
|
|
|
u8 conn_type;
|
2016-04-13 22:37:30 -06:00
|
|
|
int channels, ca;
|
2015-11-10 06:12:09 -07:00
|
|
|
|
2018-06-01 21:53:49 -06:00
|
|
|
ca = snd_hdac_channel_allocation(hdev, port->eld.info.spk_alloc,
|
2017-01-24 09:19:05 -07:00
|
|
|
pcm->channels, pcm->chmap_set, true, pcm->chmap);
|
2016-04-13 22:37:30 -06:00
|
|
|
|
|
|
|
channels = snd_hdac_get_active_channels(ca);
|
2018-06-01 21:53:49 -06:00
|
|
|
hdmi->chmap.ops.set_channel_count(hdev, cvt->nid, channels);
|
2016-04-13 22:37:30 -06:00
|
|
|
|
|
|
|
snd_hdac_setup_channel_mapping(&hdmi->chmap, pin->nid, false, ca,
|
2017-01-24 09:19:05 -07:00
|
|
|
pcm->channels, pcm->chmap, pcm->chmap_set);
|
2016-04-13 22:37:30 -06:00
|
|
|
|
2017-02-05 23:39:14 -07:00
|
|
|
eld_buf = port->eld.eld_buffer;
|
2016-02-11 19:16:09 -07:00
|
|
|
conn_type = drm_eld_get_conn_type(eld_buf);
|
2015-11-10 06:12:09 -07:00
|
|
|
|
2016-02-11 19:16:09 -07:00
|
|
|
switch (conn_type) {
|
|
|
|
case DRM_ELD_CONN_TYPE_HDMI:
|
|
|
|
hdmi_audio_infoframe_init(&frame);
|
|
|
|
|
|
|
|
frame.channels = channels;
|
2016-04-13 22:37:30 -06:00
|
|
|
frame.channel_allocation = ca;
|
2016-02-11 19:16:09 -07:00
|
|
|
|
|
|
|
ret = hdmi_audio_infoframe_pack(&frame, buffer, sizeof(buffer));
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
2015-11-10 06:12:09 -07:00
|
|
|
|
2016-02-11 19:16:09 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
case DRM_ELD_CONN_TYPE_DP:
|
|
|
|
memset(&dp_ai, 0, sizeof(dp_ai));
|
|
|
|
dp_ai.type = 0x84;
|
|
|
|
dp_ai.len = 0x1b;
|
|
|
|
dp_ai.ver = 0x11 << 2;
|
|
|
|
dp_ai.CC02_CT47 = channels - 1;
|
2016-04-13 22:37:30 -06:00
|
|
|
dp_ai.CA = ca;
|
2016-02-11 19:16:09 -07:00
|
|
|
|
|
|
|
dip = (u8 *)&dp_ai;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2018-06-01 21:53:49 -06:00
|
|
|
dev_err(&hdev->dev, "Invalid connection type: %d\n", conn_type);
|
2016-02-11 19:16:09 -07:00
|
|
|
return -EIO;
|
|
|
|
}
|
2015-11-10 06:12:09 -07:00
|
|
|
|
|
|
|
/* stop infoframe transmission */
|
2018-06-01 21:53:49 -06:00
|
|
|
hdac_hdmi_set_dip_index(hdev, pin->nid, 0x0, 0x0);
|
|
|
|
snd_hdac_codec_write(hdev, pin->nid, 0,
|
2015-11-10 06:12:09 -07:00
|
|
|
AC_VERB_SET_HDMI_DIP_XMIT, AC_DIPXMIT_DISABLE);
|
|
|
|
|
|
|
|
|
|
|
|
/* Fill infoframe. Index auto-incremented */
|
2018-06-01 21:53:49 -06:00
|
|
|
hdac_hdmi_set_dip_index(hdev, pin->nid, 0x0, 0x0);
|
2016-02-11 19:16:09 -07:00
|
|
|
if (conn_type == DRM_ELD_CONN_TYPE_HDMI) {
|
2016-03-09 20:34:07 -07:00
|
|
|
for (i = 0; i < sizeof(buffer); i++)
|
2018-06-01 21:53:49 -06:00
|
|
|
snd_hdac_codec_write(hdev, pin->nid, 0,
|
2016-03-09 20:34:07 -07:00
|
|
|
AC_VERB_SET_HDMI_DIP_DATA, buffer[i]);
|
2016-02-11 19:16:09 -07:00
|
|
|
} else {
|
|
|
|
for (i = 0; i < sizeof(dp_ai); i++)
|
2018-06-01 21:53:49 -06:00
|
|
|
snd_hdac_codec_write(hdev, pin->nid, 0,
|
2015-11-10 06:12:09 -07:00
|
|
|
AC_VERB_SET_HDMI_DIP_DATA, dip[i]);
|
2016-02-11 19:16:09 -07:00
|
|
|
}
|
2015-11-10 06:12:09 -07:00
|
|
|
|
|
|
|
/* Start infoframe */
|
2018-06-01 21:53:49 -06:00
|
|
|
hdac_hdmi_set_dip_index(hdev, pin->nid, 0x0, 0x0);
|
|
|
|
snd_hdac_codec_write(hdev, pin->nid, 0,
|
2015-11-10 06:12:09 -07:00
|
|
|
AC_VERB_SET_HDMI_DIP_XMIT, AC_DIPXMIT_BEST);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-01-24 09:19:03 -07:00
|
|
|
static int hdac_hdmi_set_tdm_slot(struct snd_soc_dai *dai,
|
|
|
|
unsigned int tx_mask, unsigned int rx_mask,
|
|
|
|
int slots, int slot_width)
|
2015-11-10 06:12:08 -07:00
|
|
|
{
|
2018-06-01 21:53:49 -06:00
|
|
|
struct hdac_hdmi_priv *hdmi = snd_soc_dai_get_drvdata(dai);
|
|
|
|
struct hdac_device *hdev = hdmi->hdev;
|
2017-02-05 23:39:14 -07:00
|
|
|
struct hdac_hdmi_dai_port_map *dai_map;
|
2017-01-24 09:19:03 -07:00
|
|
|
struct hdac_hdmi_pcm *pcm;
|
2015-11-10 06:12:08 -07:00
|
|
|
|
2018-06-01 21:53:49 -06:00
|
|
|
dev_dbg(&hdev->dev, "%s: strm_tag: %d\n", __func__, tx_mask);
|
2015-11-10 06:12:08 -07:00
|
|
|
|
2017-01-24 09:19:03 -07:00
|
|
|
dai_map = &hdmi->dai_map[dai->id];
|
2015-11-10 06:12:08 -07:00
|
|
|
|
2017-01-24 09:19:03 -07:00
|
|
|
pcm = hdac_hdmi_get_pcm_from_cvt(hdmi, dai_map->cvt);
|
2016-04-13 22:37:30 -06:00
|
|
|
|
2017-01-24 09:19:03 -07:00
|
|
|
if (pcm)
|
|
|
|
pcm->stream_tag = (tx_mask << 4);
|
2015-11-10 06:12:09 -07:00
|
|
|
|
2017-01-24 09:19:03 -07:00
|
|
|
return 0;
|
2015-11-10 06:12:08 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static int hdac_hdmi_set_hw_params(struct snd_pcm_substream *substream,
|
|
|
|
struct snd_pcm_hw_params *hparams, struct snd_soc_dai *dai)
|
|
|
|
{
|
2018-06-01 21:53:49 -06:00
|
|
|
struct hdac_hdmi_priv *hdmi = snd_soc_dai_get_drvdata(dai);
|
2017-02-05 23:39:14 -07:00
|
|
|
struct hdac_hdmi_dai_port_map *dai_map;
|
2017-01-24 09:19:03 -07:00
|
|
|
struct hdac_hdmi_pcm *pcm;
|
|
|
|
int format;
|
2015-11-10 06:12:08 -07:00
|
|
|
|
2016-02-17 09:04:00 -07:00
|
|
|
dai_map = &hdmi->dai_map[dai->id];
|
2015-11-10 06:12:08 -07:00
|
|
|
|
2017-01-24 09:19:03 -07:00
|
|
|
format = snd_hdac_calc_stream_format(params_rate(hparams),
|
2015-11-10 06:12:08 -07:00
|
|
|
params_channels(hparams), params_format(hparams),
|
2017-03-24 11:40:26 -06:00
|
|
|
dai->driver->playback.sig_bits, 0);
|
2015-11-10 06:12:08 -07:00
|
|
|
|
2017-01-24 09:19:03 -07:00
|
|
|
pcm = hdac_hdmi_get_pcm_from_cvt(hdmi, dai_map->cvt);
|
|
|
|
if (!pcm)
|
2016-02-11 19:16:07 -07:00
|
|
|
return -EIO;
|
|
|
|
|
2017-01-24 09:19:03 -07:00
|
|
|
pcm->format = format;
|
|
|
|
pcm->channels = params_channels(hparams);
|
2016-02-11 19:16:07 -07:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-06-01 21:53:49 -06:00
|
|
|
static int hdac_hdmi_query_port_connlist(struct hdac_device *hdev,
|
2017-02-05 23:39:14 -07:00
|
|
|
struct hdac_hdmi_pin *pin,
|
|
|
|
struct hdac_hdmi_port *port)
|
2016-02-11 19:16:07 -07:00
|
|
|
{
|
2018-06-01 21:53:49 -06:00
|
|
|
if (!(get_wcaps(hdev, pin->nid) & AC_WCAP_CONN_LIST)) {
|
|
|
|
dev_warn(&hdev->dev,
|
2016-02-11 19:16:07 -07:00
|
|
|
"HDMI: pin %d wcaps %#x does not support connection list\n",
|
2018-06-01 21:53:49 -06:00
|
|
|
pin->nid, get_wcaps(hdev, pin->nid));
|
2016-02-11 19:16:07 -07:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2018-06-01 21:53:49 -06:00
|
|
|
if (hdac_hdmi_port_select_set(hdev, port) < 0)
|
2017-02-07 06:39:47 -07:00
|
|
|
return -EIO;
|
|
|
|
|
2018-06-01 21:53:49 -06:00
|
|
|
port->num_mux_nids = snd_hdac_get_connections(hdev, pin->nid,
|
2017-02-05 23:39:14 -07:00
|
|
|
port->mux_nids, HDA_MAX_CONNECTIONS);
|
|
|
|
if (port->num_mux_nids == 0)
|
2018-06-01 21:53:49 -06:00
|
|
|
dev_warn(&hdev->dev,
|
2017-02-05 23:39:14 -07:00
|
|
|
"No connections found for pin:port %d:%d\n",
|
|
|
|
pin->nid, port->id);
|
2016-02-11 19:16:07 -07:00
|
|
|
|
2018-06-01 21:53:49 -06:00
|
|
|
dev_dbg(&hdev->dev, "num_mux_nids %d for pin:port %d:%d\n",
|
2017-02-05 23:39:14 -07:00
|
|
|
port->num_mux_nids, pin->nid, port->id);
|
2016-02-11 19:16:07 -07:00
|
|
|
|
2017-02-05 23:39:14 -07:00
|
|
|
return port->num_mux_nids;
|
2016-02-11 19:16:07 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2017-02-05 23:39:14 -07:00
|
|
|
* Query pcm list and return port to which stream is routed.
|
2016-02-11 19:16:07 -07:00
|
|
|
*
|
2017-02-05 23:39:14 -07:00
|
|
|
* Also query connection list of the pin, to validate the cvt to port map.
|
2016-02-11 19:16:07 -07:00
|
|
|
*
|
2017-02-05 23:39:14 -07:00
|
|
|
* Same stream rendering to multiple ports simultaneously can be done
|
|
|
|
* possibly, but not supported for now in driver. So return the first port
|
2016-02-11 19:16:07 -07:00
|
|
|
* connected.
|
|
|
|
*/
|
2017-02-05 23:39:14 -07:00
|
|
|
static struct hdac_hdmi_port *hdac_hdmi_get_port_from_cvt(
|
2018-06-01 21:53:49 -06:00
|
|
|
struct hdac_device *hdev,
|
2016-02-11 19:16:07 -07:00
|
|
|
struct hdac_hdmi_priv *hdmi,
|
|
|
|
struct hdac_hdmi_cvt *cvt)
|
|
|
|
{
|
|
|
|
struct hdac_hdmi_pcm *pcm;
|
2017-02-05 23:39:14 -07:00
|
|
|
struct hdac_hdmi_port *port = NULL;
|
2016-02-11 19:16:07 -07:00
|
|
|
int ret, i;
|
|
|
|
|
|
|
|
list_for_each_entry(pcm, &hdmi->pcm_list, head) {
|
|
|
|
if (pcm->cvt == cvt) {
|
2017-02-07 06:39:48 -07:00
|
|
|
if (list_empty(&pcm->port_list))
|
|
|
|
continue;
|
2016-02-11 19:16:07 -07:00
|
|
|
|
2017-02-07 06:39:48 -07:00
|
|
|
list_for_each_entry(port, &pcm->port_list, head) {
|
|
|
|
mutex_lock(&pcm->lock);
|
2018-06-01 21:53:49 -06:00
|
|
|
ret = hdac_hdmi_query_port_connlist(hdev,
|
2017-02-07 06:39:48 -07:00
|
|
|
port->pin, port);
|
|
|
|
mutex_unlock(&pcm->lock);
|
|
|
|
if (ret < 0)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
for (i = 0; i < port->num_mux_nids; i++) {
|
|
|
|
if (port->mux_nids[i] == cvt->nid &&
|
|
|
|
port->eld.monitor_present &&
|
|
|
|
port->eld.eld_valid)
|
|
|
|
return port;
|
|
|
|
}
|
|
|
|
}
|
2016-02-11 19:16:07 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2019-06-13 05:54:12 -06:00
|
|
|
/*
|
|
|
|
* Go through all converters and ensure connection is set to
|
|
|
|
* the correct pin as set via kcontrols.
|
|
|
|
*/
|
|
|
|
static void hdac_hdmi_verify_connect_sel_all_pins(struct hdac_device *hdev)
|
|
|
|
{
|
|
|
|
struct hdac_hdmi_priv *hdmi = hdev_to_hdmi_priv(hdev);
|
|
|
|
struct hdac_hdmi_port *port;
|
|
|
|
struct hdac_hdmi_cvt *cvt;
|
|
|
|
int cvt_idx = 0;
|
|
|
|
|
|
|
|
list_for_each_entry(cvt, &hdmi->cvt_list, head) {
|
|
|
|
port = hdac_hdmi_get_port_from_cvt(hdev, hdmi, cvt);
|
|
|
|
if (port && port->pin) {
|
|
|
|
snd_hdac_codec_write(hdev, port->pin->nid, 0,
|
|
|
|
AC_VERB_SET_CONNECT_SEL, cvt_idx);
|
|
|
|
dev_dbg(&hdev->dev, "%s: %s set connect %d -> %d\n",
|
|
|
|
__func__, cvt->name, port->pin->nid, cvt_idx);
|
|
|
|
}
|
|
|
|
++cvt_idx;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-02-17 09:04:00 -07:00
|
|
|
/*
|
|
|
|
* This tries to get a valid pin and set the HW constraints based on the
|
|
|
|
* ELD. Even if a valid pin is not found return success so that device open
|
|
|
|
* doesn't fail.
|
|
|
|
*/
|
2015-11-10 06:12:08 -07:00
|
|
|
static int hdac_hdmi_pcm_open(struct snd_pcm_substream *substream,
|
|
|
|
struct snd_soc_dai *dai)
|
|
|
|
{
|
2018-06-01 21:53:49 -06:00
|
|
|
struct hdac_hdmi_priv *hdmi = snd_soc_dai_get_drvdata(dai);
|
|
|
|
struct hdac_device *hdev = hdmi->hdev;
|
2017-02-05 23:39:14 -07:00
|
|
|
struct hdac_hdmi_dai_port_map *dai_map;
|
2016-02-11 19:16:07 -07:00
|
|
|
struct hdac_hdmi_cvt *cvt;
|
2017-02-05 23:39:14 -07:00
|
|
|
struct hdac_hdmi_port *port;
|
2016-02-11 19:16:02 -07:00
|
|
|
int ret;
|
2015-11-10 06:12:08 -07:00
|
|
|
|
|
|
|
dai_map = &hdmi->dai_map[dai->id];
|
|
|
|
|
2016-02-11 19:16:07 -07:00
|
|
|
cvt = dai_map->cvt;
|
2018-06-01 21:53:49 -06:00
|
|
|
port = hdac_hdmi_get_port_from_cvt(hdev, hdmi, cvt);
|
2016-02-17 09:04:00 -07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* To make PA and other userland happy.
|
|
|
|
* userland scans devices so returning error does not help.
|
|
|
|
*/
|
2017-02-05 23:39:14 -07:00
|
|
|
if (!port)
|
2016-02-17 09:04:00 -07:00
|
|
|
return 0;
|
2017-02-05 23:39:14 -07:00
|
|
|
if ((!port->eld.monitor_present) ||
|
|
|
|
(!port->eld.eld_valid)) {
|
2016-02-11 19:16:01 -07:00
|
|
|
|
2018-06-01 21:53:49 -06:00
|
|
|
dev_warn(&hdev->dev,
|
2017-02-05 23:39:14 -07:00
|
|
|
"Failed: present?:%d ELD valid?:%d pin:port: %d:%d\n",
|
|
|
|
port->eld.monitor_present, port->eld.eld_valid,
|
|
|
|
port->pin->nid, port->id);
|
2015-11-10 06:12:08 -07:00
|
|
|
|
2016-02-17 09:04:00 -07:00
|
|
|
return 0;
|
2015-11-10 06:12:08 -07:00
|
|
|
}
|
|
|
|
|
2017-02-05 23:39:14 -07:00
|
|
|
dai_map->port = port;
|
2015-11-10 06:12:08 -07:00
|
|
|
|
2016-02-11 19:16:02 -07:00
|
|
|
ret = hdac_hdmi_eld_limit_formats(substream->runtime,
|
2017-02-05 23:39:14 -07:00
|
|
|
port->eld.eld_buffer);
|
2016-02-11 19:16:02 -07:00
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
2015-11-10 06:12:08 -07:00
|
|
|
|
2016-02-11 19:16:02 -07:00
|
|
|
return snd_pcm_hw_constraint_eld(substream->runtime,
|
2017-02-05 23:39:14 -07:00
|
|
|
port->eld.eld_buffer);
|
2015-11-10 06:12:08 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void hdac_hdmi_pcm_close(struct snd_pcm_substream *substream,
|
|
|
|
struct snd_soc_dai *dai)
|
|
|
|
{
|
2018-06-01 21:53:49 -06:00
|
|
|
struct hdac_hdmi_priv *hdmi = snd_soc_dai_get_drvdata(dai);
|
2017-02-05 23:39:14 -07:00
|
|
|
struct hdac_hdmi_dai_port_map *dai_map;
|
2017-01-24 09:19:05 -07:00
|
|
|
struct hdac_hdmi_pcm *pcm;
|
2015-11-10 06:12:08 -07:00
|
|
|
|
|
|
|
dai_map = &hdmi->dai_map[dai->id];
|
|
|
|
|
2017-01-24 09:19:05 -07:00
|
|
|
pcm = hdac_hdmi_get_pcm_from_cvt(hdmi, dai_map->cvt);
|
2016-04-13 22:37:30 -06:00
|
|
|
|
2017-01-24 09:19:05 -07:00
|
|
|
if (pcm) {
|
|
|
|
mutex_lock(&pcm->lock);
|
|
|
|
pcm->chmap_set = false;
|
|
|
|
memset(pcm->chmap, 0, sizeof(pcm->chmap));
|
|
|
|
pcm->channels = 0;
|
|
|
|
mutex_unlock(&pcm->lock);
|
2016-02-17 09:04:00 -07:00
|
|
|
}
|
2017-01-24 09:19:05 -07:00
|
|
|
|
2017-02-05 23:39:14 -07:00
|
|
|
if (dai_map->port)
|
|
|
|
dai_map->port = NULL;
|
2015-11-10 06:12:08 -07:00
|
|
|
}
|
|
|
|
|
2015-11-10 06:12:06 -07:00
|
|
|
static int
|
2017-12-01 02:13:19 -07:00
|
|
|
hdac_hdmi_query_cvt_params(struct hdac_device *hdev, struct hdac_hdmi_cvt *cvt)
|
2015-11-10 06:12:06 -07:00
|
|
|
{
|
2016-04-13 22:37:30 -06:00
|
|
|
unsigned int chans;
|
2017-12-01 02:13:19 -07:00
|
|
|
struct hdac_hdmi_priv *hdmi = hdev_to_hdmi_priv(hdev);
|
2015-11-10 06:12:06 -07:00
|
|
|
int err;
|
|
|
|
|
2017-12-01 02:13:19 -07:00
|
|
|
chans = get_wcaps(hdev, cvt->nid);
|
2016-04-13 22:37:30 -06:00
|
|
|
chans = get_wcaps_channels(chans);
|
|
|
|
|
|
|
|
cvt->params.channels_min = 2;
|
|
|
|
|
|
|
|
cvt->params.channels_max = chans;
|
|
|
|
if (chans > hdmi->chmap.channels_max)
|
|
|
|
hdmi->chmap.channels_max = chans;
|
2015-11-10 06:12:06 -07:00
|
|
|
|
2017-12-01 02:13:19 -07:00
|
|
|
err = snd_hdac_query_supported_pcm(hdev, cvt->nid,
|
2015-11-10 06:12:06 -07:00
|
|
|
&cvt->params.rates,
|
|
|
|
&cvt->params.formats,
|
|
|
|
&cvt->params.maxbps);
|
|
|
|
if (err < 0)
|
2017-12-01 02:13:19 -07:00
|
|
|
dev_err(&hdev->dev,
|
2015-11-10 06:12:06 -07:00
|
|
|
"Failed to query pcm params for nid %d: %d\n",
|
|
|
|
cvt->nid, err);
|
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2016-02-11 19:16:05 -07:00
|
|
|
static int hdac_hdmi_fill_widget_info(struct device *dev,
|
2017-01-24 09:19:03 -07:00
|
|
|
struct snd_soc_dapm_widget *w, enum snd_soc_dapm_type id,
|
|
|
|
void *priv, const char *wname, const char *stream,
|
|
|
|
struct snd_kcontrol_new *wc, int numkc,
|
|
|
|
int (*event)(struct snd_soc_dapm_widget *,
|
|
|
|
struct snd_kcontrol *, int), unsigned short event_flags)
|
2015-11-10 06:12:06 -07:00
|
|
|
{
|
|
|
|
w->id = id;
|
2016-02-11 19:16:05 -07:00
|
|
|
w->name = devm_kstrdup(dev, wname, GFP_KERNEL);
|
|
|
|
if (!w->name)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
2015-11-10 06:12:06 -07:00
|
|
|
w->sname = stream;
|
|
|
|
w->reg = SND_SOC_NOPM;
|
|
|
|
w->shift = 0;
|
2016-02-11 19:16:05 -07:00
|
|
|
w->kcontrol_news = wc;
|
|
|
|
w->num_kcontrols = numkc;
|
|
|
|
w->priv = priv;
|
2017-01-24 09:19:03 -07:00
|
|
|
w->event = event;
|
|
|
|
w->event_flags = event_flags;
|
2016-02-11 19:16:05 -07:00
|
|
|
|
|
|
|
return 0;
|
2015-11-10 06:12:06 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void hdac_hdmi_fill_route(struct snd_soc_dapm_route *route,
|
2016-02-11 19:16:05 -07:00
|
|
|
const char *sink, const char *control, const char *src,
|
|
|
|
int (*handler)(struct snd_soc_dapm_widget *src,
|
|
|
|
struct snd_soc_dapm_widget *sink))
|
2015-11-10 06:12:06 -07:00
|
|
|
{
|
|
|
|
route->sink = sink;
|
|
|
|
route->source = src;
|
|
|
|
route->control = control;
|
2016-02-11 19:16:05 -07:00
|
|
|
route->connected = handler;
|
2015-11-10 06:12:06 -07:00
|
|
|
}
|
|
|
|
|
2018-06-01 21:53:49 -06:00
|
|
|
static struct hdac_hdmi_pcm *hdac_hdmi_get_pcm(struct hdac_device *hdev,
|
2017-02-05 23:39:14 -07:00
|
|
|
struct hdac_hdmi_port *port)
|
2016-02-11 19:16:06 -07:00
|
|
|
{
|
2018-06-01 21:53:49 -06:00
|
|
|
struct hdac_hdmi_priv *hdmi = hdev_to_hdmi_priv(hdev);
|
2016-02-11 19:16:06 -07:00
|
|
|
struct hdac_hdmi_pcm *pcm = NULL;
|
2017-02-07 06:39:48 -07:00
|
|
|
struct hdac_hdmi_port *p;
|
2016-02-11 19:16:06 -07:00
|
|
|
|
|
|
|
list_for_each_entry(pcm, &hdmi->pcm_list, head) {
|
2017-02-07 06:39:48 -07:00
|
|
|
if (list_empty(&pcm->port_list))
|
2017-02-05 23:39:14 -07:00
|
|
|
continue;
|
|
|
|
|
2017-02-07 06:39:48 -07:00
|
|
|
list_for_each_entry(p, &pcm->port_list, head) {
|
|
|
|
if (p->id == port->id && port->pin == p->pin)
|
|
|
|
return pcm;
|
|
|
|
}
|
2016-02-11 19:16:06 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2018-06-01 21:53:49 -06:00
|
|
|
static void hdac_hdmi_set_power_state(struct hdac_device *hdev,
|
2017-01-24 09:19:03 -07:00
|
|
|
hda_nid_t nid, unsigned int pwr_state)
|
|
|
|
{
|
2018-02-15 01:35:38 -07:00
|
|
|
int count;
|
|
|
|
unsigned int state;
|
|
|
|
|
2018-06-01 21:53:49 -06:00
|
|
|
if (get_wcaps(hdev, nid) & AC_WCAP_POWER) {
|
|
|
|
if (!snd_hdac_check_power_state(hdev, nid, pwr_state)) {
|
2018-02-15 01:35:38 -07:00
|
|
|
for (count = 0; count < 10; count++) {
|
2018-06-01 21:53:49 -06:00
|
|
|
snd_hdac_codec_read(hdev, nid, 0,
|
2018-02-15 01:35:38 -07:00
|
|
|
AC_VERB_SET_POWER_STATE,
|
|
|
|
pwr_state);
|
2018-06-01 21:53:49 -06:00
|
|
|
state = snd_hdac_sync_power_state(hdev,
|
2018-02-15 01:35:38 -07:00
|
|
|
nid, pwr_state);
|
|
|
|
if (!(state & AC_PWRST_ERROR))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2017-01-24 09:19:03 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-01 21:53:49 -06:00
|
|
|
static void hdac_hdmi_set_amp(struct hdac_device *hdev,
|
2017-01-24 09:19:03 -07:00
|
|
|
hda_nid_t nid, int val)
|
|
|
|
{
|
2018-06-01 21:53:49 -06:00
|
|
|
if (get_wcaps(hdev, nid) & AC_WCAP_OUT_AMP)
|
|
|
|
snd_hdac_codec_write(hdev, nid, 0,
|
2017-01-24 09:19:03 -07:00
|
|
|
AC_VERB_SET_AMP_GAIN_MUTE, val);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int hdac_hdmi_pin_output_widget_event(struct snd_soc_dapm_widget *w,
|
|
|
|
struct snd_kcontrol *kc, int event)
|
|
|
|
{
|
2017-02-05 23:39:14 -07:00
|
|
|
struct hdac_hdmi_port *port = w->priv;
|
2018-06-01 21:53:49 -06:00
|
|
|
struct hdac_device *hdev = dev_to_hdac_dev(w->dapm->dev);
|
2017-01-24 09:19:03 -07:00
|
|
|
struct hdac_hdmi_pcm *pcm;
|
|
|
|
|
2018-06-01 21:53:49 -06:00
|
|
|
dev_dbg(&hdev->dev, "%s: widget: %s event: %x\n",
|
2017-01-24 09:19:03 -07:00
|
|
|
__func__, w->name, event);
|
|
|
|
|
2018-06-01 21:53:49 -06:00
|
|
|
pcm = hdac_hdmi_get_pcm(hdev, port);
|
2017-01-24 09:19:03 -07:00
|
|
|
if (!pcm)
|
|
|
|
return -EIO;
|
|
|
|
|
2017-02-07 06:39:47 -07:00
|
|
|
/* set the device if pin is mst_capable */
|
2018-06-01 21:53:49 -06:00
|
|
|
if (hdac_hdmi_port_select_set(hdev, port) < 0)
|
2017-02-07 06:39:47 -07:00
|
|
|
return -EIO;
|
|
|
|
|
2017-01-24 09:19:03 -07:00
|
|
|
switch (event) {
|
|
|
|
case SND_SOC_DAPM_PRE_PMU:
|
2018-06-01 21:53:49 -06:00
|
|
|
hdac_hdmi_set_power_state(hdev, port->pin->nid, AC_PWRST_D0);
|
2017-01-24 09:19:03 -07:00
|
|
|
|
|
|
|
/* Enable out path for this pin widget */
|
2018-06-01 21:53:49 -06:00
|
|
|
snd_hdac_codec_write(hdev, port->pin->nid, 0,
|
2017-01-24 09:19:03 -07:00
|
|
|
AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
|
|
|
|
|
2018-06-01 21:53:49 -06:00
|
|
|
hdac_hdmi_set_amp(hdev, port->pin->nid, AMP_OUT_UNMUTE);
|
2017-01-24 09:19:03 -07:00
|
|
|
|
2018-06-01 21:53:49 -06:00
|
|
|
return hdac_hdmi_setup_audio_infoframe(hdev, pcm, port);
|
2017-01-24 09:19:03 -07:00
|
|
|
|
|
|
|
case SND_SOC_DAPM_POST_PMD:
|
2018-06-01 21:53:49 -06:00
|
|
|
hdac_hdmi_set_amp(hdev, port->pin->nid, AMP_OUT_MUTE);
|
2017-01-24 09:19:03 -07:00
|
|
|
|
|
|
|
/* Disable out path for this pin widget */
|
2018-06-01 21:53:49 -06:00
|
|
|
snd_hdac_codec_write(hdev, port->pin->nid, 0,
|
2017-01-24 09:19:03 -07:00
|
|
|
AC_VERB_SET_PIN_WIDGET_CONTROL, 0);
|
|
|
|
|
2018-06-01 21:53:49 -06:00
|
|
|
hdac_hdmi_set_power_state(hdev, port->pin->nid, AC_PWRST_D3);
|
2017-01-24 09:19:03 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int hdac_hdmi_cvt_output_widget_event(struct snd_soc_dapm_widget *w,
|
|
|
|
struct snd_kcontrol *kc, int event)
|
|
|
|
{
|
|
|
|
struct hdac_hdmi_cvt *cvt = w->priv;
|
2018-06-01 21:53:49 -06:00
|
|
|
struct hdac_device *hdev = dev_to_hdac_dev(w->dapm->dev);
|
|
|
|
struct hdac_hdmi_priv *hdmi = hdev_to_hdmi_priv(hdev);
|
2017-01-24 09:19:03 -07:00
|
|
|
struct hdac_hdmi_pcm *pcm;
|
|
|
|
|
2018-06-01 21:53:49 -06:00
|
|
|
dev_dbg(&hdev->dev, "%s: widget: %s event: %x\n",
|
2017-01-24 09:19:03 -07:00
|
|
|
__func__, w->name, event);
|
|
|
|
|
|
|
|
pcm = hdac_hdmi_get_pcm_from_cvt(hdmi, cvt);
|
|
|
|
if (!pcm)
|
|
|
|
return -EIO;
|
|
|
|
|
|
|
|
switch (event) {
|
|
|
|
case SND_SOC_DAPM_PRE_PMU:
|
2018-06-01 21:53:49 -06:00
|
|
|
hdac_hdmi_set_power_state(hdev, cvt->nid, AC_PWRST_D0);
|
2017-01-24 09:19:03 -07:00
|
|
|
|
|
|
|
/* Enable transmission */
|
2018-06-01 21:53:49 -06:00
|
|
|
snd_hdac_codec_write(hdev, cvt->nid, 0,
|
2017-01-24 09:19:03 -07:00
|
|
|
AC_VERB_SET_DIGI_CONVERT_1, 1);
|
|
|
|
|
|
|
|
/* Category Code (CC) to zero */
|
2018-06-01 21:53:49 -06:00
|
|
|
snd_hdac_codec_write(hdev, cvt->nid, 0,
|
2017-01-24 09:19:03 -07:00
|
|
|
AC_VERB_SET_DIGI_CONVERT_2, 0);
|
|
|
|
|
2018-06-01 21:53:49 -06:00
|
|
|
snd_hdac_codec_write(hdev, cvt->nid, 0,
|
2017-01-24 09:19:03 -07:00
|
|
|
AC_VERB_SET_CHANNEL_STREAMID, pcm->stream_tag);
|
2018-06-01 21:53:49 -06:00
|
|
|
snd_hdac_codec_write(hdev, cvt->nid, 0,
|
2017-01-24 09:19:03 -07:00
|
|
|
AC_VERB_SET_STREAM_FORMAT, pcm->format);
|
2019-06-13 05:54:12 -06:00
|
|
|
|
|
|
|
/*
|
|
|
|
* The connection indices are shared by all converters and
|
|
|
|
* may interfere with each other. Ensure correct
|
|
|
|
* routing for all converters at stream start.
|
|
|
|
*/
|
|
|
|
hdac_hdmi_verify_connect_sel_all_pins(hdev);
|
|
|
|
|
2017-01-24 09:19:03 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
case SND_SOC_DAPM_POST_PMD:
|
2018-06-01 21:53:49 -06:00
|
|
|
snd_hdac_codec_write(hdev, cvt->nid, 0,
|
2017-01-24 09:19:03 -07:00
|
|
|
AC_VERB_SET_CHANNEL_STREAMID, 0);
|
2018-06-01 21:53:49 -06:00
|
|
|
snd_hdac_codec_write(hdev, cvt->nid, 0,
|
2017-01-24 09:19:03 -07:00
|
|
|
AC_VERB_SET_STREAM_FORMAT, 0);
|
|
|
|
|
2018-06-01 21:53:49 -06:00
|
|
|
hdac_hdmi_set_power_state(hdev, cvt->nid, AC_PWRST_D3);
|
2017-01-24 09:19:03 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int hdac_hdmi_pin_mux_widget_event(struct snd_soc_dapm_widget *w,
|
|
|
|
struct snd_kcontrol *kc, int event)
|
|
|
|
{
|
2017-02-05 23:39:14 -07:00
|
|
|
struct hdac_hdmi_port *port = w->priv;
|
2018-06-01 21:53:49 -06:00
|
|
|
struct hdac_device *hdev = dev_to_hdac_dev(w->dapm->dev);
|
2017-01-24 09:19:03 -07:00
|
|
|
int mux_idx;
|
|
|
|
|
2018-06-01 21:53:49 -06:00
|
|
|
dev_dbg(&hdev->dev, "%s: widget: %s event: %x\n",
|
2017-01-24 09:19:03 -07:00
|
|
|
__func__, w->name, event);
|
|
|
|
|
|
|
|
if (!kc)
|
|
|
|
kc = w->kcontrols[0];
|
|
|
|
|
|
|
|
mux_idx = dapm_kcontrol_get_value(kc);
|
2017-02-07 06:39:47 -07:00
|
|
|
|
|
|
|
/* set the device if pin is mst_capable */
|
2018-06-01 21:53:49 -06:00
|
|
|
if (hdac_hdmi_port_select_set(hdev, port) < 0)
|
2017-02-07 06:39:47 -07:00
|
|
|
return -EIO;
|
|
|
|
|
2017-01-24 09:19:03 -07:00
|
|
|
if (mux_idx > 0) {
|
2018-06-01 21:53:49 -06:00
|
|
|
snd_hdac_codec_write(hdev, port->pin->nid, 0,
|
2017-01-24 09:19:03 -07:00
|
|
|
AC_VERB_SET_CONNECT_SEL, (mux_idx - 1));
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-02-11 19:16:06 -07:00
|
|
|
/*
|
|
|
|
* Based on user selection, map the PINs with the PCMs.
|
|
|
|
*/
|
2017-02-05 23:39:14 -07:00
|
|
|
static int hdac_hdmi_set_pin_port_mux(struct snd_kcontrol *kcontrol,
|
2016-02-11 19:16:06 -07:00
|
|
|
struct snd_ctl_elem_value *ucontrol)
|
|
|
|
{
|
|
|
|
int ret;
|
2017-02-07 06:39:48 -07:00
|
|
|
struct hdac_hdmi_port *p, *p_next;
|
2016-02-11 19:16:06 -07:00
|
|
|
struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
|
|
|
|
struct snd_soc_dapm_widget *w = snd_soc_dapm_kcontrol_widget(kcontrol);
|
|
|
|
struct snd_soc_dapm_context *dapm = w->dapm;
|
2017-02-05 23:39:14 -07:00
|
|
|
struct hdac_hdmi_port *port = w->priv;
|
2018-06-01 21:53:49 -06:00
|
|
|
struct hdac_device *hdev = dev_to_hdac_dev(dapm->dev);
|
|
|
|
struct hdac_hdmi_priv *hdmi = hdev_to_hdmi_priv(hdev);
|
2016-02-11 19:16:06 -07:00
|
|
|
struct hdac_hdmi_pcm *pcm = NULL;
|
|
|
|
const char *cvt_name = e->texts[ucontrol->value.enumerated.item[0]];
|
|
|
|
|
|
|
|
ret = snd_soc_dapm_put_enum_double(kcontrol, ucontrol);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
|
2017-02-05 23:39:14 -07:00
|
|
|
if (port == NULL)
|
|
|
|
return -EINVAL;
|
|
|
|
|
2016-02-11 19:16:06 -07:00
|
|
|
mutex_lock(&hdmi->pin_mutex);
|
|
|
|
list_for_each_entry(pcm, &hdmi->pcm_list, head) {
|
2017-02-07 06:39:48 -07:00
|
|
|
if (list_empty(&pcm->port_list))
|
|
|
|
continue;
|
2016-02-11 19:16:06 -07:00
|
|
|
|
2017-02-07 06:39:48 -07:00
|
|
|
list_for_each_entry_safe(p, p_next, &pcm->port_list, head) {
|
|
|
|
if (p == port && p->id == port->id &&
|
|
|
|
p->pin == port->pin) {
|
2019-08-09 09:15:31 -06:00
|
|
|
hdac_hdmi_jack_report_sync(pcm, port, false);
|
2017-02-07 06:39:48 -07:00
|
|
|
list_del(&p->head);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-02-11 19:16:06 -07:00
|
|
|
|
2017-02-07 06:39:48 -07:00
|
|
|
/*
|
|
|
|
* Jack status is not reported during device probe as the
|
|
|
|
* PCMs are not registered by then. So report it here.
|
|
|
|
*/
|
|
|
|
list_for_each_entry(pcm, &hdmi->pcm_list, head) {
|
|
|
|
if (!strcmp(cvt_name, pcm->cvt->name)) {
|
|
|
|
list_add_tail(&port->head, &pcm->port_list);
|
|
|
|
if (port->eld.monitor_present && port->eld.eld_valid) {
|
2019-08-09 09:15:31 -06:00
|
|
|
hdac_hdmi_jack_report_sync(pcm, port, true);
|
2017-02-07 06:39:48 -07:00
|
|
|
mutex_unlock(&hdmi->pin_mutex);
|
|
|
|
return ret;
|
2016-02-11 19:16:06 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
mutex_unlock(&hdmi->pin_mutex);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2016-02-11 19:16:05 -07:00
|
|
|
/*
|
|
|
|
* Ideally the Mux inputs should be based on the num_muxs enumerated, but
|
|
|
|
* the display driver seem to be programming the connection list for the pin
|
|
|
|
* widget runtime.
|
|
|
|
*
|
|
|
|
* So programming all the possible inputs for the mux, the user has to take
|
|
|
|
* care of selecting the right one and leaving all other inputs selected to
|
|
|
|
* "NONE"
|
|
|
|
*/
|
2018-06-01 21:53:49 -06:00
|
|
|
static int hdac_hdmi_create_pin_port_muxs(struct hdac_device *hdev,
|
2017-02-05 23:39:14 -07:00
|
|
|
struct hdac_hdmi_port *port,
|
2016-02-11 19:16:05 -07:00
|
|
|
struct snd_soc_dapm_widget *widget,
|
|
|
|
const char *widget_name)
|
|
|
|
{
|
2018-06-01 21:53:49 -06:00
|
|
|
struct hdac_hdmi_priv *hdmi = hdev_to_hdmi_priv(hdev);
|
2017-02-05 23:39:14 -07:00
|
|
|
struct hdac_hdmi_pin *pin = port->pin;
|
2016-02-11 19:16:05 -07:00
|
|
|
struct snd_kcontrol_new *kc;
|
|
|
|
struct hdac_hdmi_cvt *cvt;
|
|
|
|
struct soc_enum *se;
|
|
|
|
char kc_name[NAME_SIZE];
|
|
|
|
char mux_items[NAME_SIZE];
|
|
|
|
/* To hold inputs to the Pin mux */
|
|
|
|
char *items[HDA_MAX_CONNECTIONS];
|
|
|
|
int i = 0;
|
|
|
|
int num_items = hdmi->num_cvt + 1;
|
|
|
|
|
2018-06-01 21:53:49 -06:00
|
|
|
kc = devm_kzalloc(&hdev->dev, sizeof(*kc), GFP_KERNEL);
|
2016-02-11 19:16:05 -07:00
|
|
|
if (!kc)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
2018-06-01 21:53:49 -06:00
|
|
|
se = devm_kzalloc(&hdev->dev, sizeof(*se), GFP_KERNEL);
|
2016-02-11 19:16:05 -07:00
|
|
|
if (!se)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
2017-11-07 03:46:24 -07:00
|
|
|
snprintf(kc_name, NAME_SIZE, "Pin %d port %d Input",
|
|
|
|
pin->nid, port->id);
|
2018-06-01 21:53:49 -06:00
|
|
|
kc->name = devm_kstrdup(&hdev->dev, kc_name, GFP_KERNEL);
|
2016-02-11 19:16:05 -07:00
|
|
|
if (!kc->name)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
kc->private_value = (long)se;
|
|
|
|
kc->iface = SNDRV_CTL_ELEM_IFACE_MIXER;
|
|
|
|
kc->access = 0;
|
|
|
|
kc->info = snd_soc_info_enum_double;
|
2017-02-05 23:39:14 -07:00
|
|
|
kc->put = hdac_hdmi_set_pin_port_mux;
|
2016-02-11 19:16:05 -07:00
|
|
|
kc->get = snd_soc_dapm_get_enum_double;
|
|
|
|
|
|
|
|
se->reg = SND_SOC_NOPM;
|
|
|
|
|
|
|
|
/* enum texts: ["NONE", "cvt #", "cvt #", ...] */
|
|
|
|
se->items = num_items;
|
|
|
|
se->mask = roundup_pow_of_two(se->items) - 1;
|
|
|
|
|
|
|
|
sprintf(mux_items, "NONE");
|
2018-06-01 21:53:49 -06:00
|
|
|
items[i] = devm_kstrdup(&hdev->dev, mux_items, GFP_KERNEL);
|
2016-02-11 19:16:05 -07:00
|
|
|
if (!items[i])
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
list_for_each_entry(cvt, &hdmi->cvt_list, head) {
|
|
|
|
i++;
|
|
|
|
sprintf(mux_items, "cvt %d", cvt->nid);
|
2018-06-01 21:53:49 -06:00
|
|
|
items[i] = devm_kstrdup(&hdev->dev, mux_items, GFP_KERNEL);
|
2016-02-11 19:16:05 -07:00
|
|
|
if (!items[i])
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
2018-06-01 21:53:49 -06:00
|
|
|
se->texts = devm_kmemdup(&hdev->dev, items,
|
2016-02-11 19:16:05 -07:00
|
|
|
(num_items * sizeof(char *)), GFP_KERNEL);
|
|
|
|
if (!se->texts)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
2018-06-01 21:53:49 -06:00
|
|
|
return hdac_hdmi_fill_widget_info(&hdev->dev, widget,
|
2017-02-05 23:39:14 -07:00
|
|
|
snd_soc_dapm_mux, port, widget_name, NULL, kc, 1,
|
2017-01-24 09:19:03 -07:00
|
|
|
hdac_hdmi_pin_mux_widget_event,
|
|
|
|
SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_REG);
|
2016-02-11 19:16:05 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Add cvt <- input <- mux route map */
|
2018-06-01 21:53:49 -06:00
|
|
|
static void hdac_hdmi_add_pinmux_cvt_route(struct hdac_device *hdev,
|
2016-02-11 19:16:05 -07:00
|
|
|
struct snd_soc_dapm_widget *widgets,
|
|
|
|
struct snd_soc_dapm_route *route, int rindex)
|
|
|
|
{
|
2018-06-01 21:53:49 -06:00
|
|
|
struct hdac_hdmi_priv *hdmi = hdev_to_hdmi_priv(hdev);
|
2016-02-11 19:16:05 -07:00
|
|
|
const struct snd_kcontrol_new *kc;
|
|
|
|
struct soc_enum *se;
|
2017-02-05 23:39:14 -07:00
|
|
|
int mux_index = hdmi->num_cvt + hdmi->num_ports;
|
2016-02-11 19:16:05 -07:00
|
|
|
int i, j;
|
|
|
|
|
2017-02-05 23:39:14 -07:00
|
|
|
for (i = 0; i < hdmi->num_ports; i++) {
|
2016-02-11 19:16:05 -07:00
|
|
|
kc = widgets[mux_index].kcontrol_news;
|
|
|
|
se = (struct soc_enum *)kc->private_value;
|
|
|
|
for (j = 0; j < hdmi->num_cvt; j++) {
|
|
|
|
hdac_hdmi_fill_route(&route[rindex],
|
|
|
|
widgets[mux_index].name,
|
|
|
|
se->texts[j + 1],
|
|
|
|
widgets[j].name, NULL);
|
|
|
|
|
|
|
|
rindex++;
|
|
|
|
}
|
|
|
|
|
|
|
|
mux_index++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Widgets are added in the below sequence
|
|
|
|
* Converter widgets for num converters enumerated
|
2017-02-05 23:39:14 -07:00
|
|
|
* Pin-port widgets for num ports for Pins enumerated
|
|
|
|
* Pin-port mux widgets to represent connenction list of pin widget
|
2016-02-11 19:16:05 -07:00
|
|
|
*
|
2017-02-05 23:39:14 -07:00
|
|
|
* For each port, one Mux and One output widget is added
|
|
|
|
* Total widgets elements = num_cvt + (num_ports * 2);
|
2016-02-11 19:16:05 -07:00
|
|
|
*
|
|
|
|
* Routes are added as below:
|
2017-02-05 23:39:14 -07:00
|
|
|
* pin-port mux -> pin (based on num_ports)
|
|
|
|
* cvt -> "Input sel control" -> pin-port_mux
|
2016-02-11 19:16:05 -07:00
|
|
|
*
|
|
|
|
* Total route elements:
|
2017-02-05 23:39:14 -07:00
|
|
|
* num_ports + (pin_muxes * num_cvt)
|
2016-02-11 19:16:05 -07:00
|
|
|
*/
|
|
|
|
static int create_fill_widget_route_map(struct snd_soc_dapm_context *dapm)
|
2015-11-10 06:12:06 -07:00
|
|
|
{
|
2016-02-11 19:16:05 -07:00
|
|
|
struct snd_soc_dapm_widget *widgets;
|
|
|
|
struct snd_soc_dapm_route *route;
|
2018-06-01 21:53:49 -06:00
|
|
|
struct hdac_device *hdev = dev_to_hdac_dev(dapm->dev);
|
|
|
|
struct hdac_hdmi_priv *hdmi = hdev_to_hdmi_priv(hdev);
|
2017-12-19 18:48:13 -07:00
|
|
|
struct snd_soc_dai_driver *dai_drv = hdmi->dai_drv;
|
2016-02-11 19:16:05 -07:00
|
|
|
char widget_name[NAME_SIZE];
|
|
|
|
struct hdac_hdmi_cvt *cvt;
|
|
|
|
struct hdac_hdmi_pin *pin;
|
2017-02-05 23:39:14 -07:00
|
|
|
int ret, i = 0, num_routes = 0, j;
|
2015-11-10 06:12:06 -07:00
|
|
|
|
2016-02-11 19:16:05 -07:00
|
|
|
if (list_empty(&hdmi->cvt_list) || list_empty(&hdmi->pin_list))
|
|
|
|
return -EINVAL;
|
2015-11-10 06:12:06 -07:00
|
|
|
|
2017-02-05 23:39:14 -07:00
|
|
|
widgets = devm_kzalloc(dapm->dev, (sizeof(*widgets) *
|
|
|
|
((2 * hdmi->num_ports) + hdmi->num_cvt)),
|
|
|
|
GFP_KERNEL);
|
2015-11-10 06:12:06 -07:00
|
|
|
|
2016-02-11 19:16:05 -07:00
|
|
|
if (!widgets)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
/* DAPM widgets to represent each converter widget */
|
|
|
|
list_for_each_entry(cvt, &hdmi->cvt_list, head) {
|
|
|
|
sprintf(widget_name, "Converter %d", cvt->nid);
|
|
|
|
ret = hdac_hdmi_fill_widget_info(dapm->dev, &widgets[i],
|
2017-01-24 09:19:03 -07:00
|
|
|
snd_soc_dapm_aif_in, cvt,
|
|
|
|
widget_name, dai_drv[i].playback.stream_name, NULL, 0,
|
|
|
|
hdac_hdmi_cvt_output_widget_event,
|
|
|
|
SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD);
|
2016-02-11 19:16:05 -07:00
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
|
|
|
list_for_each_entry(pin, &hdmi->pin_list, head) {
|
2017-02-05 23:39:14 -07:00
|
|
|
for (j = 0; j < pin->num_ports; j++) {
|
|
|
|
sprintf(widget_name, "hif%d-%d Output",
|
|
|
|
pin->nid, pin->ports[j].id);
|
|
|
|
ret = hdac_hdmi_fill_widget_info(dapm->dev, &widgets[i],
|
|
|
|
snd_soc_dapm_output, &pin->ports[j],
|
|
|
|
widget_name, NULL, NULL, 0,
|
|
|
|
hdac_hdmi_pin_output_widget_event,
|
|
|
|
SND_SOC_DAPM_PRE_PMU |
|
|
|
|
SND_SOC_DAPM_POST_PMD);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
2017-02-07 06:39:55 -07:00
|
|
|
pin->ports[j].output_pin = widgets[i].name;
|
2017-02-05 23:39:14 -07:00
|
|
|
i++;
|
|
|
|
}
|
2016-02-11 19:16:05 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* DAPM widgets to represent the connection list to pin widget */
|
|
|
|
list_for_each_entry(pin, &hdmi->pin_list, head) {
|
2017-02-05 23:39:14 -07:00
|
|
|
for (j = 0; j < pin->num_ports; j++) {
|
|
|
|
sprintf(widget_name, "Pin%d-Port%d Mux",
|
|
|
|
pin->nid, pin->ports[j].id);
|
2018-06-01 21:53:49 -06:00
|
|
|
ret = hdac_hdmi_create_pin_port_muxs(hdev,
|
2017-02-05 23:39:14 -07:00
|
|
|
&pin->ports[j], &widgets[i],
|
|
|
|
widget_name);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
i++;
|
2016-02-11 19:16:05 -07:00
|
|
|
|
2017-02-05 23:39:14 -07:00
|
|
|
/* For cvt to pin_mux mapping */
|
|
|
|
num_routes += hdmi->num_cvt;
|
2016-02-11 19:16:05 -07:00
|
|
|
|
2017-02-05 23:39:14 -07:00
|
|
|
/* For pin_mux to pin mapping */
|
|
|
|
num_routes++;
|
|
|
|
}
|
2016-02-11 19:16:05 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
route = devm_kzalloc(dapm->dev, (sizeof(*route) * num_routes),
|
|
|
|
GFP_KERNEL);
|
|
|
|
if (!route)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
i = 0;
|
|
|
|
/* Add pin <- NULL <- mux route map */
|
|
|
|
list_for_each_entry(pin, &hdmi->pin_list, head) {
|
2017-02-05 23:39:14 -07:00
|
|
|
for (j = 0; j < pin->num_ports; j++) {
|
|
|
|
int sink_index = i + hdmi->num_cvt;
|
|
|
|
int src_index = sink_index + pin->num_ports *
|
|
|
|
hdmi->num_pin;
|
2016-02-11 19:16:05 -07:00
|
|
|
|
2017-02-05 23:39:14 -07:00
|
|
|
hdac_hdmi_fill_route(&route[i],
|
2016-02-11 19:16:05 -07:00
|
|
|
widgets[sink_index].name, NULL,
|
|
|
|
widgets[src_index].name, NULL);
|
2017-02-05 23:39:14 -07:00
|
|
|
i++;
|
|
|
|
}
|
2016-02-11 19:16:05 -07:00
|
|
|
}
|
|
|
|
|
2018-06-01 21:53:49 -06:00
|
|
|
hdac_hdmi_add_pinmux_cvt_route(hdev, widgets, route, i);
|
2016-02-11 19:16:05 -07:00
|
|
|
|
|
|
|
snd_soc_dapm_new_controls(dapm, widgets,
|
2017-02-05 23:39:14 -07:00
|
|
|
((2 * hdmi->num_ports) + hdmi->num_cvt));
|
2016-02-11 19:16:05 -07:00
|
|
|
|
|
|
|
snd_soc_dapm_add_routes(dapm, route, num_routes);
|
|
|
|
snd_soc_dapm_new_widgets(dapm->card);
|
|
|
|
|
|
|
|
return 0;
|
2015-11-10 06:12:06 -07:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2018-06-01 21:53:49 -06:00
|
|
|
static int hdac_hdmi_init_dai_map(struct hdac_device *hdev)
|
2015-11-10 06:12:06 -07:00
|
|
|
{
|
2018-06-01 21:53:49 -06:00
|
|
|
struct hdac_hdmi_priv *hdmi = hdev_to_hdmi_priv(hdev);
|
2017-02-05 23:39:14 -07:00
|
|
|
struct hdac_hdmi_dai_port_map *dai_map;
|
2015-12-09 09:16:10 -07:00
|
|
|
struct hdac_hdmi_cvt *cvt;
|
2016-02-11 19:16:07 -07:00
|
|
|
int dai_id = 0;
|
2015-11-10 06:12:06 -07:00
|
|
|
|
2016-02-11 19:16:07 -07:00
|
|
|
if (list_empty(&hdmi->cvt_list))
|
2015-12-09 09:16:10 -07:00
|
|
|
return -EINVAL;
|
2015-11-10 06:12:06 -07:00
|
|
|
|
2016-02-11 19:16:07 -07:00
|
|
|
list_for_each_entry(cvt, &hdmi->cvt_list, head) {
|
|
|
|
dai_map = &hdmi->dai_map[dai_id];
|
|
|
|
dai_map->dai_id = dai_id;
|
|
|
|
dai_map->cvt = cvt;
|
2015-11-10 06:12:06 -07:00
|
|
|
|
2016-02-11 19:16:07 -07:00
|
|
|
dai_id++;
|
2015-11-10 06:12:06 -07:00
|
|
|
|
2016-02-11 19:16:07 -07:00
|
|
|
if (dai_id == HDA_MAX_CVTS) {
|
2018-06-01 21:53:49 -06:00
|
|
|
dev_warn(&hdev->dev,
|
2016-02-11 19:16:07 -07:00
|
|
|
"Max dais supported: %d\n", dai_id);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2015-11-10 06:12:06 -07:00
|
|
|
|
2015-12-09 09:16:10 -07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-06-01 21:53:49 -06:00
|
|
|
static int hdac_hdmi_add_cvt(struct hdac_device *hdev, hda_nid_t nid)
|
2015-12-09 09:16:10 -07:00
|
|
|
{
|
2018-06-01 21:53:49 -06:00
|
|
|
struct hdac_hdmi_priv *hdmi = hdev_to_hdmi_priv(hdev);
|
2015-12-09 09:16:10 -07:00
|
|
|
struct hdac_hdmi_cvt *cvt;
|
2016-02-11 19:16:06 -07:00
|
|
|
char name[NAME_SIZE];
|
2015-12-09 09:16:10 -07:00
|
|
|
|
2019-02-08 16:26:53 -07:00
|
|
|
cvt = devm_kzalloc(&hdev->dev, sizeof(*cvt), GFP_KERNEL);
|
2015-12-09 09:16:10 -07:00
|
|
|
if (!cvt)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
cvt->nid = nid;
|
2016-02-11 19:16:06 -07:00
|
|
|
sprintf(name, "cvt %d", cvt->nid);
|
2019-02-08 16:26:53 -07:00
|
|
|
cvt->name = devm_kstrdup(&hdev->dev, name, GFP_KERNEL);
|
|
|
|
if (!cvt->name)
|
|
|
|
return -ENOMEM;
|
2015-12-09 09:16:10 -07:00
|
|
|
|
|
|
|
list_add_tail(&cvt->head, &hdmi->cvt_list);
|
|
|
|
hdmi->num_cvt++;
|
|
|
|
|
2018-06-01 21:53:49 -06:00
|
|
|
return hdac_hdmi_query_cvt_params(hdev, cvt);
|
2015-12-09 09:16:10 -07:00
|
|
|
}
|
|
|
|
|
2018-06-01 21:53:49 -06:00
|
|
|
static int hdac_hdmi_parse_eld(struct hdac_device *hdev,
|
2017-02-05 23:39:14 -07:00
|
|
|
struct hdac_hdmi_port *port)
|
2016-04-13 22:37:28 -06:00
|
|
|
{
|
2017-01-18 09:04:41 -07:00
|
|
|
unsigned int ver, mnl;
|
|
|
|
|
2017-02-05 23:39:14 -07:00
|
|
|
ver = (port->eld.eld_buffer[DRM_ELD_VER] & DRM_ELD_VER_MASK)
|
2017-01-18 09:04:41 -07:00
|
|
|
>> DRM_ELD_VER_SHIFT;
|
|
|
|
|
|
|
|
if (ver != ELD_VER_CEA_861D && ver != ELD_VER_PARTIAL) {
|
2018-06-01 21:53:49 -06:00
|
|
|
dev_err(&hdev->dev, "HDMI: Unknown ELD version %d\n", ver);
|
2017-01-18 09:04:41 -07:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2017-02-05 23:39:14 -07:00
|
|
|
mnl = (port->eld.eld_buffer[DRM_ELD_CEA_EDID_VER_MNL] &
|
2017-01-18 09:04:41 -07:00
|
|
|
DRM_ELD_MNL_MASK) >> DRM_ELD_MNL_SHIFT;
|
|
|
|
|
|
|
|
if (mnl > ELD_MAX_MNL) {
|
2018-06-01 21:53:49 -06:00
|
|
|
dev_err(&hdev->dev, "HDMI: MNL Invalid %d\n", mnl);
|
2017-01-18 09:04:41 -07:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2017-02-05 23:39:14 -07:00
|
|
|
port->eld.info.spk_alloc = port->eld.eld_buffer[DRM_ELD_SPEAKER];
|
2017-01-18 09:04:41 -07:00
|
|
|
|
|
|
|
return 0;
|
2016-04-13 22:37:28 -06:00
|
|
|
}
|
|
|
|
|
2017-02-05 23:39:14 -07:00
|
|
|
static void hdac_hdmi_present_sense(struct hdac_hdmi_pin *pin,
|
|
|
|
struct hdac_hdmi_port *port)
|
2016-02-11 19:16:01 -07:00
|
|
|
{
|
2018-06-01 21:53:49 -06:00
|
|
|
struct hdac_device *hdev = pin->hdev;
|
|
|
|
struct hdac_hdmi_priv *hdmi = hdev_to_hdmi_priv(hdev);
|
2016-02-11 19:16:06 -07:00
|
|
|
struct hdac_hdmi_pcm *pcm;
|
2017-02-05 23:39:14 -07:00
|
|
|
int size = 0;
|
2017-02-05 23:39:18 -07:00
|
|
|
int port_id = -1;
|
2017-02-05 23:39:14 -07:00
|
|
|
|
|
|
|
if (!hdmi)
|
|
|
|
return;
|
2016-02-11 19:16:01 -07:00
|
|
|
|
2017-02-05 23:39:18 -07:00
|
|
|
/*
|
|
|
|
* In case of non MST pin, get_eld info API expectes port
|
|
|
|
* to be -1.
|
|
|
|
*/
|
2017-01-18 09:04:41 -07:00
|
|
|
mutex_lock(&hdmi->pin_mutex);
|
2017-02-05 23:39:14 -07:00
|
|
|
port->eld.monitor_present = false;
|
2016-02-11 19:16:01 -07:00
|
|
|
|
2017-02-05 23:39:18 -07:00
|
|
|
if (pin->mst_capable)
|
|
|
|
port_id = port->id;
|
|
|
|
|
2018-06-01 21:53:49 -06:00
|
|
|
size = snd_hdac_acomp_get_eld(hdev, pin->nid, port_id,
|
2017-02-05 23:39:14 -07:00
|
|
|
&port->eld.monitor_present,
|
|
|
|
port->eld.eld_buffer,
|
2017-01-18 09:04:41 -07:00
|
|
|
ELD_MAX_SIZE);
|
2016-02-11 19:16:01 -07:00
|
|
|
|
2017-01-18 09:04:41 -07:00
|
|
|
if (size > 0) {
|
|
|
|
size = min(size, ELD_MAX_SIZE);
|
2018-06-01 21:53:49 -06:00
|
|
|
if (hdac_hdmi_parse_eld(hdev, port) < 0)
|
2017-01-18 09:04:41 -07:00
|
|
|
size = -EINVAL;
|
|
|
|
}
|
2016-02-11 19:16:06 -07:00
|
|
|
|
2017-01-18 09:04:41 -07:00
|
|
|
if (size > 0) {
|
2017-02-05 23:39:14 -07:00
|
|
|
port->eld.eld_valid = true;
|
|
|
|
port->eld.eld_size = size;
|
2017-01-18 09:04:41 -07:00
|
|
|
} else {
|
2017-02-05 23:39:14 -07:00
|
|
|
port->eld.eld_valid = false;
|
|
|
|
port->eld.eld_size = 0;
|
2017-01-18 09:04:41 -07:00
|
|
|
}
|
2016-02-11 19:16:01 -07:00
|
|
|
|
2018-06-01 21:53:49 -06:00
|
|
|
pcm = hdac_hdmi_get_pcm(hdev, port);
|
2016-02-11 19:16:06 -07:00
|
|
|
|
2017-02-05 23:39:14 -07:00
|
|
|
if (!port->eld.monitor_present || !port->eld.eld_valid) {
|
2016-02-11 19:16:01 -07:00
|
|
|
|
2018-06-01 21:53:49 -06:00
|
|
|
dev_err(&hdev->dev, "%s: disconnect for pin:port %d:%d\n",
|
2017-02-05 23:39:14 -07:00
|
|
|
__func__, pin->nid, port->id);
|
2016-02-11 19:16:06 -07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* PCMs are not registered during device probe, so don't
|
|
|
|
* report jack here. It will be done in usermode mux
|
|
|
|
* control select.
|
|
|
|
*/
|
2019-08-09 09:15:31 -06:00
|
|
|
if (pcm) {
|
2017-02-07 06:39:48 -07:00
|
|
|
hdac_hdmi_jack_report(pcm, port, false);
|
2019-08-09 09:15:31 -06:00
|
|
|
schedule_work(&port->dapm_work);
|
|
|
|
}
|
2016-02-11 19:16:06 -07:00
|
|
|
|
|
|
|
mutex_unlock(&hdmi->pin_mutex);
|
2017-01-18 09:04:41 -07:00
|
|
|
return;
|
2016-02-11 19:16:01 -07:00
|
|
|
}
|
|
|
|
|
2017-02-05 23:39:14 -07:00
|
|
|
if (port->eld.monitor_present && port->eld.eld_valid) {
|
2019-08-09 09:15:31 -06:00
|
|
|
if (pcm) {
|
2017-02-07 06:39:48 -07:00
|
|
|
hdac_hdmi_jack_report(pcm, port, true);
|
2019-08-09 09:15:31 -06:00
|
|
|
schedule_work(&port->dapm_work);
|
|
|
|
}
|
2017-01-18 09:04:41 -07:00
|
|
|
|
|
|
|
print_hex_dump_debug("ELD: ", DUMP_PREFIX_OFFSET, 16, 1,
|
2017-02-05 23:39:14 -07:00
|
|
|
port->eld.eld_buffer, port->eld.eld_size, false);
|
2016-02-11 19:16:01 -07:00
|
|
|
|
2017-02-05 23:39:14 -07:00
|
|
|
}
|
2016-02-11 19:16:06 -07:00
|
|
|
mutex_unlock(&hdmi->pin_mutex);
|
2016-02-11 19:16:01 -07:00
|
|
|
}
|
|
|
|
|
2019-02-08 16:26:53 -07:00
|
|
|
static int hdac_hdmi_add_ports(struct hdac_device *hdev,
|
|
|
|
struct hdac_hdmi_pin *pin)
|
2017-02-05 23:39:14 -07:00
|
|
|
{
|
|
|
|
struct hdac_hdmi_port *ports;
|
|
|
|
int max_ports = HDA_MAX_PORTS;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* FIXME: max_port may vary for each platform, so pass this as
|
|
|
|
* as driver data or query from i915 interface when this API is
|
|
|
|
* implemented.
|
|
|
|
*/
|
|
|
|
|
2019-02-08 16:26:53 -07:00
|
|
|
ports = devm_kcalloc(&hdev->dev, max_ports, sizeof(*ports), GFP_KERNEL);
|
2017-02-05 23:39:14 -07:00
|
|
|
if (!ports)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
for (i = 0; i < max_ports; i++) {
|
|
|
|
ports[i].id = i;
|
|
|
|
ports[i].pin = pin;
|
2019-08-09 09:15:31 -06:00
|
|
|
INIT_WORK(&ports[i].dapm_work, hdac_hdmi_jack_dapm_work);
|
2017-02-05 23:39:14 -07:00
|
|
|
}
|
|
|
|
pin->ports = ports;
|
|
|
|
pin->num_ports = max_ports;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-06-01 21:53:49 -06:00
|
|
|
static int hdac_hdmi_add_pin(struct hdac_device *hdev, hda_nid_t nid)
|
2015-12-09 09:16:10 -07:00
|
|
|
{
|
2018-06-01 21:53:49 -06:00
|
|
|
struct hdac_hdmi_priv *hdmi = hdev_to_hdmi_priv(hdev);
|
2015-12-09 09:16:10 -07:00
|
|
|
struct hdac_hdmi_pin *pin;
|
2017-02-05 23:39:14 -07:00
|
|
|
int ret;
|
2015-12-09 09:16:10 -07:00
|
|
|
|
2019-02-08 16:26:53 -07:00
|
|
|
pin = devm_kzalloc(&hdev->dev, sizeof(*pin), GFP_KERNEL);
|
2015-12-09 09:16:10 -07:00
|
|
|
if (!pin)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
pin->nid = nid;
|
2017-02-05 23:39:18 -07:00
|
|
|
pin->mst_capable = false;
|
2018-06-01 21:53:49 -06:00
|
|
|
pin->hdev = hdev;
|
2019-02-08 16:26:53 -07:00
|
|
|
ret = hdac_hdmi_add_ports(hdev, pin);
|
2017-02-05 23:39:14 -07:00
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
2015-12-09 09:16:10 -07:00
|
|
|
|
|
|
|
list_add_tail(&pin->head, &hdmi->pin_list);
|
|
|
|
hdmi->num_pin++;
|
2017-02-05 23:39:14 -07:00
|
|
|
hdmi->num_ports += pin->num_ports;
|
2016-02-11 19:16:01 -07:00
|
|
|
|
2015-12-09 09:16:10 -07:00
|
|
|
return 0;
|
2015-11-10 06:12:06 -07:00
|
|
|
}
|
|
|
|
|
2018-11-10 14:18:46 -07:00
|
|
|
#define INTEL_VENDOR_NID_0x2 0x02
|
|
|
|
#define INTEL_VENDOR_NID_0x8 0x08
|
|
|
|
#define INTEL_VENDOR_NID_0xb 0x0b
|
2016-02-11 19:16:03 -07:00
|
|
|
#define INTEL_GET_VENDOR_VERB 0xf81
|
|
|
|
#define INTEL_SET_VENDOR_VERB 0x781
|
2018-11-10 14:18:46 -07:00
|
|
|
#define INTEL_EN_DP12 0x02 /* enable DP 1.2 features */
|
2016-02-11 19:16:03 -07:00
|
|
|
#define INTEL_EN_ALL_PIN_CVTS 0x01 /* enable 2nd & 3rd pins and convertors */
|
|
|
|
|
2017-12-01 02:13:19 -07:00
|
|
|
static void hdac_hdmi_skl_enable_all_pins(struct hdac_device *hdev)
|
2016-02-11 19:16:03 -07:00
|
|
|
{
|
|
|
|
unsigned int vendor_param;
|
2017-12-01 02:13:19 -07:00
|
|
|
struct hdac_hdmi_priv *hdmi = hdev_to_hdmi_priv(hdev);
|
2017-07-20 00:10:56 -06:00
|
|
|
unsigned int vendor_nid = hdmi->drv_data->vendor_nid;
|
2016-02-11 19:16:03 -07:00
|
|
|
|
2017-12-01 02:13:19 -07:00
|
|
|
vendor_param = snd_hdac_codec_read(hdev, vendor_nid, 0,
|
2016-02-11 19:16:03 -07:00
|
|
|
INTEL_GET_VENDOR_VERB, 0);
|
|
|
|
if (vendor_param == -1 || vendor_param & INTEL_EN_ALL_PIN_CVTS)
|
|
|
|
return;
|
|
|
|
|
|
|
|
vendor_param |= INTEL_EN_ALL_PIN_CVTS;
|
2017-12-01 02:13:19 -07:00
|
|
|
vendor_param = snd_hdac_codec_read(hdev, vendor_nid, 0,
|
2016-02-11 19:16:03 -07:00
|
|
|
INTEL_SET_VENDOR_VERB, vendor_param);
|
|
|
|
if (vendor_param == -1)
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-12-01 02:13:19 -07:00
|
|
|
static void hdac_hdmi_skl_enable_dp12(struct hdac_device *hdev)
|
2016-02-11 19:16:03 -07:00
|
|
|
{
|
|
|
|
unsigned int vendor_param;
|
2017-12-01 02:13:19 -07:00
|
|
|
struct hdac_hdmi_priv *hdmi = hdev_to_hdmi_priv(hdev);
|
2017-07-20 00:10:56 -06:00
|
|
|
unsigned int vendor_nid = hdmi->drv_data->vendor_nid;
|
2016-02-11 19:16:03 -07:00
|
|
|
|
2017-12-01 02:13:19 -07:00
|
|
|
vendor_param = snd_hdac_codec_read(hdev, vendor_nid, 0,
|
2016-02-11 19:16:03 -07:00
|
|
|
INTEL_GET_VENDOR_VERB, 0);
|
|
|
|
if (vendor_param == -1 || vendor_param & INTEL_EN_DP12)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* enable DP1.2 mode */
|
|
|
|
vendor_param |= INTEL_EN_DP12;
|
2017-12-01 02:13:19 -07:00
|
|
|
vendor_param = snd_hdac_codec_read(hdev, vendor_nid, 0,
|
2016-02-11 19:16:03 -07:00
|
|
|
INTEL_SET_VENDOR_VERB, vendor_param);
|
|
|
|
if (vendor_param == -1)
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2017-07-13 14:38:38 -06:00
|
|
|
static const struct snd_soc_dai_ops hdmi_dai_ops = {
|
2016-02-11 19:16:04 -07:00
|
|
|
.startup = hdac_hdmi_pcm_open,
|
|
|
|
.shutdown = hdac_hdmi_pcm_close,
|
|
|
|
.hw_params = hdac_hdmi_set_hw_params,
|
2017-01-24 09:19:03 -07:00
|
|
|
.set_tdm_slot = hdac_hdmi_set_tdm_slot,
|
2016-02-11 19:16:04 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Each converter can support a stream independently. So a dai is created
|
|
|
|
* based on the number of converter queried.
|
|
|
|
*/
|
2017-12-01 02:13:19 -07:00
|
|
|
static int hdac_hdmi_create_dais(struct hdac_device *hdev,
|
2016-02-11 19:16:04 -07:00
|
|
|
struct snd_soc_dai_driver **dais,
|
|
|
|
struct hdac_hdmi_priv *hdmi, int num_dais)
|
|
|
|
{
|
|
|
|
struct snd_soc_dai_driver *hdmi_dais;
|
|
|
|
struct hdac_hdmi_cvt *cvt;
|
|
|
|
char name[NAME_SIZE], dai_name[NAME_SIZE];
|
|
|
|
int i = 0;
|
|
|
|
u32 rates, bps;
|
|
|
|
unsigned int rate_max = 384000, rate_min = 8000;
|
|
|
|
u64 formats;
|
|
|
|
int ret;
|
|
|
|
|
2017-12-01 02:13:19 -07:00
|
|
|
hdmi_dais = devm_kzalloc(&hdev->dev,
|
2016-02-11 19:16:04 -07:00
|
|
|
(sizeof(*hdmi_dais) * num_dais),
|
|
|
|
GFP_KERNEL);
|
|
|
|
if (!hdmi_dais)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
list_for_each_entry(cvt, &hdmi->cvt_list, head) {
|
2017-12-01 02:13:19 -07:00
|
|
|
ret = snd_hdac_query_supported_pcm(hdev, cvt->nid,
|
2016-02-11 19:16:04 -07:00
|
|
|
&rates, &formats, &bps);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
2018-08-07 11:19:16 -06:00
|
|
|
/* Filter out 44.1, 88.2 and 176.4Khz */
|
|
|
|
rates &= ~(SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_88200 |
|
|
|
|
SNDRV_PCM_RATE_176400);
|
|
|
|
if (!rates)
|
|
|
|
return -EINVAL;
|
|
|
|
|
2016-02-11 19:16:04 -07:00
|
|
|
sprintf(dai_name, "intel-hdmi-hifi%d", i+1);
|
2017-12-01 02:13:19 -07:00
|
|
|
hdmi_dais[i].name = devm_kstrdup(&hdev->dev,
|
2016-02-11 19:16:04 -07:00
|
|
|
dai_name, GFP_KERNEL);
|
|
|
|
|
|
|
|
if (!hdmi_dais[i].name)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
snprintf(name, sizeof(name), "hifi%d", i+1);
|
|
|
|
hdmi_dais[i].playback.stream_name =
|
2017-12-01 02:13:19 -07:00
|
|
|
devm_kstrdup(&hdev->dev, name, GFP_KERNEL);
|
2016-02-11 19:16:04 -07:00
|
|
|
if (!hdmi_dais[i].playback.stream_name)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set caps based on capability queried from the converter.
|
|
|
|
* It will be constrained runtime based on ELD queried.
|
|
|
|
*/
|
|
|
|
hdmi_dais[i].playback.formats = formats;
|
|
|
|
hdmi_dais[i].playback.rates = rates;
|
|
|
|
hdmi_dais[i].playback.rate_max = rate_max;
|
|
|
|
hdmi_dais[i].playback.rate_min = rate_min;
|
|
|
|
hdmi_dais[i].playback.channels_min = 2;
|
|
|
|
hdmi_dais[i].playback.channels_max = 2;
|
2017-03-24 11:40:26 -06:00
|
|
|
hdmi_dais[i].playback.sig_bits = bps;
|
2016-02-11 19:16:04 -07:00
|
|
|
hdmi_dais[i].ops = &hdmi_dai_ops;
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
|
|
|
*dais = hdmi_dais;
|
2017-12-19 18:48:13 -07:00
|
|
|
hdmi->dai_drv = hdmi_dais;
|
2016-02-11 19:16:04 -07:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-11-10 06:12:06 -07:00
|
|
|
/*
|
|
|
|
* Parse all nodes and store the cvt/pin nids in array
|
|
|
|
* Add one time initialization for pin and cvt widgets
|
|
|
|
*/
|
2018-06-01 21:53:49 -06:00
|
|
|
static int hdac_hdmi_parse_and_map_nid(struct hdac_device *hdev,
|
2016-02-11 19:16:04 -07:00
|
|
|
struct snd_soc_dai_driver **dais, int *num_dais)
|
2015-11-10 06:12:06 -07:00
|
|
|
{
|
|
|
|
hda_nid_t nid;
|
2015-12-01 01:59:35 -07:00
|
|
|
int i, num_nodes;
|
2018-06-01 21:53:49 -06:00
|
|
|
struct hdac_hdmi_priv *hdmi = hdev_to_hdmi_priv(hdev);
|
2015-12-09 09:16:10 -07:00
|
|
|
int ret;
|
2015-11-10 06:12:06 -07:00
|
|
|
|
2017-12-01 02:13:19 -07:00
|
|
|
hdac_hdmi_skl_enable_all_pins(hdev);
|
|
|
|
hdac_hdmi_skl_enable_dp12(hdev);
|
2016-02-11 19:16:03 -07:00
|
|
|
|
2017-12-01 02:13:19 -07:00
|
|
|
num_nodes = snd_hdac_get_sub_nodes(hdev, hdev->afg, &nid);
|
2015-12-09 09:16:08 -07:00
|
|
|
if (!nid || num_nodes <= 0) {
|
2017-12-01 02:13:19 -07:00
|
|
|
dev_warn(&hdev->dev, "HDMI: failed to get afg sub nodes\n");
|
2015-11-10 06:12:06 -07:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2017-12-06 04:04:06 -07:00
|
|
|
for (i = 0; i < num_nodes; i++, nid++) {
|
2015-11-10 06:12:06 -07:00
|
|
|
unsigned int caps;
|
|
|
|
unsigned int type;
|
|
|
|
|
2017-12-01 02:13:19 -07:00
|
|
|
caps = get_wcaps(hdev, nid);
|
2015-11-10 06:12:06 -07:00
|
|
|
type = get_wcaps_type(caps);
|
|
|
|
|
|
|
|
if (!(caps & AC_WCAP_DIGITAL))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
|
|
|
|
case AC_WID_AUD_OUT:
|
2018-06-01 21:53:49 -06:00
|
|
|
ret = hdac_hdmi_add_cvt(hdev, nid);
|
2015-12-09 09:16:10 -07:00
|
|
|
if (ret < 0)
|
2019-02-08 16:26:53 -07:00
|
|
|
return ret;
|
2015-11-10 06:12:06 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
case AC_WID_PIN:
|
2018-06-01 21:53:49 -06:00
|
|
|
ret = hdac_hdmi_add_pin(hdev, nid);
|
2015-12-09 09:16:10 -07:00
|
|
|
if (ret < 0)
|
2019-02-08 16:26:53 -07:00
|
|
|
return ret;
|
2015-11-10 06:12:06 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-07 03:46:26 -07:00
|
|
|
if (!hdmi->num_pin || !hdmi->num_cvt) {
|
|
|
|
ret = -EIO;
|
2019-02-08 16:26:53 -07:00
|
|
|
dev_err(&hdev->dev, "Bad pin/cvt setup in %s\n", __func__);
|
|
|
|
return ret;
|
2017-11-07 03:46:26 -07:00
|
|
|
}
|
2015-11-10 06:12:06 -07:00
|
|
|
|
2017-12-01 02:13:19 -07:00
|
|
|
ret = hdac_hdmi_create_dais(hdev, dais, hdmi, hdmi->num_cvt);
|
2016-02-11 19:16:04 -07:00
|
|
|
if (ret) {
|
2017-12-01 02:13:19 -07:00
|
|
|
dev_err(&hdev->dev, "Failed to create dais with err: %d\n",
|
2019-02-08 16:26:53 -07:00
|
|
|
ret);
|
|
|
|
return ret;
|
2016-02-11 19:16:04 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
*num_dais = hdmi->num_cvt;
|
2018-06-01 21:53:49 -06:00
|
|
|
ret = hdac_hdmi_init_dai_map(hdev);
|
2017-11-07 03:46:26 -07:00
|
|
|
if (ret < 0)
|
2019-02-08 16:26:53 -07:00
|
|
|
dev_err(&hdev->dev, "Failed to init DAI map with err: %d\n",
|
|
|
|
ret);
|
2017-11-07 03:46:26 -07:00
|
|
|
return ret;
|
2015-11-10 06:12:06 -07:00
|
|
|
}
|
|
|
|
|
ALSA: hda: Make audio component support more generic
This is the final step for more generic support of DRM audio
component. The generic audio component code is now moved to its own
file, and the symbols are renamed from snd_hac_i915_* to
snd_hdac_acomp_*, respectively. The generic code is enabled via the
new kconfig, CONFIG_SND_HDA_COMPONENT, while CONFIG_SND_HDA_I915 is
kept as the super-class.
Along with the split, three new callbacks are added to audio_ops:
pin2port is for providing the conversion between the pin number and
the widget id, and master_bind/master_unbin are called at binding /
unbinding the master component, respectively. All these are optional,
but used in i915 implementation and also other later implementations.
A note about the new snd_hdac_acomp_init() function: there is a slight
difference between this and the old snd_hdac_i915_init(). The latter
(still) synchronizes with the master component binding, i.e. it
assures that the relevant DRM component gets bound when it returns, or
gives a negative error. Meanwhile the new function doesn't
synchronize but just leaves as is. It's the responsibility by the
caller's side to synchronize, or the caller may accept the
asynchronous binding on the fly.
v1->v2: Fix missing NULL check in master_bind/unbind
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2018-07-11 08:23:16 -06:00
|
|
|
static int hdac_hdmi_pin2port(void *aptr, int pin)
|
|
|
|
{
|
2018-11-10 14:18:46 -07:00
|
|
|
struct hdac_device *hdev = aptr;
|
|
|
|
struct hdac_hdmi_priv *hdmi = hdev_to_hdmi_priv(hdev);
|
|
|
|
const int *map = hdmi->drv_data->port_map;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (!hdmi->drv_data->port_num)
|
|
|
|
return pin - 4; /* map NID 0x05 -> port #1 */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* looking for the pin number in the mapping table and return
|
|
|
|
* the index which indicate the port number
|
|
|
|
*/
|
|
|
|
for (i = 0; i < hdmi->drv_data->port_num; i++) {
|
|
|
|
if (pin == map[i])
|
|
|
|
return i + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* return -1 if pin number exceeds our expectation */
|
|
|
|
dev_err(&hdev->dev, "Can't find the port for pin %d\n", pin);
|
|
|
|
return -1;
|
ALSA: hda: Make audio component support more generic
This is the final step for more generic support of DRM audio
component. The generic audio component code is now moved to its own
file, and the symbols are renamed from snd_hac_i915_* to
snd_hdac_acomp_*, respectively. The generic code is enabled via the
new kconfig, CONFIG_SND_HDA_COMPONENT, while CONFIG_SND_HDA_I915 is
kept as the super-class.
Along with the split, three new callbacks are added to audio_ops:
pin2port is for providing the conversion between the pin number and
the widget id, and master_bind/master_unbin are called at binding /
unbinding the master component, respectively. All these are optional,
but used in i915 implementation and also other later implementations.
A note about the new snd_hdac_acomp_init() function: there is a slight
difference between this and the old snd_hdac_i915_init(). The latter
(still) synchronizes with the master component binding, i.e. it
assures that the relevant DRM component gets bound when it returns, or
gives a negative error. Meanwhile the new function doesn't
synchronize but just leaves as is. It's the responsibility by the
caller's side to synchronize, or the caller may accept the
asynchronous binding on the fly.
v1->v2: Fix missing NULL check in master_bind/unbind
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2018-07-11 08:23:16 -06:00
|
|
|
}
|
|
|
|
|
drm/i915/dp: DP audio API changes for MST
DP MST provides the capability to send multiple video and audio streams
through a single port. This requires the API's between i915 and audio
drivers to distinguish between multiple audio capable displays that can be
connected to a port. Currently only the port identity is shared in the
APIs. This patch adds support for MST with an additional parameter
'int pipe'. The existing parameter 'port' does not change it's meaning.
pipe =
MST : display pipe that the stream originates from
Non-MST : -1
Affected APIs:
struct i915_audio_component_ops
- int (*sync_audio_rate)(struct device *, int port, int rate);
+ int (*sync_audio_rate)(struct device *, int port, int pipe,
+ int rate);
- int (*get_eld)(struct device *, int port, bool *enabled,
- unsigned char *buf, int max_bytes);
+ int (*get_eld)(struct device *, int port, int pipe,
+ bool *enabled, unsigned char *buf, int max_bytes);
struct i915_audio_component_audio_ops
- void (*pin_eld_notify)(void *audio_ptr, int port);
+ void (*pin_eld_notify)(void *audio_ptr, int port, int pipe);
This patch makes dummy changes in the audio drivers (thanks Libin) for
build to succeed. The audio side drivers will send the right 'pipe' values
for MST in patches that will follow.
v2:
Renamed the new API parameter from 'dev_id' to 'pipe'. (Jim, Ville)
Included Asoc driver API compatibility changes from Jeeja.
Added WARN_ON() for invalid pipe in get_saved_encoder(). (Takashi)
Added comment for av_enc_map[] definition. (Takashi)
v3:
Fixed logic error introduced while renaming 'dev_id' as 'pipe' (Ville)
Renamed get_saved_encoder() to get_saved_enc() to reduce line length
v4:
Rebased.
Parameter check for pipe < -1 values in get_saved_enc() (Ville)
Switched to for_each_pipe() in get_saved_enc() (Ville)
Renamed 'pipe' to 'dev_id' in audio side code (Takashi)
v5:
Included a comment for the dev_id arg. (Libin)
Signed-off-by: Dhinakaran Pandiyan <dhinakaran.pandiyan@intel.com>
Reviewed-by: Takashi Iwai <tiwai@suse.de>
Reviewed-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
Signed-off-by: Rodrigo Vivi <rodrigo.vivi@intel.com>
Link: http://patchwork.freedesktop.org/patch/msgid/1474488168-2343-1-git-send-email-dhinakaran.pandiyan@intel.com
2016-09-21 14:02:48 -06:00
|
|
|
static void hdac_hdmi_eld_notify_cb(void *aptr, int port, int pipe)
|
2016-02-11 19:16:01 -07:00
|
|
|
{
|
2018-06-01 21:53:49 -06:00
|
|
|
struct hdac_device *hdev = aptr;
|
|
|
|
struct hdac_hdmi_priv *hdmi = hdev_to_hdmi_priv(hdev);
|
2017-02-05 23:39:14 -07:00
|
|
|
struct hdac_hdmi_pin *pin = NULL;
|
|
|
|
struct hdac_hdmi_port *hport = NULL;
|
2018-06-01 21:53:49 -06:00
|
|
|
struct snd_soc_component *component = hdmi->component;
|
2017-02-05 23:39:18 -07:00
|
|
|
int i;
|
2018-11-10 14:18:46 -07:00
|
|
|
hda_nid_t pin_nid;
|
|
|
|
|
|
|
|
if (!hdmi->drv_data->port_num) {
|
|
|
|
/* for legacy platforms */
|
|
|
|
pin_nid = port + 0x04;
|
|
|
|
} else if (port < hdmi->drv_data->port_num) {
|
|
|
|
/* get pin number from the pin2port mapping table */
|
|
|
|
pin_nid = hdmi->drv_data->port_map[port - 1];
|
|
|
|
} else {
|
|
|
|
dev_err(&hdev->dev, "Can't find the pin for port %d\n", port);
|
|
|
|
return;
|
|
|
|
}
|
2016-02-11 19:16:01 -07:00
|
|
|
|
2018-06-01 21:53:49 -06:00
|
|
|
dev_dbg(&hdev->dev, "%s: for pin:%d port=%d\n", __func__,
|
2017-02-05 23:39:14 -07:00
|
|
|
pin_nid, pipe);
|
2016-02-11 19:16:01 -07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* skip notification during system suspend (but not in runtime PM);
|
|
|
|
* the state will be updated at resume. Also since the ELD and
|
|
|
|
* connection states are updated in anyway at the end of the resume,
|
|
|
|
* we can skip it when received during PM process.
|
|
|
|
*/
|
2018-01-28 21:36:54 -07:00
|
|
|
if (snd_power_get_state(component->card->snd_card) !=
|
2016-02-11 19:16:01 -07:00
|
|
|
SNDRV_CTL_POWER_D0)
|
|
|
|
return;
|
|
|
|
|
2018-06-01 21:53:49 -06:00
|
|
|
if (atomic_read(&hdev->in_pm))
|
2016-02-11 19:16:01 -07:00
|
|
|
return;
|
|
|
|
|
|
|
|
list_for_each_entry(pin, &hdmi->pin_list, head) {
|
2017-02-05 23:39:14 -07:00
|
|
|
if (pin->nid != pin_nid)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/* In case of non MST pin, pipe is -1 */
|
|
|
|
if (pipe == -1) {
|
2017-02-05 23:39:18 -07:00
|
|
|
pin->mst_capable = false;
|
2017-02-05 23:39:14 -07:00
|
|
|
/* if not MST, default is port[0] */
|
|
|
|
hport = &pin->ports[0];
|
2017-02-05 23:39:18 -07:00
|
|
|
} else {
|
|
|
|
for (i = 0; i < pin->num_ports; i++) {
|
|
|
|
pin->mst_capable = true;
|
|
|
|
if (pin->ports[i].id == pipe) {
|
|
|
|
hport = &pin->ports[i];
|
2017-03-01 10:11:23 -07:00
|
|
|
break;
|
2017-02-05 23:39:18 -07:00
|
|
|
}
|
|
|
|
}
|
2017-02-05 23:39:14 -07:00
|
|
|
}
|
2017-03-01 10:11:23 -07:00
|
|
|
|
|
|
|
if (hport)
|
|
|
|
hdac_hdmi_present_sense(pin, hport);
|
2016-02-11 19:16:01 -07:00
|
|
|
}
|
2017-02-05 23:39:14 -07:00
|
|
|
|
2016-02-11 19:16:01 -07:00
|
|
|
}
|
|
|
|
|
2018-07-11 07:17:22 -06:00
|
|
|
static struct drm_audio_component_audio_ops aops = {
|
ALSA: hda: Make audio component support more generic
This is the final step for more generic support of DRM audio
component. The generic audio component code is now moved to its own
file, and the symbols are renamed from snd_hac_i915_* to
snd_hdac_acomp_*, respectively. The generic code is enabled via the
new kconfig, CONFIG_SND_HDA_COMPONENT, while CONFIG_SND_HDA_I915 is
kept as the super-class.
Along with the split, three new callbacks are added to audio_ops:
pin2port is for providing the conversion between the pin number and
the widget id, and master_bind/master_unbin are called at binding /
unbinding the master component, respectively. All these are optional,
but used in i915 implementation and also other later implementations.
A note about the new snd_hdac_acomp_init() function: there is a slight
difference between this and the old snd_hdac_i915_init(). The latter
(still) synchronizes with the master component binding, i.e. it
assures that the relevant DRM component gets bound when it returns, or
gives a negative error. Meanwhile the new function doesn't
synchronize but just leaves as is. It's the responsibility by the
caller's side to synchronize, or the caller may accept the
asynchronous binding on the fly.
v1->v2: Fix missing NULL check in master_bind/unbind
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2018-07-11 08:23:16 -06:00
|
|
|
.pin2port = hdac_hdmi_pin2port,
|
2016-02-11 19:16:01 -07:00
|
|
|
.pin_eld_notify = hdac_hdmi_eld_notify_cb,
|
|
|
|
};
|
|
|
|
|
2016-04-13 22:37:34 -06:00
|
|
|
static struct snd_pcm *hdac_hdmi_get_pcm_from_id(struct snd_soc_card *card,
|
|
|
|
int device)
|
|
|
|
{
|
|
|
|
struct snd_soc_pcm_runtime *rtd;
|
|
|
|
|
2018-09-17 19:29:35 -06:00
|
|
|
for_each_card_rtds(card, rtd) {
|
2016-04-13 22:37:34 -06:00
|
|
|
if (rtd->pcm && (rtd->pcm->device == device))
|
|
|
|
return rtd->pcm;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2017-02-07 06:39:55 -07:00
|
|
|
/* create jack pin kcontrols */
|
|
|
|
static int create_fill_jack_kcontrols(struct snd_soc_card *card,
|
2018-06-01 21:53:49 -06:00
|
|
|
struct hdac_device *hdev)
|
2017-02-07 06:39:55 -07:00
|
|
|
{
|
|
|
|
struct hdac_hdmi_pin *pin;
|
|
|
|
struct snd_kcontrol_new *kc;
|
|
|
|
char kc_name[NAME_SIZE], xname[NAME_SIZE];
|
|
|
|
char *name;
|
|
|
|
int i = 0, j;
|
2018-06-01 21:53:49 -06:00
|
|
|
struct hdac_hdmi_priv *hdmi = hdev_to_hdmi_priv(hdev);
|
|
|
|
struct snd_soc_component *component = hdmi->component;
|
2017-02-07 06:39:55 -07:00
|
|
|
|
2018-01-28 21:36:54 -07:00
|
|
|
kc = devm_kcalloc(component->dev, hdmi->num_ports,
|
2017-02-07 06:39:55 -07:00
|
|
|
sizeof(*kc), GFP_KERNEL);
|
|
|
|
|
|
|
|
if (!kc)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
list_for_each_entry(pin, &hdmi->pin_list, head) {
|
|
|
|
for (j = 0; j < pin->num_ports; j++) {
|
|
|
|
snprintf(xname, sizeof(xname), "hif%d-%d Jack",
|
|
|
|
pin->nid, pin->ports[j].id);
|
2018-01-28 21:36:54 -07:00
|
|
|
name = devm_kstrdup(component->dev, xname, GFP_KERNEL);
|
2017-02-07 06:39:55 -07:00
|
|
|
if (!name)
|
|
|
|
return -ENOMEM;
|
|
|
|
snprintf(kc_name, sizeof(kc_name), "%s Switch", xname);
|
2018-01-28 21:36:54 -07:00
|
|
|
kc[i].name = devm_kstrdup(component->dev, kc_name,
|
2017-02-07 06:39:55 -07:00
|
|
|
GFP_KERNEL);
|
|
|
|
if (!kc[i].name)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
kc[i].private_value = (unsigned long)name;
|
|
|
|
kc[i].iface = SNDRV_CTL_ELEM_IFACE_MIXER;
|
|
|
|
kc[i].access = 0;
|
|
|
|
kc[i].info = snd_soc_dapm_info_pin_switch;
|
|
|
|
kc[i].put = snd_soc_dapm_put_pin_switch;
|
|
|
|
kc[i].get = snd_soc_dapm_get_pin_switch;
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return snd_soc_add_card_controls(card, kc, i);
|
|
|
|
}
|
|
|
|
|
2018-01-28 21:36:54 -07:00
|
|
|
int hdac_hdmi_jack_port_init(struct snd_soc_component *component,
|
2017-02-07 06:39:55 -07:00
|
|
|
struct snd_soc_dapm_context *dapm)
|
|
|
|
{
|
2018-06-01 21:53:49 -06:00
|
|
|
struct hdac_hdmi_priv *hdmi = snd_soc_component_get_drvdata(component);
|
|
|
|
struct hdac_device *hdev = hdmi->hdev;
|
2017-02-07 06:39:55 -07:00
|
|
|
struct hdac_hdmi_pin *pin;
|
|
|
|
struct snd_soc_dapm_widget *widgets;
|
|
|
|
struct snd_soc_dapm_route *route;
|
|
|
|
char w_name[NAME_SIZE];
|
|
|
|
int i = 0, j, ret;
|
|
|
|
|
|
|
|
widgets = devm_kcalloc(dapm->dev, hdmi->num_ports,
|
|
|
|
sizeof(*widgets), GFP_KERNEL);
|
|
|
|
|
|
|
|
if (!widgets)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
route = devm_kcalloc(dapm->dev, hdmi->num_ports,
|
|
|
|
sizeof(*route), GFP_KERNEL);
|
|
|
|
if (!route)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
/* create Jack DAPM widget */
|
|
|
|
list_for_each_entry(pin, &hdmi->pin_list, head) {
|
|
|
|
for (j = 0; j < pin->num_ports; j++) {
|
|
|
|
snprintf(w_name, sizeof(w_name), "hif%d-%d Jack",
|
|
|
|
pin->nid, pin->ports[j].id);
|
|
|
|
|
|
|
|
ret = hdac_hdmi_fill_widget_info(dapm->dev, &widgets[i],
|
|
|
|
snd_soc_dapm_spk, NULL,
|
|
|
|
w_name, NULL, NULL, 0, NULL, 0);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
pin->ports[j].jack_pin = widgets[i].name;
|
|
|
|
pin->ports[j].dapm = dapm;
|
|
|
|
|
|
|
|
/* add to route from Jack widget to output */
|
|
|
|
hdac_hdmi_fill_route(&route[i], pin->ports[j].jack_pin,
|
|
|
|
NULL, pin->ports[j].output_pin, NULL);
|
|
|
|
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Add Route from Jack widget to the output widget */
|
|
|
|
ret = snd_soc_dapm_new_controls(dapm, widgets, hdmi->num_ports);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
ret = snd_soc_dapm_add_routes(dapm, route, hdmi->num_ports);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
ret = snd_soc_dapm_new_widgets(dapm->card);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
/* Add Jack Pin switch Kcontrol */
|
2018-06-01 21:53:49 -06:00
|
|
|
ret = create_fill_jack_kcontrols(dapm->card, hdev);
|
2017-02-07 06:39:55 -07:00
|
|
|
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
/* default set the Jack Pin switch to OFF */
|
|
|
|
list_for_each_entry(pin, &hdmi->pin_list, head) {
|
|
|
|
for (j = 0; j < pin->num_ports; j++)
|
|
|
|
snd_soc_dapm_disable_pin(pin->ports[j].dapm,
|
|
|
|
pin->ports[j].jack_pin);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(hdac_hdmi_jack_port_init);
|
|
|
|
|
2017-02-07 06:39:49 -07:00
|
|
|
int hdac_hdmi_jack_init(struct snd_soc_dai *dai, int device,
|
|
|
|
struct snd_soc_jack *jack)
|
2016-02-11 19:16:06 -07:00
|
|
|
{
|
2018-01-28 21:36:54 -07:00
|
|
|
struct snd_soc_component *component = dai->component;
|
2018-06-01 21:53:49 -06:00
|
|
|
struct hdac_hdmi_priv *hdmi = snd_soc_component_get_drvdata(component);
|
|
|
|
struct hdac_device *hdev = hdmi->hdev;
|
2016-02-11 19:16:06 -07:00
|
|
|
struct hdac_hdmi_pcm *pcm;
|
2016-04-13 22:37:34 -06:00
|
|
|
struct snd_pcm *snd_pcm;
|
|
|
|
int err;
|
2016-02-11 19:16:06 -07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* this is a new PCM device, create new pcm and
|
|
|
|
* add to the pcm list
|
|
|
|
*/
|
2019-02-08 16:26:53 -07:00
|
|
|
pcm = devm_kzalloc(&hdev->dev, sizeof(*pcm), GFP_KERNEL);
|
2016-02-11 19:16:06 -07:00
|
|
|
if (!pcm)
|
|
|
|
return -ENOMEM;
|
|
|
|
pcm->pcm_id = device;
|
|
|
|
pcm->cvt = hdmi->dai_map[dai->id].cvt;
|
2017-02-07 06:39:48 -07:00
|
|
|
pcm->jack_event = 0;
|
2017-02-07 06:39:49 -07:00
|
|
|
pcm->jack = jack;
|
2017-01-24 09:19:05 -07:00
|
|
|
mutex_init(&pcm->lock);
|
2017-02-07 06:39:48 -07:00
|
|
|
INIT_LIST_HEAD(&pcm->port_list);
|
2016-04-13 22:37:34 -06:00
|
|
|
snd_pcm = hdac_hdmi_get_pcm_from_id(dai->component->card, device);
|
|
|
|
if (snd_pcm) {
|
|
|
|
err = snd_hdac_add_chmap_ctls(snd_pcm, device, &hdmi->chmap);
|
|
|
|
if (err < 0) {
|
2018-06-01 21:53:49 -06:00
|
|
|
dev_err(&hdev->dev,
|
2016-04-13 22:37:34 -06:00
|
|
|
"chmap control add failed with err: %d for pcm: %d\n",
|
|
|
|
err, device);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-02-11 19:16:06 -07:00
|
|
|
list_add_tail(&pcm->head, &hdmi->pcm_list);
|
|
|
|
|
2017-02-07 06:39:49 -07:00
|
|
|
return 0;
|
2016-02-11 19:16:06 -07:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(hdac_hdmi_jack_init);
|
|
|
|
|
2018-06-01 21:53:49 -06:00
|
|
|
static void hdac_hdmi_present_sense_all_pins(struct hdac_device *hdev,
|
2017-02-07 06:39:46 -07:00
|
|
|
struct hdac_hdmi_priv *hdmi, bool detect_pin_caps)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
struct hdac_hdmi_pin *pin;
|
|
|
|
|
|
|
|
list_for_each_entry(pin, &hdmi->pin_list, head) {
|
|
|
|
if (detect_pin_caps) {
|
|
|
|
|
2018-06-01 21:53:49 -06:00
|
|
|
if (hdac_hdmi_get_port_len(hdev, pin->nid) == 0)
|
2017-02-07 06:39:46 -07:00
|
|
|
pin->mst_capable = false;
|
|
|
|
else
|
|
|
|
pin->mst_capable = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < pin->num_ports; i++) {
|
|
|
|
if (!pin->mst_capable && i > 0)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
hdac_hdmi_present_sense(pin, &pin->ports[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-28 21:36:54 -07:00
|
|
|
static int hdmi_codec_probe(struct snd_soc_component *component)
|
2015-11-10 06:12:06 -07:00
|
|
|
{
|
2018-06-01 21:53:49 -06:00
|
|
|
struct hdac_hdmi_priv *hdmi = snd_soc_component_get_drvdata(component);
|
|
|
|
struct hdac_device *hdev = hdmi->hdev;
|
2015-11-10 06:12:06 -07:00
|
|
|
struct snd_soc_dapm_context *dapm =
|
2018-01-28 21:36:54 -07:00
|
|
|
snd_soc_component_get_dapm(component);
|
2016-05-11 21:28:55 -06:00
|
|
|
struct hdac_ext_link *hlink = NULL;
|
2017-02-07 06:39:46 -07:00
|
|
|
int ret;
|
2015-11-10 06:12:06 -07:00
|
|
|
|
2018-06-01 21:53:49 -06:00
|
|
|
hdmi->component = component;
|
2015-11-10 06:12:06 -07:00
|
|
|
|
2016-05-11 21:28:55 -06:00
|
|
|
/*
|
|
|
|
* hold the ref while we probe, also no need to drop the ref on
|
|
|
|
* exit, we call pm_runtime_suspend() so that will do for us
|
|
|
|
*/
|
2018-06-01 21:53:50 -06:00
|
|
|
hlink = snd_hdac_ext_bus_get_link(hdev->bus, dev_name(&hdev->dev));
|
2016-05-31 07:39:55 -06:00
|
|
|
if (!hlink) {
|
2018-06-01 21:53:49 -06:00
|
|
|
dev_err(&hdev->dev, "hdac link not found\n");
|
2016-05-31 07:39:55 -06:00
|
|
|
return -EIO;
|
|
|
|
}
|
|
|
|
|
2018-06-01 21:53:50 -06:00
|
|
|
snd_hdac_ext_bus_link_get(hdev->bus, hlink);
|
2016-05-11 21:28:55 -06:00
|
|
|
|
2016-02-11 19:16:05 -07:00
|
|
|
ret = create_fill_widget_route_map(dapm);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
2015-11-10 06:12:06 -07:00
|
|
|
|
2018-06-01 21:53:49 -06:00
|
|
|
aops.audio_ptr = hdev;
|
ALSA: hda: Make audio component support more generic
This is the final step for more generic support of DRM audio
component. The generic audio component code is now moved to its own
file, and the symbols are renamed from snd_hac_i915_* to
snd_hdac_acomp_*, respectively. The generic code is enabled via the
new kconfig, CONFIG_SND_HDA_COMPONENT, while CONFIG_SND_HDA_I915 is
kept as the super-class.
Along with the split, three new callbacks are added to audio_ops:
pin2port is for providing the conversion between the pin number and
the widget id, and master_bind/master_unbin are called at binding /
unbinding the master component, respectively. All these are optional,
but used in i915 implementation and also other later implementations.
A note about the new snd_hdac_acomp_init() function: there is a slight
difference between this and the old snd_hdac_i915_init(). The latter
(still) synchronizes with the master component binding, i.e. it
assures that the relevant DRM component gets bound when it returns, or
gives a negative error. Meanwhile the new function doesn't
synchronize but just leaves as is. It's the responsibility by the
caller's side to synchronize, or the caller may accept the
asynchronous binding on the fly.
v1->v2: Fix missing NULL check in master_bind/unbind
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2018-07-11 08:23:16 -06:00
|
|
|
ret = snd_hdac_acomp_register_notifier(hdev->bus, &aops);
|
2016-02-11 19:16:01 -07:00
|
|
|
if (ret < 0) {
|
2018-06-01 21:53:49 -06:00
|
|
|
dev_err(&hdev->dev, "notifier register failed: err: %d\n", ret);
|
2016-02-11 19:16:01 -07:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2018-06-01 21:53:49 -06:00
|
|
|
hdac_hdmi_present_sense_all_pins(hdev, hdmi, true);
|
2015-11-10 06:12:06 -07:00
|
|
|
/* Imp: Store the card pointer in hda_codec */
|
2018-06-01 21:53:49 -06:00
|
|
|
hdmi->card = dapm->card->snd_card;
|
2015-11-10 06:12:06 -07:00
|
|
|
|
2019-04-13 07:18:12 -06:00
|
|
|
/*
|
|
|
|
* Setup a device_link between card device and HDMI codec device.
|
|
|
|
* The card device is the consumer and the HDMI codec device is
|
|
|
|
* the supplier. With this setting, we can make sure that the audio
|
|
|
|
* domain in display power will be always turned on before operating
|
|
|
|
* on the HDMI audio codec registers.
|
|
|
|
* Let's use the flag DL_FLAG_AUTOREMOVE_CONSUMER. This can make
|
|
|
|
* sure the device link is freed when the machine driver is removed.
|
|
|
|
*/
|
|
|
|
device_link_add(component->card->dev, &hdev->dev, DL_FLAG_RPM_ACTIVE |
|
|
|
|
DL_FLAG_AUTOREMOVE_CONSUMER);
|
2015-11-10 06:12:07 -07:00
|
|
|
/*
|
|
|
|
* hdac_device core already sets the state to active and calls
|
|
|
|
* get_noresume. So enable runtime and set the device to suspend.
|
|
|
|
*/
|
2018-06-01 21:53:49 -06:00
|
|
|
pm_runtime_enable(&hdev->dev);
|
|
|
|
pm_runtime_put(&hdev->dev);
|
|
|
|
pm_runtime_suspend(&hdev->dev);
|
2015-11-10 06:12:07 -07:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-01-28 21:36:54 -07:00
|
|
|
static void hdmi_codec_remove(struct snd_soc_component *component)
|
2015-11-10 06:12:07 -07:00
|
|
|
{
|
2018-06-01 21:53:49 -06:00
|
|
|
struct hdac_hdmi_priv *hdmi = snd_soc_component_get_drvdata(component);
|
|
|
|
struct hdac_device *hdev = hdmi->hdev;
|
2019-06-17 05:36:42 -06:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = snd_hdac_acomp_register_notifier(hdev->bus, NULL);
|
|
|
|
if (ret < 0)
|
|
|
|
dev_err(&hdev->dev, "notifier unregister failed: err: %d\n",
|
|
|
|
ret);
|
2015-11-10 06:12:07 -07:00
|
|
|
|
2018-06-01 21:53:49 -06:00
|
|
|
pm_runtime_disable(&hdev->dev);
|
2015-11-10 06:12:06 -07:00
|
|
|
}
|
|
|
|
|
2019-01-08 03:37:31 -07:00
|
|
|
#ifdef CONFIG_PM_SLEEP
|
|
|
|
static int hdmi_codec_resume(struct device *dev)
|
2016-02-21 19:20:33 -07:00
|
|
|
{
|
2018-06-01 21:53:49 -06:00
|
|
|
struct hdac_device *hdev = dev_to_hdac_dev(dev);
|
|
|
|
struct hdac_hdmi_priv *hdmi = hdev_to_hdmi_priv(hdev);
|
2019-01-08 03:37:31 -07:00
|
|
|
int ret;
|
2016-02-21 19:20:33 -07:00
|
|
|
|
2019-01-08 03:37:31 -07:00
|
|
|
ret = pm_runtime_force_resume(dev);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
2016-02-21 19:20:33 -07:00
|
|
|
/*
|
|
|
|
* As the ELD notify callback request is not entertained while the
|
|
|
|
* device is in suspend state. Need to manually check detection of
|
2017-02-07 06:39:46 -07:00
|
|
|
* all pins here. pin capablity change is not support, so use the
|
|
|
|
* already set pin caps.
|
2019-01-08 03:37:31 -07:00
|
|
|
*
|
|
|
|
* NOTE: this is safe to call even if the codec doesn't actually resume.
|
|
|
|
* The pin check involves only with DRM audio component hooks, so it
|
|
|
|
* works even if the HD-audio side is still dreaming peacefully.
|
2016-02-21 19:20:33 -07:00
|
|
|
*/
|
2018-06-01 21:53:49 -06:00
|
|
|
hdac_hdmi_present_sense_all_pins(hdev, hdmi, false);
|
2019-01-08 03:37:31 -07:00
|
|
|
return 0;
|
2016-02-21 19:20:33 -07:00
|
|
|
}
|
|
|
|
#else
|
2019-01-08 03:37:31 -07:00
|
|
|
#define hdmi_codec_resume NULL
|
2016-02-21 19:20:33 -07:00
|
|
|
#endif
|
|
|
|
|
2018-01-28 21:36:54 -07:00
|
|
|
static const struct snd_soc_component_driver hdmi_hda_codec = {
|
|
|
|
.probe = hdmi_codec_probe,
|
|
|
|
.remove = hdmi_codec_remove,
|
|
|
|
.use_pmdown_time = 1,
|
|
|
|
.endianness = 1,
|
|
|
|
.non_legacy_dai_naming = 1,
|
2015-11-10 06:12:06 -07:00
|
|
|
};
|
|
|
|
|
2017-12-01 02:13:19 -07:00
|
|
|
static void hdac_hdmi_get_chmap(struct hdac_device *hdev, int pcm_idx,
|
2016-04-13 22:37:34 -06:00
|
|
|
unsigned char *chmap)
|
|
|
|
{
|
2017-12-01 02:13:19 -07:00
|
|
|
struct hdac_hdmi_priv *hdmi = hdev_to_hdmi_priv(hdev);
|
2016-04-13 22:37:34 -06:00
|
|
|
struct hdac_hdmi_pcm *pcm = get_hdmi_pcm_from_id(hdmi, pcm_idx);
|
|
|
|
|
2017-01-24 09:19:05 -07:00
|
|
|
memcpy(chmap, pcm->chmap, ARRAY_SIZE(pcm->chmap));
|
2016-04-13 22:37:34 -06:00
|
|
|
}
|
|
|
|
|
2017-12-01 02:13:19 -07:00
|
|
|
static void hdac_hdmi_set_chmap(struct hdac_device *hdev, int pcm_idx,
|
2016-04-13 22:37:34 -06:00
|
|
|
unsigned char *chmap, int prepared)
|
|
|
|
{
|
2017-12-01 02:13:19 -07:00
|
|
|
struct hdac_hdmi_priv *hdmi = hdev_to_hdmi_priv(hdev);
|
2016-04-13 22:37:34 -06:00
|
|
|
struct hdac_hdmi_pcm *pcm = get_hdmi_pcm_from_id(hdmi, pcm_idx);
|
2017-02-07 06:39:48 -07:00
|
|
|
struct hdac_hdmi_port *port;
|
|
|
|
|
2017-11-07 03:46:25 -07:00
|
|
|
if (!pcm)
|
|
|
|
return;
|
|
|
|
|
2017-02-07 06:39:48 -07:00
|
|
|
if (list_empty(&pcm->port_list))
|
|
|
|
return;
|
2016-04-13 22:37:34 -06:00
|
|
|
|
2017-01-24 09:19:05 -07:00
|
|
|
mutex_lock(&pcm->lock);
|
|
|
|
pcm->chmap_set = true;
|
|
|
|
memcpy(pcm->chmap, chmap, ARRAY_SIZE(pcm->chmap));
|
2017-02-07 06:39:48 -07:00
|
|
|
list_for_each_entry(port, &pcm->port_list, head)
|
|
|
|
if (prepared)
|
2018-06-01 21:53:49 -06:00
|
|
|
hdac_hdmi_setup_audio_infoframe(hdev, pcm, port);
|
2017-01-24 09:19:05 -07:00
|
|
|
mutex_unlock(&pcm->lock);
|
2016-04-13 22:37:34 -06:00
|
|
|
}
|
|
|
|
|
2017-12-01 02:13:19 -07:00
|
|
|
static bool is_hdac_hdmi_pcm_attached(struct hdac_device *hdev, int pcm_idx)
|
2016-04-13 22:37:34 -06:00
|
|
|
{
|
2017-12-01 02:13:19 -07:00
|
|
|
struct hdac_hdmi_priv *hdmi = hdev_to_hdmi_priv(hdev);
|
2016-04-13 22:37:34 -06:00
|
|
|
struct hdac_hdmi_pcm *pcm = get_hdmi_pcm_from_id(hdmi, pcm_idx);
|
|
|
|
|
2017-11-07 03:46:25 -07:00
|
|
|
if (!pcm)
|
|
|
|
return false;
|
|
|
|
|
2017-02-07 06:39:48 -07:00
|
|
|
if (list_empty(&pcm->port_list))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
2016-04-13 22:37:34 -06:00
|
|
|
}
|
|
|
|
|
2017-12-01 02:13:19 -07:00
|
|
|
static int hdac_hdmi_get_spk_alloc(struct hdac_device *hdev, int pcm_idx)
|
2016-04-13 22:37:34 -06:00
|
|
|
{
|
2017-12-01 02:13:19 -07:00
|
|
|
struct hdac_hdmi_priv *hdmi = hdev_to_hdmi_priv(hdev);
|
2016-04-13 22:37:34 -06:00
|
|
|
struct hdac_hdmi_pcm *pcm = get_hdmi_pcm_from_id(hdmi, pcm_idx);
|
2017-02-07 06:39:48 -07:00
|
|
|
struct hdac_hdmi_port *port;
|
|
|
|
|
2017-11-07 03:46:25 -07:00
|
|
|
if (!pcm)
|
|
|
|
return 0;
|
|
|
|
|
2017-02-07 06:39:48 -07:00
|
|
|
if (list_empty(&pcm->port_list))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
port = list_first_entry(&pcm->port_list, struct hdac_hdmi_port, head);
|
|
|
|
|
2017-02-05 23:39:14 -07:00
|
|
|
if (!port || !port->eld.eld_valid)
|
2016-04-13 22:37:34 -06:00
|
|
|
return 0;
|
|
|
|
|
2017-02-05 23:39:14 -07:00
|
|
|
return port->eld.info.spk_alloc;
|
2016-04-13 22:37:34 -06:00
|
|
|
}
|
|
|
|
|
2018-11-10 14:18:46 -07:00
|
|
|
static struct hdac_hdmi_drv_data intel_icl_drv_data = {
|
|
|
|
.vendor_nid = INTEL_VENDOR_NID_0x2,
|
|
|
|
.port_map = icl_pin2port_map,
|
|
|
|
.port_num = ARRAY_SIZE(icl_pin2port_map),
|
|
|
|
};
|
|
|
|
|
2017-07-20 00:10:56 -06:00
|
|
|
static struct hdac_hdmi_drv_data intel_glk_drv_data = {
|
2018-11-10 14:18:46 -07:00
|
|
|
.vendor_nid = INTEL_VENDOR_NID_0xb,
|
2017-07-20 00:10:56 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
static struct hdac_hdmi_drv_data intel_drv_data = {
|
2018-11-10 14:18:46 -07:00
|
|
|
.vendor_nid = INTEL_VENDOR_NID_0x8,
|
2017-07-20 00:10:56 -06:00
|
|
|
};
|
|
|
|
|
2018-06-01 21:53:49 -06:00
|
|
|
static int hdac_hdmi_dev_probe(struct hdac_device *hdev)
|
2015-11-10 06:12:06 -07:00
|
|
|
{
|
2018-06-01 21:53:49 -06:00
|
|
|
struct hdac_hdmi_priv *hdmi_priv = NULL;
|
2016-02-11 19:16:04 -07:00
|
|
|
struct snd_soc_dai_driver *hdmi_dais = NULL;
|
2016-05-11 21:28:55 -06:00
|
|
|
struct hdac_ext_link *hlink = NULL;
|
2016-02-11 19:16:04 -07:00
|
|
|
int num_dais = 0;
|
2015-11-10 06:12:06 -07:00
|
|
|
int ret = 0;
|
2017-12-01 02:13:19 -07:00
|
|
|
struct hdac_driver *hdrv = drv_to_hdac_driver(hdev->dev.driver);
|
|
|
|
const struct hda_device_id *hdac_id = hdac_get_device_id(hdev, hdrv);
|
2015-11-10 06:12:06 -07:00
|
|
|
|
2016-05-11 21:28:55 -06:00
|
|
|
/* hold the ref while we probe */
|
2018-06-01 21:53:50 -06:00
|
|
|
hlink = snd_hdac_ext_bus_get_link(hdev->bus, dev_name(&hdev->dev));
|
2016-05-31 07:39:55 -06:00
|
|
|
if (!hlink) {
|
2018-06-01 21:53:49 -06:00
|
|
|
dev_err(&hdev->dev, "hdac link not found\n");
|
2016-05-31 07:39:55 -06:00
|
|
|
return -EIO;
|
|
|
|
}
|
|
|
|
|
2018-06-01 21:53:50 -06:00
|
|
|
snd_hdac_ext_bus_link_get(hdev->bus, hlink);
|
2016-05-11 21:28:55 -06:00
|
|
|
|
2017-12-01 02:13:19 -07:00
|
|
|
hdmi_priv = devm_kzalloc(&hdev->dev, sizeof(*hdmi_priv), GFP_KERNEL);
|
2015-11-10 06:12:06 -07:00
|
|
|
if (hdmi_priv == NULL)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
2017-12-01 02:13:19 -07:00
|
|
|
snd_hdac_register_chmap_ops(hdev, &hdmi_priv->chmap);
|
2016-04-13 22:37:34 -06:00
|
|
|
hdmi_priv->chmap.ops.get_chmap = hdac_hdmi_get_chmap;
|
|
|
|
hdmi_priv->chmap.ops.set_chmap = hdac_hdmi_set_chmap;
|
|
|
|
hdmi_priv->chmap.ops.is_pcm_attached = is_hdac_hdmi_pcm_attached;
|
|
|
|
hdmi_priv->chmap.ops.get_spk_alloc = hdac_hdmi_get_spk_alloc;
|
2018-06-01 21:53:49 -06:00
|
|
|
hdmi_priv->hdev = hdev;
|
2015-11-10 06:12:06 -07:00
|
|
|
|
2017-11-07 03:46:25 -07:00
|
|
|
if (!hdac_id)
|
|
|
|
return -ENODEV;
|
|
|
|
|
2017-07-20 00:10:56 -06:00
|
|
|
if (hdac_id->driver_data)
|
|
|
|
hdmi_priv->drv_data =
|
|
|
|
(struct hdac_hdmi_drv_data *)hdac_id->driver_data;
|
|
|
|
else
|
|
|
|
hdmi_priv->drv_data = &intel_drv_data;
|
|
|
|
|
2018-06-01 21:53:49 -06:00
|
|
|
dev_set_drvdata(&hdev->dev, hdmi_priv);
|
2015-11-10 06:12:06 -07:00
|
|
|
|
2015-12-09 09:16:10 -07:00
|
|
|
INIT_LIST_HEAD(&hdmi_priv->pin_list);
|
|
|
|
INIT_LIST_HEAD(&hdmi_priv->cvt_list);
|
2016-02-11 19:16:06 -07:00
|
|
|
INIT_LIST_HEAD(&hdmi_priv->pcm_list);
|
|
|
|
mutex_init(&hdmi_priv->pin_mutex);
|
2015-12-09 09:16:10 -07:00
|
|
|
|
2016-02-17 09:04:01 -07:00
|
|
|
/*
|
|
|
|
* Turned off in the runtime_suspend during the first explicit
|
|
|
|
* pm_runtime_suspend call.
|
|
|
|
*/
|
2018-12-09 02:04:25 -07:00
|
|
|
snd_hdac_display_power(hdev->bus, hdev->addr, true);
|
|
|
|
|
2018-06-01 21:53:49 -06:00
|
|
|
ret = hdac_hdmi_parse_and_map_nid(hdev, &hdmi_dais, &num_dais);
|
2016-02-11 19:16:04 -07:00
|
|
|
if (ret < 0) {
|
2017-12-01 02:13:19 -07:00
|
|
|
dev_err(&hdev->dev,
|
2016-02-11 19:16:04 -07:00
|
|
|
"Failed in parse and map nid with err: %d\n", ret);
|
2015-11-10 06:12:06 -07:00
|
|
|
return ret;
|
2016-02-11 19:16:04 -07:00
|
|
|
}
|
2019-07-03 06:35:12 -06:00
|
|
|
snd_hdac_refresh_widgets(hdev);
|
2015-11-10 06:12:06 -07:00
|
|
|
|
|
|
|
/* ASoC specific initialization */
|
2018-01-28 21:36:54 -07:00
|
|
|
ret = devm_snd_soc_register_component(&hdev->dev, &hdmi_hda_codec,
|
2016-05-11 21:28:55 -06:00
|
|
|
hdmi_dais, num_dais);
|
|
|
|
|
2018-06-01 21:53:50 -06:00
|
|
|
snd_hdac_ext_bus_link_put(hdev->bus, hlink);
|
2016-05-11 21:28:55 -06:00
|
|
|
|
|
|
|
return ret;
|
2015-11-10 06:12:06 -07:00
|
|
|
}
|
|
|
|
|
2019-08-09 09:15:31 -06:00
|
|
|
static void clear_dapm_works(struct hdac_device *hdev)
|
|
|
|
{
|
|
|
|
struct hdac_hdmi_priv *hdmi = hdev_to_hdmi_priv(hdev);
|
|
|
|
struct hdac_hdmi_pin *pin;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
list_for_each_entry(pin, &hdmi->pin_list, head)
|
|
|
|
for (i = 0; i < pin->num_ports; i++)
|
|
|
|
cancel_work_sync(&pin->ports[i].dapm_work);
|
|
|
|
}
|
|
|
|
|
2018-06-01 21:53:49 -06:00
|
|
|
static int hdac_hdmi_dev_remove(struct hdac_device *hdev)
|
2015-11-10 06:12:06 -07:00
|
|
|
{
|
2019-08-09 09:15:31 -06:00
|
|
|
clear_dapm_works(hdev);
|
2018-12-09 02:06:59 -07:00
|
|
|
snd_hdac_display_power(hdev->bus, hdev->addr, false);
|
|
|
|
|
2015-11-10 06:12:06 -07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-11-10 06:12:07 -07:00
|
|
|
#ifdef CONFIG_PM
|
|
|
|
static int hdac_hdmi_runtime_suspend(struct device *dev)
|
|
|
|
{
|
2018-06-01 21:53:49 -06:00
|
|
|
struct hdac_device *hdev = dev_to_hdac_dev(dev);
|
2017-12-01 02:13:19 -07:00
|
|
|
struct hdac_bus *bus = hdev->bus;
|
2016-05-11 21:28:55 -06:00
|
|
|
struct hdac_ext_link *hlink = NULL;
|
2015-11-10 06:12:07 -07:00
|
|
|
|
|
|
|
dev_dbg(dev, "Enter: %s\n", __func__);
|
|
|
|
|
2015-11-10 06:12:10 -07:00
|
|
|
/* controller may not have been initialized for the first time */
|
|
|
|
if (!bus)
|
|
|
|
return 0;
|
|
|
|
|
2019-08-09 09:15:31 -06:00
|
|
|
clear_dapm_works(hdev);
|
|
|
|
|
2016-04-01 02:06:26 -06:00
|
|
|
/*
|
|
|
|
* Power down afg.
|
|
|
|
* codec_read is preferred over codec_write to set the power state.
|
|
|
|
* This way verb is send to set the power state and response
|
|
|
|
* is received. So setting power state is ensured without using loop
|
|
|
|
* to read the state.
|
|
|
|
*/
|
2017-12-01 02:13:19 -07:00
|
|
|
snd_hdac_codec_read(hdev, hdev->afg, 0, AC_VERB_SET_POWER_STATE,
|
2016-04-01 02:06:26 -06:00
|
|
|
AC_PWRST_D3);
|
2015-11-10 06:12:10 -07:00
|
|
|
|
2018-06-01 21:53:50 -06:00
|
|
|
hlink = snd_hdac_ext_bus_get_link(bus, dev_name(dev));
|
2016-05-31 07:39:55 -06:00
|
|
|
if (!hlink) {
|
|
|
|
dev_err(dev, "hdac link not found\n");
|
|
|
|
return -EIO;
|
|
|
|
}
|
|
|
|
|
2019-07-02 07:24:26 -06:00
|
|
|
snd_hdac_codec_link_down(hdev);
|
2018-06-01 21:53:50 -06:00
|
|
|
snd_hdac_ext_bus_link_put(bus, hlink);
|
2016-05-11 21:28:55 -06:00
|
|
|
|
2018-12-09 02:04:25 -07:00
|
|
|
snd_hdac_display_power(bus, hdev->addr, false);
|
2018-11-09 12:39:23 -07:00
|
|
|
|
2018-12-09 02:04:25 -07:00
|
|
|
return 0;
|
2015-11-10 06:12:07 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static int hdac_hdmi_runtime_resume(struct device *dev)
|
|
|
|
{
|
2018-06-01 21:53:49 -06:00
|
|
|
struct hdac_device *hdev = dev_to_hdac_dev(dev);
|
2017-12-01 02:13:19 -07:00
|
|
|
struct hdac_bus *bus = hdev->bus;
|
2016-05-11 21:28:55 -06:00
|
|
|
struct hdac_ext_link *hlink = NULL;
|
2015-11-10 06:12:07 -07:00
|
|
|
|
|
|
|
dev_dbg(dev, "Enter: %s\n", __func__);
|
|
|
|
|
2015-11-10 06:12:10 -07:00
|
|
|
/* controller may not have been initialized for the first time */
|
|
|
|
if (!bus)
|
|
|
|
return 0;
|
|
|
|
|
2018-06-01 21:53:50 -06:00
|
|
|
hlink = snd_hdac_ext_bus_get_link(bus, dev_name(dev));
|
2016-05-31 07:39:55 -06:00
|
|
|
if (!hlink) {
|
|
|
|
dev_err(dev, "hdac link not found\n");
|
|
|
|
return -EIO;
|
|
|
|
}
|
|
|
|
|
2018-06-01 21:53:50 -06:00
|
|
|
snd_hdac_ext_bus_link_get(bus, hlink);
|
2019-07-02 07:24:26 -06:00
|
|
|
snd_hdac_codec_link_up(hdev);
|
2016-05-11 21:28:55 -06:00
|
|
|
|
2018-12-09 02:04:25 -07:00
|
|
|
snd_hdac_display_power(bus, hdev->addr, true);
|
2015-11-10 06:12:10 -07:00
|
|
|
|
2018-06-01 21:53:49 -06:00
|
|
|
hdac_hdmi_skl_enable_all_pins(hdev);
|
|
|
|
hdac_hdmi_skl_enable_dp12(hdev);
|
2016-02-17 09:04:02 -07:00
|
|
|
|
2015-11-10 06:12:07 -07:00
|
|
|
/* Power up afg */
|
2017-12-01 02:13:19 -07:00
|
|
|
snd_hdac_codec_read(hdev, hdev->afg, 0, AC_VERB_SET_POWER_STATE,
|
2016-04-01 02:06:26 -06:00
|
|
|
AC_PWRST_D0);
|
2015-11-10 06:12:07 -07:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
#define hdac_hdmi_runtime_suspend NULL
|
|
|
|
#define hdac_hdmi_runtime_resume NULL
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static const struct dev_pm_ops hdac_hdmi_pm = {
|
|
|
|
SET_RUNTIME_PM_OPS(hdac_hdmi_runtime_suspend, hdac_hdmi_runtime_resume, NULL)
|
2019-01-08 03:37:31 -07:00
|
|
|
SET_SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend, hdmi_codec_resume)
|
2015-11-10 06:12:07 -07:00
|
|
|
};
|
|
|
|
|
2015-11-10 06:12:06 -07:00
|
|
|
static const struct hda_device_id hdmi_list[] = {
|
|
|
|
HDA_CODEC_EXT_ENTRY(0x80862809, 0x100000, "Skylake HDMI", 0),
|
2016-03-10 21:42:55 -07:00
|
|
|
HDA_CODEC_EXT_ENTRY(0x8086280a, 0x100000, "Broxton HDMI", 0),
|
2016-07-11 10:32:09 -06:00
|
|
|
HDA_CODEC_EXT_ENTRY(0x8086280b, 0x100000, "Kabylake HDMI", 0),
|
2017-12-20 20:15:29 -07:00
|
|
|
HDA_CODEC_EXT_ENTRY(0x8086280c, 0x100000, "Cannonlake HDMI",
|
|
|
|
&intel_glk_drv_data),
|
2017-07-20 00:10:56 -06:00
|
|
|
HDA_CODEC_EXT_ENTRY(0x8086280d, 0x100000, "Geminilake HDMI",
|
|
|
|
&intel_glk_drv_data),
|
2018-11-10 14:18:46 -07:00
|
|
|
HDA_CODEC_EXT_ENTRY(0x8086280f, 0x100000, "Icelake HDMI",
|
|
|
|
&intel_icl_drv_data),
|
2015-11-10 06:12:06 -07:00
|
|
|
{}
|
|
|
|
};
|
|
|
|
|
|
|
|
MODULE_DEVICE_TABLE(hdaudio, hdmi_list);
|
|
|
|
|
2018-06-01 21:53:51 -06:00
|
|
|
static struct hdac_driver hdmi_driver = {
|
|
|
|
.driver = {
|
|
|
|
.name = "HDMI HDA Codec",
|
|
|
|
.pm = &hdac_hdmi_pm,
|
2015-11-10 06:12:06 -07:00
|
|
|
},
|
2018-06-01 21:53:51 -06:00
|
|
|
.id_table = hdmi_list,
|
2015-11-10 06:12:06 -07:00
|
|
|
.probe = hdac_hdmi_dev_probe,
|
|
|
|
.remove = hdac_hdmi_dev_remove,
|
|
|
|
};
|
|
|
|
|
|
|
|
static int __init hdmi_init(void)
|
|
|
|
{
|
|
|
|
return snd_hda_ext_driver_register(&hdmi_driver);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void __exit hdmi_exit(void)
|
|
|
|
{
|
|
|
|
snd_hda_ext_driver_unregister(&hdmi_driver);
|
|
|
|
}
|
|
|
|
|
|
|
|
module_init(hdmi_init);
|
|
|
|
module_exit(hdmi_exit);
|
|
|
|
|
|
|
|
MODULE_LICENSE("GPL v2");
|
|
|
|
MODULE_DESCRIPTION("HDMI HD codec");
|
|
|
|
MODULE_AUTHOR("Samreen Nilofer<samreen.nilofer@intel.com>");
|
|
|
|
MODULE_AUTHOR("Subhransu S. Prusty<subhransu.s.prusty@intel.com>");
|