Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp771485ybi; Tue, 16 Jul 2019 05:05:42 -0700 (PDT) X-Google-Smtp-Source: APXvYqwhzrsT6NsjH2NneDaFQxLlSZyUy2BegDBnz81NKcGNIlXEYWypBMqx+rlQ2VLFmdOHHDVB X-Received: by 2002:a17:902:e58b:: with SMTP id cl11mr33999125plb.24.1563278742339; Tue, 16 Jul 2019 05:05:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563278742; cv=none; d=google.com; s=arc-20160816; b=oiGxs2rxM1xsq22Or98XNGzDiKnjwcVilXRpbfuvYfShuFxQz3J1iOk8G88KKjOAP+ 8Bwv9UkgqgdYI3hIBAIcDglxMg9/mGFZpEAy3GO9ig6vaztZLK/ze/NVdcfEoU8RyZAM buq7+laJ7NP0vn+xvACJl+e+xDkE0fLM89qtJwEbfl73g3BWekBCFA0FsmEUB248m/9w kTTmyRyFyZz5a9VbSs0FwRZ1XXv4ygIJUHQ0zQbNzqSHDba7kS7UpuiBpFh50+hOCx+V GEP+mc/ehLPyjEBcePwFe0UB8PCf5jeG388Q6NbeGna7l9JLP5HCbRAHMznI6TRLcPNg /mYQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=P7ULxAuKEaSYzWYdGTr4IlP25QOrvD8KBofH6zWNyzQ=; b=msCZrzV5RcOaLrdp+eBkeXuYCoYqhmmyBw5Fmx3D9+MrGUqD0AWDDLoZ0dl5vRnoV5 Hhr/lQ0X1QrHw5lHrWc1QUY94r6pCzGtcSN3fUwfBY98NYsQR+a6j1ZUg7WjoiIhaw5f V3EXgB55sXxnWsXz2UdTwWAqrAbf4lfrELzwCylLqYGtVquRbHS5JI5SG1CM1gPFOkuG y8bxEgVwpuvUz+zilipuBeNEvupbZ1cbKlULSV48Mgu1aQMhHTvbOxZJ3GgHSw9x4j5F HMYKxMWJQ67NLSZmTYT9qLOsDncv7IKc1LaIDnqTz6hA2TMYT7TBCIbAb7SjmucZHUJw cSKg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b="mkw993/n"; 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 q23si19526781pfc.179.2019.07.16.05.05.25; Tue, 16 Jul 2019 05:05:42 -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="mkw993/n"; 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 S1731589AbfGPME5 (ORCPT + 99 others); Tue, 16 Jul 2019 08:04:57 -0400 Received: from mail-vk1-f193.google.com ([209.85.221.193]:41750 "EHLO mail-vk1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727796AbfGPME4 (ORCPT ); Tue, 16 Jul 2019 08:04:56 -0400 Received: by mail-vk1-f193.google.com with SMTP id u64so4101975vku.8 for ; Tue, 16 Jul 2019 05:04:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=P7ULxAuKEaSYzWYdGTr4IlP25QOrvD8KBofH6zWNyzQ=; b=mkw993/neQKAw2c2FfYVkxn+sOjDePcI0SFBqSo2uQ9XgxU7qFjPiY3YH5IUddHb1f 0Zi+0q7QkAQBUfFLrw7PZjyy/zDoBIwIax+0NNKvtUxDk8C+SkzNSpFCXzQ0EZg4L/nh NgyhuIC9Ws15LrFjfBQKOKwslddMzuYtVkZiU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=P7ULxAuKEaSYzWYdGTr4IlP25QOrvD8KBofH6zWNyzQ=; b=l2IV6ZDV5uDHgbPZV/IiWH4pGkAMg28Ke8eXvWNAQessxkz+rVPJVr1Nt2AVy3mona q9Ih2irgP3DgZvADgLXKhHmEd65OCntVlEo/HXvHJbT3VmbkxKxQ6r2YzT3vUJNYclGX 2prbWxOqTgkWO1KgpxMDrsqrBvCpkhEwamjMhRMGek2X4O6lCH5/dvMYIbGtQIwG5KkZ S0/3sNxhOinReb7D+xPZzlI5w/rJE9qJcynLZ6jzvMzu0OZalfrm6fJVxlPLOHCoHeHK yi7juEGUAWM5r1dh79DlNPwGL/siDyhKY3SwQNNdOd8jPDUZ+Uie/hOyTI2XdnlhVbfo jYmw== X-Gm-Message-State: APjAAAVUa+ArHe6rZOQnrEIXUL4BCoDtnHSev3HKn0TsEobt99rHkfvT 5Et/1qQZC1VDQf6i51IK3IfV6aNJ/b7MFpDeJo2lfKDEvtU= X-Received: by 2002:a1f:3692:: with SMTP id d140mr11929548vka.88.1563278694560; Tue, 16 Jul 2019 05:04:54 -0700 (PDT) MIME-Version: 1.0 References: <20190712100443.221322-1-cychiang@chromium.org> <20190712100443.221322-3-cychiang@chromium.org> <20190712104748.zlgxgdjbtj2gw4yz@shell.armlinux.org.uk> In-Reply-To: <20190712104748.zlgxgdjbtj2gw4yz@shell.armlinux.org.uk> From: Cheng-yi Chiang Date: Tue, 16 Jul 2019 20:04:28 +0800 Message-ID: Subject: Re: [PATCH v3 2/5] drm: bridge: dw-hdmi: Report connector status using callback To: Russell King - ARM Linux admin Cc: linux-kernel , "moderated list:SOUND - SOC LAYER / DYNAMIC AUDIO POWER MANAGEM..." , Doug Anderson , Heiko Stuebner , linux-rockchip@lists.infradead.org, David Airlie , dri-devel@lists.freedesktop.org, Takashi Iwai , Liam Girdwood , tzungbi@chromium.org, Jaroslav Kysela , Hans Verkuil , Andrzej Hajda , Mark Brown , Laurent Pinchart , Daniel Vetter , Dylan Reid , linux-arm-kernel@lists.infradead.org Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jul 12, 2019 at 6:48 PM Russell King - ARM Linux admin wrote: > > On Fri, Jul 12, 2019 at 06:04:40PM +0800, Cheng-Yi Chiang wrote: > > 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; > > This looks fragile to me, poking about in another device's driver data > from another driver is really not a good design decision. I think this > can be simplified if the registration function took the function > pointer and the struct device pointer, and then you only need one test > below: > Hi Russell, Thank you for the detailed review. ACK to this suggestion. I have updated the registration function following your suggestion in v4. It looks much cleaner. > > + 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; > > Given the current code structure, how can this ever be true when the > function is called? > ACK Removed in v4. > > + codec_pdev = platform_get_drvdata(hdmi->audio); > > + if (!codec_pdev || IS_ERR(codec_pdev)) > > + return -EINVAL; > > This doesn't seem like a good idea as I've pointed out above. > ACK Fixed in v4. > > + > > + 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); > > Should be a blank line here for readability. > ACK Fixed in v4. > > + 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; > > Why is this necessary? > > The I2S audio driver already depends on the dw-hdmi module through its > use of functions already exported. Indirecting this through the > platform data makes no sense. > > Just rename hdmi_set_plugged_cb to dw_hdmi_set_plugged_cb() and export > it for dw-hdmi-i2s-audio.c to use. ACK. Your suggestion makes sense. Removed in v4. > > Thanks. Thanks so much! > > -- > RMK's Patch system: https://www.armlinux.org.uk/developer/patches/ > FTTC broadband for 0.8mile line in suburbia: sync at 12.1Mbps down 622kbps up > According to speedtest.net: 11.9Mbps down 500kbps up