Lines Matching +full:dummy +full:- +full:bytes +full:- +full:count
4 * SPDX-License-Identifier: Apache-2.0
106 #define LMP90XXX_HAS_DRDYB(config) (config->drdyb.port != NULL)
172 const struct lmp90xxx_config *config = dev->config; in lmp90xxx_read_reg()
173 struct lmp90xxx_data *data = dev->data; in lmp90xxx_read_reg()
181 int dummy = 0; in lmp90xxx_read_reg() local
186 LOG_ERR("attempt to read 0 bytes from register 0x%02x", addr); in lmp90xxx_read_reg()
187 return -EINVAL; in lmp90xxx_read_reg()
192 return -EWOULDBLOCK; in lmp90xxx_read_reg()
195 k_mutex_lock(&data->ura_lock, K_FOREVER); in lmp90xxx_read_reg()
197 if (ura != data->ura) { in lmp90xxx_read_reg()
201 dummy += sizeof(inst1_uab); in lmp90xxx_read_reg()
209 dummy += sizeof(inst2); in lmp90xxx_read_reg()
212 /* Dummy RX Bytes */ in lmp90xxx_read_reg()
214 rx_buf[0].len = dummy; in lmp90xxx_read_reg()
221 tx.count = i; in lmp90xxx_read_reg()
223 rx.count = 2; in lmp90xxx_read_reg()
225 err = spi_transceive_dt(&config->bus, &tx, &rx); in lmp90xxx_read_reg()
227 data->ura = ura; in lmp90xxx_read_reg()
230 data->ura = LMP90XXX_INVALID_URA; in lmp90xxx_read_reg()
233 k_mutex_unlock(&data->ura_lock); in lmp90xxx_read_reg()
248 const struct lmp90xxx_config *config = dev->config; in lmp90xxx_write_reg()
249 struct lmp90xxx_data *data = dev->data; in lmp90xxx_write_reg()
259 LOG_ERR("attempt write 0 bytes to register 0x%02x", addr); in lmp90xxx_write_reg()
260 return -EINVAL; in lmp90xxx_write_reg()
265 return -EWOULDBLOCK; in lmp90xxx_write_reg()
268 k_mutex_lock(&data->ura_lock, K_FOREVER); in lmp90xxx_write_reg()
270 if (ura != data->ura) { in lmp90xxx_write_reg()
289 tx.count = i; in lmp90xxx_write_reg()
291 err = spi_write_dt(&config->bus, &tx); in lmp90xxx_write_reg()
293 data->ura = ura; in lmp90xxx_write_reg()
296 data->ura = LMP90XXX_INVALID_URA; in lmp90xxx_write_reg()
299 k_mutex_unlock(&data->ura_lock); in lmp90xxx_write_reg()
328 const struct lmp90xxx_config *config = dev->config; in lmp90xxx_has_channel()
330 if (channel >= config->channels) { in lmp90xxx_has_channel()
339 const struct lmp90xxx_config *config = dev->config; in lmp90xxx_has_input()
343 } else if (config->channels < LMP90XXX_MAX_CHANNELS && in lmp90xxx_has_input()
361 return -EINVAL; in lmp90xxx_acq_time_to_odr()
374 return -EINVAL; in lmp90xxx_acq_time_to_odr()
380 struct lmp90xxx_data *data = dev->data; in lmp90xxx_adc_channel_setup()
387 switch (channel_cfg->reference) { in lmp90xxx_adc_channel_setup()
396 channel_cfg->reference); in lmp90xxx_adc_channel_setup()
397 return -ENOTSUP; in lmp90xxx_adc_channel_setup()
400 if (!lmp90xxx_has_channel(dev, channel_cfg->channel_id)) { in lmp90xxx_adc_channel_setup()
401 LOG_ERR("unsupported channel id '%d'", channel_cfg->channel_id); in lmp90xxx_adc_channel_setup()
402 return -ENOTSUP; in lmp90xxx_adc_channel_setup()
405 if (!lmp90xxx_has_input(dev, channel_cfg->input_positive)) { in lmp90xxx_adc_channel_setup()
407 channel_cfg->input_positive); in lmp90xxx_adc_channel_setup()
408 return -ENOTSUP; in lmp90xxx_adc_channel_setup()
410 chx_inputcn |= LMP90XXX_VINP(channel_cfg->input_positive); in lmp90xxx_adc_channel_setup()
412 if (!lmp90xxx_has_input(dev, channel_cfg->input_negative)) { in lmp90xxx_adc_channel_setup()
414 channel_cfg->input_negative); in lmp90xxx_adc_channel_setup()
415 return -ENOTSUP; in lmp90xxx_adc_channel_setup()
417 chx_inputcn |= LMP90XXX_VINN(channel_cfg->input_negative); in lmp90xxx_adc_channel_setup()
419 ret = lmp90xxx_acq_time_to_odr(channel_cfg->acquisition_time); in lmp90xxx_adc_channel_setup()
422 channel_cfg->acquisition_time); in lmp90xxx_adc_channel_setup()
423 return -ENOTSUP; in lmp90xxx_adc_channel_setup()
426 data->channel_odr[channel_cfg->channel_id] = ret; in lmp90xxx_adc_channel_setup()
428 switch (channel_cfg->gain) { in lmp90xxx_adc_channel_setup()
454 LOG_ERR("unsupported channel gain '%d'", channel_cfg->gain); in lmp90xxx_adc_channel_setup()
455 return -ENOTSUP; in lmp90xxx_adc_channel_setup()
461 addr = LMP90XXX_REG_CH_INPUTCN(channel_cfg->channel_id); in lmp90xxx_adc_channel_setup()
476 for (mask = BIT(LMP90XXX_MAX_CHANNELS - 1); mask != 0; mask >>= 1) { in lmp90xxx_validate_buffer_size()
477 if (mask & sequence->channels) { in lmp90xxx_validate_buffer_size()
483 if (sequence->options) { in lmp90xxx_validate_buffer_size()
484 needed *= (1 + sequence->options->extra_samplings); in lmp90xxx_validate_buffer_size()
487 if (sequence->buffer_size < needed) { in lmp90xxx_validate_buffer_size()
488 return -ENOMEM; in lmp90xxx_validate_buffer_size()
497 const struct lmp90xxx_config *config = dev->config; in lmp90xxx_adc_start_read()
498 struct lmp90xxx_data *data = dev->data; in lmp90xxx_adc_start_read()
501 if (sequence->resolution != config->resolution) { in lmp90xxx_adc_start_read()
502 LOG_ERR("unsupported resolution %d", sequence->resolution); in lmp90xxx_adc_start_read()
503 return -ENOTSUP; in lmp90xxx_adc_start_read()
506 if (!lmp90xxx_has_channel(dev, find_msb_set(sequence->channels) - 1)) { in lmp90xxx_adc_start_read()
508 sequence->channels); in lmp90xxx_adc_start_read()
509 return -ENOTSUP; in lmp90xxx_adc_start_read()
518 data->buffer = sequence->buffer; in lmp90xxx_adc_start_read()
519 data->calibrate = sequence->calibrate; in lmp90xxx_adc_start_read()
520 adc_context_start_read(&data->ctx, sequence); in lmp90xxx_adc_start_read()
522 return adc_context_wait_for_completion(&data->ctx); in lmp90xxx_adc_start_read()
529 struct lmp90xxx_data *data = dev->data; in lmp90xxx_adc_read_async()
532 adc_context_lock(&data->ctx, async ? true : false, async); in lmp90xxx_adc_read_async()
534 adc_context_release(&data->ctx, err); in lmp90xxx_adc_read_async()
550 data->channels = ctx->sequence.channels; in adc_context_start_sampling()
551 data->repeat_buffer = data->buffer; in adc_context_start_sampling()
553 k_sem_give(&data->acq_sem); in adc_context_start_sampling()
563 data->buffer = data->repeat_buffer; in adc_context_update_buffer_pointer()
571 const struct lmp90xxx_config *config = dev->config; in lmp90xxx_adc_read_channel()
572 struct lmp90xxx_data *data = dev->data; in lmp90xxx_adc_read_channel()
598 k_sem_take(&data->drdyb_sem, K_FOREVER); in lmp90xxx_adc_read_channel()
600 odr = data->channel_odr[channel]; in lmp90xxx_adc_read_channel()
628 config->resolution / 8); in lmp90xxx_adc_read_channel()
642 return -EIO; in lmp90xxx_adc_read_channel()
648 *result >>= (32 - config->resolution); in lmp90xxx_adc_read_channel()
665 k_sem_take(&data->acq_sem, K_FOREVER); in lmp90xxx_acquisition_thread()
667 if (data->calibrate) { in lmp90xxx_acquisition_thread()
673 err = lmp90xxx_write_reg8(data->dev, in lmp90xxx_acquisition_thread()
678 adc_context_complete(&data->ctx, err); in lmp90xxx_acquisition_thread()
682 while (data->channels) { in lmp90xxx_acquisition_thread()
683 channel = find_lsb_set(data->channels) - 1; in lmp90xxx_acquisition_thread()
687 err = lmp90xxx_adc_read_channel(data->dev, in lmp90xxx_acquisition_thread()
690 adc_context_complete(&data->ctx, err); in lmp90xxx_acquisition_thread()
702 *data->buffer++ = result; in lmp90xxx_acquisition_thread()
703 WRITE_BIT(data->channels, channel, 0); in lmp90xxx_acquisition_thread()
706 adc_context_on_sampling_done(&data->ctx, data->dev); in lmp90xxx_acquisition_thread()
717 k_sem_give(&data->drdyb_sem); in lmp90xxx_drdyb_callback()
723 struct lmp90xxx_data *data = dev->data; in lmp90xxx_gpio_set_output()
728 return -EINVAL; in lmp90xxx_gpio_set_output()
731 k_mutex_lock(&data->gpio_lock, K_FOREVER); in lmp90xxx_gpio_set_output()
733 tmp = data->gpio_dircn | BIT(pin); in lmp90xxx_gpio_set_output()
734 if (tmp != data->gpio_dircn) { in lmp90xxx_gpio_set_output()
737 data->gpio_dircn = tmp; in lmp90xxx_gpio_set_output()
741 k_mutex_unlock(&data->gpio_lock); in lmp90xxx_gpio_set_output()
748 struct lmp90xxx_data *data = dev->data; in lmp90xxx_gpio_set_input()
753 return -EINVAL; in lmp90xxx_gpio_set_input()
756 k_mutex_lock(&data->gpio_lock, K_FOREVER); in lmp90xxx_gpio_set_input()
758 tmp = data->gpio_dircn & ~BIT(pin); in lmp90xxx_gpio_set_input()
759 if (tmp != data->gpio_dircn) { in lmp90xxx_gpio_set_input()
762 data->gpio_dircn = tmp; in lmp90xxx_gpio_set_input()
766 k_mutex_unlock(&data->gpio_lock); in lmp90xxx_gpio_set_input()
774 struct lmp90xxx_data *data = dev->data; in lmp90xxx_gpio_set_pin_value()
779 return -EINVAL; in lmp90xxx_gpio_set_pin_value()
782 k_mutex_lock(&data->gpio_lock, K_FOREVER); in lmp90xxx_gpio_set_pin_value()
784 tmp = data->gpio_dat; in lmp90xxx_gpio_set_pin_value()
787 if (tmp != data->gpio_dat) { in lmp90xxx_gpio_set_pin_value()
790 data->gpio_dat = tmp; in lmp90xxx_gpio_set_pin_value()
794 k_mutex_unlock(&data->gpio_lock); in lmp90xxx_gpio_set_pin_value()
802 struct lmp90xxx_data *data = dev->data; in lmp90xxx_gpio_get_pin_value()
807 return -EINVAL; in lmp90xxx_gpio_get_pin_value()
810 k_mutex_lock(&data->gpio_lock, K_FOREVER); in lmp90xxx_gpio_get_pin_value()
817 k_mutex_unlock(&data->gpio_lock); in lmp90xxx_gpio_get_pin_value()
825 struct lmp90xxx_data *data = dev->data; in lmp90xxx_gpio_port_get_raw()
829 k_mutex_lock(&data->gpio_lock, K_FOREVER); in lmp90xxx_gpio_port_get_raw()
831 tmp &= ~(data->gpio_dircn); in lmp90xxx_gpio_port_get_raw()
832 k_mutex_unlock(&data->gpio_lock); in lmp90xxx_gpio_port_get_raw()
843 struct lmp90xxx_data *data = dev->data; in lmp90xxx_gpio_port_set_masked_raw()
849 k_mutex_lock(&data->gpio_lock, K_FOREVER); in lmp90xxx_gpio_port_set_masked_raw()
850 tmp = (data->gpio_dat & ~mask) | (value & mask); in lmp90xxx_gpio_port_set_masked_raw()
851 if (tmp != data->gpio_dat) { in lmp90xxx_gpio_port_set_masked_raw()
854 data->gpio_dat = tmp; in lmp90xxx_gpio_port_set_masked_raw()
857 k_mutex_unlock(&data->gpio_lock); in lmp90xxx_gpio_port_set_masked_raw()
865 struct lmp90xxx_data *data = dev->data; in lmp90xxx_gpio_port_set_bits_raw()
871 k_mutex_lock(&data->gpio_lock, K_FOREVER); in lmp90xxx_gpio_port_set_bits_raw()
872 if (tmp != data->gpio_dat) { in lmp90xxx_gpio_port_set_bits_raw()
873 tmp |= data->gpio_dat; in lmp90xxx_gpio_port_set_bits_raw()
876 data->gpio_dat = tmp; in lmp90xxx_gpio_port_set_bits_raw()
879 k_mutex_unlock(&data->gpio_lock); in lmp90xxx_gpio_port_set_bits_raw()
887 struct lmp90xxx_data *data = dev->data; in lmp90xxx_gpio_port_clear_bits_raw()
893 k_mutex_lock(&data->gpio_lock, K_FOREVER); in lmp90xxx_gpio_port_clear_bits_raw()
894 if ((tmp & data->gpio_dat) != 0) { in lmp90xxx_gpio_port_clear_bits_raw()
895 tmp = data->gpio_dat & ~tmp; in lmp90xxx_gpio_port_clear_bits_raw()
898 data->gpio_dat = tmp; in lmp90xxx_gpio_port_clear_bits_raw()
901 k_mutex_unlock(&data->gpio_lock); in lmp90xxx_gpio_port_clear_bits_raw()
909 struct lmp90xxx_data *data = dev->data; in lmp90xxx_gpio_port_toggle_bits()
915 k_mutex_lock(&data->gpio_lock, K_FOREVER); in lmp90xxx_gpio_port_toggle_bits()
916 tmp ^= data->gpio_dat; in lmp90xxx_gpio_port_toggle_bits()
919 data->gpio_dat = tmp; in lmp90xxx_gpio_port_toggle_bits()
921 k_mutex_unlock(&data->gpio_lock); in lmp90xxx_gpio_port_toggle_bits()
930 const struct lmp90xxx_config *config = dev->config; in lmp90xxx_init()
931 struct lmp90xxx_data *data = dev->data; in lmp90xxx_init()
935 data->dev = dev; in lmp90xxx_init()
937 k_mutex_init(&data->ura_lock); in lmp90xxx_init()
938 k_sem_init(&data->acq_sem, 0, 1); in lmp90xxx_init()
939 k_sem_init(&data->drdyb_sem, 0, 1); in lmp90xxx_init()
941 k_mutex_init(&data->gpio_lock); in lmp90xxx_init()
945 data->ura = LMP90XXX_INVALID_URA; in lmp90xxx_init()
947 if (!spi_is_ready_dt(&config->bus)) { in lmp90xxx_init()
948 LOG_ERR("SPI bus %s not ready", config->bus.bus->name); in lmp90xxx_init()
949 return -ENODEV; in lmp90xxx_init()
966 if (config->rtd_current) { in lmp90xxx_init()
968 LMP90XXX_RTD_CUR_SEL(config->rtd_current)); in lmp90xxx_init()
986 err = gpio_pin_configure_dt(&config->drdyb, GPIO_INPUT); in lmp90xxx_init()
990 return -EINVAL; in lmp90xxx_init()
993 gpio_init_callback(&data->drdyb_cb, lmp90xxx_drdyb_callback, in lmp90xxx_init()
994 BIT(config->drdyb.pin)); in lmp90xxx_init()
996 err = gpio_add_callback(config->drdyb.port, &data->drdyb_cb); in lmp90xxx_init()
999 return -EINVAL; in lmp90xxx_init()
1010 err = gpio_pin_interrupt_configure_dt(&config->drdyb, in lmp90xxx_init()
1015 return -EINVAL; in lmp90xxx_init()
1019 tid = k_thread_create(&data->thread, data->stack, in lmp90xxx_init()
1020 K_KERNEL_STACK_SIZEOF(data->stack), in lmp90xxx_init()
1027 /* Put device in stand-by to prepare it for single-shot conversion */ in lmp90xxx_init()
1030 LOG_ERR("failed to request stand-by mode (err %d)", err); in lmp90xxx_init()
1034 adc_context_unlock_unconditionally(&data->ctx); in lmp90xxx_init()
1099 * LMP90079: 16 bit, 4 diff/7 se (7 channels), 0 currents, has VIN3-5
1107 * LMP90080: 16 bit, 4 diff/7 se (7 channels), 2 currents, has VIN3-5
1131 * LMP90099: 24 bit, 4 diff/7 se (7 channels), 0 currents, has VIN3-5
1139 * LMP90100: 24 bit, 4 diff/7 se (7 channels), 2 currents, has VIN3-5