Lines Matching +full:lock +full:- +full:mode
4 * SPDX-License-Identifier: Apache-2.0
19 struct regulator_common_data *data = dev->data; in regulator_common_data_init()
22 (void)k_mutex_init(&data->lock); in regulator_common_data_init()
24 data->refcnt = 0; in regulator_common_data_init()
29 const struct regulator_driver_api *api = dev->api; in regulator_common_init()
30 const struct regulator_common_config *config = dev->config; in regulator_common_init()
31 struct regulator_common_data *data = dev->data; in regulator_common_init()
35 if (config->initial_mode != REGULATOR_INITIAL_MODE_UNKNOWN) { in regulator_common_init()
36 ret = regulator_set_mode(dev, config->initial_mode); in regulator_common_init()
42 if (REGULATOR_ACTIVE_DISCHARGE_GET_BITS(config->flags) != in regulator_common_init()
45 (bool)REGULATOR_ACTIVE_DISCHARGE_GET_BITS(config->flags)); in regulator_common_init()
51 if (config->init_uv > INT32_MIN) { in regulator_common_init()
52 ret = regulator_set_voltage(dev, config->init_uv, config->init_uv); in regulator_common_init()
58 if (config->init_ua > INT32_MIN) { in regulator_common_init()
59 ret = regulator_set_current_limit(dev, config->init_ua, config->init_ua); in regulator_common_init()
66 if ((config->min_uv > INT32_MIN) || (config->max_uv < INT32_MAX)) { in regulator_common_init()
74 if (current_uv < config->min_uv) { in regulator_common_init()
75 ret = regulator_set_voltage(dev, config->min_uv, config->min_uv); in regulator_common_init()
79 } else if (current_uv > config->max_uv) { in regulator_common_init()
80 ret = regulator_set_voltage(dev, config->max_uv, config->max_uv); in regulator_common_init()
88 data->refcnt++; in regulator_common_init()
89 if ((config->flags & REGULATOR_BOOT_OFF) != 0U) { in regulator_common_init()
92 } else if ((config->flags & REGULATOR_INIT_ENABLED) != 0U) { in regulator_common_init()
93 ret = api->enable(dev); in regulator_common_init()
98 regulator_delay(config->startup_delay_us); in regulator_common_init()
99 data->refcnt++; in regulator_common_init()
107 const struct regulator_driver_api *api = dev->api; in regulator_enable()
108 const struct regulator_common_config *config = dev->config; in regulator_enable()
109 struct regulator_common_data *data = dev->data; in regulator_enable()
113 if (api->enable == NULL) { in regulator_enable()
118 if ((config->flags & REGULATOR_ALWAYS_ON) != 0U) { in regulator_enable()
123 (void)k_mutex_lock(&data->lock, K_FOREVER); in regulator_enable()
126 data->refcnt++; in regulator_enable()
128 if (data->refcnt == 1) { in regulator_enable()
129 ret = api->enable(dev); in regulator_enable()
131 data->refcnt--; in regulator_enable()
133 regulator_delay(config->off_on_delay_us); in regulator_enable()
138 k_mutex_unlock(&data->lock); in regulator_enable()
146 const struct regulator_common_config *config = dev->config; in regulator_is_enabled()
147 struct regulator_common_data *data = dev->data; in regulator_is_enabled()
150 if ((config->flags & REGULATOR_ALWAYS_ON) != 0U) { in regulator_is_enabled()
154 (void)k_mutex_lock(&data->lock, K_FOREVER); in regulator_is_enabled()
156 enabled = data->refcnt != 0; in regulator_is_enabled()
158 k_mutex_unlock(&data->lock); in regulator_is_enabled()
167 const struct regulator_driver_api *api = dev->api; in regulator_disable()
168 const struct regulator_common_config *config = dev->config; in regulator_disable()
169 struct regulator_common_data *data = dev->data; in regulator_disable()
173 if (api->disable == NULL) { in regulator_disable()
178 if ((config->flags & REGULATOR_ALWAYS_ON) != 0U) { in regulator_disable()
183 (void)k_mutex_lock(&data->lock, K_FOREVER); in regulator_disable()
186 if (data->refcnt > 0) { in regulator_disable()
187 data->refcnt--; in regulator_disable()
189 if (data->refcnt == 0) { in regulator_disable()
190 ret = api->disable(dev); in regulator_disable()
192 data->refcnt++; in regulator_disable()
198 k_mutex_unlock(&data->lock); in regulator_disable()
207 const struct regulator_common_config *config = dev->config; in regulator_is_supported_voltage()
211 if ((min_uv > config->max_uv) || (max_uv < config->min_uv)) { in regulator_is_supported_voltage()
233 const struct regulator_common_config *config = dev->config; in regulator_set_voltage()
234 const struct regulator_driver_api *api = dev->api; in regulator_set_voltage()
236 if (api->set_voltage == NULL) { in regulator_set_voltage()
237 return -ENOSYS; in regulator_set_voltage()
241 if ((min_uv > config->max_uv) || (max_uv < config->min_uv)) { in regulator_set_voltage()
242 return -EINVAL; in regulator_set_voltage()
245 return api->set_voltage(dev, min_uv, max_uv); in regulator_set_voltage()
251 const struct regulator_common_config *config = dev->config; in regulator_set_current_limit()
252 const struct regulator_driver_api *api = dev->api; in regulator_set_current_limit()
254 if (api->set_current_limit == NULL) { in regulator_set_current_limit()
255 return -ENOSYS; in regulator_set_current_limit()
259 if ((min_ua > config->max_ua) || (max_ua < config->min_ua)) { in regulator_set_current_limit()
260 return -EINVAL; in regulator_set_current_limit()
263 return api->set_current_limit(dev, min_ua, max_ua); in regulator_set_current_limit()
266 int regulator_set_mode(const struct device *dev, regulator_mode_t mode) in regulator_set_mode() argument
268 const struct regulator_common_config *config = dev->config; in regulator_set_mode()
269 const struct regulator_driver_api *api = dev->api; in regulator_set_mode()
271 if (api->set_mode == NULL) { in regulator_set_mode()
272 return -ENOSYS; in regulator_set_mode()
275 /* no mode restrictions */ in regulator_set_mode()
276 if (config->allowed_modes_cnt == 0U) { in regulator_set_mode()
277 return api->set_mode(dev, mode); in regulator_set_mode()
280 /* check if mode is allowed, apply if it is */ in regulator_set_mode()
281 for (uint8_t i = 0U; i < config->allowed_modes_cnt; i++) { in regulator_set_mode()
282 if (mode == config->allowed_modes[i]) { in regulator_set_mode()
283 return api->set_mode(dev, mode); in regulator_set_mode()
287 return -ENOTSUP; in regulator_set_mode()