From patchwork Thu Sep 7 09:28:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jani Nikula X-Patchwork-Id: 13376315 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 8B01CEE14D0 for ; Thu, 7 Sep 2023 09:29:10 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 3057F10E7AD; Thu, 7 Sep 2023 09:29:09 +0000 (UTC) Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.120]) by gabe.freedesktop.org (Postfix) with ESMTPS id DCF6410E7AA; Thu, 7 Sep 2023 09:29:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1694078944; x=1725614944; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=syQbZ5qRJK2FNj80CB+7mqUwCsFDRJzEz+YgluFuyJg=; b=RhROVW+vdg00J2FYVD/efL2xwFZTZVMzcecsQE49zJSL4A5xbIcbDQLx blLUSr4G0CmE4T1a7wmYKg/IcJItqNAXoPrQc3pbjd/wXMDstZ1GSSSD/ j5crcdhfW0JSbrjnv/+BuMsvG3GpSY6FtXRXXICx1W9rsX4Ex7zd2wR66 GTmugTkjRP/vH5gIgbS14cv27RixJK57mzzxqiAURWBxw0FAvjIHYF6BZ TE6zGilQnc6NLcIEVt2+x5+Ti0s0UAllU2YMvKQxY5QA9XSAE1weWBp+O faRuR+M6Q5LnLjJZRfqJk+TAS9+b1x7tmiffqyoDtwBOR08tvU0ehGPvX w==; X-IronPort-AV: E=McAfee;i="6600,9927,10825"; a="376217301" X-IronPort-AV: E=Sophos;i="6.02,234,1688454000"; d="scan'208";a="376217301" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Sep 2023 02:28:52 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10825"; a="735425511" X-IronPort-AV: E=Sophos;i="6.02,234,1688454000"; d="scan'208";a="735425511" Received: from iraduica-mobl1.ger.corp.intel.com (HELO localhost) ([10.252.61.21]) by orsmga007-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Sep 2023 02:28:50 -0700 From: Jani Nikula To: dri-devel@lists.freedesktop.org Date: Thu, 7 Sep 2023 12:28:23 +0300 Message-Id: X-Mailer: git-send-email 2.39.2 In-Reply-To: References: MIME-Version: 1.0 Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo Subject: [Intel-gfx] [PATCH 5/6] drm/edid: add helpers to get/set struct cea_sad from/to 3-byte sad X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: jani.nikula@intel.com, intel-gfx@lists.freedesktop.org Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" Add helpers to pack/unpack SADs. Both ways and non-static, as follow-up work needs them. Cc: Mitul Golani Signed-off-by: Jani Nikula Reviewed-by: Mitul Golani --- drivers/gpu/drm/drm_edid.c | 33 ++++++++++++++++++++++++--------- drivers/gpu/drm/drm_internal.h | 6 ++++++ 2 files changed, 30 insertions(+), 9 deletions(-) diff --git a/drivers/gpu/drm/drm_edid.c b/drivers/gpu/drm/drm_edid.c index fcdc2c314cde..1260e2688bd7 100644 --- a/drivers/gpu/drm/drm_edid.c +++ b/drivers/gpu/drm/drm_edid.c @@ -5499,6 +5499,27 @@ static void clear_eld(struct drm_connector *connector) connector->audio_latency[1] = 0; } +/* + * Get 3-byte SAD buf from struct cea_sad. + */ +void drm_edid_cta_sad_get(const struct cea_sad *cta_sad, u8 *sad) +{ + sad[0] = cta_sad->format << 3 | cta_sad->channels; + sad[1] = cta_sad->freq; + sad[2] = cta_sad->byte2; +} + +/* + * Set struct cea_sad from 3-byte SAD buf. + */ +void drm_edid_cta_sad_set(struct cea_sad *cta_sad, const u8 *sad) +{ + cta_sad->format = (sad[0] & 0x78) >> 3; + cta_sad->channels = sad[0] & 0x07; + cta_sad->freq = sad[1] & 0x7f; + cta_sad->byte2 = sad[2]; +} + /* * drm_edid_to_eld - build ELD from EDID * @connector: connector corresponding to the HDMI/DP sink @@ -5593,21 +5614,15 @@ static int _drm_edid_to_sad(const struct drm_edid *drm_edid, cea_db_iter_for_each(db, &iter) { if (cea_db_tag(db) == CTA_DB_AUDIO) { struct cea_sad *sads; - int j; + int i; count = cea_db_payload_len(db) / 3; /* SAD is 3B */ sads = kcalloc(count, sizeof(*sads), GFP_KERNEL); *psads = sads; if (!sads) return -ENOMEM; - for (j = 0; j < count; j++) { - const u8 *sad = &db->data[j * 3]; - - sads[j].format = (sad[0] & 0x78) >> 3; - sads[j].channels = sad[0] & 0x7; - sads[j].freq = sad[1] & 0x7F; - sads[j].byte2 = sad[2]; - } + for (i = 0; i < count; i++) + drm_edid_cta_sad_set(&sads[i], &db->data[i * 3]); break; } } diff --git a/drivers/gpu/drm/drm_internal.h b/drivers/gpu/drm/drm_internal.h index ab9a472f4a47..5b7c661da459 100644 --- a/drivers/gpu/drm/drm_internal.h +++ b/drivers/gpu/drm/drm_internal.h @@ -22,6 +22,7 @@ */ #include +#include #include #include @@ -31,6 +32,7 @@ #define DRM_IF_VERSION(maj, min) (maj << 16 | min) +struct cea_sad; struct dentry; struct dma_buf; struct iosys_map; @@ -265,3 +267,7 @@ int drm_syncobj_query_ioctl(struct drm_device *dev, void *data, void drm_framebuffer_print_info(struct drm_printer *p, unsigned int indent, const struct drm_framebuffer *fb); void drm_framebuffer_debugfs_init(struct drm_device *dev); + +/* drm_edid.c */ +void drm_edid_cta_sad_get(const struct cea_sad *cta_sad, u8 *sad); +void drm_edid_cta_sad_set(struct cea_sad *cta_sad, const u8 *sad);