]> git.karo-electronics.de Git - linux-beck.git/commitdiff
iio: st-sensors: add configuration for WhoAmI address
authorGiuseppe Barba <giuseppe.barba@st.com>
Tue, 21 Jul 2015 08:35:41 +0000 (10:35 +0200)
committerJonathan Cameron <jic23@kernel.org>
Thu, 23 Jul 2015 19:43:04 +0000 (20:43 +0100)
This patch permits to configure the WhoAmI register address
because some device could have not a standard address for
this register.

Signed-off-by: Giuseppe Barba <giuseppe.barba@st.com>
Reviewed-by: Denis Ciocca <denis.ciocca@st.com>
Acked-by: Denis Ciocca <denis.ciocca@st.com>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
drivers/iio/accel/st_accel_core.c
drivers/iio/common/st_sensors/st_sensors_core.c
drivers/iio/gyro/st_gyro_core.c
drivers/iio/magnetometer/st_magn_core.c
drivers/iio/pressure/st_pressure_core.c
include/linux/iio/common/st_sensors.h

index 4002e6410444e780f5258813ceb600cd5a9b04c2..12b42f6e70ab90139c428f85d47d846c13c3342a 100644 (file)
@@ -226,6 +226,7 @@ static const struct iio_chan_spec st_accel_16bit_channels[] = {
 static const struct st_sensor_settings st_accel_sensors_settings[] = {
        {
                .wai = ST_ACCEL_1_WAI_EXP,
+               .wai_addr = ST_SENSORS_DEFAULT_WAI_ADDRESS,
                .sensors_supported = {
                        [0] = LIS3DH_ACCEL_DEV_NAME,
                        [1] = LSM303DLHC_ACCEL_DEV_NAME,
@@ -297,6 +298,7 @@ static const struct st_sensor_settings st_accel_sensors_settings[] = {
        },
        {
                .wai = ST_ACCEL_2_WAI_EXP,
+               .wai_addr = ST_SENSORS_DEFAULT_WAI_ADDRESS,
                .sensors_supported = {
                        [0] = LIS331DLH_ACCEL_DEV_NAME,
                        [1] = LSM303DL_ACCEL_DEV_NAME,
@@ -359,6 +361,7 @@ static const struct st_sensor_settings st_accel_sensors_settings[] = {
        },
        {
                .wai = ST_ACCEL_3_WAI_EXP,
+               .wai_addr = ST_SENSORS_DEFAULT_WAI_ADDRESS,
                .sensors_supported = {
                        [0] = LSM330_ACCEL_DEV_NAME,
                },
@@ -437,6 +440,7 @@ static const struct st_sensor_settings st_accel_sensors_settings[] = {
        },
        {
                .wai = ST_ACCEL_4_WAI_EXP,
+               .wai_addr = ST_SENSORS_DEFAULT_WAI_ADDRESS,
                .sensors_supported = {
                        [0] = LIS3LV02DL_ACCEL_DEV_NAME,
                },
@@ -494,6 +498,7 @@ static const struct st_sensor_settings st_accel_sensors_settings[] = {
        },
        {
                .wai = ST_ACCEL_5_WAI_EXP,
+               .wai_addr = ST_SENSORS_DEFAULT_WAI_ADDRESS,
                .sensors_supported = {
                        [0] = LIS331DL_ACCEL_DEV_NAME,
                },
index 8086cbcff87db48a2ad0695d5a031e009b821662..d44bf16808592131fa3af1a5dab89385568230b2 100644 (file)
@@ -479,46 +479,43 @@ int st_sensors_check_device_support(struct iio_dev *indio_dev,
                        int num_sensors_list,
                        const struct st_sensor_settings *sensor_settings)
 {
-       u8 wai;
        int i, n, err;
+       u8 wai;
        struct st_sensor_data *sdata = iio_priv(indio_dev);
 
-       err = sdata->tf->read_byte(&sdata->tb, sdata->dev,
-                                       ST_SENSORS_DEFAULT_WAI_ADDRESS, &wai);
-       if (err < 0) {
-               dev_err(&indio_dev->dev, "failed to read Who-Am-I register.\n");
-               goto read_wai_error;
-       }
-
        for (i = 0; i < num_sensors_list; i++) {
-               if (sensor_settings[i].wai == wai)
+               for (n = 0; n < ST_SENSORS_MAX_4WAI; n++) {
+                       if (strcmp(indio_dev->name,
+                               sensor_settings[i].sensors_supported[n]) == 0) {
+                               break;
+                       }
+               }
+               if (n < ST_SENSORS_MAX_4WAI)
                        break;
        }
-       if (i == num_sensors_list)
-               goto device_not_supported;
+       if (i == num_sensors_list) {
+               dev_err(&indio_dev->dev, "device name %s not recognized.\n",
+                                                       indio_dev->name);
+               return -ENODEV;
+       }
 
-       for (n = 0; n < ARRAY_SIZE(sensor_settings[i].sensors_supported); n++) {
-               if (strcmp(indio_dev->name,
-                               &sensor_settings[i].sensors_supported[n][0]) == 0)
-                       break;
+       err = sdata->tf->read_byte(&sdata->tb, sdata->dev,
+                                       sensor_settings[i].wai_addr, &wai);
+       if (err < 0) {
+               dev_err(&indio_dev->dev, "failed to read Who-Am-I register.\n");
+               return err;
        }
-       if (n == ARRAY_SIZE(sensor_settings[i].sensors_supported)) {
-               dev_err(&indio_dev->dev, "device name \"%s\" and WhoAmI (0x%02x) mismatch",
-                       indio_dev->name, wai);
-               goto sensor_name_mismatch;
+
+       if (sensor_settings[i].wai != wai) {
+               dev_err(&indio_dev->dev, "%s: WhoAmI mismatch (0x%x).\n",
+                                               indio_dev->name, wai);
+               return -EINVAL;
        }
 
        sdata->sensor_settings =
                        (struct st_sensor_settings *)&sensor_settings[i];
 
        return i;
-
-device_not_supported:
-       dev_err(&indio_dev->dev, "device not supported: WhoAmI (0x%x).\n", wai);
-sensor_name_mismatch:
-       err = -ENODEV;
-read_wai_error:
-       return err;
 }
 EXPORT_SYMBOL(st_sensors_check_device_support);
 
index ffe96642b6d049569d73356a1df541782657a912..4b993a5bc9a1196dab5ff91bfa6084ed006ed89b 100644 (file)
@@ -131,6 +131,7 @@ static const struct iio_chan_spec st_gyro_16bit_channels[] = {
 static const struct st_sensor_settings st_gyro_sensors_settings[] = {
        {
                .wai = ST_GYRO_1_WAI_EXP,
+               .wai_addr = ST_SENSORS_DEFAULT_WAI_ADDRESS,
                .sensors_supported = {
                        [0] = L3G4200D_GYRO_DEV_NAME,
                        [1] = LSM330DL_GYRO_DEV_NAME,
@@ -190,6 +191,7 @@ static const struct st_sensor_settings st_gyro_sensors_settings[] = {
        },
        {
                .wai = ST_GYRO_2_WAI_EXP,
+               .wai_addr = ST_SENSORS_DEFAULT_WAI_ADDRESS,
                .sensors_supported = {
                        [0] = L3GD20_GYRO_DEV_NAME,
                        [1] = LSM330D_GYRO_DEV_NAME,
@@ -252,6 +254,7 @@ static const struct st_sensor_settings st_gyro_sensors_settings[] = {
        },
        {
                .wai = ST_GYRO_3_WAI_EXP,
+               .wai_addr = ST_SENSORS_DEFAULT_WAI_ADDRESS,
                .sensors_supported = {
                        [0] = L3GD20_GYRO_DEV_NAME,
                },
index b4bcfb790f49fe2060247b259e141d76bf1aff92..8d7d3a172874c2b11530b2b0928e0038c19e653b 100644 (file)
@@ -192,6 +192,7 @@ static const struct iio_chan_spec st_magn_2_16bit_channels[] = {
 static const struct st_sensor_settings st_magn_sensors_settings[] = {
        {
                .wai = 0, /* This sensor has no valid WhoAmI report 0 */
+               .wai_addr = ST_SENSORS_DEFAULT_WAI_ADDRESS,
                .sensors_supported = {
                        [0] = LSM303DLH_MAGN_DEV_NAME,
                },
@@ -268,6 +269,7 @@ static const struct st_sensor_settings st_magn_sensors_settings[] = {
        },
        {
                .wai = ST_MAGN_1_WAI_EXP,
+               .wai_addr = ST_SENSORS_DEFAULT_WAI_ADDRESS,
                .sensors_supported = {
                        [0] = LSM303DLHC_MAGN_DEV_NAME,
                        [1] = LSM303DLM_MAGN_DEV_NAME,
@@ -346,6 +348,7 @@ static const struct st_sensor_settings st_magn_sensors_settings[] = {
        },
        {
                .wai = ST_MAGN_2_WAI_EXP,
+               .wai_addr = ST_SENSORS_DEFAULT_WAI_ADDRESS,
                .sensors_supported = {
                        [0] = LIS3MDL_MAGN_DEV_NAME,
                },
index e881fa6291e9228a56cc0a7f3d6cf3ee51621855..eb41d2b92c24048ce2c65918bc7d42e03640f19d 100644 (file)
@@ -178,6 +178,7 @@ static const struct iio_chan_spec st_press_lps001wp_channels[] = {
 static const struct st_sensor_settings st_press_sensors_settings[] = {
        {
                .wai = ST_PRESS_LPS331AP_WAI_EXP,
+               .wai_addr = ST_SENSORS_DEFAULT_WAI_ADDRESS,
                .sensors_supported = {
                        [0] = LPS331AP_PRESS_DEV_NAME,
                },
@@ -225,6 +226,7 @@ static const struct st_sensor_settings st_press_sensors_settings[] = {
        },
        {
                .wai = ST_PRESS_LPS001WP_WAI_EXP,
+               .wai_addr = ST_SENSORS_DEFAULT_WAI_ADDRESS,
                .sensors_supported = {
                        [0] = LPS001WP_PRESS_DEV_NAME,
                },
@@ -260,6 +262,7 @@ static const struct st_sensor_settings st_press_sensors_settings[] = {
        },
        {
                .wai = ST_PRESS_LPS25H_WAI_EXP,
+               .wai_addr = ST_SENSORS_DEFAULT_WAI_ADDRESS,
                .sensors_supported = {
                        [0] = LPS25H_PRESS_DEV_NAME,
                },
index 2c476acb87d92784529690c6dd1b5d299a9aa2fe..3c17cd7fdf06f08b9c8a85c502f592e4124e6053 100644 (file)
@@ -166,6 +166,7 @@ struct st_sensor_transfer_function {
 /**
  * struct st_sensor_settings - ST specific sensor settings
  * @wai: Contents of WhoAmI register.
+ * @wai_addr: The address of WhoAmI register.
  * @sensors_supported: List of supported sensors by struct itself.
  * @ch: IIO channels for the sensor.
  * @odr: Output data rate register and ODR list available.
@@ -179,6 +180,7 @@ struct st_sensor_transfer_function {
  */
 struct st_sensor_settings {
        u8 wai;
+       u8 wai_addr;
        char sensors_supported[ST_SENSORS_MAX_4WAI][ST_SENSORS_MAX_NAME];
        struct iio_chan_spec *ch;
        int num_ch;