Lines Matching +full:valid +full:- +full:channels

4  * SPDX-License-Identifier: Apache-2.0
13 #include <zephyr/dt-bindings/adc/smartbond-adc.h>
39 /* Number of bits in sequence channels */
57 uint8_t channel_id = channel_cfg->channel_id; in sdadc_smartbond_channel_setup()
61 return -EINVAL; in sdadc_smartbond_channel_setup()
64 if (channel_cfg->acquisition_time != ADC_ACQ_TIME_DEFAULT) { in sdadc_smartbond_channel_setup()
65 LOG_ERR("Selected ADC acquisition time is not valid"); in sdadc_smartbond_channel_setup()
66 return -EINVAL; in sdadc_smartbond_channel_setup()
69 if (channel_cfg->input_positive > SMARTBOND_SDADC_VBAT) { in sdadc_smartbond_channel_setup()
70 LOG_ERR("Channels out of range"); in sdadc_smartbond_channel_setup()
71 return -EINVAL; in sdadc_smartbond_channel_setup()
73 if (channel_cfg->differential) { in sdadc_smartbond_channel_setup()
74 if (channel_cfg->input_negative >= SMARTBOND_SDADC_VBAT) { in sdadc_smartbond_channel_setup()
75 LOG_ERR("Differential negative channels out of range"); in sdadc_smartbond_channel_setup()
76 return -EINVAL; in sdadc_smartbond_channel_setup()
80 config->sd_adc_ctrl_reg = 0; in sdadc_smartbond_channel_setup()
81 if ((channel_cfg->input_positive == SMARTBOND_SDADC_VBAT && in sdadc_smartbond_channel_setup()
82 channel_cfg->gain != ADC_GAIN_1_4) || in sdadc_smartbond_channel_setup()
83 (channel_cfg->input_positive != SMARTBOND_SDADC_VBAT && in sdadc_smartbond_channel_setup()
84 channel_cfg->gain != ADC_GAIN_1)) { in sdadc_smartbond_channel_setup()
85 LOG_ERR("ADC gain should be 1/4 for VBAT and 1 for all other channels"); in sdadc_smartbond_channel_setup()
86 return -EINVAL; in sdadc_smartbond_channel_setup()
89 switch (channel_cfg->reference) { in sdadc_smartbond_channel_setup()
93 LOG_ERR("Selected ADC reference is not valid"); in sdadc_smartbond_channel_setup()
94 return -EINVAL; in sdadc_smartbond_channel_setup()
97 config->sd_adc_ctrl_reg = in sdadc_smartbond_channel_setup()
98 channel_cfg->input_positive << SDADC_SDADC_CTRL_REG_SDADC_INP_SEL_Pos; in sdadc_smartbond_channel_setup()
99 if (channel_cfg->differential) { in sdadc_smartbond_channel_setup()
100 config->sd_adc_ctrl_reg |= in sdadc_smartbond_channel_setup()
101 channel_cfg->input_negative << SDADC_SDADC_CTRL_REG_SDADC_INN_SEL_Pos; in sdadc_smartbond_channel_setup()
103 config->sd_adc_ctrl_reg |= SDADC_SDADC_CTRL_REG_SDADC_SE_Msk; in sdadc_smartbond_channel_setup()
150 int current_channel = u32_count_trailing_zeros(data->channel_read_mask); in adc_context_start_sampling()
153 while (!(SDADC->SDADC_CTRL_REG & SDADC_SDADC_CTRL_REG_SDADC_LDO_OK_Msk)) { in adc_context_start_sampling()
157 if (ctx->sequence.calibrate) { in adc_context_start_sampling()
160 val = SDADC->SDADC_CTRL_REG & ~PER_CHANNEL_ADC_CONFIG_MASK; in adc_context_start_sampling()
164 val |= (ctx->sequence.oversampling - 7) << SDADC_SDADC_CTRL_REG_SDADC_OSR_Pos; in adc_context_start_sampling()
166 SDADC->SDADC_CTRL_REG = val; in adc_context_start_sampling()
177 data->buffer += data->sequence_channel_count; in adc_context_update_buffer_pointer()
187 if (sequence->options) { in check_buffer_size()
188 needed_buffer_size *= (1 + sequence->options->extra_samplings); in check_buffer_size()
191 if (sequence->buffer_size < needed_buffer_size) { in check_buffer_size()
193 sequence->buffer_size, needed_buffer_size); in check_buffer_size()
194 return -ENOMEM; in check_buffer_size()
204 struct sdadc_smartbond_data *data = dev->data; in start_read()
206 if (sequence->oversampling < 7U || sequence->oversampling > 10) { in start_read()
208 return -EINVAL; in start_read()
211 if ((sequence->channels == 0) || in start_read()
212 ((sequence->channels & ~BIT_MASK(SMARTBOND_SDADC_CHANNEL_COUNT)) != 0)) { in start_read()
214 return -EINVAL; in start_read()
217 if (sequence->resolution < 8 || sequence->resolution > 15) { in start_read()
218 LOG_ERR("ADC resolution value %d is not valid", in start_read()
219 sequence->resolution); in start_read()
220 return -EINVAL; in start_read()
228 data->buffer = sequence->buffer; in start_read()
229 data->channel_read_mask = sequence->channels; in start_read()
230 data->sequence_channel_count = pop_count(sequence->channels); in start_read()
231 data->result_index = 0; in start_read()
233 adc_context_start_read(&data->ctx, sequence); in start_read()
235 error = adc_context_wait_for_completion(&data->ctx); in start_read()
241 struct sdadc_smartbond_data *data = dev->data; in sdadc_smartbond_isr()
242 int current_channel = u32_count_trailing_zeros(data->channel_read_mask); in sdadc_smartbond_isr()
244 SDADC->SDADC_CLEAR_INT_REG = 0; in sdadc_smartbond_isr()
246 data->buffer[data->result_index++] = ((uint16_t)SDADC->SDADC_RESULT_REG) >> in sdadc_smartbond_isr()
247 (16 - data->ctx.sequence.resolution); in sdadc_smartbond_isr()
249 data->channel_read_mask ^= 1 << current_channel; in sdadc_smartbond_isr()
251 if (data->channel_read_mask == 0) { in sdadc_smartbond_isr()
253 adc_context_on_sampling_done(&data->ctx, dev); in sdadc_smartbond_isr()
255 adc_context_start_sampling(&data->ctx); in sdadc_smartbond_isr()
258 LOG_DBG("%s ISR triggered.", dev->name); in sdadc_smartbond_isr()
266 struct sdadc_smartbond_data *data = dev->data; in sdadc_smartbond_read()
268 adc_context_lock(&data->ctx, false, NULL); in sdadc_smartbond_read()
271 adc_context_release(&data->ctx, error); in sdadc_smartbond_read()
282 struct sdadc_smartbond_data *data = dev->data; in sdadc_smartbond_read_async()
285 adc_context_lock(&data->ctx, true, async); in sdadc_smartbond_read_async()
288 adc_context_release(&data->ctx, error); in sdadc_smartbond_read_async()
297 const struct sdadc_smartbond_cfg *config = dev->config; in sdadc_smartbond_resume()
301 SDADC->SDADC_TEST_REG = in sdadc_smartbond_resume()
302 (SDADC->SDADC_TEST_REG & ~SDADC_SDADC_TEST_REG_SDADC_CLK_FREQ_Msk) | in sdadc_smartbond_resume()
303 (config->sdadc_clk_freq) << SDADC_SDADC_TEST_REG_SDADC_CLK_FREQ_Pos; in sdadc_smartbond_resume()
305 SDADC->SDADC_CTRL_REG = SDADC_SDADC_CTRL_REG_SDADC_EN_Msk; in sdadc_smartbond_resume()
311 ret = pinctrl_apply_state(config->pcfg, PINCTRL_STATE_DEFAULT); in sdadc_smartbond_resume()
312 if (ret < 0 && ret != -ENOENT) { in sdadc_smartbond_resume()
313 SDADC->SDADC_CTRL_REG = 0; in sdadc_smartbond_resume()
329 const struct sdadc_smartbond_cfg *config = dev->config; in sdadc_smartbond_suspend()
332 SDADC->SDADC_CTRL_REG = 0; in sdadc_smartbond_suspend()
341 ret = pinctrl_apply_state(config->pcfg, PINCTRL_STATE_SLEEP); in sdadc_smartbond_suspend()
342 if (ret < 0 && ret != -ENOENT) { in sdadc_smartbond_suspend()
363 return -ENOTSUP; in sdadc_smartbond_pm_action()
372 struct sdadc_smartbond_data *data = dev->data; in sdadc_smartbond_init()
391 adc_context_unlock_unconditionally(&data->ctx); in sdadc_smartbond_init()