-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Npm2100 driver #79587
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
Merged
Merged
Npm2100 driver #79587
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
fd531a0
drivers: mfd: npm2100: Add npm2100 mfd driver
nordic-auko cdbfa7c
drivers: gpio: npm2100: Add driver for npm2100 pmic
nordic-auko 11d1c4d
drivers: regulator: npm2100: Add driver for npm2100 pmic
nordic-auko 7e86e73
drivers: sensor: npm2100: Add driver for npm2100 pmic
nordic-auko 7e0cb3e
drivers: watchdog: npm2100: Add driver for npm2100 pmic
nordic-auko File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| # Copyright (c) 2024 Nordic Semiconductor ASA | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| config GPIO_NPM2100 | ||
| bool "nPM2100 GPIO driver" | ||
| default y | ||
| depends on DT_HAS_NORDIC_NPM2100_GPIO_ENABLED | ||
| select I2C | ||
| select MFD | ||
| help | ||
| Enable the nPM2100 GPIO driver. | ||
|
|
||
| config GPIO_NPM2100_INIT_PRIORITY | ||
| int "nPM2100 GPIO driver initialization priority" | ||
| depends on GPIO_NPM2100 | ||
| default 80 | ||
| help | ||
| Initialization priority for the nPM2100 GPIO driver. It must be | ||
| greater than the I2C controller init priority. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,182 @@ | ||
| /* | ||
| * Copyright (c) 2024 Nordic Semiconductor ASA | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| #define DT_DRV_COMPAT nordic_npm2100_gpio | ||
|
|
||
| #include <errno.h> | ||
|
|
||
| #include <zephyr/drivers/gpio.h> | ||
| #include <zephyr/drivers/gpio/gpio_utils.h> | ||
| #include <zephyr/drivers/i2c.h> | ||
| #include <zephyr/dt-bindings/gpio/nordic-npm2100-gpio.h> | ||
| #include <zephyr/kernel.h> | ||
| #include <zephyr/sys/util_macro.h> | ||
|
|
||
| #define NPM2100_GPIO_CONFIG 0x80U | ||
| #define NPM2100_GPIO_USAGE 0x83U | ||
| #define NPM2100_GPIO_OUTPUT 0x86U | ||
| #define NPM2100_GPIO_READ 0x89U | ||
|
|
||
| #define NPM2100_GPIO_PINS 2U | ||
|
|
||
| #define NPM2100_GPIO_CONFIG_INPUT 0x01U | ||
| #define NPM2100_GPIO_CONFIG_OUTPUT 0x02U | ||
| #define NPM2100_GPIO_CONFIG_OPENDRAIN 0x04U | ||
| #define NPM2100_GPIO_CONFIG_PULLDOWN 0x08U | ||
| #define NPM2100_GPIO_CONFIG_PULLUP 0x10U | ||
| #define NPM2100_GPIO_CONFIG_DRIVE 0x20U | ||
| #define NPM2100_GPIO_CONFIG_DEBOUNCE 0x40U | ||
|
|
||
| struct gpio_npm2100_config { | ||
| struct gpio_driver_config common; | ||
| struct i2c_dt_spec i2c; | ||
| }; | ||
|
|
||
| struct gpio_npm2100_data { | ||
| struct gpio_driver_data common; | ||
| }; | ||
|
|
||
| static int gpio_npm2100_port_get_raw(const struct device *dev, uint32_t *value) | ||
| { | ||
| const struct gpio_npm2100_config *config = dev->config; | ||
| uint8_t data; | ||
| int ret; | ||
|
|
||
| ret = i2c_reg_read_byte_dt(&config->i2c, NPM2100_GPIO_READ, &data); | ||
| if (ret < 0) { | ||
| return ret; | ||
| } | ||
|
|
||
| *value = data; | ||
|
|
||
| return 0; | ||
| } | ||
|
|
||
| static int gpio_npm2100_port_set_masked_raw(const struct device *dev, gpio_port_pins_t mask, | ||
| gpio_port_value_t value) | ||
| { | ||
| const struct gpio_npm2100_config *config = dev->config; | ||
| int ret = 0; | ||
|
|
||
| for (size_t idx = 0; idx < NPM2100_GPIO_PINS; idx++) { | ||
| if ((mask & BIT(idx)) != 0U) { | ||
| i2c_reg_write_byte_dt(&config->i2c, NPM2100_GPIO_OUTPUT + idx, | ||
| !!(value & BIT(idx))); | ||
| if (ret != 0U) { | ||
| return ret; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| return ret; | ||
| } | ||
|
|
||
| static int gpio_npm2100_port_set_bits_raw(const struct device *dev, gpio_port_pins_t pins) | ||
| { | ||
| return gpio_npm2100_port_set_masked_raw(dev, pins, pins); | ||
| } | ||
|
|
||
| static int gpio_npm2100_port_clear_bits_raw(const struct device *dev, gpio_port_pins_t pins) | ||
| { | ||
| return gpio_npm2100_port_set_masked_raw(dev, pins, 0U); | ||
| } | ||
|
|
||
| static inline int gpio_npm2100_configure(const struct device *dev, gpio_pin_t pin, | ||
| gpio_flags_t flags) | ||
| { | ||
| const struct gpio_npm2100_config *config = dev->config; | ||
| uint8_t reg = 0U; | ||
|
|
||
| if (k_is_in_isr()) { | ||
| return -EWOULDBLOCK; | ||
| } | ||
|
|
||
| if (pin >= NPM2100_GPIO_PINS) { | ||
| return -EINVAL; | ||
| } | ||
|
|
||
| /* Set initial state if defined */ | ||
| if ((flags & (GPIO_OUTPUT_INIT_LOW | GPIO_OUTPUT_INIT_HIGH)) != 0U) { | ||
| int ret = i2c_reg_write_byte_dt(&config->i2c, NPM2100_GPIO_OUTPUT + pin, | ||
| !!(flags & GPIO_OUTPUT_INIT_HIGH)); | ||
| if (ret < 0) { | ||
| return ret; | ||
| } | ||
| } | ||
|
|
||
| /* Set pin configuration */ | ||
| if ((flags & GPIO_INPUT) != 0U) { | ||
| reg |= NPM2100_GPIO_CONFIG_INPUT; | ||
| } | ||
| if ((flags & GPIO_OUTPUT) != 0U) { | ||
| reg |= NPM2100_GPIO_CONFIG_OUTPUT; | ||
| } | ||
| if ((flags & GPIO_SINGLE_ENDED) != 0U) { | ||
| reg |= NPM2100_GPIO_CONFIG_OPENDRAIN; | ||
| } | ||
| if ((flags & GPIO_PULL_UP) != 0U) { | ||
| reg |= NPM2100_GPIO_CONFIG_PULLUP; | ||
| } | ||
| if ((flags & GPIO_PULL_DOWN) != 0U) { | ||
| reg |= NPM2100_GPIO_CONFIG_PULLDOWN; | ||
| } | ||
| if ((flags & NPM2100_GPIO_DRIVE_HIGH) != 0U) { | ||
| reg |= NPM2100_GPIO_CONFIG_DRIVE; | ||
| } | ||
| if ((flags & NPM2100_GPIO_DEBOUNCE_ON) != 0U) { | ||
| reg |= NPM2100_GPIO_CONFIG_DEBOUNCE; | ||
| } | ||
|
|
||
| return i2c_reg_write_byte_dt(&config->i2c, NPM2100_GPIO_CONFIG + pin, reg); | ||
| } | ||
|
|
||
| static int gpio_npm2100_port_toggle_bits(const struct device *dev, gpio_port_pins_t pins) | ||
| { | ||
| int ret; | ||
| uint32_t value; | ||
|
|
||
| ret = gpio_npm2100_port_get_raw(dev, &value); | ||
| if (ret < 0) { | ||
| return ret; | ||
| } | ||
|
|
||
| return gpio_npm2100_port_set_masked_raw(dev, pins, ~value); | ||
| } | ||
|
|
||
| static DEVICE_API(gpio, gpio_npm2100_api) = { | ||
| .pin_configure = gpio_npm2100_configure, | ||
| .port_get_raw = gpio_npm2100_port_get_raw, | ||
| .port_set_masked_raw = gpio_npm2100_port_set_masked_raw, | ||
| .port_set_bits_raw = gpio_npm2100_port_set_bits_raw, | ||
| .port_clear_bits_raw = gpio_npm2100_port_clear_bits_raw, | ||
| .port_toggle_bits = gpio_npm2100_port_toggle_bits, | ||
| }; | ||
|
|
||
| static int gpio_npm2100_init(const struct device *dev) | ||
| { | ||
| const struct gpio_npm2100_config *config = dev->config; | ||
|
|
||
| if (!i2c_is_ready_dt(&config->i2c)) { | ||
| return -ENODEV; | ||
| } | ||
|
|
||
| return 0; | ||
| } | ||
|
|
||
| #define GPIO_NPM2100_DEFINE(n) \ | ||
| static const struct gpio_npm2100_config gpio_npm2100_config##n = { \ | ||
| .common = \ | ||
| { \ | ||
| .port_pin_mask = GPIO_PORT_PIN_MASK_FROM_DT_INST(n), \ | ||
| }, \ | ||
| .i2c = I2C_DT_SPEC_GET(DT_INST_PARENT(n))}; \ | ||
| \ | ||
| static struct gpio_npm2100_data gpio_npm2100_data##n; \ | ||
| \ | ||
| DEVICE_DT_INST_DEFINE(n, &gpio_npm2100_init, NULL, &gpio_npm2100_data##n, \ | ||
| &gpio_npm2100_config##n, POST_KERNEL, \ | ||
| CONFIG_GPIO_NPM2100_INIT_PRIORITY, &gpio_npm2100_api); | ||
|
|
||
| DT_INST_FOREACH_STATUS_OKAY(GPIO_NPM2100_DEFINE) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| # Copyright (c) 2024 Nordic Semiconductor ASA | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| config MFD_NPM2100 | ||
| bool "nPM2100 PMIC multi-function device driver" | ||
| default y | ||
| depends on DT_HAS_NORDIC_NPM2100_ENABLED | ||
| select I2C | ||
| help | ||
| Enable the Nordic nPM2100 PMIC multi-function device driver |
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.