Lines Matching refs:dev
66 char * iio_device_get_xml(const struct iio_device *dev, size_t *length) in iio_device_get_xml() argument
69 + strlen(dev->id) + (dev->name ? strlen(dev->name) : 0); in iio_device_get_xml()
74 attrs_len = malloc(dev->nb_attrs * sizeof(*attrs_len)); in iio_device_get_xml()
78 attrs = malloc(dev->nb_attrs * sizeof(*attrs)); in iio_device_get_xml()
82 for (i = 0; i < dev->nb_attrs; i++) { in iio_device_get_xml()
83 char *xml = get_attr_xml(dev->attrs[i], &attrs_len[i], IIO_ATTR_TYPE_DEVICE); in iio_device_get_xml()
90 channels_len = malloc(dev->nb_channels * sizeof(*channels_len)); in iio_device_get_xml()
94 channels = malloc(dev->nb_channels * sizeof(*channels)); in iio_device_get_xml()
98 for (j = 0; j < dev->nb_channels; j++) { in iio_device_get_xml()
99 char *xml = iio_channel_get_xml(dev->channels[j], in iio_device_get_xml()
107 buffer_attrs_len = malloc(dev->nb_buffer_attrs * in iio_device_get_xml()
112 buffer_attrs = malloc(dev->nb_buffer_attrs * sizeof(*buffer_attrs)); in iio_device_get_xml()
116 for (k = 0; k < dev->nb_buffer_attrs; k++) { in iio_device_get_xml()
117 char *xml = get_attr_xml(dev->buffer_attrs[k], in iio_device_get_xml()
125 debug_attrs_len = malloc(dev->nb_debug_attrs * in iio_device_get_xml()
130 debug_attrs = malloc(dev->nb_debug_attrs * sizeof(*debug_attrs)); in iio_device_get_xml()
134 for (k = 0; k < dev->nb_debug_attrs; k++) { in iio_device_get_xml()
135 char *xml = get_attr_xml(dev->debug_attrs[k], in iio_device_get_xml()
147 iio_snprintf(str, len, "<device id=\"%s\"", dev->id); in iio_device_get_xml()
150 if (dev->name) { in iio_device_get_xml()
151 sprintf(ptr, " name=\"%s\"", dev->name); in iio_device_get_xml()
158 for (i = 0; i < dev->nb_channels; i++) { in iio_device_get_xml()
167 for (i = 0; i < dev->nb_attrs; i++) { in iio_device_get_xml()
176 for (i = 0; i < dev->nb_buffer_attrs; i++) { in iio_device_get_xml()
185 for (i = 0; i < dev->nb_debug_attrs; i++) { in iio_device_get_xml()
225 const char * iio_device_get_id(const struct iio_device *dev) in iio_device_get_id() argument
227 return dev->id; in iio_device_get_id()
230 const char * iio_device_get_name(const struct iio_device *dev) in iio_device_get_name() argument
232 return dev->name; in iio_device_get_name()
235 unsigned int iio_device_get_channels_count(const struct iio_device *dev) in iio_device_get_channels_count() argument
237 return dev->nb_channels; in iio_device_get_channels_count()
240 struct iio_channel * iio_device_get_channel(const struct iio_device *dev, in iio_device_get_channel() argument
243 if (index >= dev->nb_channels) in iio_device_get_channel()
246 return dev->channels[index]; in iio_device_get_channel()
249 struct iio_channel * iio_device_find_channel(const struct iio_device *dev, in iio_device_find_channel() argument
253 for (i = 0; i < dev->nb_channels; i++) { in iio_device_find_channel()
254 struct iio_channel *chn = dev->channels[i]; in iio_device_find_channel()
265 unsigned int iio_device_get_attrs_count(const struct iio_device *dev) in iio_device_get_attrs_count() argument
267 return dev->nb_attrs; in iio_device_get_attrs_count()
270 const char * iio_device_get_attr(const struct iio_device *dev, in iio_device_get_attr() argument
273 if (index >= dev->nb_attrs) in iio_device_get_attr()
276 return dev->attrs[index]; in iio_device_get_attr()
279 const char * iio_device_find_attr(const struct iio_device *dev, in iio_device_find_attr() argument
283 for (i = 0; i < dev->nb_attrs; i++) { in iio_device_find_attr()
284 const char *attr = dev->attrs[i]; in iio_device_find_attr()
291 unsigned int iio_device_get_buffer_attrs_count(const struct iio_device *dev) in iio_device_get_buffer_attrs_count() argument
293 return dev->nb_buffer_attrs; in iio_device_get_buffer_attrs_count()
296 const char * iio_device_get_buffer_attr(const struct iio_device *dev, in iio_device_get_buffer_attr() argument
299 if (index >= dev->nb_buffer_attrs) in iio_device_get_buffer_attr()
302 return dev->buffer_attrs[index]; in iio_device_get_buffer_attr()
305 const char * iio_device_find_buffer_attr(const struct iio_device *dev, in iio_device_find_buffer_attr() argument
309 for (i = 0; i < dev->nb_buffer_attrs; i++) { in iio_device_find_buffer_attr()
310 const char *attr = dev->buffer_attrs[i]; in iio_device_find_buffer_attr()
317 const char * iio_device_find_debug_attr(const struct iio_device *dev, in iio_device_find_debug_attr() argument
321 for (i = 0; i < dev->nb_debug_attrs; i++) { in iio_device_find_debug_attr()
322 const char *attr = dev->debug_attrs[i]; in iio_device_find_debug_attr()
329 bool iio_device_is_tx(const struct iio_device *dev) in iio_device_is_tx() argument
333 for (i = 0; i < dev->nb_channels; i++) { in iio_device_is_tx()
334 struct iio_channel *ch = dev->channels[i]; in iio_device_is_tx()
342 int iio_device_open(const struct iio_device *dev, in iio_device_open() argument
348 for (i = 0; !has_channels && i < dev->words; i++) in iio_device_open()
349 has_channels = !!dev->mask[i]; in iio_device_open()
353 if (dev->ctx->ops->open) in iio_device_open()
354 return dev->ctx->ops->open(dev, samples_count, cyclic); in iio_device_open()
359 int iio_device_close(const struct iio_device *dev) in iio_device_close() argument
361 if (dev->ctx->ops->close) in iio_device_close()
362 return dev->ctx->ops->close(dev); in iio_device_close()
367 int iio_device_get_poll_fd(const struct iio_device *dev) in iio_device_get_poll_fd() argument
369 if (dev->ctx->ops->get_fd) in iio_device_get_poll_fd()
370 return dev->ctx->ops->get_fd(dev); in iio_device_get_poll_fd()
375 int iio_device_set_blocking_mode(const struct iio_device *dev, bool blocking) in iio_device_set_blocking_mode() argument
377 if (dev->ctx->ops->set_blocking_mode) in iio_device_set_blocking_mode()
378 return dev->ctx->ops->set_blocking_mode(dev, blocking); in iio_device_set_blocking_mode()
383 ssize_t iio_device_read_raw(const struct iio_device *dev, in iio_device_read_raw() argument
386 if (dev->ctx->ops->read) in iio_device_read_raw()
387 return dev->ctx->ops->read(dev, dst, len, mask, words); in iio_device_read_raw()
392 ssize_t iio_device_write_raw(const struct iio_device *dev, in iio_device_write_raw() argument
395 if (dev->ctx->ops->write) in iio_device_write_raw()
396 return dev->ctx->ops->write(dev, src, len); in iio_device_write_raw()
401 ssize_t iio_device_attr_read(const struct iio_device *dev, in iio_device_attr_read() argument
404 if (dev->ctx->ops->read_device_attr) in iio_device_attr_read()
405 return dev->ctx->ops->read_device_attr(dev, in iio_device_attr_read()
411 ssize_t iio_device_attr_write_raw(const struct iio_device *dev, in iio_device_attr_write_raw() argument
414 if (dev->ctx->ops->write_device_attr) in iio_device_attr_write_raw()
415 return dev->ctx->ops->write_device_attr(dev, in iio_device_attr_write_raw()
421 ssize_t iio_device_attr_write(const struct iio_device *dev, in iio_device_attr_write() argument
424 return iio_device_attr_write_raw(dev, attr, src, strlen(src) + 1); in iio_device_attr_write()
427 ssize_t iio_device_buffer_attr_read(const struct iio_device *dev, in iio_device_buffer_attr_read() argument
430 if (dev->ctx->ops->read_device_attr) in iio_device_buffer_attr_read()
431 return dev->ctx->ops->read_device_attr(dev, in iio_device_buffer_attr_read()
437 ssize_t iio_device_buffer_attr_write_raw(const struct iio_device *dev, in iio_device_buffer_attr_write_raw() argument
440 if (dev->ctx->ops->write_device_attr) in iio_device_buffer_attr_write_raw()
441 return dev->ctx->ops->write_device_attr(dev, in iio_device_buffer_attr_write_raw()
447 ssize_t iio_device_buffer_attr_write(const struct iio_device *dev, in iio_device_buffer_attr_write() argument
450 return iio_device_buffer_attr_write_raw(dev, attr, src, strlen(src) + 1); in iio_device_buffer_attr_write()
453 void iio_device_set_data(struct iio_device *dev, void *data) in iio_device_set_data() argument
455 dev->userdata = data; in iio_device_set_data()
458 void * iio_device_get_data(const struct iio_device *dev) in iio_device_get_data() argument
460 return dev->userdata; in iio_device_get_data()
463 bool iio_device_is_trigger(const struct iio_device *dev) in iio_device_is_trigger() argument
468 unsigned int nb = iio_device_get_channels_count(dev); in iio_device_is_trigger()
469 const char *name = iio_device_get_name(dev), in iio_device_is_trigger()
470 *id = iio_device_get_id(dev); in iio_device_is_trigger()
475 int iio_device_set_kernel_buffers_count(const struct iio_device *dev, in iio_device_set_kernel_buffers_count() argument
480 else if (dev->ctx->ops->set_kernel_buffers_count) in iio_device_set_kernel_buffers_count()
481 return dev->ctx->ops->set_kernel_buffers_count(dev, nb_buffers); in iio_device_set_kernel_buffers_count()
486 int iio_device_get_trigger(const struct iio_device *dev, in iio_device_get_trigger() argument
491 else if (dev->ctx->ops->get_trigger) in iio_device_get_trigger()
492 return dev->ctx->ops->get_trigger(dev, trigger); in iio_device_get_trigger()
497 int iio_device_set_trigger(const struct iio_device *dev, in iio_device_set_trigger() argument
502 else if (dev->ctx->ops->set_trigger) in iio_device_set_trigger()
503 return dev->ctx->ops->set_trigger(dev, trigger); in iio_device_set_trigger()
508 void free_device(struct iio_device *dev) in free_device() argument
511 for (i = 0; i < dev->nb_attrs; i++) in free_device()
512 free(dev->attrs[i]); in free_device()
513 if (dev->nb_attrs) in free_device()
514 free(dev->attrs); in free_device()
515 for (i = 0; i < dev->nb_buffer_attrs; i++) in free_device()
516 free(dev->buffer_attrs[i]); in free_device()
517 if (dev->nb_buffer_attrs) in free_device()
518 free(dev->buffer_attrs); in free_device()
519 for (i = 0; i < dev->nb_debug_attrs; i++) in free_device()
520 free(dev->debug_attrs[i]); in free_device()
521 if (dev->nb_debug_attrs) in free_device()
522 free(dev->debug_attrs); in free_device()
523 for (i = 0; i < dev->nb_channels; i++) in free_device()
524 free_channel(dev->channels[i]); in free_device()
525 if (dev->nb_channels) in free_device()
526 free(dev->channels); in free_device()
527 if (dev->mask) in free_device()
528 free(dev->mask); in free_device()
529 if (dev->name) in free_device()
530 free(dev->name); in free_device()
531 if (dev->id) in free_device()
532 free(dev->id); in free_device()
533 free(dev); in free_device()
536 ssize_t iio_device_get_sample_size_mask(const struct iio_device *dev, in iio_device_get_sample_size_mask() argument
543 if (words != (dev->nb_channels + 31) / 32) in iio_device_get_sample_size_mask()
546 for (i = 0; i < dev->nb_channels; i++) { in iio_device_get_sample_size_mask()
547 const struct iio_channel *chn = dev->channels[i]; in iio_device_get_sample_size_mask()
571 ssize_t iio_device_get_sample_size(const struct iio_device *dev) in iio_device_get_sample_size() argument
573 return iio_device_get_sample_size_mask(dev, dev->mask, dev->words); in iio_device_get_sample_size()
576 int iio_device_attr_read_longlong(const struct iio_device *dev, in iio_device_attr_read_longlong() argument
581 ssize_t ret = iio_device_attr_read(dev, attr, buf, sizeof(buf)); in iio_device_attr_read_longlong()
592 int iio_device_attr_read_bool(const struct iio_device *dev, in iio_device_attr_read_bool() argument
596 int ret = iio_device_attr_read_longlong(dev, attr, &value); in iio_device_attr_read_bool()
604 int iio_device_attr_read_double(const struct iio_device *dev, in iio_device_attr_read_double() argument
608 ssize_t ret = iio_device_attr_read(dev, attr, buf, sizeof(buf)); in iio_device_attr_read_double()
615 int iio_device_attr_write_longlong(const struct iio_device *dev, in iio_device_attr_write_longlong() argument
622 ret = iio_device_attr_write(dev, attr, buf); in iio_device_attr_write_longlong()
627 int iio_device_attr_write_double(const struct iio_device *dev, in iio_device_attr_write_double() argument
635 ret = iio_device_attr_write(dev, attr, buf); in iio_device_attr_write_double()
639 int iio_device_attr_write_bool(const struct iio_device *dev, in iio_device_attr_write_bool() argument
645 ret = iio_device_attr_write(dev, attr, "1"); in iio_device_attr_write_bool()
647 ret = iio_device_attr_write(dev, attr, "0"); in iio_device_attr_write_bool()
652 int iio_device_buffer_attr_read_longlong(const struct iio_device *dev, in iio_device_buffer_attr_read_longlong() argument
657 ssize_t ret = iio_device_buffer_attr_read(dev, attr, buf, sizeof(buf)); in iio_device_buffer_attr_read_longlong()
668 int iio_device_buffer_attr_read_bool(const struct iio_device *dev, in iio_device_buffer_attr_read_bool() argument
672 int ret = iio_device_buffer_attr_read_longlong(dev, attr, &value); in iio_device_buffer_attr_read_bool()
680 int iio_device_buffer_attr_read_double(const struct iio_device *dev, in iio_device_buffer_attr_read_double() argument
684 ssize_t ret = iio_device_buffer_attr_read(dev, attr, buf, sizeof(buf)); in iio_device_buffer_attr_read_double()
691 int iio_device_buffer_attr_write_longlong(const struct iio_device *dev, in iio_device_buffer_attr_write_longlong() argument
698 ret = iio_device_buffer_attr_write(dev, attr, buf); in iio_device_buffer_attr_write_longlong()
703 int iio_device_buffer_attr_write_double(const struct iio_device *dev, in iio_device_buffer_attr_write_double() argument
711 ret = iio_device_buffer_attr_write(dev, attr, buf); in iio_device_buffer_attr_write_double()
715 int iio_device_buffer_attr_write_bool(const struct iio_device *dev, in iio_device_buffer_attr_write_bool() argument
721 ret = iio_device_buffer_attr_write(dev, attr, "1"); in iio_device_buffer_attr_write_bool()
723 ret = iio_device_buffer_attr_write(dev, attr, "0"); in iio_device_buffer_attr_write_bool()
728 ssize_t iio_device_debug_attr_read(const struct iio_device *dev, in iio_device_debug_attr_read() argument
731 if (dev->ctx->ops->read_device_attr) in iio_device_debug_attr_read()
732 return dev->ctx->ops->read_device_attr(dev, in iio_device_debug_attr_read()
738 ssize_t iio_device_debug_attr_write_raw(const struct iio_device *dev, in iio_device_debug_attr_write_raw() argument
741 if (dev->ctx->ops->write_device_attr) in iio_device_debug_attr_write_raw()
742 return dev->ctx->ops->write_device_attr(dev, in iio_device_debug_attr_write_raw()
748 ssize_t iio_device_debug_attr_write(const struct iio_device *dev, in iio_device_debug_attr_write() argument
751 return iio_device_debug_attr_write_raw(dev, attr, src, strlen(src) + 1); in iio_device_debug_attr_write()
754 unsigned int iio_device_get_debug_attrs_count(const struct iio_device *dev) in iio_device_get_debug_attrs_count() argument
756 return dev->nb_debug_attrs; in iio_device_get_debug_attrs_count()
759 const char * iio_device_get_debug_attr(const struct iio_device *dev, in iio_device_get_debug_attr() argument
762 if (index >= dev->nb_debug_attrs) in iio_device_get_debug_attr()
765 return dev->debug_attrs[index]; in iio_device_get_debug_attr()
768 int iio_device_debug_attr_read_longlong(const struct iio_device *dev, in iio_device_debug_attr_read_longlong() argument
773 ssize_t ret = iio_device_debug_attr_read(dev, attr, buf, sizeof(buf)); in iio_device_debug_attr_read_longlong()
784 int iio_device_debug_attr_read_bool(const struct iio_device *dev, in iio_device_debug_attr_read_bool() argument
788 int ret = iio_device_debug_attr_read_longlong(dev, attr, &value); in iio_device_debug_attr_read_bool()
796 int iio_device_debug_attr_read_double(const struct iio_device *dev, in iio_device_debug_attr_read_double() argument
800 ssize_t ret = iio_device_debug_attr_read(dev, attr, buf, sizeof(buf)); in iio_device_debug_attr_read_double()
807 int iio_device_debug_attr_write_longlong(const struct iio_device *dev, in iio_device_debug_attr_write_longlong() argument
814 ret = iio_device_debug_attr_write(dev, attr, buf); in iio_device_debug_attr_write_longlong()
819 int iio_device_debug_attr_write_double(const struct iio_device *dev, in iio_device_debug_attr_write_double() argument
827 ret = iio_device_debug_attr_write(dev, attr, buf); in iio_device_debug_attr_write_double()
831 int iio_device_debug_attr_write_bool(const struct iio_device *dev, in iio_device_debug_attr_write_bool() argument
837 ret = iio_device_debug_attr_write_raw(dev, attr, "1", 2); in iio_device_debug_attr_write_bool()
839 ret = iio_device_debug_attr_write_raw(dev, attr, "0", 2); in iio_device_debug_attr_write_bool()
844 int iio_device_identify_filename(const struct iio_device *dev, in iio_device_identify_filename() argument
850 for (i = 0; i < dev->nb_channels; i++) { in iio_device_identify_filename()
851 struct iio_channel *ch = dev->channels[i]; in iio_device_identify_filename()
863 for (i = 0; i < dev->nb_attrs; i++) { in iio_device_identify_filename()
865 if (!strcmp(dev->attrs[i], filename)) { in iio_device_identify_filename()
866 *attr = dev->attrs[i]; in iio_device_identify_filename()
872 for (i = 0; i < dev->nb_debug_attrs; i++) { in iio_device_identify_filename()
873 if (!strcmp(dev->debug_attrs[i], filename)) { in iio_device_identify_filename()
874 *attr = dev->debug_attrs[i]; in iio_device_identify_filename()
883 int iio_device_reg_write(struct iio_device *dev, in iio_device_reg_write() argument
891 ret = iio_device_debug_attr_write(dev, "direct_reg_access", buf); in iio_device_reg_write()
896 int iio_device_reg_read(struct iio_device *dev, in iio_device_reg_read() argument
904 int ret = iio_device_debug_attr_write_longlong(dev, in iio_device_reg_read()
909 ret = iio_device_debug_attr_read_longlong(dev, in iio_device_reg_read()
916 static int read_each_attr(struct iio_device *dev, enum iio_attr_type type, in read_each_attr() argument
917 int (*cb)(struct iio_device *dev, in read_each_attr() argument
932 count = iio_device_get_attrs_count(dev); in read_each_attr()
933 ret = (int) iio_device_attr_read(dev, in read_each_attr()
937 count = iio_device_get_debug_attrs_count(dev); in read_each_attr()
938 ret = (int) iio_device_debug_attr_read(dev, in read_each_attr()
942 count = iio_device_get_buffer_attrs_count(dev); in read_each_attr()
943 ret = (int) iio_device_buffer_attr_read(dev, in read_each_attr()
978 attr = iio_device_get_attr(dev, i); in read_each_attr()
981 attr = iio_device_get_debug_attr(dev, i); in read_each_attr()
984 attr = iio_device_get_buffer_attr(dev, i); in read_each_attr()
992 ret = cb(dev, attr, ptr, (size_t) len, data); in read_each_attr()
1011 static int write_each_attr(struct iio_device *dev, enum iio_attr_type type, in write_each_attr() argument
1012 ssize_t (*cb)(struct iio_device *dev, in write_each_attr() argument
1030 count = iio_device_get_attrs_count(dev); in write_each_attr()
1033 count = iio_device_get_debug_attrs_count(dev); in write_each_attr()
1036 count = iio_device_get_buffer_attrs_count(dev); in write_each_attr()
1048 attr = iio_device_get_attr(dev, i); in write_each_attr()
1051 attr = iio_device_get_debug_attr(dev, i); in write_each_attr()
1054 attr = iio_device_get_buffer_attr(dev, i); in write_each_attr()
1061 ret = (int) cb(dev, attr, ptr + 4, len - 4, data); in write_each_attr()
1079 ret = (int) iio_device_attr_write_raw(dev, in write_each_attr()
1083 ret = (int) iio_device_debug_attr_write_raw(dev, in write_each_attr()
1087 ret = (int) iio_device_buffer_attr_write_raw(dev, in write_each_attr()
1100 int iio_device_debug_attr_read_all(struct iio_device *dev, in iio_device_debug_attr_read_all() argument
1101 int (*cb)(struct iio_device *dev, in iio_device_debug_attr_read_all() argument
1105 return read_each_attr(dev, IIO_ATTR_TYPE_DEBUG, cb, data); in iio_device_debug_attr_read_all()
1108 int iio_device_buffer_attr_read_all(struct iio_device *dev, in iio_device_buffer_attr_read_all() argument
1109 int (*cb)(struct iio_device *dev, in iio_device_buffer_attr_read_all() argument
1113 return read_each_attr(dev, IIO_ATTR_TYPE_BUFFER, cb, data); in iio_device_buffer_attr_read_all()
1116 int iio_device_attr_read_all(struct iio_device *dev, in iio_device_attr_read_all() argument
1117 int (*cb)(struct iio_device *dev, in iio_device_attr_read_all() argument
1121 return read_each_attr(dev, IIO_ATTR_TYPE_DEVICE ,cb, data); in iio_device_attr_read_all()
1124 int iio_device_debug_attr_write_all(struct iio_device *dev, in iio_device_debug_attr_write_all() argument
1125 ssize_t (*cb)(struct iio_device *dev, in iio_device_debug_attr_write_all() argument
1129 return write_each_attr(dev, IIO_ATTR_TYPE_DEBUG, cb, data); in iio_device_debug_attr_write_all()
1132 int iio_device_buffer_attr_write_all(struct iio_device *dev, in iio_device_buffer_attr_write_all() argument
1133 ssize_t (*cb)(struct iio_device *dev, in iio_device_buffer_attr_write_all() argument
1137 return write_each_attr(dev, IIO_ATTR_TYPE_BUFFER, cb, data); in iio_device_buffer_attr_write_all()
1140 int iio_device_attr_write_all(struct iio_device *dev, in iio_device_attr_write_all() argument
1141 ssize_t (*cb)(struct iio_device *dev, in iio_device_attr_write_all() argument
1145 return write_each_attr(dev, IIO_ATTR_TYPE_DEVICE, cb, data); in iio_device_attr_write_all()
1148 const struct iio_context * iio_device_get_context(const struct iio_device *dev) in iio_device_get_context() argument
1150 return dev->ctx; in iio_device_get_context()