Branch data Line data Source code
1 : : /* 2 : : * Copyright (c) 2021 Nordic Semiconductor ASA 3 : : * 4 : : * SPDX-License-Identifier: Apache-2.0 5 : : */ 6 : : 7 : : #include <drivers/pinctrl.h> 8 : : 9 : 1 : int pinctrl_lookup_state(const struct pinctrl_dev_config *config, uint8_t id, 10 : : const struct pinctrl_state **state) 11 : : { 12 : 1 : *state = &config->states[0]; 13 [ + - ]: 1 : while (*state <= &config->states[config->state_cnt - 1U]) { 14 [ + - ]: 1 : if (id == (*state)->id) { 15 : 1 : return 0; 16 : : } 17 : : 18 : 0 : (*state)++; 19 : : } 20 : : 21 : 0 : return -ENOENT; 22 : : } 23 : : 24 : : #ifdef CONFIG_PINCTRL_DYNAMIC 25 : : int pinctrl_update_states(struct pinctrl_dev_config *config, 26 : : const struct pinctrl_state *states, 27 : : uint8_t state_cnt) 28 : : { 29 : : uint8_t equal = 0U; 30 : : 31 : : /* check we are inserting same number of states */ 32 : : if (config->state_cnt != state_cnt) { 33 : : return -EINVAL; 34 : : } 35 : : 36 : : /* check we have the same states */ 37 : : for (uint8_t i = 0U; i < state_cnt; i++) { 38 : : for (uint8_t j = 0U; j < config->state_cnt; j++) { 39 : : if (states[i].id == config->states[j].id) { 40 : : equal++; 41 : : break; 42 : : } 43 : : } 44 : : } 45 : : 46 : : if (equal != state_cnt) { 47 : : return -EINVAL; 48 : : } 49 : : 50 : : /* replace current states */ 51 : : config->states = states; 52 : : 53 : : return 0; 54 : : } 55 : : #endif /* CONFIG_PINCTRL_DYNAMIC */