Skip to content

Fix orientation issue using 4.8 kernel

Bastien Nocera requested to merge github/fork/spandruvada/master into master

Created by: spandruvada

Using 4.8-rc kernel orientation got flipped. The right-up became normal and normal became right-up. The reason for this is that orientation code of iio-sensor-proxy observes x and y swapped (actually they are not in the data provided by IIO).

Although it is triggered by some kernel change, but the reliance on g_dir_read_name() to get the correct order of channels is not correct. We should look at the in_xxx_x_index field and calculate correct byte offset in the iio buffer data.

For example with 4.8 kernel: from log with added index location printed

** (process:4945): DEBUG: Built channel array for in_accel_y: index: 1, is signed: 1, bytes: 4, bits_used: 32, shift: 0, mask: 0x0, be: 0 ** (process:4945): DEBUG: Built channel array for in_accel_x: index: 0, is signed: 1, bytes: 4, bits_used: 32, shift: 0, mask: 0x0, be: 0 ** (process:4945): DEBUG: Built channel array for in_accel_z: index: 2, is signed: 1, bytes: 4, bits_used: 32, shift: 0, mask: 0x0, be: 0

(Here in_accel_y appeared before in_accel_x by g_dir_read_name(), because of that channel array ordering is wrong hence location was calculated wrong as below) ... ... ** (process:4945): DEBUG: process_scan_1: channel_index: 1, chan_name: in_accel_x, channel_data_index: 0 location: 4 ** (process:4945): DEBUG: process_scan_1: channel_index: 0, chan_name: in_accel_y, channel_data_index: 1 location: 0 ** (process:4945): DEBUG: process_scan_1: channel_index: 2, chan_name: in_accel_z, channel_data_index: 2 location: 8 ** (process:4945): DEBUG: Read from IIO: -880449, 32851, -457812

To fix this we need to calculate the byte offset location using channel_index not in the order they are returned by g_dir_read_name(). The easiest fix is to sort the array of channels in build_channel_array() based on index. Also added some debug to print index and location.

After the fix, the above log will change to: ** (process:4674): DEBUG: Built channel array for in_accel_x: index: 0, is signed: 1, bytes: 4, bits_used: 32, shift: 0, mask: 0x0, be: 0 ** (process:4674): DEBUG: Built channel array for in_accel_y: index: 1, is signed: 1, bytes: 4, bits_used: 32, shift: 0, mask: 0x0, be: 0 ** (process:4674): DEBUG: Built channel array for in_accel_z: index: 2, is signed: 1, bytes: 4, bits_used: 32, shift: 0, mask: 0x0, be: 0

(Sorted above, so location of byte offset is correct)

** (process:4674): DEBUG: process_scan_1: channel_index: 0, chan_name: in_accel_x, channel_data_index: 0 location: 0 ** (process:4674): DEBUG: process_scan_1: channel_index: 1, chan_name: in_accel_y, channel_data_index: 1 location: 4 ** (process:4674): DEBUG: process_scan_1: channel_index: 2, chan_name: in_accel_z, channel_data_index: 2 location: 8 ** (process:4674): DEBUG: Read from IIO: 34804, -878496, -448046

Signed-off-by: Srinivas Pandruvada srinivas.pandruvada@linux.intel.com

Merge request reports