From patchwork Fri Oct 13 00:13:50 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Robert Tarasov X-Patchwork-Id: 10003563 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 93B7B602B3 for ; Fri, 13 Oct 2017 07:07:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 84A1D28FCA for ; Fri, 13 Oct 2017 07:07:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7980E28FDB; Fri, 13 Oct 2017 07:07:35 +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=-4.1 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 0148028FCA for ; Fri, 13 Oct 2017 07:07:35 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 01B6A6EA51; Fri, 13 Oct 2017 07:07:08 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-pf0-x233.google.com (mail-pf0-x233.google.com [IPv6:2607:f8b0:400e:c00::233]) by gabe.freedesktop.org (Postfix) with ESMTPS id A772D6E9CB for ; Fri, 13 Oct 2017 00:14:38 +0000 (UTC) Received: by mail-pf0-x233.google.com with SMTP id m63so7283619pfk.7 for ; Thu, 12 Oct 2017 17:14:38 -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; bh=2Hu/cfVMetnmNdBwOSlB+mLfXvD5mzu5Fs11EXTuN2M=; b=ZvPJ2wM161rkS7JHyhRfAlTcKY1g9625BALjJO3+Hwjjf1JA5eYOXn7u6GOOapFmFV 54pKRGIi7RbTeQEBmb7XG8Kf5nZ51GjuzaEUj2jfOTBlmUCWbF2k9m8KK2gk4eg/Pf7c sfxmD3HPygFi1vvBOXiwPZLAvEtFAU0DQPNrE= 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; bh=2Hu/cfVMetnmNdBwOSlB+mLfXvD5mzu5Fs11EXTuN2M=; b=nYGzCuoQcdCKpoBoqzaeGJtXJU9dAE6mY2GXRc6X8uILT9xs06B4HOLNCUarQMEYtK Q0PAYtnAApfAWU8NWRO9rl3HS+kkyUmYFZTCL0uN8bCFjEjVFeYlBusvhjXquQqepwzU BxbRmU5/nFJ0qrr9KemEIaLWwktG+C+yvOPOAMGRQkr1Dr2eod1IzYmyTdSG0ZYvpyoV jtIiAgdN0o2PnoigRIroIynH5f3tIK54muVnI8keCtXmolbiw/okMsW7V57NTgJydQM6 3jv72f/3kOm5pWMpFqgxx18D9KmNT87hmhhyk6AI2XGu0eI3+guhE32j+8SoE+GVWqJn EqhA== X-Gm-Message-State: AMCzsaWwgrRvSssZZCavJc70N7L08m6bLT/t1tsn0iMhQMDtPE3csvc1 RAq3tcNNTXDk4OlS1bBTsnuG5w== X-Google-Smtp-Source: AOwi7QA2mb6BSuiVNyGMobBKIYRgQcJUg0bE2mNkHH+DCbVmDLhrpgZos52swbDzojbRyBjGrgLFDg== X-Received: by 10.101.93.136 with SMTP id f8mr1535619pgt.60.1507853677981; Thu, 12 Oct 2017 17:14:37 -0700 (PDT) Received: from tutans-desktop.mtv.corp.google.com ([172.22.113.33]) by smtp.gmail.com with ESMTPSA id o10sm28137019pgq.69.2017.10.12.17.14.37 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 12 Oct 2017 17:14:37 -0700 (PDT) From: Robert Tarasov To: airlied@redhat.com Subject: [PATCH 2/2] drm/udl: Reading all edid blocks in DRM/UDL driver Date: Thu, 12 Oct 2017 17:13:50 -0700 Message-Id: <20171013001350.172155-2-tutankhamen@chromium.org> X-Mailer: git-send-email 2.15.0.rc0.271.g36b669edcc-goog In-Reply-To: <20171013001350.172155-1-tutankhamen@chromium.org> References: <20171013001350.172155-1-tutankhamen@chromium.org> X-Mailman-Approved-At: Fri, 13 Oct 2017 07:07:02 +0000 Cc: Robert Tarasov , marcheau@chromium.org, dri-devel@lists.freedesktop.org X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP Now DRM/UDL driver retreives all edid data blocks instead of only base one. Previous approch could lead to improper initialization of video mode with certain monitors. Signed-off-by: Robert Tarasov Reviewed-by: Alex Deucher --- drivers/gpu/drm/udl/udl_connector.c | 106 +++++++++++++++++++++++------------- 1 file changed, 68 insertions(+), 38 deletions(-) diff --git a/drivers/gpu/drm/udl/udl_connector.c b/drivers/gpu/drm/udl/udl_connector.c index 6a9250ac8f29..c3dc1fd20cb4 100644 --- a/drivers/gpu/drm/udl/udl_connector.c +++ b/drivers/gpu/drm/udl/udl_connector.c @@ -17,42 +17,79 @@ #include "udl_connector.h" #include "udl_drv.h" -/* dummy connector to just get EDID, - all UDL appear to have a DVI-D */ - -static u8 *udl_get_edid(struct udl_device *udl) +static bool udl_get_edid_block(struct udl_device *udl, int block_idx, + u8 *buff) { - u8 *block; - char *rbuf; int ret, i; + u8 *read_buff; - block = kmalloc(EDID_LENGTH, GFP_KERNEL); - if (block == NULL) - return NULL; - - rbuf = kmalloc(2, GFP_KERNEL); - if (rbuf == NULL) - goto error; + read_buff = kmalloc(2, GFP_KERNEL); + if (!read_buff) + return false; for (i = 0; i < EDID_LENGTH; i++) { + int bval = (i + block_idx * EDID_LENGTH) << 8; ret = usb_control_msg(udl->udev, - usb_rcvctrlpipe(udl->udev, 0), (0x02), - (0x80 | (0x02 << 5)), i << 8, 0xA1, rbuf, 2, - HZ); + usb_rcvctrlpipe(udl->udev, 0), + (0x02), (0x80 | (0x02 << 5)), bval, + 0xA1, read_buff, 2, HZ); if (ret < 1) { DRM_ERROR("Read EDID byte %d failed err %x\n", i, ret); - goto error; + kfree(read_buff); + return false; } - block[i] = rbuf[1]; + buff[i] = read_buff[1]; } - kfree(rbuf); - return block; + kfree(read_buff); + return true; +} -error: - kfree(block); - kfree(rbuf); - return NULL; +static bool udl_get_edid(struct udl_device *udl, u8 **result_buff, + int *result_buff_size) +{ + int i, extensions; + u8 *block_buff = NULL, *buff_ptr; + + block_buff = kmalloc(EDID_LENGTH, GFP_KERNEL); + if (block_buff == NULL) + return false; + + if (udl_get_edid_block(udl, 0, block_buff) && + memchr_inv(block_buff, 0, EDID_LENGTH)) { + extensions = ((struct edid *)block_buff)->extensions; + if (extensions > 0) { + /* we have to read all extensions one by one */ + *result_buff_size = EDID_LENGTH * (extensions + 1); + *result_buff = kmalloc(*result_buff_size, GFP_KERNEL); + buff_ptr = *result_buff; + if (buff_ptr == NULL) { + kfree(block_buff); + return false; + } + memcpy(buff_ptr, block_buff, EDID_LENGTH); + kfree(block_buff); + buff_ptr += EDID_LENGTH; + for (i = 1; i < extensions; ++i) { + if (udl_get_edid_block(udl, i, buff_ptr)) { + buff_ptr += EDID_LENGTH; + } else { + kfree(*result_buff); + *result_buff = NULL; + return false; + } + } + return true; + } + /* we have only base edid block */ + *result_buff = block_buff; + *result_buff_size = EDID_LENGTH; + return true; + } + + kfree(block_buff); + + return false; } static int udl_get_modes(struct drm_connector *connector) @@ -84,33 +121,26 @@ static int udl_mode_valid(struct drm_connector *connector, static enum drm_connector_status udl_detect(struct drm_connector *connector, bool force) { - struct edid *edid; + u8 *edid_buff = NULL; + int edid_buff_size = 0; struct udl_device *udl = connector->dev->dev_private; struct udl_drm_connector *udl_connector = container_of(connector, struct udl_drm_connector, connector); + /* cleanup previous edid */ if (udl_connector->edid != NULL) { kfree(udl_connector->edid); udl_connector->edid = NULL; } - edid = (struct edid *)udl_get_edid(udl); - if (!edid || !memchr_inv(edid, 0, EDID_LENGTH)) - return connector_status_disconnected; - udl_connector->edid = edid; - - /* - * We only read the main block, but if the monitor reports extension - * blocks then the drm edid code expects them to be present, so patch - * the extension count to 0. - */ - udl_connector->edid->checksum += - udl_connector->edid->extensions; - udl_connector->edid->extensions = 0; + if (!udl_get_edid(udl, &edid_buff, &edid_buff_size)) + return connector_status_disconnected; + udl_connector->edid = (struct edid *)edid_buff; + return connector_status_connected; }