iio.h 20 KB

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