staging:iio:adis16400: Fix product id check
authorLars-Peter Clausen <lars@metafoo.de>
Tue, 30 Oct 2012 10:26:00 +0000 (10:26 +0000)
committerJonathan Cameron <jic23@kernel.org>
Sun, 4 Nov 2012 15:55:37 +0000 (15:55 +0000)
The product id check currently ANDs the read id with 0xF000 and compares the
result to the product id from the chip info. Since none of the product ids in
the chip info table end in 0x000 the check will always fail. Furthermore it is
also wrong, the product id in the PROD_ID register will always match the part
number of the device.

Some of the ADIS16XXX devices are identical from a software point of
view with the product id register having a different content. If we keep the
current scheme of storing the product id in the chip info table this would
require us to have multiple almost identical chip info table entries. So instead
this patch changes the code to parse the product id from the device name.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
drivers/staging/iio/imu/adis16400.h
drivers/staging/iio/imu/adis16400_core.c

index 07a6aea75fed646eb43ef88914b5c91428c78e00..7a105e9664643a06b25767580e2964991683a379 100644 (file)
 struct adis16400_chip_info {
        const struct iio_chan_spec *channels;
        const int num_channels;
-       const int product_id;
        const long flags;
        unsigned int gyro_scale_micro;
        unsigned int accel_scale_micro;
index 86192df2f79d805103d58320944e8c393daf710d..b876d823eb52250a30f60f8d2cdc81f9a8ddc095 100644 (file)
@@ -415,6 +415,7 @@ static int adis16400_initial_setup(struct iio_dev *indio_dev)
 {
        int ret;
        u16 prod_id, smp_prd;
+       unsigned int device_id;
        struct adis16400_state *st = iio_priv(indio_dev);
 
        /* use low spi speed for init if the device has a slow mode */
@@ -454,8 +455,11 @@ static int adis16400_initial_setup(struct iio_dev *indio_dev)
                if (ret)
                        goto err_ret;
 
-               if ((prod_id & 0xF000) != st->variant->product_id)
-                       dev_warn(&indio_dev->dev, "incorrect id");
+               sscanf(indio_dev->name, "adis%u\n", &device_id);
+
+               if (prod_id != device_id)
+                       dev_warn(&indio_dev->dev, "Device ID(%u) and product ID(%u) do not match.",
+                                       device_id, prod_id);
 
                dev_info(&indio_dev->dev, "%s: prod_id 0x%04x at CS%d (irq %d)\n",
                       indio_dev->name, prod_id,
@@ -1149,7 +1153,6 @@ static struct adis16400_chip_info adis16400_chips[] = {
                .channels = adis16350_channels,
                .num_channels = ARRAY_SIZE(adis16350_channels),
                .flags = ADIS16400_HAS_PROD_ID | ADIS16400_HAS_SLOW_MODE,
-               .product_id = 0x3FE8,
                .gyro_scale_micro = IIO_DEGREE_TO_RAD(50000), /* 0.05 deg/s */
                .accel_scale_micro = IIO_G_TO_M_S_2(3333), /* 3.333 mg */
                .temp_scale_nano = 136000000, /* 0.136 C */
@@ -1162,7 +1165,6 @@ static struct adis16400_chip_info adis16400_chips[] = {
                .channels = adis16350_channels,
                .num_channels = ARRAY_SIZE(adis16350_channels),
                .flags = ADIS16400_HAS_PROD_ID | ADIS16400_HAS_SLOW_MODE,
-               .product_id = 0x3FEA,
                .gyro_scale_micro = IIO_DEGREE_TO_RAD(50000), /* 0.05 deg/s */
                .accel_scale_micro = IIO_G_TO_M_S_2(333), /* 0.333 mg */
                .temp_scale_nano = 136000000, /* 0.136 C */
@@ -1175,7 +1177,6 @@ static struct adis16400_chip_info adis16400_chips[] = {
                .channels = adis16350_channels,
                .num_channels = ARRAY_SIZE(adis16350_channels),
                .flags = ADIS16400_HAS_PROD_ID | ADIS16400_HAS_SLOW_MODE,
-               .product_id = 0x3FEC,
                .gyro_scale_micro = IIO_DEGREE_TO_RAD(50000), /* 0.05 deg/s */
                .accel_scale_micro = IIO_G_TO_M_S_2(1000), /* 1 mg */
                .temp_scale_nano = 136000000, /* 0.136 C */
@@ -1188,7 +1189,6 @@ static struct adis16400_chip_info adis16400_chips[] = {
                .channels = adis16350_channels,
                .num_channels = ARRAY_SIZE(adis16350_channels),
                .flags = ADIS16400_HAS_PROD_ID | ADIS16400_HAS_SLOW_MODE,
-               .product_id = 0x3FED,
                .gyro_scale_micro = IIO_DEGREE_TO_RAD(50000), /* 0.05 deg/s */
                .accel_scale_micro = IIO_G_TO_M_S_2(1000), /* 1 mg */
                .temp_scale_nano = 136000000, /* 0.136 C */
@@ -1201,7 +1201,6 @@ static struct adis16400_chip_info adis16400_chips[] = {
                .channels = adis16400_channels,
                .num_channels = ARRAY_SIZE(adis16400_channels),
                .flags = ADIS16400_HAS_PROD_ID | ADIS16400_HAS_SLOW_MODE,
-               .product_id = 0x4015,
                .gyro_scale_micro = IIO_DEGREE_TO_RAD(50000), /* 0.05 deg/s */
                .accel_scale_micro = IIO_G_TO_M_S_2(3333), /* 3.333 mg */
                .default_scan_mask = 0xFFF,