279
304
const u8 *eld_buf;
283
308
list_for_each_entry(pin, &hdmi->pin_list, head) {
284
309
if (pin->nid == pin_nid)
313
ca = snd_hdac_channel_allocation(&hdac->hdac, pin->eld.info.spk_alloc,
314
pin->channels, pin->chmap_set, true, pin->chmap);
316
channels = snd_hdac_get_active_channels(ca);
317
hdmi->chmap.ops.set_channel_count(&hdac->hdac, cvt_nid, channels);
319
snd_hdac_setup_channel_mapping(&hdmi->chmap, pin->nid, false, ca,
320
pin->channels, pin->chmap, pin->chmap_set);
288
322
eld_buf = pin->eld.eld_buffer;
289
323
conn_type = drm_eld_get_conn_type(eld_buf);
291
/* setup channel count */
292
snd_hdac_codec_write(&hdac->hdac, cvt_nid, 0,
293
AC_VERB_SET_CVT_CHAN_COUNT, channels - 1);
295
325
switch (conn_type) {
296
326
case DRM_ELD_CONN_TYPE_HDMI:
297
327
hdmi_audio_infoframe_init(&frame);
299
/* Default stereo for now */
300
329
frame.channels = channels;
330
frame.channel_allocation = ca;
302
332
ret = hdmi_audio_infoframe_pack(&frame, buffer, sizeof(buffer));
370
400
struct hdac_ext_device *hdac = snd_soc_dai_get_drvdata(dai);
371
401
struct hdac_hdmi_priv *hdmi = hdac->private_data;
372
402
struct hdac_hdmi_dai_pin_map *dai_map;
403
struct hdac_hdmi_pin *pin;
373
404
struct hdac_ext_dma_params *dd;
376
407
dai_map = &hdmi->dai_map[dai->id];
378
410
dd = (struct hdac_ext_dma_params *)snd_soc_dai_get_dma_data(dai, substream);
379
411
dev_dbg(&hdac->hdac.dev, "stream tag from cpu dai %d format in cvt 0x%x\n",
380
412
dd->stream_tag, dd->format);
414
mutex_lock(&pin->lock);
415
pin->channels = substream->runtime->channels;
382
417
ret = hdac_hdmi_setup_audio_infoframe(hdac, dai_map->cvt->nid,
383
418
dai_map->pin->nid);
419
mutex_unlock(&pin->lock);
640
676
snd_hdac_codec_write(&hdac->hdac, dai_map->pin->nid, 0,
641
677
AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE);
679
mutex_lock(&dai_map->pin->lock);
680
dai_map->pin->chmap_set = false;
681
memset(dai_map->pin->chmap, 0, sizeof(dai_map->pin->chmap));
682
dai_map->pin->channels = 0;
683
mutex_unlock(&dai_map->pin->lock);
643
685
dai_map->pin = NULL;
648
690
hdac_hdmi_query_cvt_params(struct hdac_device *hdac, struct hdac_hdmi_cvt *cvt)
693
struct hdac_ext_device *edev = to_ehdac_device(hdac);
694
struct hdac_hdmi_priv *hdmi = edev->private_data;
652
/* Only stereo supported as of now */
653
cvt->params.channels_min = cvt->params.channels_max = 2;
697
chans = get_wcaps(hdac, cvt->nid);
698
chans = get_wcaps_channels(chans);
700
cvt->params.channels_min = 2;
702
cvt->params.channels_max = chans;
703
if (chans > hdmi->chmap.channels_max)
704
hdmi->chmap.channels_max = chans;
655
706
err = snd_hdac_query_supported_pcm(hdac, cvt->nid,
656
707
&cvt->params.rates,
1342
1401
.pin_eld_notify = hdac_hdmi_eld_notify_cb,
1404
static struct snd_pcm *hdac_hdmi_get_pcm_from_id(struct snd_soc_card *card,
1407
struct snd_soc_pcm_runtime *rtd;
1409
list_for_each_entry(rtd, &card->rtd_list, list) {
1410
if (rtd->pcm && (rtd->pcm->device == device))
1345
1417
int hdac_hdmi_jack_init(struct snd_soc_dai *dai, int device)
1347
1419
char jack_name[NAME_SIZE];
1362
1436
pcm->pcm_id = device;
1363
1437
pcm->cvt = hdmi->dai_map[dai->id].cvt;
1439
snd_pcm = hdac_hdmi_get_pcm_from_id(dai->component->card, device);
1441
err = snd_hdac_add_chmap_ctls(snd_pcm, device, &hdmi->chmap);
1443
dev_err(&edev->hdac.dev,
1444
"chmap control add failed with err: %d for pcm: %d\n",
1365
1451
list_add_tail(&pcm->head, &hdmi->pcm_list);
1367
1453
sprintf(jack_name, "HDMI/DP, pcm=%d Jack", device);
1378
1464
struct snd_soc_dapm_context *dapm =
1379
1465
snd_soc_component_get_dapm(&codec->component);
1380
1466
struct hdac_hdmi_pin *pin;
1467
struct hdac_ext_link *hlink = NULL;
1383
1470
edev->scodec = codec;
1473
* hold the ref while we probe, also no need to drop the ref on
1474
* exit, we call pm_runtime_suspend() so that will do for us
1476
hlink = snd_hdac_ext_bus_get_link(edev->ebus, dev_name(&edev->hdac.dev));
1477
snd_hdac_ext_bus_link_get(edev->ebus, hlink);
1385
1479
ret = create_fill_widget_route_map(dapm);
1475
1569
.idle_bias_off = true,
1572
static void hdac_hdmi_get_chmap(struct hdac_device *hdac, int pcm_idx,
1573
unsigned char *chmap)
1575
struct hdac_ext_device *edev = to_ehdac_device(hdac);
1576
struct hdac_hdmi_priv *hdmi = edev->private_data;
1577
struct hdac_hdmi_pcm *pcm = get_hdmi_pcm_from_id(hdmi, pcm_idx);
1578
struct hdac_hdmi_pin *pin = pcm->pin;
1580
/* chmap is already set to 0 in caller */
1584
memcpy(chmap, pin->chmap, ARRAY_SIZE(pin->chmap));
1587
static void hdac_hdmi_set_chmap(struct hdac_device *hdac, int pcm_idx,
1588
unsigned char *chmap, int prepared)
1590
struct hdac_ext_device *edev = to_ehdac_device(hdac);
1591
struct hdac_hdmi_priv *hdmi = edev->private_data;
1592
struct hdac_hdmi_pcm *pcm = get_hdmi_pcm_from_id(hdmi, pcm_idx);
1593
struct hdac_hdmi_pin *pin = pcm->pin;
1595
mutex_lock(&pin->lock);
1596
pin->chmap_set = true;
1597
memcpy(pin->chmap, chmap, ARRAY_SIZE(pin->chmap));
1599
hdac_hdmi_setup_audio_infoframe(edev, pcm->cvt->nid, pin->nid);
1600
mutex_unlock(&pin->lock);
1603
static bool is_hdac_hdmi_pcm_attached(struct hdac_device *hdac, int pcm_idx)
1605
struct hdac_ext_device *edev = to_ehdac_device(hdac);
1606
struct hdac_hdmi_priv *hdmi = edev->private_data;
1607
struct hdac_hdmi_pcm *pcm = get_hdmi_pcm_from_id(hdmi, pcm_idx);
1608
struct hdac_hdmi_pin *pin = pcm->pin;
1610
return pin ? true:false;
1613
static int hdac_hdmi_get_spk_alloc(struct hdac_device *hdac, int pcm_idx)
1615
struct hdac_ext_device *edev = to_ehdac_device(hdac);
1616
struct hdac_hdmi_priv *hdmi = edev->private_data;
1617
struct hdac_hdmi_pcm *pcm = get_hdmi_pcm_from_id(hdmi, pcm_idx);
1618
struct hdac_hdmi_pin *pin = pcm->pin;
1620
if (!pin || !pin->eld.eld_valid)
1623
return pin->eld.info.spk_alloc;
1478
1626
static int hdac_hdmi_dev_probe(struct hdac_ext_device *edev)
1480
1628
struct hdac_device *codec = &edev->hdac;
1481
1629
struct hdac_hdmi_priv *hdmi_priv;
1482
1630
struct snd_soc_dai_driver *hdmi_dais = NULL;
1631
struct hdac_ext_link *hlink = NULL;
1483
1632
int num_dais = 0;
1635
/* hold the ref while we probe */
1636
hlink = snd_hdac_ext_bus_get_link(edev->ebus, dev_name(&edev->hdac.dev));
1637
snd_hdac_ext_bus_link_get(edev->ebus, hlink);
1486
1639
hdmi_priv = devm_kzalloc(&codec->dev, sizeof(*hdmi_priv), GFP_KERNEL);
1487
1640
if (hdmi_priv == NULL)
1488
1641
return -ENOMEM;
1490
1643
edev->private_data = hdmi_priv;
1644
snd_hdac_register_chmap_ops(codec, &hdmi_priv->chmap);
1645
hdmi_priv->chmap.ops.get_chmap = hdac_hdmi_get_chmap;
1646
hdmi_priv->chmap.ops.set_chmap = hdac_hdmi_set_chmap;
1647
hdmi_priv->chmap.ops.is_pcm_attached = is_hdac_hdmi_pcm_attached;
1648
hdmi_priv->chmap.ops.get_spk_alloc = hdac_hdmi_get_spk_alloc;
1492
1650
dev_set_drvdata(&codec->dev, edev);