Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp689553ybi; Fri, 12 Jul 2019 03:06:26 -0700 (PDT) X-Google-Smtp-Source: APXvYqzrEXaVwQjE5FtJ1wwQN62kMS5KPaiIavcxwMeTqdqiZFC8FXXVtSJLKSddrePI91BbKMvr X-Received: by 2002:a17:90a:1b4a:: with SMTP id q68mr10614807pjq.61.1562925985971; Fri, 12 Jul 2019 03:06:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562925985; cv=none; d=google.com; s=arc-20160816; b=N4wUJAd47fR6bV5uZlZuJrrq9uZqw23oU1yfZmqP94O1Wblsix5DhwR6YEFD3v1xYg VC7KobMkJS+JDGKviQjO0o2Tu/mxU5CYgfFISF1x/f1XnrovimznSqYLk9Rs7b4KSxbh kI4HEW2TjlUeWLuNEAl3gBjwUWYGdJiXsaj+JxAeSWeMQRZSY13sFZ62/kh/awT7A6LE sjYjjQPIAaSGNCpzu2gcQF1dWNDpnSqz9Zw63e4C8t75xIkSvqpPNimn/E6xednuhKt8 IygAo+HXwtDs1pmCRzv+OXXr7JwsW7UfjQX/6iyelBXTcdBjTDE73HoB74dN0NgVfH/S Ph/Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=y0qt1iJQFWNi/R5Sunk3Tmvt4UzQ4aqV+HsTxoesj8Y=; b=pWcG4UUIl9v5PH1u1dLx/vYJigRNsnn9cLLIrN+Ns1c8WM0PhKKiPCH3wTIIn9N9uk iGpNG5s4+CXRGwMN1333jeENzsMWAT5HpBtNTAejMcODO+0/gnRCkxRf5/uBtXl0WKz+ dwXz3JwevDzWl0DqqIqHjRBFeJbPG3MTY6cETVTx4Prxc9r4lbwxLGyw3Vis1VHAKwiB CTBrLwAF+VC9WXJEI0qKgy8UAGEGOWS5rC4jnK7QnpSShyAhjLTOSluaCseAHxOtIxoY p8cSExWWgvvzGzEE27eTq0UuIWxBUXrbECR0U+KXSPApKxOHR5dh+YZS8IVk2QtcPVtu +xhQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=dvLENILO; 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 x13si7912705pgo.182.2019.07.12.03.06.10; Fri, 12 Jul 2019 03:06:25 -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=dvLENILO; 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 S1726768AbfGLKFc (ORCPT + 99 others); Fri, 12 Jul 2019 06:05:32 -0400 Received: from mail-pf1-f194.google.com ([209.85.210.194]:41115 "EHLO mail-pf1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726002AbfGLKFc (ORCPT ); Fri, 12 Jul 2019 06:05:32 -0400 Received: by mail-pf1-f194.google.com with SMTP id m30so4095850pff.8 for ; Fri, 12 Jul 2019 03:05:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=y0qt1iJQFWNi/R5Sunk3Tmvt4UzQ4aqV+HsTxoesj8Y=; b=dvLENILOFgOVMpvcNd0l/5dEWPufhsvrL3xJ4Z3FDdDMu4UIKDpPPVTX6ImXaHcPbl QwAHYTCFw7FNL86wOzVmUBGJKjxbazeNJgtHaAik/sfMhqVQUmU3dspzcSa9epyAfJlj q/oZkyRoak5hW6RdnFhAkxkgnVCxB+Whe4PbI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=y0qt1iJQFWNi/R5Sunk3Tmvt4UzQ4aqV+HsTxoesj8Y=; b=JnGAe49zffnzjBvoopkBu+8zMBc146xVvY9FAYe7eeJP8b7xMxT3TbxNY5oo68PKph w5l627ptgVuq65nmsM0ArzlHIT6cQrTb8mnwZEHI67C6l37HddKgnhbVZmMamy/V/qpK 7gzEJtvCfDnlOuSTJDsDYeB+hDCkjx+hAJvondpZIhlTM7t/qKdxBZsLI8U0r0JYNR41 BDKDn3ROkvVX+8YGQltxI3Y9QhR7dOC7Ph0mJ3V/1hbOQU+GBdsoljtoELB4Zpf5eV9+ syQ7MDWxdD0EBIjMuL6M1ZMvOofFoJq3IpqUVgDwB2FUeMXwaI1QYSF4F2Uz7Yzkk1hI Oo9g== X-Gm-Message-State: APjAAAUs+PVoEYzpHJFtndWt4WpyExdjhhInk//FJBEstZrrR+D91iq+ PX1Bvr942/a+EbGlmP1DMQeGXkwG0NQ= X-Received: by 2002:a63:f807:: with SMTP id n7mr10107313pgh.119.1562925930952; Fri, 12 Jul 2019 03:05:30 -0700 (PDT) Received: from localhost ([2401:fa00:1:b:e688:dfd2:a1a7:2956]) by smtp.gmail.com with ESMTPSA id t11sm8198174pgb.33.2019.07.12.03.05.27 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 12 Jul 2019 03:05:30 -0700 (PDT) From: Cheng-Yi Chiang To: linux-kernel@vger.kernel.org Cc: 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-devel@alsa-project.org, dri-devel@lists.freedesktop.org, linux-arm-kernel@lists.infradead.org, linux-rockchip@lists.infradead.org, Cheng-Yi Chiang Subject: [PATCH v3 2/5] drm: bridge: dw-hdmi: Report connector status using callback Date: Fri, 12 Jul 2019 18:04:40 +0800 Message-Id: <20190712100443.221322-3-cychiang@chromium.org> X-Mailer: git-send-email 2.22.0.510.g264f2c817a-goog In-Reply-To: <20190712100443.221322-1-cychiang@chromium.org> References: <20190712100443.221322-1-cychiang@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. 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 | 55 ++++++++++++++++++- 3 files changed, 67 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..ce6646067472 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,40 @@ static inline u8 hdmi_readb(struct dw_hdmi *hdmi, int offset) return val; } +static void handle_plugged_change(struct dw_hdmi *hdmi, bool plugged) +{ + struct platform_device *codec_pdev; + + if (!hdmi->audio || IS_ERR(hdmi->audio)) + return; + codec_pdev = platform_get_drvdata(hdmi->audio); + if (!codec_pdev || IS_ERR(codec_pdev)) + return; + if (!hdmi->plugged_cb) + return; + + hdmi->plugged_cb(&codec_pdev->dev, plugged); +} + +static int hdmi_set_plugged_cb(struct dw_hdmi *hdmi, hdmi_codec_plugged_cb fn) +{ + bool plugged; + struct platform_device *codec_pdev; + + if (!hdmi->audio || IS_ERR(hdmi->audio)) + return -EINVAL; + codec_pdev = platform_get_drvdata(hdmi->audio); + if (!codec_pdev || IS_ERR(codec_pdev)) + return -EINVAL; + + mutex_lock(&hdmi->mutex); + hdmi->plugged_cb = fn; + plugged = hdmi->last_connector_result == connector_status_connected; + handle_plugged_change(hdmi, plugged); + 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 +2083,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 +2091,18 @@ 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); + handle_plugged_change(hdmi, + 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 +2511,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 +2705,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; -- 2.22.0.510.g264f2c817a-goog