From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 12D19C32767 for ; Sat, 4 Jan 2020 08:21:30 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id DDAD4215A4 for ; Sat, 4 Jan 2020 08:21:29 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org DDAD4215A4 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=suse.de Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 409966E3B7; Sat, 4 Jan 2020 08:21:29 +0000 (UTC) Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) by gabe.freedesktop.org (Postfix) with ESMTPS id 60CAD6E3B7 for ; Sat, 4 Jan 2020 08:21:28 +0000 (UTC) X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id DFCC9AD00; Sat, 4 Jan 2020 08:21:25 +0000 (UTC) Date: Sat, 04 Jan 2020 09:21:25 +0100 Message-ID: From: Takashi Iwai To: Lyude Paul Subject: Re: [PATCH 2/2] drm/nouveau: Add HD-audio component notifier support In-Reply-To: <22b7ae5b1535ae51333250b12f47e4e715be3795.camel@redhat.com> References: <20190722143815.7339-1-tiwai@suse.de> <20190722143815.7339-3-tiwai@suse.de> <22b7ae5b1535ae51333250b12f47e4e715be3795.camel@redhat.com> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI/1.14.6 (Maruoka) FLIM/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL/10.8 Emacs/25.3 (x86_64-suse-linux-gnu) MULE/6.0 (HANACHIRUSATO) MIME-Version: 1.0 (generated by SEMI 1.14.6 - "Maruoka") X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Maxime Ripard , dri-devel@lists.freedesktop.org, Ben Skeggs , Alex Deucher , Sean Paul , Christian =?UTF-8?B?S8O2bmln?= Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" On Sat, 04 Jan 2020 00:01:14 +0100, Lyude Paul wrote: > > Got shown this patch at work and realized it still needed review, so I went > ahead and did that :) > > Reviewed-by: Lyude Paul Thanks! Let me know if the submission of the patch is needed. Takashi > > On Mon, 2019-07-22 at 16:38 +0200, Takashi Iwai wrote: > > This patch adds the support for the notification of HD-audio hotplug > > via the already existing drm_audio_component framework. This allows > > us more reliable hotplug notification and ELD transfer without > > accessing HD-audio bus; it's more efficient, and more importantly, it > > works without waking up the runtime PM. > > > > The implementation is rather simplistic: nouveau driver provides the > > get_eld ops for HD-audio, and it notifies the audio hotplug via > > pin_eld_notify callback upon each nv50_audio_enable() and _disable() > > call. As the HD-audio pin assignment seems corresponding to the CRTC, > > the crtc->index number is passed directly as the zero-based port > > number. > > > > The bind and unbind callbacks handle the device-link so that it > > assures the PM call order. > > > > Signed-off-by: Takashi Iwai > > --- > > drivers/gpu/drm/nouveau/Kconfig | 1 + > > drivers/gpu/drm/nouveau/dispnv50/disp.c | 111 > > ++++++++++++++++++++++++++++++++ > > drivers/gpu/drm/nouveau/nouveau_drv.h | 7 ++ > > 3 files changed, 119 insertions(+) > > > > diff --git a/drivers/gpu/drm/nouveau/Kconfig > > b/drivers/gpu/drm/nouveau/Kconfig > > index 96b9814e6d06..33ccf11bd70d 100644 > > --- a/drivers/gpu/drm/nouveau/Kconfig > > +++ b/drivers/gpu/drm/nouveau/Kconfig > > @@ -16,6 +16,7 @@ config DRM_NOUVEAU > > select INPUT if ACPI && X86 > > select THERMAL if ACPI && X86 > > select ACPI_VIDEO if ACPI && X86 > > + select SND_HDA_COMPONENT if SND_HDA_CORE > > help > > Choose this option for open-source NVIDIA support. > > > > diff --git a/drivers/gpu/drm/nouveau/dispnv50/disp.c > > b/drivers/gpu/drm/nouveau/dispnv50/disp.c > > index 8497768f1b41..919f3d3db161 100644 > > --- a/drivers/gpu/drm/nouveau/dispnv50/disp.c > > +++ b/drivers/gpu/drm/nouveau/dispnv50/disp.c > > @@ -29,6 +29,7 @@ > > > > #include > > #include > > +#include > > > > #include > > #include > > @@ -466,12 +467,113 @@ nv50_dac_create(struct drm_connector *connector, > > struct dcb_output *dcbe) > > return 0; > > } > > > > +/* > > + * audio component binding for ELD notification > > + */ > > +static void > > +nv50_audio_component_eld_notify(struct drm_audio_component *acomp, int > > port) > > +{ > > + if (acomp && acomp->audio_ops && acomp->audio_ops->pin_eld_notify) > > + acomp->audio_ops->pin_eld_notify(acomp->audio_ops->audio_ptr, > > + port, -1); > > +} > > + > > +static int > > +nv50_audio_component_get_eld(struct device *kdev, int port, int pipe, > > + bool *enabled, unsigned char *buf, int max_bytes) > > +{ > > + struct drm_device *drm_dev = dev_get_drvdata(kdev); > > + struct nouveau_drm *drm = nouveau_drm(drm_dev); > > + struct drm_encoder *encoder; > > + struct nouveau_encoder *nv_encoder; > > + struct nouveau_connector *nv_connector; > > + struct nouveau_crtc *nv_crtc; > > + int ret = 0; > > + > > + *enabled = false; > > + drm_for_each_encoder(encoder, drm->dev) { > > + nv_encoder = nouveau_encoder(encoder); > > + nv_connector = nouveau_encoder_connector_get(nv_encoder); > > + nv_crtc = nouveau_crtc(encoder->crtc); > > + if (!nv_connector || !nv_crtc || nv_crtc->index != port) > > + continue; > > + *enabled = drm_detect_monitor_audio(nv_connector->edid); > > + if (*enabled) { > > + ret = drm_eld_size(nv_connector->base.eld); > > + memcpy(buf, nv_connector->base.eld, > > + min(max_bytes, ret)); > > + } > > + break; > > + } > > + return ret; > > +} > > + > > +static const struct drm_audio_component_ops nv50_audio_component_ops = { > > + .get_eld = nv50_audio_component_get_eld, > > +}; > > + > > +static int > > +nv50_audio_component_bind(struct device *kdev, struct device *hda_kdev, > > + void *data) > > +{ > > + struct drm_device *drm_dev = dev_get_drvdata(kdev); > > + struct nouveau_drm *drm = nouveau_drm(drm_dev); > > + struct drm_audio_component *acomp = data; > > + > > + if (WARN_ON(!device_link_add(hda_kdev, kdev, DL_FLAG_STATELESS))) > > + return -ENOMEM; > > + > > + drm_modeset_lock_all(drm_dev); > > + acomp->ops = &nv50_audio_component_ops; > > + acomp->dev = kdev; > > + drm->audio.component = acomp; > > + drm_modeset_unlock_all(drm_dev); > > + return 0; > > +} > > + > > +static void > > +nv50_audio_component_unbind(struct device *kdev, struct device *hda_kdev, > > + void *data) > > +{ > > + struct drm_device *drm_dev = dev_get_drvdata(kdev); > > + struct nouveau_drm *drm = nouveau_drm(drm_dev); > > + struct drm_audio_component *acomp = data; > > + > > + drm_modeset_lock_all(drm_dev); > > + drm->audio.component = NULL; > > + acomp->ops = NULL; > > + acomp->dev = NULL; > > + drm_modeset_unlock_all(drm_dev); > > +} > > + > > +static const struct component_ops nv50_audio_component_bind_ops = { > > + .bind = nv50_audio_component_bind, > > + .unbind = nv50_audio_component_unbind, > > +}; > > + > > +static void > > +nv50_audio_component_init(struct nouveau_drm *drm) > > +{ > > + if (!component_add(drm->dev->dev, &nv50_audio_component_bind_ops)) > > + drm->audio.component_registered = true; > > +} > > + > > +static void > > +nv50_audio_component_fini(struct nouveau_drm *drm) > > +{ > > + if (drm->audio.component_registered) { > > + component_del(drm->dev->dev, &nv50_audio_component_bind_ops); > > + drm->audio.component_registered = false; > > + } > > +} > > + > > /************************************************************************** > > **** > > * Audio > > > > **************************************************************************** > > */ > > static void > > nv50_audio_disable(struct drm_encoder *encoder, struct nouveau_crtc > > *nv_crtc) > > { > > + struct nouveau_drm *drm = nouveau_drm(encoder->dev); > > struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder); > > struct nv50_disp *disp = nv50_disp(encoder->dev); > > struct { > > @@ -486,11 +588,14 @@ nv50_audio_disable(struct drm_encoder *encoder, struct > > nouveau_crtc *nv_crtc) > > }; > > > > nvif_mthd(&disp->disp->object, 0, &args, sizeof(args)); > > + > > + nv50_audio_component_eld_notify(drm->audio.component, nv_crtc->index); > > } > > > > static void > > nv50_audio_enable(struct drm_encoder *encoder, struct drm_display_mode > > *mode) > > { > > + struct nouveau_drm *drm = nouveau_drm(encoder->dev); > > struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder); > > struct nouveau_crtc *nv_crtc = nouveau_crtc(encoder->crtc); > > struct nouveau_connector *nv_connector; > > @@ -517,6 +622,8 @@ nv50_audio_enable(struct drm_encoder *encoder, struct > > drm_display_mode *mode) > > > > nvif_mthd(&disp->disp->object, 0, &args, > > sizeof(args.base) + drm_eld_size(args.data)); > > + > > + nv50_audio_component_eld_notify(drm->audio.component, nv_crtc->index); > > } > > > > /************************************************************************** > > **** > > @@ -2281,6 +2388,8 @@ nv50_display_destroy(struct drm_device *dev) > > { > > struct nv50_disp *disp = nv50_disp(dev); > > > > + nv50_audio_component_fini(nouveau_drm(dev)); > > + > > nv50_core_del(&disp->core); > > > > nouveau_bo_unmap(disp->sync); > > @@ -2401,6 +2510,8 @@ nv50_display_create(struct drm_device *dev) > > /* Disable vblank irqs aggressively for power-saving, safe on nv50+ */ > > dev->vblank_disable_immediate = true; > > > > + nv50_audio_component_init(drm); > > + > > out: > > if (ret) > > nv50_display_destroy(dev); > > diff --git a/drivers/gpu/drm/nouveau/nouveau_drv.h > > b/drivers/gpu/drm/nouveau/nouveau_drv.h > > index aae035816383..15e4f2aa19bf 100644 > > --- a/drivers/gpu/drm/nouveau/nouveau_drv.h > > +++ b/drivers/gpu/drm/nouveau/nouveau_drv.h > > @@ -55,6 +55,8 @@ > > #include > > #include > > > > +#include > > + > > #include "uapi/drm/nouveau_drm.h" > > > > struct nouveau_channel; > > @@ -212,6 +214,11 @@ struct nouveau_drm { > > struct nouveau_svm *svm; > > > > struct nouveau_dmem *dmem; > > + > > + struct { > > + struct drm_audio_component *component; > > + bool component_registered; > > + } audio; > > }; > > > > static inline struct nouveau_drm * > -- > Cheers, > Lyude Paul > _______________________________________________ dri-devel mailing list dri-devel@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/dri-devel