-
Notifications
You must be signed in to change notification settings - Fork 6.6k
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
drivers: gpio: axp192: GPIO driver implementation #59768
Conversation
a8e6ab9
to
17a04d0
Compare
1660e05
to
3c10038
Compare
43be5b7
to
9200109
Compare
Hey guys, this is a kind reminder to support me on this PR. |
drivers/gpio/gpio_axp192.c
Outdated
if (pin >= AXP192_GPIO_NUM_PINS) { | ||
LOG_ERR("Invalid gpio pin (%d)", pin); | ||
return -EINVAL; | ||
} |
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.
I think you should be using ngpios
property
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.
The number is physically restricted and this information is also needed on mfd layer. I can use the ngpios
property in gpio driver but would it really be the better solution to have 2 definitions then?
uint8_t port_val; | ||
const struct gpio_axp192_config *config = dev->config; | ||
|
||
ret = mfd_axp192_gpio_read_port(config->mfd, &port_val); |
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 can block, right? If so you need something like https://github.com/zephyrproject-rtos/zephyr/blob/main/drivers/gpio/gpio_npm6001.c#L53 (per API interface specs)
lgtm, just some minor comments. Believe it or not, GPIO area does not have a maintainer right now... |
@@ -50,12 +153,495 @@ static int mfd_axp192_init(const struct device *dev) | |||
return 0; | |||
} | |||
|
|||
int mfd_axp192_gpio_func_get(const struct device *dev, uint8_t gpio, enum axp192_gpio_func *func) |
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.
question: why is this part of the mfd layer? who else is using this?
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.
It is used by regulator and gpio drivers as some pins of the pmu are multiplexed. And it also was a recommendation in my regulator PR (#58809 (comment)) .
drivers/mfd/mfd_axp192.c
Outdated
if (k_is_in_isr()) { | ||
return -EWOULDBLOCK; | ||
} |
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 is translating GPIO API requirements to the mfd layer... wrong
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.
I See. Thank you.
Fixed it.
aa5c50d
to
252c73e
Compare
drivers/gpio/gpio_axp192.c
Outdated
return gpio_axp192_port_set_masked_raw(dev, pins, 0); | ||
} | ||
|
||
static inline int gpio_axp192_configure(const struct device *dev, gpio_pin_t 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.
static inline int gpio_axp192_configure(const struct device *dev, gpio_pin_t pin, | |
static int gpio_axp192_configure(const struct device *dev, gpio_pin_t pin, |
@@ -4,4 +4,5 @@ CONFIG_TEST_USERSPACE=y | |||
CONFIG_I2C=y | |||
CONFIG_GPIO_PCA95XX_INTERRUPT=y | |||
CONFIG_SPI=y | |||
CONFIG_MFD=y |
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.
redundant, driver must select MFD
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.
changes to regulator driver should go into its own commit maybe?
#define AXP192_GPIO0_INPUT_VAL 0x10U | ||
#define AXP192_GPIO1_INPUT_VAL 0x20U | ||
#define AXP192_GPIO2_INPUT_VAL 0x40U | ||
#define AXP192_GPIO012_INTPUT_SHIFT 4U |
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.
nit: Should this be INPUT?
drivers/mfd/mfd_axp192.c
Outdated
if ((port_val & (1u << pin)) != 0) { | ||
*value = true; | ||
} else { | ||
*value = false; | ||
} |
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.
if ((port_val & (1u << pin)) != 0) { | |
*value = true; | |
} else { | |
*value = false; | |
} | |
*value = (port_val & BIT(pin)) != 0; |
drivers/mfd/mfd_axp192.c
Outdated
DEVICE_DT_INST_DEFINE(inst, mfd_axp192_init, NULL, NULL, &config##inst, POST_KERNEL, \ | ||
CONFIG_MFD_INIT_PRIORITY, NULL); | ||
static struct mfd_axp192_data data##inst = { \ | ||
.gpio_mask_used = {0}, \ |
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 don't need to initialise static data
42823dc
to
b9424a1
Compare
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 is looking really good
drivers/gpio/gpio_axp192.c
Outdated
ret = mfd_axp192_gpio_write_pin(config->mfd, pin, false); | ||
} else if ((flags & GPIO_OUTPUT_INIT_HIGH) != 0) { | ||
ret = mfd_axp192_gpio_write_pin(config->mfd, pin, true); |
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 this the only place you are using mfd_axp192_gpio_write_pin?
If so you could replace it with a call to mfd_axp192_gpio_write_port(config->mfd, BIT(pin),...)
and remove mfd_axp192_gpio_write_pin entirely.
drivers/mfd/mfd_axp192.c
Outdated
return 0; | ||
} | ||
|
||
int mfd_axp192_gpio_read_pin(const struct device *dev, uint8_t pin, bool *value) |
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 this function needed?
AXP192 is a small power management IC, that also features 5 GPIOS. Besides GPIO driver this commit also includes needed modifications in axp192 regulator and mfd driver as LDOIO0 functioanlity is multiplexed with GPIO0 pin. Signed-off-by: Martin Kiepfer <[email protected]>
@gmarull @henrikbrixandersen do you have additional comments or would you like to approve the PR as well? |
AXP192 is a small power management IC, that also features 5 GPIOS.
Besides GPIO driver this commit also includes needed modifications in axp192 regulator and mfd driver as LDOIO0 functioanlity is multiplexed with GPIO0 pin.
Signed-off-by: Martin Kiepfer [email protected]