|
| 1 | +/* |
| 2 | + * Copyright (c) 2024 Nordic Semiconductor ASA |
| 3 | + * |
| 4 | + * SPDX-License-Identifier: Apache-2.0 |
| 5 | + */ |
| 6 | + |
| 7 | +#include <soc_lrcconf.h> |
| 8 | +#include <zephyr/kernel.h> |
| 9 | + |
| 10 | +static struct k_spinlock lock; |
| 11 | +static sys_slist_t poweron_main_list; |
| 12 | +static sys_slist_t poweron_active_list; |
| 13 | + |
| 14 | +void soc_lrcconf_poweron_request(sys_snode_t *node, nrf_lrcconf_power_domain_mask_t domain) |
| 15 | +{ |
| 16 | + __ASSERT(is_power_of_two(domain), "Only one bit can be set for the domain parameter"); |
| 17 | + |
| 18 | + sys_slist_t *poweron_list; |
| 19 | + |
| 20 | + if (domain == NRF_LRCCONF_POWER_MAIN) { |
| 21 | + poweron_list = &poweron_main_list; |
| 22 | + } else if (domain == NRF_LRCCONF_POWER_DOMAIN_0) { |
| 23 | + poweron_list = &poweron_active_list; |
| 24 | + } else { |
| 25 | + return; |
| 26 | + } |
| 27 | + K_SPINLOCK(&lock) { |
| 28 | + if (sys_slist_len(poweron_list) == 0) { |
| 29 | + nrf_lrcconf_poweron_force_set(NRF_LRCCONF010, domain, true); |
| 30 | + } |
| 31 | + |
| 32 | + sys_slist_find_and_remove(poweron_list, node); |
| 33 | + sys_slist_append(poweron_list, node); |
| 34 | + } |
| 35 | +} |
| 36 | + |
| 37 | +void soc_lrcconf_poweron_release(sys_snode_t *node, nrf_lrcconf_power_domain_mask_t domain) |
| 38 | +{ |
| 39 | + __ASSERT(is_power_of_two(domain), "Only one bit can be set for the domain parameter"); |
| 40 | + |
| 41 | + sys_slist_t *poweron_list; |
| 42 | + |
| 43 | + if (domain == NRF_LRCCONF_POWER_MAIN) { |
| 44 | + poweron_list = &poweron_main_list; |
| 45 | + } else if (domain == NRF_LRCCONF_POWER_DOMAIN_0) { |
| 46 | + poweron_list = &poweron_active_list; |
| 47 | + } else { |
| 48 | + return; |
| 49 | + } |
| 50 | + |
| 51 | + K_SPINLOCK(&lock) { |
| 52 | + if (!sys_slist_find_and_remove(poweron_list, node)) { |
| 53 | + K_SPINLOCK_BREAK; |
| 54 | + } |
| 55 | + |
| 56 | + if (sys_slist_len(poweron_list) > 0) { |
| 57 | + K_SPINLOCK_BREAK; |
| 58 | + } |
| 59 | + nrf_lrcconf_poweron_force_set(NRF_LRCCONF010, domain, false); |
| 60 | + } |
| 61 | +} |
0 commit comments