From 616dc6ff4e847a035e4da90ea6a07476febc2db3 Mon Sep 17 00:00:00 2001 From: "Shen Jianping (CC-DA/ESI6)" Date: Tue, 1 Aug 2023 12:23:22 +0200 Subject: [PATCH] Release v0.8.2 Release v0.8.2 Co-Authored-By: Markus Lochmann <100404916+ma-loc@users.noreply.github.com> --- drivers/input/sensors/smi230/Kbuild | 30 +++ drivers/input/sensors/smi230/Makefile | 32 +-- .../input/sensors/smi230/smi230_acc_driver.c | 199 ++++++++---------- drivers/input/sensors/smi230/smi230_defs.h | 7 +- drivers/input/sensors/smi230/smi230_driver.h | 2 +- drivers/input/sensors/smi230/smi230_gyro.c | 3 +- .../input/sensors/smi230/smi230_gyro_driver.c | 128 ++++------- .../input/sensors/smi230/smi230_i2c_driver.c | 14 +- 8 files changed, 184 insertions(+), 231 deletions(-) create mode 100644 drivers/input/sensors/smi230/Kbuild diff --git a/drivers/input/sensors/smi230/Kbuild b/drivers/input/sensors/smi230/Kbuild new file mode 100644 index 0000000..2671d9c --- /dev/null +++ b/drivers/input/sensors/smi230/Kbuild @@ -0,0 +1,30 @@ +# SPDX-License-Identifier: GPL-2.0-only +# +# SMI230 driver +# + +ifneq ($(CONFIG_BOSCH_DRIVER_LOG_FUNC),n) + EXTRA_CFLAGS += -DBOSCH_DRIVER_LOG_FUNC +endif + + +obj-$(CONFIG_INPUT_SMI230) += smi230.o +smi230-objs := smi230_log.o smi230_acc.o smi230_gyro.o + +ifeq ($(CONFIG_SMI230_DATA_SYNC),y) + smi230-objs += smi230_data_sync.o +endif + +ifeq ($(CONFIG_SMI230_ACC_DRIVER),y) + smi230-objs += smi230_acc_driver.o +endif + +ifeq ($(CONFIG_SMI230_GYRO_DRIVER),y) + smi230-objs += smi230_gyro_driver.o +endif + +ifeq ($(CONFIG_SMI230_I2C),y) + smi230-objs += smi230_i2c_driver.o +else + smi230-objs += smi230_spi_driver.o +endif diff --git a/drivers/input/sensors/smi230/Makefile b/drivers/input/sensors/smi230/Makefile index b380b83..9a58998 100644 --- a/drivers/input/sensors/smi230/Makefile +++ b/drivers/input/sensors/smi230/Makefile @@ -1,29 +1,13 @@ +# SPDX-License-Identifier: GPL-2.0-only # -# Makefile for Bosch sensor driver. +# Makefile for Bosch SMI230 driver # -ifneq ($(CONFIG_BOSCH_DRIVER_LOG_FUNC),n) - EXTRA_CFLAGS += -DBOSCH_DRIVER_LOG_FUNC -endif +all: + $(MAKE) -C $(KERNEL_SRC) M=$(PWD) modules +modules_install: + $(MAKE) -C $(KERNEL_SRC) M=$(PWD) modules_install -obj-$(CONFIG_INPUT_SMI230) += smi230.o -smi230-objs := smi230_log.o smi230_acc.o smi230_gyro.o - -ifeq ($(CONFIG_SMI230_DATA_SYNC),y) - smi230-objs += smi230_data_sync.o -endif - -ifeq ($(CONFIG_SMI230_ACC_DRIVER),y) - smi230-objs += smi230_acc_driver.o -endif - -ifeq ($(CONFIG_SMI230_GYRO_DRIVER),y) - smi230-objs += smi230_gyro_driver.o -endif - -ifeq ($(CONFIG_SMI230_I2C),y) - smi230-objs += smi230_i2c_driver.o -else - smi230-objs += smi230_spi_driver.o -endif +clean: + $(MAKE) -C $(KERNEL_SRC) M=$(PWD) clean diff --git a/drivers/input/sensors/smi230/smi230_acc_driver.c b/drivers/input/sensors/smi230/smi230_acc_driver.c index a8de939..c405bee 100644 --- a/drivers/input/sensors/smi230/smi230_acc_driver.c +++ b/drivers/input/sensors/smi230/smi230_acc_driver.c @@ -44,47 +44,43 @@ * **/ -#include -#include -#include -#include #include #include +#include +#include +#include #include #include #include #include +#include +#include -#include "smi230_driver.h" +#include "smi230.h" #include "smi230_data_sync.h" - -#define MODULE_TAG MODULE_NAME +#include "smi230_driver.h" #include "smi230_log.h" -#include "smi230.h" -#define SMI230_ACC_ENABLE_INT2 1 -#define SMI230_MIN_VALUE -32768 -#define SMI230_MAX_VALUE 32767 +#define SMI230_MIN_VALUE -32768 +#define SMI230_MAX_VALUE 32767 -#ifdef CONFIG_SMI230_ACC_FIFO #define SMI230_MAX_ACC_FIFO_BYTES 1024 /*1024 bytes fifo host max 147 data frames*/ #define SMI230_MAX_ACC_FIFO_FRAME 147 static uint8_t fifo_buf[SMI230_MAX_ACC_FIFO_BYTES]; -#endif +static struct smi230_sensor_data fifo_accel_data[SMI230_MAX_ACC_FIFO_FRAME]; struct smi230_client_data { struct device *dev; struct input_dev *input; int IRQ; int gpio_pin; - struct work_struct irq_work; uint64_t timestamp; + uint64_t timestamp_old; }; static struct smi230_dev *p_smi230_dev; -static struct workqueue_struct *p_workqueue; static struct smi230_anymotion_cfg anymotion_cfg; static struct smi230_orient_cfg orientation_cfg; static struct smi230_no_motion_cfg no_motion_cfg; @@ -1241,16 +1237,17 @@ static ssize_t smi230_acc_no_motion_enable_store(struct device *dev, smi230_set_no_motion_config(&no_motion_cfg, p_smi230_dev); -#ifdef CONFIG_SMI230_ACC_INT1 - int_config.accel_int_config_1.int_type = SMI230_ACCEL_NO_MOTION_INT; - err |= smi230_acc_set_int_config(&int_config.accel_int_config_1, - p_smi230_dev); -#endif -#ifdef CONFIG_SMI230_ACC_INT2 - int_config.accel_int_config_2.int_type = SMI230_ACCEL_NO_MOTION_INT; - err |= smi230_acc_set_int_config(&int_config.accel_int_config_2, - p_smi230_dev); -#endif + if (IS_ENABLED(CONFIG_SMI230_ACC_INT1)) { + int_config.accel_int_config_1.int_type = + SMI230_ACCEL_NO_MOTION_INT; + err |= smi230_acc_set_int_config(&int_config.accel_int_config_1, + p_smi230_dev); + } else if (IS_ENABLED(CONFIG_SMI230_ACC_INT2)) { + int_config.accel_int_config_2.int_type = + SMI230_ACCEL_NO_MOTION_INT; + err |= smi230_acc_set_int_config(&int_config.accel_int_config_2, + p_smi230_dev); + } if (err != SMI230_OK) { PERR("set no_motion interrupt failed"); @@ -1390,7 +1387,8 @@ smi230_acc_no_motion_duration_store(struct device *dev, } static ssize_t smi230_acc_show_self_test(struct device *dev, - struct device_attribute *attr, char *buf) + struct device_attribute *attr, + char *buf) { int err, rslt; @@ -1580,7 +1578,6 @@ static int smi230_input_init(struct smi230_client_data *client_data) return err; } -#ifdef CONFIG_SMI230_DATA_SYNC static void smi230_data_sync_ready_handle(struct smi230_client_data *client_data) { @@ -1614,7 +1611,6 @@ smi230_data_sync_ready_handle(struct smi230_client_data *client_data) input_sync(client_data->input); } -#endif static void smi230_orientation_handle(struct smi230_client_data *client_data) { @@ -1751,9 +1747,6 @@ static void smi230_low_g_handle(struct smi230_client_data *client_data) PINFO("low-g detected."); } -#ifdef CONFIG_SMI230_ACC_FIFO -static struct smi230_sensor_data fifo_accel_data[SMI230_MAX_ACC_FIFO_FRAME]; - static void smi230_acc_fifo_handle(struct smi230_client_data *client_data) { struct smi230_fifo_frame fifo; @@ -1776,53 +1769,6 @@ static void smi230_acc_fifo_handle(struct smi230_client_data *client_data) return; } -#if 0 - PINFO("ACC FIFO length %d", fifo.length); - PINFO("===================="); - PINFO("ACC FIFO data %d", fifo.data[0]); - PINFO("ACC FIFO data %d", fifo.data[1]); - PINFO("ACC FIFO data %d", fifo.data[2]); - PINFO("ACC FIFO data %d", fifo.data[3]); - PINFO("ACC FIFO data %d", fifo.data[4]); - PINFO("ACC FIFO data %d", fifo.data[5]); - PINFO("ACC FIFO data %d", fifo.data[6]); - PINFO("--------------------"); -#endif - -#if 0 - /* this event shall never be mixed with sensor data */ - /* this event here is to indicate IRQ timing if needed */ - input_event(client_data->input, EV_MSC, MSC_RAW, (int)fifo.length); - input_sync(client_data->input); -#endif - - switch (p_smi230_dev->accel_cfg.odr) { - case SMI230_ACCEL_ODR_12_5_HZ: - tsamp = 80000000; - break; - case SMI230_ACCEL_ODR_25_HZ: - tsamp = 40000000; - break; - case SMI230_ACCEL_ODR_50_HZ: - tsamp = 20000000; - break; - case SMI230_ACCEL_ODR_100_HZ: - tsamp = 10000000; - break; - case SMI230_ACCEL_ODR_200_HZ: - tsamp = 5000000; - break; - case SMI230_ACCEL_ODR_400_HZ: - tsamp = 2500000; - break; - case SMI230_ACCEL_ODR_800_HZ: - tsamp = 1250000; - break; - case SMI230_ACCEL_ODR_1600_HZ: - tsamp = 625000; - break; - } - /* make sure all frames are read out, * the actual frame numbers will be returned * through fifo_length itself*/ @@ -1830,7 +1776,10 @@ static void smi230_acc_fifo_handle(struct smi230_client_data *client_data) err = smi230_acc_extract_accel(fifo_accel_data, &fifo_length, &fifo, p_smi230_dev); - timestamp_ns = client_data->timestamp - tsamp * fifo_length; + tsamp = div_u64(client_data->timestamp - client_data->timestamp_old, + fifo_length); + timestamp_ns = client_data->timestamp_old; + client_data->timestamp_old = client_data->timestamp; for (i = 0; i < fifo_length; i++) { timestamp_ns += tsamp; @@ -1850,10 +1799,7 @@ static void smi230_acc_fifo_handle(struct smi230_client_data *client_data) } } -#else /* new data */ - -__maybe_unused static void -smi230_new_data_ready_handle(struct smi230_client_data *client_data) +static void smi230_new_data_ready_handle(struct smi230_client_data *client_data) { struct smi230_sensor_data accel_data; int err = 0; @@ -1872,32 +1818,65 @@ smi230_new_data_ready_handle(struct smi230_client_data *client_data) input_sync(client_data->input); } -#endif -static void smi230_irq_work_func(struct work_struct *work) +static int smi230_acc_toggle_int_pin(uint8_t enable) +{ + int err; + uint8_t reg_addr = 0; + uint8_t data = 0; + + if (IS_ENABLED(CONFIG_SMI230_ACC_INT1)) + reg_addr = SMI230_ACCEL_INT1_IO_CONF_REG; + else if (IS_ENABLED(CONFIG_SMI230_ACC_INT2)) + reg_addr = SMI230_ACCEL_INT2_IO_CONF_REG; + else { + PERR("Invalid Kconfig for interrupt pin."); + return SMI230_E_INVALID_CONFIG; + } + + err = smi230_acc_get_regs(reg_addr, &data, 1, p_smi230_dev); + if (err != SMI230_OK) { + PERR("Error reading INT_IO_CONF_REG"); + return err; + } + + data = SMI230_SET_BITS(data, SMI230_ACCEL_INT_IO, enable); + + err = smi230_acc_set_regs(reg_addr, &data, 1, p_smi230_dev); + if (err != SMI230_OK) + PERR("Error writing INT_IO_CONF_REG"); + + return err; +} + +static irqreturn_t smi230_irq_work_func(int irq, void *handle) { - struct smi230_client_data *client_data = - container_of(work, struct smi230_client_data, irq_work); + struct smi230_client_data *client_data = handle; int err = 0; uint8_t int_stat[2]; + err = smi230_acc_toggle_int_pin(0); + if (err != SMI230_OK) + PERR("deactivate int pin error"); + err = smi230_acc_get_regs(SMI230_ACCEL_INT_STAT_0_REG, int_stat, 2, p_smi230_dev); if (err) { PERR("read int status error"); - return; + return IRQ_HANDLED; } -#if defined(CONFIG_SMI230_ACC_FIFO) - if (int_stat[1] & (SMI230_ACCEL_FIFO_FULL | SMI230_ACCEL_FIFO_WTM)) - smi230_acc_fifo_handle(client_data); -#elif defined(CONFIG_SMI230_DATA_SYNC) - if (int_stat[0] & SMI230_ACCEL_DATA_SYNC_INT_ENABLE) - smi230_data_sync_ready_handle(client_data); -#else - if (int_stat[1] & SMI230_ACCEL_DATA_READY_INT) - smi230_new_data_ready_handle(client_data); -#endif + if (IS_ENABLED(CONFIG_SMI230_ACC_FIFO)) { + if (int_stat[1] & + (SMI230_ACCEL_FIFO_FULL | SMI230_ACCEL_FIFO_WTM)) + smi230_acc_fifo_handle(client_data); + } else if (IS_ENABLED(CONFIG_SMI230_DATA_SYNC)) { + if (int_stat[0] & SMI230_ACCEL_DATA_SYNC_INT_ENABLE) + smi230_data_sync_ready_handle(client_data); + } else { + if (int_stat[1] & SMI230_ACCEL_DATA_READY_INT) + smi230_new_data_ready_handle(client_data); + } if (int_stat[0] & SMI230_ACCEL_ANY_MOT_INT_ENABLE) smi230_anymotion_handle(client_data); @@ -1913,37 +1892,32 @@ static void smi230_irq_work_func(struct work_struct *work) if (int_stat[0] & SMI230_ACCEL_LOW_G_INT_ENABLE) smi230_low_g_handle(client_data); + + err = smi230_acc_toggle_int_pin(1); + if (err != SMI230_OK) + PERR("activate int pin error"); + + return IRQ_HANDLED; } static irqreturn_t smi230_irq_handle(int irq, void *handle) { struct smi230_client_data *client_data = handle; - int err = 0; client_data->timestamp = ktime_get_boottime_ns(); - - err = queue_work(p_workqueue, &client_data->irq_work); - if (err < 0) - PERR("schedule_work failed\n"); - - return IRQ_HANDLED; + return IRQ_WAKE_THREAD; } static void smi230_free_irq(struct smi230_client_data *client_data) { - cancel_work_sync(&client_data->irq_work); free_irq(client_data->IRQ, client_data); gpio_free(client_data->gpio_pin); - destroy_workqueue(p_workqueue); } static int smi230_request_irq(struct smi230_client_data *client_data) { int err = 0; - p_workqueue = create_singlethread_workqueue("smi230"); - INIT_WORK(&client_data->irq_work, smi230_irq_work_func); - client_data->gpio_pin = of_get_named_gpio_flags( client_data->dev->of_node, "gpio_irq", 0, NULL); PINFO("SMI230_ACC gpio number:%d\n", client_data->gpio_pin); @@ -1959,8 +1933,9 @@ static int smi230_request_irq(struct smi230_client_data *client_data) return err; } client_data->IRQ = gpio_to_irq(client_data->gpio_pin); - err = request_irq(client_data->IRQ, smi230_irq_handle, - IRQF_TRIGGER_RISING, SENSOR_ACC_NAME, client_data); + err = request_threaded_irq(client_data->IRQ, smi230_irq_handle, + smi230_irq_work_func, IRQF_TRIGGER_RISING, + SENSOR_ACC_NAME, client_data); if (err < 0) { PDEBUG("request_irq\n"); return err; diff --git a/drivers/input/sensors/smi230/smi230_defs.h b/drivers/input/sensors/smi230/smi230_defs.h index c240b08..1aa00a8 100644 --- a/drivers/input/sensors/smi230/smi230_defs.h +++ b/drivers/input/sensors/smi230/smi230_defs.h @@ -610,8 +610,8 @@ #define SMI230_ACC_FIFO_MODE UINT8_C(0x01) #define SMI230_FIFO_GYRO_FRAME_LENGTH UINT8_C(6) -#define SMI230_GYRO_STREAM_MODE UINT8_C(0x80) -#define SMI230_GYRO_FIFO_MODE UINT8_C(0x40) +#define SMI230_GYRO_STREAM_MODE UINT8_C(0x8C) +#define SMI230_GYRO_FIFO_MODE UINT8_C(0x4C) /*name Mask definitions for FIFO configuration modes */ #define SMI230_ACC_FIFO_MODE_CONFIG_MASK UINT8_C(0x01) @@ -873,6 +873,9 @@ struct smi230_cfg { /*! output data rate */ uint8_t odr; + + /*! fifo watermark level */ + uint8_t fifo_wm; }; /*! diff --git a/drivers/input/sensors/smi230/smi230_driver.h b/drivers/input/sensors/smi230/smi230_driver.h index 3da0e4c..0cf4459 100644 --- a/drivers/input/sensors/smi230/smi230_driver.h +++ b/drivers/input/sensors/smi230/smi230_driver.h @@ -51,7 +51,7 @@ #include #include "smi230_defs.h" -#define DRIVER_VERSION "0.8.1" +#define DRIVER_VERSION "0.8.2" #define MODULE_NAME "SMI230" #define SENSOR_ACC_NAME "SMI230ACC" #define SENSOR_GYRO_NAME "SMI230GYRO" diff --git a/drivers/input/sensors/smi230/smi230_gyro.c b/drivers/input/sensors/smi230/smi230_gyro.c index c4b67cb..4b36556 100644 --- a/drivers/input/sensors/smi230/smi230_gyro.c +++ b/drivers/input/sensors/smi230/smi230_gyro.c @@ -977,7 +977,8 @@ int8_t smi230_gyro_get_fifo_length(uint16_t *fifo_bytes, 1, dev); if (rslt == SMI230_OK) { /* Get total FIFO length */ - (*fifo_bytes) = (uint16_t)(data & 0x7F) * SMI230_FIFO_GYRO_FRAME_LENGTH; + (*fifo_bytes) = (uint16_t)(data & 0x7F) * + SMI230_FIFO_GYRO_FRAME_LENGTH; } else { rslt = SMI230_E_NULL_PTR; } diff --git a/drivers/input/sensors/smi230/smi230_gyro_driver.c b/drivers/input/sensors/smi230/smi230_gyro_driver.c index 915ddf4..bc63122 100644 --- a/drivers/input/sensors/smi230/smi230_gyro_driver.c +++ b/drivers/input/sensors/smi230/smi230_gyro_driver.c @@ -44,44 +44,44 @@ * **/ -#include -#include -#include -#include #include #include +#include +#include +#include #include #include #include +#include +#include -#include "smi230_driver.h" #include "smi230_data_sync.h" +#include "smi230_driver.h" #define MODULE_TAG MODULE_NAME -#include "smi230_log.h" #include "smi230.h" +#include "smi230_log.h" #define SMI230_MIN_VALUE -32768 #define SMI230_MAX_VALUE 32767 -#ifdef CONFIG_SMI230_GYRO_FIFO #define SMI230_MAX_GYRO_FIFO_FRAME 100 #define SMI230_MAX_GYRO_FIFO_BYTES \ (SMI230_MAX_GYRO_FIFO_FRAME * SMI230_FIFO_GYRO_FRAME_LENGTH) static uint8_t fifo_buf[SMI230_MAX_GYRO_FIFO_BYTES]; -#endif struct smi230_client_data { struct device *dev; struct input_dev *input; int IRQ; int gpio_pin; - struct work_struct irq_work; uint64_t timestamp; + uint64_t timestamp_old; }; static struct smi230_dev *p_smi230_dev; +static struct smi230_sensor_data fifo_gyro_data[SMI230_MAX_GYRO_FIFO_FRAME]; static ssize_t smi230_gyro_show_chip_id(struct device *dev, struct device_attribute *attr, @@ -151,6 +151,7 @@ static ssize_t smi230_gyro_store_fifo_wm(struct device *dev, return err; } + p_smi230_dev->gyro_cfg.fifo_wm = fifo_wm; PDEBUG("set fifo wm to %d", fifo_wm); return count; @@ -466,75 +467,32 @@ static int smi230_input_init(struct smi230_client_data *client_data) return err; } -#ifndef CONFIG_SMI230_DATA_SYNC -#ifdef CONFIG_SMI230_GYRO_FIFO -static struct smi230_sensor_data fifo_gyro_data[SMI230_MAX_GYRO_FIFO_FRAME]; - static void smi230_gyro_fifo_handle(struct smi230_client_data *client_data) { struct smi230_fifo_frame fifo; int err = 0, i; uint8_t fifo_frames; - uint16_t fifo_bytes; uint32_t tsamp; uint64_t timestamp_ns; struct timespec64 ts; - err = smi230_gyro_get_fifo_length(&fifo_bytes, p_smi230_dev); - if (err != SMI230_OK) { - PERR("FIFO get length error!"); - return; - } - -#if 0 - PINFO("GYRO FIFO length %d", fifo_bytes); -#endif fifo.data = fifo_buf; - fifo.length = fifo_bytes; + fifo.length = (uint16_t)(p_smi230_dev->gyro_cfg.fifo_wm) * + SMI230_FIFO_GYRO_FRAME_LENGTH; + err = smi230_gyro_read_fifo_data(&fifo, p_smi230_dev); if (err != SMI230_OK) { PERR("FIFO read data error %d", err); return; } -#if 0 - /* this event shall never be mixed with sensor data */ - /* this event here is to indicate IRQ timing if needed */ - input_event(client_data->input, EV_MSC, MSC_RAW, (int)fifo.length); - input_sync(client_data->input); -#endif - - switch (p_smi230_dev->gyro_cfg.odr) { - case SMI230_GYRO_BW_523_ODR_2000_HZ: - tsamp = 500000; - break; - case SMI230_GYRO_BW_230_ODR_2000_HZ: - tsamp = 500000; - break; - case SMI230_GYRO_BW_116_ODR_1000_HZ: - tsamp = 1000000; - break; - case SMI230_GYRO_BW_47_ODR_400_HZ: - tsamp = 2500000; - break; - case SMI230_GYRO_BW_23_ODR_200_HZ: - tsamp = 5000000; - break; - case SMI230_GYRO_BW_12_ODR_100_HZ: - tsamp = 10000000; - break; - case SMI230_GYRO_BW_64_ODR_200_HZ: - tsamp = 5000000; - break; - case SMI230_GYRO_BW_32_ODR_100_HZ: - tsamp = 10000000; - break; - } - err = smi230_gyro_extract_fifo(fifo_gyro_data, &fifo_frames, &fifo, p_smi230_dev); - timestamp_ns = client_data->timestamp - tsamp * fifo_frames; + tsamp = div_u64(client_data->timestamp - client_data->timestamp_old, + fifo_frames); + timestamp_ns = client_data->timestamp_old; + client_data->timestamp_old = client_data->timestamp; for (i = 0; i < fifo_frames; i++) { timestamp_ns += tsamp; @@ -554,8 +512,6 @@ static void smi230_gyro_fifo_handle(struct smi230_client_data *client_data) } } -#else /* new data */ - __maybe_unused static void smi230_new_data_ready_handle(struct smi230_client_data *client_data) { @@ -576,41 +532,44 @@ smi230_new_data_ready_handle(struct smi230_client_data *client_data) input_sync(client_data->input); } -#endif -#endif -__maybe_unused static void smi230_irq_work_func(struct work_struct *work) +static irqreturn_t smi230_irq_work_func(int irq, void *handle) { -#ifndef CONFIG_SMI230_DATA_SYNC - struct smi230_client_data *client_data = - container_of(work, struct smi230_client_data, irq_work); + int err; + uint8_t data = 0; + struct smi230_client_data *client_data = handle; -#ifdef CONFIG_SMI230_GYRO_FIFO - smi230_gyro_fifo_handle(client_data); -#else - smi230_new_data_ready_handle(client_data); -#endif + err = smi230_gyro_get_regs(SMI230_GYRO_INT_STAT_1_REG, &data, 1, + p_smi230_dev); + if (err != SMI230_OK) { + PERR("Read gyro interrupt status failed %d", err); + return IRQ_HANDLED; + } -#endif + if (data & 0x10) + smi230_gyro_fifo_handle(client_data); + + if (data & 0x80) + smi230_new_data_ready_handle(client_data); + + return IRQ_HANDLED; } static irqreturn_t smi230_irq_handle(int irq, void *handle) { struct smi230_client_data *client_data = handle; - int err = 0; - client_data->timestamp = ktime_get_ns(); - err = schedule_work(&client_data->irq_work); - if (err < 0) - PERR("schedule_work failed\n"); + client_data->timestamp = ktime_get_boottime_ns(); - return IRQ_HANDLED; + if (IS_ENABLED(CONFIG_SMI230_DATA_SYNC)) + return IRQ_HANDLED; + else + return IRQ_WAKE_THREAD; } __maybe_unused static void smi230_free_irq(struct smi230_client_data *client_data) { - cancel_work_sync(&client_data->irq_work); free_irq(client_data->IRQ, client_data); gpio_free(client_data->gpio_pin); } @@ -620,8 +579,6 @@ smi230_request_irq(struct smi230_client_data *client_data) { int err = 0; - INIT_WORK(&client_data->irq_work, smi230_irq_work_func); - client_data->gpio_pin = of_get_named_gpio_flags( client_data->dev->of_node, "gpio_irq", 0, NULL); PINFO("SMI230_GYRO gpio number:%d\n", client_data->gpio_pin); @@ -637,8 +594,9 @@ smi230_request_irq(struct smi230_client_data *client_data) return err; } client_data->IRQ = gpio_to_irq(client_data->gpio_pin); - err = request_irq(client_data->IRQ, smi230_irq_handle, - IRQF_TRIGGER_RISING, SENSOR_GYRO_NAME, client_data); + err = request_threaded_irq(client_data->IRQ, smi230_irq_handle, + smi230_irq_work_func, IRQF_TRIGGER_RISING, + SENSOR_GYRO_NAME, client_data); if (err < 0) { PDEBUG("request_irq\n"); return err; @@ -756,10 +714,12 @@ int smi230_gyro_probe(struct device *dev, struct smi230_dev *smi230_dev) PINFO("GYRO FIFO set water mark"); err |= smi230_gyro_set_fifo_wm(100, p_smi230_dev); + p_smi230_dev->gyro_cfg.fifo_wm = 100; #endif #ifdef CONFIG_SMI230_GYRO_FIFO_FULL PINFO("GYRO FIFO full enabled"); fifo_config.wm_en = 0x08; + p_smi230_dev->gyro_cfg.fifo_wm = 100; #endif /* disable external event sync on both int3 and int 4 */ diff --git a/drivers/input/sensors/smi230/smi230_i2c_driver.c b/drivers/input/sensors/smi230/smi230_i2c_driver.c index 861b8d8..f2135ce 100644 --- a/drivers/input/sensors/smi230/smi230_i2c_driver.c +++ b/drivers/input/sensors/smi230/smi230_i2c_driver.c @@ -44,17 +44,17 @@ * **/ -#include +#include #include #include -#include #include +#include #include "smi230_driver.h" #define MODULE_TAG MODULE_NAME -#include "smi230_log.h" #include "smi230.h" +#include "smi230_log.h" #define SMI230_MAX_RETRY_I2C_XFER 10 #define SMI230_I2C_WRITE_DELAY_TIME 10 @@ -148,8 +148,8 @@ static int smi230_acc_i2c_probe(struct i2c_client *client, if ((smi230_i2c_adapter != NULL) && (smi230_i2c_adapter == client->adapter)) { - PINFO("%s i2c adapter is at %x", SENSOR_ACC_NAME, - (unsigned int)client->adapter); + PINFO("%s i2c adapter is at 0x%p", SENSOR_ACC_NAME, + (void *)client->adapter); } else { PERR("%s i2c driver is not initialized yet before ACC driver!", SENSOR_GYRO_NAME); @@ -215,8 +215,8 @@ static int smi230_gyro_i2c_probe(struct i2c_client *client, if (smi230_i2c_adapter == NULL) { smi230_i2c_adapter = client->adapter; - PINFO("%s i2c adapter is at %x", SENSOR_GYRO_NAME, - (unsigned int)client->adapter); + PINFO("%s i2c adapter is at 0x%px", SENSOR_GYRO_NAME, + (void *)client->adapter); } else { PERR("%s i2c driver should be initialized first!", SENSOR_GYRO_NAME);