Received: by 2002:a25:d7c1:0:0:0:0:0 with SMTP id o184csp3231492ybg; Mon, 28 Oct 2019 09:28:20 -0700 (PDT) X-Google-Smtp-Source: APXvYqwFo4gQMuIkbuKB7Oj/KwZM+pd7558h9Y6sEUO2wVWPcFVMUsXCuZgT/rRhK/g4i0MKgbU7 X-Received: by 2002:a17:906:4dc9:: with SMTP id f9mr16896105ejw.23.1572280099972; Mon, 28 Oct 2019 09:28:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1572280099; cv=none; d=google.com; s=arc-20160816; b=dxMttyRqn/v/cdl/8p7OAOxh3uIubnntMTpEYzUVhnXxueCaZTg5wRsQdXHE3/N+Y3 m3SHBZFtLNz+rklnzNv0uXYeK2A+rROTbKya3vcBtsVkI2E+kKvX72TaMG+Ooqd9khem Hbi5KUe4DKL0PeQ08iopL4ckwucic4goIF7qkjvV4afgOl6wS9S0cKwSdn6NLmyRxDgg oJZAlgPCTXfnJAKDduYfv/GC/32m9wqibcLDFRsIhj/PMzhwsWWy+WlmoR0mGVk5DNQL RxQaiD5vQ6UEqX/yKeyboxRm42TwTQB/sW6X6TopAw042p+wl/h9WWp+Mf9FhdN/EC0c B9xg== 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=XYM3qB/A4Lm9j2VjgXfdDTWXHmtn/kTE10xGM/NiKFEvqNfbYFlCIXbTKO6r+X/yGp fVGmJwVbNZRVrUtbUdi+GJhzYfJHM/kRY4/3fL4fgg8QlSpnWz9iTur7s1aP7fYplwPW tJ4SRH7Y71Cggb5BvG5enhQ55rC60sX896yfxlS5QQsxW12QsxDtF7gsnBeCE9PUGwjK NHfNU/xEnwhqRoqc4BpTTrCQhpMb3EtwbxNXHvwU8RFTA4ujNdFw/fyLx29Q4qKBULsO IsK5r4gCq2ofTi+0/Hewjmti9ylNI2HD6ecQF1XoRfZ1mUZUiXslBz0ZhpcGPxFa6dEg vcvw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=hzDxQcpe; 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 d13si8264984edb.362.2019.10.28.09.27.54; Mon, 28 Oct 2019 09:28:19 -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=hzDxQcpe; 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 S1732682AbfJ1HUa (ORCPT + 99 others); Mon, 28 Oct 2019 03:20:30 -0400 Received: from mail-pg1-f196.google.com ([209.85.215.196]:44166 "EHLO mail-pg1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730963AbfJ1HU3 (ORCPT ); Mon, 28 Oct 2019 03:20:29 -0400 Received: by mail-pg1-f196.google.com with SMTP id e10so6273425pgd.11 for ; Mon, 28 Oct 2019 00:20:28 -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=hzDxQcpe8ZAozCEeLby7W+1X3EA8e4bzhLTQhRD7Xv7NjwoILlXBFKw9g5Qz82uVIg dK78qiaeJFX0mr5gn9tGU7l+LqaGNq0GN5NbdZ3FnYqFy1qadcN/aQmj6+GIum/V59FX 3mukg7LneVke61YvVEM5GJ1xgjhgeVwO2Tp3Q= 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=dG9THHT2bWa7HyDygS4bVWPWCPLSqvV2Ru3ycDIbZYBadDRa+3VpTs71I4nRgp9sPJ ggd4+gUncTmRIbetlCdmxfEumsSI2+jrlSzS0GWf46f0EARYTV86D0MU2D3GvlRmznEk kMXz5T1guLXc+YyrA591Sxte8JSAdsIaHSQPApWlV4CBIsDzeDxUhDVqMaD9PaVLQ1/6 E/9djByOHdqYF9sNDsRqh2sghvLSjQu4lw2/IdGbJU5VBVx/tN20xDCHWgFn9fBySrHt X89sqZ//NPmLCowFCelG+iidwx3Msvjpca3Ld6D6Ycu4DF9+bTUQPWCJDht/j1+hpju+ GLvQ== X-Gm-Message-State: APjAAAU0m5WKR/ePM0y+gqqkSJGDiasHDD3eR17Kiobto0XjqtYonVi1 LuSMSF2UGtb3iTO2UWOKDt21/6eMhpZ+8A== X-Received: by 2002:a63:1417:: with SMTP id u23mr11445620pgl.279.1572247228043; Mon, 28 Oct 2019 00:20:28 -0700 (PDT) Received: from localhost ([2401:fa00:1:10:79b4:bd83:e4a5:a720]) by smtp.gmail.com with ESMTPSA id 16sm9908856pfn.35.2019.10.28.00.20.23 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 28 Oct 2019 00:20:27 -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 v9 1/6] drm: bridge: dw-hdmi: Report connector status using callback Date: Mon, 28 Oct 2019 15:19:25 +0800 Message-Id: <20191028071930.145899-2-cychiang@chromium.org> X-Mailer: git-send-email 2.24.0.rc0.303.g954a862665-goog In-Reply-To: <20191028071930.145899-1-cychiang@chromium.org> References: <20191028071930.145899-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