diff --git a/drivers/input/misc/bos0614_mmi/Android.mk b/drivers/input/misc/bos0614_mmi/Android.mk new file mode 100644 index 000000000000..a8a426802f45 --- /dev/null +++ b/drivers/input/misc/bos0614_mmi/Android.mk @@ -0,0 +1,10 @@ +DLKM_DIR := motorola/kernel/modules +LOCAL_PATH := $(call my-dir) + +include $(CLEAR_VARS) +LOCAL_MODULE := bos0614_mmi.ko +LOCAL_MODULE_TAGS := optional +LOCAL_MODULE_PATH := $(KERNEL_MODULES_OUT) +KBUILD_OPTIONS_GKI += GKI_OBJ_MODULE_DIR=gki +include $(DLKM_DIR)/AndroidKernelModule.mk + diff --git a/drivers/input/misc/bos0614_mmi/Kbuild b/drivers/input/misc/bos0614_mmi/Kbuild new file mode 100644 index 000000000000..abbef9d908e4 --- /dev/null +++ b/drivers/input/misc/bos0614_mmi/Kbuild @@ -0,0 +1,14 @@ +# add -Wall to try to catch everything we can. +EXTRA_CFLAGS += -Wall +EXTRA_CFLAGS += -I$(ANDROID_BUILD_TOP)/motorola/kernel/modules/include \ + -I$(ANDROID_BUILD_TOP)/motorola/kernel/modules/drivers/input/misc/bos0614_mmi \ + -I$(ANDROID_BUILD_TOP)/motorola/kernel/modules/drivers/input/misc/bos0614_mmi/libs/dk-core/src \ + -I$(ANDROID_BUILD_TOP)/motorola/kernel/modules/drivers/input/misc/bos0614_mmi/libs/dk-core + +EXTRA_CFLAGS += -DMOTOROLA +EXTRA_CFLAGS += -DLITTLE_ENDIAN=1234 -DBYTE_ORDER=LITTLE_ENDIAN + +obj-m := bos0614_mmi.o +bos0614_mmi-objs := i2cLinux.o bosDriver.o +bos0614_mmi-objs += libs/dk-core/src/bsp/drivers/haptic/bos0614Driver.o +bos0614_mmi-objs += libs/dk-core/contribs/comm-stack-dk/data.o diff --git a/drivers/input/misc/bos0614_mmi/Makefile b/drivers/input/misc/bos0614_mmi/Makefile index af31ca586695..4191dea22679 100644 --- a/drivers/input/misc/bos0614_mmi/Makefile +++ b/drivers/input/misc/bos0614_mmi/Makefile @@ -1,17 +1,10 @@ -obj-m := bosDriverModule.o -bosDriverModule-y := i2cLinux.o -bosDriverModule-y += bosDriver.o -bosDriverModule-y += libs/dk-core/src/bsp/drivers/haptic/bos0614Driver.o -bosDriverModule-y += libs/dk-core/contribs/comm-stack-dk/data.o +KERNEL_SRC ?= /lib/modules/$(shell uname -r)/build -ccflags-y += -I$(src)/libs/dk-core/src -ccflags-y += -I$(src)/libs/dk-core/ -ccflags-y += -std=gnu99 -ccflags-y += -DDEBUG -ccflags-y += -DLITTLE_ENDIAN=1234 -ccflags-y += -DBYTE_ORDER=LITTLE_ENDIAN +all: + $(MAKE) -C $(KERNEL_SRC) M=$(shell pwd) modules $(KBUILD_OPTIONS) -PWD := $(shell pwd) +modules_install: + $(MAKE) INSTALL_MOD_STRIP=1 -C $(KERNEL_SRC) M=$(shell pwd) modules_install -default: - $(MAKE) -C $(KERNELDIR) M=$(PWD) +clean: + $(MAKE) -C $(KERNEL_SRC) M=$(PWD) clean diff --git a/drivers/input/misc/bos0614_mmi/bosDriver.c b/drivers/input/misc/bos0614_mmi/bosDriver.c index 68e568af341f..8c9c12c9cb66 100644 --- a/drivers/input/misc/bos0614_mmi/bosDriver.c +++ b/drivers/input/misc/bos0614_mmi/bosDriver.c @@ -28,10 +28,68 @@ #include #include #include + #include "libs/dk-core/src/bsp/drivers/haptic/bosDriver.h" #include "i2cLinux.h" -#include -#include +#include "libs/dk-core/src/bsp/drivers/i2c/i2c.h" +#include "libs/dk-core/src/bsp/drivers/haptic/bos0614Driver.h" + +enum { + PARAM_UCHAR8 = 1, + PARAM_INT16, + PARAM_UINT16, + PARAM_INT32, + PARAM_UINT32 +}; + +typedef struct { + int tid; + void *data_ptr; +} ParamsLst; + +#define PARAM_ADD(t, v) {\ + params[numP].tid = t;\ + params[numP].data_ptr = v;\ + numP++;\ +} + +static int process_params(ParamsLst *params, int numP, const char *buffer) +{ + char *arg, *buf, *p; + int n, err; + + buf = kstrdup(buffer, GFP_KERNEL); + for (n = 0; n < numP && p && *p; n++, params++) { + arg = strsep(&p, " "); + if (!arg || !*arg) + break; + + switch (params->tid) { + case PARAM_UCHAR8: + err = kstrtou8(arg, 0, params->data_ptr); + break; + case PARAM_INT16: + err = kstrtos16(arg, 0, params->data_ptr); + break; + case PARAM_UINT16: + err = kstrtou16(arg, 0, params->data_ptr); + break; + case PARAM_INT32: + err = kstrtoint(arg, 0, params->data_ptr); + break; + case PARAM_UINT32: + err = kstrtouint(arg, 0, params->data_ptr); + break; + } + + if (err) { + n = err; + break; + } + } + kfree(buf); + return n; +} typedef struct { @@ -76,11 +134,12 @@ static DEVICE_ATTR(chip_id, 0440, getChipId, NULL); static bool hasError(BOSError *errors, size_t length, BOSError errorType) { + size_t index; bool res = false; if (errors != NULL) { - for (size_t index = 0; index < length; index++) + for (index = 0; index < length; index++) { if (errors[index] == errorType) { @@ -102,9 +161,11 @@ static ssize_t getIcErrors(struct device *dev, if (ctx != NULL && ctx->hapticDriver != NULL) { + BOSError *errors; + mutex_lock(&ctx->lock); - BOSError *errors = kzalloc(sizeof(BOSError) * BOSERROR_Length, GFP_KERNEL); + errors = kzalloc(sizeof(BOSError) * BOSERROR_Length, GFP_KERNEL); if (errors != NULL) { @@ -141,18 +202,32 @@ static ssize_t setSynthWaveform(struct device *dev, if (ctx != NULL && ctx->hapticDriver != NULL) { + WaveformId id = 0; + uint8_t startSliceId = 0; + size_t nbrOfSlices = 0; + uint16_t cycle = 0; + uint8_t outputChannel = 0; + size_t paramLength = 0; + int numP = 0; + ParamsLst params[5]; + + PARAM_ADD(PARAM_UCHAR8, &id); + PARAM_ADD(PARAM_UCHAR8, &startSliceId); + PARAM_ADD(PARAM_UINT32, &nbrOfSlices); + PARAM_ADD(PARAM_UINT16, &cycle); + PARAM_ADD(PARAM_UCHAR8, &outputChannel); + mutex_lock(&ctx->lock); - WaveformId id; - uint8_t startSliceId; - size_t nbrOfSlices; - uint16_t cycle; - uint8_t outputChannel; - - size_t paramLength = sscanf(buf, "%hi %hi %zi %hi %hi", &id, &startSliceId, &nbrOfSlices, &cycle, - &outputChannel); + paramLength = process_params(params, numP, buf); + if (paramLength < 0) { + mutex_unlock(&ctx->lock); + return (ssize_t)paramLength; + } + //paramLength = sscanf(buf, "%hh %hi %zi %hi %hi", &id, &startSliceId, + // &nbrOfSlices, &cycle, &outputChannel); dev_dbg(ctx->dev, - "[Set Synth Waveform] Waveform Id: %d Start Slice Id: %d Nbr Of Slices: %d Cycle: %d Output Channel: %d\n", + "[Set Synth Waveform] Waveform Id: %d Start Slice Id: %d Nbr Of Slices: %zu Cycle: %d Output Channel: %d\n", id, startSliceId, nbrOfSlices, cycle, outputChannel); if (paramLength == SET_WAVEFORM_PARAM_LENGTH) @@ -177,21 +252,35 @@ static ssize_t setSynthSlice(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { - (void) attr; Context *ctx = dev_get_drvdata(dev); ssize_t res = -EIO; + (void) attr; if (ctx != NULL && ctx->hapticDriver != NULL) { + HapticDriver *driver; + SynthSlice slice; + uint8_t outputChannel = 0; + size_t paramLength = 0; + int numP = 0; + ParamsLst params[4]; + + PARAM_ADD(PARAM_UINT32, &slice.sliceId); + PARAM_ADD(PARAM_INT32, &slice.mVAmp); + PARAM_ADD(PARAM_UINT32, &slice.mHzFreq); + PARAM_ADD(PARAM_UCHAR8, &outputChannel); + mutex_lock(&ctx->lock); - HapticDriver *driver = ctx->hapticDriver; - SynthSlice slice; - uint8_t outputChannel; - - size_t paramLength = sscanf(buf, "%d %d %d %d %d", &slice.sliceId, &slice.mVAmp, &slice.mHzFreq, - &slice.cycle, &outputChannel); + driver = ctx->hapticDriver; + paramLength = process_params(params, numP, buf); + if (paramLength < 0) { + mutex_unlock(&ctx->lock); + return (ssize_t)paramLength; + } + //paramLength = sscanf(buf, "%d %d %d %d %d", &slice.sliceId, &slice.mVAmp, + // &slice.mHzFreq, &slice.cycle, &outputChannel); dev_dbg(ctx->dev, "[Set Slice] Slice Id: %d Amplitude: %d mV Frequency: %d milliHertz Cycle: %d Output Channel: %d\n", slice.sliceId, slice.mVAmp, slice.mHzFreq, slice.cycle, outputChannel); @@ -215,20 +304,30 @@ static ssize_t synthPlay(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { - (void) attr; Context *ctx = dev_get_drvdata(dev); ssize_t res = -EIO; + (void) attr; if (ctx != NULL && ctx->hapticDriver != NULL) { - mutex_lock(&ctx->lock); + HapticDriver *driver; + WaveformId start = 0; + WaveformId stop = 0; + size_t paramLength = 0; + int numP = 0; + ParamsLst params[2]; - HapticDriver *driver = ctx->hapticDriver; + PARAM_ADD(PARAM_UCHAR8, &start); + PARAM_ADD(PARAM_UCHAR8, &stop); - WaveformId start; - WaveformId stop; + driver = ctx->hapticDriver; - size_t paramLength = sscanf(buf, "%hi %hi", &start, &stop); + paramLength = process_params(params, numP, buf); + if (paramLength < 0) { + mutex_unlock(&ctx->lock); + return (ssize_t)paramLength; + } + //paramLength = sscanf(buf, "%hi %hi", &start, &stop); if (paramLength == SYNTH_PLAY_PARAM_LENGTH && driver->wfsPlay(driver, start, stop)) { @@ -247,20 +346,30 @@ static ssize_t setOutput(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { - (void) attr; Context *ctx = dev_get_drvdata(dev); ssize_t res = -EIO; + (void) attr; if (ctx != NULL && ctx->hapticDriver != NULL) { - mutex_lock(&ctx->lock); - - HapticDriver *driver = ctx->hapticDriver; - + HapticDriver *driver; int outputState = 0; - size_t paramLength = sscanf(buf, "%d", &outputState); - + size_t paramLength = 0; bool bOutputState = outputState > 0 ? true : false; + int numP = 0; + ParamsLst params[1]; + + PARAM_ADD(PARAM_INT32, &outputState); + + mutex_lock(&ctx->lock); + driver = ctx->hapticDriver; + + paramLength = process_params(params, numP, buf); + if (paramLength < 0) { + mutex_unlock(&ctx->lock); + return (ssize_t)paramLength; + } + //paramLength = sscanf(buf, "%d", &outputState); if (paramLength == CTRL_OUTPUT_PARAM_LENGTH && driver->ctrlOutput(driver, bOutputState)) @@ -325,27 +434,39 @@ static ssize_t setSensingConfig(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { - (void) attr; Context *ctx = dev_get_drvdata(dev); ssize_t res = -EIO; + (void) attr; if (ctx != NULL && ctx->hapticDriver != NULL) { - mutex_lock(&ctx->lock); - - HapticDriver *driver = ctx->hapticDriver; - + HapticDriver *driver; SensingConfig config; - ChannelId channelId; - - size_t paramLength = sscanf(buf, "%hhu %d %d %hd %hd %s", - &channelId, &config.mode, &config.direction, - &config.debounceUs, - &config.thresholdMv, - &config.stabilisationMs); - + ChannelId channelId = 0; + size_t paramLength = 0; const char *directionS = getSensingDirection(config.direction); const char *modeS = getSensingDetectionMode(config.mode); + int numP = 0; + ParamsLst params[6]; + + PARAM_ADD(PARAM_UCHAR8, &channelId); + PARAM_ADD(PARAM_UCHAR8, &config.mode); + PARAM_ADD(PARAM_UCHAR8, &config.direction); + PARAM_ADD(PARAM_UINT16, &config.debounceUs); + PARAM_ADD(PARAM_UINT16, &config.thresholdMv); + PARAM_ADD(PARAM_UCHAR8, &config.stabilisationMs); + + mutex_lock(&ctx->lock); + driver = ctx->hapticDriver; + + paramLength = process_params(params, numP, buf); + if (paramLength < 0) { + mutex_unlock(&ctx->lock); + return (ssize_t)paramLength; + } + //paramLength = sscanf(buf, "%hhu %d %d %hd %hd %s", &channelId, &config.mode, + // &config.direction, &config.debounceUs, + // &config.thresholdMv, &config.stabilisationMs); if (paramLength == SENSING_CONFIG_PARAM_LENGTH && directionS != NULL && @@ -372,23 +493,35 @@ static ssize_t setSensingAutoPlay(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { - (void) attr; Context *ctx = dev_get_drvdata(dev); ssize_t res = -EIO; + (void) attr; if (ctx != NULL && ctx->hapticDriver != NULL) { + HapticDriver *driver; + ChannelId channelId = 0; + WaveformId id = 0; + SensingDirection direction = 0; + size_t paramLength = 0; + const char *directionS; + int numP = 0; + ParamsLst params[3]; + + PARAM_ADD(PARAM_UCHAR8, &channelId); + PARAM_ADD(PARAM_UCHAR8, &id); + PARAM_ADD(PARAM_UCHAR8, &direction); + + paramLength = process_params(params, numP, buf); + if (paramLength < 0) { + return (ssize_t)paramLength; + } + //paramLength = sscanf(buf, "%d %d %d", &channelId, &id, &direction); + + directionS = getSensingDirection(direction); + mutex_lock(&ctx->lock); - - HapticDriver *driver = ctx->hapticDriver; - - ChannelId channelId; - WaveformId id; - SensingDirection direction; - - size_t paramLength = sscanf(buf, "%d %d %d", &channelId, &id, &direction); - const char *directionS = getSensingDirection(direction); - + driver = ctx->hapticDriver; if (paramLength == SENSING_AUTO_FEEDBACK_PARAM_LENGTH && directionS != NULL && @@ -412,21 +545,32 @@ static ssize_t stopSensing(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { - (void) attr; Context *ctx = dev_get_drvdata(dev); ssize_t res = -EIO; + (void) attr; if (ctx != NULL && ctx->hapticDriver != NULL) { + HapticDriver *driver; + ChannelId channelId = 0; + SensingDirection direction = 0; + const char *directionS; + size_t paramLength = 0; + int numP = 0; + ParamsLst params[2]; + + PARAM_ADD(PARAM_UCHAR8, &channelId); + PARAM_ADD(PARAM_UCHAR8, &direction); + + paramLength = process_params(params, numP, buf); + if (paramLength < 0) { + return (ssize_t)paramLength; + } + //paramLength = sscanf(buf, "%d %d", &channelId, &direction); + directionS = getSensingDirection(direction); + mutex_lock(&ctx->lock); - - HapticDriver *driver = ctx->hapticDriver; - - ChannelId channelId; - SensingDirection direction; - - size_t paramLength = sscanf(buf, "%d %d", &channelId, &direction); - const char *directionS = getSensingDirection(direction); + driver = ctx->hapticDriver; if (paramLength == STOP_SENSING_PARAM_LENGTH && directionS != NULL && @@ -487,6 +631,14 @@ static int bosDriverI2cProbe(struct i2c_client *client, const struct i2c_device_id *id) { int res = -ENODEV; + int err; + Context *ctx; + Bos0614Resource resource = { + .gpioA = NULL, + .gpioB = NULL, + .gpioC = NULL, + .gpioD = NULL + }; dev_info(&client->dev, "%s called\n", __func__); @@ -497,7 +649,7 @@ static int bosDriverI2cProbe(struct i2c_client *client, goto bosDriverProbeError; } - Context *ctx = devm_kzalloc(&client->dev, sizeof(*ctx), GFP_KERNEL); + ctx = devm_kzalloc(&client->dev, sizeof(*ctx), GFP_KERNEL); if (ctx == NULL) { @@ -511,8 +663,7 @@ static int bosDriverI2cProbe(struct i2c_client *client, dev_set_drvdata(&client->dev, ctx); ctx->i2c = i2cBoreasLinuxInit(client); - - Bos0614Resource resource = {.i2c = ctx->i2c, .gpioA = NULL, .gpioB = NULL, .gpioC = NULL, .gpioD = NULL}; + resource.i2c = ctx->i2c; ctx->hapticDriver = bos0614DriverI2cInit(resource); if (ctx->i2c == NULL || ctx->hapticDriver == NULL) @@ -523,7 +674,7 @@ static int bosDriverI2cProbe(struct i2c_client *client, mutex_init(&ctx->lock); - int err = sysfs_create_group(&ctx->dev->kobj, &bosDriverAttrGroup); + err = sysfs_create_group(&ctx->dev->kobj, &bosDriverAttrGroup); if (err) { @@ -555,11 +706,10 @@ static int bosDriverI2cProbe(struct i2c_client *client, static int bosDriverI2cRemove(struct i2c_client *client) { int res = -ENODEV; + Context *ctx = i2c_get_clientdata(client); dev_info(&client->dev, "%s called \n", __func__); - Context *ctx = i2c_get_clientdata(client); - freeResources(ctx); return res; @@ -579,11 +729,23 @@ static int detect(struct i2c_client *client, struct i2c_board_info *info) return 0; } +#ifdef CONFIG_OF +static const struct of_device_id matchTable[] = { + { .compatible = "boreas,bos0614", }, + {}, +}; +#endif + static struct i2c_driver bosDriverI2c = { .class = I2C_CLASS_HWMON, .driver = { - .name = "bos0614", .owner = THIS_MODULE, +#ifdef CONFIG_OF + .name = "bos0614_mmi", + .of_match_table = matchTable, +#else + .name = "bos0614", +#endif }, .probe = bosDriverI2cProbe, .remove = bosDriverI2cRemove, @@ -592,7 +754,24 @@ static struct i2c_driver bosDriverI2c = { .address_list = addrList }; +#ifdef CONFIG_OF +static int __init bosDriver_init(void) +{ + pr_info("%s: loading driver\n", __func__); + return i2c_add_driver(&bosDriverI2c); +} + +static void __exit bosDriver_exit(void) +{ + pr_info("%s: removing driver\n", __func__); + i2c_del_driver(&bosDriverI2c); +} + +module_init(bosDriver_init); +module_exit(bosDriver_exit); +#else module_i2c_driver(bosDriverI2c) +#endif MODULE_AUTHOR("Pascal-Frédéric St-Laurent "); MODULE_DESCRIPTION("I2C Driver for Boréas Haptic Technologies"); diff --git a/drivers/input/misc/bos0614_mmi/coreDefOption.h b/drivers/input/misc/bos0614_mmi/coreDefOption.h index 7db7c7ffdd4b..9582e65aebfb 100644 --- a/drivers/input/misc/bos0614_mmi/coreDefOption.h +++ b/drivers/input/misc/bos0614_mmi/coreDefOption.h @@ -22,5 +22,6 @@ #define DKCORE_COREDEFOPTION_H #define BOS0614_NBR_OF_INSTANCE (1) +#define BOS0614_NBR_OF_CHANNEL (4) #endif //DKCORE_COREDEFOPTION_H diff --git a/drivers/input/misc/bos0614_mmi/i2cLinux.c b/drivers/input/misc/bos0614_mmi/i2cLinux.c index abc400070d0b..358f72d9cc98 100644 --- a/drivers/input/misc/bos0614_mmi/i2cLinux.c +++ b/drivers/input/misc/bos0614_mmi/i2cLinux.c @@ -21,13 +21,12 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. // - -#include #include #include #include #include +#include "i2cLinux.h" typedef struct { @@ -47,17 +46,19 @@ static void logBuffer(const char *message, const void *data, size_t length) if (buf != NULL) { + size_t index; char *ptr = buf; char *end = buf + bufferLength; uint8_t *_data = (uint8_t *) data; - for (size_t index = 0; index < length && ptr < end; index++) + for (index = 0; index < length && ptr < end; index++) { ptr += sprintf(ptr, index < (length - 1) ? "0x%02x " : "0x%02x", _data[index]); } - printk("%s length: %d [%s]\n", message, length, buf, bufferLength, ptr, end); + //printk("%s length: %zu [%s]\n", message, length, buf, bufferLength, ptr, end); + printk("%s length: %zu [%s]\n", message, length, buf); kfree(buf); } @@ -76,17 +77,18 @@ static int32_t i2cKernelSend(I2c *i2c, uint8_t address, const void *data, size_t if (i2c != NULL && data != NULL) { Context *ctx = container_of(i2c, Context, driver); + char *buf = kzalloc(num, GFP_KERNEL); dev_dbg(&ctx->client->dev, "I2C Write Address: 0x%x\n", address); logBuffer("Write: ", data, num); - char *buf = kzalloc(num, GFP_KERNEL); - if (buf != NULL) { + int status; + memcpy(buf, data, num); - int status = i2c_master_send(ctx->client, (const char *) buf, (int) num); + status = i2c_master_send(ctx->client, (const char *) buf, (int) num); res = status == num ? ARM_DRIVER_OK : status; kfree(buf); @@ -103,11 +105,10 @@ int32_t i2cKernelRead(I2c *i2c, uint8_t address, void *data, size_t num) if (i2c != NULL && data != NULL) { Context *ctx = container_of(i2c, Context, driver); + char *buf = kzalloc(num, GFP_KERNEL); dev_dbg(&ctx->client->dev, "I2C Read Address: 0x%x \n", address); - char *buf = kzalloc(num, GFP_KERNEL); - if (buf != NULL) { int status = i2c_master_recv(ctx->client, (char *) buf, num); @@ -141,7 +142,7 @@ I2c *i2cBoreasLinuxInit(struct i2c_client *client) { Context *ctx = kzalloc(sizeof(Context), GFP_KERNEL); - printk("[PF-Debug] I2C Client 0x%8x", client); + printk("[PF-Debug] I2C Client %p", client); if (ctx != NULL) { @@ -180,4 +181,4 @@ void initDriverFct(Context *ctx) { ctx->driver.write = i2cKernelSend; ctx->driver.read = i2cKernelRead; -} \ No newline at end of file +} diff --git a/drivers/input/misc/bos0614_mmi/i2cLinux.h b/drivers/input/misc/bos0614_mmi/i2cLinux.h index a683ba4dbf1e..a2511b4f2d37 100644 --- a/drivers/input/misc/bos0614_mmi/i2cLinux.h +++ b/drivers/input/misc/bos0614_mmi/i2cLinux.h @@ -25,11 +25,11 @@ #ifndef BOREAS_HAPTIC_DRIVER_LINUX_I2CLINUX_H #define BOREAS_HAPTIC_DRIVER_LINUX_I2CLINUX_H -#include "libs/dk-core/src/bsp/drivers/i2c/i2c.h" #include +#include "libs/dk-core/src/bsp/drivers/i2c/i2c.h" I2c *i2cBoreasLinuxInit(struct i2c_client *client); bool i2cBoreasLinuxFree(I2c * i2c); -#endif //BOREAS_HAPTIC_DRIVER_LINUX_I2CLINUX_H \ No newline at end of file +#endif //BOREAS_HAPTIC_DRIVER_LINUX_I2CLINUX_H diff --git a/drivers/input/misc/bos0614_mmi/libs/dk-core/contribs/comm-stack-dk/data.c b/drivers/input/misc/bos0614_mmi/libs/dk-core/contribs/comm-stack-dk/data.c index c36e46d07cad..22406f102c57 100644 --- a/drivers/input/misc/bos0614_mmi/libs/dk-core/contribs/comm-stack-dk/data.c +++ b/drivers/input/misc/bos0614_mmi/libs/dk-core/contribs/comm-stack-dk/data.c @@ -184,8 +184,9 @@ uint64_t endian_reverse64(uint64_t val) void endian_reverse_array_enc(uint8_t *dst, uint8_t *array, uint8_t sizeInBytes) { + uint8_t dstIndex; uint8_t valueIndex = sizeInBytes; - for (uint8_t dstIndex = 0; dstIndex < sizeInBytes; dstIndex++) + for (dstIndex = 0; dstIndex < sizeInBytes; dstIndex++) { dst[dstIndex] = array[--valueIndex]; } @@ -194,9 +195,10 @@ void endian_reverse_array_enc(uint8_t *dst, uint8_t *array, uint8_t sizeInBytes) void endian_reverse_array(uint8_t *array, uint8_t sizeInBytes) { uint8_t endIndex = sizeInBytes; + uint8_t startIndex; uint8_t value; - for (uint8_t startIndex = 0; startIndex < endIndex; startIndex++, endIndex--) + for (startIndex = 0; startIndex < endIndex; startIndex++, endIndex--) { value = array[startIndex]; array[startIndex] = array[endIndex]; diff --git a/drivers/input/misc/bos0614_mmi/libs/dk-core/contribs/comm-stack-dk/data.h b/drivers/input/misc/bos0614_mmi/libs/dk-core/contribs/comm-stack-dk/data.h index 5af2c069fd3a..7225fdc6fba9 100644 --- a/drivers/input/misc/bos0614_mmi/libs/dk-core/contribs/comm-stack-dk/data.h +++ b/drivers/input/misc/bos0614_mmi/libs/dk-core/contribs/comm-stack-dk/data.h @@ -25,9 +25,9 @@ #ifndef _DATA_H #define _DATA_H -#include -#include -#include +#include + +#define DATA_ARRAY_LENGTH(array) (sizeof(array)/sizeof(array[0])) #ifdef __cplusplus extern "C" { @@ -74,14 +74,8 @@ extern "C" { #define BYTE_LENGTH_IN_BITS (8) -#define container_of(ptr, type, member) ({ \ - const typeof( ((type *)0)->member ) *__mptr = (ptr); \ - (type *)( (char *)__mptr - offsetof(type,member) );}) - #define PI (3.14159265) -#define DATA_ARRAY_LENGTH(array) (sizeof(array)/sizeof(array[0])) - void htoBe32(uint32_t value, uint8_t *data); void htoBe16(uint16_t value, uint8_t *data); diff --git a/drivers/input/misc/bos0614_mmi/libs/dk-core/src/bsp/boards/boreasTime.h b/drivers/input/misc/bos0614_mmi/libs/dk-core/src/bsp/boards/boreasTime.h index ae1daade6655..10d106f8b386 100644 --- a/drivers/input/misc/bos0614_mmi/libs/dk-core/src/bsp/boards/boreasTime.h +++ b/drivers/input/misc/bos0614_mmi/libs/dk-core/src/bsp/boards/boreasTime.h @@ -25,8 +25,7 @@ #ifndef DKCORE_LAUNCHPADTIME_H #define DKCORE_LAUNCHPADTIME_H -#include -#include +#include #define MICROSECOND_IN_MILLISECOND(_us) (_us/1000) diff --git a/drivers/input/misc/bos0614_mmi/libs/dk-core/src/bsp/drivers/gpio/gpio.h b/drivers/input/misc/bos0614_mmi/libs/dk-core/src/bsp/drivers/gpio/gpio.h index 70539020c730..d804726250a1 100644 --- a/drivers/input/misc/bos0614_mmi/libs/dk-core/src/bsp/drivers/gpio/gpio.h +++ b/drivers/input/misc/bos0614_mmi/libs/dk-core/src/bsp/drivers/gpio/gpio.h @@ -24,7 +24,7 @@ #ifndef DKCORE_GPIO_H #define DKCORE_GPIO_H -#include +#include typedef struct _GPIO Gpio; diff --git a/drivers/input/misc/bos0614_mmi/libs/dk-core/src/bsp/drivers/haptic/bos0614Driver.c b/drivers/input/misc/bos0614_mmi/libs/dk-core/src/bsp/drivers/haptic/bos0614Driver.c index acda4df42768..226041aac786 100644 --- a/drivers/input/misc/bos0614_mmi/libs/dk-core/src/bsp/drivers/haptic/bos0614Driver.c +++ b/drivers/input/misc/bos0614_mmi/libs/dk-core/src/bsp/drivers/haptic/bos0614Driver.c @@ -21,21 +21,23 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. // +#define pr_fmt(fmt) "bos0614: %s: " fmt, __func__ + +#include +#include -#include #include "contribs/cmsis/CMSIS/Driver/Include/Driver_Common.h" #include "contribs/comm-stack-dk/data.h" #include "bsp/boards/boreasTime.h" #include "bsp/drivers/i2c/i2c.h" #include "bsp/drivers/haptic/bos0614Driver.h" -#include +#include "bsp/drivers/haptic/bos0614Register.h" #define BOS0614_CHIP_ID (0x0D) #define BOS0614_I2C_ADDRESS (0x2c) #define SFT_RESET_TIME_IN_US (100) - #define AMPLITUDE_MAX_VALUE_VOLT (60) #define AMPLITUDE_MAX_VALUE (0xFFF) #define FB_R_V_REF (68.4) @@ -178,9 +180,11 @@ static bool writeReg(Context *ctx, Bos0614Register *reg) static bool resetSoftware(Context *ctx) { + bool res; + ctx->reg.CONFIG_0614.bit.RST = 0x1; - bool res = writeReg(ctx, &ctx->reg.CONFIG_0614.reg); + res = writeReg(ctx, &ctx->reg.CONFIG_0614.reg); ctx->reg.CONFIG_0614.bit.RST = 0x0; @@ -189,9 +193,10 @@ static bool resetSoftware(Context *ctx) static Context *getNewInstance() { + int index; Context *ctx = NULL; - for (int index = 0; index < DATA_ARRAY_LENGTH(driverInstances); index++) + for (index = 0; index < DATA_ARRAY_LENGTH(driverInstances); index++) { if (driverInstances[index].isInitiated == false) { @@ -403,10 +408,11 @@ static Bos0614Register *getRegister(Context *ctx, uint8_t addr) static bool readI2cRegister(Context *ctx, Bos0614Register *reg) { + bool res; uint8_t rxData[REG_VALUE_LENGTH] = {0}; ctx->reg.READ_0614.bit.BC = reg->generic.addr; - bool res = writeReg(ctx, &ctx->reg.READ_0614.reg); + res = writeReg(ctx, &ctx->reg.READ_0614.reg); res = res && ctx->i2c->read(ctx->i2c, BOS0614_I2C_ADDRESS, rxData, REG_VALUE_LENGTH) == ARM_DRIVER_OK; @@ -451,6 +457,7 @@ static bool readRegister(Context *ctx, Bos0614Register *reg) static bool burstWriteRam(Context *driver, WSFBank bank, uint16_t address, uint16_t *data, size_t length) { + int i; bool res = false; if (length < MAXIMUM_DATA_LENGTH) { @@ -459,7 +466,7 @@ static bool burstWriteRam(Context *driver, WSFBank bank, uint16_t address, uint1 htoBe16(bank, &driver->txBuffer[BURST_WRITE_RAM_BANK_INDEX]); // [1-2] WFS bank htoBe16(address, &driver->txBuffer[BURST_WRITE_RAM_ADDRESS_INDEX]); // [3-4] Burst start address htoBe16(length, &driver->txBuffer[BURST_WRITE_RAM_LENGTH_INDEX]); // [5-6] Burst data length - for (int i = 0; i < length; i++) // [7..] RAM Data to be forwarded to WFS + for (i = 0; i < length; i++) // [7..] RAM Data to be forwarded to WFS { htoBe16(data[i], &driver->txBuffer[(i * 2) + BURST_WRITE_RAM_DATA_INDEX]); } @@ -482,12 +489,13 @@ static bool burstWriteRam(Context *driver, WSFBank bank, uint16_t address, uint1 static bool writeRam(Context *driver, WSFBank bank, uint16_t *data, size_t length) { + int i; bool res = false; memset(driver->txBuffer, 0, sizeof(driver->txBuffer)); driver->txBuffer[I2C_ADDRESS_INDEX] = ADDRESS_BOS0614_REFERENCE_REG; // [0] Main register map address htoBe16(bank, &driver->txBuffer[WRITE_RAM_BANK_INDEX]); // [1-2] WFS bank address - for (int i = 0; i < length; i += 2) // [3..] RAM Data to be forwarded to WFS + for (i = 0; i < length; i += 2) // [3..] RAM Data to be forwarded to WFS { htoBe16(*(data++), &driver->txBuffer[i + WRITE_RAM_DATA_INDEX]); } @@ -683,9 +691,10 @@ static bool lookupGpioCtl(GPOCtrl ctrl, Bos0614GPIOMode *bos0614Ctrl) static bool isGpoSignalingAvailable(Context *ctx) { + size_t index; bool res = false; - for (size_t index = 0; index < DATA_ARRAY_LENGTH(ctx->channel); index++) + for (index = 0; index < DATA_ARRAY_LENGTH(ctx->channel); index++) { if (ctx->channel[index].gpio != NULL) { @@ -909,7 +918,7 @@ setThresholdSensing(Context *ctx, SensingConfig config, SENSE_BITS_0614 *senseBi DebouncingTime debouncingValue; res = twoComplement(getThresholdFromMV(config.thresholdMv), THRESHOLD_NBR_OF_BITS, &threshold); - res = res && getDebouncingConfig(config.debounceUs, &debouncingValue); + res = getDebouncingConfig(config.debounceUs, &debouncingValue); senseThreshold->THRESHOLD = threshold; senseThreshold->REP = debouncingValue; @@ -962,11 +971,11 @@ setSlopeSensing(Context *ctx, SensingConfig config, SENSE_BITS_0614 *senseBitFie return res; } -static size_t pushErrorInQueue(BOSError *errors, size_t current, size_t maxLength, BOSError error) +static size_t pushErrorInQueue(BOSError *errors, size_t curpos, size_t maxLength, BOSError error) { - size_t length = current; + size_t length = curpos; - if (current < maxLength) + if (curpos < maxLength) { errors[length++] = error; } @@ -1034,6 +1043,7 @@ bool bos0614GetRegister(HapticDriver *driver, uint8_t addr, uint16_t *value) if (driver != NULL) { + Bos0614Register *reg; Context *ctx = container_of(driver, Context, hDriver); @@ -1043,7 +1053,7 @@ bool bos0614GetRegister(HapticDriver *driver, uint8_t addr, uint16_t *value) writeReg(ctx, &ctx->reg.DEBUG_0614.reg); } - Bos0614Register *reg = getRegister(ctx, addr); + reg = getRegister(ctx, addr); if (reg != NULL) { if (readRegister(ctx, reg)) @@ -1064,6 +1074,7 @@ bool bos0614SetRegister(HapticDriver *driver, uint8_t addr, uint16_t value) if (driver != NULL) { + Bos0614Register *reg; Context *ctx = container_of(driver, Context, hDriver); @@ -1073,7 +1084,7 @@ bool bos0614SetRegister(HapticDriver *driver, uint8_t addr, uint16_t value) writeReg(ctx, &ctx->reg.DEBUG_0614.reg); } - Bos0614Register *reg = getRegister(ctx, addr); + reg = getRegister(ctx, addr); if (reg != NULL) { reg->generic.value = value; @@ -1153,7 +1164,6 @@ bos0614SetWaveforms(HapticDriver *driver, WaveformId id, uint8_t startSliceId, s outputChannel < BOS0614_CHANNEL_MASK) { Context *ctx = container_of(driver, Context, hDriver); - ctx->outputChanForWaveformId[id] = outputChannel; uint16_t waveformAddr = RAM_WAVEFORM_METADATA_ADDR + (id * WAVEFORM_METADATA_LENGTH); @@ -1162,6 +1172,8 @@ bos0614SetWaveforms(HapticDriver *driver, WaveformId id, uint8_t startSliceId, s RAM_SLICE_WAVEFORM_ADDR + ((startSliceId + nbrOfSlices) * SLICE_LENGTH) - 1, (uint16_t) cycle}; + ctx->outputChanForWaveformId[id] = outputChannel; + res = writeRam(ctx, WSFBank_Ram, command, sizeof(command)); ctx->synth.sequencerCmd[id] = (waveformAddr); @@ -1178,11 +1190,12 @@ bool bos0614SynthesizerPlay(HapticDriver *driver, WaveformId start, WaveformId s if (driver != NULL && start < MAXIMUM_WAVEFORM_ID_SEQUENCER && stop < MAXIMUM_WAVEFORM_ID_SEQUENCER) { + uint16_t startStopAddr; Context *ctx = container_of(driver, Context, hDriver); ctx->currentChannelMask = ctx->outputChanForWaveformId[start]; - uint16_t startStopAddr = (start << SEQUENCER_STOP_ADDRESS_SHIFT) | stop; + startStopAddr = (start << SEQUENCER_STOP_ADDRESS_SHIFT) | stop; res = writeRam(ctx, WSFBank_SequencerStartStop, &startStopAddr, sizeof(startStopAddr)); } @@ -1196,6 +1209,8 @@ bool bos0614SynthesizerPlay(HapticDriver *driver, WaveformId start, WaveformId s bool bos0614SetRamPlaybackMode(HapticDriver *driver, uint32_t samplingRate, void *data, size_t length, uint8_t channelMask) { + int index; + uint16_t *buffer; bool res = false; if (driver != NULL && samplingRate <= MAXIMUM_SAMPLING_RATE && data != NULL && length <= MAXIMUM_DATA_LENGTH && @@ -1207,8 +1222,8 @@ bool bos0614SetRamPlaybackMode(HapticDriver *driver, uint32_t samplingRate, void res = res && setSamplingRate(ctx, samplingRate); //Configure the channel output - uint16_t *buffer = (uint16_t *) data; - for (int index = 0; index < length; index++) + buffer = (uint16_t *) data; + for (index = 0; index < length; index++) { buffer[index] &= RAMPLAYBACK_DATA_MASK; buffer[index] |= (channelMask << RAMPLAYBACK_CHANNEL_OFFSET); @@ -1269,10 +1284,11 @@ uint16_t bos0614GetMaxFifoSpace() static bool writeDataInFifo(Context *ctx, void *data, size_t length) { + int index; bool res = false; uint16_t *dataArray = (uint16_t *) data; - for (int index = 0; index < length; index++) + for (index = 0; index < length; index++) { res = true; ctx->reg.REFERENCE_0614.bit.FIFO = dataArray[index]; @@ -1317,8 +1333,9 @@ static void gpoIsr(Gpio *gpio, void *context, GPIOIsr isrEvent) if (context != NULL) { Context *ctx = (Context *) context; + uint32_t index; - for (uint32_t index = 0; index < DATA_ARRAY_LENGTH(ctx->channel); index++) + for (index = 0; index < DATA_ARRAY_LENGTH(ctx->channel); index++) { if (ctx->channel[index].gpio != NULL && ctx->channel[index].gpio == gpio && @@ -1511,11 +1528,12 @@ size_t bos0614NbrOfRegister() bool bos0614ReferencingFromVolt(HapticDriver *ctx, int16_t *data, size_t length) { + int index; bool res = false; if (ctx != NULL) { - for (int index = 0; index < length; index++) + for (index = 0; index < length; index++) { float num = (float) data[index] * AMPLITUDE_MAX_VALUE; @@ -1696,8 +1714,7 @@ bool bos0614FeatureSupport(HapticDriver *driver, BosFeature feature) * Private Section */ -//static BOS_REGS BOS0614Regs = -BOS0614_REGS bOS0614Regs = +static BOS0614_REGS bOS0614Regs = { .REFERENCE_0614.reg.generic.addr = ADDRESS_BOS0614_REFERENCE_REG, .IC_STATUS_0614.reg.generic.addr = ADDRESS_BOS0614_IC_STATUS_REG, @@ -1828,9 +1845,10 @@ static uint8_t regAddrToRead[] = {ADDRESS_BOS0614_REFERENCE_REG, static bool readAllRegister(Context *ctx) { + uint32_t index; bool res = true; - for (uint32_t index = 0; index < DATA_ARRAY_LENGTH(regAddrToRead) && res; index++) + for (index = 0; index < DATA_ARRAY_LENGTH(regAddrToRead) && res; index++) { uint16_t dummy; res = bos0614GetRegister(&ctx->hDriver, regAddrToRead[index], &dummy); @@ -1853,20 +1871,22 @@ static bool setDefaultConfig(Context *ctx) ctx->reg.SENSECONFIG_0614.bit.CH3 = BOS0614_DISABLE; ctx->reg.SENSECONFIG_0614.bit.SAME = BOS0614_DISABLE; - Bos0614Register *reg[] = {&ctx->reg.SENSECONFIG_0614.reg}; - - for (uint32_t index = 0; index < DATA_ARRAY_LENGTH(reg); index++) - { - res = res && ctx->hDriver.setRegister(&ctx->hDriver, reg[index]->generic.addr, - reg[index]->generic.value); - } + res = ctx->hDriver.setRegister(&ctx->hDriver, + ctx->reg.SENSECONFIG_0614.reg.generic.addr, + ctx->reg.SENSECONFIG_0614.reg.generic.value); +// Bos0614Register *reg[] = {&ctx->reg.SENSECONFIG_0614.reg}; +// for (uint32_t index = 0; index < DATA_ARRAY_LENGTH(reg); index++) +// { +// res = res && ctx->hDriver.setRegister(&ctx->hDriver, reg[index]->generic.addr, +// reg[index]->generic.value); +// } return res; } static void initiateDriver(Context *ctx) { - memcpy(&ctx->reg, &bOS0614Regs, sizeof(BOS0614_REGS)); + memcpy(&ctx->reg, &bOS0614Regs, sizeof(bOS0614Regs)); ctx->hDriver.softwareReset = bos0614SoftwareReset; ctx->hDriver.deepSleep = bos0614DeepSleep; diff --git a/drivers/input/misc/bos0614_mmi/libs/dk-core/src/bsp/drivers/haptic/bos0614Register.h b/drivers/input/misc/bos0614_mmi/libs/dk-core/src/bsp/drivers/haptic/bos0614Register.h index 19c8ee04097e..c14d87dbe751 100644 --- a/drivers/input/misc/bos0614_mmi/libs/dk-core/src/bsp/drivers/haptic/bos0614Register.h +++ b/drivers/input/misc/bos0614_mmi/libs/dk-core/src/bsp/drivers/haptic/bos0614Register.h @@ -25,7 +25,7 @@ #ifndef BOS0614_REGISTER_H_ #define BOS0614_REGISTER_H_ -#include +#include #define ADDRESS_BOS0614_REFERENCE_REG 0x0000 #define ADDRESS_BOS0614_IC_STATUS_REG 0x0001 diff --git a/drivers/input/misc/bos0614_mmi/libs/dk-core/src/bsp/drivers/haptic/bosDriver.h b/drivers/input/misc/bos0614_mmi/libs/dk-core/src/bsp/drivers/haptic/bosDriver.h index 34f1411c0f2c..26f6c44a6c9b 100644 --- a/drivers/input/misc/bos0614_mmi/libs/dk-core/src/bsp/drivers/haptic/bosDriver.h +++ b/drivers/input/misc/bos0614_mmi/libs/dk-core/src/bsp/drivers/haptic/bosDriver.h @@ -25,9 +25,7 @@ #ifndef DKCORE_BOSDRIVER_H #define DKCORE_BOSDRIVER_H -#include -#include -#include +#include #include "bsp/drivers/spi/spi.h" #include "bsp/drivers/gpio/gpio.h" diff --git a/drivers/input/misc/bos0614_mmi/libs/dk-core/src/bsp/drivers/i2c/i2c.h b/drivers/input/misc/bos0614_mmi/libs/dk-core/src/bsp/drivers/i2c/i2c.h index b51354bff685..a2a652023487 100644 --- a/drivers/input/misc/bos0614_mmi/libs/dk-core/src/bsp/drivers/i2c/i2c.h +++ b/drivers/input/misc/bos0614_mmi/libs/dk-core/src/bsp/drivers/i2c/i2c.h @@ -25,10 +25,9 @@ #ifndef DKCORE_I2C_H #define DKCORE_I2C_H -#include -#include +#include -#include +#include "contribs/cmsis/CMSIS/Driver/Include/Driver_Common.h" #define I2C_7BIT_ADDRESS_MASK (0x7F) diff --git a/drivers/input/misc/bos0614_mmi/libs/dk-core/src/bsp/drivers/spi/spi.h b/drivers/input/misc/bos0614_mmi/libs/dk-core/src/bsp/drivers/spi/spi.h index 50d9a174dc96..ba72dfd0ac73 100644 --- a/drivers/input/misc/bos0614_mmi/libs/dk-core/src/bsp/drivers/spi/spi.h +++ b/drivers/input/misc/bos0614_mmi/libs/dk-core/src/bsp/drivers/spi/spi.h @@ -8,7 +8,7 @@ #ifndef DKCORE_SPI_H #define DKCORE_SPI_H -#include +#include typedef struct _spi Spi;