Lines Matching +full:proximity +full:- +full:close +full:- +full:hysteresis

1 // SPDX-License-Identifier: GPL-2.0-only
10 #define pr_fmt(fmt) "iio-core: " fmt
32 #include <linux/iio/iio-opaque.h>
66 [IIO_PROXIMITY] = "proximity",
174 [IIO_CHAN_INFO_HYSTERESIS] = "hysteresis",
190 * iio_device_id() - query the unique ID for the device
202 return iio_dev_opaque->id; in iio_device_id()
207 * iio_buffer_enabled() - helper function to test if the buffer is enabled
216 return iio_dev_opaque->currentmode & in iio_buffer_enabled()
231 return iio_dev_opaque->debugfs_dentry; in iio_get_debugfs_dentry()
237 * iio_find_channel_from_si() - get channel from its scan index
249 for (i = 0; i < indio_dev->num_channels; i++) in iio_find_channel_from_si()
250 if (indio_dev->channels[i].scan_index == si) in iio_find_channel_from_si()
251 return &indio_dev->channels[i]; in iio_find_channel_from_si()
260 return sysfs_emit(buf, "%s\n", to_iio_const_attr(attr)->string); in iio_read_const_attr()
265 * iio_device_set_clock() - Set current timestamping clock for the device
275 const struct iio_event_interface *ev_int = iio_dev_opaque->event_interface; in iio_device_set_clock()
277 ret = mutex_lock_interruptible(&iio_dev_opaque->mlock); in iio_device_set_clock()
282 mutex_unlock(&iio_dev_opaque->mlock); in iio_device_set_clock()
283 return -EBUSY; in iio_device_set_clock()
285 iio_dev_opaque->clock_id = clock_id; in iio_device_set_clock()
286 mutex_unlock(&iio_dev_opaque->mlock); in iio_device_set_clock()
293 * iio_device_get_clock() - Retrieve current timestamping clock for the device
302 return iio_dev_opaque->clock_id; in iio_device_get_clock()
307 * iio_get_time_ns() - utility function to get a time stamp for events etc
377 struct iio_dev *indio_dev = file->private_data; in iio_debugfs_read_reg()
384 iio_dev_opaque->read_buf, in iio_debugfs_read_reg()
385 iio_dev_opaque->read_buf_len); in iio_debugfs_read_reg()
387 ret = indio_dev->info->debugfs_reg_access(indio_dev, in iio_debugfs_read_reg()
388 iio_dev_opaque->cached_reg_addr, in iio_debugfs_read_reg()
391 dev_err(indio_dev->dev.parent, "%s: read failed\n", __func__); in iio_debugfs_read_reg()
395 iio_dev_opaque->read_buf_len = snprintf(iio_dev_opaque->read_buf, in iio_debugfs_read_reg()
396 sizeof(iio_dev_opaque->read_buf), in iio_debugfs_read_reg()
400 iio_dev_opaque->read_buf, in iio_debugfs_read_reg()
401 iio_dev_opaque->read_buf_len); in iio_debugfs_read_reg()
407 struct iio_dev *indio_dev = file->private_data; in iio_debugfs_write_reg()
413 count = min(count, sizeof(buf) - 1); in iio_debugfs_write_reg()
415 return -EFAULT; in iio_debugfs_write_reg()
423 iio_dev_opaque->cached_reg_addr = reg; in iio_debugfs_write_reg()
426 iio_dev_opaque->cached_reg_addr = reg; in iio_debugfs_write_reg()
427 ret = indio_dev->info->debugfs_reg_access(indio_dev, reg, in iio_debugfs_write_reg()
430 dev_err(indio_dev->dev.parent, "%s: write failed\n", in iio_debugfs_write_reg()
436 return -EINVAL; in iio_debugfs_write_reg()
452 debugfs_remove_recursive(iio_dev_opaque->debugfs_dentry); in iio_device_unregister_debugfs()
459 if (indio_dev->info->debugfs_reg_access == NULL) in iio_device_register_debugfs()
467 iio_dev_opaque->debugfs_dentry = in iio_device_register_debugfs()
468 debugfs_create_dir(dev_name(&indio_dev->dev), in iio_device_register_debugfs()
472 iio_dev_opaque->debugfs_dentry, indio_dev, in iio_device_register_debugfs()
493 ext_info = &this_attr->c->ext_info[this_attr->address]; in iio_read_channel_ext_info()
495 return ext_info->read(indio_dev, ext_info->private, this_attr->c, buf); in iio_read_channel_ext_info()
506 ext_info = &this_attr->c->ext_info[this_attr->address]; in iio_write_channel_ext_info()
508 return ext_info->write(indio_dev, ext_info->private, in iio_write_channel_ext_info()
509 this_attr->c, buf, len); in iio_write_channel_ext_info()
519 if (!e->num_items) in iio_enum_available_read()
522 for (i = 0; i < e->num_items; ++i) { in iio_enum_available_read()
523 if (!e->items[i]) in iio_enum_available_read()
525 len += sysfs_emit_at(buf, len, "%s ", e->items[i]); in iio_enum_available_read()
529 buf[len - 1] = '\n'; in iio_enum_available_read()
541 if (!e->get) in iio_enum_read()
542 return -EINVAL; in iio_enum_read()
544 i = e->get(indio_dev, chan); in iio_enum_read()
547 if (i >= e->num_items || !e->items[i]) in iio_enum_read()
548 return -EINVAL; in iio_enum_read()
550 return sysfs_emit(buf, "%s\n", e->items[i]); in iio_enum_read()
561 if (!e->set) in iio_enum_write()
562 return -EINVAL; in iio_enum_write()
564 ret = __sysfs_match_string(e->items, e->num_items, buf); in iio_enum_write()
568 ret = e->set(indio_dev, chan, ret); in iio_enum_write()
602 mtx->rotation[0], mtx->rotation[1], mtx->rotation[2], in iio_show_mount_matrix()
603 mtx->rotation[3], mtx->rotation[4], mtx->rotation[5], in iio_show_mount_matrix()
604 mtx->rotation[6], mtx->rotation[7], mtx->rotation[8]); in iio_show_mount_matrix()
609 * iio_read_mount_matrix() - retrieve iio device mounting matrix from
610 * device "mount-matrix" property
624 err = device_property_read_string_array(dev, "mount-matrix", matrix->rotation, len); in iio_read_mount_matrix()
630 return -EINVAL; in iio_read_mount_matrix()
632 if (err != -EINVAL) in iio_read_mount_matrix()
656 return sysfs_emit_at(buf, offset, "-%d.%06u%s", in __iio_format_value()
657 abs(vals[0]), -vals[1], in __iio_format_value()
664 return sysfs_emit_at(buf, offset, "-%d.%09u", in __iio_format_value()
665 abs(vals[0]), -vals[1]); in __iio_format_value()
674 return sysfs_emit_at(buf, offset, "-0.%09u", abs(tmp1)); in __iio_format_value()
682 return sysfs_emit_at(buf, offset, "-0.%09u", abs(tmp1)); in __iio_format_value()
706 * iio_format_value() - Formats a IIO value into its string representation
724 if (len >= PAGE_SIZE - 1) in iio_format_value()
725 return -EFBIG; in iio_format_value()
738 if (indio_dev->info->read_label) in iio_read_channel_label()
739 return indio_dev->info->read_label(indio_dev, this_attr->c, buf); in iio_read_channel_label()
741 if (this_attr->c->extend_name) in iio_read_channel_label()
742 return sysfs_emit(buf, "%s\n", this_attr->c->extend_name); in iio_read_channel_label()
744 return -EINVAL; in iio_read_channel_label()
757 if (indio_dev->info->read_raw_multi) in iio_read_channel_info()
758 ret = indio_dev->info->read_raw_multi(indio_dev, this_attr->c, in iio_read_channel_info()
761 this_attr->address); in iio_read_channel_info()
763 ret = indio_dev->info->read_raw(indio_dev, this_attr->c, in iio_read_channel_info()
764 &vals[0], &vals[1], this_attr->address); in iio_read_channel_info()
790 for (i = 0; i <= length - stride; i += stride) { in iio_format_list()
794 return -EFBIG; in iio_format_list()
799 return -EFBIG; in iio_format_list()
846 ret = indio_dev->info->read_avail(indio_dev, this_attr->c, in iio_read_channel_info_avail()
848 this_attr->address); in iio_read_channel_info_avail()
858 return -EINVAL; in iio_read_channel_info_avail()
863 * __iio_str_to_fixpoint() - Parse a fixed-point number from a string
885 if (str[0] == '-') { in __iio_str_to_fixpoint()
895 i = i * 10 + *str - '0'; in __iio_str_to_fixpoint()
897 f += fract_mult * (*str - '0'); in __iio_str_to_fixpoint()
903 return -EINVAL; in __iio_str_to_fixpoint()
904 } else if (!strncmp(str, " dB", sizeof(" dB") - 1) && scale_db) { in __iio_str_to_fixpoint()
906 str += sizeof(" dB") - 1; in __iio_str_to_fixpoint()
908 } else if (!strncmp(str, "dB", sizeof("dB") - 1) && scale_db) { in __iio_str_to_fixpoint()
910 str += sizeof("dB") - 1; in __iio_str_to_fixpoint()
915 return -EINVAL; in __iio_str_to_fixpoint()
922 i = -i; in __iio_str_to_fixpoint()
924 f = -f; in __iio_str_to_fixpoint()
934 * iio_str_to_fixpoint() - Parse a fixed-point number from a string
962 /* Assumes decimal - precision based on number of digits */ in iio_write_channel_info()
963 if (!indio_dev->info->write_raw) in iio_write_channel_info()
964 return -EINVAL; in iio_write_channel_info()
966 if (indio_dev->info->write_raw_get_fmt) in iio_write_channel_info()
967 switch (indio_dev->info->write_raw_get_fmt(indio_dev, in iio_write_channel_info()
968 this_attr->c, this_attr->address)) { in iio_write_channel_info()
985 return -EINVAL; in iio_write_channel_info()
992 return -EINVAL; in iio_write_channel_info()
1001 ret = indio_dev->info->write_raw(indio_dev, this_attr->c, in iio_write_channel_info()
1002 integer, fract, this_attr->address); in iio_write_channel_info()
1026 sysfs_attr_init(&dev_attr->attr); in __iio_device_attr_init()
1029 if (chan->modified && (shared_by == IIO_SEPARATE)) { in __iio_device_attr_init()
1030 if (chan->extend_name) in __iio_device_attr_init()
1032 iio_modifier_names[chan->channel2], in __iio_device_attr_init()
1033 chan->extend_name, in __iio_device_attr_init()
1037 iio_modifier_names[chan->channel2], in __iio_device_attr_init()
1040 if (chan->extend_name == NULL || shared_by != IIO_SEPARATE) in __iio_device_attr_init()
1045 chan->extend_name, in __iio_device_attr_init()
1049 return -ENOMEM; in __iio_device_attr_init()
1051 if (chan->differential) { /* Differential can not have modifier */ in __iio_device_attr_init()
1058 iio_direction[chan->output], in __iio_device_attr_init()
1062 name = kasprintf(GFP_KERNEL, "%s_%s-%s_%s", in __iio_device_attr_init()
1063 iio_direction[chan->output], in __iio_device_attr_init()
1064 iio_chan_type_name_spec[chan->type], in __iio_device_attr_init()
1065 iio_chan_type_name_spec[chan->type], in __iio_device_attr_init()
1069 if (!chan->indexed) { in __iio_device_attr_init()
1071 ret = -EINVAL; in __iio_device_attr_init()
1075 "%s_%s%d-%s%d_%s", in __iio_device_attr_init()
1076 iio_direction[chan->output], in __iio_device_attr_init()
1077 iio_chan_type_name_spec[chan->type], in __iio_device_attr_init()
1078 chan->channel, in __iio_device_attr_init()
1079 iio_chan_type_name_spec[chan->type], in __iio_device_attr_init()
1080 chan->channel2, in __iio_device_attr_init()
1091 iio_direction[chan->output], in __iio_device_attr_init()
1096 iio_direction[chan->output], in __iio_device_attr_init()
1097 iio_chan_type_name_spec[chan->type], in __iio_device_attr_init()
1102 if (chan->indexed) in __iio_device_attr_init()
1104 iio_direction[chan->output], in __iio_device_attr_init()
1105 iio_chan_type_name_spec[chan->type], in __iio_device_attr_init()
1106 chan->channel, in __iio_device_attr_init()
1110 iio_direction[chan->output], in __iio_device_attr_init()
1111 iio_chan_type_name_spec[chan->type], in __iio_device_attr_init()
1117 ret = -ENOMEM; in __iio_device_attr_init()
1120 dev_attr->attr.name = name; in __iio_device_attr_init()
1123 dev_attr->attr.mode |= 0444; in __iio_device_attr_init()
1124 dev_attr->show = readfunc; in __iio_device_attr_init()
1128 dev_attr->attr.mode |= 0200; in __iio_device_attr_init()
1129 dev_attr->store = writefunc; in __iio_device_attr_init()
1140 kfree(dev_attr->attr.name); in __iio_device_attr_deinit()
1163 return -ENOMEM; in __iio_add_chan_devattr()
1164 ret = __iio_device_attr_init(&iio_attr->dev_attr, in __iio_add_chan_devattr()
1169 iio_attr->c = chan; in __iio_add_chan_devattr()
1170 iio_attr->address = mask; in __iio_add_chan_devattr()
1171 iio_attr->buffer = buffer; in __iio_add_chan_devattr()
1173 if (strcmp(t->dev_attr.attr.name, in __iio_add_chan_devattr()
1174 iio_attr->dev_attr.attr.name) == 0) { in __iio_add_chan_devattr()
1177 t->dev_attr.attr.name); in __iio_add_chan_devattr()
1178 ret = -EBUSY; in __iio_add_chan_devattr()
1181 list_add(&iio_attr->l, attr_list); in __iio_add_chan_devattr()
1186 __iio_device_attr_deinit(&iio_attr->dev_attr); in __iio_add_chan_devattr()
1198 if (!indio_dev->info->read_label && !chan->extend_name) in iio_device_add_channel_label()
1207 &indio_dev->dev, in iio_device_add_channel_label()
1209 &iio_dev_opaque->channel_attr_list); in iio_device_add_channel_label()
1226 return -EINVAL; in iio_device_add_info_mask_type()
1233 &indio_dev->dev, in iio_device_add_info_mask_type()
1235 &iio_dev_opaque->channel_attr_list); in iio_device_add_info_mask_type()
1236 if ((ret == -EBUSY) && (shared_by != IIO_SEPARATE)) in iio_device_add_info_mask_type()
1257 return -EINVAL; in iio_device_add_info_mask_type_avail()
1262 return -ENOMEM; in iio_device_add_info_mask_type_avail()
1270 &indio_dev->dev, in iio_device_add_info_mask_type_avail()
1272 &iio_dev_opaque->channel_attr_list); in iio_device_add_info_mask_type_avail()
1274 if ((ret == -EBUSY) && (shared_by != IIO_SEPARATE)) in iio_device_add_info_mask_type_avail()
1291 if (chan->channel < 0) in iio_device_add_channel_sysfs()
1295 &chan->info_mask_separate); in iio_device_add_channel_sysfs()
1302 &chan->info_mask_separate_available); in iio_device_add_channel_sysfs()
1309 &chan->info_mask_shared_by_type); in iio_device_add_channel_sysfs()
1316 &chan->info_mask_shared_by_type_available); in iio_device_add_channel_sysfs()
1323 &chan->info_mask_shared_by_dir); in iio_device_add_channel_sysfs()
1330 &chan->info_mask_shared_by_dir_available); in iio_device_add_channel_sysfs()
1337 &chan->info_mask_shared_by_all); in iio_device_add_channel_sysfs()
1344 &chan->info_mask_shared_by_all_available); in iio_device_add_channel_sysfs()
1354 if (chan->ext_info) { in iio_device_add_channel_sysfs()
1357 for (ext_info = chan->ext_info; ext_info->name; ext_info++) { in iio_device_add_channel_sysfs()
1358 ret = __iio_add_chan_devattr(ext_info->name, in iio_device_add_channel_sysfs()
1360 ext_info->read ? in iio_device_add_channel_sysfs()
1362 ext_info->write ? in iio_device_add_channel_sysfs()
1365 ext_info->shared, in iio_device_add_channel_sysfs()
1366 &indio_dev->dev, in iio_device_add_channel_sysfs()
1368 &iio_dev_opaque->channel_attr_list); in iio_device_add_channel_sysfs()
1370 if (ret == -EBUSY && ext_info->shared) in iio_device_add_channel_sysfs()
1384 * iio_free_chan_devattr_list() - Free a list of IIO device attributes
1395 kfree_const(p->dev_attr.attr.name); in iio_free_chan_devattr_list()
1396 list_del(&p->l); in iio_free_chan_devattr_list()
1406 return sysfs_emit(buf, "%s\n", indio_dev->name); in name_show()
1416 return sysfs_emit(buf, "%s\n", indio_dev->label); in label_show()
1481 return -EINVAL; in current_timestamp_clock_store()
1495 const struct attribute_group **new, **old = iio_dev_opaque->groups; in iio_device_register_sysfs_group()
1496 unsigned int cnt = iio_dev_opaque->groupcounter; in iio_device_register_sysfs_group()
1500 return -ENOMEM; in iio_device_register_sysfs_group()
1502 new[iio_dev_opaque->groupcounter++] = group; in iio_device_register_sysfs_group()
1503 new[iio_dev_opaque->groupcounter] = NULL; in iio_device_register_sysfs_group()
1505 iio_dev_opaque->groups = new; in iio_device_register_sysfs_group()
1520 if (indio_dev->info->attrs) { in iio_device_register_sysfs()
1521 attr = indio_dev->info->attrs->attrs; in iio_device_register_sysfs()
1527 * New channel registration method - relies on the fact a group does in iio_device_register_sysfs()
1530 if (indio_dev->channels) in iio_device_register_sysfs()
1531 for (i = 0; i < indio_dev->num_channels; i++) { in iio_device_register_sysfs()
1533 &indio_dev->channels[i]; in iio_device_register_sysfs()
1535 if (chan->type == IIO_TIMESTAMP) in iio_device_register_sysfs()
1544 if (iio_dev_opaque->event_interface) in iio_device_register_sysfs()
1547 if (indio_dev->name) in iio_device_register_sysfs()
1549 if (indio_dev->label) in iio_device_register_sysfs()
1554 iio_dev_opaque->chan_attr_group.attrs = in iio_device_register_sysfs()
1556 sizeof(iio_dev_opaque->chan_attr_group.attrs[0]), in iio_device_register_sysfs()
1558 if (iio_dev_opaque->chan_attr_group.attrs == NULL) { in iio_device_register_sysfs()
1559 ret = -ENOMEM; in iio_device_register_sysfs()
1563 if (indio_dev->info->attrs) { in iio_device_register_sysfs()
1564 memcpy(iio_dev_opaque->chan_attr_group.attrs, in iio_device_register_sysfs()
1565 indio_dev->info->attrs->attrs, in iio_device_register_sysfs()
1566 sizeof(iio_dev_opaque->chan_attr_group.attrs[0]) in iio_device_register_sysfs()
1568 iio_dev_opaque->chan_attr_group.is_visible = in iio_device_register_sysfs()
1569 indio_dev->info->attrs->is_visible; in iio_device_register_sysfs()
1570 iio_dev_opaque->chan_attr_group.bin_attrs = in iio_device_register_sysfs()
1571 indio_dev->info->attrs->bin_attrs; in iio_device_register_sysfs()
1575 list_for_each_entry(p, &iio_dev_opaque->channel_attr_list, l) in iio_device_register_sysfs()
1576 iio_dev_opaque->chan_attr_group.attrs[attrn++] = &p->dev_attr.attr; in iio_device_register_sysfs()
1577 if (indio_dev->name) in iio_device_register_sysfs()
1578 iio_dev_opaque->chan_attr_group.attrs[attrn++] = &dev_attr_name.attr; in iio_device_register_sysfs()
1579 if (indio_dev->label) in iio_device_register_sysfs()
1580 iio_dev_opaque->chan_attr_group.attrs[attrn++] = &dev_attr_label.attr; in iio_device_register_sysfs()
1582 iio_dev_opaque->chan_attr_group.attrs[attrn++] = clk; in iio_device_register_sysfs()
1585 &iio_dev_opaque->chan_attr_group); in iio_device_register_sysfs()
1592 kfree(iio_dev_opaque->chan_attr_group.attrs); in iio_device_register_sysfs()
1593 iio_dev_opaque->chan_attr_group.attrs = NULL; in iio_device_register_sysfs()
1595 iio_free_chan_devattr_list(&iio_dev_opaque->channel_attr_list); in iio_device_register_sysfs()
1604 iio_free_chan_devattr_list(&iio_dev_opaque->channel_attr_list); in iio_device_unregister_sysfs()
1605 kfree(iio_dev_opaque->chan_attr_group.attrs); in iio_device_unregister_sysfs()
1606 iio_dev_opaque->chan_attr_group.attrs = NULL; in iio_device_unregister_sysfs()
1607 kfree(iio_dev_opaque->groups); in iio_device_unregister_sysfs()
1608 iio_dev_opaque->groups = NULL; in iio_device_unregister_sysfs()
1616 if (indio_dev->modes & INDIO_ALL_TRIGGERED_MODES) in iio_dev_release()
1623 lockdep_unregister_key(&iio_dev_opaque->mlock_key); in iio_dev_release()
1625 ida_free(&iio_ida, iio_dev_opaque->id); in iio_dev_release()
1635 * iio_device_alloc() - allocate an iio_dev from a driver
1658 indio_dev = &iio_dev_opaque->indio_dev; in iio_device_alloc()
1659 indio_dev->priv = (char *)iio_dev_opaque + in iio_device_alloc()
1662 indio_dev->dev.parent = parent; in iio_device_alloc()
1663 indio_dev->dev.type = &iio_device_type; in iio_device_alloc()
1664 indio_dev->dev.bus = &iio_bus_type; in iio_device_alloc()
1665 device_initialize(&indio_dev->dev); in iio_device_alloc()
1666 mutex_init(&iio_dev_opaque->mlock); in iio_device_alloc()
1667 mutex_init(&iio_dev_opaque->info_exist_lock); in iio_device_alloc()
1668 INIT_LIST_HEAD(&iio_dev_opaque->channel_attr_list); in iio_device_alloc()
1670 iio_dev_opaque->id = ida_alloc(&iio_ida, GFP_KERNEL); in iio_device_alloc()
1671 if (iio_dev_opaque->id < 0) { in iio_device_alloc()
1678 if (dev_set_name(&indio_dev->dev, "iio:device%d", iio_dev_opaque->id)) { in iio_device_alloc()
1679 ida_free(&iio_ida, iio_dev_opaque->id); in iio_device_alloc()
1684 INIT_LIST_HEAD(&iio_dev_opaque->buffer_list); in iio_device_alloc()
1685 INIT_LIST_HEAD(&iio_dev_opaque->ioctl_handlers); in iio_device_alloc()
1687 lockdep_register_key(&iio_dev_opaque->mlock_key); in iio_device_alloc()
1688 lockdep_set_class(&iio_dev_opaque->mlock, &iio_dev_opaque->mlock_key); in iio_device_alloc()
1695 * iio_device_free() - free an iio_dev from a driver
1701 put_device(&dev->dev); in iio_device_free()
1711 * devm_iio_device_alloc - Resource-managed iio_device_alloc()
1740 * iio_chrdev_open() - chrdev file open for buffer access and ioctls
1745 * Returns: 0 on success or -EBUSY if the device is already opened
1750 container_of(inode->i_cdev, struct iio_dev_opaque, chrdev); in iio_chrdev_open()
1751 struct iio_dev *indio_dev = &iio_dev_opaque->indio_dev; in iio_chrdev_open()
1754 if (test_and_set_bit(IIO_BUSY_BIT_POS, &iio_dev_opaque->flags)) in iio_chrdev_open()
1755 return -EBUSY; in iio_chrdev_open()
1762 clear_bit(IIO_BUSY_BIT_POS, &iio_dev_opaque->flags); in iio_chrdev_open()
1763 return -ENOMEM; in iio_chrdev_open()
1766 ib->indio_dev = indio_dev; in iio_chrdev_open()
1767 ib->buffer = indio_dev->buffer; in iio_chrdev_open()
1769 filp->private_data = ib; in iio_chrdev_open()
1775 * iio_chrdev_release() - chrdev file close buffer access and ioctls
1783 struct iio_dev_buffer_pair *ib = filp->private_data; in iio_chrdev_release()
1785 container_of(inode->i_cdev, struct iio_dev_opaque, chrdev); in iio_chrdev_release()
1786 struct iio_dev *indio_dev = &iio_dev_opaque->indio_dev; in iio_chrdev_release()
1789 clear_bit(IIO_BUSY_BIT_POS, &iio_dev_opaque->flags); in iio_chrdev_release()
1800 list_add_tail(&h->entry, &iio_dev_opaque->ioctl_handlers); in iio_device_ioctl_handler_register()
1805 list_del(&h->entry); in iio_device_ioctl_handler_unregister()
1810 struct iio_dev_buffer_pair *ib = filp->private_data; in iio_ioctl()
1811 struct iio_dev *indio_dev = ib->indio_dev; in iio_ioctl()
1814 int ret = -ENODEV; in iio_ioctl()
1816 mutex_lock(&iio_dev_opaque->info_exist_lock); in iio_ioctl()
1823 if (!indio_dev->info) in iio_ioctl()
1826 list_for_each_entry(h, &iio_dev_opaque->ioctl_handlers, entry) { in iio_ioctl()
1827 ret = h->ioctl(indio_dev, filp, cmd, arg); in iio_ioctl()
1833 ret = -ENODEV; in iio_ioctl()
1836 mutex_unlock(&iio_dev_opaque->info_exist_lock); in iio_ioctl()
1865 const struct iio_chan_spec *channels = indio_dev->channels; in iio_check_unique_scan_index()
1867 if (!(indio_dev->modes & INDIO_ALL_BUFFER_MODES)) in iio_check_unique_scan_index()
1870 for (i = 0; i < indio_dev->num_channels - 1; i++) { in iio_check_unique_scan_index()
1873 for (j = i + 1; j < indio_dev->num_channels; j++) in iio_check_unique_scan_index()
1875 dev_err(&indio_dev->dev, in iio_check_unique_scan_index()
1878 return -EINVAL; in iio_check_unique_scan_index()
1889 if (!indio_dev->info->read_label) in iio_check_extended_name()
1892 for (i = 0; i < indio_dev->num_channels; i++) { in iio_check_extended_name()
1893 if (indio_dev->channels[i].extend_name) { in iio_check_extended_name()
1894 dev_err(&indio_dev->dev, in iio_check_extended_name()
1896 return -EINVAL; in iio_check_extended_name()
1911 av_masks = indio_dev->available_scan_masks; in iio_sanity_check_avail_scan_masks()
1912 masklength = indio_dev->masklength; in iio_sanity_check_avail_scan_masks()
1925 dev_warn(indio_dev->dev.parent, in iio_sanity_check_avail_scan_masks()
1929 dev_warn(indio_dev->dev.parent, "empty scan mask\n"); in iio_sanity_check_avail_scan_masks()
1937 av_masks = indio_dev->available_scan_masks; in iio_sanity_check_avail_scan_masks()
1948 for (i = 0; i < num_masks - 1; i++) { in iio_sanity_check_avail_scan_masks()
1958 dev_warn(indio_dev->dev.parent, in iio_sanity_check_avail_scan_masks()
1971 if (!indio_dev->info) in __iio_device_register()
1972 return -EINVAL; in __iio_device_register()
1974 iio_dev_opaque->driver_module = this_mod; in __iio_device_register()
1977 if (dev_fwnode(&indio_dev->dev)) in __iio_device_register()
1978 fwnode = dev_fwnode(&indio_dev->dev); in __iio_device_register()
1980 else if (indio_dev->dev.parent) in __iio_device_register()
1981 fwnode = dev_fwnode(indio_dev->dev.parent); in __iio_device_register()
1982 device_set_node(&indio_dev->dev, fwnode); in __iio_device_register()
1984 fwnode_property_read_string(fwnode, "label", &indio_dev->label); in __iio_device_register()
1998 dev_err(indio_dev->dev.parent, in __iio_device_register()
2003 if (indio_dev->available_scan_masks) in __iio_device_register()
2008 dev_err(indio_dev->dev.parent, in __iio_device_register()
2014 dev_err(indio_dev->dev.parent, in __iio_device_register()
2018 if (indio_dev->modes & INDIO_ALL_TRIGGERED_MODES) in __iio_device_register()
2021 if ((indio_dev->modes & INDIO_ALL_BUFFER_MODES) && in __iio_device_register()
2022 indio_dev->setup_ops == NULL) in __iio_device_register()
2023 indio_dev->setup_ops = &noop_ring_setup_ops; in __iio_device_register()
2025 if (iio_dev_opaque->attached_buffers_cnt) in __iio_device_register()
2026 cdev_init(&iio_dev_opaque->chrdev, &iio_buffer_fileops); in __iio_device_register()
2027 else if (iio_dev_opaque->event_interface) in __iio_device_register()
2028 cdev_init(&iio_dev_opaque->chrdev, &iio_event_fileops); in __iio_device_register()
2030 if (iio_dev_opaque->attached_buffers_cnt || iio_dev_opaque->event_interface) { in __iio_device_register()
2031 indio_dev->dev.devt = MKDEV(MAJOR(iio_devt), iio_dev_opaque->id); in __iio_device_register()
2032 iio_dev_opaque->chrdev.owner = this_mod; in __iio_device_register()
2036 indio_dev->dev.groups = iio_dev_opaque->groups; in __iio_device_register()
2038 ret = cdev_device_add(&iio_dev_opaque->chrdev, &indio_dev->dev); in __iio_device_register()
2057 * iio_device_unregister() - unregister a device from the IIO subsystem
2064 cdev_device_del(&iio_dev_opaque->chrdev, &indio_dev->dev); in iio_device_unregister()
2066 mutex_lock(&iio_dev_opaque->info_exist_lock); in iio_device_unregister()
2072 indio_dev->info = NULL; in iio_device_unregister()
2077 mutex_unlock(&iio_dev_opaque->info_exist_lock); in iio_device_unregister()
2102 * iio_device_claim_direct_mode - Keep device in direct mode
2110 * Returns: 0 on success, -EBUSY on failure.
2116 mutex_lock(&iio_dev_opaque->mlock); in iio_device_claim_direct_mode()
2119 mutex_unlock(&iio_dev_opaque->mlock); in iio_device_claim_direct_mode()
2120 return -EBUSY; in iio_device_claim_direct_mode()
2127 * iio_device_release_direct_mode - releases claim on direct mode
2137 mutex_unlock(&to_iio_dev_opaque(indio_dev)->mlock); in iio_device_release_direct_mode()
2142 * iio_device_claim_buffer_mode - Keep device in buffer mode
2150 * Returns: 0 on success, -EBUSY on failure.
2156 mutex_lock(&iio_dev_opaque->mlock); in iio_device_claim_buffer_mode()
2161 mutex_unlock(&iio_dev_opaque->mlock); in iio_device_claim_buffer_mode()
2162 return -EBUSY; in iio_device_claim_buffer_mode()
2167 * iio_device_release_buffer_mode - releases claim on buffer mode
2177 mutex_unlock(&to_iio_dev_opaque(indio_dev)->mlock); in iio_device_release_buffer_mode()
2182 * iio_device_get_current_mode() - helper function providing read-only access to
2190 return iio_dev_opaque->currentmode; in iio_device_get_current_mode()