Skip to content

Conversation

smalae
Copy link
Contributor

@smalae smalae commented Sep 24, 2025

  1. Add the port_count field to the configuration structure and allocate different sizes for the ports array based
    on whether the node is HP or ULP.
  2. Add Device runtime PM for GPIO driver

@jhedberg jhedberg changed the title Device runtime support for gpio driver drivers: gpio: silabs-siwx91x: Add device runtime support Sep 24, 2025
@jhedberg
Copy link
Member

@smalae for the future, please use titles that give enough context for the entire Zephyr project, as issues & PRs are visible to everyone. I fixed it now for this PR.

@smalae smalae force-pushed the device-runtime-support-for-gpio-driver branch from 862d501 to ea23cd1 Compare September 25, 2025 06:58

#address-cells = <1>;
#size-cells = <0>;
silabs,port-count = <4>;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code should use DT_CHILD_NUM() instead of this being a property in dts

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

#address-cells = <1>;
#size-cells = <0>;
silabs,port-count = <4>;
silabs,max-pin-usage-count = <8>;
Copy link
Contributor

@asmellby asmellby Sep 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code should use the pin mask constructed from ngpios and gpio-reserved-ranges, which is already available as the .common.port_pin_mask member of the config struct on each port. No need for another dts property. If you need a compile time constant, it should be possible to do some macrobatics to create a number that is ngpios - popcnt(reserved_ranges).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated accordingly

pdata->pin_config_info[pdata->cur_pin].port_dev = dev;
pdata->pin_config_info[pdata->cur_pin].pin = pin;
pdata->pin_config_info[pdata->cur_pin].flags = flags;
pdata->cur_pin++;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A pin can be configured multiple times, this needs to reuse an existing allocation if the same pin is reconfigured.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@smalae smalae force-pushed the device-runtime-support-for-gpio-driver branch from ea23cd1 to e2e9218 Compare October 3, 2025 17:29
@smalae smalae force-pushed the device-runtime-support-for-gpio-driver branch from e2e9218 to c892a57 Compare October 3, 2025 17:34
@smalae smalae requested review from asmellby and jhedberg October 3, 2025 17:35
Add soc power domain and zephyr,pm-device-runtime-auto

Signed-off-by: Sai Santhosh Malae <[email protected]>
Comment on lines 178 to 183
while (port_data->pin_config_info[i].port_dev != NULL &&
pin_cnt < __builtin_popcount(port_cfg->common.port_pin_mask)) {
ret = gpio_siwx91x_pin_configure(
port_data->pin_config_info[pin_cnt].port_dev,
port_data->pin_config_info[pin_cnt].pin,
port_data->pin_config_info[pin_cnt].flags);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it really correct that you're using a different index for port_data->pin_config_info in the while loop condition and inside the loop? Looks a bit suspicious.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right — that was missed. I've corrected it now.

Comment on lines 164 to 165
const struct gpio_siwx91x_common_config *pcfg = dev->config;
struct gpio_siwx91x_common_data *pdata = dev->data;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does the p prefix for these variable names stand for "port", or are you using Hungarian notation? In both cases I think you should just drop it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added the 'port' prefix to port-specific config and data, and used generic cfg and data labels for common configurations.

@smalae smalae force-pushed the device-runtime-support-for-gpio-driver branch 2 times, most recently from 3e9475b to c6c07bf Compare October 7, 2025 06:29
@smalae smalae requested a review from jhedberg October 7, 2025 06:49
Copy link

sonarqubecloud bot commented Oct 7, 2025

smalae added 4 commits October 7, 2025 17:29
Add the port_count field to the configuration structure
and allocate different sizes for the ports array based
on whether the node is HP or ULP.

Signed-off-by: Sai Santhosh Malae <[email protected]>
This commit enables the pm device runtime support
for the siwx91x gpio driver.

Signed-off-by: Sai Santhosh Malae <[email protected]>
Apply clang format corrections

Signed-off-by: Sai Santhosh Malae <[email protected]>
Drop usage of `pcfg` and `pdata` in favor of unified `cfg`
for common configuration and `port_cfg`, `port_data` for
port-specific configurations.

Signed-off-by: Sai Santhosh Malae <[email protected]>
uint16_t pin_direction[MAX_PIN_COUNT];
#endif
struct gpio_siwx91x_pin_config_info *pin_config_info;
uint8_t next_pin;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

next_pin feels not the good name for this variable. If I understand right, it saves the number of configured pin in the port ? would rather use "pin_ctn" or "pin_count" to have link with port variable.

port_data->next_pin++;
}

if (cur_cfg_pin < __builtin_popcount(port_cfg->common.port_pin_mask)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This value is already known and constant, it is ARRAY_SIZE(port_data->pin_config_info)

port_data->pin_config_info[cur_cfg_pin].pin = pin;
port_data->pin_config_info[cur_cfg_pin].flags = flags;
} else {
return -EIO;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-EINVAL feels to be a better return value.
-EIO is for: "I/O error when accessing an external GPIO chip."

Comment on lines +179 to +189
while (port_data->pin_config_info[pin_cnt].port_dev != NULL &&
pin_cnt < __builtin_popcount(port_cfg->common.port_pin_mask)) {
ret = gpio_siwx91x_pin_configure(
port_data->pin_config_info[pin_cnt].port_dev,
port_data->pin_config_info[pin_cnt].pin,
port_data->pin_config_info[pin_cnt].flags);
if (ret) {
return ret;
}
pin_cnt++;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can't you use the fact that you knows how much pin has been configured with your next_pin variable in port data ?

Suggested change
while (port_data->pin_config_info[pin_cnt].port_dev != NULL &&
pin_cnt < __builtin_popcount(port_cfg->common.port_pin_mask)) {
ret = gpio_siwx91x_pin_configure(
port_data->pin_config_info[pin_cnt].port_dev,
port_data->pin_config_info[pin_cnt].pin,
port_data->pin_config_info[pin_cnt].flags);
if (ret) {
return ret;
}
pin_cnt++;
}
for(int i = 0; i < port_data->next_pin; i++) {
ret = gpio_siwx91x_pin_configure(
port_data->pin_config_info[i].port_dev,
port_data->pin_config_info[i].pin,
port_data->pin_config_info[i].flags);
if (ret) {
return ret;
}
}

or something like this ? renaming to "pin_ctn" make more sense too here.

port_data->pin_config_info[pin_cnt].pin,
port_data->pin_config_info[pin_cnt].flags);
if (ret) {
return ret;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe a stupid question question but how could it failed since you already managed to configure this pin this way ? and even if it failed, what our power domain driver will do about that info ? (more open question)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants