Skip to content

Commit d4381dc

Browse files
committed
platform/x86: int3472: discrete: Remove sensor_config-s
Currently the only 2 sensor_config-s both specify "avdd" as supply-id. The INT3472 device is going to be the only supplier of a regulator for the sensor device. So there is no chance of collisions with other regulator suppliers and it is undesirable to need to manually add new entries to int3472_sensor_configs[] for each new sensor module which uses a GPIO regulator. Instead just always use "avdd" as supply-id when registering the GPIO regulator. If necessary for specific sensor drivers then other supply-ids can be added as aliases in the future, adding aliases will be safe since INT3472 will be the only regulator supplier for the sensor. Cc: Bingbu Cao <[email protected]> Tested-by: Hao Yao <[email protected]> Signed-off-by: Hans de Goede <[email protected]> Reviewed-by: Daniel Scally <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent b52798a commit d4381dc

File tree

3 files changed

+31
-61
lines changed

3 files changed

+31
-61
lines changed

drivers/platform/x86/intel/int3472/clk_and_regulator.c

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -232,32 +232,40 @@ void skl_int3472_unregister_clock(struct int3472_discrete_device *int3472)
232232
gpiod_put(int3472->clock.ena_gpio);
233233
}
234234

235+
/*
236+
* The INT3472 device is going to be the only supplier of a regulator for
237+
* the sensor device. But unlike the clk framework the regulator framework
238+
* does not allow matching by consumer-device-name only.
239+
*
240+
* Ideally all sensor drivers would use "avdd" as supply-id. But for drivers
241+
* where this cannot be changed because another supply-id is already used in
242+
* e.g. DeviceTree files an alias for the other supply-id can be added here.
243+
*
244+
* Do not forget to update GPIO_REGULATOR_SUPPLY_MAP_COUNT when changing this.
245+
*/
246+
static const char * const skl_int3472_regulator_map_supplies[] = {
247+
"avdd",
248+
};
249+
250+
static_assert(ARRAY_SIZE(skl_int3472_regulator_map_supplies) ==
251+
GPIO_REGULATOR_SUPPLY_MAP_COUNT);
252+
235253
int skl_int3472_register_regulator(struct int3472_discrete_device *int3472,
236254
struct acpi_resource_gpio *agpio)
237255
{
238-
const struct int3472_sensor_config *sensor_config;
239256
char *path = agpio->resource_source.string_ptr;
240-
struct regulator_consumer_supply supply_map;
241257
struct regulator_init_data init_data = { };
242258
struct regulator_config cfg = { };
243-
int ret;
244-
245-
sensor_config = int3472->sensor_config;
246-
if (IS_ERR(sensor_config)) {
247-
dev_err(int3472->dev, "No sensor module config\n");
248-
return PTR_ERR(sensor_config);
249-
}
259+
int i, ret;
250260

251-
if (!sensor_config->supply_map.supply) {
252-
dev_err(int3472->dev, "No supply name defined\n");
253-
return -ENODEV;
261+
for (i = 0; i < ARRAY_SIZE(skl_int3472_regulator_map_supplies); i++) {
262+
int3472->regulator.supply_map[i].supply = skl_int3472_regulator_map_supplies[i];
263+
int3472->regulator.supply_map[i].dev_name = int3472->sensor_name;
254264
}
255265

256266
init_data.constraints.valid_ops_mask = REGULATOR_CHANGE_STATUS;
257-
init_data.num_consumer_supplies = 1;
258-
supply_map = sensor_config->supply_map;
259-
supply_map.dev_name = int3472->sensor_name;
260-
init_data.consumer_supplies = &supply_map;
267+
init_data.consumer_supplies = int3472->regulator.supply_map;
268+
init_data.num_consumer_supplies = GPIO_REGULATOR_SUPPLY_MAP_COUNT;
261269

262270
snprintf(int3472->regulator.regulator_name,
263271
sizeof(int3472->regulator.regulator_name), "%s-regulator",

drivers/platform/x86/intel/int3472/common.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828

2929
#define GPIO_REGULATOR_NAME_LENGTH 21
3030
#define GPIO_REGULATOR_SUPPLY_NAME_LENGTH 9
31+
#define GPIO_REGULATOR_SUPPLY_MAP_COUNT 1
3132

3233
#define INT3472_LED_MAX_NAME_LEN 32
3334

@@ -69,11 +70,6 @@ struct int3472_cldb {
6970
u8 reserved2[17];
7071
};
7172

72-
struct int3472_sensor_config {
73-
const char *sensor_module_name;
74-
struct regulator_consumer_supply supply_map;
75-
};
76-
7773
struct int3472_discrete_device {
7874
struct acpi_device *adev;
7975
struct device *dev;
@@ -83,6 +79,7 @@ struct int3472_discrete_device {
8379
const struct int3472_sensor_config *sensor_config;
8480

8581
struct int3472_gpio_regulator {
82+
struct regulator_consumer_supply supply_map[GPIO_REGULATOR_SUPPLY_MAP_COUNT];
8683
char regulator_name[GPIO_REGULATOR_NAME_LENGTH];
8784
char supply_name[GPIO_REGULATOR_SUPPLY_NAME_LENGTH];
8885
struct gpio_desc *gpio;

drivers/platform/x86/intel/int3472/discrete.c

Lines changed: 5 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -34,48 +34,17 @@ static const guid_t cio2_sensor_module_guid =
3434
GUID_INIT(0x822ace8f, 0x2814, 0x4174,
3535
0xa5, 0x6b, 0x5f, 0x02, 0x9f, 0xe0, 0x79, 0xee);
3636

37-
/*
38-
* Here follows platform specific mapping information that we can pass to
39-
* the functions mapping resources to the sensors. Where the sensors have
40-
* a power enable pin defined in DSDT we need to provide a supply name so
41-
* the sensor drivers can find the regulator. The device name will be derived
42-
* from the sensor's ACPI device within the code.
43-
*/
44-
static const struct int3472_sensor_config int3472_sensor_configs[] = {
45-
/* Lenovo Miix 510-12ISK - OV5648, Rear */
46-
{ "GEFF150023R", REGULATOR_SUPPLY("avdd", NULL) },
47-
/* Surface Go 1&2 - OV5693, Front */
48-
{ "YHCU", REGULATOR_SUPPLY("avdd", NULL) },
49-
};
50-
51-
static const struct int3472_sensor_config *
52-
skl_int3472_get_sensor_module_config(struct int3472_discrete_device *int3472)
37+
static void skl_int3472_log_sensor_module_name(struct int3472_discrete_device *int3472)
5338
{
5439
union acpi_object *obj;
55-
unsigned int i;
5640

5741
obj = acpi_evaluate_dsm_typed(int3472->sensor->handle,
5842
&cio2_sensor_module_guid, 0x00,
5943
0x01, NULL, ACPI_TYPE_STRING);
60-
61-
if (!obj) {
62-
dev_err(int3472->dev,
63-
"Failed to get sensor module string from _DSM\n");
64-
return ERR_PTR(-ENODEV);
65-
}
66-
67-
for (i = 0; i < ARRAY_SIZE(int3472_sensor_configs); i++) {
68-
if (!strcmp(int3472_sensor_configs[i].sensor_module_name,
69-
obj->string.pointer))
70-
break;
44+
if (obj) {
45+
dev_dbg(int3472->dev, "Sensor module id: '%s'\n", obj->string.pointer);
46+
ACPI_FREE(obj);
7147
}
72-
73-
ACPI_FREE(obj);
74-
75-
if (i >= ARRAY_SIZE(int3472_sensor_configs))
76-
return ERR_PTR(-EINVAL);
77-
78-
return &int3472_sensor_configs[i];
7948
}
8049

8150
static int skl_int3472_map_gpio_to_sensor(struct int3472_discrete_device *int3472,
@@ -266,11 +235,7 @@ static int skl_int3472_parse_crs(struct int3472_discrete_device *int3472)
266235
LIST_HEAD(resource_list);
267236
int ret;
268237

269-
/*
270-
* No error check, because not having a sensor config is not necessarily
271-
* a failure mode.
272-
*/
273-
int3472->sensor_config = skl_int3472_get_sensor_module_config(int3472);
238+
skl_int3472_log_sensor_module_name(int3472);
274239

275240
ret = acpi_dev_get_resources(int3472->adev, &resource_list,
276241
skl_int3472_handle_gpio_resources,

0 commit comments

Comments
 (0)