iio:common:ssp_sensors fix warnings due to 32 bit instead of 64 bit passed to do_div
[deliverable/linux.git] / drivers / iio / common / ssp_sensors / ssp_iio_sensor.h
CommitLineData
7e3a8b44
KW
1#ifndef __SSP_IIO_SENSOR_H__
2#define __SSP_IIO_SENSOR_H__
3
4#define SSP_CHANNEL_AG(_type, _mod, _index) \
5{ \
6 .type = _type,\
7 .modified = 1,\
8 .channel2 = _mod,\
9 .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SAMP_FREQ),\
10 .scan_index = _index,\
11 .scan_type = {\
12 .sign = 's',\
13 .realbits = 16,\
14 .storagebits = 16,\
15 .shift = 0,\
16 .endianness = IIO_LE,\
17 },\
18}
19
20/* It is defined here as it is a mixed timestamp */
21#define SSP_CHAN_TIMESTAMP(_si) { \
22 .type = IIO_TIMESTAMP, \
23 .channel = -1, \
24 .scan_index = _si, \
25 .scan_type = { \
26 .sign = 's', \
27 .realbits = 64, \
28 .storagebits = 64, \
29 }, \
30}
31
32#define SSP_MS_PER_S 1000
67460e8c 33#define SSP_INVERTED_SCALING_FACTOR 1000000U
7e3a8b44
KW
34
35#define SSP_FACTOR_WITH_MS \
36 (SSP_INVERTED_SCALING_FACTOR * SSP_MS_PER_S)
37
38int ssp_common_buffer_postenable(struct iio_dev *indio_dev);
39
40int ssp_common_buffer_postdisable(struct iio_dev *indio_dev);
41
42int ssp_common_process_data(struct iio_dev *indio_dev, void *buf,
43 unsigned int len, int64_t timestamp);
44
45/* Converts time in ms to frequency */
46static inline void ssp_convert_to_freq(u32 time, int *integer_part,
47 int *fractional)
48{
49 if (time == 0) {
50 *fractional = 0;
51 *integer_part = 0;
52 return;
53 }
54
55 *integer_part = SSP_FACTOR_WITH_MS / time;
67460e8c
JC
56 *fractional = *integer_part % SSP_INVERTED_SCALING_FACTOR;
57 *integer_part = *integer_part / SSP_INVERTED_SCALING_FACTOR;
7e3a8b44
KW
58}
59
60/* Converts frequency to time in ms */
61static inline int ssp_convert_to_time(int integer_part, int fractional)
62{
63 u64 value;
64
67460e8c 65 value = (u64)integer_part * SSP_INVERTED_SCALING_FACTOR + fractional;
7e3a8b44
KW
66 if (value == 0)
67 return 0;
68
67460e8c 69 return div64_u64((u64)SSP_FACTOR_WITH_MS, value);
7e3a8b44
KW
70}
71#endif /* __SSP_IIO_SENSOR_H__ */
This page took 0.025802 seconds and 5 git commands to generate.