0001
0002 #ifndef __SSP_IIO_SENSOR_H__
0003 #define __SSP_IIO_SENSOR_H__
0004
0005 #define SSP_CHANNEL_AG(_type, _mod, _index) \
0006 { \
0007 .type = _type,\
0008 .modified = 1,\
0009 .channel2 = _mod,\
0010 .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SAMP_FREQ),\
0011 .scan_index = _index,\
0012 .scan_type = {\
0013 .sign = 's',\
0014 .realbits = 16,\
0015 .storagebits = 16,\
0016 .shift = 0,\
0017 .endianness = IIO_LE,\
0018 },\
0019 }
0020
0021
0022 #define SSP_CHAN_TIMESTAMP(_si) { \
0023 .type = IIO_TIMESTAMP, \
0024 .channel = -1, \
0025 .scan_index = _si, \
0026 .scan_type = { \
0027 .sign = 's', \
0028 .realbits = 64, \
0029 .storagebits = 64, \
0030 }, \
0031 }
0032
0033 #define SSP_MS_PER_S 1000
0034 #define SSP_INVERTED_SCALING_FACTOR 1000000U
0035
0036 #define SSP_FACTOR_WITH_MS \
0037 (SSP_INVERTED_SCALING_FACTOR * SSP_MS_PER_S)
0038
0039 int ssp_common_buffer_postenable(struct iio_dev *indio_dev);
0040
0041 int ssp_common_buffer_postdisable(struct iio_dev *indio_dev);
0042
0043 int ssp_common_process_data(struct iio_dev *indio_dev, void *buf,
0044 unsigned int len, int64_t timestamp);
0045
0046
0047 static inline void ssp_convert_to_freq(u32 time, int *integer_part,
0048 int *fractional)
0049 {
0050 if (time == 0) {
0051 *fractional = 0;
0052 *integer_part = 0;
0053 return;
0054 }
0055
0056 *integer_part = SSP_FACTOR_WITH_MS / time;
0057 *fractional = *integer_part % SSP_INVERTED_SCALING_FACTOR;
0058 *integer_part = *integer_part / SSP_INVERTED_SCALING_FACTOR;
0059 }
0060
0061
0062 static inline int ssp_convert_to_time(int integer_part, int fractional)
0063 {
0064 u64 value;
0065
0066 value = (u64)integer_part * SSP_INVERTED_SCALING_FACTOR + fractional;
0067 if (value == 0)
0068 return 0;
0069
0070 return div64_u64((u64)SSP_FACTOR_WITH_MS, value);
0071 }
0072 #endif