From patchwork Wed Mar 6 19:55:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hsin-Yi Wang X-Patchwork-Id: 13584609 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 8D42DC54E49 for ; Wed, 6 Mar 2024 20:04:00 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 7F21F113500; Wed, 6 Mar 2024 20:03:59 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="CcWOofzl"; dkim-atps=neutral Received: from mail-pf1-f169.google.com (mail-pf1-f169.google.com [209.85.210.169]) by gabe.freedesktop.org (Postfix) with ESMTPS id B8E801134FD for ; Wed, 6 Mar 2024 20:03:57 +0000 (UTC) Received: by mail-pf1-f169.google.com with SMTP id d2e1a72fcca58-6e5b1c6daa3so105904b3a.1 for ; Wed, 06 Mar 2024 12:03:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1709755437; x=1710360237; darn=lists.freedesktop.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=TO8narEInEW2sevq0mocA7Cmq1HqvsvqWDqWB03ZgLw=; b=CcWOofzl5oJC9b8moow200/SS9qyAmLeYAYZvy2vJOrkc1BJARqXvyfFUvsOu+2nuz GjQCmp8umY1OOMCembiE2YD6kFkPdNVECj5JydIwWf1WOqx+ERV0KOPbfpm3dn2/Isvy SBWmV4L1bljIqQyBm6JXzAf80D+/alEPAOUqw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709755437; x=1710360237; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=TO8narEInEW2sevq0mocA7Cmq1HqvsvqWDqWB03ZgLw=; b=Y43a+VTFDZvjFEuvgujl+7oi29IM+Yij9ihmn97utjKY8FlqEU+Bo9HiOQ8hPxCDcM heo/cCxlIymwN1JB1AKqOcS0N5G6Zn0mMMWz1MPgDeUOkBzj9gMmBiQ/LPbNTGG1AKzR nCmtktixcQ473XL5wBLBcTJp35/XNJi5h3jGxS4o+tnRxuu7PYchEfQNHpgp7YPtyrw1 QgvUBmPlCFZiM6WHhs22L/vkQh463+EZUWlkL3FX0Zxp4AOXslg76E274j01Lyx2Y7sA pOVut44OLP74afiW/jK9mprK9jvfHBI3poGGQlQg7Nn0YNVjtTZ0QBfoRLEc64n4rgRq ybdg== X-Forwarded-Encrypted: i=1; AJvYcCW8sHJbm6orcw9TZvZ0XnMN4GGesjTR3e59JCL0G/ci03t5oRMsKd1cBy5Xc3x/fXnn1t8CPTbRHLxou3E68UvnVNr6ZwTAaHzTyMErXoxD X-Gm-Message-State: AOJu0Yxax/BSpf7KPscUVtDDvS/32h1o+NrB91Wy/uQscuJ6uLgl3fLu O+65h0y+Sv7NFeRFtpap7W8ZNBJvRaIvsu8H4sQ7mGNmno6p1WhLV8GDP9IlZw== X-Google-Smtp-Source: AGHT+IFaWxLfmbk2letB3HSWHPl2i/aon3QJrVq0CuAm8X0TzZjoFsVZYJU8YOQj3s4ApQg/9FzYNQ== X-Received: by 2002:a05:6a20:7f99:b0:1a1:49be:c81d with SMTP id d25-20020a056a207f9900b001a149bec81dmr6833171pzj.33.1709755437070; Wed, 06 Mar 2024 12:03:57 -0800 (PST) Received: from hsinyi.sjc.corp.google.com ([2620:15c:9d:2:a215:f6c0:3224:5460]) by smtp.gmail.com with ESMTPSA id e3-20020aa79803000000b006e5667793d4sm11124241pfl.66.2024.03.06.12.03.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Mar 2024 12:03:56 -0800 (PST) From: Hsin-Yi Wang To: Jani Nikula , Dmitry Baryshkov , Douglas Anderson Cc: Neil Armstrong , Jessica Zhang , Sam Ravnborg , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Daniel Vetter , dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org Subject: [PATCH v5 1/6] drm_edid: Add a function to get EDID base block Date: Wed, 6 Mar 2024 11:55:51 -0800 Message-ID: <20240306200353.1436198-2-hsinyi@chromium.org> X-Mailer: git-send-email 2.44.0.278.ge034bb2e1d-goog In-Reply-To: <20240306200353.1436198-1-hsinyi@chromium.org> References: <20240306200353.1436198-1-hsinyi@chromium.org> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" It's found that some panels have variants that they share the same panel id although their EDID and names are different. Besides panel id, now we need more information from the EDID base block to distinguish these panel variants. Add drm_edid_read_base_block() to return the EDID base block, which is wrapped in struct drm_edid. Caller can further use it to get panel id or check if the block contains certain strings, such as panel name. Signed-off-by: Hsin-Yi Wang Reviewed-by: Douglas Anderson Reviewed-by: Jani Nikula --- v4->v5: use _drm_edid_alloc --- drivers/gpu/drm/drm_edid.c | 63 +++++++++++++++++++------------ drivers/gpu/drm/panel/panel-edp.c | 8 +++- include/drm/drm_edid.h | 3 +- 3 files changed, 46 insertions(+), 28 deletions(-) diff --git a/drivers/gpu/drm/drm_edid.c b/drivers/gpu/drm/drm_edid.c index 1ad94473e400..8c7e871eff58 100644 --- a/drivers/gpu/drm/drm_edid.c +++ b/drivers/gpu/drm/drm_edid.c @@ -2764,58 +2764,71 @@ static u32 edid_extract_panel_id(const struct edid *edid) } /** - * drm_edid_get_panel_id - Get a panel's ID through DDC - * @adapter: I2C adapter to use for DDC + * drm_edid_get_panel_id - Get a panel's ID from EDID + * @drm_edid: EDID that contains panel ID. * - * This function reads the first block of the EDID of a panel and (assuming + * This function uses the first block of the EDID of a panel and (assuming * that the EDID is valid) extracts the ID out of it. The ID is a 32-bit value * (16 bits of manufacturer ID and 16 bits of per-manufacturer ID) that's * supposed to be different for each different modem of panel. * + * Return: A 32-bit ID that should be different for each make/model of panel. + * See the functions drm_edid_encode_panel_id() and + * drm_edid_decode_panel_id() for some details on the structure of this + * ID. + */ +u32 drm_edid_get_panel_id(const struct drm_edid *drm_edid) +{ + return edid_extract_panel_id(drm_edid->edid); +} +EXPORT_SYMBOL(drm_edid_get_panel_id); + +/** + * drm_edid_read_base_block - Get a panel's EDID base block + * @adapter: I2C adapter to use for DDC + * + * This function returns the drm_edid containing the first block of the EDID of + * a panel. + * * This function is intended to be used during early probing on devices where * more than one panel might be present. Because of its intended use it must - * assume that the EDID of the panel is correct, at least as far as the ID - * is concerned (in other words, we don't process any overrides here). + * assume that the EDID of the panel is correct, at least as far as the base + * block is concerned (in other words, we don't process any overrides here). + * + * Caller should call drm_edid_free() after use. * * NOTE: it's expected that this function and drm_do_get_edid() will both * be read the EDID, but there is no caching between them. Since we're only * reading the first block, hopefully this extra overhead won't be too big. * - * Return: A 32-bit ID that should be different for each make/model of panel. - * See the functions drm_edid_encode_panel_id() and - * drm_edid_decode_panel_id() for some details on the structure of this - * ID. + * WARNING: Only use this function when the connector is unknown. For example, + * during the early probe of panel. The EDID read from the function is temporary + * and should be replaced by the full EDID returned from other drm_edid_read. + * + * Return: Pointer to allocated EDID base block, or NULL on any failure. */ - -u32 drm_edid_get_panel_id(struct i2c_adapter *adapter) +const struct drm_edid *drm_edid_read_base_block(struct i2c_adapter *adapter) { enum edid_block_status status; void *base_block; - u32 panel_id = 0; - - /* - * There are no manufacturer IDs of 0, so if there is a problem reading - * the EDID then we'll just return 0. - */ base_block = kzalloc(EDID_LENGTH, GFP_KERNEL); if (!base_block) - return 0; + return NULL; status = edid_block_read(base_block, 0, drm_do_probe_ddc_edid, adapter); edid_block_status_print(status, base_block, 0); - if (edid_block_status_valid(status, edid_block_tag(base_block))) - panel_id = edid_extract_panel_id(base_block); - else + if (!edid_block_status_valid(status, edid_block_tag(base_block))) { edid_block_dump(KERN_NOTICE, base_block, 0); + kfree(base_block); + return NULL; + } - kfree(base_block); - - return panel_id; + return _drm_edid_alloc(base_block, EDID_LENGTH); } -EXPORT_SYMBOL(drm_edid_get_panel_id); +EXPORT_SYMBOL(drm_edid_read_base_block); /** * drm_get_edid_switcheroo - get EDID data for a vga_switcheroo output diff --git a/drivers/gpu/drm/panel/panel-edp.c b/drivers/gpu/drm/panel/panel-edp.c index 3fb5fcd326a4..fe51680feb61 100644 --- a/drivers/gpu/drm/panel/panel-edp.c +++ b/drivers/gpu/drm/panel/panel-edp.c @@ -766,6 +766,7 @@ static const struct edp_panel_entry *find_edp_panel(u32 panel_id); static int generic_edp_panel_probe(struct device *dev, struct panel_edp *panel) { struct panel_desc *desc; + const struct drm_edid *base_block; u32 panel_id; char vend[4]; u16 product_id; @@ -795,8 +796,11 @@ static int generic_edp_panel_probe(struct device *dev, struct panel_edp *panel) goto exit; } - panel_id = drm_edid_get_panel_id(panel->ddc); - if (!panel_id) { + base_block = drm_edid_read_base_block(panel->ddc); + if (base_block) { + panel_id = drm_edid_get_panel_id(base_block); + drm_edid_free(base_block); + } else { dev_err(dev, "Couldn't identify panel via EDID\n"); ret = -EIO; goto exit; diff --git a/include/drm/drm_edid.h b/include/drm/drm_edid.h index 70ae6c290bdc..8b233865b085 100644 --- a/include/drm/drm_edid.h +++ b/include/drm/drm_edid.h @@ -565,7 +565,8 @@ struct edid *drm_do_get_edid(struct drm_connector *connector, void *data); struct edid *drm_get_edid(struct drm_connector *connector, struct i2c_adapter *adapter); -u32 drm_edid_get_panel_id(struct i2c_adapter *adapter); +const struct drm_edid *drm_edid_read_base_block(struct i2c_adapter *adapter); +u32 drm_edid_get_panel_id(const struct drm_edid *drm_edid); struct edid *drm_get_edid_switcheroo(struct drm_connector *connector, struct i2c_adapter *adapter); struct edid *drm_edid_duplicate(const struct edid *edid);