![]() |
|
|||
0001 /* SPDX-License-Identifier: GPL-2.0-only */ 0002 0003 /* The industrial I/O core 0004 * 0005 * Copyright (c) 2008 Jonathan Cameron 0006 */ 0007 #ifndef _INDUSTRIAL_IO_H_ 0008 #define _INDUSTRIAL_IO_H_ 0009 0010 #include <linux/device.h> 0011 #include <linux/cdev.h> 0012 #include <linux/slab.h> 0013 #include <linux/iio/types.h> 0014 /* IIO TODO LIST */ 0015 /* 0016 * Provide means of adjusting timer accuracy. 0017 * Currently assumes nano seconds. 0018 */ 0019 0020 struct of_phandle_args; 0021 0022 enum iio_shared_by { 0023 IIO_SEPARATE, 0024 IIO_SHARED_BY_TYPE, 0025 IIO_SHARED_BY_DIR, 0026 IIO_SHARED_BY_ALL 0027 }; 0028 0029 enum iio_endian { 0030 IIO_CPU, 0031 IIO_BE, 0032 IIO_LE, 0033 }; 0034 0035 struct iio_chan_spec; 0036 struct iio_dev; 0037 0038 /** 0039 * struct iio_chan_spec_ext_info - Extended channel info attribute 0040 * @name: Info attribute name 0041 * @shared: Whether this attribute is shared between all channels. 0042 * @read: Read callback for this info attribute, may be NULL. 0043 * @write: Write callback for this info attribute, may be NULL. 0044 * @private: Data private to the driver. 0045 */ 0046 struct iio_chan_spec_ext_info { 0047 const char *name; 0048 enum iio_shared_by shared; 0049 ssize_t (*read)(struct iio_dev *, uintptr_t private, 0050 struct iio_chan_spec const *, char *buf); 0051 ssize_t (*write)(struct iio_dev *, uintptr_t private, 0052 struct iio_chan_spec const *, const char *buf, 0053 size_t len); 0054 uintptr_t private; 0055 }; 0056 0057 /** 0058 * struct iio_enum - Enum channel info attribute 0059 * @items: An array of strings. 0060 * @num_items: Length of the item array. 0061 * @set: Set callback function, may be NULL. 0062 * @get: Get callback function, may be NULL. 0063 * 0064 * The iio_enum struct can be used to implement enum style channel attributes. 0065 * Enum style attributes are those which have a set of strings which map to 0066 * unsigned integer values. The IIO enum helper code takes care of mapping 0067 * between value and string as well as generating a "_available" file which 0068 * contains a list of all available items. The set callback will be called when 0069 * the attribute is updated. The last parameter is the index to the newly 0070 * activated item. The get callback will be used to query the currently active 0071 * item and is supposed to return the index for it. 0072 */ 0073 struct iio_enum { 0074 const char * const *items; 0075 unsigned int num_items; 0076 int (*set)(struct iio_dev *, const struct iio_chan_spec *, unsigned int); 0077 int (*get)(struct iio_dev *, const struct iio_chan_spec *); 0078 }; 0079 0080 ssize_t iio_enum_available_read(struct iio_dev *indio_dev, 0081 uintptr_t priv, const struct iio_chan_spec *chan, char *buf); 0082 ssize_t iio_enum_read(struct iio_dev *indio_dev, 0083 uintptr_t priv, const struct iio_chan_spec *chan, char *buf); 0084 ssize_t iio_enum_write(struct iio_dev *indio_dev, 0085 uintptr_t priv, const struct iio_chan_spec *chan, const char *buf, 0086 size_t len); 0087 0088 /** 0089 * IIO_ENUM() - Initialize enum extended channel attribute 0090 * @_name: Attribute name 0091 * @_shared: Whether the attribute is shared between all channels 0092 * @_e: Pointer to an iio_enum struct 0093 * 0094 * This should usually be used together with IIO_ENUM_AVAILABLE() 0095 */ 0096 #define IIO_ENUM(_name, _shared, _e) \ 0097 { \ 0098 .name = (_name), \ 0099 .shared = (_shared), \ 0100 .read = iio_enum_read, \ 0101 .write = iio_enum_write, \ 0102 .private = (uintptr_t)(_e), \ 0103 } 0104 0105 /** 0106 * IIO_ENUM_AVAILABLE() - Initialize enum available extended channel attribute 0107 * @_name: Attribute name ("_available" will be appended to the name) 0108 * @_shared: Whether the attribute is shared between all channels 0109 * @_e: Pointer to an iio_enum struct 0110 * 0111 * Creates a read only attribute which lists all the available enum items in a 0112 * space separated list. This should usually be used together with IIO_ENUM() 0113 */ 0114 #define IIO_ENUM_AVAILABLE(_name, _shared, _e) \ 0115 { \ 0116 .name = (_name "_available"), \ 0117 .shared = _shared, \ 0118 .read = iio_enum_available_read, \ 0119 .private = (uintptr_t)(_e), \ 0120 } 0121 0122 /** 0123 * struct iio_mount_matrix - iio mounting matrix 0124 * @rotation: 3 dimensional space rotation matrix defining sensor alignment with 0125 * main hardware 0126 */ 0127 struct iio_mount_matrix { 0128 const char *rotation[9]; 0129 }; 0130 0131 ssize_t iio_show_mount_matrix(struct iio_dev *indio_dev, uintptr_t priv, 0132 const struct iio_chan_spec *chan, char *buf); 0133 int iio_read_mount_matrix(struct device *dev, struct iio_mount_matrix *matrix); 0134 0135 typedef const struct iio_mount_matrix * 0136 (iio_get_mount_matrix_t)(const struct iio_dev *indio_dev, 0137 const struct iio_chan_spec *chan); 0138 0139 /** 0140 * IIO_MOUNT_MATRIX() - Initialize mount matrix extended channel attribute 0141 * @_shared: Whether the attribute is shared between all channels 0142 * @_get: Pointer to an iio_get_mount_matrix_t accessor 0143 */ 0144 #define IIO_MOUNT_MATRIX(_shared, _get) \ 0145 { \ 0146 .name = "mount_matrix", \ 0147 .shared = (_shared), \ 0148 .read = iio_show_mount_matrix, \ 0149 .private = (uintptr_t)(_get), \ 0150 } 0151 0152 /** 0153 * struct iio_event_spec - specification for a channel event 0154 * @type: Type of the event 0155 * @dir: Direction of the event 0156 * @mask_separate: Bit mask of enum iio_event_info values. Attributes 0157 * set in this mask will be registered per channel. 0158 * @mask_shared_by_type: Bit mask of enum iio_event_info values. Attributes 0159 * set in this mask will be shared by channel type. 0160 * @mask_shared_by_dir: Bit mask of enum iio_event_info values. Attributes 0161 * set in this mask will be shared by channel type and 0162 * direction. 0163 * @mask_shared_by_all: Bit mask of enum iio_event_info values. Attributes 0164 * set in this mask will be shared by all channels. 0165 */ 0166 struct iio_event_spec { 0167 enum iio_event_type type; 0168 enum iio_event_direction dir; 0169 unsigned long mask_separate; 0170 unsigned long mask_shared_by_type; 0171 unsigned long mask_shared_by_dir; 0172 unsigned long mask_shared_by_all; 0173 }; 0174 0175 /** 0176 * struct iio_chan_spec - specification of a single channel 0177 * @type: What type of measurement is the channel making. 0178 * @channel: What number do we wish to assign the channel. 0179 * @channel2: If there is a second number for a differential 0180 * channel then this is it. If modified is set then the 0181 * value here specifies the modifier. 0182 * @address: Driver specific identifier. 0183 * @scan_index: Monotonic index to give ordering in scans when read 0184 * from a buffer. 0185 * @scan_type: struct describing the scan type 0186 * @scan_type.sign: 's' or 'u' to specify signed or unsigned 0187 * @scan_type.realbits: Number of valid bits of data 0188 * @scan_type.storagebits: Realbits + padding 0189 * @scan_type.shift: Shift right by this before masking out 0190 * realbits. 0191 * @scan_type.repeat: Number of times real/storage bits repeats. 0192 * When the repeat element is more than 1, then 0193 * the type element in sysfs will show a repeat 0194 * value. Otherwise, the number of repetitions 0195 * is omitted. 0196 * @scan_type.endianness: little or big endian 0197 * @info_mask_separate: What information is to be exported that is specific to 0198 * this channel. 0199 * @info_mask_separate_available: What availability information is to be 0200 * exported that is specific to this channel. 0201 * @info_mask_shared_by_type: What information is to be exported that is shared 0202 * by all channels of the same type. 0203 * @info_mask_shared_by_type_available: What availability information is to be 0204 * exported that is shared by all channels of the same 0205 * type. 0206 * @info_mask_shared_by_dir: What information is to be exported that is shared 0207 * by all channels of the same direction. 0208 * @info_mask_shared_by_dir_available: What availability information is to be 0209 * exported that is shared by all channels of the same 0210 * direction. 0211 * @info_mask_shared_by_all: What information is to be exported that is shared 0212 * by all channels. 0213 * @info_mask_shared_by_all_available: What availability information is to be 0214 * exported that is shared by all channels. 0215 * @event_spec: Array of events which should be registered for this 0216 * channel. 0217 * @num_event_specs: Size of the event_spec array. 0218 * @ext_info: Array of extended info attributes for this channel. 0219 * The array is NULL terminated, the last element should 0220 * have its name field set to NULL. 0221 * @extend_name: Allows labeling of channel attributes with an 0222 * informative name. Note this has no effect codes etc, 0223 * unlike modifiers. 0224 * @datasheet_name: A name used in in-kernel mapping of channels. It should 0225 * correspond to the first name that the channel is referred 0226 * to by in the datasheet (e.g. IND), or the nearest 0227 * possible compound name (e.g. IND-INC). 0228 * @modified: Does a modifier apply to this channel. What these are 0229 * depends on the channel type. Modifier is set in 0230 * channel2. Examples are IIO_MOD_X for axial sensors about 0231 * the 'x' axis. 0232 * @indexed: Specify the channel has a numerical index. If not, 0233 * the channel index number will be suppressed for sysfs 0234 * attributes but not for event codes. 0235 * @output: Channel is output. 0236 * @differential: Channel is differential. 0237 */ 0238 struct iio_chan_spec { 0239 enum iio_chan_type type; 0240 int channel; 0241 int channel2; 0242 unsigned long address; 0243 int scan_index; 0244 struct { 0245 char sign; 0246 u8 realbits; 0247 u8 storagebits; 0248 u8 shift; 0249 u8 repeat; 0250 enum iio_endian endianness; 0251 } scan_type; 0252 long info_mask_separate; 0253 long info_mask_separate_available; 0254 long info_mask_shared_by_type; 0255 long info_mask_shared_by_type_available; 0256 long info_mask_shared_by_dir; 0257 long info_mask_shared_by_dir_available; 0258 long info_mask_shared_by_all; 0259 long info_mask_shared_by_all_available; 0260 const struct iio_event_spec *event_spec; 0261 unsigned int num_event_specs; 0262 const struct iio_chan_spec_ext_info *ext_info; 0263 const char *extend_name; 0264 const char *datasheet_name; 0265 unsigned modified:1; 0266 unsigned indexed:1; 0267 unsigned output:1; 0268 unsigned differential:1; 0269 }; 0270 0271 0272 /** 0273 * iio_channel_has_info() - Checks whether a channel supports a info attribute 0274 * @chan: The channel to be queried 0275 * @type: Type of the info attribute to be checked 0276 * 0277 * Returns true if the channels supports reporting values for the given info 0278 * attribute type, false otherwise. 0279 */ 0280 static inline bool iio_channel_has_info(const struct iio_chan_spec *chan, 0281 enum iio_chan_info_enum type) 0282 { 0283 return (chan->info_mask_separate & BIT(type)) | 0284 (chan->info_mask_shared_by_type & BIT(type)) | 0285 (chan->info_mask_shared_by_dir & BIT(type)) | 0286 (chan->info_mask_shared_by_all & BIT(type)); 0287 } 0288 0289 /** 0290 * iio_channel_has_available() - Checks if a channel has an available attribute 0291 * @chan: The channel to be queried 0292 * @type: Type of the available attribute to be checked 0293 * 0294 * Returns true if the channel supports reporting available values for the 0295 * given attribute type, false otherwise. 0296 */ 0297 static inline bool iio_channel_has_available(const struct iio_chan_spec *chan, 0298 enum iio_chan_info_enum type) 0299 { 0300 return (chan->info_mask_separate_available & BIT(type)) | 0301 (chan->info_mask_shared_by_type_available & BIT(type)) | 0302 (chan->info_mask_shared_by_dir_available & BIT(type)) | 0303 (chan->info_mask_shared_by_all_available & BIT(type)); 0304 } 0305 0306 #define IIO_CHAN_SOFT_TIMESTAMP(_si) { \ 0307 .type = IIO_TIMESTAMP, \ 0308 .channel = -1, \ 0309 .scan_index = _si, \ 0310 .scan_type = { \ 0311 .sign = 's', \ 0312 .realbits = 64, \ 0313 .storagebits = 64, \ 0314 }, \ 0315 } 0316 0317 s64 iio_get_time_ns(const struct iio_dev *indio_dev); 0318 0319 /* 0320 * Device operating modes 0321 * @INDIO_DIRECT_MODE: There is an access to either: 0322 * a) The last single value available for devices that do not provide 0323 * on-demand reads. 0324 * b) A new value after performing an on-demand read otherwise. 0325 * On most devices, this is a single-shot read. On some devices with data 0326 * streams without an 'on-demand' function, this might also be the 'last value' 0327 * feature. Above all, this mode internally means that we are not in any of the 0328 * other modes, and sysfs reads should work. 0329 * Device drivers should inform the core if they support this mode. 0330 * @INDIO_BUFFER_TRIGGERED: Common mode when dealing with kfifo buffers. 0331 * It indicates that an explicit trigger is required. This requests the core to 0332 * attach a poll function when enabling the buffer, which is indicated by the 0333 * _TRIGGERED suffix. 0334 * The core will ensure this mode is set when registering a triggered buffer 0335 * with iio_triggered_buffer_setup(). 0336 * @INDIO_BUFFER_SOFTWARE: Another kfifo buffer mode, but not event triggered. 0337 * No poll function can be attached because there is no triggered infrastructure 0338 * we can use to cause capture. There is a kfifo that the driver will fill, but 0339 * not "only one scan at a time". Typically, hardware will have a buffer that 0340 * can hold multiple scans. Software may read one or more scans at a single time 0341 * and push the available data to a Kfifo. This means the core will not attach 0342 * any poll function when enabling the buffer. 0343 * The core will ensure this mode is set when registering a simple kfifo buffer 0344 * with devm_iio_kfifo_buffer_setup(). 0345 * @INDIO_BUFFER_HARDWARE: For specific hardware, if unsure do not use this mode. 0346 * Same as above but this time the buffer is not a kfifo where we have direct 0347 * access to the data. Instead, the consumer driver must access the data through 0348 * non software visible channels (or DMA when there is no demux possible in 0349 * software) 0350 * The core will ensure this mode is set when registering a dmaengine buffer 0351 * with devm_iio_dmaengine_buffer_setup(). 0352 * @INDIO_EVENT_TRIGGERED: Very unusual mode. 0353 * Triggers usually refer to an external event which will start data capture. 0354 * Here it is kind of the opposite as, a particular state of the data might 0355 * produce an event which can be considered as an event. We don't necessarily 0356 * have access to the data itself, but to the event produced. For example, this 0357 * can be a threshold detector. The internal path of this mode is very close to 0358 * the INDIO_BUFFER_TRIGGERED mode. 0359 * The core will ensure this mode is set when registering a triggered event. 0360 * @INDIO_HARDWARE_TRIGGERED: Very unusual mode. 0361 * Here, triggers can result in data capture and can be routed to multiple 0362 * hardware components, which make them close to regular triggers in the way 0363 * they must be managed by the core, but without the entire interrupts/poll 0364 * functions burden. Interrupts are irrelevant as the data flow is hardware 0365 * mediated and distributed. 0366 */ 0367 #define INDIO_DIRECT_MODE 0x01 0368 #define INDIO_BUFFER_TRIGGERED 0x02 0369 #define INDIO_BUFFER_SOFTWARE 0x04 0370 #define INDIO_BUFFER_HARDWARE 0x08 0371 #define INDIO_EVENT_TRIGGERED 0x10 0372 #define INDIO_HARDWARE_TRIGGERED 0x20 0373 0374 #define INDIO_ALL_BUFFER_MODES \ 0375 (INDIO_BUFFER_TRIGGERED | INDIO_BUFFER_HARDWARE | INDIO_BUFFER_SOFTWARE) 0376 0377 #define INDIO_ALL_TRIGGERED_MODES \ 0378 (INDIO_BUFFER_TRIGGERED \ 0379 | INDIO_EVENT_TRIGGERED \ 0380 | INDIO_HARDWARE_TRIGGERED) 0381 0382 #define INDIO_MAX_RAW_ELEMENTS 4 0383 0384 struct iio_trigger; /* forward declaration */ 0385 0386 /** 0387 * struct iio_info - constant information about device 0388 * @event_attrs: event control attributes 0389 * @attrs: general purpose device attributes 0390 * @read_raw: function to request a value from the device. 0391 * mask specifies which value. Note 0 means a reading of 0392 * the channel in question. Return value will specify the 0393 * type of value returned by the device. val and val2 will 0394 * contain the elements making up the returned value. 0395 * @read_raw_multi: function to return values from the device. 0396 * mask specifies which value. Note 0 means a reading of 0397 * the channel in question. Return value will specify the 0398 * type of value returned by the device. vals pointer 0399 * contain the elements making up the returned value. 0400 * max_len specifies maximum number of elements 0401 * vals pointer can contain. val_len is used to return 0402 * length of valid elements in vals. 0403 * @read_avail: function to return the available values from the device. 0404 * mask specifies which value. Note 0 means the available 0405 * values for the channel in question. Return value 0406 * specifies if a IIO_AVAIL_LIST or a IIO_AVAIL_RANGE is 0407 * returned in vals. The type of the vals are returned in 0408 * type and the number of vals is returned in length. For 0409 * ranges, there are always three vals returned; min, step 0410 * and max. For lists, all possible values are enumerated. 0411 * @write_raw: function to write a value to the device. 0412 * Parameters are the same as for read_raw. 0413 * @read_label: function to request label name for a specified label, 0414 * for better channel identification. 0415 * @write_raw_get_fmt: callback function to query the expected 0416 * format/precision. If not set by the driver, write_raw 0417 * returns IIO_VAL_INT_PLUS_MICRO. 0418 * @read_event_config: find out if the event is enabled. 0419 * @write_event_config: set if the event is enabled. 0420 * @read_event_value: read a configuration value associated with the event. 0421 * @write_event_value: write a configuration value for the event. 0422 * @validate_trigger: function to validate the trigger when the 0423 * current trigger gets changed. 0424 * @update_scan_mode: function to configure device and scan buffer when 0425 * channels have changed 0426 * @debugfs_reg_access: function to read or write register value of device 0427 * @of_xlate: function pointer to obtain channel specifier index. 0428 * When #iio-cells is greater than '0', the driver could 0429 * provide a custom of_xlate function that reads the 0430 * *args* and returns the appropriate index in registered 0431 * IIO channels array. 0432 * @hwfifo_set_watermark: function pointer to set the current hardware 0433 * fifo watermark level; see hwfifo_* entries in 0434 * Documentation/ABI/testing/sysfs-bus-iio for details on 0435 * how the hardware fifo operates 0436 * @hwfifo_flush_to_buffer: function pointer to flush the samples stored 0437 * in the hardware fifo to the device buffer. The driver 0438 * should not flush more than count samples. The function 0439 * must return the number of samples flushed, 0 if no 0440 * samples were flushed or a negative integer if no samples 0441 * were flushed and there was an error. 0442 **/ 0443 struct iio_info { 0444 const struct attribute_group *event_attrs; 0445 const struct attribute_group *attrs; 0446 0447 int (*read_raw)(struct iio_dev *indio_dev, 0448 struct iio_chan_spec const *chan, 0449 int *val, 0450 int *val2, 0451 long mask); 0452 0453 int (*read_raw_multi)(struct iio_dev *indio_dev, 0454 struct iio_chan_spec const *chan, 0455 int max_len, 0456 int *vals, 0457 int *val_len, 0458 long mask); 0459 0460 int (*read_avail)(struct iio_dev *indio_dev, 0461 struct iio_chan_spec const *chan, 0462 const int **vals, 0463 int *type, 0464 int *length, 0465 long mask); 0466 0467 int (*write_raw)(struct iio_dev *indio_dev, 0468 struct iio_chan_spec const *chan, 0469 int val, 0470 int val2, 0471 long mask); 0472 0473 int (*read_label)(struct iio_dev *indio_dev, 0474 struct iio_chan_spec const *chan, 0475 char *label); 0476 0477 int (*write_raw_get_fmt)(struct iio_dev *indio_dev, 0478 struct iio_chan_spec const *chan, 0479 long mask); 0480 0481 int (*read_event_config)(struct iio_dev *indio_dev, 0482 const struct iio_chan_spec *chan, 0483 enum iio_event_type type, 0484 enum iio_event_direction dir); 0485 0486 int (*write_event_config)(struct iio_dev *indio_dev, 0487 const struct iio_chan_spec *chan, 0488 enum iio_event_type type, 0489 enum iio_event_direction dir, 0490 int state); 0491 0492 int (*read_event_value)(struct iio_dev *indio_dev, 0493 const struct iio_chan_spec *chan, 0494 enum iio_event_type type, 0495 enum iio_event_direction dir, 0496 enum iio_event_info info, int *val, int *val2); 0497 0498 int (*write_event_value)(struct iio_dev *indio_dev, 0499 const struct iio_chan_spec *chan, 0500 enum iio_event_type type, 0501 enum iio_event_direction dir, 0502 enum iio_event_info info, int val, int val2); 0503 0504 int (*validate_trigger)(struct iio_dev *indio_dev, 0505 struct iio_trigger *trig); 0506 int (*update_scan_mode)(struct iio_dev *indio_dev, 0507 const unsigned long *scan_mask); 0508 int (*debugfs_reg_access)(struct iio_dev *indio_dev, 0509 unsigned reg, unsigned writeval, 0510 unsigned *readval); 0511 int (*of_xlate)(struct iio_dev *indio_dev, 0512 const struct of_phandle_args *iiospec); 0513 int (*hwfifo_set_watermark)(struct iio_dev *indio_dev, unsigned val); 0514 int (*hwfifo_flush_to_buffer)(struct iio_dev *indio_dev, 0515 unsigned count); 0516 }; 0517 0518 /** 0519 * struct iio_buffer_setup_ops - buffer setup related callbacks 0520 * @preenable: [DRIVER] function to run prior to marking buffer enabled 0521 * @postenable: [DRIVER] function to run after marking buffer enabled 0522 * @predisable: [DRIVER] function to run prior to marking buffer 0523 * disabled 0524 * @postdisable: [DRIVER] function to run after marking buffer disabled 0525 * @validate_scan_mask: [DRIVER] function callback to check whether a given 0526 * scan mask is valid for the device. 0527 */ 0528 struct iio_buffer_setup_ops { 0529 int (*preenable)(struct iio_dev *); 0530 int (*postenable)(struct iio_dev *); 0531 int (*predisable)(struct iio_dev *); 0532 int (*postdisable)(struct iio_dev *); 0533 bool (*validate_scan_mask)(struct iio_dev *indio_dev, 0534 const unsigned long *scan_mask); 0535 }; 0536 0537 /** 0538 * struct iio_dev - industrial I/O device 0539 * @modes: [DRIVER] bitmask listing all the operating modes 0540 * supported by the IIO device. This list should be 0541 * initialized before registering the IIO device. It can 0542 * also be filed up by the IIO core, as a result of 0543 * enabling particular features in the driver 0544 * (see iio_triggered_event_setup()). 0545 * @dev: [DRIVER] device structure, should be assigned a parent 0546 * and owner 0547 * @buffer: [DRIVER] any buffer present 0548 * @scan_bytes: [INTERN] num bytes captured to be fed to buffer demux 0549 * @mlock: [INTERN] lock used to prevent simultaneous device state 0550 * changes 0551 * @available_scan_masks: [DRIVER] optional array of allowed bitmasks 0552 * @masklength: [INTERN] the length of the mask established from 0553 * channels 0554 * @active_scan_mask: [INTERN] union of all scan masks requested by buffers 0555 * @scan_timestamp: [INTERN] set if any buffers have requested timestamp 0556 * @trig: [INTERN] current device trigger (buffer modes) 0557 * @pollfunc: [DRIVER] function run on trigger being received 0558 * @pollfunc_event: [DRIVER] function run on events trigger being received 0559 * @channels: [DRIVER] channel specification structure table 0560 * @num_channels: [DRIVER] number of channels specified in @channels. 0561 * @name: [DRIVER] name of the device. 0562 * @label: [DRIVER] unique name to identify which device this is 0563 * @info: [DRIVER] callbacks and constant info from driver 0564 * @setup_ops: [DRIVER] callbacks to call before and after buffer 0565 * enable/disable 0566 * @priv: [DRIVER] reference to driver's private information 0567 * **MUST** be accessed **ONLY** via iio_priv() helper 0568 */ 0569 struct iio_dev { 0570 int modes; 0571 struct device dev; 0572 0573 struct iio_buffer *buffer; 0574 int scan_bytes; 0575 struct mutex mlock; 0576 0577 const unsigned long *available_scan_masks; 0578 unsigned masklength; 0579 const unsigned long *active_scan_mask; 0580 bool scan_timestamp; 0581 struct iio_trigger *trig; 0582 struct iio_poll_func *pollfunc; 0583 struct iio_poll_func *pollfunc_event; 0584 0585 struct iio_chan_spec const *channels; 0586 int num_channels; 0587 0588 const char *name; 0589 const char *label; 0590 const struct iio_info *info; 0591 const struct iio_buffer_setup_ops *setup_ops; 0592 0593 void *priv; 0594 }; 0595 0596 int iio_device_id(struct iio_dev *indio_dev); 0597 int iio_device_get_current_mode(struct iio_dev *indio_dev); 0598 bool iio_buffer_enabled(struct iio_dev *indio_dev); 0599 0600 const struct iio_chan_spec 0601 *iio_find_channel_from_si(struct iio_dev *indio_dev, int si); 0602 /** 0603 * iio_device_register() - register a device with the IIO subsystem 0604 * @indio_dev: Device structure filled by the device driver 0605 **/ 0606 #define iio_device_register(indio_dev) \ 0607 __iio_device_register((indio_dev), THIS_MODULE) 0608 int __iio_device_register(struct iio_dev *indio_dev, struct module *this_mod); 0609 void iio_device_unregister(struct iio_dev *indio_dev); 0610 /** 0611 * devm_iio_device_register - Resource-managed iio_device_register() 0612 * @dev: Device to allocate iio_dev for 0613 * @indio_dev: Device structure filled by the device driver 0614 * 0615 * Managed iio_device_register. The IIO device registered with this 0616 * function is automatically unregistered on driver detach. This function 0617 * calls iio_device_register() internally. Refer to that function for more 0618 * information. 0619 * 0620 * RETURNS: 0621 * 0 on success, negative error number on failure. 0622 */ 0623 #define devm_iio_device_register(dev, indio_dev) \ 0624 __devm_iio_device_register((dev), (indio_dev), THIS_MODULE) 0625 int __devm_iio_device_register(struct device *dev, struct iio_dev *indio_dev, 0626 struct module *this_mod); 0627 int iio_push_event(struct iio_dev *indio_dev, u64 ev_code, s64 timestamp); 0628 int iio_device_claim_direct_mode(struct iio_dev *indio_dev); 0629 void iio_device_release_direct_mode(struct iio_dev *indio_dev); 0630 0631 extern struct bus_type iio_bus_type; 0632 0633 /** 0634 * iio_device_put() - reference counted deallocation of struct device 0635 * @indio_dev: IIO device structure containing the device 0636 **/ 0637 static inline void iio_device_put(struct iio_dev *indio_dev) 0638 { 0639 if (indio_dev) 0640 put_device(&indio_dev->dev); 0641 } 0642 0643 clockid_t iio_device_get_clock(const struct iio_dev *indio_dev); 0644 int iio_device_set_clock(struct iio_dev *indio_dev, clockid_t clock_id); 0645 0646 /** 0647 * dev_to_iio_dev() - Get IIO device struct from a device struct 0648 * @dev: The device embedded in the IIO device 0649 * 0650 * Note: The device must be a IIO device, otherwise the result is undefined. 0651 */ 0652 static inline struct iio_dev *dev_to_iio_dev(struct device *dev) 0653 { 0654 return container_of(dev, struct iio_dev, dev); 0655 } 0656 0657 /** 0658 * iio_device_get() - increment reference count for the device 0659 * @indio_dev: IIO device structure 0660 * 0661 * Returns: The passed IIO device 0662 **/ 0663 static inline struct iio_dev *iio_device_get(struct iio_dev *indio_dev) 0664 { 0665 return indio_dev ? dev_to_iio_dev(get_device(&indio_dev->dev)) : NULL; 0666 } 0667 0668 /** 0669 * iio_device_set_parent() - assign parent device to the IIO device object 0670 * @indio_dev: IIO device structure 0671 * @parent: reference to parent device object 0672 * 0673 * This utility must be called between IIO device allocation 0674 * (via devm_iio_device_alloc()) & IIO device registration 0675 * (via iio_device_register() and devm_iio_device_register())). 0676 * By default, the device allocation will also assign a parent device to 0677 * the IIO device object. In cases where devm_iio_device_alloc() is used, 0678 * sometimes the parent device must be different than the device used to 0679 * manage the allocation. 0680 * In that case, this helper should be used to change the parent, hence the 0681 * requirement to call this between allocation & registration. 0682 **/ 0683 static inline void iio_device_set_parent(struct iio_dev *indio_dev, 0684 struct device *parent) 0685 { 0686 indio_dev->dev.parent = parent; 0687 } 0688 0689 /** 0690 * iio_device_set_drvdata() - Set device driver data 0691 * @indio_dev: IIO device structure 0692 * @data: Driver specific data 0693 * 0694 * Allows to attach an arbitrary pointer to an IIO device, which can later be 0695 * retrieved by iio_device_get_drvdata(). 0696 */ 0697 static inline void iio_device_set_drvdata(struct iio_dev *indio_dev, void *data) 0698 { 0699 dev_set_drvdata(&indio_dev->dev, data); 0700 } 0701 0702 /** 0703 * iio_device_get_drvdata() - Get device driver data 0704 * @indio_dev: IIO device structure 0705 * 0706 * Returns the data previously set with iio_device_set_drvdata() 0707 */ 0708 static inline void *iio_device_get_drvdata(const struct iio_dev *indio_dev) 0709 { 0710 return dev_get_drvdata(&indio_dev->dev); 0711 } 0712 0713 /* 0714 * Used to ensure the iio_priv() structure is aligned to allow that structure 0715 * to in turn include IIO_DMA_MINALIGN'd elements such as buffers which 0716 * must not share cachelines with the rest of the structure, thus making 0717 * them safe for use with non-coherent DMA. 0718 */ 0719 #define IIO_DMA_MINALIGN ARCH_KMALLOC_MINALIGN 0720 struct iio_dev *iio_device_alloc(struct device *parent, int sizeof_priv); 0721 0722 /* The information at the returned address is guaranteed to be cacheline aligned */ 0723 static inline void *iio_priv(const struct iio_dev *indio_dev) 0724 { 0725 return indio_dev->priv; 0726 } 0727 0728 void iio_device_free(struct iio_dev *indio_dev); 0729 struct iio_dev *devm_iio_device_alloc(struct device *parent, int sizeof_priv); 0730 0731 #define devm_iio_trigger_alloc(parent, fmt, ...) \ 0732 __devm_iio_trigger_alloc((parent), THIS_MODULE, (fmt), ##__VA_ARGS__) 0733 __printf(3, 4) 0734 struct iio_trigger *__devm_iio_trigger_alloc(struct device *parent, 0735 struct module *this_mod, 0736 const char *fmt, ...); 0737 /** 0738 * iio_get_debugfs_dentry() - helper function to get the debugfs_dentry 0739 * @indio_dev: IIO device structure for device 0740 **/ 0741 #if defined(CONFIG_DEBUG_FS) 0742 struct dentry *iio_get_debugfs_dentry(struct iio_dev *indio_dev); 0743 #else 0744 static inline struct dentry *iio_get_debugfs_dentry(struct iio_dev *indio_dev) 0745 { 0746 return NULL; 0747 } 0748 #endif 0749 0750 ssize_t iio_format_value(char *buf, unsigned int type, int size, int *vals); 0751 0752 int iio_str_to_fixpoint(const char *str, int fract_mult, int *integer, 0753 int *fract); 0754 0755 /** 0756 * IIO_DEGREE_TO_RAD() - Convert degree to rad 0757 * @deg: A value in degree 0758 * 0759 * Returns the given value converted from degree to rad 0760 */ 0761 #define IIO_DEGREE_TO_RAD(deg) (((deg) * 314159ULL + 9000000ULL) / 18000000ULL) 0762 0763 /** 0764 * IIO_RAD_TO_DEGREE() - Convert rad to degree 0765 * @rad: A value in rad 0766 * 0767 * Returns the given value converted from rad to degree 0768 */ 0769 #define IIO_RAD_TO_DEGREE(rad) \ 0770 (((rad) * 18000000ULL + 314159ULL / 2) / 314159ULL) 0771 0772 /** 0773 * IIO_G_TO_M_S_2() - Convert g to meter / second**2 0774 * @g: A value in g 0775 * 0776 * Returns the given value converted from g to meter / second**2 0777 */ 0778 #define IIO_G_TO_M_S_2(g) ((g) * 980665ULL / 100000ULL) 0779 0780 /** 0781 * IIO_M_S_2_TO_G() - Convert meter / second**2 to g 0782 * @ms2: A value in meter / second**2 0783 * 0784 * Returns the given value converted from meter / second**2 to g 0785 */ 0786 #define IIO_M_S_2_TO_G(ms2) (((ms2) * 100000ULL + 980665ULL / 2) / 980665ULL) 0787 0788 #endif /* _INDUSTRIAL_IO_H_ */
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.1.0 LXR engine. The LXR team |
![]() ![]() |