Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp3010811ybi; Fri, 5 Jul 2019 00:10:33 -0700 (PDT) X-Google-Smtp-Source: APXvYqzmW4B/T5D7yJL34W1zQZkFc5DdIIBCJwaRJbSlaARp3WeJNB7Q+q2hUvcC2vzg3mDzIWgO X-Received: by 2002:a17:902:8489:: with SMTP id c9mr3257980plo.327.1562310633496; Fri, 05 Jul 2019 00:10:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562310633; cv=none; d=google.com; s=arc-20160816; b=eNAXm9s9RCwXsq+b/8YKIIr0O2zZbENJdTnrhBu1oz7moQYDlFgktvJFnfTXmHfKvR YizZEbzLWrSKGyMt79uPpV2nsvhcIAhEmheGlHNOhb5m5ZgJAke0ViVFQuRD4WI9MGBV SUCtnntq3Vzg/7fg4lTi2jF+qYj1E1Pk0oLHfpY7JLxVCelZdhGIx+mo6/jdUScqIshT ZjDXafa+ULvqirZC6L9GzYecixcUEoPfoDttmzihdyiMimRz2fZZ0CE33abJ33Ot5Yes PozAS+dUEG/OXl+WvTDxApVQused3gBM5ZdxLEMBXW1R9X5e2gvxo8143kP51OfZBB0G b3RQ== 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=+HA1gRJUU1q/vq10J2Cj5qnKuph6mRHyYxPoVAGdEoY=; b=EVfEdAnK1ZL26HvlYxFEJ7WHS1uEhotbvlbMJqCN8zLzP8zb7ZbfMPjW3xcTHJHhee P6fFArecByE53EcdzHq3JaVLYAQ84PObiWE3puQjBT6Tzcc0F7NWZPMb8hgveYQLotTV Xh7lGu7B7cpy4Eruf8iQCHK++sN5QONAJyjEP5gGa2L21XHsBHxhbpYMoQlcxwzss1RH jBaSU4Y99l8UCq7qig9k6eLbtreL1DJYxzD0ybL//P1EUGdNcmxmCfsUNuZ+oNOTjxZO x7eGf6ijnfBiLXNP7G4xTGG00AdBmRvBCF2z6uXAD1hMclVhifDBIZVA84PxC8nJqnxh AtQw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=Hn5+GLp2; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a2si8259025pgj.54.2019.07.05.00.10.18; Fri, 05 Jul 2019 00:10:33 -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=@google.com header.s=20161025 header.b=Hn5+GLp2; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727835AbfGEHJV (ORCPT + 99 others); Fri, 5 Jul 2019 03:09:21 -0400 Received: from mail-ot1-f66.google.com ([209.85.210.66]:45144 "EHLO mail-ot1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725827AbfGEHJU (ORCPT ); Fri, 5 Jul 2019 03:09:20 -0400 Received: by mail-ot1-f66.google.com with SMTP id x21so8079390otq.12 for ; Fri, 05 Jul 2019 00:09:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=+HA1gRJUU1q/vq10J2Cj5qnKuph6mRHyYxPoVAGdEoY=; b=Hn5+GLp28rD0iRoGwRHbRq7GRqhDGFy99Nq0elsuKdVJNwUHVcdvJRg+gisPdFcpAZ qEdsBQ/afocCCAKXjvk+7j6rsUbqRcawLyzd70CSM0IbNIX9k0WdbOckw9qauhSBUKbs KsS8UCyQhKHpbg2mJG97lYMWJdWnZIc9xlhH1aPkk/x65Lyq+DEu9zuQz3itB4uXU5Jx Wp2757OkuQRX27nYk26bC5yZaCPgQVKegnpuEwUi3IhMmeam8wEmZq0QBjIAZzjRK2Vy J6XUiGXIqYCImxBzdj/5HNLtVcjYug3zt2+FpURR/lYSVsNYx9z7L0YratiSYcZPpaf3 EX3g== 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=+HA1gRJUU1q/vq10J2Cj5qnKuph6mRHyYxPoVAGdEoY=; b=B8v99x6nP1S6YxTAX+AlauccBYAEKAUC9M7FqSUUnkvOsEpNPmPgUiKNfDgpMzq+y4 5PssRqTiQ/JovC7Tke4g9uTQ5YCkvj0F+RDgMEeD0hgeuYpeXflnxClt1Ul7oeat7fZD sp1mxmJl93/RX6kS+aLtNZELSBODoT7Ubr4NyZxeI+RiKxSGPaaxHwEFzsGgLmn2G9T3 I48P3NLLVNPsp1VvjYQh/mJp0Jsq6sxOvsL4uB2gONf6YOhXhLFzyawM3rLb1PpROxZN zow5psElH9T+ViZDZMJb0jKq9kBmpt8/qicfeSiJz0y03EUbvkIvIrCCTOrIXuvGDSGZ d+9w== X-Gm-Message-State: APjAAAUStaKAzOJdhKmIeAjByXuKU/3SMMXLbAF8Nv2mdYLeLkKELWjA wWyUe6ZmZZmePOUeL7aF+stdofjfSq0HRO4rwsRGLpDM2S7rNA== X-Received: by 2002:a9d:6195:: with SMTP id g21mr1790572otk.103.1562310559416; Fri, 05 Jul 2019 00:09:19 -0700 (PDT) MIME-Version: 1.0 References: <20190705042623.129541-1-cychiang@chromium.org> <20190705042623.129541-3-cychiang@chromium.org> In-Reply-To: <20190705042623.129541-3-cychiang@chromium.org> From: Tzung-Bi Shih Date: Fri, 5 Jul 2019 15:09:08 +0800 Message-ID: Subject: Re: [PATCH 2/4] drm: bridge: dw-hdmi: Report connector status using callback To: Cheng-Yi Chiang Cc: linux-kernel@vger.kernel.org, Hans Verkuil , Mark Brown , Liam Girdwood , Takashi Iwai , Jaroslav Kysela , Russell King , Andrzej Hajda , Laurent Pinchart , David Airlie , Daniel Vetter , Heiko Stuebner , dianders@chromium.org, dgreid@chromium.org, tzungbi@chromium.org, ALSA development , dri-devel@lists.freedesktop.org, linux-arm-kernel@lists.infradead.org, linux-rockchip@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 12:26 PM Cheng-Yi Chiang wrote: > 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); > +} > + The first parameter dev could be removed. Not used. > 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)) I would expect if IS_ERR(hdmi->audio), then this should not be called (i.e. should exit somewhere earlier). > + 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)) { Share the same concern above.