All of lore.kernel.org
 help / color / mirror / Atom feed
From: Imre Deak <imre.deak@intel.com>
To: <intel-gfx@lists.freedesktop.org>, <intel-xe@lists.freedesktop.org>
Subject: [PATCH 07/13] drm/i915/gmbus: Extract adapter creation and destruction
Date: Thu, 26 Nov 2026 12:07:47 +0200	[thread overview]
Message-ID: <20261126100755.1252635-8-imre.deak@intel.com> (raw)
In-Reply-To: <20261126100755.1252635-1-imre.deak@intel.com>

Move allocation, initialization and registration of an adapter into a
helper, and share its teardown.

This allows additional adapters to use the same setup and cleanup paths.

Signed-off-by: Imre Deak <imre.deak@intel.com>
---
 drivers/gpu/drm/i915/display/intel_gmbus.c | 113 +++++++++++----------
 1 file changed, 62 insertions(+), 51 deletions(-)

diff --git a/drivers/gpu/drm/i915/display/intel_gmbus.c b/drivers/gpu/drm/i915/display/intel_gmbus.c
index e80822d3e9185..8736b39e1ea62 100644
--- a/drivers/gpu/drm/i915/display/intel_gmbus.c
+++ b/drivers/gpu/drm/i915/display/intel_gmbus.c
@@ -28,6 +28,7 @@
  */
 
 #include <linux/debugfs.h>
+#include <linux/err.h>
 #include <linux/export.h>
 #include <linux/i2c-algo-bit.h>
 #include <linux/i2c.h>
@@ -1013,13 +1014,69 @@ static const struct i2c_lock_operations gmbus_lock_ops = {
 	.unlock_bus =  gmbus_unlock_bus,
 };
 
+static struct intel_gmbus *
+intel_gmbus_create(struct intel_display *display, unsigned int pin)
+{
+	struct pci_dev *pdev = to_pci_dev(display->drm->dev);
+	const struct gmbus_pin *gmbus_pin = get_gmbus_pin(display, pin);
+	struct intel_gmbus *bus;
+	int ret;
+
+	if (!gmbus_pin)
+		return NULL;
+
+	bus = kzalloc_obj(*bus);
+	if (!bus)
+		return ERR_PTR(-ENOMEM);
+
+	bus->adapter.owner = THIS_MODULE;
+	snprintf(bus->adapter.name, sizeof(bus->adapter.name),
+		 "i915 gmbus %s", gmbus_pin->name);
+	bus->adapter.dev.parent = &pdev->dev;
+	bus->display = display;
+	bus->adapter.algo = &gmbus_algorithm;
+	bus->adapter.lock_ops = &gmbus_lock_ops;
+
+	/*
+	 * We wish to retry with bit banging
+	 * after a timed out GMBUS attempt.
+	 */
+	bus->adapter.retries = 1;
+
+	/* By default use a conservative clock rate */
+	bus->reg0 = pin | GMBUS_RATE_100KHZ;
+
+	/* gmbus seems to be broken on i830 */
+	if (display->platform.i830)
+		bus->force_bit = 1;
+
+	intel_gpio_setup(bus, GPIO(display, gmbus_pin->gpio));
+
+	ret = i2c_add_adapter(&bus->adapter);
+	if (ret) {
+		kfree(bus);
+
+		return ERR_PTR(ret);
+	}
+
+	return bus;
+}
+
+static void intel_gmbus_destroy(struct intel_gmbus *bus)
+{
+	if (!bus)
+		return;
+
+	i2c_del_adapter(&bus->adapter);
+	kfree(bus);
+}
+
 /**
  * intel_gmbus_setup - instantiate all Intel i2c GMBuses
  * @display: display device
  */
 int intel_gmbus_setup(struct intel_display *display)
 {
-	struct pci_dev *pdev = to_pci_dev(display->drm->dev);
 	unsigned int pin;
 	int ret;
 
@@ -1036,48 +1093,10 @@ int intel_gmbus_setup(struct intel_display *display)
 	init_waitqueue_head(&display->gmbus.wait_queue);
 
 	for (pin = 0; pin < ARRAY_SIZE(display->gmbus.bus); pin++) {
-		const struct gmbus_pin *gmbus_pin;
-		struct intel_gmbus *bus;
+		struct intel_gmbus *bus = intel_gmbus_create(display, pin);
 
-		gmbus_pin = get_gmbus_pin(display, pin);
-		if (!gmbus_pin)
-			continue;
-
-		bus = kzalloc_obj(*bus);
-		if (!bus) {
-			ret = -ENOMEM;
-			goto err;
-		}
-
-		bus->adapter.owner = THIS_MODULE;
-		snprintf(bus->adapter.name,
-			 sizeof(bus->adapter.name),
-			 "i915 gmbus %s", gmbus_pin->name);
-
-		bus->adapter.dev.parent = &pdev->dev;
-		bus->display = display;
-
-		bus->adapter.algo = &gmbus_algorithm;
-		bus->adapter.lock_ops = &gmbus_lock_ops;
-
-		/*
-		 * We wish to retry with bit banging
-		 * after a timed out GMBUS attempt.
-		 */
-		bus->adapter.retries = 1;
-
-		/* By default use a conservative clock rate */
-		bus->reg0 = pin | GMBUS_RATE_100KHZ;
-
-		/* gmbus seems to be broken on i830 */
-		if (display->platform.i830)
-			bus->force_bit = 1;
-
-		intel_gpio_setup(bus, GPIO(display, gmbus_pin->gpio));
-
-		ret = i2c_add_adapter(&bus->adapter);
-		if (ret) {
-			kfree(bus);
+		if (IS_ERR(bus)) {
+			ret = PTR_ERR(bus);
 			goto err;
 		}
 
@@ -1132,15 +1151,7 @@ void intel_gmbus_teardown(struct intel_display *display)
 	unsigned int pin;
 
 	for (pin = 0; pin < ARRAY_SIZE(display->gmbus.bus); pin++) {
-		struct intel_gmbus *bus;
-
-		bus = display->gmbus.bus[pin];
-		if (!bus)
-			continue;
-
-		i2c_del_adapter(&bus->adapter);
-
-		kfree(bus);
+		intel_gmbus_destroy(display->gmbus.bus[pin]);
 		display->gmbus.bus[pin] = NULL;
 	}
 }
-- 
2.49.1


  parent reply	other threads:[~2026-11-26 10:08 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-26 10:07 [PATCH 00/13] drm/i915/ddi_mgr: Add support for dynamic DDI allocation Imre Deak
2026-11-26 10:07 ` [PATCH 01/13] drm/i915/dp: Allow rebuilding the source rate list Imre Deak
2026-11-26 10:07 ` [PATCH 02/13] drm/i915/hotplug: Set detector enable bits without a clear mask Imre Deak
2026-11-26 10:07 ` [PATCH 03/13] drm/i915/nvl+: Add support for remapping logical HPD pins to HW pins Imre Deak
2026-11-26 10:07 ` [PATCH 04/13] drm/xe/display: Distinguish failed system suspend recovery Imre Deak
2026-11-26 13:22   ` Jani Nikula
2026-11-26 10:07 ` [PATCH 05/13] drm/i915/gmbus: Extract a helper for Type-C DDC pin mapping Imre Deak
2026-11-26 10:07 ` [PATCH 06/13] drm/i915/ddi_mgr: Add support for dynamic DDI allocation Imre Deak
2026-11-26 13:23   ` Jani Nikula
2026-11-26 16:51     ` Imre Deak
2026-11-26 10:07 ` Imre Deak [this message]
2026-11-26 10:07 ` [PATCH 08/13] drm/i915/gmbus: Add stable DDC adapters for the DDI pool Imre Deak
2026-11-26 10:07 ` [PATCH 09/13] drm/i915/ddi_mgr: Register encoders with dynamic DDI support Imre Deak
2026-11-26 10:26   ` sashiko-bot
2026-11-26 10:07 ` [PATCH 10/13] drm/i915/ddi_mgr: Keep AUX access consistent with DDI pool routes Imre Deak
2026-11-26 10:07 ` [PATCH 11/13] drm/i915/ddi_mgr: Verify and restore DDI allocations after runtime resume Imre Deak
2026-11-26 13:25   ` Jani Nikula
2026-11-26 10:07 ` [PATCH 12/13] drm/i915/ddi_mgr: Handle DDI pool system suspend and resume Imre Deak
2026-11-26 10:41   ` sashiko-bot
2026-11-26 13:25   ` Jani Nikula
2026-11-26 10:07 ` [PATCH 13/13] drm/i915/ddi_mgr: Enable dynamic DDI allocation at load Imre Deak
2026-11-26 11:15 ` ✗ i915.CI.BAT: failure for drm/i915/ddi_mgr: Add support for dynamic DDI allocation Patchwork
2026-11-26 14:08 ` ✗ CI.checkpatch: warning " Patchwork
2026-11-26 14:10 ` ✓ CI.KUnit: success " Patchwork
2026-11-26 14:49 ` ✓ Xe.CI.BAT: " Patchwork
2026-11-26 21:32 ` ✓ Xe.CI.FULL: " Patchwork

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=20261126100755.1252635-8-imre.deak@intel.com \
    --to=imre.deak@intel.com \
    --cc=intel-gfx@lists.freedesktop.org \
    --cc=intel-xe@lists.freedesktop.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: link
Be 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.