Skip to contentSkip to conversation

Add additional i2c buses

PATCH In review Alex Deucher 2 participants 12 messages Jan 6, 2025 – Jan 10, 2025

Subsystems (3)
lore
Share & tools
lore

Alex Deucher

author maintainer
#0 lore raw

cover Add additional i2c buses

At the momemt we only expose the i2c buses used by the driver for displays or EEPROMs. However, some OEMs/AIBs use extra i2c buses for things like RGB controls. Expose the extra i2c buses in case the OEM uses one of them.

Alex Deucher (10):
drm/amd/display/dm: drop extra parameters to create_i2c() drm/amd/display/dm: drop hw_support check in amdgpu_dm_i2c_xfer() drm/amd/display/dc: add a new helper to fetch the OEM ddc_service drm/amd/display/dm: handle OEM i2c buses in i2c functions drm/amd/display/dm: add support for OEM i2c bus drm/amd/display/dc: add support for oem i2c in atom_firmware_info_v3_1 drm/amd/display/dc: enable oem i2c support for DCE 12.x drm/amdgpu/atombios: drop empty function
drm/amdgpu: rework i2c init and fini
drm/amdgpu: add OEM i2c bus for polaris chips

 drivers/gpu/drm/amd/amdgpu/amdgpu_atombios.c  | 44 ++++++++----
 drivers/gpu/drm/amd/amdgpu/amdgpu_atombios.h  |  1 +
 drivers/gpu/drm/amd/amdgpu/amdgpu_device.c    |  6 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_i2c.c       | 19 ++++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_i2c.h       |  1 +
 drivers/gpu/drm/amd/amdgpu/amdgpu_mode.h      |  1 +
 .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 67 ++++++++++++++++---
 .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.h |  7 ++
 .../drm/amd/display/dc/bios/bios_parser2.c    | 13 +++-
 .../drm/amd/display/dc/core/dc_link_exports.c |  6 ++
 drivers/gpu/drm/amd/display/dc/dc.h           |  3 +
 .../dc/resource/dce120/dce120_resource.c      | 17 +++++
 12 files changed, 157 insertions(+), 28 deletions(-)
Signature · 1 line
2.47.1
author maintainer
#1 lore raw

PATCH 1/10 drm/amd/display/dm: drop extra parameters to create_i2c()

link_index can be fetched from the ddc_service; no need for a separate parameter. res is not used.

---
 drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +4 -5
index e9a4750a83d6c..139f1a74f05d5 100644
@@ -8256,9 +8256,7 @@ static const struct i2c_algorithm amdgpu_dm_i2c_algo = {
 };
 
 static struct amdgpu_i2c_adapter *
-create_i2c(struct ddc_service *ddc_service,
-	   int link_index,
-	   int *res)
+create_i2c(struct ddc_service *ddc_service)
 {
 	struct amdgpu_device *adev = ddc_service->ctx->driver_context;
 	struct amdgpu_i2c_adapter *i2c;
@@ -8269,7 +8267,8 @@ create_i2c(struct ddc_service *ddc_service,
 	i2c->base.owner = THIS_MODULE;
 	i2c->base.dev.parent = &adev->pdev->dev;
 	i2c->base.algo = &amdgpu_dm_i2c_algo;
-	snprintf(i2c->base.name, sizeof(i2c->base.name), "AMDGPU DM i2c hw bus %d", link_index);
+	snprintf(i2c->base.name, sizeof(i2c->base.name), "AMDGPU DM i2c hw bus %d",
+		 ddc_service->link->link_index);
 	i2c_set_adapdata(&i2c->base, i2c);
 	i2c->ddc_service = ddc_service;
 
@@ -8296,7 +8295,7 @@ static int amdgpu_dm_connector_init(struct amdgpu_display_manager *dm,
 	link->priv = aconnector;
 
 
-	i2c = create_i2c(link->ddc, link->link_index, &res);
+	i2c = create_i2c(link->ddc);
 	if (!i2c) {
 		DRM_ERROR("Failed to create i2c adapter data\n");
 		return -ENOMEM;
Signature · 1 line
2.47.1
author maintainer
#2 lore raw

PATCH 2/10 drm/amd/display/dm: drop hw_support check in amdgpu_dm_i2c_xfer()

In reply to Alex Deucher

DC supports SW i2c as well. Drop the check.

---
 drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +1 -1
index 139f1a74f05d5..030edc6a29e12 100644
@@ -8216,7 +8216,7 @@ static int amdgpu_dm_i2c_xfer(struct i2c_adapter *i2c_adap,
 	int i;
 	int result = -EIO;
 
-	if (!ddc_service->ddc_pin || !ddc_service->ddc_pin->hw_info.hw_supported)
+	if (!ddc_service->ddc_pin)
 		return result;
 
 	cmd.payloads = kcalloc(num, sizeof(struct i2c_payload), GFP_KERNEL);
Signature · 1 line
2.47.1
author maintainer
#3 lore raw

PATCH 3/10 drm/amd/display/dc: add a new helper to fetch the OEM ddc_service

In reply to Alex Deucher

This is the i2c bus used by OEMs for board specific i2c features like RGB.

---
 drivers/gpu/drm/amd/display/dc/core/dc_link_exports.c | 6 ++++++
 drivers/gpu/drm/amd/display/dc/dc.h                   | 3 +++
 2 files changed, 9 insertions(+)
drivers/gpu/drm/amd/display/dc/core/dc_link_exports.c +6 -0
index 457d60eeb486c..13636eb4ec3f4 100644
@@ -142,6 +142,12 @@ bool dc_link_update_dsc_config(struct pipe_ctx *pipe_ctx)
 	return link->dc->link_srv->update_dsc_config(pipe_ctx);
 }
 
+struct ddc_service *
+dc_get_oem_i2c_device(struct dc *dc)
+{
+	return dc->res_pool->oem_device;
+}
+
 bool dc_is_oem_i2c_device_present(
 	struct dc *dc,
 	size_t slave_address)
drivers/gpu/drm/amd/display/dc/dc.h +3 -0
index 8c6347413038d..47fde4f09f27b 100644
@@ -1945,6 +1945,9 @@ int dc_link_aux_transfer_raw(struct ddc_service *ddc,
 		struct aux_payload *payload,
 		enum aux_return_code_type *operation_result);
 
+struct ddc_service *
+dc_get_oem_i2c_device(struct dc *dc);
+
 bool dc_is_oem_i2c_device_present(
 	struct dc *dc,
 	size_t slave_address
Signature · 1 line
2.47.1
author maintainer
#4 lore raw

PATCH 4/10 drm/amd/display/dm: handle OEM i2c buses in i2c functions

In reply to Alex Deucher

Allow the creation of an OEM i2c bus and use the proper DC helpers for that case.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_mode.h      |  1 +
 .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 29 +++++++++++++------
 2 files changed, 21 insertions(+), 9 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_mode.h +1 -0
index 5e3faefc55109..6da4f946cac00 100644
@@ -609,6 +609,7 @@ struct amdgpu_i2c_adapter {
 	struct i2c_adapter base;
 
 	struct ddc_service *ddc_service;
+	bool oem;
 };
 
 #define TO_DM_AUX(x) container_of((x), struct amdgpu_dm_dp_aux, aux)
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +20 -9
index 030edc6a29e12..5c70b512e6367 100644
@@ -8235,11 +8235,18 @@ static int amdgpu_dm_i2c_xfer(struct i2c_adapter *i2c_adap,
 		cmd.payloads[i].data = msgs[i].buf;
 	}
 
-	if (dc_submit_i2c(
-			ddc_service->ctx->dc,
-			ddc_service->link->link_index,
-			&cmd))
-		result = num;
+	if (i2c->oem) {
+		if (dc_submit_i2c_oem(
+			    ddc_service->ctx->dc,
+			    &cmd))
+			result = num;
+	} else {
+		if (dc_submit_i2c(
+			    ddc_service->ctx->dc,
+			    ddc_service->link->link_index,
+			    &cmd))
+			result = num;
+	}
 
 	kfree(cmd.payloads);
 	return result;
@@ -8256,7 +8263,7 @@ static const struct i2c_algorithm amdgpu_dm_i2c_algo = {
 };
 
 static struct amdgpu_i2c_adapter *
-create_i2c(struct ddc_service *ddc_service)
+create_i2c(struct ddc_service *ddc_service, bool oem)
 {
 	struct amdgpu_device *adev = ddc_service->ctx->driver_context;
 	struct amdgpu_i2c_adapter *i2c;
@@ -8267,10 +8274,14 @@ create_i2c(struct ddc_service *ddc_service)
 	i2c->base.owner = THIS_MODULE;
 	i2c->base.dev.parent = &adev->pdev->dev;
 	i2c->base.algo = &amdgpu_dm_i2c_algo;
-	snprintf(i2c->base.name, sizeof(i2c->base.name), "AMDGPU DM i2c hw bus %d",
-		 ddc_service->link->link_index);
+	if (oem)
+		snprintf(i2c->base.name, sizeof(i2c->base.name), "AMDGPU DM i2c OEM bus");
+	else
+		snprintf(i2c->base.name, sizeof(i2c->base.name), "AMDGPU DM i2c hw bus %d",
+			 ddc_service->link->link_index);
 	i2c_set_adapdata(&i2c->base, i2c);
 	i2c->ddc_service = ddc_service;
+	i2c->oem = oem;
 
 	return i2c;
 }
@@ -8295,7 +8306,7 @@ static int amdgpu_dm_connector_init(struct amdgpu_display_manager *dm,
 	link->priv = aconnector;
 
 
-	i2c = create_i2c(link->ddc);
+	i2c = create_i2c(link->ddc, false);
 	if (!i2c) {
 		DRM_ERROR("Failed to create i2c adapter data\n");
 		return -ENOMEM;
Signature · 1 line
2.47.1
author maintainer
#5 lore raw

PATCH 5/10 drm/amd/display/dm: add support for OEM i2c bus

In reply to Alex Deucher

Expose the OEM i2c bus on boards that support it. This bus is used for OEM specific features like RGB, etc.

---
 .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 35 +++++++++++++++++++
 .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.h |  7 ++++
 2 files changed, 42 insertions(+)
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +35 -0
index 5c70b512e6367..d9b983bd1c2dc 100644
@@ -177,6 +177,8 @@ static int amdgpu_dm_init(struct amdgpu_device *adev);
 static void amdgpu_dm_fini(struct amdgpu_device *adev);
 static bool is_freesync_video_mode(const struct drm_display_mode *mode, struct amdgpu_dm_connector *aconnector);
 static void reset_freesync_config_for_crtc(struct dm_crtc_state *new_crtc_state);
+static struct amdgpu_i2c_adapter *
+create_i2c(struct ddc_service *ddc_service, bool oem);
 
 static enum drm_mode_subconnector get_subconnector_type(struct dc_link *link)
 {
@@ -2840,6 +2842,33 @@ static int amdgpu_dm_smu_write_watermarks_table(struct amdgpu_device *adev)
 	return 0;
 }
 
+static int dm_oem_i2c_hw_init(struct amdgpu_device *adev)
+{
+	struct amdgpu_display_manager *dm = &adev->dm;
+	struct amdgpu_i2c_adapter *oem_i2c;
+	struct ddc_service *oem_ddc_service;
+	int r;
+
+	oem_ddc_service = dc_get_oem_i2c_device(adev->dm.dc);
+	if (oem_ddc_service) {
+		oem_i2c = create_i2c(oem_ddc_service, true);
+		if (!oem_i2c) {
+			dev_info(adev->dev, "Failed to create oem i2c adapter data\n");
+			return -ENOMEM;
+		}
+
+		r = i2c_add_adapter(&oem_i2c->base);
+		if (r) {
+			dev_info(adev->dev, "Failed to register oem i2c\n");
+			kfree(oem_i2c);
+			return r;
+		}
+		dm->oem_i2c = oem_i2c;
+	}
+
+	return 0;
+}
+
 /**
  * dm_hw_init() - Initialize DC device
  * @ip_block: Pointer to the amdgpu_ip_block for this hw instance.
@@ -2871,6 +2900,10 @@ static int dm_hw_init(struct amdgpu_ip_block *ip_block)
 		return r;
 	amdgpu_dm_hpd_init(adev);
 
+	r = dm_oem_i2c_hw_init(adev);
+	if (r)
+		dev_info(adev->dev, "Failed to add OEM i2c bus\n");
+
 	return 0;
 }
 
@@ -2886,6 +2919,8 @@ static int dm_hw_fini(struct amdgpu_ip_block *ip_block)
 {
 	struct amdgpu_device *adev = ip_block->adev;
 
+	kfree(adev->dm.oem_i2c);
+
 	amdgpu_dm_hpd_fini(adev);
 
 	amdgpu_dm_irq_fini(adev);
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.h +7 -0
index e46e1365fe910..e1479228eba61 100644
@@ -606,6 +606,13 @@ struct amdgpu_display_manager {
 	 * Bounding box data read from dmub during early initialization for DCN4+
 	 */
 	struct dml2_soc_bb *bb_from_dmub;
+
+	/**
+	 * @oem_i2c:
+	 *
+	 * OEM i2c bus
+	 */
+	struct amdgpu_i2c_adapter *oem_i2c;
 };
 
 enum dsc_clock_force_state {
Signature · 1 line
2.47.1
author maintainer
#6 lore raw

PATCH 6/10 drm/amd/display/dc: add support for oem i2c in atom_firmware_info_v3_1

In reply to Alex Deucher

The fields are marked as reserved in atom_firmware_info_v3_1, but thet contain valid data in all of the vbios images I've looked at so add parse these fields as per atom_firmware_info_v3_2. The offsets are the same and the reset of the structure is the same.

---
 drivers/gpu/drm/amd/display/dc/bios/bios_parser2.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/display/dc/bios/bios_parser2.c +12 -1
index c9a6de110b742..470ec970217b5 100644
@@ -1778,6 +1778,7 @@ static enum bp_result get_firmware_info_v3_1(
 	struct dc_firmware_info *info)
 {
 	struct atom_firmware_info_v3_1 *firmware_info;
+	struct atom_firmware_info_v3_2 *firmware_info32;
 	struct atom_display_controller_info_v4_1 *dce_info = NULL;
 
 	if (!info)
@@ -1785,6 +1786,8 @@ static enum bp_result get_firmware_info_v3_1(
 
 	firmware_info = GET_IMAGE(struct atom_firmware_info_v3_1,
 			DATA_TABLES(firmwareinfo));
+	firmware_info32 = GET_IMAGE(struct atom_firmware_info_v3_2,
+			DATA_TABLES(firmwareinfo));
 
 	dce_info = GET_IMAGE(struct atom_display_controller_info_v4_1,
 			DATA_TABLES(dce_info));
@@ -1817,7 +1820,15 @@ static enum bp_result get_firmware_info_v3_1(
 				bp->cmd_tbl.get_smu_clock_info(bp, SMU9_SYSPLL0_ID) * 10;
 	}
 
-	info->oem_i2c_present = false;
+	/* These fields are marked as reserved in v3_1, but they appear to be populated
+	 * properly.
+	 */
+	if (firmware_info32->board_i2c_feature_id == 0x2) {
+		info->oem_i2c_present = true;
+		info->oem_i2c_obj_id = firmware_info32->board_i2c_feature_gpio_id;
+	} else {
+		info->oem_i2c_present = false;
+	}
 
 	return BP_RESULT_OK;
 }
Signature · 1 line
2.47.1
author maintainer
#7 lore raw

PATCH 7/10 drm/amd/display/dc: enable oem i2c support for DCE 12.x

In reply to Alex Deucher

Use the value pulled from the vbios just like newer chips.

---
 .../dc/resource/dce120/dce120_resource.c        | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)
drivers/gpu/drm/amd/display/dc/resource/dce120/dce120_resource.c +17 -0
index c63c596234333..eb1e158d34361 100644
@@ -67,6 +67,7 @@
 #include "reg_helper.h"
 
 #include "dce100/dce100_resource.h"
+#include "link.h"
 
 #ifndef mmDP0_DP_DPHY_INTERNAL_CTRL
 	#define mmDP0_DP_DPHY_INTERNAL_CTRL		0x210f
@@ -659,6 +660,12 @@ static void dce120_resource_destruct(struct dce110_resource_pool *pool)
 
 	if (pool->base.dmcu != NULL)
 		dce_dmcu_destroy(&pool->base.dmcu);
+
+	if (pool->base.oem_device != NULL) {
+		struct dc *dc = pool->base.oem_device->ctx->dc;
+
+		dc->link_srv->destroy_ddc_service(&pool->base.oem_device);
+	}
 }
 
 static void read_dce_straps(
@@ -1054,6 +1061,7 @@ static bool dce120_resource_construct(
 	struct dc *dc,
 	struct dce110_resource_pool *pool)
 {
+	struct ddc_service_init_data ddc_init_data = {0};
 	unsigned int i;
 	int j;
 	struct dc_context *ctx = dc->ctx;
@@ -1257,6 +1265,15 @@ static bool dce120_resource_construct(
 
 	bw_calcs_data_update_from_pplib(dc);
 
+	if (dc->ctx->dc_bios->fw_info.oem_i2c_present) {
+		ddc_init_data.ctx = dc->ctx;
+		ddc_init_data.link = NULL;
+		ddc_init_data.id.id = dc->ctx->dc_bios->fw_info.oem_i2c_obj_id;
+		ddc_init_data.id.enum_id = 0;
+		ddc_init_data.id.type = OBJECT_TYPE_GENERIC;
+		pool->base.oem_device = dc->link_srv->create_ddc_service(&ddc_init_data);
+	}
+
 	return true;
 
 irqs_create_fail:
Signature · 1 line
2.47.1
author maintainer
#8 lore raw

PATCH 8/10 drm/amdgpu/atombios: drop empty function

In reply to Alex Deucher

This was leftover from when amdgpu was forked from radeon. The function is empty so drop it.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_atombios.c | 12 ------------
 1 file changed, 12 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_atombios.c +0 -12
index 093141ad6ed01..263242bd7c10c 100644
@@ -36,13 +36,6 @@
 #include "atombios_encoders.h"
 #include "bif/bif_4_1_d.h"
 
-static void amdgpu_atombios_lookup_i2c_gpio_quirks(struct amdgpu_device *adev,
-					  ATOM_GPIO_I2C_ASSIGMENT *gpio,
-					  u8 index)
-{
-
-}
-
 static struct amdgpu_i2c_bus_rec amdgpu_atombios_get_bus_rec_for_i2c_gpio(ATOM_GPIO_I2C_ASSIGMENT *gpio)
 {
 	struct amdgpu_i2c_bus_rec i2c;
@@ -108,9 +101,6 @@ struct amdgpu_i2c_bus_rec amdgpu_atombios_lookup_i2c_gpio(struct amdgpu_device *
 
 		gpio = &i2c_info->asGPIO_Info[0];
 		for (i = 0; i < num_indices; i++) {
-
-			amdgpu_atombios_lookup_i2c_gpio_quirks(adev, gpio, i);
-
 			if (gpio->sucI2cId.ucAccess == id) {
 				i2c = amdgpu_atombios_get_bus_rec_for_i2c_gpio(gpio);
 				break;
@@ -142,8 +132,6 @@ void amdgpu_atombios_i2c_init(struct amdgpu_device *adev)
 
 		gpio = &i2c_info->asGPIO_Info[0];
 		for (i = 0; i < num_indices; i++) {
-			amdgpu_atombios_lookup_i2c_gpio_quirks(adev, gpio, i);
-
 			i2c = amdgpu_atombios_get_bus_rec_for_i2c_gpio(gpio);
 
 			if (i2c.valid) {
Signature · 1 line
2.47.1
author maintainer
#9 lore raw

PATCH 9/10 drm/amdgpu: rework i2c init and fini

In reply to Alex Deucher

No functional change. Rework the code to allow for adding some additional i2c buses in conjunction with DC in the future.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 6 ++----
 drivers/gpu/drm/amd/amdgpu/amdgpu_i2c.c    | 8 ++++++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_i2c.h    | 1 +
 3 files changed, 11 insertions(+), 4 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +2 -4
index 0a121aab5c745..d6b473217c8b5 100644
@@ -4467,8 +4467,7 @@ int amdgpu_device_init(struct amdgpu_device *adev,
 				goto failed;
 			}
 			/* init i2c buses */
-			if (!amdgpu_device_has_dc_support(adev))
-				amdgpu_atombios_i2c_init(adev);
+			amdgpu_i2c_init(adev);
 		}
 	}
 
@@ -4737,8 +4736,7 @@ void amdgpu_device_fini_sw(struct amdgpu_device *adev)
 	amdgpu_reset_fini(adev);
 
 	/* free i2c buses */
-	if (!amdgpu_device_has_dc_support(adev))
-		amdgpu_i2c_fini(adev);
+	amdgpu_i2c_fini(adev);
 
 	if (amdgpu_emu_mode != 1)
 		amdgpu_atombios_fini(adev);
drivers/gpu/drm/amd/amdgpu/amdgpu_i2c.c +8 -0
index f0765ccde6680..72f73a186dd94 100644
@@ -225,6 +225,14 @@ void amdgpu_i2c_destroy(struct amdgpu_i2c_chan *i2c)
 	kfree(i2c);
 }
 
+void amdgpu_i2c_init(struct amdgpu_device *adev)
+{
+	if (!adev->is_atom_fw) {
+		if (!amdgpu_device_has_dc_support(adev))
+			amdgpu_atombios_i2c_init(adev);
+	}
+}
+
 /* remove all the buses */
 void amdgpu_i2c_fini(struct amdgpu_device *adev)
 {
drivers/gpu/drm/amd/amdgpu/amdgpu_i2c.h +1 -0
index 21e3d1dad0a12..1d3d3806e0ddb 100644
@@ -28,6 +28,7 @@ struct amdgpu_i2c_chan *amdgpu_i2c_create(struct drm_device *dev,
 					  const struct amdgpu_i2c_bus_rec *rec,
 					  const char *name);
 void amdgpu_i2c_destroy(struct amdgpu_i2c_chan *i2c);
+void amdgpu_i2c_init(struct amdgpu_device *adev);
 void amdgpu_i2c_fini(struct amdgpu_device *adev);
 struct amdgpu_i2c_chan *
 amdgpu_i2c_lookup(struct amdgpu_device *adev,
Signature · 1 line
2.47.1
author maintainer
#10 lore raw

PATCH 10/10 drm/amdgpu: add OEM i2c bus for polaris chips

In reply to Alex Deucher

It uses the VGADCC bus. DC doesn't use this bus, so it is safe to add it here.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_atombios.c | 32 ++++++++++++++++++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_atombios.h |  1 +
 drivers/gpu/drm/amd/amdgpu/amdgpu_i2c.c      | 13 +++++++-
 3 files changed, 45 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_atombios.c +32 -0
index 263242bd7c10c..e476e45b996a2 100644
@@ -144,6 +144,38 @@ void amdgpu_atombios_i2c_init(struct amdgpu_device *adev)
 	}
 }
 
+void amdgpu_atombios_oem_i2c_init(struct amdgpu_device *adev, u8 i2c_id)
+{
+	struct atom_context *ctx = adev->mode_info.atom_context;
+	ATOM_GPIO_I2C_ASSIGMENT *gpio;
+	struct amdgpu_i2c_bus_rec i2c;
+	int index = GetIndexIntoMasterTable(DATA, GPIO_I2C_Info);
+	struct _ATOM_GPIO_I2C_INFO *i2c_info;
+	uint16_t data_offset, size;
+	int i, num_indices;
+	char stmp[32];
+
+	if (amdgpu_atom_parse_data_header(ctx, index, &size, NULL, NULL, &data_offset)) {
+		i2c_info = (struct _ATOM_GPIO_I2C_INFO *)(ctx->bios + data_offset);
+
+		num_indices = (size - sizeof(ATOM_COMMON_TABLE_HEADER)) /
+			sizeof(ATOM_GPIO_I2C_ASSIGMENT);
+
+		gpio = &i2c_info->asGPIO_Info[0];
+		for (i = 0; i < num_indices; i++) {
+			i2c = amdgpu_atombios_get_bus_rec_for_i2c_gpio(gpio);
+
+			if (i2c.valid && i2c.i2c_id == i2c_id) {
+				sprintf(stmp, "OEM 0x%x", i2c.i2c_id);
+				adev->i2c_bus[i] = amdgpu_i2c_create(adev_to_drm(adev), &i2c, stmp);
+				break;
+			}
+			gpio = (ATOM_GPIO_I2C_ASSIGMENT *)
+				((u8 *)gpio + sizeof(ATOM_GPIO_I2C_ASSIGMENT));
+		}
+	}
+}
+
 struct amdgpu_gpio_rec
 amdgpu_atombios_lookup_gpio(struct amdgpu_device *adev,
 			    u8 id)
drivers/gpu/drm/amd/amdgpu/amdgpu_atombios.h +1 -0
index 0e16432d9a725..867bc5c5ce67d 100644
@@ -136,6 +136,7 @@ amdgpu_atombios_lookup_gpio(struct amdgpu_device *adev,
 struct amdgpu_i2c_bus_rec amdgpu_atombios_lookup_i2c_gpio(struct amdgpu_device *adev,
 							  uint8_t id);
 void amdgpu_atombios_i2c_init(struct amdgpu_device *adev);
+void amdgpu_atombios_oem_i2c_init(struct amdgpu_device *adev, u8 i2c_id);
 
 bool amdgpu_atombios_has_dce_engine_info(struct amdgpu_device *adev);
 
drivers/gpu/drm/amd/amdgpu/amdgpu_i2c.c +12 -1
index 72f73a186dd94..8179d0814db99 100644
@@ -228,8 +228,19 @@ void amdgpu_i2c_destroy(struct amdgpu_i2c_chan *i2c)
 void amdgpu_i2c_init(struct amdgpu_device *adev)
 {
 	if (!adev->is_atom_fw) {
-		if (!amdgpu_device_has_dc_support(adev))
+		if (!amdgpu_device_has_dc_support(adev)) {
 			amdgpu_atombios_i2c_init(adev);
+		} else {
+			switch (adev->asic_type) {
+			case CHIP_POLARIS10:
+			case CHIP_POLARIS11:
+			case CHIP_POLARIS12:
+				amdgpu_atombios_oem_i2c_init(adev, 0x97);
+				break;
+			default:
+				break;
+			}
+		}
 	}
 }
 
Signature · 1 line
2.47.1
maintainer Reviewed-by on the v1 series
#11 lore raw
In reply to Alex Deucher

Series is

Harry

Quoted 31 lines · Alex Deucher

At the momemt we only expose the i2c buses used by the driver for displays or EEPROMs. However, some OEMs/AIBs use extra i2c buses for things like RGB controls. Expose the extra i2c buses in case the OEM uses one of them.

Alex Deucher (10):
drm/amd/display/dm: drop extra parameters to create_i2c() drm/amd/display/dm: drop hw_support check in amdgpu_dm_i2c_xfer() drm/amd/display/dc: add a new helper to fetch the OEM ddc_service drm/amd/display/dm: handle OEM i2c buses in i2c functions drm/amd/display/dm: add support for OEM i2c bus drm/amd/display/dc: add support for oem i2c in atom_firmware_info_v3_1 drm/amd/display/dc: enable oem i2c support for DCE 12.x drm/amdgpu/atombios: drop empty function
drm/amdgpu: rework i2c init and fini
drm/amdgpu: add OEM i2c bus for polaris chips

 drivers/gpu/drm/amd/amdgpu/amdgpu_atombios.c  | 44 ++++++++----
 drivers/gpu/drm/amd/amdgpu/amdgpu_atombios.h  |  1 +
 drivers/gpu/drm/amd/amdgpu/amdgpu_device.c    |  6 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_i2c.c       | 19 ++++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_i2c.h       |  1 +
 drivers/gpu/drm/amd/amdgpu/amdgpu_mode.h      |  1 +
 .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 67 ++++++++++++++++---
 .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.h |  7 ++
 .../drm/amd/display/dc/bios/bios_parser2.c    | 13 +++-
 .../drm/amd/display/dc/core/dc_link_exports.c |  6 ++
 drivers/gpu/drm/amd/display/dc/dc.h           |  3 +
 .../dc/resource/dce120/dce120_resource.c      | 17 +++++
 12 files changed, 157 insertions(+), 28 deletions(-)