-
Notifications
You must be signed in to change notification settings - Fork 8k
drivers: gpio: silabs-siwx91x: Add device runtime support #96491
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
drivers: gpio: silabs-siwx91x: Add device runtime support #96491
Conversation
@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. |
862d501
to
ea23cd1
Compare
dts/arm/silabs/siwg917.dtsi
Outdated
|
||
#address-cells = <1>; | ||
#size-cells = <0>; | ||
silabs,port-count = <4>; |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
dts/arm/silabs/siwg917.dtsi
Outdated
#address-cells = <1>; | ||
#size-cells = <0>; | ||
silabs,port-count = <4>; | ||
silabs,max-pin-usage-count = <8>; |
There was a problem hiding this comment.
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)
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated accordingly
drivers/gpio/gpio_silabs_siwx91x.c
Outdated
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++; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
ea23cd1
to
e2e9218
Compare
e2e9218
to
c892a57
Compare
Add soc power domain and zephyr,pm-device-runtime-auto Signed-off-by: Sai Santhosh Malae <[email protected]>
drivers/gpio/gpio_silabs_siwx91x.c
Outdated
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); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
drivers/gpio/gpio_silabs_siwx91x.c
Outdated
const struct gpio_siwx91x_common_config *pcfg = dev->config; | ||
struct gpio_siwx91x_common_data *pdata = dev->data; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
3e9475b
to
c6c07bf
Compare
|
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; |
There was a problem hiding this comment.
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)) { |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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."
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++; | ||
} |
There was a problem hiding this comment.
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 ?
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; |
There was a problem hiding this comment.
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)
on whether the node is HP or ULP.