drivers: led_strip: ws2812_gpio: Adapt to clock using onoff
Adapted to use onoff service for clock control Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
This commit is contained in:
parent
4883a36be2
commit
e82419074c
|
@ -24,7 +24,6 @@ LOG_MODULE_REGISTER(ws2812_gpio);
|
|||
|
||||
struct ws2812_gpio_data {
|
||||
struct device *gpio;
|
||||
struct device *clk;
|
||||
};
|
||||
|
||||
struct ws2812_gpio_cfg {
|
||||
|
@ -103,15 +102,22 @@ static int send_buf(struct device *dev, uint8_t *buf, size_t len)
|
|||
{
|
||||
volatile uint32_t *base = (uint32_t *)&NRF_GPIO->OUTSET;
|
||||
const uint32_t val = BIT(dev_cfg(dev)->pin);
|
||||
struct device *clk = dev_data(dev)->clk;
|
||||
struct onoff_manager *mgr =
|
||||
z_nrf_clock_control_get_onoff(CLOCK_CONTROL_NRF_SUBSYS_HF);
|
||||
struct onoff_client cli;
|
||||
unsigned int key;
|
||||
int rc;
|
||||
|
||||
rc = clock_control_on(clk, CLOCK_CONTROL_NRF_SUBSYS_HF);
|
||||
if (rc) {
|
||||
sys_notify_init_spinwait(&cli.notify);
|
||||
rc = onoff_request(mgr, &cli);
|
||||
if (rc < 0) {
|
||||
return rc;
|
||||
}
|
||||
|
||||
while (sys_notify_fetch_result(&cli.notify, &rc)) {
|
||||
/* pend until clock is up and running */
|
||||
}
|
||||
|
||||
key = irq_lock();
|
||||
|
||||
while (len--) {
|
||||
|
@ -140,7 +146,9 @@ static int send_buf(struct device *dev, uint8_t *buf, size_t len)
|
|||
|
||||
irq_unlock(key);
|
||||
|
||||
rc = clock_control_off(clk, CLOCK_CONTROL_NRF_SUBSYS_HF);
|
||||
rc = onoff_release(mgr);
|
||||
/* Returns non-negative value on success. Cap to 0 as API states. */
|
||||
rc = MIN(rc, 0);
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
@ -213,13 +221,6 @@ static const struct led_strip_driver_api ws2812_gpio_api = {
|
|||
return -ENODEV; \
|
||||
} \
|
||||
\
|
||||
data->clk = device_get_binding(WS2812_GPIO_CLK(idx)); \
|
||||
if (!data->clk) { \
|
||||
LOG_ERR("Unable to find clock %s", \
|
||||
WS2812_GPIO_CLK(idx)); \
|
||||
return -ENODEV; \
|
||||
} \
|
||||
\
|
||||
return gpio_pin_configure(data->gpio, \
|
||||
WS2812_GPIO_PIN(idx), \
|
||||
WS2812_GPIO_FLAGS(idx) | \
|
||||
|
|
Loading…
Reference in a new issue