drivers: bmi088: Fix build for post-Linux v6.2

BMI088 driver was failing to build for Kernel version
> 6.2 and the following error is seen:

drivers/bmi088/bmi088_core.c:1043:42: error: 'struct iio_dev'
has no member named 'mlock'
  mutex_lock(&st->snsrs[hw].bmi_iio->mlock);

mlock field is moved from indio_dev to iio_dev_opaque
structure from v6.2 onwards.  Instead of using kernel
version, use conftest.sh script which checks for the
'mlock' field in iio_dev_opaque structure or not.

Bug 4190630

Change-Id: Icc540edd916718d30460b314600c20e70144b1d6
Signed-off-by: Gautham Srinivasan <gauthams@nvidia.com>
Reviewed-on: https://git-master.nvidia.com/r/c/linux-nv-oot/+/2983266
Reviewed-by: Jonathan Hunter <jonathanh@nvidia.com>
Tested-by: Jonathan Hunter <jonathanh@nvidia.com>
GVS: Gerrit_Virtual_Submit <buildbot_gerritrpt@nvidia.com>
This commit is contained in:
Gautham Srinivasan
2023-09-21 18:41:51 +00:00
committed by mobile promotions
parent 6323c46280
commit 6fec90c658
5 changed files with 48 additions and 57 deletions

View File

@@ -1039,15 +1039,11 @@ static irqreturn_t bmi_irq_thread(int irq, void *dev_id)
goto out;
}
#if KERNEL_VERSION(6, 2, 0) >= LINUX_VERSION_CODE
mutex_lock(&st->snsrs[hw].bmi_iio->mlock);
#endif
mutex_lock(BMI_MUTEX(st->snsrs[hw].bmi_iio));
ret = bmi_i2c_rd(st, hw, reg, sizeof(sample), sample);
#if KERNEL_VERSION(6, 2, 0) >= LINUX_VERSION_CODE
mutex_unlock(&st->snsrs[hw].bmi_iio->mlock);
#endif
mutex_unlock(BMI_MUTEX(st->snsrs[hw].bmi_iio));
if (!ret) {
bmi_iio_push_buf(st->snsrs[hw].bmi_iio, sample,
@@ -1391,9 +1387,7 @@ static int __maybe_unused bmi_suspend(struct device *dev)
st->suspend_en_st = 0;
for (i = 0; i < st->hw_n; i++) {
#if KERNEL_VERSION(6, 2, 0) >= LINUX_VERSION_CODE
mutex_lock(&st->snsrs[i].bmi_iio->mlock);
#endif
mutex_lock(BMI_MUTEX(st->snsrs[i].bmi_iio));
/* check if sensor is enabled to begin with */
old_en_st = bmi_enable(st, st->snsrs[i].cfg.snsr_id, -1,
false);
@@ -1405,9 +1399,7 @@ static int __maybe_unused bmi_suspend(struct device *dev)
ret |= temp_ret;
}
#if KERNEL_VERSION(6, 2, 0) >= LINUX_VERSION_CODE
mutex_unlock(&st->snsrs[i].bmi_iio->mlock);
#endif
mutex_unlock(BMI_MUTEX(st->snsrs[i].bmi_iio));
}
return ret;
@@ -1421,15 +1413,11 @@ static int __maybe_unused bmi_resume(struct device *dev)
int ret = 0;
for (i = 0; i < st->hw_n; i++) {
#if KERNEL_VERSION(6, 2, 0) >= LINUX_VERSION_CODE
mutex_lock(&st->snsrs[i].bmi_iio->mlock);
#endif
mutex_lock(BMI_MUTEX(st->snsrs[i].bmi_iio));
if (st->suspend_en_st & (1 << st->snsrs[i].cfg.snsr_id))
ret |= bmi_enable(st, st->snsrs[i].cfg.snsr_id, 1,
false);
#if KERNEL_VERSION(6, 2, 0) >= LINUX_VERSION_CODE
mutex_unlock(&st->snsrs[i].bmi_iio->mlock);
#endif
mutex_unlock(BMI_MUTEX(st->snsrs[i].bmi_iio));
}
st->sts &= ~BMI_STS_SUSPEND;
@@ -1447,17 +1435,13 @@ static void bmi_shutdown(struct i2c_client *client)
st->sts |= BMI_STS_SHUTDOWN;
for (i = 0; i < st->hw_n; i++) {
if (st->iio_init_done[i])
#if KERNEL_VERSION(6, 2, 0) >= LINUX_VERSION_CODE
mutex_lock(&st->snsrs[i].bmi_iio->mlock);
#endif
mutex_lock(BMI_MUTEX(st->snsrs[i].bmi_iio));
if (bmi_enable(st, st->snsrs[i].cfg.snsr_id, -1, false))
bmi_enable(st, st->snsrs[i].cfg.snsr_id, 0, false);
if (st->iio_init_done[i]) {
#if KERNEL_VERSION(6, 2, 0) >= LINUX_VERSION_CODE
mutex_unlock(&st->snsrs[i].bmi_iio->mlock);
#endif
mutex_unlock(BMI_MUTEX(st->snsrs[i].bmi_iio));
}
}
}

View File

@@ -231,14 +231,10 @@ static ssize_t bmi_iio_attr_store(struct device *dev,
if (!indio_dev || !st || !this_attr)
return -EINVAL;
#if KERNEL_VERSION(6, 2, 0) >= LINUX_VERSION_CODE
mutex_lock(&indio_dev->mlock);
#endif
mutex_lock(BMI_MUTEX(indio_dev));
if (*st->fn_dev->sts & (BMI_STS_SHUTDOWN | BMI_STS_SUSPEND)) {
#if KERNEL_VERSION(6, 2, 0) >= LINUX_VERSION_CODE
mutex_unlock(&indio_dev->mlock);
#endif
mutex_unlock(BMI_MUTEX(indio_dev));
return -EPERM;
}
@@ -269,9 +265,7 @@ static ssize_t bmi_iio_attr_store(struct device *dev,
ret = -EINVAL;
}
#if KERNEL_VERSION(6, 2, 0) >= LINUX_VERSION_CODE
mutex_unlock(&indio_dev->mlock);
#endif
mutex_unlock(BMI_MUTEX(indio_dev));
return ret;
}
@@ -294,17 +288,13 @@ static ssize_t bmi_iio_attr_show(struct device *dev,
st->cfg->part, st->cfg->name);
case BMI_ATTR_MATRIX:
#if KERNEL_VERSION(6, 2, 0) >= LINUX_VERSION_CODE
mutex_lock(&indio_dev->mlock);
#endif
mutex_lock(BMI_MUTEX(indio_dev));
for (i = 0; i < 8; i++)
t += snprintf(buf + t, PAGE_SIZE - t, "%hhd,",
st->cfg->matrix[i]);
t += snprintf(buf + t, PAGE_SIZE - t, "%hhd\n",
st->cfg->matrix[i]);
#if KERNEL_VERSION(6, 2, 0) >= LINUX_VERSION_CODE
mutex_unlock(&indio_dev->mlock);
#endif
mutex_unlock(BMI_MUTEX(indio_dev));
return t;
@@ -370,13 +360,9 @@ static int bmi_iio_read_raw(struct iio_dev *indio_dev,
struct bmi_iio_state *st = iio_priv(indio_dev);
int ret;
#if KERNEL_VERSION(6, 2, 0) >= LINUX_VERSION_CODE
mutex_lock(&indio_dev->mlock);
#endif
mutex_lock(BMI_MUTEX(indio_dev));
if (*st->fn_dev->sts & (BMI_STS_SHUTDOWN | BMI_STS_SUSPEND)) {
#if KERNEL_VERSION(6, 2, 0) >= LINUX_VERSION_CODE
mutex_unlock(&indio_dev->mlock);
#endif
mutex_unlock(BMI_MUTEX(indio_dev));
return -EPERM;
}
@@ -419,9 +405,7 @@ static int bmi_iio_read_raw(struct iio_dev *indio_dev,
}
out:
#if KERNEL_VERSION(6, 2, 0) >= LINUX_VERSION_CODE
mutex_unlock(&indio_dev->mlock);
#endif
mutex_unlock(BMI_MUTEX(indio_dev));
return ret;
}
@@ -433,13 +417,9 @@ static int bmi_iio_write_raw(struct iio_dev *indio_dev,
struct bmi_iio_state *st = iio_priv(indio_dev);
int ret = 0;
#if KERNEL_VERSION(6, 2, 0) >= LINUX_VERSION_CODE
mutex_lock(&indio_dev->mlock);
#endif
mutex_lock(BMI_MUTEX(indio_dev));
if (*st->fn_dev->sts & (BMI_STS_SHUTDOWN | BMI_STS_SUSPEND)) {
#if KERNEL_VERSION(6, 2, 0) >= LINUX_VERSION_CODE
mutex_unlock(&indio_dev->mlock);
#endif
mutex_unlock(BMI_MUTEX(indio_dev));
return -EPERM;
}
@@ -470,9 +450,7 @@ static int bmi_iio_write_raw(struct iio_dev *indio_dev,
}
out:
#if KERNEL_VERSION(6, 2, 0) >= LINUX_VERSION_CODE
mutex_unlock(&indio_dev->mlock);
#endif
mutex_unlock(BMI_MUTEX(indio_dev));
return ret;
}

View File

@@ -5,12 +5,21 @@
#ifndef _BMI_IIO_H_
#define _BMI_IIO_H_
#include <nvidia/conftest.h>
#include <linux/device.h>
#include <linux/iio/iio.h>
#include <linux/iio/iio-opaque.h>
#define BMI_STS_SHUTDOWN (1 << 0)
#define BMI_STS_SUSPEND (1 << 1)
#if defined(NV_IIO_DEV_OPAQUE_HAS_LOCK)
#define BMI_MUTEX(indio_dev) (&to_iio_dev_opaque(indio_dev)->mlock)
#else
#define BMI_MUTEX(indio_dev) (&indio_dev->mlock)
#endif
struct bmi_float {
int ival;
int fval;

View File

@@ -89,6 +89,7 @@ endef
#
NV_CONFTEST_FUNCTION_COMPILE_TESTS += devm_thermal_of_zone_register
NV_CONFTEST_FUNCTION_COMPILE_TESTS += iio_dev_opaque_has_mlock
NV_CONFTEST_GENERIC_COMPILE_TESTS ?=
NV_CONFTEST_MACRO_COMPILE_TESTS ?=
NV_CONFTEST_SYMBOL_COMPILE_TESTS ?=

View File

@@ -6310,6 +6310,25 @@ compile_test() {
compile_check_conftest "$CODE" "NV_DEVM_THERMAL_OF_ZONE_REGISTER_PRESENT" "" "functions"
;;
iio_dev_opaque_has_mlock)
#
# Determine if the 'iio_dev_opaque' structure has 'mlock' field.
# 'mlock' field is moved from 'indio_dev' to 'iio_dev_opaque'
# structure.
#
# Added in commit 16afe125b53f88b855d2713c8ba253d905dcf3cc (iio: core:
# move 'mlock' to 'struct iio_dev_opaque') in v6.2 2022-10-12
CODE="
#include <linux/iio/iio.h>
#include <linux/iio/iio-opaque.h>
int conftest_iio_dev_opaque_has_mlock(void) {
return offsetof(struct iio_dev_opaque, mlock);
}"
compile_check_conftest "$CODE" "NV_IIO_DEV_OPAQUE_HAS_LOCK" "" "types"
;;
# When adding a new conftest entry, please use the correct format for
# specifying the relevant upstream Linux kernel commit.
#