Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp580201ybi; Wed, 17 Jul 2019 01:34:36 -0700 (PDT) X-Google-Smtp-Source: APXvYqzktoXXVv/LWQBE/99PAZ8jmkjQtDgqODMWdkCBOhe9hm95KXS8E7J2TxI68Pps9G0Tg8hG X-Received: by 2002:a17:902:724a:: with SMTP id c10mr39004397pll.298.1563352476033; Wed, 17 Jul 2019 01:34:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563352476; cv=none; d=google.com; s=arc-20160816; b=nWYZ1uBBH5pruAvHLSC1ac2oYVojmVrKrot80e/oVpPwTFSjPMhYi9oM2vuHRmVVw4 BTBsJev/0RIp1JTbVCftBEHVSI+5IQqPjU+NQV4JGl3yN6Xu+vimd33aARmZztLaGRQu B2rbCOS8Lwjch7ZTFFxjN30/ljTcw4R+XlPF34i+mVae1sQWlqUUbKnZhiaJ1iyfkwIs UZ6Yh4mYLIT67HpEZ7KyY1OUYhegZFVvR11p+goyAmGsoscWd1qEHRFJsBuMfWK2t5Jq spKYMpJsO7XtoX0z0Ip8EcqYxopP6yP3qqq+w/xsyKHi9wNlTT7YO/fmuWm455gEsOjS zHAA== 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=5TBZYfajN5HVRea84QAJKLSTPB155HmdASNn879m/EQ=; b=suUC63cgNfjsJNEzzSj6J22N6sSUl93Zeas9z0aPOfm+3/hkgp1REAJtOjCieeOK2A f6JjgLaVP2SnwY16NmwOn770vxc6ZmZebNDzQBdoWIQ4md6Veu94lKgTRgsz30LNWxmc DcJEEAaVBKjIX7eWLTaV2+/9VQ+yt6fMO5/2if5cBR0rOfOI4cPats/x1gMBRTfJHIDs bkGJ7Er/xyJR1DBStnzWP6ipKMmfvVSmqCYrNo0XJNWAYIfk2SOj67ICm7nflentpuV/ LKFCMeZkc3Z/uJ0VuIe/G4vYnfBIpX8VBv3sIf/xrfDpfhW7du3FWoH3X5SOxYkvKngt pLuQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=IZmFxnxu; 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 h8si16187726pgc.402.2019.07.17.01.34.19; Wed, 17 Jul 2019 01:34:36 -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=IZmFxnxu; 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 S1726610AbfGQIdu (ORCPT + 99 others); Wed, 17 Jul 2019 04:33:50 -0400 Received: from mail-pf1-f194.google.com ([209.85.210.194]:37009 "EHLO mail-pf1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725873AbfGQIdu (ORCPT ); Wed, 17 Jul 2019 04:33:50 -0400 Received: by mail-pf1-f194.google.com with SMTP id 19so10484170pfa.4 for ; Wed, 17 Jul 2019 01:33:49 -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=5TBZYfajN5HVRea84QAJKLSTPB155HmdASNn879m/EQ=; b=IZmFxnxuDP3SuQvqoNRO+M8bB3TSTsZBFrAjJvHPnM9kp7cArfgRl3fNvJnOhR6Nt/ owbNXXyCv73kC3TUprNz5BR5MHcpZuh2mG8YWDAxqt28eldSBGCdTQdgybXQOvetlHuN oDKjd96uLQtPAXxkS81Zld3NvoTHxNAXtJZts= 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=5TBZYfajN5HVRea84QAJKLSTPB155HmdASNn879m/EQ=; b=YF3LFjQTwLM3ZByQ8UMrPvprD4qvuQg5bPWUVzhG5/XFh50a7mOb2t0fBo2D+e3eo/ VoIC6xDZV9JxRSpkJHZsRSorJxineBWBcTzbLEI+ynm/jhchp8WnRITG62G9ZY7HG/Cf 3lw1Y8mHHytOzRV3+gBSY//pHoAwbTaaengIKK3VNqW+nCuY3Vk1jydK30OVXsRalAZw /QCzjn7CJkzQqYSr5H9Kkx2jlHkQ2kNTU7ciO95RIzeRSZukPKtqa0+Y/0ybx39VNzl8 hfgYW6w6H+EixQOwdLb32eWdgBOqmWO1W2DgtybgmaFF0ckiH9jZ8veMdIbu6fRS1D7n oLtA== X-Gm-Message-State: APjAAAXiM0dl5bVkhguFpXXzm6xLBfCkCxOJh9Xqwe5hkwnHxS0xm0B7 BNpBUB5qI9YMAGS/fH4Lxc7jPV1qsiQ= X-Received: by 2002:a65:41c6:: with SMTP id b6mr39402014pgq.269.1563352429076; Wed, 17 Jul 2019 01:33:49 -0700 (PDT) Received: from localhost ([2401:fa00:1:b:e688:dfd2:a1a7:2956]) by smtp.gmail.com with ESMTPSA id e6sm27560082pfn.71.2019.07.17.01.33.45 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 17 Jul 2019 01:33:48 -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 v5 2/5] drm: bridge: dw-hdmi: Report connector status using callback Date: Wed, 17 Jul 2019 16:33:24 +0800 Message-Id: <20190717083327.47646-3-cychiang@chromium.org> X-Mailer: git-send-email 2.22.0.510.g264f2c817a-goog In-Reply-To: <20190717083327.47646-1-cychiang@chromium.org> References: <20190717083327.47646-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 5cbb71a866d5..ca56783fae47 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,21 @@ 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_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..f32c66a6873d 100644 --- a/drivers/gpu/drm/bridge/synopsys/dw-hdmi.c +++ b/drivers/gpu/drm/bridge/synopsys/dw-hdmi.c @@ -185,6 +185,10 @@ struct dw_hdmi { void (*disable_audio)(struct dw_hdmi *hdmi); 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 \ @@ -209,6 +213,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); @@ -2044,6 +2070,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 +2078,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 +2498,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 b4ca970a5b75..d6c925236c55 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; @@ -152,6 +154,8 @@ struct dw_hdmi *dw_hdmi_bind(struct platform_device *pdev, 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_audio_enable(struct dw_hdmi *hdmi); void dw_hdmi_audio_disable(struct dw_hdmi *hdmi); -- 2.22.0.510.g264f2c817a-goog