drivers: led: npm1300: nPM1300 LED driver
Added LED driver for nPM1300 PMIC Signed-off-by: Andy Sinclair <andy.sinclair@nordicsemi.no>
This commit is contained in:
parent
bb5f421ade
commit
7bc99e246c
|
@ -7,6 +7,7 @@ zephyr_library()
|
|||
zephyr_library_sources_ifdef(CONFIG_HT16K33 ht16k33.c)
|
||||
zephyr_library_sources_ifdef(CONFIG_IS31FL3216A is31fl3216a.c)
|
||||
zephyr_library_sources_ifdef(CONFIG_LED_GPIO led_gpio.c)
|
||||
zephyr_library_sources_ifdef(CONFIG_LED_NPM1300 led_npm1300.c)
|
||||
zephyr_library_sources_ifdef(CONFIG_LED_PWM led_pwm.c)
|
||||
zephyr_library_sources_ifdef(CONFIG_LED_XEC led_mchp_xec.c)
|
||||
zephyr_library_sources_ifdef(CONFIG_LP3943 lp3943.c)
|
||||
|
|
|
@ -33,6 +33,7 @@ source "drivers/led/Kconfig.lp3943"
|
|||
source "drivers/led/Kconfig.lp503x"
|
||||
source "drivers/led/Kconfig.lp5562"
|
||||
source "drivers/led/Kconfig.lp5569"
|
||||
source "drivers/led/Kconfig.npm1300"
|
||||
source "drivers/led/Kconfig.pca9633"
|
||||
source "drivers/led/Kconfig.pwm"
|
||||
source "drivers/led/Kconfig.tlc59108"
|
||||
|
|
11
drivers/led/Kconfig.npm1300
Normal file
11
drivers/led/Kconfig.npm1300
Normal file
|
@ -0,0 +1,11 @@
|
|||
# Copyright (c) 2023 Nordic Semiconductor ASA
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
config LED_NPM1300
|
||||
bool "nPM1300 LED driver"
|
||||
default y
|
||||
depends on DT_HAS_NORDIC_NPM1300_LED_ENABLED
|
||||
select I2C
|
||||
select MFD
|
||||
help
|
||||
Enable the nPM1300 LED driver.
|
100
drivers/led/led_npm1300.c
Normal file
100
drivers/led/led_npm1300.c
Normal file
|
@ -0,0 +1,100 @@
|
|||
/*
|
||||
* Copyright (c) 2023 Nordic Semiconductor ASA
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#define DT_DRV_COMPAT nordic_npm1300_led
|
||||
|
||||
#include <errno.h>
|
||||
|
||||
#include <zephyr/device.h>
|
||||
#include <zephyr/drivers/led.h>
|
||||
#include <zephyr/drivers/mfd/npm1300.h>
|
||||
|
||||
/* nPM1300 LED base address */
|
||||
#define NPM_LED_BASE 0x0AU
|
||||
|
||||
/* nPM1300 LED register offsets */
|
||||
#define NPM_LED_OFFSET_MODE 0x00U
|
||||
#define NPM_LED_OFFSET_SET 0x03U
|
||||
#define NPM_LED_OFFSET_CLR 0x04U
|
||||
|
||||
/* nPM1300 Channel counts */
|
||||
#define NPM1300_LED_PINS 3U
|
||||
|
||||
/* nPM1300 LED modes */
|
||||
#define NPM_LED_HOST 2U
|
||||
|
||||
struct led_npm1300_config {
|
||||
const struct device *mfd;
|
||||
uint8_t mode[NPM1300_LED_PINS];
|
||||
};
|
||||
|
||||
static int led_npm1300_on(const struct device *dev, uint32_t led)
|
||||
{
|
||||
const struct led_npm1300_config *config = dev->config;
|
||||
|
||||
if (led >= NPM1300_LED_PINS) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (config->mode[led] != NPM_LED_HOST) {
|
||||
return -EPERM;
|
||||
}
|
||||
|
||||
return mfd_npm1300_reg_write(config->mfd, NPM_LED_BASE, NPM_LED_OFFSET_SET + (led * 2U),
|
||||
1U);
|
||||
}
|
||||
|
||||
static int led_npm1300_off(const struct device *dev, uint32_t led)
|
||||
{
|
||||
const struct led_npm1300_config *config = dev->config;
|
||||
|
||||
if (led >= NPM1300_LED_PINS) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (config->mode[led] != NPM_LED_HOST) {
|
||||
return -EPERM;
|
||||
}
|
||||
|
||||
return mfd_npm1300_reg_write(config->mfd, NPM_LED_BASE, NPM_LED_OFFSET_CLR + (led * 2U),
|
||||
1U);
|
||||
}
|
||||
|
||||
static const struct led_driver_api led_npm1300_api = {
|
||||
.on = led_npm1300_on,
|
||||
.off = led_npm1300_off,
|
||||
};
|
||||
|
||||
static int led_npm1300_init(const struct device *dev)
|
||||
{
|
||||
const struct led_npm1300_config *config = dev->config;
|
||||
|
||||
if (!device_is_ready(config->mfd)) {
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
for (uint8_t led = 0U; led < NPM1300_LED_PINS; led++) {
|
||||
int ret = mfd_npm1300_reg_write(config->mfd, NPM_LED_BASE,
|
||||
NPM_LED_OFFSET_MODE + led, config->mode[led]);
|
||||
|
||||
if (ret < 0) {
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#define LED_NPM1300_DEFINE(n) \
|
||||
static const struct led_npm1300_config led_npm1300_config##n = { \
|
||||
.mfd = DEVICE_DT_GET(DT_INST_PARENT(n)), \
|
||||
.mode = {DT_INST_ENUM_IDX(n, nordic_led0_mode), \
|
||||
DT_INST_ENUM_IDX(n, nordic_led1_mode), \
|
||||
DT_INST_ENUM_IDX(n, nordic_led2_mode)}}; \
|
||||
\
|
||||
DEVICE_DT_INST_DEFINE(n, &led_npm1300_init, NULL, NULL, &led_npm1300_config##n, \
|
||||
POST_KERNEL, CONFIG_LED_INIT_PRIORITY, &led_npm1300_api);
|
||||
|
||||
DT_INST_FOREACH_STATUS_OKAY(LED_NPM1300_DEFINE)
|
39
dts/bindings/led/nordic,npm1300-led.yaml
Normal file
39
dts/bindings/led/nordic,npm1300-led.yaml
Normal file
|
@ -0,0 +1,39 @@
|
|||
# Copyright (c) 2023 Nordic Semiconductor ASA
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
description: |
|
||||
Nordic nPM1300 LED controller
|
||||
|
||||
The nPM1300 has three LED outputs.
|
||||
Each LED can automatically display error or charging status,
|
||||
or be controlled by software.
|
||||
|
||||
compatible: "nordic,npm1300-led"
|
||||
|
||||
properties:
|
||||
nordic,led0-mode:
|
||||
type: string
|
||||
required: true
|
||||
enum:
|
||||
- error
|
||||
- charging
|
||||
- host
|
||||
description: LED 0 mode
|
||||
|
||||
nordic,led1-mode:
|
||||
type: string
|
||||
required: true
|
||||
enum:
|
||||
- error
|
||||
- charging
|
||||
- host
|
||||
description: LED 1 mode
|
||||
|
||||
nordic,led2-mode:
|
||||
type: string
|
||||
required: true
|
||||
enum:
|
||||
- error
|
||||
- charging
|
||||
- host
|
||||
description: LED 2 mode
|
Loading…
Reference in a new issue