From patchwork Fri Jul 12 10:04:39 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cheng-yi Chiang X-Patchwork-Id: 11042025 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 093F2912 for ; Fri, 12 Jul 2019 10:05:47 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EB3EB2883D for ; Fri, 12 Jul 2019 10:05:46 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DE6F628C01; Fri, 12 Jul 2019 10:05:46 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 7DE6928BF4 for ; Fri, 12 Jul 2019 10:05:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=yyAmHuqcq4ZlaldliqIfphLJfv8blQ9Ge4zR9tq4asw=; b=Wb8D+6p6G7rswS E4Ay5fu4PX72CFBAZTD/XSL0Cv3Mioj84ZyZoYO5aSofLlm2f6Q2BuWDGmlrCjGZoqCuv6rUcygb9 nuhUx1s20vPz/S+J3i6lBXcPuJNynEQzhOWqUkAZRH3Xey3CzNMREtlq850ExG86iFFEqlJOeazu7 K+6kHooV6bXtZPOJnhkSglQqFSTMwZRmLYlX/NYhNM84rSZtdoNq/OBp7iMWaLJDpPgHmk+MGDSCI vxmjaEZ8fldIyAyJFHY2VH07Pu7uIOBSS19GVjZBeE+NqavL9ZDzp8xE77m9ijmraNOdANExI84kY DjP7wswTzAr8hv0Y6cAg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92 #3 (Red Hat Linux)) id 1hlsQy-0000wK-5s; Fri, 12 Jul 2019 10:05:44 +0000 Received: from mail-pg1-x542.google.com ([2607:f8b0:4864:20::542]) by bombadil.infradead.org with esmtps (Exim 4.92 #3 (Red Hat Linux)) id 1hlsQf-0000gj-4N for linux-rockchip@lists.infradead.org; Fri, 12 Jul 2019 10:05:26 +0000 Received: by mail-pg1-x542.google.com with SMTP id s27so4337606pgl.2 for ; Fri, 12 Jul 2019 03:05:24 -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=rS6zkcW47m8W9zfkh+VM7vIXvZMkibrUOXYUf4msEEM=; b=RDVx1KXccl3mvFHUy6r7nTol8Lf7wAQOsrR/0/uAxUrL7oNBlwm9mkTQQMbzZbVwHH KcW5fTbUZyvWJCY2CbIAdoPOk4gWZa6CxObxvRpHBj4SYAJOz2cnrVCVij9HqjhFtIjQ pz4bYOSc1ZWCTc4s8x3GObiD4Dr1AUwN4Qbt8= 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=rS6zkcW47m8W9zfkh+VM7vIXvZMkibrUOXYUf4msEEM=; b=a3ljL04jfI5eDuQJq5sqRxxuo8DUvtH+B853tUrN0oILfvHOh3oo2h0pk/BiRKWxTe dxQSHpJNx/3hNrsOXUkFYvugduOMGlInd0XgH+7TpMkJ4IOK8iu3XF/wEli7Eoas93kp V58+6+I+g0CgJ72OxsfT2L1DZBmEtExxjEkgpMfV1pKalvTQjDcaaP8dsJW0B0eDms1i LuZkBo5beEm7WpfdXPxwuO+hrARioGCXTFZdXs5LQnH4X+8X1f4OIVGGsOzhlGge4iTv 1AbFqPXAoPps97+KYoXmOSjE3DC1dX1YM1A6erqSI6MLXuWT3BWIaIKyPqDdyqj+luVF gtdg== X-Gm-Message-State: APjAAAWI2JNw8f9cOj7Y+0fU7OsImcUo1IiEfr6KPNqA8k4gQbPQuyEf qVksJk9LSxr0IldSTHwLhMYp3A== X-Google-Smtp-Source: APXvYqz7SudcvvS5pF+UuX1xodz8OlwvmJ4ZVax0qTiAuJMFysNNw5skd8gJXRuISPAh/Pift1dikA== X-Received: by 2002:a17:90a:898e:: with SMTP id v14mr10597150pjn.119.1562925924549; Fri, 12 Jul 2019 03:05:24 -0700 (PDT) Received: from localhost ([2401:fa00:1:b:e688:dfd2:a1a7:2956]) by smtp.gmail.com with ESMTPSA id s11sm7658859pgv.13.2019.07.12.03.05.21 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 12 Jul 2019 03:05:23 -0700 (PDT) From: Cheng-Yi Chiang To: linux-kernel@vger.kernel.org Subject: [PATCH v3 1/5] ASoC: hdmi-codec: Add an op to set callback function for plug event Date: Fri, 12 Jul 2019 18:04:39 +0800 Message-Id: <20190712100443.221322-2-cychiang@chromium.org> X-Mailer: git-send-email 2.22.0.510.g264f2c817a-goog In-Reply-To: <20190712100443.221322-1-cychiang@chromium.org> References: <20190712100443.221322-1-cychiang@chromium.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190712_030525_180578_838D4FF6 X-CRM114-Status: GOOD ( 14.20 ) X-BeenThere: linux-rockchip@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Upstream kernel work for Rockchip platforms List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: alsa-devel@alsa-project.org, dianders@chromium.org, 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 , Russell King , Mark Brown , Laurent Pinchart , Daniel Vetter , dgreid@chromium.org, linux-arm-kernel@lists.infradead.org, Cheng-Yi Chiang Sender: "Linux-rockchip" Errors-To: linux-rockchip-bounces+patchwork-linux-rockchip=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Add an op in hdmi_codec_ops so codec driver can register callback function to handle plug event. Driver in DRM can use this callback function to report connector status. Signed-off-by: Cheng-Yi Chiang --- include/sound/hdmi-codec.h | 16 +++++++++++++ sound/soc/codecs/hdmi-codec.c | 45 +++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+) diff --git a/include/sound/hdmi-codec.h b/include/sound/hdmi-codec.h index 7fea496f1f34..9a8661680256 100644 --- a/include/sound/hdmi-codec.h +++ b/include/sound/hdmi-codec.h @@ -47,6 +47,9 @@ struct hdmi_codec_params { int channels; }; +typedef void (*hdmi_codec_plugged_cb)(struct device *dev, + bool plugged); + struct hdmi_codec_pdata; struct hdmi_codec_ops { /* @@ -88,6 +91,13 @@ struct hdmi_codec_ops { */ int (*get_dai_id)(struct snd_soc_component *comment, struct device_node *endpoint); + + /* + * Hook callback function to handle connector plug event. + * Optional + */ + int (*hook_plugged_cb)(struct device *dev, void *data, + hdmi_codec_plugged_cb fn); }; /* HDMI codec initalization data */ @@ -99,6 +109,12 @@ struct hdmi_codec_pdata { void *data; }; +struct snd_soc_component; +struct snd_soc_jack; + +int hdmi_codec_set_jack_detect(struct snd_soc_component *component, + struct snd_soc_jack *jack); + #define HDMI_CODEC_DRV_NAME "hdmi-audio-codec" #endif /* __HDMI_CODEC_H__ */ diff --git a/sound/soc/codecs/hdmi-codec.c b/sound/soc/codecs/hdmi-codec.c index 0bf1c8cad108..32bf7441be5c 100644 --- a/sound/soc/codecs/hdmi-codec.c +++ b/sound/soc/codecs/hdmi-codec.c @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include @@ -274,6 +275,8 @@ struct hdmi_codec_priv { struct snd_pcm_chmap *chmap_info; unsigned int chmap_idx; struct mutex lock; + struct snd_soc_jack *jack; + unsigned int jack_status; }; static const struct snd_soc_dapm_widget hdmi_widgets[] = { @@ -663,6 +666,48 @@ static int hdmi_dai_probe(struct snd_soc_dai *dai) return 0; } +static void hdmi_codec_jack_report(struct hdmi_codec_priv *hcp, + unsigned int jack_status) +{ + if (hcp->jack && jack_status != hcp->jack_status) { + snd_soc_jack_report(hcp->jack, jack_status, SND_JACK_LINEOUT); + hcp->jack_status = jack_status; + } +} + +static void plugged_cb(struct device *dev, bool plugged) +{ + struct hdmi_codec_priv *hcp = dev_get_drvdata(dev); + + if (plugged) + hdmi_codec_jack_report(hcp, SND_JACK_LINEOUT); + else + hdmi_codec_jack_report(hcp, 0); +} + +/** + * hdmi_codec_set_jack_detect - register HDMI plugged callback + * @component: the hdmi-codec instance + * @jack: ASoC jack to report (dis)connection events on + */ +int hdmi_codec_set_jack_detect(struct snd_soc_component *component, + struct snd_soc_jack *jack) +{ + struct hdmi_codec_priv *hcp = snd_soc_component_get_drvdata(component); + int ret = -EOPNOTSUPP; + + if (hcp->hcd.ops->hook_plugged_cb) { + hcp->jack = jack; + ret = hcp->hcd.ops->hook_plugged_cb(component->dev->parent, + hcp->hcd.data, + plugged_cb); + if (ret) + hcp->jack = NULL; + } + return ret; +} +EXPORT_SYMBOL_GPL(hdmi_codec_set_jack_detect); + static int hdmi_dai_spdif_probe(struct snd_soc_dai *dai) { struct hdmi_codec_daifmt *cf = dai->playback_dma_data;