Message ID | 20250416124037.90508-1-hdegoede@redhat.com |
---|---|
Headers | show |
Series | platform/x86: int3472: Add handshake pin support | expand |
On Wed, Apr 16, 2025 at 02:40:33PM +0200, Hans de Goede wrote: > This is a preparation patch for registering multiple regulators, which > requires a different supply-name for each regulator. Make supply-name > a parameter to skl_int3472_register_regulator() and use con-id to set it > so that the existing int3472_gpio_map remapping can be used with it. > > Since supply-name is a parameter now, drop the fixed > skl_int3472_regulator_map_supplies[] array and instead add lower- and > upper-case mappings of the passed-in supply-name to the regulator. ... > + for (i = 0, j = 0; i < GPIO_REGULATOR_SUPPLY_MAP_COUNT; i++) { > + const char *supply = i ? regulator->supply_name_upper : supply_name; But this won't scale, it seems it relies on the fact that GPIO_REGULATOR_SUPPLY_MAP_COUNT <= 2. > + regulator->supply_map[j].supply = supply; > + regulator->supply_map[j].dev_name = int3472->sensor_name; > j++; > > if (second_sensor) { > - int3472->regulator.supply_map[j].supply = > - skl_int3472_regulator_map_supplies[i]; > - int3472->regulator.supply_map[j].dev_name = second_sensor; > + regulator->supply_map[j].supply = supply; > + regulator->supply_map[j].dev_name = second_sensor; > j++; > } With that in mind, why not unroll the loop? > } ... > +/* lower- and upper-case mapping */ > #define GPIO_REGULATOR_SUPPLY_MAP_COUNT 2 Code seems really relies on this not be bigger than 2, perhaps static assert?
Hi Andy, On 16-Apr-25 8:13 PM, Andy Shevchenko wrote: > On Wed, Apr 16, 2025 at 02:40:33PM +0200, Hans de Goede wrote: >> This is a preparation patch for registering multiple regulators, which >> requires a different supply-name for each regulator. Make supply-name >> a parameter to skl_int3472_register_regulator() and use con-id to set it >> so that the existing int3472_gpio_map remapping can be used with it. >> >> Since supply-name is a parameter now, drop the fixed >> skl_int3472_regulator_map_supplies[] array and instead add lower- and >> upper-case mappings of the passed-in supply-name to the regulator. > > ... > >> + for (i = 0, j = 0; i < GPIO_REGULATOR_SUPPLY_MAP_COUNT; i++) { >> + const char *supply = i ? regulator->supply_name_upper : supply_name; > > But this won't scale, it seems it relies on the fact that > GPIO_REGULATOR_SUPPLY_MAP_COUNT <= 2. Ack, I've added a static_assert(GPIO_REGULATOR_SUPPLY_MAP_COUNT == 2) just above the for () {} for this for v4, as you suggest below. > >> + regulator->supply_map[j].supply = supply; >> + regulator->supply_map[j].dev_name = int3472->sensor_name; >> j++; >> >> if (second_sensor) { >> - int3472->regulator.supply_map[j].supply = >> - skl_int3472_regulator_map_supplies[i]; >> - int3472->regulator.supply_map[j].dev_name = second_sensor; >> + regulator->supply_map[j].supply = supply; >> + regulator->supply_map[j].dev_name = second_sensor; >> j++; >> } > > With that in mind, why not unroll the loop? That will lead to code duplication wrt the second_sensor handler and it will make the diff from the previous code bigger, so I've gone with a static_assert() instead, as suggested below. > >> } > > ... > >> +/* lower- and upper-case mapping */ >> #define GPIO_REGULATOR_SUPPLY_MAP_COUNT 2 > > Code seems really relies on this not be bigger than 2, perhaps static assert? Ack, I've added a static assert for this for v4. Regards, Hans