Lines Matching +full:data +full:- +full:ready +full:- +full:gpios

3  * SPDX-License-Identifier: Apache-2.0
19 const struct gpio_dt_spec *gpios; member
35 const struct regulator_gpio_config *cfg = dev->config; in regulator_gpio_apply_state()
37 for (unsigned int gpio_idx = 0; gpio_idx < cfg->num_gpios; gpio_idx++) { in regulator_gpio_apply_state()
41 ret = gpio_pin_get_dt(&cfg->gpios[gpio_idx]); in regulator_gpio_apply_state()
43 LOG_ERR("%s: can't get pin state", dev->name); in regulator_gpio_apply_state()
48 ret = gpio_pin_set_dt(&cfg->gpios[gpio_idx], new_state_of_gpio); in regulator_gpio_apply_state()
50 LOG_ERR("%s: can't set pin state", dev->name); in regulator_gpio_apply_state()
61 const struct regulator_gpio_config *cfg = dev->config; in regulator_gpio_enable()
64 if (cfg->enable.port == NULL) { in regulator_gpio_enable()
68 ret = gpio_pin_set_dt(&cfg->enable, 1); in regulator_gpio_enable()
70 LOG_ERR("%s: can't enable regulator!", dev->name); in regulator_gpio_enable()
79 const struct regulator_gpio_config *cfg = dev->config; in regulator_gpio_disable()
81 if (cfg->enable.port == NULL) { in regulator_gpio_disable()
85 return gpio_pin_set_dt(&cfg->enable, 0); in regulator_gpio_disable()
90 const struct regulator_gpio_config *cfg = dev->config; in regulator_gpio_count_voltages()
92 return cfg->states_cnt; in regulator_gpio_count_voltages()
97 const struct regulator_gpio_config *cfg = dev->config; in regulator_gpio_list_voltage()
99 if (idx >= cfg->states_cnt) { in regulator_gpio_list_voltage()
100 LOG_ERR("%s: can't get list voltage for idx %u", dev->name, idx); in regulator_gpio_list_voltage()
101 return -EINVAL; in regulator_gpio_list_voltage()
104 *volt_uv = cfg->states[idx * 2]; in regulator_gpio_list_voltage()
110 const struct regulator_gpio_config *cfg = dev->config; in regulator_gpio_set_voltage()
111 struct regulator_gpio_data *data = dev->data; in regulator_gpio_set_voltage() local
117 for (unsigned int state_idx = 0; state_idx < cfg->states_cnt; state_idx++) { in regulator_gpio_set_voltage()
118 if (!IN_RANGE(cfg->states[state_idx * 2], min_uv, max_uv) || in regulator_gpio_set_voltage()
119 cfg->states[state_idx * 2] >= best_voltage) { in regulator_gpio_set_voltage()
123 best_voltage = cfg->states[state_idx * 2]; in regulator_gpio_set_voltage()
124 best_state = cfg->states[state_idx * 2 + 1]; in regulator_gpio_set_voltage()
128 LOG_ERR("%s: can't find voltage is states", dev->name); in regulator_gpio_set_voltage()
129 return -EINVAL; in regulator_gpio_set_voltage()
132 if (best_voltage == data->current_volt_uv) { in regulator_gpio_set_voltage()
141 data->current_volt_uv = best_voltage; in regulator_gpio_set_voltage()
147 const struct regulator_gpio_data *data = dev->data; in regulator_gpio_get_voltage() local
149 *volt_uv = data->current_volt_uv; in regulator_gpio_get_voltage()
164 const struct regulator_gpio_config *cfg = dev->config; in regulator_gpio_init()
169 for (unsigned int gpio_idx = 0; gpio_idx < cfg->num_gpios; gpio_idx++) { in regulator_gpio_init()
170 if (!gpio_is_ready_dt(&cfg->gpios[gpio_idx])) { in regulator_gpio_init()
171 LOG_ERR("%s: gpio pin: %s not ready", dev->name, in regulator_gpio_init()
172 cfg->gpios[gpio_idx].port ? cfg->gpios[gpio_idx].port->name in regulator_gpio_init()
174 return -ENODEV; in regulator_gpio_init()
177 ret = gpio_pin_configure_dt(&cfg->gpios[gpio_idx], GPIO_OUTPUT); in regulator_gpio_init()
179 LOG_ERR("%s: can't configure pin (%d) as output", dev->name, in regulator_gpio_init()
180 cfg->gpios[gpio_idx].pin); in regulator_gpio_init()
185 if (cfg->enable.port != NULL) { in regulator_gpio_init()
186 if (!gpio_is_ready_dt(&cfg->enable)) { in regulator_gpio_init()
187 LOG_ERR("%s: gpio pin: %s not ready", dev->name, cfg->enable.port->name); in regulator_gpio_init()
188 return -ENODEV; in regulator_gpio_init()
191 ret = gpio_pin_configure_dt(&cfg->enable, GPIO_OUTPUT | GPIO_OUTPUT_INIT_LOW); in regulator_gpio_init()
193 LOG_ERR("%s: can't configure enable pin (%d) as output", dev->name, in regulator_gpio_init()
194 cfg->enable.pin); in regulator_gpio_init()
206 DT_FOREACH_PROP_ELEM(DT_DRV_INST(inst), gpios, REG_GPIO_CONTEXT_GPIOS_SPEC_ELEM)
209 .gpios = (const struct gpio_dt_spec[]){REG_GPIO_CONTEXT_GPIOS_FOREACH_ELEM(inst)}, \
210 .num_gpios = DT_INST_PROP_LEN(inst, gpios)
213 static struct regulator_gpio_data data##inst = { \
225 DEVICE_DT_INST_DEFINE(inst, regulator_gpio_init, NULL, &data##inst, &config##inst, \