Add required changes for zmk power domain support #8
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hey guys, these are the necessary changes to add power domain support in ZMK.
Please review it in conjunction with the zmk PR: zmkfirmware/zmk#1300
Background Info
To be completely honest... I don't full understand many of the decisions behind zephyr's original code.
For example...
PM_DEVICE_ACTION_TURN_ONsets the device state toPM_DEVICE_STATE_SUSPENDEDI am not sure why, I would have expected it to set it to
PM_DEVICE_STATE_ACTIVE.Because of this, in the zmk code, I use
PM_DEVICE_ACTION_RESUMEin zmk's code to enable power domains.You can find it here:
https://github.com/infused-kim/zmk-zephyr/blob/v3.0.0%2Bzmk-fixes%2Bpd-oled/subsys/pm/device.c#L140-L146
pd_gpio_pm_actionforwards different actions to childrenAnother thing that seems off is that
pd_gpio_pm_actionforwards different actions to it's children.For example:
PM_DEVICE_ACTION_RESUMErunsPM_DEVICE_ACTION_TURN_ONon the childrenPM_DEVICE_ACTION_SUSPENDrunsPM_DEVICE_ACTION_TURN_OFFon the childrenPM_DEVICE_ACTION_TURN_ONruns nothing on the childrenPM_DEVICE_ACTION_TURN_OFFruns nothing on the childrenI have modified it to always run the matching action to the children.
https://github.com/zmkfirmware/zephyr/blob/v3.0.0%2Bzmk-fixes/drivers/power_domain/power_domain_gpio.c#L48
pd_gpio_pm_actiononly toggled GPIO pin forRESUMEandSUSPENDactionsFor example:
PM_DEVICE_ACTION_RESUMEset the pin to 1PM_DEVICE_ACTION_SUSPENDset the pin 0PM_DEVICE_ACTION_TURN_ONdid NOT set the pin to 1, but instead configured it toGPIO_OUTPUT_INACTIVEPM_DEVICE_ACTION_TURN_OFFdid NOT set the pin to 0, but instead configured it toGPIO_DISCONNECTEDTo be completely honest, I have no idea what it means for the pin to be configured to
GPIO_OUTPUT_INACTIVEandGPIO_DISCONNECTED.So I just changed the actions to turn and off the pins instead of configuring them.
https://github.com/zmkfirmware/zephyr/blob/v3.0.0%2Bzmk-fixes/drivers/power_domain/power_domain_gpio.c#L59
pd_gpio_initcould fail ifgpio_pin_configure_dtfailedThis is another issue I ran into when adding a power domain as a child to another power domain.
For reference:
https://github.com/zmkfirmware/zephyr/blob/v3.0.0%2Bzmk-fixes/drivers/power_domain/power_domain_gpio.c#L84-L88
If a power domain is a child of another power domain, then the code attempts to configure the pin as
GPIO_DISCONNECTED.If that fails, the init function returns a non 0 return code.
That in turn causes the device to be marked as not initialized.
When attempting to get the device through
device_get_binding(), it fails and prevents zmk code to not work properly.So I changed this by ignoring the return code of
gpio_pin_configure_dtand to always return 0.In conclusion...
I have made it work, but I don't fully understand the original intentions of the zephyr developers.
Maybe these were bugs and I fixed them or maybe I just don't understand how power domains are supposed to work and made wrong assumptions.
I would really appreciate it if you could guide me to the right solution if what I did is not correct.
Thank you.