Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp11575466ybl; Fri, 27 Dec 2019 17:03:47 -0800 (PST) X-Google-Smtp-Source: APXvYqzoXPkbuw4w5txL7vVNGrlIcGY0kRHIpHYvNcWCGIlRrChUlf80++LwxKeOwYyPLkjodrVu X-Received: by 2002:a05:6808:a8a:: with SMTP id q10mr4014051oij.66.1577495027225; Fri, 27 Dec 2019 17:03:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1577495027; cv=none; d=google.com; s=arc-20160816; b=GsZdVvkZmaGY2WHcCfsHG8ubFbQkedgHa6t+vP6uZwJAHBeirZfH32mpP+NB8LcWg+ T494k+23PFMSCrUV4YO7R5bfjJY2M97qVBjc1H+nXN0UfznFUy1WZdwspF3LOhM2baJG cPR0l+qu9LoLM/8d3gUXuwO74wmQwxtBwlKtgNLGr9TdQ8KwoSaxeIJqTAMXznlcdVSY iBDBdO9CJYQNP6dsWaMmlY/B+FJ0PSVwSCR6RV6BPReKfIjctsyaeON3vF8CeS3cFsqx p1lmDHiSjeBsEJQMt72MCW4Q8rd+3R3AQnTCdLpjjAf8oUZnsHDFSFYCHwc/sR0NhgqW 6yvg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:date:subject:cc :to:from; bh=tym0/RcKyLrr4dyUUcqvO0neYwzkqBe5F9WKGPMU+ns=; b=izis/8EXiczZ5thRHuXTz0DJb2o8ZvS0IJn3qZZb+x4BvwJOtXFV3T1fhrLhZ3oKmX 6lZjz7WYv4rfHW8tiI6TAK3jti+lHEeG8ZvXP4DD3mRNw5VLKd7Dhri9YSDEd6dXp8Go 8jurEmZhSwOVONS/z1X0Nn6d+BY76TW1G/wJCVfxZdQkIPsnsbiIS4KqRD7iQbTUi+U3 Dc9k0QuJwvQ4pfYyCpPI2aciSCrZUjOSaJFWNlDDRZhcJUdy+oTlrMwceJZQPHl8cREd PmO4kBGzj6T1RVVue4IgR2qJnxekzqths1p2n6dJnl4QEDFNR6s2N+93IBlYsAFiJeON r8Kg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b1si14839100oiy.9.2019.12.27.17.03.34; Fri, 27 Dec 2019 17:03:47 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726220AbfL1BCl (ORCPT + 99 others); Fri, 27 Dec 2019 20:02:41 -0500 Received: from szxga06-in.huawei.com ([45.249.212.32]:49094 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725306AbfL1BCk (ORCPT ); Fri, 27 Dec 2019 20:02:40 -0500 Received: from DGGEMS402-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id 6A5A5C5BDA18D09E142B; Sat, 28 Dec 2019 09:02:38 +0800 (CST) Received: from localhost.localdomain (10.69.192.56) by DGGEMS402-HUB.china.huawei.com (10.3.19.202) with Microsoft SMTP Server id 14.3.439.0; Sat, 28 Dec 2019 09:02:20 +0800 From: Tian Tao To: , , , , , , , , , CC: Subject: [PATCH] drm/hisilicon: Checked the resolution is valid before connector Date: Sat, 28 Dec 2019 09:02:31 +0800 Message-ID: <1577494951-28435-1-git-send-email-tiantao6@hisilicon.com> X-Mailer: git-send-email 2.7.4 MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.69.192.56] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In the previous version, the callback function mode_valid of drm_connector_helper_funcs directly returned MODE_OK. Now we will ensure that the resolution is correct and return MODE_OK, otherwise return MODE_NOMODE. Signed-off-by: Tian Tao Signed-off-by: Gong junjie --- drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_vdac.c | 41 ++++++++++++++++++++++-- 1 file changed, 39 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_vdac.c b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_vdac.c index 6d98fdc..3d08210 100644 --- a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_vdac.c +++ b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_vdac.c @@ -11,22 +11,59 @@ * Jianhua Li */ +#include #include #include +#include #include #include "hibmc_drm_drv.h" #include "hibmc_drm_regs.h" +static const struct hibmc_resolution { + int w; + int h; +} hibmc_modetables[] = { + {640, 480}, {800, 600}, {1024, 768}, {1152, 864}, {1280, 768}, + {1280, 720}, {1280, 960}, {1280, 1024}, {1440, 900}, {1600, 900}, + {1600, 1200}, {1920, 1080}, {1920, 1200} +}; + +static int hibmc_valid_mode(int w, int h) +{ + int size = sizeof(hibmc_modetables) / sizeof(struct hibmc_resolution); + int i; + + for (i = 0; i < size; i++) { + if (hibmc_modetables[i].w == w && hibmc_modetables[i].h == h) + return 0; + } + + return -1; +} + static int hibmc_connector_get_modes(struct drm_connector *connector) { - return drm_add_modes_noedid(connector, 800, 600); + int count; + + drm_connector_update_edid_property(connector, NULL); + count = drm_add_modes_noedid(connector, 1920, 1200); + drm_set_preferred_mode(connector, 1024, 768); + + return count; } static enum drm_mode_status hibmc_connector_mode_valid(struct drm_connector *connector, struct drm_display_mode *mode) { - return MODE_OK; + int vrefresh = drm_mode_vrefresh(mode); + + if (vrefresh < 59 || vrefresh > 61) + return MODE_NOMODE; + else if (hibmc_valid_mode(mode->hdisplay, mode->vdisplay) != 0) + return MODE_NOMODE; + else + return MODE_OK; } static const struct drm_connector_helper_funcs -- 2.7.4