From: Mario Limonciello <mario.limonciello@amd.com> To: <amd-gfx@lists.freedesktop.org>, Alex Deucher <alexander.deucher@amd.com>, Harry Wentland <harry.wentland@amd.com>, "Rafael J . Wysocki" <rafael@kernel.org>, Hans de Goede <hdegoede@redhat.com> Cc: open list <linux-kernel@vger.kernel.org>, "open list:DRM DRIVERS" <dri-devel@lists.freedesktop.org>, Melissa Wen <mwen@igalia.com>, "open list:ACPI" <linux-acpi@vger.kernel.org>, Mario Limonciello <mario.limonciello@amd.com>, Mark Pearson <mpearson-lenovo@squebb.ca> Subject: [PATCH v2 2/4] drm: Add drm_get_acpi_edid() helper Date: Tue, 30 Jan 2024 13:26:06 -0600 [thread overview] Message-ID: <20240130192608.11666-3-mario.limonciello@amd.com> (raw) In-Reply-To: <20240130192608.11666-1-mario.limonciello@amd.com> Some manufacturers have intentionally put an EDID that differs from the EDID on the internal panel on laptops. Drivers can call this helper to attempt to fetch the EDID from the BIOS's ACPI _DDC method. Signed-off-by: Mario Limonciello <mario.limonciello@amd.com> --- v1->v2: * Split code from previous amdgpu specific helper to generic drm helper. --- drivers/gpu/drm/Kconfig | 4 +++ drivers/gpu/drm/drm_edid.c | 73 ++++++++++++++++++++++++++++++++++++++ include/drm/drm_edid.h | 1 + 3 files changed, 78 insertions(+) diff --git a/drivers/gpu/drm/Kconfig b/drivers/gpu/drm/Kconfig index 2520db0b776e..0065dcb63745 100644 --- a/drivers/gpu/drm/Kconfig +++ b/drivers/gpu/drm/Kconfig @@ -21,6 +21,10 @@ menuconfig DRM select KCMP select VIDEO_CMDLINE select VIDEO_NOMODESET + select ACPI_VIDEO if ACPI + select BACKLIGHT_CLASS_DEVICE if ACPI + select INPUT if ACPI + select ACPI_WMI if X86 help Kernel-level support for the Direct Rendering Infrastructure (DRI) introduced in XFree86 4.0. If you say Y here, you need to select diff --git a/drivers/gpu/drm/drm_edid.c b/drivers/gpu/drm/drm_edid.c index 69c68804023f..1fbbeaa664b2 100644 --- a/drivers/gpu/drm/drm_edid.c +++ b/drivers/gpu/drm/drm_edid.c @@ -28,6 +28,7 @@ * DEALINGS IN THE SOFTWARE. */ +#include <acpi/video.h> #include <linux/bitfield.h> #include <linux/cec.h> #include <linux/hdmi.h> @@ -2188,6 +2189,47 @@ drm_do_probe_ddc_edid(void *data, u8 *buf, unsigned int block, size_t len) return ret == xfers ? 0 : -1; } +/** + * drm_do_probe_acpi_edid() - get EDID information via ACPI _DDC + * @data: struct drm_device + * @buf: EDID data buffer to be filled + * @block: 128 byte EDID block to start fetching from + * @len: EDID data buffer length to fetch + * + * Try to fetch EDID information by calling acpi_video_get_edid() function. + * + * Return: 0 on success or error code on failure. + */ +static int +drm_do_probe_acpi_edid(void *data, u8 *buf, unsigned int block, size_t len) +{ + struct drm_device *ddev = data; + struct acpi_device *acpidev = ACPI_COMPANION(ddev->dev); + unsigned char start = block * EDID_LENGTH; + void *edid; + int r; + + if (!acpidev) + return -ENODEV; + + /* fetch the entire edid from BIOS */ + r = acpi_video_get_edid(acpidev, ACPI_VIDEO_DISPLAY_LCD, -1, &edid); + if (r < 0) { + DRM_DEBUG_KMS("Failed to get EDID from ACPI: %d\n", r); + return -EINVAL; + } + if (len > r || start > r || start + len > r) { + r = EINVAL; + goto cleanup; + } + + memcpy(buf, edid + start, len); + r = 0; +cleanup: + kfree(edid); + return r; +} + static void connector_bad_edid(struct drm_connector *connector, const struct edid *edid, int num_blocks) { @@ -2643,6 +2685,37 @@ struct edid *drm_get_edid(struct drm_connector *connector, } EXPORT_SYMBOL(drm_get_edid); +/** + * drm_get_acpi_edid - get EDID data, if available + * @connector: connector we're probing + * + * Use the BIOS to attempt to grab EDID data if possible. If found, + * attach it to the connector. + * + * Return: Pointer to valid EDID or NULL if we couldn't find any. + */ +struct edid *drm_get_acpi_edid(struct drm_connector *connector) +{ + struct edid *edid = NULL; + + switch (connector->connector_type) { + case DRM_MODE_CONNECTOR_LVDS: + case DRM_MODE_CONNECTOR_eDP: + break; + default: + return NULL; + } + + if (connector->force == DRM_FORCE_OFF) + return NULL; + + edid = _drm_do_get_edid(connector, drm_do_probe_acpi_edid, connector->dev, NULL); + + drm_connector_update_edid_property(connector, edid); + return edid; +} +EXPORT_SYMBOL(drm_get_acpi_edid); + /** * drm_edid_read_custom - Read EDID data using given EDID block read function * @connector: Connector to use diff --git a/include/drm/drm_edid.h b/include/drm/drm_edid.h index 518d1b8106c7..60fbdc06badc 100644 --- a/include/drm/drm_edid.h +++ b/include/drm/drm_edid.h @@ -412,6 +412,7 @@ 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); +struct edid *drm_get_acpi_edid(struct drm_connector *connector); u32 drm_edid_get_panel_id(struct i2c_adapter *adapter); struct edid *drm_get_edid_switcheroo(struct drm_connector *connector, struct i2c_adapter *adapter); -- 2.34.1
WARNING: multiple messages have this Message-ID (diff)
From: Mario Limonciello <mario.limonciello@amd.com> To: <amd-gfx@lists.freedesktop.org>, Alex Deucher <alexander.deucher@amd.com>, Harry Wentland <harry.wentland@amd.com>, "Rafael J . Wysocki" <rafael@kernel.org>, Hans de Goede <hdegoede@redhat.com> Cc: "open list:ACPI" <linux-acpi@vger.kernel.org>, open list <linux-kernel@vger.kernel.org>, "open list:DRM DRIVERS" <dri-devel@lists.freedesktop.org>, Melissa Wen <mwen@igalia.com>, "Mark Pearson" <mpearson-lenovo@squebb.ca>, Mario Limonciello <mario.limonciello@amd.com> Subject: [PATCH v2 2/4] drm: Add drm_get_acpi_edid() helper Date: Tue, 30 Jan 2024 13:26:06 -0600 [thread overview] Message-ID: <20240130192608.11666-3-mario.limonciello@amd.com> (raw) In-Reply-To: <20240130192608.11666-1-mario.limonciello@amd.com> Some manufacturers have intentionally put an EDID that differs from the EDID on the internal panel on laptops. Drivers can call this helper to attempt to fetch the EDID from the BIOS's ACPI _DDC method. Signed-off-by: Mario Limonciello <mario.limonciello@amd.com> --- v1->v2: * Split code from previous amdgpu specific helper to generic drm helper. --- drivers/gpu/drm/Kconfig | 4 +++ drivers/gpu/drm/drm_edid.c | 73 ++++++++++++++++++++++++++++++++++++++ include/drm/drm_edid.h | 1 + 3 files changed, 78 insertions(+) diff --git a/drivers/gpu/drm/Kconfig b/drivers/gpu/drm/Kconfig index 2520db0b776e..0065dcb63745 100644 --- a/drivers/gpu/drm/Kconfig +++ b/drivers/gpu/drm/Kconfig @@ -21,6 +21,10 @@ menuconfig DRM select KCMP select VIDEO_CMDLINE select VIDEO_NOMODESET + select ACPI_VIDEO if ACPI + select BACKLIGHT_CLASS_DEVICE if ACPI + select INPUT if ACPI + select ACPI_WMI if X86 help Kernel-level support for the Direct Rendering Infrastructure (DRI) introduced in XFree86 4.0. If you say Y here, you need to select diff --git a/drivers/gpu/drm/drm_edid.c b/drivers/gpu/drm/drm_edid.c index 69c68804023f..1fbbeaa664b2 100644 --- a/drivers/gpu/drm/drm_edid.c +++ b/drivers/gpu/drm/drm_edid.c @@ -28,6 +28,7 @@ * DEALINGS IN THE SOFTWARE. */ +#include <acpi/video.h> #include <linux/bitfield.h> #include <linux/cec.h> #include <linux/hdmi.h> @@ -2188,6 +2189,47 @@ drm_do_probe_ddc_edid(void *data, u8 *buf, unsigned int block, size_t len) return ret == xfers ? 0 : -1; } +/** + * drm_do_probe_acpi_edid() - get EDID information via ACPI _DDC + * @data: struct drm_device + * @buf: EDID data buffer to be filled + * @block: 128 byte EDID block to start fetching from + * @len: EDID data buffer length to fetch + * + * Try to fetch EDID information by calling acpi_video_get_edid() function. + * + * Return: 0 on success or error code on failure. + */ +static int +drm_do_probe_acpi_edid(void *data, u8 *buf, unsigned int block, size_t len) +{ + struct drm_device *ddev = data; + struct acpi_device *acpidev = ACPI_COMPANION(ddev->dev); + unsigned char start = block * EDID_LENGTH; + void *edid; + int r; + + if (!acpidev) + return -ENODEV; + + /* fetch the entire edid from BIOS */ + r = acpi_video_get_edid(acpidev, ACPI_VIDEO_DISPLAY_LCD, -1, &edid); + if (r < 0) { + DRM_DEBUG_KMS("Failed to get EDID from ACPI: %d\n", r); + return -EINVAL; + } + if (len > r || start > r || start + len > r) { + r = EINVAL; + goto cleanup; + } + + memcpy(buf, edid + start, len); + r = 0; +cleanup: + kfree(edid); + return r; +} + static void connector_bad_edid(struct drm_connector *connector, const struct edid *edid, int num_blocks) { @@ -2643,6 +2685,37 @@ struct edid *drm_get_edid(struct drm_connector *connector, } EXPORT_SYMBOL(drm_get_edid); +/** + * drm_get_acpi_edid - get EDID data, if available + * @connector: connector we're probing + * + * Use the BIOS to attempt to grab EDID data if possible. If found, + * attach it to the connector. + * + * Return: Pointer to valid EDID or NULL if we couldn't find any. + */ +struct edid *drm_get_acpi_edid(struct drm_connector *connector) +{ + struct edid *edid = NULL; + + switch (connector->connector_type) { + case DRM_MODE_CONNECTOR_LVDS: + case DRM_MODE_CONNECTOR_eDP: + break; + default: + return NULL; + } + + if (connector->force == DRM_FORCE_OFF) + return NULL; + + edid = _drm_do_get_edid(connector, drm_do_probe_acpi_edid, connector->dev, NULL); + + drm_connector_update_edid_property(connector, edid); + return edid; +} +EXPORT_SYMBOL(drm_get_acpi_edid); + /** * drm_edid_read_custom - Read EDID data using given EDID block read function * @connector: Connector to use diff --git a/include/drm/drm_edid.h b/include/drm/drm_edid.h index 518d1b8106c7..60fbdc06badc 100644 --- a/include/drm/drm_edid.h +++ b/include/drm/drm_edid.h @@ -412,6 +412,7 @@ 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); +struct edid *drm_get_acpi_edid(struct drm_connector *connector); u32 drm_edid_get_panel_id(struct i2c_adapter *adapter); struct edid *drm_get_edid_switcheroo(struct drm_connector *connector, struct i2c_adapter *adapter); -- 2.34.1
next prev parent reply other threads:[~2024-01-30 19:26 UTC|newest] Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top 2024-01-30 19:26 [PATCH v2 0/4] Add support for fetching EDID from ACPI _DDC Mario Limonciello 2024-01-30 19:26 ` Mario Limonciello 2024-01-30 19:26 ` [PATCH v2 1/4] ACPI: video: Handle fetching EDID that is longer than 256 bytes Mario Limonciello 2024-01-30 19:26 ` Mario Limonciello 2024-01-30 19:26 ` Mario Limonciello [this message] 2024-01-30 19:26 ` [PATCH v2 2/4] drm: Add drm_get_acpi_edid() helper Mario Limonciello 2024-01-31 7:53 ` kernel test robot 2024-01-31 7:53 ` kernel test robot 2024-01-31 9:01 ` kernel test robot 2024-01-31 9:01 ` kernel test robot 2024-01-31 9:34 ` kernel test robot 2024-01-31 9:34 ` kernel test robot 2024-01-31 10:37 ` kernel test robot 2024-01-31 10:37 ` kernel test robot 2024-01-31 15:00 ` kernel test robot 2024-01-31 15:00 ` kernel test robot 2024-01-30 19:26 ` [PATCH v2 3/4] drm/amd: Fetch the EDID from _DDC if available for eDP Mario Limonciello 2024-01-30 19:26 ` Mario Limonciello 2024-01-30 19:26 ` [PATCH v2 4/4] drm/nouveau: Use drm_get_acpi_edid() helper Mario Limonciello 2024-01-30 19:26 ` Mario Limonciello
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20240130192608.11666-3-mario.limonciello@amd.com \ --to=mario.limonciello@amd.com \ --cc=alexander.deucher@amd.com \ --cc=amd-gfx@lists.freedesktop.org \ --cc=dri-devel@lists.freedesktop.org \ --cc=harry.wentland@amd.com \ --cc=hdegoede@redhat.com \ --cc=linux-acpi@vger.kernel.org \ --cc=linux-kernel@vger.kernel.org \ --cc=mpearson-lenovo@squebb.ca \ --cc=mwen@igalia.com \ --cc=rafael@kernel.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.