From: Guilherme Ivo Bozi <guilherme.bozi@usp.br>
To: airlied@gmail.com, alexander.deucher@amd.com,
christian.koenig@amd.com, harry.wentland@amd.com,
simona@ffwll.ch, siqueira@igalia.com, sunpeng.li@amd.com
Cc: Guilherme Ivo Bozi <guilherme.bozi@usp.br>,
amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org
Subject: [PATCH 1/9] drm/amd/display: add GPIO HW translation helpers
Date: Tue, 12 May 2026 15:59:44 -0300 [thread overview]
Message-ID: <20260512190019.228440-2-guilherme.bozi@usp.br> (raw)
In-Reply-To: <20260512190019.228440-1-guilherme.bozi@usp.br>
Add generic helpers and lookup table types for GPIO hardware
translation.
The new helpers provide reusable conversions between GPIO IDs,
register offsets and DDC lines, allowing ASIC-specific drivers
to replace large switch statements with static lookup tables.
No functional changes intended.
Signed-off-by: Guilherme Ivo Bozi <guilherme.bozi@usp.br>
---
.../drm/amd/display/dc/gpio/hw_translate.c | 86 +++++++++++++++++++
.../drm/amd/display/dc/gpio/hw_translate.h | 21 +++++
.../gpu/drm/amd/display/include/gpio_types.h | 48 +++++++++++
3 files changed, 155 insertions(+)
diff --git a/drivers/gpu/drm/amd/display/dc/gpio/hw_translate.c b/drivers/gpu/drm/amd/display/dc/gpio/hw_translate.c
index e6e36a912b13..18f14f9f244c 100644
--- a/drivers/gpu/drm/amd/display/dc/gpio/hw_translate.c
+++ b/drivers/gpu/drm/amd/display/dc/gpio/hw_translate.c
@@ -129,3 +129,89 @@ bool dal_hw_translate_init(
return false;
}
}
+
+bool dal_hw_translate_gpio_offset_to_id(
+ const struct gpio_id_offset_entry *table,
+ uint32_t table_size,
+ uint32_t offset,
+ uint32_t mask,
+ enum gpio_id *id,
+ uint32_t *en)
+{
+ uint32_t i;
+
+ for (i = 0; i < table_size; i++) {
+ const struct gpio_id_offset_entry *entry = &table[i];
+
+ if (entry->offset != offset)
+ continue;
+
+ if (entry->check_mask && entry->mask != mask)
+ continue;
+
+ *id = entry->id;
+ *en = entry->en;
+
+ return true;
+ }
+
+ return false;
+}
+
+/* we don't care about the GPIO_ID for DDC
+ * in DdcHandle it will use GPIO_ID_DDC_DATA/GPIO_ID_DDC_CLOCK
+ * directly in the create method
+ */
+bool dal_hw_translate_gpio_ddc_offset_to_id(
+ const struct gpio_ddc_offset_entry *table,
+ uint32_t table_size,
+ uint32_t offset,
+ uint32_t *en)
+{
+ uint32_t i;
+
+ for (i = 0; i < table_size; i++) {
+ const struct gpio_ddc_offset_entry *entry = &table[i];
+
+ if (entry->offset != offset)
+ continue;
+
+ *en = entry->en;
+
+ return true;
+ }
+
+ return false;
+}
+
+bool dal_hw_translate_id_to_offset(
+ const struct gpio_pin_entry *table,
+ uint32_t table_size,
+ enum gpio_id id,
+ uint32_t en,
+ struct gpio_pin_info *info)
+{
+ uint32_t i;
+
+ for (i = 0; i < table_size; i++) {
+ const struct gpio_pin_entry *entry = &table[i];
+
+ if (entry->id != id || entry->en != en)
+ continue;
+
+ info->offset = entry->offset;
+ info->mask = entry->mask;
+
+ info->offset_y = info->offset + 2;
+ info->offset_en = info->offset + 1;
+ info->offset_mask = info->offset - 1;
+
+ info->mask_y = info->mask;
+ info->mask_en = info->mask;
+ info->mask_mask = info->mask;
+
+ return true;
+ }
+
+ return false;
+}
diff --git a/drivers/gpu/drm/amd/display/dc/gpio/hw_translate.h b/drivers/gpu/drm/amd/display/dc/gpio/hw_translate.h
index 3a7d89ca1605..339e381f8fde 100644
--- a/drivers/gpu/drm/amd/display/dc/gpio/hw_translate.h
+++ b/drivers/gpu/drm/amd/display/dc/gpio/hw_translate.h
@@ -47,4 +47,25 @@ bool dal_hw_translate_init(
enum dce_version dce_version,
enum dce_environment dce_environment);
+bool dal_hw_translate_gpio_offset_to_id(
+ const struct gpio_id_offset_entry *table,
+ uint32_t table_size,
+ uint32_t offset,
+ uint32_t mask,
+ enum gpio_id *id,
+ uint32_t *en);
+
+bool dal_hw_translate_gpio_ddc_offset_to_id(
+ const struct gpio_ddc_offset_entry *table,
+ uint32_t table_size,
+ uint32_t offset,
+ uint32_t *en);
+
+bool dal_hw_translate_id_to_offset(
+ const struct gpio_pin_entry *table,
+ uint32_t table_size,
+ enum gpio_id id,
+ uint32_t en,
+ struct gpio_pin_info *info);
+
#endif
diff --git a/drivers/gpu/drm/amd/display/include/gpio_types.h b/drivers/gpu/drm/amd/display/include/gpio_types.h
index 8dd46ed799e5..afd3fc73a911 100644
--- a/drivers/gpu/drm/amd/display/include/gpio_types.h
+++ b/drivers/gpu/drm/amd/display/include/gpio_types.h
@@ -277,6 +277,49 @@ enum gpio_config_type {
GPIO_CONFIG_TYPE_I2C_AUX_DUAL_MODE
};
+struct gpio_id_offset_entry {
+ uint32_t offset;
+ uint32_t mask;
+
+ bool check_mask;
+
+ enum gpio_id id;
+ uint32_t en;
+};
+
+#define GPIO_ENTRY(_offset, _id, _en) \
+ { \
+ .offset = REG(_offset), \
+ .check_mask = false, \
+ .id = (_id), \
+ .en = (_en), \
+ }
+
+#define GPIO_MASK_ENTRY(_offset, _mask, _id, _en) \
+ { \
+ .offset = REG(_offset), \
+ .mask = (_mask), \
+ .check_mask = true, \
+ .id = (_id), \
+ .en = (_en), \
+ }
+
+struct gpio_pin_entry {
+ enum gpio_id id;
+ uint32_t en;
+
+ uint32_t offset;
+ uint32_t mask;
+};
+
+#define GPIO_PIN_ENTRY(_id, _en, _offset, _mask) \
+ { \
+ .id = (_id), \
+ .en = (_en), \
+ .offset = REG(_offset), \
+ .mask = (_mask), \
+ }
+
/* DDC configuration */
enum gpio_ddc_config_type {
@@ -293,6 +336,11 @@ struct gpio_ddc_config {
bool clock_en_bit_present;
};
+struct gpio_ddc_offset_entry {
+ uint32_t offset;
+ uint32_t en;
+};
+
/* HPD configuration */
struct gpio_hpd_config {
--
2.47.3
next prev parent reply other threads:[~2026-05-12 19:01 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-12 18:59 [PATCH 0/9] drm/amd/display: convert GPIO translation logic to lookup tables Guilherme Ivo Bozi
2026-05-12 18:59 ` Guilherme Ivo Bozi [this message]
2026-05-16 3:03 ` Claude review: drm/amd/display: add GPIO HW translation helpers Claude Code Review Bot
2026-05-12 18:59 ` [PATCH 2/9] drm/amd/display: convert dcn10 GPIO translation to lookup tables Guilherme Ivo Bozi
2026-05-16 3:03 ` Claude review: " Claude Code Review Bot
2026-05-12 18:59 ` [PATCH 3/9] drm/amd/display: convert dcn20 " Guilherme Ivo Bozi
2026-05-16 3:03 ` Claude review: " Claude Code Review Bot
2026-05-12 18:59 ` [PATCH 4/9] drm/amd/display: convert dcn21 " Guilherme Ivo Bozi
2026-05-16 3:03 ` Claude review: " Claude Code Review Bot
2026-05-12 18:59 ` [PATCH 5/9] drm/amd/display: convert dcn30 " Guilherme Ivo Bozi
2026-05-16 3:03 ` Claude review: " Claude Code Review Bot
2026-05-12 18:59 ` [PATCH 6/9] drm/amd/display: convert dcn315 " Guilherme Ivo Bozi
2026-05-16 3:03 ` Claude review: " Claude Code Review Bot
2026-05-12 18:59 ` [PATCH 7/9] drm/amd/display: convert dcn32 " Guilherme Ivo Bozi
2026-05-16 3:03 ` Claude review: " Claude Code Review Bot
2026-05-12 18:59 ` [PATCH 8/9] drm/amd/display: convert dcn401 " Guilherme Ivo Bozi
2026-05-16 3:03 ` Claude review: " Claude Code Review Bot
2026-05-12 18:59 ` [PATCH 9/9] drm/amd/display: convert dcn42 " Guilherme Ivo Bozi
2026-05-16 3:03 ` Claude review: " Claude Code Review Bot
2026-05-16 3:03 ` Claude review: drm/amd/display: convert GPIO translation logic " Claude Code Review Bot
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=20260512190019.228440-2-guilherme.bozi@usp.br \
--to=guilherme.bozi@usp.br \
--cc=airlied@gmail.com \
--cc=alexander.deucher@amd.com \
--cc=amd-gfx@lists.freedesktop.org \
--cc=christian.koenig@amd.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=harry.wentland@amd.com \
--cc=simona@ffwll.ch \
--cc=siqueira@igalia.com \
--cc=sunpeng.li@amd.com \
/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: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox