Lines Matching +full:valid +full:- +full:channels
6 * SPDX-License-Identifier: Apache-2.0
15 * Front-End Controller (AFEC) peripheral.
37 #define CONF_ADC_PRESCALER ((SOC_ATMEL_SAM_MCK_FREQ_HZ / 15000000) - 1)
52 * channels in the sequence: this buffer changes by that amount
53 * so all the channels would get repeated.
57 /* Bit mask of the channels to be sampled. */
58 uint32_t channels; member
74 const struct adc_sam_cfg * const cfg = dev->config; in adc_sam_channel_setup()
75 Afec *const afec = cfg->regs; in adc_sam_channel_setup()
77 uint8_t channel_id = channel_cfg->channel_id; in adc_sam_channel_setup()
80 afec->AFEC_CGR &= ~(3 << channel_id * 2U); in adc_sam_channel_setup()
82 switch (channel_cfg->gain) { in adc_sam_channel_setup()
87 afec->AFEC_CGR |= (1 << (channel_id * 2U)); in adc_sam_channel_setup()
90 afec->AFEC_CGR |= (2 << (channel_id * 2U)); in adc_sam_channel_setup()
93 LOG_ERR("Selected ADC gain is not valid"); in adc_sam_channel_setup()
94 return -EINVAL; in adc_sam_channel_setup()
97 if (channel_cfg->acquisition_time != ADC_ACQ_TIME_DEFAULT) { in adc_sam_channel_setup()
98 LOG_ERR("Selected ADC acquisition time is not valid"); in adc_sam_channel_setup()
99 return -EINVAL; in adc_sam_channel_setup()
102 if (channel_cfg->reference != ADC_REF_EXTERNAL0) { in adc_sam_channel_setup()
103 LOG_ERR("Selected reference is not valid"); in adc_sam_channel_setup()
104 return -EINVAL; in adc_sam_channel_setup()
107 if (channel_cfg->differential) { in adc_sam_channel_setup()
109 return -EINVAL; in adc_sam_channel_setup()
113 /* Set single ended channels to unsigned and differential channels in adc_sam_channel_setup()
116 afec->AFEC_EMR &= ~(AFEC_EMR_SIGNMODE( in adc_sam_channel_setup()
125 const struct adc_sam_cfg *const cfg = dev->config; in adc_sam_start_conversion()
126 struct adc_sam_data *data = dev->data; in adc_sam_start_conversion()
127 Afec *const afec = cfg->regs; in adc_sam_start_conversion()
129 data->channel_id = find_lsb_set(data->channels) - 1; in adc_sam_start_conversion()
131 LOG_DBG("Starting channel %d", data->channel_id); in adc_sam_start_conversion()
133 /* Disable all channels. */ in adc_sam_start_conversion()
134 afec->AFEC_CHDR = 0xfff; in adc_sam_start_conversion()
135 afec->AFEC_IDR = 0xfff; in adc_sam_start_conversion()
140 afec->AFEC_CHER = (1 << data->channel_id); in adc_sam_start_conversion()
143 afec->AFEC_IER = (1 << data->channel_id); in adc_sam_start_conversion()
146 afec->AFEC_CR = AFEC_CR_START; in adc_sam_start_conversion()
151 * all channels as a group.
157 data->channels = ctx->sequence.channels; in adc_context_start_sampling()
159 adc_sam_start_conversion(data->dev); in adc_context_start_sampling()
168 data->buffer = data->repeat_buffer; in adc_context_update_buffer_pointer()
177 if (sequence->options) { in check_buffer_size()
178 needed_buffer_size *= (1 + sequence->options->extra_samplings); in check_buffer_size()
180 if (sequence->buffer_size < needed_buffer_size) { in check_buffer_size()
182 sequence->buffer_size, needed_buffer_size); in check_buffer_size()
183 return -ENOMEM; in check_buffer_size()
191 struct adc_sam_data *data = dev->data; in start_read()
193 uint32_t channels = sequence->channels; in start_read() local
195 data->channels = 0U; in start_read()
197 /* Signal an error if the channel selection is invalid (no channels or in start_read()
198 * a non-existing one is selected). in start_read()
200 if (channels == 0U || in start_read()
201 (channels & (~0UL << NUM_CHANNELS))) { in start_read()
202 LOG_ERR("Invalid selection of channels"); in start_read()
203 return -EINVAL; in start_read()
206 if (sequence->oversampling != 0U) { in start_read()
208 return -EINVAL; in start_read()
211 if (sequence->resolution != 12U) { in start_read()
215 LOG_ERR("ADC resolution value %d is not valid", in start_read()
216 sequence->resolution); in start_read()
217 return -EINVAL; in start_read()
223 while (channels > 0) { in start_read()
224 if (channels & 1) { in start_read()
227 channels >>= 1; in start_read()
239 data->buffer = sequence->buffer; in start_read()
240 data->repeat_buffer = sequence->buffer; in start_read()
247 adc_context_start_read(&data->ctx, sequence); in start_read()
249 error = adc_context_wait_for_completion(&data->ctx); in start_read()
256 struct adc_sam_data *data = dev->data; in adc_sam_read()
259 adc_context_lock(&data->ctx, false, NULL); in adc_sam_read()
261 adc_context_release(&data->ctx, error); in adc_sam_read()
268 const struct adc_sam_cfg *const cfg = dev->config; in adc_sam_init()
269 struct adc_sam_data *data = dev->data; in adc_sam_init()
270 Afec *const afec = cfg->regs; in adc_sam_init()
274 afec->AFEC_CR = AFEC_CR_SWRST; in adc_sam_init()
276 afec->AFEC_MR = AFEC_MR_TRGEN_DIS in adc_sam_init()
285 /* Set all channels CM voltage to Vrefp/2 (512). */ in adc_sam_init()
287 afec->AFEC_CSELR = i; in adc_sam_init()
288 afec->AFEC_COCR = 512; in adc_sam_init()
292 afec->AFEC_ACR = AFEC_ACR_IBCTL(1) in adc_sam_init()
301 (clock_control_subsys_t)&cfg->clock_cfg); in adc_sam_init()
304 retval = pinctrl_apply_state(cfg->pcfg, PINCTRL_STATE_DEFAULT); in adc_sam_init()
309 cfg->cfg_func(dev); in adc_sam_init()
311 data->dev = dev; in adc_sam_init()
313 adc_context_unlock_unconditionally(&data->ctx); in adc_sam_init()
323 struct adc_sam_data *data = dev->data; in adc_sam_read_async()
326 adc_context_lock(&data->ctx, true, async); in adc_sam_read_async()
328 adc_context_release(&data->ctx, error); in adc_sam_read_async()
344 struct adc_sam_data *data = dev->data; in adc_sam_isr()
345 const struct adc_sam_cfg *const cfg = dev->config; in adc_sam_isr()
346 Afec *const afec = cfg->regs; in adc_sam_isr()
349 afec->AFEC_CHDR |= BIT(data->channel_id); in adc_sam_isr()
350 afec->AFEC_IDR |= BIT(data->channel_id); in adc_sam_isr()
352 afec->AFEC_CSELR = AFEC_CSELR_CSEL(data->channel_id); in adc_sam_isr()
353 result = (uint16_t)(afec->AFEC_CDR); in adc_sam_isr()
355 *data->buffer++ = result; in adc_sam_isr()
356 data->channels &= ~BIT(data->channel_id); in adc_sam_isr()
358 if (data->channels) { in adc_sam_isr()
362 adc_context_on_sampling_done(&data->ctx, dev); in adc_sam_isr()