Lines Matching +full:iio +full:- +full:backend
1 // SPDX-License-Identifier: GPL-2.0-only
3 * Framework to handle complex IIO aggregate devices.
6 * can be "linked" against one or multiple backend devices. All the IIO and
11 * -------------------------------------------------------
12 * ------------------ | ------------ ------------ ------- FPGA|
13 * | ADC |------------------------| | ADC CORE |---------| DMA CORE |------| RAM | |
14 * | (Frontend/IIO) | Serial Data (eg: LVDS) | |(backend) |---------| |------| | |
15 * | |------------------------| ------------ ------------ ------- |
16 * ------------------ -------------------------------------------------------
19 * - Backends should register themselves with devm_iio_backend_register()
20 * - Frontend devices should get backends with devm_iio_backend_get()
24 * devices. On top of that, this is "generic" for all IIO which means any kind
27 * the industrialio-backend.c is only left with the really generic stuff. Then,
30 * Copyright (C) 2023-2024 Analog Devices Inc.
32 #define dev_fmt(fmt) "iio-backend: " fmt
47 #include <linux/iio/backend.h>
48 #include <linux/iio/iio.h>
62 * backend. Used for the debugfs directory name.
80 * Helper macros to call backend ops. Makes sure the option is supported.
86 if (!____back->ops->op) \
87 ____ret = -EOPNOTSUPP; \
98 __ret = __back->ops->op(__back, ##args); \
112 ptr_err = __back->ops->op(__back, ##args); \
123 __back->ops->op(__back, ##args); \
125 dev_dbg(__back->dev, "Op(%s) not implemented\n",\
133 struct iio_backend *back = file->private_data; in iio_backend_debugfs_read_reg()
139 back->cached_reg_addr, 0, &val); in iio_backend_debugfs_read_reg()
152 struct iio_backend *back = file->private_data; in iio_backend_debugfs_write_reg()
158 rc = simple_write_to_buffer(buf, sizeof(buf) - 1, ppos, userbuf, count); in iio_backend_debugfs_write_reg()
164 ret = sscanf(buf, "%i %i", &back->cached_reg_addr, &val); in iio_backend_debugfs_write_reg()
171 back->cached_reg_addr, val, NULL); in iio_backend_debugfs_write_reg()
176 return -EINVAL; in iio_backend_debugfs_write_reg()
190 struct iio_backend *back = file->private_data; in iio_backend_debugfs_read_name()
194 len = scnprintf(name, sizeof(name), "%s\n", back->name); in iio_backend_debugfs_read_name()
205 * iio_backend_debugfs_add - Add debugfs interfaces for Backends
206 * @back: Backend device
207 * @indio_dev: IIO device
218 if (!back->ops->debugfs_reg_access && !back->name) in iio_backend_debugfs_add()
221 snprintf(name, sizeof(name), "backend%d", back->idx); in iio_backend_debugfs_add()
227 if (back->ops->debugfs_reg_access) in iio_backend_debugfs_add()
231 if (back->name) in iio_backend_debugfs_add()
238 * iio_backend_debugfs_print_chan_status - Print channel status
239 * @back: Backend device
245 * interface and "ask" the backend to dump more details on why a test tone might
256 return -ENODEV; in iio_backend_debugfs_print_chan_status()
264 * iio_backend_chan_enable - Enable a backend channel
265 * @back: Backend device
278 * iio_backend_chan_disable - Disable a backend channel
279 * @back: Backend device
297 * iio_backend_disable - Backend disable
298 * @back: Backend device
307 * iio_backend_enable - Backend enable
308 * @back: Backend device
320 * devm_iio_backend_enable - Device managed backend enable
321 * @dev: Consumer device for the backend
322 * @back: Backend device
340 * iio_backend_data_format_set - Configure the channel data format
341 * @back: Backend device
354 if (!data || data->type >= IIO_BACKEND_DATA_TYPE_MAX) in iio_backend_data_format_set()
355 return -EINVAL; in iio_backend_data_format_set()
362 * iio_backend_data_source_set - Select data source
363 * @back: Backend device
367 * A given backend may have different sources to stream/sync data. This allows
377 return -EINVAL; in iio_backend_data_source_set()
384 * iio_backend_set_sampling_freq - Set channel sampling rate
385 * @back: Backend device
400 * iio_backend_test_pattern_set - Configure a test pattern
401 * @back: Backend device
405 * Configure a test pattern on the backend. This is typically used for
416 return -EINVAL; in iio_backend_test_pattern_set()
423 * iio_backend_chan_status - Get the channel status
424 * @back: Backend device
428 * Get the current state of the backend channel. Typically used to check if
442 * iio_backend_iodelay_set - Set digital I/O delay
443 * @back: Backend device
450 * is very backend specific. Hence, frontend devices typically should go through
465 * iio_backend_data_sample_trigger - Control when to sample data
466 * @back: Backend device
469 * Mostly useful for input backends. Configures the backend for when to sample
479 return -EINVAL; in iio_backend_data_sample_trigger()
489 iio_backend_void_op_call(pair->back, free_buffer, pair->buffer); in iio_backend_free_buffer()
493 * devm_iio_backend_request_buffer - Device managed buffer request
494 * @dev: Consumer device for the backend
495 * @back: Backend device
496 * @indio_dev: IIO device
498 * Request an IIO buffer from the backend. The type of the buffer (typically
499 * INDIO_BUFFER_HARDWARE) is up to the backend to decide. This is because,
500 * normally, the backend dictates what kind of buffering we can get.
502 * The backend .free_buffer() hooks is automatically called on @dev detach.
516 return -ENOMEM; in devm_iio_backend_request_buffer()
523 pair->back = back; in devm_iio_backend_request_buffer()
524 pair->buffer = buffer; in devm_iio_backend_request_buffer()
531 * iio_backend_read_raw - Read a channel attribute from a backend device.
532 * @back: Backend device
533 * @chan: IIO channel reference
551 struct iio_backend *back = ERR_PTR(-ENODEV), *iter; in iio_backend_from_indio_dev_parent()
556 * than one backend in which case returning the first we find is bogus. in iio_backend_from_indio_dev_parent()
562 if (dev == iter->frontend_dev) { in iio_backend_from_indio_dev_parent()
566 return ERR_PTR(-ENODEV); in iio_backend_from_indio_dev_parent()
577 * iio_backend_ext_info_get - IIO ext_info read callback
578 * @indio_dev: IIO device
580 * @chan: IIO channel
583 * This helper is intended to be used by backends that extend an IIO channel
586 * a way to get the backend from indio_dev). This is the getter.
600 * backend from the frontend. Anyways, let's only introduce new options in iio_backend_ext_info_get()
603 back = iio_backend_from_indio_dev_parent(indio_dev->dev.parent); in iio_backend_ext_info_get()
612 * iio_backend_ext_info_set - IIO ext_info write callback
613 * @indio_dev: IIO device
615 * @chan: IIO channel
619 * This helper is intended to be used by backends that extend an IIO channel
622 * a way to get the backend from indio_dev). This is the setter.
633 back = iio_backend_from_indio_dev_parent(indio_dev->dev.parent); in iio_backend_ext_info_set()
642 * iio_backend_extend_chan_spec - Extend an IIO channel
643 * @back: Backend device
644 * @chan: IIO channel
655 const struct iio_chan_spec_ext_info *frontend_ext_info = chan->ext_info; in iio_backend_extend_chan_spec()
667 if (frontend_ext_info && chan->ext_info != frontend_ext_info) in iio_backend_extend_chan_spec()
668 return -EOPNOTSUPP; in iio_backend_extend_chan_spec()
669 if (!chan->ext_info) in iio_backend_extend_chan_spec()
673 for (back_ext_info = chan->ext_info; back_ext_info->name; back_ext_info++) { in iio_backend_extend_chan_spec()
674 if (back_ext_info->read != iio_backend_ext_info_get) in iio_backend_extend_chan_spec()
675 return -EINVAL; in iio_backend_extend_chan_spec()
676 if (back_ext_info->write != iio_backend_ext_info_set) in iio_backend_extend_chan_spec()
677 return -EINVAL; in iio_backend_extend_chan_spec()
688 module_put(back->owner); in iio_backend_release()
702 if (!try_module_get(back->owner)) in __devm_iio_backend_get()
703 return dev_err_probe(dev, -ENODEV, in __devm_iio_backend_get()
710 link = device_link_add(dev, back->dev, DL_FLAG_AUTOREMOVE_CONSUMER); in __devm_iio_backend_get()
712 return dev_err_probe(dev, -EINVAL, in __devm_iio_backend_get()
714 dev_name(back->dev)); in __devm_iio_backend_get()
716 back->frontend_dev = dev; in __devm_iio_backend_get()
718 dev_dbg(dev, "Found backend(%s) device\n", dev_name(back->dev)); in __devm_iio_backend_get()
724 * iio_backend_ddr_enable - Enable interface DDR (Double Data Rate) mode
725 * @back: Backend device
740 * iio_backend_ddr_disable - Disable interface DDR (Double Data Rate) mode
741 * @back: Backend device
755 * iio_backend_data_stream_enable - Enable data stream
756 * @back: Backend device
770 * iio_backend_data_stream_disable - Disable data stream
771 * @back: Backend device
785 * iio_backend_data_transfer_addr - Set data address.
786 * @back: Backend device
789 * Some devices may need to inform the backend about an address
810 ret = device_property_match_string(dev, "io-backend-names", in __devm_iio_backend_fwnode_get()
819 fwnode_back = fwnode_find_reference(fwnode, "io-backends", index); in __devm_iio_backend_fwnode_get()
826 if (!device_match_fwnode(back->dev, fwnode_back)) in __devm_iio_backend_fwnode_get()
835 back->idx = index; in __devm_iio_backend_fwnode_get()
841 return ERR_PTR(-EPROBE_DEFER); in __devm_iio_backend_fwnode_get()
845 * devm_iio_backend_get - Device managed backend device get
846 * @dev: Consumer device for the backend
847 * @name: Backend name
849 * Get's the backend associated with @dev.
852 * A backend pointer, negative error pointer otherwise.
861 * devm_iio_backend_fwnode_get - Device managed backend firmware node get
862 * @dev: Consumer device for the backend
863 * @name: Backend name
864 * @fwnode: Firmware node of the backend consumer
866 * Get's the backend associated with a firmware node.
869 * A backend pointer, negative error pointer otherwise.
880 * __devm_iio_backend_get_from_fwnode_lookup - Device managed fwnode backend device get
881 * @dev: Consumer device for the backend
882 * @fwnode: Firmware node of the backend device
884 * Search the backend list for a device matching @fwnode.
889 * A backend pointer, negative error pointer otherwise.
900 if (!device_match_fwnode(back->dev, fwnode)) in __devm_iio_backend_get_from_fwnode_lookup()
910 return ERR_PTR(-EPROBE_DEFER); in __devm_iio_backend_get_from_fwnode_lookup()
915 * iio_backend_get_priv - Get driver private data
916 * @back: Backend device
920 return back->priv; in iio_backend_get_priv()
929 list_del(&back->entry); in iio_backend_unregister()
933 * devm_iio_backend_register - Device managed backend device register
934 * @dev: Backend device being registered
935 * @info: Backend info
938 * @info is mandatory. Not providing it results in -EINVAL.
948 if (!info || !info->ops) in devm_iio_backend_register()
949 return dev_err_probe(dev, -EINVAL, "No backend ops given\n"); in devm_iio_backend_register()
953 * bound/exist if the backend driver is not around. Hence, we can bind in devm_iio_backend_register()
954 * the backend object lifetime with the device being passed since in devm_iio_backend_register()
959 return -ENOMEM; in devm_iio_backend_register()
961 back->ops = info->ops; in devm_iio_backend_register()
962 back->name = info->name; in devm_iio_backend_register()
963 back->owner = dev->driver->owner; in devm_iio_backend_register()
964 back->dev = dev; in devm_iio_backend_register()
965 back->priv = priv; in devm_iio_backend_register()
967 list_add(&back->entry, &iio_back_list); in devm_iio_backend_register()
974 MODULE_DESCRIPTION("Framework to handle complex IIO aggregate devices");