Received: by 2002:a25:c593:0:0:0:0:0 with SMTP id v141csp987408ybe; Thu, 19 Sep 2019 07:02:45 -0700 (PDT) X-Google-Smtp-Source: APXvYqyKOjYs/1VA0wLxI7yqqgeKZBsv0ALORKpAL9jU0xngIuhwh+kDFGlVDYYFOUXwgc+gRJVu X-Received: by 2002:a17:907:20f1:: with SMTP id rh17mr182799ejb.110.1568901765108; Thu, 19 Sep 2019 07:02:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1568901765; cv=none; d=google.com; s=arc-20160816; b=Ge41lmf3p2Pv3Bv4+5+OylQ7KWbXqD7dQizkUP5j4DiENzq2wewb5GRRqlVqmRzzGF NeUYcPOB7RCL1I71MNkcXuTammWYosv34AYELZ1zyxQe3vbZ6dj6tab4gctQhJLEwbDs Qo7PKH7FacKwcQB1dtD2dCAAQhDh8cwPFVoliWUJ/DRjvcsI/iPtb5K+we54AtZhnv7t wMtps9oCySikxHfTL+lQa9Hh3p9jljpr1sM9mRWbyqXnIO4B90t3GCzM5z6JJlNYKqfc A4+nOQIhN4tOvmQ/Y9adRh2PocZw6YMWlbAW90K6/X+rPSD7m1hf6eX0z0u2+jnVw4Bc XnuA== 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=a8fpKw2ued4D0BZtPXoBVbNaINT07QEPJ3+f6qSFqa0=; b=DF3I1Xu9xyfAkyKuW+xTay90ipn7PuJ2Nik8rMYlhnQPg7OcpSrmSW/y9wDjdwPdwq pX641au/1m8ZZJGD57nI+RKuUBJ58wGxaP9YGu+bmdPPFo0beVLQSzPEOQi7c8eoQf4U 7U56EExKZY+906rcBYGF4qIzBuPqtm4mMiTXBZJbeLRzeMCUqmHi+CWKr6DXBb71XeZ0 13kkhGRUT6HZSnluOq9hzAqItNSst+YbPBnRK1EW5ms6OEEBIbgVxXLbhKXCBQIBzGGo 8PUjSpTpRi6As5djG55NDZSGXJ3bjxc+FO2dWc1/G150S3piY4OziTmPfV2qKdKTteD0 34hw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=L3xnzMqM; 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 y27si5466571edd.249.2019.09.19.07.02.20; Thu, 19 Sep 2019 07:02:45 -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=L3xnzMqM; 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 S1732142AbfISNzS (ORCPT + 99 others); Thu, 19 Sep 2019 09:55:18 -0400 Received: from mail-pl1-f196.google.com ([209.85.214.196]:37251 "EHLO mail-pl1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731759AbfISNzR (ORCPT ); Thu, 19 Sep 2019 09:55:17 -0400 Received: by mail-pl1-f196.google.com with SMTP id b10so1675666plr.4 for ; Thu, 19 Sep 2019 06:55:17 -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=a8fpKw2ued4D0BZtPXoBVbNaINT07QEPJ3+f6qSFqa0=; b=L3xnzMqMl5yATf7M8qV3dWBYtjqKLuwX1Z3V7xTT2T52JQu8zb3X8z7wgB27Hv7+zw 7d7//09xdWXHnMy6rt5OZR6bYguQushN/1G2CF/WNp0g2kC0fYkhjDOxwq7wJZU/h4U2 1h8g9NWrpFYQKAlCsR15nsj2KdmkJcRDkx/HU= 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=a8fpKw2ued4D0BZtPXoBVbNaINT07QEPJ3+f6qSFqa0=; b=c90lZ7PVtrB9YRN+R/A/DUk0eKUhtQaRSSuqZ4dMYpyeew0JGbPfHAa92grADVyMT2 Hty7l9C6zOw3A/OrLkaA40NEdyFRZrqyI6DWmlYr95uMErVWk9+z7QHN3Is3S+DE03YI 0nigBE1suCILbYpSSvVAyk1ynq8578lUfhpYTWoesgWFFpXA/IMBiqy325PnD/lu5ixC 79sUqDRw6WQ2BsIZZn+JtGaLKb5wmZ66Y0Yb9hVzRUGQJSq/0yzxorqjKsQEooGC1TDJ XOfRrx52RwQjyt9+Oi9eJwOXEEtS7j8xecSBxtsxmSCaLkmGmcv7Jua3oK0EOk7lA72S SMXA== X-Gm-Message-State: APjAAAXo1PXpAuDB1ftzZG3kgTk1K9BVbTdeuM+4oUaEssb0Qi/il3Ll nzmTJ6xsUo337TJL+2SzetemGWDoddQ= X-Received: by 2002:a17:902:b402:: with SMTP id x2mr2003221plr.17.1568901316467; Thu, 19 Sep 2019 06:55:16 -0700 (PDT) Received: from localhost ([2401:fa00:1:10:79b4:bd83:e4a5:a720]) by smtp.gmail.com with ESMTPSA id w187sm8259292pgw.88.2019.09.19.06.55.12 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 19 Sep 2019 06:55:15 -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 , 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 v7 1/4] drm: bridge: dw-hdmi: Report connector status using callback Date: Thu, 19 Sep 2019 21:54:47 +0800 Message-Id: <20190919135450.62309-2-cychiang@chromium.org> X-Mailer: git-send-email 2.23.0.237.gc6a4ce50a0-goog In-Reply-To: <20190919135450.62309-1-cychiang@chromium.org> References: <20190919135450.62309-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 20f4f92dd866..d7e65c869415 100644 --- a/drivers/gpu/drm/bridge/synopsys/dw-hdmi-i2s-audio.c +++ b/drivers/gpu/drm/bridge/synopsys/dw-hdmi-i2s-audio.c @@ -160,12 +160,23 @@ 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_startup = dw_hdmi_i2s_audio_startup, .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 aa7efd4da1c8..7ffe8ed675ff 100644 --- a/drivers/gpu/drm/bridge/synopsys/dw-hdmi.c +++ b/drivers/gpu/drm/bridge/synopsys/dw-hdmi.c @@ -193,6 +193,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 \ @@ -217,6 +221,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); @@ -2183,6 +2209,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; @@ -2190,7 +2217,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) @@ -2641,6 +2679,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 4b3e863c4f8a..45a05e97e78a 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_status(struct dw_hdmi *hdmi, u8 *channel_status); -- 2.23.0.237.gc6a4ce50a0-goog