]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
platform/x86: int3472: Prepare for registering more than 1 GPIO regulator
authorHans de Goede <hdegoede@redhat.com>
Thu, 17 Apr 2025 11:13:35 +0000 (13:13 +0200)
committerIlpo Järvinen <ilpo.jarvinen@linux.intel.com>
Thu, 24 Apr 2025 13:05:39 +0000 (16:05 +0300)
Prepare the discrete code for registering more than 1 GPIO regulator.

Reviewed-by: Andy Shevchenko <andy@kernel.org>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Tested-by: David Heidelberg <david@ixit.cz> # Dell Latitude 9440
Reviewed-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Link: https://lore.kernel.org/r/20250417111337.38142-8-hdegoede@redhat.com
Reviewed-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
drivers/platform/x86/intel/int3472/clk_and_regulator.c
drivers/platform/x86/intel/int3472/common.h

index 0a46d48896ed190948793866e43e34f566786e7e..c85cbfbc16c18c7d112f8355193a8a8680bcadcd 100644 (file)
@@ -196,12 +196,17 @@ int skl_int3472_register_regulator(struct int3472_discrete_device *int3472,
        struct regulator_config cfg = { };
        int i, j;
 
+       if (int3472->n_regulator_gpios >= INT3472_MAX_REGULATORS) {
+               dev_err(int3472->dev, "Too many regulators mapped\n");
+               return -EINVAL;
+       }
+
        if (strlen(supply_name) >= GPIO_SUPPLY_NAME_LENGTH) {
                dev_err(int3472->dev, "supply-name '%s' length too long\n", supply_name);
                return -E2BIG;
        }
 
-       regulator = &int3472->regulator;
+       regulator = &int3472->regulators[int3472->n_regulator_gpios];
        string_upper(regulator->supply_name_upper, supply_name);
 
        /* The below code assume that map-count is 2 (upper- and lower-case) */
@@ -222,7 +227,7 @@ int skl_int3472_register_regulator(struct int3472_discrete_device *int3472,
        }
 
        init_data.constraints.valid_ops_mask = REGULATOR_CHANGE_STATUS;
-       init_data.consumer_supplies = int3472->regulator.supply_map;
+       init_data.consumer_supplies = regulator->supply_map;
        init_data.num_consumer_supplies = j;
 
        snprintf(regulator->regulator_name, sizeof(regulator->regulator_name), "%s-%s",
@@ -236,14 +241,16 @@ int skl_int3472_register_regulator(struct int3472_discrete_device *int3472,
        cfg.init_data = &init_data;
        cfg.ena_gpiod = gpio;
 
-       int3472->regulator.rdev = regulator_register(int3472->dev,
-                                                    &int3472->regulator.rdesc,
-                                                    &cfg);
+       regulator->rdev = regulator_register(int3472->dev, &regulator->rdesc, &cfg);
+       if (IS_ERR(regulator->rdev))
+               return PTR_ERR(regulator->rdev);
 
-       return PTR_ERR_OR_ZERO(int3472->regulator.rdev);
+       int3472->n_regulator_gpios++;
+       return 0;
 }
 
 void skl_int3472_unregister_regulator(struct int3472_discrete_device *int3472)
 {
-       regulator_unregister(int3472->regulator.rdev);
+       for (int i = 0; i < int3472->n_regulator_gpios; i++)
+               regulator_unregister(int3472->regulators[i].rdev);
 }
index 2af8dc1ed25e7a4db7da9714a8dadbed4d6f3b4a..3d8b5c5ff236600c3ec65b349015c78232856c15 100644 (file)
@@ -25,6 +25,7 @@
 
 #define INT3472_PDEV_MAX_NAME_LEN                              23
 #define INT3472_MAX_SENSOR_GPIOS                               3
+#define INT3472_MAX_REGULATORS                                 3
 
 /* E.g. "avdd\0" */
 #define GPIO_SUPPLY_NAME_LENGTH                                5
@@ -88,6 +89,15 @@ struct int3472_discrete_quirks {
        const char *avdd_second_sensor;
 };
 
+struct int3472_gpio_regulator {
+       /* SUPPLY_MAP_COUNT * 2 to make room for second sensor mappings */
+       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 regulator_dev *rdev;
+       struct regulator_desc rdesc;
+};
+
 struct int3472_discrete_device {
        struct acpi_device *adev;
        struct device *dev;
@@ -96,14 +106,7 @@ struct int3472_discrete_device {
 
        const struct int3472_sensor_config *sensor_config;
 
-       struct int3472_gpio_regulator {
-               /* SUPPLY_MAP_COUNT * 2 to make room for second sensor mappings */
-               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 regulator_dev *rdev;
-               struct regulator_desc rdesc;
-       } regulator;
+       struct int3472_gpio_regulator regulators[INT3472_MAX_REGULATORS];
 
        struct int3472_clock {
                struct clk *clk;
@@ -125,6 +128,7 @@ struct int3472_discrete_device {
 
        unsigned int ngpios; /* how many GPIOs have we seen */
        unsigned int n_sensor_gpios; /* how many have we mapped to sensor */
+       unsigned int n_regulator_gpios; /* how many have we mapped to a regulator */
        struct gpiod_lookup_table gpios;
 };