Received: by 2002:a25:d7c1:0:0:0:0:0 with SMTP id o184csp6132ybg; Fri, 25 Oct 2019 15:37:00 -0700 (PDT) X-Google-Smtp-Source: APXvYqyViYOBvl55YnZQ6YUjcMGSyzHKlnlSQPGSfGlEipzzNF0ViT70CGFLl6ttfehaPURDF96V X-Received: by 2002:a50:9b10:: with SMTP id o16mr3711735edi.117.1572043020142; Fri, 25 Oct 2019 15:37:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1572043020; cv=none; d=google.com; s=arc-20160816; b=tik1XzILXrtZyyMNpe6K7feoCHE9A6TGGMe/Wcmp10KXDk5a9JjFiWeXpaKJr+CjU/ wsQhd9m5k+SC4x2RQdb8zeYaqDihhjNuM4K3E9Hso7pA4797wy7fRJkrBiC6CvGYrHCa O6/VbiSQfBoShCnNqCQPdN4urHX/iWrP3WAsnOxJhGHiBiqiGi0mPljcUfFdhU63VnDg U15X7z/O3mXW2za1MqLfM7QxCZ+DaO3QNcnLM/dM4tMH9kzuhuMaO5mBrmNrUseNazrh WWEREzX6DzZ9oXSouwkKNVNX89lKzYzG28f0CfkPAjCO9HteStAxLV0SyRt76sFZhUjA RrQw== 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=z189/JbsrejSxg4snj1cfmf7WABylQJkAzsniyW058U=; b=kuMiNng8NAb6zCpRXoUqxYutwwaW0sNdCdYU+KRkybCY3uJAlnsLoNpeP8t54FfJ/y a6bYJtFv4Y97kSaHhVODyy2Q1odSsN4isuYb3IO4mu0PQxGNFah664zKHDIKkgmy79Zf X4Y/SEPX+Uf6MVa650cG7L2C3EEEivQGYbbrOINbS4S44BFDiFL3Vh9yxqCdPLN1YNtk IvHNhit5sfsx1KhxSqZVCexiNEK/K80zMMYTw1lNHXI1dB8wqG6RrAWxJgr0LBTJ3iBe iC0vGDoyRrz2/SpM8XlZ/XLUgHhUWzrOdq6kP3WG8edTdN4wayTPuGiXSmaoRYtMf3SI Wtsg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=YO0uC703; 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 x1si1971209eju.296.2019.10.25.15.36.35; Fri, 25 Oct 2019 15:37:00 -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=YO0uC703; 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 S2440395AbfJYNac (ORCPT + 99 others); Fri, 25 Oct 2019 09:30:32 -0400 Received: from mail-pf1-f194.google.com ([209.85.210.194]:37116 "EHLO mail-pf1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2439593AbfJYNac (ORCPT ); Fri, 25 Oct 2019 09:30:32 -0400 Received: by mail-pf1-f194.google.com with SMTP id y5so1600479pfo.4 for ; Fri, 25 Oct 2019 06:30: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=z189/JbsrejSxg4snj1cfmf7WABylQJkAzsniyW058U=; b=YO0uC703Es0XdjSv+m/Qvwu2lBMBC4mcrx3S+PZ3tgy66mjDryhZaRvLDwL/pXRP2H aq7u/poJrjwWeLjKlcgLmsKbWuG4KVXftD2iynBeU0SD9eczQoK9xFxSNAZ0zm4i2a+E 35gOqlCyReRVKsQEuloTZAlL1wuOaWcf5j0Qo= 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=z189/JbsrejSxg4snj1cfmf7WABylQJkAzsniyW058U=; b=SQs9iXyvgO3oazLTVhI2/MbOrGNGpsH1wwsWG4Urq2dciNQNku9/j450B7yHA1tlxB 0yLRpiXFgJW49G/rVUcFAkzyHnP2eWdQAE9SK7AziJ2o8x3z2s3JpVz5UX5rNU6OJbhF 529K8Y6p3C0VcBX2V+TFcbaSTYyFlT0kiwzHvsubxjvJFGCd9ceFrn3pbayWHUsxuiGM E9cuJTfem6dMGDWK+6FMT8Qb96ePD/bTs8UItwmA5e6lZzPyP14FhxoZcvR+9lgS1JT6 icAS4zPtRlKlL5Tw2b702k+MY0BBGTJRi/RXuiQmmi58B9ttP7WNJpfL79UxpuV/jFr2 pmQw== X-Gm-Message-State: APjAAAXEiIdRHqgHL4YeGQCdVKx9vMoI8HYUCcBJ0wiUlfnQF1d+/OyD WiWsXQnHjWtWYkoElv0P+f1dc9NWm705lw== X-Received: by 2002:a62:6842:: with SMTP id d63mr4348012pfc.16.1572010231077; Fri, 25 Oct 2019 06:30:31 -0700 (PDT) Received: from localhost ([2401:fa00:1:10:79b4:bd83:e4a5:a720]) by smtp.gmail.com with ESMTPSA id e17sm3749293pfl.40.2019.10.25.06.30.26 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 25 Oct 2019 06:30:30 -0700 (PDT) From: Cheng-Yi Chiang To: linux-kernel@vger.kernel.org Cc: Neil Armstrong , Jerome Brunet , Jernej Skrabec , Jonas Karlman , Hans Verkuil , Mark Brown , Liam Girdwood , Takashi Iwai , Jaroslav Kysela , Russell King , Andrzej Hajda , Laurent Pinchart , David Airlie , Daniel Vetter , Heiko Stuebner , Rob Herring , Mark Rutland , 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, devicetree@vger.kernel.org, Cheng-Yi Chiang Subject: [PATCH v8 1/6] drm: bridge: dw-hdmi: Report connector status using callback Date: Fri, 25 Oct 2019 21:30:02 +0800 Message-Id: <20191025133007.11190-2-cychiang@chromium.org> X-Mailer: git-send-email 2.24.0.rc0.303.g954a862665-goog In-Reply-To: <20191025133007.11190-1-cychiang@chromium.org> References: <20191025133007.11190-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 exports a function dw_hdmi_set_plugged_cb 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 --- .../drm/bridge/synopsys/dw-hdmi-i2s-audio.c | 11 +++++ drivers/gpu/drm/bridge/synopsys/dw-hdmi.c | 41 ++++++++++++++++++- include/drm/bridge/dw_hdmi.h | 4 ++ 3 files changed, 55 insertions(+), 1 deletion(-) 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 1d15cf9b6821..6c2c44d0bdee 100644 --- a/drivers/gpu/drm/bridge/synopsys/dw-hdmi-i2s-audio.c +++ b/drivers/gpu/drm/bridge/synopsys/dw-hdmi-i2s-audio.c @@ -151,11 +151,22 @@ 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 device *codec_dev) +{ + struct dw_hdmi_i2s_audio_data *audio = data; + struct dw_hdmi *hdmi = audio->hdmi; + + return dw_hdmi_set_plugged_cb(hdmi, fn, codec_dev); +} + static struct hdmi_codec_ops dw_hdmi_i2s_ops = { .hw_params = dw_hdmi_i2s_hw_params, .audio_shutdown = dw_hdmi_i2s_audio_shutdown, .get_eld = dw_hdmi_i2s_get_eld, .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 521d689413c8..2102872bf43c 100644 --- a/drivers/gpu/drm/bridge/synopsys/dw-hdmi.c +++ b/drivers/gpu/drm/bridge/synopsys/dw-hdmi.c @@ -191,6 +191,10 @@ struct dw_hdmi { struct mutex cec_notifier_mutex; struct cec_notifier *cec_notifier; + + hdmi_codec_plugged_cb plugged_cb; + struct device *codec_dev; + enum drm_connector_status last_connector_result; }; #define HDMI_IH_PHY_STAT0_RX_SENSE \ @@ -215,6 +219,28 @@ static inline u8 hdmi_readb(struct dw_hdmi *hdmi, int offset) return val; } +static void handle_plugged_change(struct dw_hdmi *hdmi, bool plugged) +{ + if (hdmi->plugged_cb && hdmi->codec_dev) + hdmi->plugged_cb(hdmi->codec_dev, plugged); +} + +int dw_hdmi_set_plugged_cb(struct dw_hdmi *hdmi, hdmi_codec_plugged_cb fn, + struct device *codec_dev) +{ + bool plugged; + + mutex_lock(&hdmi->mutex); + hdmi->plugged_cb = fn; + hdmi->codec_dev = codec_dev; + plugged = hdmi->last_connector_result == connector_status_connected; + handle_plugged_change(hdmi, plugged); + mutex_unlock(&hdmi->mutex); + + return 0; +} +EXPORT_SYMBOL_GPL(dw_hdmi_set_plugged_cb); + 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); @@ -2161,6 +2187,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; @@ -2168,7 +2195,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) @@ -2619,6 +2657,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); diff --git a/include/drm/bridge/dw_hdmi.h b/include/drm/bridge/dw_hdmi.h index cf528c289857..9a0c8381a069 100644 --- a/include/drm/bridge/dw_hdmi.h +++ b/include/drm/bridge/dw_hdmi.h @@ -6,6 +6,8 @@ #ifndef __DW_HDMI__ #define __DW_HDMI__ +#include + struct drm_connector; struct drm_display_mode; struct drm_encoder; @@ -154,6 +156,8 @@ void dw_hdmi_resume(struct dw_hdmi *hdmi); void dw_hdmi_setup_rx_sense(struct dw_hdmi *hdmi, bool hpd, bool rx_sense); +int dw_hdmi_set_plugged_cb(struct dw_hdmi *hdmi, hdmi_codec_plugged_cb fn, + struct device *codec_dev); void dw_hdmi_set_sample_rate(struct dw_hdmi *hdmi, unsigned int rate); void dw_hdmi_set_channel_count(struct dw_hdmi *hdmi, unsigned int cnt); void dw_hdmi_set_channel_allocation(struct dw_hdmi *hdmi, unsigned int ca); -- 2.24.0.rc0.303.g954a862665-goog