iio.h 20 KB

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