iio.h 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624
  1. /* The industrial I/O core
  2. *
  3. * Copyright (c) 2008 Jonathan Cameron
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms of the GNU General Public License version 2 as published by
  7. * the Free Software Foundation.
  8. */
  9. #ifndef _INDUSTRIAL_IO_H_
  10. #define _INDUSTRIAL_IO_H_
  11. #include <linux/device.h>
  12. #include <linux/cdev.h>
  13. #include <linux/iio/types.h>
  14. /* IIO TODO LIST */
  15. /*
  16. * Provide means of adjusting timer accuracy.
  17. * Currently assumes nano seconds.
  18. */
  19. enum iio_chan_info_enum {
  20. IIO_CHAN_INFO_RAW = 0,
  21. IIO_CHAN_INFO_PROCESSED,
  22. IIO_CHAN_INFO_SCALE,
  23. IIO_CHAN_INFO_OFFSET,
  24. IIO_CHAN_INFO_CALIBSCALE,
  25. IIO_CHAN_INFO_CALIBBIAS,
  26. IIO_CHAN_INFO_PEAK,
  27. IIO_CHAN_INFO_PEAK_SCALE,
  28. IIO_CHAN_INFO_QUADRATURE_CORRECTION_RAW,
  29. IIO_CHAN_INFO_AVERAGE_RAW,
  30. IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY,
  31. IIO_CHAN_INFO_SAMP_FREQ,
  32. IIO_CHAN_INFO_FREQUENCY,
  33. IIO_CHAN_INFO_PHASE,
  34. IIO_CHAN_INFO_HARDWAREGAIN,
  35. IIO_CHAN_INFO_HYSTERESIS,
  36. IIO_CHAN_INFO_INT_TIME,
  37. };
  38. enum iio_shared_by {
  39. IIO_SEPARATE,
  40. IIO_SHARED_BY_TYPE,
  41. IIO_SHARED_BY_DIR,
  42. IIO_SHARED_BY_ALL
  43. };
  44. enum iio_endian {
  45. IIO_CPU,
  46. IIO_BE,
  47. IIO_LE,
  48. };
  49. struct iio_chan_spec;
  50. struct iio_dev;
  51. /**
  52. * struct iio_chan_spec_ext_info - Extended channel info attribute
  53. * @name: Info attribute name
  54. * @shared: Whether this attribute is shared between all channels.
  55. * @read: Read callback for this info attribute, may be NULL.
  56. * @write: Write callback for this info attribute, may be NULL.
  57. * @private: Data private to the driver.
  58. */
  59. struct iio_chan_spec_ext_info {
  60. const char *name;
  61. enum iio_shared_by shared;
  62. ssize_t (*read)(struct iio_dev *, uintptr_t private,
  63. struct iio_chan_spec const *, char *buf);
  64. ssize_t (*write)(struct iio_dev *, uintptr_t private,
  65. struct iio_chan_spec const *, const char *buf,
  66. size_t len);
  67. uintptr_t private;
  68. };
  69. /**
  70. * struct iio_enum - Enum channel info attribute
  71. * @items: An array of strings.
  72. * @num_items: Length of the item array.
  73. * @set: Set callback function, may be NULL.
  74. * @get: Get callback function, may be NULL.
  75. *
  76. * The iio_enum struct can be used to implement enum style channel attributes.
  77. * Enum style attributes are those which have a set of strings which map to
  78. * unsigned integer values. The IIO enum helper code takes care of mapping
  79. * between value and string as well as generating a "_available" file which
  80. * contains a list of all available items. The set callback will be called when
  81. * the attribute is updated. The last parameter is the index to the newly
  82. * activated item. The get callback will be used to query the currently active
  83. * item and is supposed to return the index for it.
  84. */
  85. struct iio_enum {
  86. const char * const *items;
  87. unsigned int num_items;
  88. int (*set)(struct iio_dev *, const struct iio_chan_spec *, unsigned int);
  89. int (*get)(struct iio_dev *, const struct iio_chan_spec *);
  90. };
  91. ssize_t iio_enum_available_read(struct iio_dev *indio_dev,
  92. uintptr_t priv, const struct iio_chan_spec *chan, char *buf);
  93. ssize_t iio_enum_read(struct iio_dev *indio_dev,
  94. uintptr_t priv, const struct iio_chan_spec *chan, char *buf);
  95. ssize_t iio_enum_write(struct iio_dev *indio_dev,
  96. uintptr_t priv, const struct iio_chan_spec *chan, const char *buf,
  97. size_t len);
  98. /**
  99. * IIO_ENUM() - Initialize enum extended channel attribute
  100. * @_name: Attribute name
  101. * @_shared: Whether the attribute is shared between all channels
  102. * @_e: Pointer to an iio_enum struct
  103. *
  104. * This should usually be used together with IIO_ENUM_AVAILABLE()
  105. */
  106. #define IIO_ENUM(_name, _shared, _e) \
  107. { \
  108. .name = (_name), \
  109. .shared = (_shared), \
  110. .read = iio_enum_read, \
  111. .write = iio_enum_write, \
  112. .private = (uintptr_t)(_e), \
  113. }
  114. /**
  115. * IIO_ENUM_AVAILABLE() - Initialize enum available extended channel attribute
  116. * @_name: Attribute name ("_available" will be appended to the name)
  117. * @_e: Pointer to an iio_enum struct
  118. *
  119. * Creates a read only attribute which lists all the available enum items in a
  120. * space separated list. This should usually be used together with IIO_ENUM()
  121. */
  122. #define IIO_ENUM_AVAILABLE(_name, _e) \
  123. { \
  124. .name = (_name "_available"), \
  125. .shared = IIO_SHARED_BY_TYPE, \
  126. .read = iio_enum_available_read, \
  127. .private = (uintptr_t)(_e), \
  128. }
  129. /**
  130. * struct iio_event_spec - specification for a channel event
  131. * @type: Type of the event
  132. * @dir: Direction of the event
  133. * @mask_separate: Bit mask of enum iio_event_info values. Attributes
  134. * set in this mask will be registered per channel.
  135. * @mask_shared_by_type: Bit mask of enum iio_event_info values. Attributes
  136. * set in this mask will be shared by channel type.
  137. * @mask_shared_by_dir: Bit mask of enum iio_event_info values. Attributes
  138. * set in this mask will be shared by channel type and
  139. * direction.
  140. * @mask_shared_by_all: Bit mask of enum iio_event_info values. Attributes
  141. * set in this mask will be shared by all channels.
  142. */
  143. struct iio_event_spec {
  144. enum iio_event_type type;
  145. enum iio_event_direction dir;
  146. unsigned long mask_separate;
  147. unsigned long mask_shared_by_type;
  148. unsigned long mask_shared_by_dir;
  149. unsigned long mask_shared_by_all;
  150. };
  151. /**
  152. * struct iio_chan_spec - specification of a single channel
  153. * @type: What type of measurement is the channel making.
  154. * @channel: What number do we wish to assign the channel.
  155. * @channel2: If there is a second number for a differential
  156. * channel then this is it. If modified is set then the
  157. * value here specifies the modifier.
  158. * @address: Driver specific identifier.
  159. * @scan_index: Monotonic index to give ordering in scans when read
  160. * from a buffer.
  161. * @scan_type: Sign: 's' or 'u' to specify signed or unsigned
  162. * realbits: Number of valid bits of data
  163. * storage_bits: Realbits + padding
  164. * shift: Shift right by this before masking out
  165. * realbits.
  166. * endianness: little or big endian
  167. * repeat: Number of times real/storage bits
  168. * repeats. When the repeat element is
  169. * more than 1, then the type element in
  170. * sysfs will show a repeat value.
  171. * Otherwise, the number of repetitions is
  172. * omitted.
  173. * @info_mask_separate: What information is to be exported that is specific to
  174. * this channel.
  175. * @info_mask_shared_by_type: What information is to be exported that is shared
  176. * by all channels of the same type.
  177. * @info_mask_shared_by_dir: What information is to be exported that is shared
  178. * by all channels of the same direction.
  179. * @info_mask_shared_by_all: What information is to be exported that is shared
  180. * by all channels.
  181. * @event_spec: Array of events which should be registered for this
  182. * channel.
  183. * @num_event_specs: Size of the event_spec array.
  184. * @ext_info: Array of extended info attributes for this channel.
  185. * The array is NULL terminated, the last element should
  186. * have its name field set to NULL.
  187. * @extend_name: Allows labeling of channel attributes with an
  188. * informative name. Note this has no effect codes etc,
  189. * unlike modifiers.
  190. * @datasheet_name: A name used in in-kernel mapping of channels. It should
  191. * correspond to the first name that the channel is referred
  192. * to by in the datasheet (e.g. IND), or the nearest
  193. * possible compound name (e.g. IND-INC).
  194. * @modified: Does a modifier apply to this channel. What these are
  195. * depends on the channel type. Modifier is set in
  196. * channel2. Examples are IIO_MOD_X for axial sensors about
  197. * the 'x' axis.
  198. * @indexed: Specify the channel has a numerical index. If not,
  199. * the channel index number will be suppressed for sysfs
  200. * attributes but not for event codes.
  201. * @output: Channel is output.
  202. * @differential: Channel is differential.
  203. */
  204. struct iio_chan_spec {
  205. enum iio_chan_type type;
  206. int channel;
  207. int channel2;
  208. unsigned long address;
  209. int scan_index;
  210. struct {
  211. char sign;
  212. u8 realbits;
  213. u8 storagebits;
  214. u8 shift;
  215. u8 repeat;
  216. enum iio_endian endianness;
  217. } scan_type;
  218. long info_mask_separate;
  219. long info_mask_shared_by_type;
  220. long info_mask_shared_by_dir;
  221. long info_mask_shared_by_all;
  222. const struct iio_event_spec *event_spec;
  223. unsigned int num_event_specs;
  224. const struct iio_chan_spec_ext_info *ext_info;
  225. const char *extend_name;
  226. const char *datasheet_name;
  227. unsigned modified:1;
  228. unsigned indexed:1;
  229. unsigned output:1;
  230. unsigned differential:1;
  231. };
  232. /**
  233. * iio_channel_has_info() - Checks whether a channel supports a info attribute
  234. * @chan: The channel to be queried
  235. * @type: Type of the info attribute to be checked
  236. *
  237. * Returns true if the channels supports reporting values for the given info
  238. * attribute type, false otherwise.
  239. */
  240. static inline bool iio_channel_has_info(const struct iio_chan_spec *chan,
  241. enum iio_chan_info_enum type)
  242. {
  243. return (chan->info_mask_separate & BIT(type)) |
  244. (chan->info_mask_shared_by_type & BIT(type)) |
  245. (chan->info_mask_shared_by_dir & BIT(type)) |
  246. (chan->info_mask_shared_by_all & BIT(type));
  247. }
  248. #define IIO_CHAN_SOFT_TIMESTAMP(_si) { \
  249. .type = IIO_TIMESTAMP, \
  250. .channel = -1, \
  251. .scan_index = _si, \
  252. .scan_type = { \
  253. .sign = 's', \
  254. .realbits = 64, \
  255. .storagebits = 64, \
  256. }, \
  257. }
  258. /**
  259. * iio_get_time_ns() - utility function to get a time stamp for events etc
  260. **/
  261. static inline s64 iio_get_time_ns(void)
  262. {
  263. return ktime_get_real_ns();
  264. }
  265. /* Device operating modes */
  266. #define INDIO_DIRECT_MODE 0x01
  267. #define INDIO_BUFFER_TRIGGERED 0x02
  268. #define INDIO_BUFFER_HARDWARE 0x08
  269. #define INDIO_ALL_BUFFER_MODES \
  270. (INDIO_BUFFER_TRIGGERED | INDIO_BUFFER_HARDWARE)
  271. #define INDIO_MAX_RAW_ELEMENTS 4
  272. struct iio_trigger; /* forward declaration */
  273. struct iio_dev;
  274. /**
  275. * struct iio_info - constant information about device
  276. * @driver_module: module structure used to ensure correct
  277. * ownership of chrdevs etc
  278. * @event_attrs: event control attributes
  279. * @attrs: general purpose device attributes
  280. * @read_raw: function to request a value from the device.
  281. * mask specifies which value. Note 0 means a reading of
  282. * the channel in question. Return value will specify the
  283. * type of value returned by the device. val and val2 will
  284. * contain the elements making up the returned value.
  285. * @read_raw_multi: function to return values from the device.
  286. * mask specifies which value. Note 0 means a reading of
  287. * the channel in question. Return value will specify the
  288. * type of value returned by the device. vals pointer
  289. * contain the elements making up the returned value.
  290. * max_len specifies maximum number of elements
  291. * vals pointer can contain. val_len is used to return
  292. * length of valid elements in vals.
  293. * @write_raw: function to write a value to the device.
  294. * Parameters are the same as for read_raw.
  295. * @write_raw_get_fmt: callback function to query the expected
  296. * format/precision. If not set by the driver, write_raw
  297. * returns IIO_VAL_INT_PLUS_MICRO.
  298. * @read_event_config: find out if the event is enabled.
  299. * @write_event_config: set if the event is enabled.
  300. * @read_event_value: read a configuration value associated with the event.
  301. * @write_event_value: write a configuration value for the event.
  302. * @validate_trigger: function to validate the trigger when the
  303. * current trigger gets changed.
  304. * @update_scan_mode: function to configure device and scan buffer when
  305. * channels have changed
  306. * @debugfs_reg_access: function to read or write register value of device
  307. **/
  308. struct iio_info {
  309. struct module *driver_module;
  310. struct attribute_group *event_attrs;
  311. const struct attribute_group *attrs;
  312. int (*read_raw)(struct iio_dev *indio_dev,
  313. struct iio_chan_spec const *chan,
  314. int *val,
  315. int *val2,
  316. long mask);
  317. int (*read_raw_multi)(struct iio_dev *indio_dev,
  318. struct iio_chan_spec const *chan,
  319. int max_len,
  320. int *vals,
  321. int *val_len,
  322. long mask);
  323. int (*write_raw)(struct iio_dev *indio_dev,
  324. struct iio_chan_spec const *chan,
  325. int val,
  326. int val2,
  327. long mask);
  328. int (*write_raw_get_fmt)(struct iio_dev *indio_dev,
  329. struct iio_chan_spec const *chan,
  330. long mask);
  331. int (*read_event_config)(struct iio_dev *indio_dev,
  332. const struct iio_chan_spec *chan,
  333. enum iio_event_type type,
  334. enum iio_event_direction dir);
  335. int (*write_event_config)(struct iio_dev *indio_dev,
  336. const struct iio_chan_spec *chan,
  337. enum iio_event_type type,
  338. enum iio_event_direction dir,
  339. int state);
  340. int (*read_event_value)(struct iio_dev *indio_dev,
  341. const struct iio_chan_spec *chan,
  342. enum iio_event_type type,
  343. enum iio_event_direction dir,
  344. enum iio_event_info info, int *val, int *val2);
  345. int (*write_event_value)(struct iio_dev *indio_dev,
  346. const struct iio_chan_spec *chan,
  347. enum iio_event_type type,
  348. enum iio_event_direction dir,
  349. enum iio_event_info info, int val, int val2);
  350. int (*validate_trigger)(struct iio_dev *indio_dev,
  351. struct iio_trigger *trig);
  352. int (*update_scan_mode)(struct iio_dev *indio_dev,
  353. const unsigned long *scan_mask);
  354. int (*debugfs_reg_access)(struct iio_dev *indio_dev,
  355. unsigned reg, unsigned writeval,
  356. unsigned *readval);
  357. };
  358. /**
  359. * struct iio_buffer_setup_ops - buffer setup related callbacks
  360. * @preenable: [DRIVER] function to run prior to marking buffer enabled
  361. * @postenable: [DRIVER] function to run after marking buffer enabled
  362. * @predisable: [DRIVER] function to run prior to marking buffer
  363. * disabled
  364. * @postdisable: [DRIVER] function to run after marking buffer disabled
  365. * @validate_scan_mask: [DRIVER] function callback to check whether a given
  366. * scan mask is valid for the device.
  367. */
  368. struct iio_buffer_setup_ops {
  369. int (*preenable)(struct iio_dev *);
  370. int (*postenable)(struct iio_dev *);
  371. int (*predisable)(struct iio_dev *);
  372. int (*postdisable)(struct iio_dev *);
  373. bool (*validate_scan_mask)(struct iio_dev *indio_dev,
  374. const unsigned long *scan_mask);
  375. };
  376. /**
  377. * struct iio_dev - industrial I/O device
  378. * @id: [INTERN] used to identify device internally
  379. * @modes: [DRIVER] operating modes supported by device
  380. * @currentmode: [DRIVER] current operating mode
  381. * @dev: [DRIVER] device structure, should be assigned a parent
  382. * and owner
  383. * @event_interface: [INTERN] event chrdevs associated with interrupt lines
  384. * @buffer: [DRIVER] any buffer present
  385. * @buffer_list: [INTERN] list of all buffers currently attached
  386. * @scan_bytes: [INTERN] num bytes captured to be fed to buffer demux
  387. * @mlock: [INTERN] lock used to prevent simultaneous device state
  388. * changes
  389. * @available_scan_masks: [DRIVER] optional array of allowed bitmasks
  390. * @masklength: [INTERN] the length of the mask established from
  391. * channels
  392. * @active_scan_mask: [INTERN] union of all scan masks requested by buffers
  393. * @scan_timestamp: [INTERN] set if any buffers have requested timestamp
  394. * @scan_index_timestamp:[INTERN] cache of the index to the timestamp
  395. * @trig: [INTERN] current device trigger (buffer modes)
  396. * @pollfunc: [DRIVER] function run on trigger being received
  397. * @channels: [DRIVER] channel specification structure table
  398. * @num_channels: [DRIVER] number of channels specified in @channels.
  399. * @channel_attr_list: [INTERN] keep track of automatically created channel
  400. * attributes
  401. * @chan_attr_group: [INTERN] group for all attrs in base directory
  402. * @name: [DRIVER] name of the device.
  403. * @info: [DRIVER] callbacks and constant info from driver
  404. * @info_exist_lock: [INTERN] lock to prevent use during removal
  405. * @setup_ops: [DRIVER] callbacks to call before and after buffer
  406. * enable/disable
  407. * @chrdev: [INTERN] associated character device
  408. * @groups: [INTERN] attribute groups
  409. * @groupcounter: [INTERN] index of next attribute group
  410. * @flags: [INTERN] file ops related flags including busy flag.
  411. * @debugfs_dentry: [INTERN] device specific debugfs dentry.
  412. * @cached_reg_addr: [INTERN] cached register address for debugfs reads.
  413. */
  414. struct iio_dev {
  415. int id;
  416. int modes;
  417. int currentmode;
  418. struct device dev;
  419. struct iio_event_interface *event_interface;
  420. struct iio_buffer *buffer;
  421. struct list_head buffer_list;
  422. int scan_bytes;
  423. struct mutex mlock;
  424. const unsigned long *available_scan_masks;
  425. unsigned masklength;
  426. const unsigned long *active_scan_mask;
  427. bool scan_timestamp;
  428. unsigned scan_index_timestamp;
  429. struct iio_trigger *trig;
  430. struct iio_poll_func *pollfunc;
  431. struct iio_chan_spec const *channels;
  432. int num_channels;
  433. struct list_head channel_attr_list;
  434. struct attribute_group chan_attr_group;
  435. const char *name;
  436. const struct iio_info *info;
  437. struct mutex info_exist_lock;
  438. const struct iio_buffer_setup_ops *setup_ops;
  439. struct cdev chrdev;
  440. #define IIO_MAX_GROUPS 6
  441. const struct attribute_group *groups[IIO_MAX_GROUPS + 1];
  442. int groupcounter;
  443. unsigned long flags;
  444. #if defined(CONFIG_DEBUG_FS)
  445. struct dentry *debugfs_dentry;
  446. unsigned cached_reg_addr;
  447. #endif
  448. };
  449. const struct iio_chan_spec
  450. *iio_find_channel_from_si(struct iio_dev *indio_dev, int si);
  451. int iio_device_register(struct iio_dev *indio_dev);
  452. void iio_device_unregister(struct iio_dev *indio_dev);
  453. int devm_iio_device_register(struct device *dev, struct iio_dev *indio_dev);
  454. void devm_iio_device_unregister(struct device *dev, struct iio_dev *indio_dev);
  455. int iio_push_event(struct iio_dev *indio_dev, u64 ev_code, s64 timestamp);
  456. extern struct bus_type iio_bus_type;
  457. /**
  458. * iio_device_put() - reference counted deallocation of struct device
  459. * @indio_dev: IIO device structure containing the device
  460. **/
  461. static inline void iio_device_put(struct iio_dev *indio_dev)
  462. {
  463. if (indio_dev)
  464. put_device(&indio_dev->dev);
  465. }
  466. /**
  467. * dev_to_iio_dev() - Get IIO device struct from a device struct
  468. * @dev: The device embedded in the IIO device
  469. *
  470. * Note: The device must be a IIO device, otherwise the result is undefined.
  471. */
  472. static inline struct iio_dev *dev_to_iio_dev(struct device *dev)
  473. {
  474. return container_of(dev, struct iio_dev, dev);
  475. }
  476. /**
  477. * iio_device_get() - increment reference count for the device
  478. * @indio_dev: IIO device structure
  479. *
  480. * Returns: The passed IIO device
  481. **/
  482. static inline struct iio_dev *iio_device_get(struct iio_dev *indio_dev)
  483. {
  484. return indio_dev ? dev_to_iio_dev(get_device(&indio_dev->dev)) : NULL;
  485. }
  486. /**
  487. * iio_device_set_drvdata() - Set device driver data
  488. * @indio_dev: IIO device structure
  489. * @data: Driver specific data
  490. *
  491. * Allows to attach an arbitrary pointer to an IIO device, which can later be
  492. * retrieved by iio_device_get_drvdata().
  493. */
  494. static inline void iio_device_set_drvdata(struct iio_dev *indio_dev, void *data)
  495. {
  496. dev_set_drvdata(&indio_dev->dev, data);
  497. }
  498. /**
  499. * iio_device_get_drvdata() - Get device driver data
  500. * @indio_dev: IIO device structure
  501. *
  502. * Returns the data previously set with iio_device_set_drvdata()
  503. */
  504. static inline void *iio_device_get_drvdata(struct iio_dev *indio_dev)
  505. {
  506. return dev_get_drvdata(&indio_dev->dev);
  507. }
  508. /* Can we make this smaller? */
  509. #define IIO_ALIGN L1_CACHE_BYTES
  510. struct iio_dev *iio_device_alloc(int sizeof_priv);
  511. static inline void *iio_priv(const struct iio_dev *indio_dev)
  512. {
  513. return (char *)indio_dev + ALIGN(sizeof(struct iio_dev), IIO_ALIGN);
  514. }
  515. static inline struct iio_dev *iio_priv_to_dev(void *priv)
  516. {
  517. return (struct iio_dev *)((char *)priv -
  518. ALIGN(sizeof(struct iio_dev), IIO_ALIGN));
  519. }
  520. void iio_device_free(struct iio_dev *indio_dev);
  521. struct iio_dev *devm_iio_device_alloc(struct device *dev, int sizeof_priv);
  522. void devm_iio_device_free(struct device *dev, struct iio_dev *indio_dev);
  523. struct iio_trigger *devm_iio_trigger_alloc(struct device *dev,
  524. const char *fmt, ...);
  525. void devm_iio_trigger_free(struct device *dev, struct iio_trigger *iio_trig);
  526. /**
  527. * iio_buffer_enabled() - helper function to test if the buffer is enabled
  528. * @indio_dev: IIO device structure for device
  529. **/
  530. static inline bool iio_buffer_enabled(struct iio_dev *indio_dev)
  531. {
  532. return indio_dev->currentmode
  533. & (INDIO_BUFFER_TRIGGERED | INDIO_BUFFER_HARDWARE);
  534. }
  535. /**
  536. * iio_get_debugfs_dentry() - helper function to get the debugfs_dentry
  537. * @indio_dev: IIO device structure for device
  538. **/
  539. #if defined(CONFIG_DEBUG_FS)
  540. static inline struct dentry *iio_get_debugfs_dentry(struct iio_dev *indio_dev)
  541. {
  542. return indio_dev->debugfs_dentry;
  543. }
  544. #else
  545. static inline struct dentry *iio_get_debugfs_dentry(struct iio_dev *indio_dev)
  546. {
  547. return NULL;
  548. }
  549. #endif
  550. int iio_str_to_fixpoint(const char *str, int fract_mult, int *integer,
  551. int *fract);
  552. /**
  553. * IIO_DEGREE_TO_RAD() - Convert degree to rad
  554. * @deg: A value in degree
  555. *
  556. * Returns the given value converted from degree to rad
  557. */
  558. #define IIO_DEGREE_TO_RAD(deg) (((deg) * 314159ULL + 9000000ULL) / 18000000ULL)
  559. /**
  560. * IIO_G_TO_M_S_2() - Convert g to meter / second**2
  561. * @g: A value in g
  562. *
  563. * Returns the given value converted from g to meter / second**2
  564. */
  565. #define IIO_G_TO_M_S_2(g) ((g) * 980665ULL / 100000ULL)
  566. #endif /* _INDUSTRIAL_IO_H_ */