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) */
}
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",
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, ®ulator->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);
}
#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
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;
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;
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;
};