Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp3029259ybi; Fri, 5 Jul 2019 00:32:38 -0700 (PDT) X-Google-Smtp-Source: APXvYqyVDC5G315MgHg3sudL0+rT8u6OwkUYYGhAp8/YyBGVfay9oxauQkv/FgQSHYHJ23t3NWCj X-Received: by 2002:a17:90a:ab0b:: with SMTP id m11mr3382231pjq.73.1562311958266; Fri, 05 Jul 2019 00:32:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562311958; cv=none; d=google.com; s=arc-20160816; b=gmZrAlQXozZbI6GoRazf9CynuPvN7OXElXfCZG+MRhYJUt6TNkRLvLyJUtRthLJsKP JB294rwXQbqaAwYHxKOk/RUGSZ6ka2xM4Shc5Ap96D9stYn+A8QD9hNtBOhlu4FUcIF0 Ky0by82r9X7BuzqWOrTHKGu6/O8+W3MEj4BcL6HYGIo7s3GkeYcm8ETINvQcPhbXfb6n fYKt3HJsg3/mkjfROkZG11ZpIh72ipBiBMJH9S83DnstJ2gniA+8d9YeTNvLS9HVJ1my 6LTdc8PZ6vnQrS6UqusX5FTjHOUlkfQDdOa5bDAIO+r39am+0uZ8dE1U26wRtM/VJqV0 2UMA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=rMd1u8f9GUtGM2BNqO4dxPBPUfEK4qgo6+64JcBSfZo=; b=rwi4+9HAwWQ+XB14sd5Gw+2YUaQaWxbKLry8B9MdVFhNaeQxWGbOsAyy06+JNPcAIl FQMbMpUBceIHXeMcOUKOJikfveNINnvXdQfzugB6JaTnmi04sVbUj1dzpkQ8BMvbOBcI xxre4KwVXSID+dighCDdgb6Ub6YGJuCa5sQkkcNyCb8/biqCZRFMLIbKBMEXbaoLvPHn oIdc2ryeiroLZpg6isFsUhGMMSykneUF+G3TPpb1Y8bkyetsChIaZjkFFc7WHTTrdXbK g65ycvu5dMIZJjQvzOj1IIa5l+JKpPzsTzRFC7MXBwO0H24aCAXlWvWy0J2EdIHr+C9j xMvQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=NCAVIjM5; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b19si6769604pgl.189.2019.07.05.00.32.23; Fri, 05 Jul 2019 00:32:38 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=NCAVIjM5; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727767AbfGEHbx (ORCPT + 99 others); Fri, 5 Jul 2019 03:31:53 -0400 Received: from mail-vs1-f68.google.com ([209.85.217.68]:46127 "EHLO mail-vs1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725862AbfGEHbx (ORCPT ); Fri, 5 Jul 2019 03:31:53 -0400 Received: by mail-vs1-f68.google.com with SMTP id r3so3262968vsr.13 for ; Fri, 05 Jul 2019 00:31:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=rMd1u8f9GUtGM2BNqO4dxPBPUfEK4qgo6+64JcBSfZo=; b=NCAVIjM5oXEoOyTfLc1j5S059x2rfCv7/17EWp9Et1EVImM8xhz2b6qhUPm19tM+aD 3+ZVdwnBS+Jajb4BoM70kV1GQ47wbUmxTn50xE4ev9Bx8gVtRLhl8fBx3ZksvBDiuqrQ xUg2H8J4gy8WPGrDWXxNkCsWaztk5/XXtdEP4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=rMd1u8f9GUtGM2BNqO4dxPBPUfEK4qgo6+64JcBSfZo=; b=uCsA/pq3N3LMnv1zjtAK5FKr4ekYE347D5vjpaMCQ42VC8sQC499eUq5J2IjtOt7+u Q94nxE3aGSRbC7Ev9Z8qy9LuLsOEqmbkYq+mamQcgeN2T1ND73N2uxw6G1GkaNnsVoGx VTOqaaVgI39OsOGo9m02qhwtRuQoUXJRJJJ/lBVW4X3o02Ro8Z9Eov+M51k2zWrz7hWR L+pC8/CT7bi7ZKF8vkP2619Ii7ZwJHH7slih87OZtvViexlirFMbzYoln0SH3bScTUQ5 6cugZcrdzLG0SMxa1ghEkLy5uaI5+fKj6EkeYyKoD0WYVAVKuY/VEQJIaZdX0X7BvL38 /DJQ== X-Gm-Message-State: APjAAAXwgKSgWbNbJnYuh+IVrfyh20KooQF885g5PP/5r3Y+dY4ZIwR8 tXes+3tqgA8L0Mqq6SIENeoqVYZeH80GwDbkPsuQOw== X-Received: by 2002:a67:eada:: with SMTP id s26mr1279515vso.163.1562311911794; Fri, 05 Jul 2019 00:31:51 -0700 (PDT) MIME-Version: 1.0 References: <20190705042623.129541-1-cychiang@chromium.org> <20190705042623.129541-3-cychiang@chromium.org> In-Reply-To: From: Cheng-yi Chiang Date: Fri, 5 Jul 2019 15:31:24 +0800 Message-ID: Subject: Re: [alsa-devel] [PATCH 2/4] drm: bridge: dw-hdmi: Report connector status using callback To: Jonas Karlman Cc: "linux-kernel@vger.kernel.org" , "alsa-devel@alsa-project.org" , "dianders@chromium.org" , Heiko Stuebner , "linux-rockchip@lists.infradead.org" , David Airlie , "dri-devel@lists.freedesktop.org" , Takashi Iwai , Liam Girdwood , "tzungbi@chromium.org" , Hans Verkuil , Andrzej Hajda , Russell King , Mark Brown , Laurent Pinchart , Daniel Vetter , "dgreid@chromium.org" , "linux-arm-kernel@lists.infradead.org" Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jul 5, 2019 at 1:45 PM Jonas Karlman wrote: > > On 2019-07-05 06:26, Cheng-Yi Chiang wrote: > > Allow codec driver register callback function for plug event. > > > > The callback registration flow: > > dw-hdmi <--- hw-hdmi-i2s-audio <--- hdmi-codec > > > > dw-hdmi-i2s-audio implements hook_plugged_cb op > > so codec driver can register the callback. > > > > dw-hdmi implements set_plugged_cb op so platform device can register the > > callback. > > > > When connector plug/unplug event happens, report this event using the > > callback. > > > > Make sure that audio and drm are using the single source of truth for > > connector status. > > I have a similar notification need for making a snd_ctl_notify() call from hdmi-codec when ELD changes, > see [1] for work in progress patches (part of a dw-hdmi multi-channel lpcm series I am preparing). > > Any suggestions on how to handle a ELD change notification? > Should I use a similar pattern as in this series? Hi Jonas, I think we are using a very similar pattern. The difference is that in my series the function is not exposed on hdmi-codec.h. I think your method makes sense for your case because dw-hdmi-i2s-audio.c needs to access and update data inside dw_hdmi_i2s_audio_data, while in my use case it is only a thin layer setting up the callback for jack status. > (I lost track of the hdmi-notifier/drm_audio_component discussion) > It was a long discussion. I think the conclusion was that if we are only talking about hdmi-codec, then we just need to extend the ops exposed in hdmi-codec and don't need to use hdmi-notifier or drm_audio_component. > [1] https://github.com/Kwiboo/linux-rockchip/compare/54b40fdd264c7ed96017271eb6524cca4ff755ab...9c17284e8a8657e8b1da53a1c7ff056cbd8ce43c > > Best regards, > Jonas > > > > > Signed-off-by: Cheng-Yi Chiang > > --- > > .../gpu/drm/bridge/synopsys/dw-hdmi-audio.h | 3 ++ > > .../drm/bridge/synopsys/dw-hdmi-i2s-audio.c | 10 ++++++ > > drivers/gpu/drm/bridge/synopsys/dw-hdmi.c | 34 ++++++++++++++++++- > > 3 files changed, 46 insertions(+), 1 deletion(-) > > > > diff --git a/drivers/gpu/drm/bridge/synopsys/dw-hdmi-audio.h b/drivers/gpu/drm/bridge/synopsys/dw-hdmi-audio.h > > index 63b5756f463b..f523c590984e 100644 > > --- a/drivers/gpu/drm/bridge/synopsys/dw-hdmi-audio.h > > +++ b/drivers/gpu/drm/bridge/synopsys/dw-hdmi-audio.h > > @@ -2,6 +2,8 @@ > > #ifndef DW_HDMI_AUDIO_H > > #define DW_HDMI_AUDIO_H > > > > +#include > > + > > struct dw_hdmi; > > > > struct dw_hdmi_audio_data { > > @@ -17,6 +19,7 @@ struct dw_hdmi_i2s_audio_data { > > > > void (*write)(struct dw_hdmi *hdmi, u8 val, int offset); > > u8 (*read)(struct dw_hdmi *hdmi, int offset); > > + int (*set_plugged_cb)(struct dw_hdmi *hdmi, hdmi_codec_plugged_cb fn); > > }; > > > > #endif > > diff --git a/drivers/gpu/drm/bridge/synopsys/dw-hdmi-i2s-audio.c b/drivers/gpu/drm/bridge/synopsys/dw-hdmi-i2s-audio.c > > index 5cbb71a866d5..7b93cf05c985 100644 > > --- a/drivers/gpu/drm/bridge/synopsys/dw-hdmi-i2s-audio.c > > +++ b/drivers/gpu/drm/bridge/synopsys/dw-hdmi-i2s-audio.c > > @@ -104,10 +104,20 @@ static int dw_hdmi_i2s_get_dai_id(struct snd_soc_component *component, > > return -EINVAL; > > } > > > > +static int dw_hdmi_i2s_hook_plugged_cb(struct device *dev, void *data, > > + hdmi_codec_plugged_cb fn) > > +{ > > + struct dw_hdmi_i2s_audio_data *audio = data; > > + struct dw_hdmi *hdmi = audio->hdmi; > > + > > + return audio->set_plugged_cb(hdmi, fn); > > +} > > + > > static struct hdmi_codec_ops dw_hdmi_i2s_ops = { > > .hw_params = dw_hdmi_i2s_hw_params, > > .audio_shutdown = dw_hdmi_i2s_audio_shutdown, > > .get_dai_id = dw_hdmi_i2s_get_dai_id, > > + .hook_plugged_cb = dw_hdmi_i2s_hook_plugged_cb, > > }; > > > > static int snd_dw_hdmi_probe(struct platform_device *pdev) > > diff --git a/drivers/gpu/drm/bridge/synopsys/dw-hdmi.c b/drivers/gpu/drm/bridge/synopsys/dw-hdmi.c > > index 045b1b13fd0e..c69a399fc7ca 100644 > > --- a/drivers/gpu/drm/bridge/synopsys/dw-hdmi.c > > +++ b/drivers/gpu/drm/bridge/synopsys/dw-hdmi.c > > @@ -26,6 +26,8 @@ > > #include > > #include > > > > +#include > > + > > #include > > #include > > > > @@ -185,6 +187,9 @@ struct dw_hdmi { > > void (*disable_audio)(struct dw_hdmi *hdmi); > > > > struct cec_notifier *cec_notifier; > > + > > + hdmi_codec_plugged_cb plugged_cb; > > + enum drm_connector_status last_connector_result; > > }; > > > > #define HDMI_IH_PHY_STAT0_RX_SENSE \ > > @@ -209,6 +214,17 @@ static inline u8 hdmi_readb(struct dw_hdmi *hdmi, int offset) > > return val; > > } > > > > +static int hdmi_set_plugged_cb(struct dw_hdmi *hdmi, hdmi_codec_plugged_cb fn) > > +{ > > + mutex_lock(&hdmi->mutex); > > + hdmi->plugged_cb = fn; > > + if (hdmi->audio && !IS_ERR(hdmi->audio)) > > + fn(hdmi->audio, > > + hdmi->last_connector_result == connector_status_connected); > > + mutex_unlock(&hdmi->mutex); > > + return 0; > > +} > > + > > static void hdmi_modb(struct dw_hdmi *hdmi, u8 data, u8 mask, unsigned reg) > > { > > regmap_update_bits(hdmi->regm, reg << hdmi->reg_shift, mask, data); > > @@ -2044,6 +2060,7 @@ dw_hdmi_connector_detect(struct drm_connector *connector, bool force) > > { > > struct dw_hdmi *hdmi = container_of(connector, struct dw_hdmi, > > connector); > > + enum drm_connector_status result; > > > > mutex_lock(&hdmi->mutex); > > hdmi->force = DRM_FORCE_UNSPECIFIED; > > @@ -2051,7 +2068,20 @@ dw_hdmi_connector_detect(struct drm_connector *connector, bool force) > > dw_hdmi_update_phy_mask(hdmi); > > mutex_unlock(&hdmi->mutex); > > > > - return hdmi->phy.ops->read_hpd(hdmi, hdmi->phy.data); > > + result = hdmi->phy.ops->read_hpd(hdmi, hdmi->phy.data); > > + > > + mutex_lock(&hdmi->mutex); > > + if (result != hdmi->last_connector_result) { > > + dev_dbg(hdmi->dev, "read_hpd result: %d", result); > > + if (hdmi->plugged_cb && hdmi->audio && !IS_ERR(hdmi->audio)) { > > + hdmi->plugged_cb(hdmi->audio, > > + result == connector_status_connected); > > + hdmi->last_connector_result = result; > > + } > > + } > > + mutex_unlock(&hdmi->mutex); > > + > > + return result; > > } > > > > static int dw_hdmi_connector_get_modes(struct drm_connector *connector) > > @@ -2460,6 +2490,7 @@ __dw_hdmi_probe(struct platform_device *pdev, > > hdmi->rxsense = true; > > hdmi->phy_mask = (u8)~(HDMI_PHY_HPD | HDMI_PHY_RX_SENSE); > > hdmi->mc_clkdis = 0x7f; > > + hdmi->last_connector_result = connector_status_disconnected; > > > > mutex_init(&hdmi->mutex); > > mutex_init(&hdmi->audio_mutex); > > @@ -2653,6 +2684,7 @@ __dw_hdmi_probe(struct platform_device *pdev, > > audio.hdmi = hdmi; > > audio.write = hdmi_writeb; > > audio.read = hdmi_readb; > > + audio.set_plugged_cb = hdmi_set_plugged_cb; > > hdmi->enable_audio = dw_hdmi_i2s_audio_enable; > > hdmi->disable_audio = dw_hdmi_i2s_audio_disable; > > >