Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp8837915ybi; Wed, 10 Jul 2019 00:09:26 -0700 (PDT) X-Google-Smtp-Source: APXvYqzTFthLLWyrgfiT+KLBgNS6BrW8bo7Y+FreYBvgemg+4KS7bcAIscahPTn5V/SB2MPwZoKX X-Received: by 2002:a17:90a:9b08:: with SMTP id f8mr5120275pjp.103.1562742566783; Wed, 10 Jul 2019 00:09:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562742566; cv=none; d=google.com; s=arc-20160816; b=vRaqUSIco0M2MoRQqkT/rc3ycWpMNHmm9TAT0rOA/QRW4klnaAxhjz+CQOcYxMn0/F xOYhj7osAACh5K4OPevJvdV6/kfUJy4jnkUy2BNqa8dcW4fzmaR04ZqByKi0nyD5ymaF Od2PhOBFxS03amYQxe5c9un8w6Cfwq0sdtUY6vuR38G6UMntg4F0oJaAWmrNg4y0SPwf CmOqYbhrMwhtuSUkwibfWh/3EcfgFej1ffN6oRGxKRNZVyKmgEc12ZiJt6lZtMISoRWj siG1mQQptMV8L1pnng5+STYvxoow1fy97NTtQbPKhWcLe9qKzj5zAT+SfGCt9s3WDE7v nSzw== 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=WaPX7Qm8pphWRb9H2V1MYjbTnx5UInRykIyxCEX1ORI=; b=RHN9J9+hpBJg9zVV5ekO2j30WcOvQ7XfA60HiqHZNzAkAJPxuoPcQPPdArwxfRwqQB mHstB9W36vysnHyuJA4QJRcVTozTK2SaRrs4nqmqFxtag5bSQAO/CSCTqz8kdaInob50 Rc8YrjBW+BRDgjrclS8hnRc8BZV6unaynZpTGmPwluTiVciwVXUJbpbjGg4gkKUn4er2 oFgzxHtgwxFA47oBukjyg1zyFkjARi3KHbsmqOnAIa3VsWU6/XWjZtZh2FoiBJ1bwV0y x/nJ2qVgJ1cElMpSUQpnaFP4i8z4Ebb/czsH1Oqo9wB5CXqymAMlY7O1+CAChlVvezqM nk5g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=GSnPY+JN; 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 91si1407340plb.39.2019.07.10.00.09.11; Wed, 10 Jul 2019 00:09:26 -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=GSnPY+JN; 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 S1726991AbfGJHIf (ORCPT + 99 others); Wed, 10 Jul 2019 03:08:35 -0400 Received: from mail-pl1-f196.google.com ([209.85.214.196]:35360 "EHLO mail-pl1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726098AbfGJHIf (ORCPT ); Wed, 10 Jul 2019 03:08:35 -0400 Received: by mail-pl1-f196.google.com with SMTP id w24so750436plp.2 for ; Wed, 10 Jul 2019 00:08:34 -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=WaPX7Qm8pphWRb9H2V1MYjbTnx5UInRykIyxCEX1ORI=; b=GSnPY+JNHAWEHjKCK/zb1o8YMdnlwZb/hoL00TXep6OdNrZzYmurM0DFsUSLSE8Z8K ful3CLkTx7wwHAbwCdFPNIjX/s5x6HZO+oDqrtuS+QKJq0aS5GHXjukMcmyJwC7u6Kpn 8kCDUA3Dl8GPtYwSJWFD+lhclag9j9Goi9IkA= 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=WaPX7Qm8pphWRb9H2V1MYjbTnx5UInRykIyxCEX1ORI=; b=A0Lsq72crOHoXmAkSj9PSuPRfZHm3Vak1WuAPcrvwpsHuxWU4ki6UEkphPhwbAY9T6 exrmVrewY2P9UJPemrutdeKCeU7RIvCIzWFJ6Y1flNTFHxwGuNsQMRJkTOEwwBLtt+23 ZUcY/cjoNyRtDMSj7RHZPU+DNUH/GSI6/4uz8eOlpbPyqMO5OnzRQGCdftLIG0HRYIa3 o50Y48D7qN0hcsUnqczBU9bQvrOxec7BL6VLuuxUoMiLNV+XzPs3UkNH7nIAEFkp3gZu toEwncbMdCrwUuQfSNx5jcBeLE4bPjLIflSBiPTelPJXgi1NS/XReI58Rm9ZIp5B1xeb mp5w== X-Gm-Message-State: APjAAAVRSVucweV4Vv5LVlHA0VSDt+qjd6DTVqojsb9tb1r2s0C7Wlqq +gGdQoiCWiI+OsymudORndbDBe52v+s= X-Received: by 2002:a17:902:7281:: with SMTP id d1mr36683815pll.329.1562742513992; Wed, 10 Jul 2019 00:08:33 -0700 (PDT) Received: from localhost ([2401:fa00:1:b:e688:dfd2:a1a7:2956]) by smtp.gmail.com with ESMTPSA id b26sm1169668pfo.129.2019.07.10.00.08.30 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 10 Jul 2019 00:08:33 -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 v2 2/4] drm: bridge: dw-hdmi: Report connector status using callback Date: Wed, 10 Jul 2019 15:07:49 +0800 Message-Id: <20190710070751.260061-3-cychiang@chromium.org> X-Mailer: git-send-email 2.22.0.410.gd8fdbe21b5-goog In-Reply-To: <20190710070751.260061-1-cychiang@chromium.org> References: <20190710070751.260061-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.410.gd8fdbe21b5-goog