public inbox for linux-staging@lists.linux.dev
 help / color / mirror / Atom feed
From: Hans de Goede <hdegoede@redhat.com>
To: "Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>,
	"Andy Shevchenko" <andy@kernel.org>,
	"Sakari Ailus" <sakari.ailus@linux.intel.com>
Cc: Hans de Goede <hdegoede@redhat.com>,
	platform-driver-x86@vger.kernel.org,
	Mauro Carvalho Chehab <mchehab@kernel.org>,
	linux-media@vger.kernel.org, linux-staging@lists.linux.dev
Subject: [PATCH 2/6] platform/x86: int3472: Stop using devm_gpiod_get()
Date: Wed,  7 May 2025 20:47:33 +0200	[thread overview]
Message-ID: <20250507184737.154747-3-hdegoede@redhat.com> (raw)
In-Reply-To: <20250507184737.154747-1-hdegoede@redhat.com>

The intent is to re-use the INT3472 code for parsing Intel camera sensor
GPIOs and mapping them to the sensor for the atomisp driver, which
currently has duplicate code.

On atomisp devices there is no special INT3472 ACPI device, instead
the Intel _DSM to get the GPIO type is part of the ACPI device for
the sensor itself.

To deal with this the mapping is done from ipu_bridge_init() instead of
from a platform-device probe() function, there is no device to tie
the lifetime of the gpiod_get() calls done by the INT3472 code to.

Switch from devm_gpiod_get() to plain gpiod_get() + explicit gpiod_put()
calls, to prepare for the code being re-used in the atomisp driver.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
---
 drivers/platform/x86/intel/int3472/clk_and_regulator.c | 6 +++++-
 drivers/platform/x86/intel/int3472/discrete.c          | 6 +++++-
 drivers/platform/x86/intel/int3472/led.c               | 1 +
 include/linux/platform_data/x86/int3472.h              | 1 +
 4 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/drivers/platform/x86/intel/int3472/clk_and_regulator.c b/drivers/platform/x86/intel/int3472/clk_and_regulator.c
index 4d00494a7670..476ec24d3702 100644
--- a/drivers/platform/x86/intel/int3472/clk_and_regulator.c
+++ b/drivers/platform/x86/intel/int3472/clk_and_regulator.c
@@ -182,6 +182,7 @@ void skl_int3472_unregister_clock(struct int3472_discrete_device *int3472)
 
 	clkdev_drop(int3472->clock.cl);
 	clk_unregister(int3472->clock.clk);
+	gpiod_put(int3472->clock.ena_gpio);
 }
 
 int skl_int3472_register_regulator(struct int3472_discrete_device *int3472,
@@ -244,12 +245,15 @@ int skl_int3472_register_regulator(struct int3472_discrete_device *int3472,
 	if (IS_ERR(regulator->rdev))
 		return PTR_ERR(regulator->rdev);
 
+	int3472->regulators[int3472->n_regulator_gpios].ena_gpio = gpio;
 	int3472->n_regulator_gpios++;
 	return 0;
 }
 
 void skl_int3472_unregister_regulator(struct int3472_discrete_device *int3472)
 {
-	for (int i = 0; i < int3472->n_regulator_gpios; i++)
+	for (int i = 0; i < int3472->n_regulator_gpios; i++) {
 		regulator_unregister(int3472->regulators[i].rdev);
+		gpiod_put(int3472->regulators[i].ena_gpio);
+	}
 }
diff --git a/drivers/platform/x86/intel/int3472/discrete.c b/drivers/platform/x86/intel/int3472/discrete.c
index d0938da0a591..808d75e8deda 100644
--- a/drivers/platform/x86/intel/int3472/discrete.c
+++ b/drivers/platform/x86/intel/int3472/discrete.c
@@ -117,7 +117,7 @@ skl_int3472_gpiod_get_from_temp_lookup(struct int3472_discrete_device *int3472,
 		return ERR_PTR(ret);
 
 	gpiod_add_lookup_table(lookup);
-	desc = devm_gpiod_get(int3472->dev, con_id, GPIOD_OUT_LOW);
+	desc = gpiod_get(int3472->dev, con_id, GPIOD_OUT_LOW);
 	gpiod_remove_lookup_table(lookup);
 
 	return desc;
@@ -340,6 +340,10 @@ static int skl_int3472_handle_gpio_resources(struct acpi_resource *ares,
 			ret = -EINVAL;
 			break;
 		}
+
+		if (ret)
+			gpiod_put(gpio);
+
 		break;
 	default:
 		dev_warn(int3472->dev,
diff --git a/drivers/platform/x86/intel/int3472/led.c b/drivers/platform/x86/intel/int3472/led.c
index c5588e143f7d..f1d6d7b0cb75 100644
--- a/drivers/platform/x86/intel/int3472/led.c
+++ b/drivers/platform/x86/intel/int3472/led.c
@@ -56,4 +56,5 @@ void skl_int3472_unregister_pled(struct int3472_discrete_device *int3472)
 
 	led_remove_lookup(&int3472->pled.lookup);
 	led_classdev_unregister(&int3472->pled.classdev);
+	gpiod_put(int3472->pled.gpio);
 }
diff --git a/include/linux/platform_data/x86/int3472.h b/include/linux/platform_data/x86/int3472.h
index 4cf02df6f753..0a835cc85c67 100644
--- a/include/linux/platform_data/x86/int3472.h
+++ b/include/linux/platform_data/x86/int3472.h
@@ -99,6 +99,7 @@ struct int3472_gpio_regulator {
 	struct regulator_consumer_supply supply_map[GPIO_REGULATOR_SUPPLY_MAP_COUNT * 2];
 	char supply_name_upper[GPIO_SUPPLY_NAME_LENGTH];
 	char regulator_name[GPIO_REGULATOR_NAME_LENGTH];
+	struct gpio_desc *ena_gpio;
 	struct regulator_dev *rdev;
 	struct regulator_desc rdesc;
 };
-- 
2.49.0


  parent reply	other threads:[~2025-05-07 18:48 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-05-07 18:47 [PATCH 0/6] platform/x86: int3472: Allow re-using sensor GPIO mapping in atomisp Hans de Goede
2025-05-07 18:47 ` [PATCH 1/6] platform/x86: int3472: Move common.h to public includes, symbols to INTEL_INT3472 Hans de Goede
2025-05-07 18:47 ` Hans de Goede [this message]
2025-05-07 18:47 ` [PATCH 3/6] platform/x86: int3472: Export int3472_discrete_parse_crs() Hans de Goede
2025-05-07 18:47 ` [PATCH 4/6] platform/x86: int3472: Remove unused sensor_config struct member Hans de Goede
2025-05-07 18:47 ` [PATCH 5/6] platform/x86: int3472: For mt9m114 sensors map powerdown to powerenable Hans de Goede
2025-05-07 18:47 ` [PATCH 6/6] media: atomisp: Switch to int3472 driver sensor GPIO mapping code Hans de Goede
2025-05-08  8:34   ` Andy Shevchenko
2025-05-08 13:18     ` Hans de Goede
2025-05-08 13:48       ` Ilpo Järvinen
2025-05-08 13:56         ` Hans de Goede
2025-05-08 14:06           ` Hans de Goede
2025-05-08 14:09             ` Ilpo Järvinen
2025-07-04  9:37     ` Hans de Goede
2025-05-08  8:36 ` [PATCH 0/6] platform/x86: int3472: Allow re-using sensor GPIO mapping in atomisp Andy Shevchenko
2025-05-08  8:37   ` Andy Shevchenko
2025-05-08 13:15     ` Hans de Goede
2025-05-08 14:00   ` Hans de Goede
2025-05-08 14:51     ` Andy Shevchenko
2025-05-08 10:22 ` Sakari Ailus
2025-05-08 14:55 ` Andy Shevchenko
2025-05-08 15:38   ` Hans de Goede

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=20250507184737.154747-3-hdegoede@redhat.com \
    --to=hdegoede@redhat.com \
    --cc=andy@kernel.org \
    --cc=ilpo.jarvinen@linux.intel.com \
    --cc=linux-media@vger.kernel.org \
    --cc=linux-staging@lists.linux.dev \
    --cc=mchehab@kernel.org \
    --cc=platform-driver-x86@vger.kernel.org \
    --cc=sakari.ailus@linux.intel.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