Accelerometer test: supports new sysfs path under kernel 3.18

In kernel 3.18 or later, it uses separated iio devices for
each accelerometer. For example:
  - /sys/bus/iio/devices/iio:device0
  - /sys/bus/iio/devices/iio:device1

For each sensor, it has:
  - in_accel_(x|y|z)_calibbias: offset calculated in factory to
    calibrate the sensor (in 1/1024 g)
  - in_accel_(x|y|z)_raw: post calibration value (in 1/16384 g)
  - scale: in the range (in g) to send to the sensor
  - location: base or lid

The physical data is _raw * scale.
For instance, if in_accel_z_raw == 16512 and scale == 0.000598550,
the physical value is 9.8832576 m/s^2.
In this case, scale == 2g >> 15 where 1g = 9.80665 m/s^2.

One of the major difference is that _raw will be normalized
to 16-bit now. For example, if we're using the following
configuration in the underlying accelerometer:
  - Resolution: 12 bits
  - Range: +/- 2g

The ideal output of 1g is 1024 but it will be normalized
to 16384 now. However, the _calibbias is still in 1/1024 g.
To simply the flow of calculating _calibbias, the factory test
will reserve the normalization from 1/16384 g to 1/1024 g.

In release image, it will apply calibration data from VPD:
  1. Read /sys/bus/iio/devices/iio:deviceX/location.
  2. If it's 'base', apply the settings from
     in_accel_(x|y|z)_base_calibbias in VPD to
     /sys/bus/iio/devices/iio:deviceX/in_accel_(x|y|z)_calibbias.
  3. If it's 'lid', apply the settings from
     in_accel_(x|y|z)_lid_calibbias in VPD to
     /sys/bus/iio/devices/iio:deviceX/in_accel_(x|y|z)_calibbias.

There is one more argument: location, needs to be specified for
acceleromters_calibration pytest. The following are usages examples:

    OperatorTest(
       id='BaseAccelerometersCalibration',
       label_zh=u'母板加速度计校准',
       pytest_name='accelerometers_calibration',
       dargs={'orientation': {
                  'in_accel_x': 0,
                  'in_accel_y': 0,
                  'in_accel_z': 1},
              'spec_offset': (128, 102),
              'spec_ideal_values': (0, 1024),
              'location': 'base'})

    OperatorTest(
       id='LidAccelerometersCalibration',
       label_zh=u'上盖加速度计校准',
       pytest_name='accelerometers_calibration',
       dargs={'orientation': {
                  'in_accel_x': 0,
                  'in_accel_y': 0,
                  'in_accel_z': -1},
              'spec_offset': (128, 102),
              'spec_ideal_values': (0, 1024),
              'location': 'lid'})

    OperatorTest(
        id='accelerometers_lid_angle',
        label_zh=u'上盖角度测试',
        pytest_name='accelerometers_lid_angle',
        dargs={'angle': 180,
               'tolerance': 5,
               'spec_offset': (128, 102),
               'spec_ideal_values': (0, 1024)})

BUG=chrome-os-partner:40177
TEST=Run calibration/lid_angle test.
     Also verify the following VPD fields are generated.
       - in_accel_x_base_calibbias
       - in_accel_y_base_calibbias
       - in_accel_z_base_calibbias
       - in_accel_x_lid_calibbias
       - in_accel_y_lid_calibbias
       - in_accel_z_lid_calibbias

Change-Id: I219731ac94f243656df285b812f064c1670ddbfe
Reviewed-on: https://chromium-review.googlesource.com/292531
Reviewed-by: Bowgo Tsai <bowgotsai@chromium.org>
Commit-Queue: Kevin Cheng <kevin.cheng@intel.com>
Tested-by: Kevin Cheng <kevin.cheng@intel.com>
3 files changed