From patchwork Fri Apr 19 17:01:25 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= X-Patchwork-Id: 2466421 Return-Path: X-Original-To: patchwork-dri-devel@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by patchwork2.kernel.org (Postfix) with ESMTP id B9B5DDF25A for ; Fri, 19 Apr 2013 17:01:54 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 672B6E6801 for ; Fri, 19 Apr 2013 10:01:54 -0700 (PDT) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-ea0-f173.google.com (mail-ea0-f173.google.com [209.85.215.173]) by gabe.freedesktop.org (Postfix) with ESMTP id 2050AE5F51 for ; Fri, 19 Apr 2013 10:01:36 -0700 (PDT) Received: by mail-ea0-f173.google.com with SMTP id k11so1825167eaj.4 for ; Fri, 19 Apr 2013 10:01:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:from:to:cc:subject:date:message-id:x-mailer:mime-version :content-type:content-transfer-encoding; bh=WZjGB7MxDeFz73IpgFTeEqLi9eMKWhBougpyor8lPhc=; b=o0Z35z4gxyVOpc2Pr0wmXJSl8Yn55Q86YgxUjCe8N0jlw/xhW0plj6mJR4R3QRcQ2S L8nVQfkW38FTbMY0i4GsETFlKNUr4w6Nc6BtW1lYOq7Y4wExQ6IxiNUoTMKZIp+zAiSs 1HU3g73th31umKAi1uS1N8WXwpF5kCtmnX376zvfZ9CwTQxPYnsBk6Q8oX+EEggPoTAo xrJv2gt2/1blMRBz+GzJ35u/ofaBE0FOdsG7x55WS4HzMarTduIwVpZeSO02FWx3soDz Mx3tOE6Z+/dkpK7Y8cil9iKb+VNmRfT0J/yx6cVSL9gIre6eta9bxAIJB1WJK2W7QOb6 fBSQ== X-Received: by 10.15.76.132 with SMTP id n4mr12375020eey.16.1366390896191; Fri, 19 Apr 2013 10:01:36 -0700 (PDT) Received: from linux-samsung700g7a.lan (evk8.neoplus.adsl.tpnet.pl. [83.20.208.8]) by mx.google.com with ESMTPS id bj2sm24362209eeb.1.2013.04.19.10.01.33 (version=TLSv1.2 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 19 Apr 2013 10:01:34 -0700 (PDT) From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= To: dri-devel@lists.freedesktop.org, Dave Airlie Subject: [PATCH 1/2] drm: add drm_edid_to_eld helper extracting SADs from EDID Date: Fri, 19 Apr 2013 19:01:25 +0200 Message-Id: <1366390886-4215-1-git-send-email-zajec5@gmail.com> X-Mailer: git-send-email 1.7.10.4 MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: dri-devel-bounces+patchwork-dri-devel=patchwork.kernel.org@lists.freedesktop.org Errors-To: dri-devel-bounces+patchwork-dri-devel=patchwork.kernel.org@lists.freedesktop.org Some devices (ATI/AMD cards) don't support passing ELD struct to the hardware but just require filling specific registers and then the hardware/firmware does the rest. In such cases we need to read the info from SAD blocks and put them in the correct registers. Signed-off-by: Rafa? Mi?ecki Reviewed-by: Christian König --- Changes since RFC: 1) Fixed allocation (and kcalloc instead of kzalloc) 2) Don't duplicate defines for audio codecs 3) Some variables scope --- drivers/gpu/drm/drm_edid.c | 58 ++++++++++++++++++++++++++++++++++++++++++++ include/drm/drm_edid.h | 9 +++++++ 2 files changed, 67 insertions(+) diff --git a/drivers/gpu/drm/drm_edid.c b/drivers/gpu/drm/drm_edid.c index e2acfdb..89ae211 100644 --- a/drivers/gpu/drm/drm_edid.c +++ b/drivers/gpu/drm/drm_edid.c @@ -2511,6 +2511,64 @@ void drm_edid_to_eld(struct drm_connector *connector, struct edid *edid) EXPORT_SYMBOL(drm_edid_to_eld); /** + * drm_edid_to_sad - extracts SADs from EDID + * @edid: EDID to parse + * @sads: pointer that will be set to the extracted SADs + * + * Looks for CEA EDID block and extracts SADs (Short Audio Descriptors) from it. + * + * Return number of found SADs or negative number on error. + */ +int drm_edid_to_sad(struct edid *edid, struct cea_sad **sads) +{ + int count = 0; + int i, start, end, dbl; + u8 *cea; + + cea = drm_find_cea_extension(edid); + if (!cea) { + DRM_DEBUG_KMS("SAD: no CEA Extension found\n"); + return -ENOENT; + } + + if (cea_revision(cea) < 3) { + DRM_DEBUG_KMS("SAD: wrong CEA revision\n"); + return -ENOTSUPP; + } + + if (cea_db_offsets(cea, &start, &end)) { + DRM_DEBUG_KMS("SAD: invalid data block offsets\n"); + return -EPROTO; + } + + for_each_cea_db(cea, i, start, end) { + u8 *db = &cea[i]; + + if (cea_db_tag(db) == AUDIO_BLOCK) { + dbl = cea_db_payload_len(db); + int j; + + count = dbl / 3; /* SAD is 3B */ + *sads = kcalloc(count, sizeof(**sads), GFP_KERNEL); + if (!*sads) + return -ENOMEM; + for (j = 0; j < count; j++) { + u8 *sad = &db[1 + 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]; + } + break; + } + } + + return count; +} +EXPORT_SYMBOL(drm_edid_to_sad); + +/** * drm_av_sync_delay - HDMI/DP sink audio-video sync delay in millisecond * @connector: connector associated with the HDMI/DP sink * @mode: the display mode diff --git a/include/drm/drm_edid.h b/include/drm/drm_edid.h index 5da1b4a..fc481fc 100644 --- a/include/drm/drm_edid.h +++ b/include/drm/drm_edid.h @@ -244,12 +244,21 @@ struct edid { #define EDID_PRODUCT_ID(e) ((e)->prod_code[0] | ((e)->prod_code[1] << 8)) +/* Short Audio Descriptor */ +struct cea_sad { + u8 format; + u8 channels; /* max number of channels - 1 */ + u8 freq; + u8 byte2; /* meaning depends on format */ +}; + struct drm_encoder; struct drm_connector; struct drm_display_mode; struct hdmi_avi_infoframe; void drm_edid_to_eld(struct drm_connector *connector, struct edid *edid); +int drm_edid_to_sad(struct edid *edid, struct cea_sad **sads); int drm_av_sync_delay(struct drm_connector *connector, struct drm_display_mode *mode); struct drm_connector *drm_select_eld(struct drm_encoder *encoder,