Skip to content
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

Merged
merged 1 commit into from
Aug 22, 2023

Conversation

MrMarteng
Copy link
Collaborator

@MrMarteng MrMarteng commented Jun 26, 2023

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]

@MrMarteng
Copy link
Collaborator Author

Hey guys, this is a kind reminder to support me on this PR.

Comment on lines 76 to 88
if (pin >= AXP192_GPIO_NUM_PINS) {
LOG_ERR("Invalid gpio pin (%d)", pin);
return -EINVAL;
}
Copy link
Member

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

Copy link
Collaborator Author

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);
Copy link
Member

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)

@gmarull
Copy link
Member

gmarull commented Aug 9, 2023

Hey guys, this is a kind reminder to support me on this PR.

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)
Copy link
Member

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?

Copy link
Collaborator Author

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)) .

Comment on lines 167 to 169
if (k_is_in_isr()) {
return -EWOULDBLOCK;
}
Copy link
Member

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

Copy link
Collaborator Author

@MrMarteng MrMarteng Aug 10, 2023

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.

@MrMarteng MrMarteng force-pushed the axp192_gpio branch 2 times, most recently from aa5c50d to 252c73e Compare August 11, 2023 07:22
@MrMarteng MrMarteng requested a review from gmarull August 11, 2023 08:17
return gpio_axp192_port_set_masked_raw(dev, pins, 0);
}

static inline int gpio_axp192_configure(const struct device *dev, gpio_pin_t pin,
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
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
Copy link
Member

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

Copy link
Member

@gmarull gmarull left a 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
Copy link
Contributor

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?

Comment on lines 528 to 532
if ((port_val & (1u << pin)) != 0) {
*value = true;
} else {
*value = false;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if ((port_val & (1u << pin)) != 0) {
*value = true;
} else {
*value = false;
}
*value = (port_val & BIT(pin)) != 0;

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}, \
Copy link
Contributor

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

@MrMarteng MrMarteng force-pushed the axp192_gpio branch 2 times, most recently from 42823dc to b9424a1 Compare August 16, 2023 14:45
Copy link
Contributor

@aasinclair aasinclair left a 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

Comment on lines 110 to 112
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);
Copy link
Contributor

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.

return 0;
}

int mfd_axp192_gpio_read_pin(const struct device *dev, uint8_t pin, bool *value)
Copy link
Contributor

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]>
@MrMarteng
Copy link
Collaborator Author

MrMarteng commented Aug 22, 2023

@gmarull @henrikbrixandersen do you have additional comments or would you like to approve the PR as well?

@carlescufi carlescufi merged commit 74db02b into zephyrproject-rtos:main Aug 22, 2023
17 checks passed
@MrMarteng MrMarteng deleted the axp192_gpio branch September 14, 2023 17:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: Devicetree Binding PR modifies or adds a Device Tree binding area: GPIO area: Regulators
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants