From patchwork Tue Oct 22 11:45:01 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tzung-Bi Shih X-Patchwork-Id: 11205899 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1DCEC112C for ; Wed, 23 Oct 2019 08:11:17 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 060842173B for ; Wed, 23 Oct 2019 08:11:17 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 060842173B Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 779666E9AD; Wed, 23 Oct 2019 08:11:11 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-vk1-xa4a.google.com (mail-vk1-xa4a.google.com [IPv6:2607:f8b0:4864:20::a4a]) by gabe.freedesktop.org (Postfix) with ESMTPS id DC1C789260 for ; Tue, 22 Oct 2019 11:46:55 +0000 (UTC) Received: by mail-vk1-xa4a.google.com with SMTP id o66so7472009vka.19 for ; Tue, 22 Oct 2019 04:46:55 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=6PvO4YGcBPU7HqTKrAMBpr5jWnrEO6vhCWHVgxtCZF0=; b=OShTUsCiPtBFeuG5aqdlnyoFzVIbzGqa/inucGaKuG06BpjrXHcEFlKyUy06pw4XCj Z0GpzmHO2yKrbsuFvkkm+0GEJDFn0Zu5us6y6BNX483pbq23h4HccVa1Mnl4Z7IXfzUO K72f/sGfxxMNnWaUTggPRJ18/fSSLoorJiij+kYlS4Y+G9EkpdLil/wW5gIn2cftMwxZ YeCZ4oSBDi4D2NkOO7SmZJz0CZ23hCClnVlgelgODSrSiFGT64FMtzvKtwubSU2cx7WD kNxfkBoQeZb9+NoT9FfhO9tTDg6D8q7jxhTamhg9fD2nCNjx7iFmKsAZe8gHpubYK2Q/ hBsg== X-Gm-Message-State: APjAAAUObgwT8EYMWWNiN16QoAAyrfNqNq0Qt3FZGCPidKiLNQBqRsA/ J1FrFDiKSGSmJosYyMU8POr1ok/Ja/YD X-Google-Smtp-Source: APXvYqwY1rlBy1N3hHiRYbjJlOMwfLIOQOq0dmz2amkEN+2rQ4+TI3BcHF+QmqbKwaRye4ZzLeXpjHYP/Bkz X-Received: by 2002:a67:f2da:: with SMTP id a26mr1534141vsn.60.1571744814867; Tue, 22 Oct 2019 04:46:54 -0700 (PDT) Date: Tue, 22 Oct 2019 19:45:01 +0800 In-Reply-To: <20191022114505.196852-1-tzungbi@google.com> Message-Id: <20191022193301.2.I66284413ef7dbbf4b6ea7735f71807ebd35bf7e8@changeid> Mime-Version: 1.0 References: <20191022114505.196852-1-tzungbi@google.com> X-Mailer: git-send-email 2.23.0.866.gb869b98d4c-goog Subject: [PATCH 2/6] drm: bridge: it6505: bridge to hdmi-codec From: Tzung-Bi Shih To: broonie@kernel.org, robh+dt@kernel.org, narmstrong@baylibre.com X-Mailman-Approved-At: Wed, 23 Oct 2019 08:09:38 +0000 X-Mailman-Original-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=6PvO4YGcBPU7HqTKrAMBpr5jWnrEO6vhCWHVgxtCZF0=; b=v/XhJrE4hvhwOzEGcKs+eQoCDnnCj5mUo5POIAosRXGG9AR786k5ivdMEx0u1rAa0G 6FwQqiAnM4B6RlupEtxMjyDNTPzx34+E+/70eATGUSkjoJ8W8GvCVILVpBm2wwS0OLtF FsHUuxV6o+LY4rkICqCZ2pv588XXJ85QW0p3TajaPFxkmYIuxmsJAgn01++mJD7sr8FX qQK7k3vaWYUeu/1UDlFrcRHs8lKDl5yseG5047lhqeRkvc7QVEOoMnskxTlBn2dviIYF WvDKYhDmT/6v2QcIjvBcyBFdj5zYQORvKyeT9rKwpfGTE+vQjTOHSioHV293JvSx2+5k jm2g== X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: devicetree@vger.kernel.org, alsa-devel@alsa-project.org, cychiang@google.com, jonas@kwiboo.se, allen.chen@ite.com.tw, jernej.skrabec@siol.net, dri-devel@lists.freedesktop.org, Laurent.pinchart@ideasonboard.com, tzungbi@google.com, dgreid@google.com Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" From: Allen Chen Bridge to hdmi-codec to support audio feature. It is observed that some DP-to-HDMI dongles will get into bad states if sending InfoFrame without audio data. Defer to enable it6505's audio feature when PCM triggers START or RESUME. Signed-off-by: Allen Chen Signed-off-by: Tzung-Bi Shih --- drivers/gpu/drm/bridge/ite-it6505.c | 152 ++++++++++++++++++++++++++++ 1 file changed, 152 insertions(+) diff --git a/drivers/gpu/drm/bridge/ite-it6505.c b/drivers/gpu/drm/bridge/ite-it6505.c index 5e046f677343..1d19184d2056 100644 --- a/drivers/gpu/drm/bridge/ite-it6505.c +++ b/drivers/gpu/drm/bridge/ite-it6505.c @@ -26,6 +26,8 @@ #include #include +#include + #define AX 0 #define BX 1 #define AUDSEL I2S @@ -146,6 +148,7 @@ struct it6505 { struct notifier_block event_nb; struct extcon_dev *extcon; struct work_struct extcon_wq; + struct delayed_work delayed_audio; enum sys_status status; bool hbr; u8 en_ssc; @@ -1223,6 +1226,149 @@ static void it6505_set_audio(struct it6505 *it6505) dptxset(it6505, 0xD3, 0x20, 0x00); } +static void it6505_delayed_audio(struct work_struct *work) +{ + struct it6505 *it6505 = container_of(work, struct it6505, + delayed_audio.work); + + it6505_set_audio(it6505); + it6505->en_audio = 1; +} + +static int it6505_audio_hw_params(struct device *dev, void *data, + struct hdmi_codec_daifmt *daifmt, + struct hdmi_codec_params *params) +{ + struct it6505 *it6505 = dev_get_drvdata(dev); + unsigned int channel_num = params->cea.channels; + + DRM_DEV_DEBUG_DRIVER(dev, "setting %d Hz, %d bit, %d channels\n", + params->sample_rate, params->sample_width, + channel_num); + + if (!it6505->bridge.encoder) + return -ENODEV; + + switch (params->sample_rate) { + case 24000: + it6505->aud_fs = AUD24K; + break; + case 32000: + it6505->aud_fs = AUD32K; + break; + case 44100: + it6505->aud_fs = AUD44P1K; + break; + case 48000: + it6505->aud_fs = AUD48K; + break; + case 88200: + it6505->aud_fs = AUD88P2K; + break; + case 96000: + it6505->aud_fs = AUD96K; + break; + case 176400: + it6505->aud_fs = AUD176P4K; + break; + case 192000: + it6505->aud_fs = AUD192K; + break; + default: + DRM_DEV_DEBUG_DRIVER(dev, "sample rate: %d Hz not support", + params->sample_rate); + return -EINVAL; + } + + switch (params->sample_width) { + case 16: + it6505->audwordlength = AUD16BIT; + break; + case 18: + it6505->audwordlength = AUD18BIT; + break; + case 20: + it6505->audwordlength = AUD20BIT; + break; + case 24: + case 32: + it6505->audwordlength = AUD24BIT; + break; + default: + DRM_DEV_DEBUG_DRIVER(dev, "wordlength: %d bit not support", + params->sample_width); + return -EINVAL; + } + + if (channel_num == 0 || channel_num % 2) { + DRM_DEV_DEBUG_DRIVER(dev, "channel number: %d not support", + channel_num); + return -EINVAL; + } + it6505->aud_ch = channel_num; + + return 0; +} + +static int it6505_audio_trigger(struct device *dev, int event) +{ + struct it6505 *it6505 = dev_get_drvdata(dev); + + DRM_DEV_DEBUG_DRIVER(dev, "event: %d", event); + switch (event) { + case HDMI_CODEC_TRIGGER_EVENT_START: + case HDMI_CODEC_TRIGGER_EVENT_RESUME: + queue_delayed_work(system_wq, &it6505->delayed_audio, + msecs_to_jiffies(180)); + break; + case HDMI_CODEC_TRIGGER_EVENT_STOP: + case HDMI_CODEC_TRIGGER_EVENT_SUSPEND: + cancel_delayed_work(&it6505->delayed_audio); + break; + default: + return -EINVAL; + } + + return 0; +} + +static void it6505_audio_shutdown(struct device *dev, void *data) +{ + struct it6505 *it6505 = dev_get_drvdata(dev); + + dptxset(it6505, 0xE8, 0x22, 0x00); + dptxset(it6505, 0x05, 0x02, 0x02); + it6505->en_audio = 0; +} + +static const struct hdmi_codec_ops it6505_audio_codec_ops = { + .hw_params = it6505_audio_hw_params, + .trigger = it6505_audio_trigger, + .audio_shutdown = it6505_audio_shutdown, +}; + +static int it6505_register_audio_driver(struct device *dev) +{ + struct it6505 *it6505 = dev_get_drvdata(dev); + struct hdmi_codec_pdata codec_data = { + .ops = &it6505_audio_codec_ops, + .max_i2s_channels = 8, + .i2s = 1, + }; + struct platform_device *pdev; + + pdev = platform_device_register_data(dev, HDMI_CODEC_DRV_NAME, + PLATFORM_DEVID_AUTO, &codec_data, + sizeof(codec_data)); + if (IS_ERR(pdev)) + return PTR_ERR(pdev); + + INIT_DELAYED_WORK(&it6505->delayed_audio, it6505_delayed_audio); + + DRM_DEV_DEBUG_DRIVER(dev, "bound to %s", HDMI_CODEC_DRV_NAME); + return 0; +} + /*************************************************************************** * DPCD Read and EDID ***************************************************************************/ @@ -2460,6 +2606,12 @@ static int it6505_i2c_probe(struct i2c_client *client, return err; } + err = it6505_register_audio_driver(dev); + if (err < 0) { + DRM_DEV_ERROR(dev, "Failed to register audio driver: %d", err); + return err; + } + /* Register aux channel */ it6505->aux.name = "DP-AUX"; it6505->aux.dev = dev;