summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (from parent 1: b326959)
raw | patch | inline | side by side (from parent 1: b326959)
author | a0393714 <navada@ti.com> | |
Thu, 26 Dec 2019 13:43:35 +0000 (19:13 +0530) | ||
committer | a0393714 <navada@ti.com> | |
Thu, 26 Dec 2019 13:43:35 +0000 (19:13 +0530) |
drv2624.c | patch | blob | history | |
drv2624.h | patch | blob | history |
diff --git a/drv2624.c b/drv2624.c
index e372932056478dfafb747644a9ee481e1a086d25..3c163f39034b2604fc4149ecc487748265f5fc7b 100755 (executable)
--- a/drv2624.c
+++ b/drv2624.c
#include <linux/interrupt.h>
#include "drv2624.h"
-static struct drv2624_data *g_DRV2624data = NULL;
+static struct drv2624_data *g_DRV2624data;
static struct regmap_config drv2624_i2c_regmap = {
.reg_bits = 8,
.val_bits = 8,
if (nResult < 0) {
dev_err(pDRV2624->dev, "%s I2C error %d\n", __func__, nResult);
- return nResult;
+ //return nResult;
} else {
- dev_dbg(pDRV2624->dev, "%s, Reg[0x%x]=0x%x\n", __func__, reg, val);
- return val;
+ dev_dbg(pDRV2624->dev,
+ "%s, Reg[0x%x]=0x%x\n", __func__, reg, val);
}
+ return val;
}
static int drv2624_reg_write(struct drv2624_data *pDRV2624,
- unsigned char reg, unsigned char val)
+ unsigned char reg, unsigned char val)
{
int nResult;
+
dev_dbg(pDRV2624->dev, "%s, Reg[0x%x]=0x%x\n", __func__, reg, val);
mutex_lock(&pDRV2624->dev_lock);
nResult = regmap_write(pDRV2624->mpRegmap, reg, val);
mutex_unlock(&pDRV2624->dev_lock);
if (nResult < 0)
- dev_err(pDRV2624->dev, "%s reg=0x%x, value=0%x error %d\n",
+ dev_err(pDRV2624->dev,
+ "%s reg=0x%x, value=0%x error %d\n",
__func__, reg, val, nResult);
+
dev_dbg(pDRV2624->dev, "%s, Reg[0x%x]=0x%x\n", __func__, reg, val);
return nResult;
nResult = regmap_bulk_read(pDRV2624->mpRegmap, reg, buf, count);
mutex_unlock(&pDRV2624->dev_lock);
if (nResult < 0)
- dev_err(pDRV2624->dev, "%s reg=0%x, count=%d error %d\n",
+ dev_err(pDRV2624->dev,
+ "%s reg=0%x, count=%d error %d\n",
__func__, reg, count, nResult);
return nResult;
}
static int drv2624_bulk_write(struct drv2624_data *pDRV2624,
- unsigned char reg, const u8 *buf, unsigned int count)
+ unsigned char reg, const u8 *buf, unsigned int count)
{
int nResult, i;
nResult = regmap_bulk_write(pDRV2624->mpRegmap, reg, buf, count);
mutex_unlock(&pDRV2624->dev_lock);
if (nResult < 0)
- dev_err(pDRV2624->dev, "%s reg=0%x, count=%d error %d\n",
- __func__, reg, count, nResult);
- for(i = 0; i < count; i++)
- dev_dbg(pDRV2624->dev, "%s, Reg[0x%x]=0x%x\n",
- __func__, reg+i, buf[i]);
+ dev_err(pDRV2624->dev,
+ "%s reg=0%x, count=%d error %d\n", __func__,
+ reg, count, nResult);
+ for (i = 0; i < count; i++)
+ dev_dbg(pDRV2624->dev,
+ "%s, Reg[0x%x]=0x%x\n", __func__, reg+i, buf[i]);
return nResult;
}
static int drv2624_set_bits(struct drv2624_data *pDRV2624,
- unsigned char reg, unsigned char mask, unsigned char val)
+ unsigned char reg, unsigned char mask, unsigned char val)
{
int nResult;
nResult = regmap_update_bits(pDRV2624->mpRegmap, reg, mask, val);
mutex_unlock(&pDRV2624->dev_lock);
if (nResult < 0)
- dev_err(pDRV2624->dev, "%s reg=%x, mask=0x%x, value=0x%x error %d\n",
+ dev_err(pDRV2624->dev,
+ "%s reg=%x, mask=0x%x, value=0x%x error %d\n",
__func__, reg, mask, val, nResult);
- dev_dbg(pDRV2624->dev, "%s, Reg[0x%x]:M=0x%x, V=0x%x\n",
- __func__, reg, mask, val);
+ dev_dbg(pDRV2624->dev,
+ "%s, Reg[0x%x]:M=0x%x, V=0x%x\n", __func__, reg, mask, val);
return nResult;
}
if (bRTP == 0)
mask = INT_ENABLE_ALL;
- nResult = drv2624_reg_read(pDRV2624,DRV2624_REG_STATUS);
+ nResult = drv2624_reg_read(pDRV2624, DRV2624_REG_STATUS);
if (nResult < 0)
goto end;
nResult = drv2624_reg_write(pDRV2624, DRV2624_REG_INT_ENABLE, mask);
if (pDRV2624->mbIRQUsed) {
if (pDRV2624->mbIRQEnabled) {
disable_irq_nosync(pDRV2624->mnIRQ);
- drv2624_reg_write(pDRV2624, DRV2624_REG_INT_ENABLE, INT_MASK_ALL);
+ drv2624_reg_write(pDRV2624,
+ DRV2624_REG_INT_ENABLE, INT_MASK_ALL);
pDRV2624->mbIRQEnabled = false;
}
}
}
static inline int drv2624_change_mode(struct drv2624_data *pDRV2624,
- drv2624_mode_t work_mode)
+ drv2624_mode_t work_mode)
{
- pDRV2624->mnWorkMode = work_mode;
+ pDRV2624->mnWorkMode = work_mode;
+
return drv2624_set_bits(pDRV2624,
- DRV2624_REG_MODE, WORKMODE_MASK, work_mode);
+ DRV2624_REG_MODE, WORKMODE_MASK, work_mode);
}
static inline void drv2624_set_stopflag(struct drv2624_data *pDRV2624)
pDRV2624->mnEffectType = 0;
}
-static int drv2624_get_diag_result(struct drv2624_data *pDRV2624, unsigned char nStatus)
+static int
+drv2624_get_diag_result(struct drv2624_data *pDRV2624, unsigned char nStatus)
{
int Re = 0, nResult = 0;
pDRV2624->mDiagResult.mnResult = nStatus;
- if((nStatus & DIAG_MASK) != DIAG_SUCCESS)
+ if ((nStatus & DIAG_MASK) != DIAG_SUCCESS)
dev_err(pDRV2624->dev, "%s: Diagnostic fail\n", __func__);
else {
nResult = drv2624_reg_read(pDRV2624, DRV2624_REG_DIAG_Z);
@@ -263,14 +273,13 @@ static int drv2624_get_diag_result(struct drv2624_data *pDRV2624, unsigned char
goto end;
pDRV2624->mDiagResult.mnDiagK = nResult;
- Re = 478.43 * (pDRV2624->mDiagResult.mnDiagZ / (4 * pDRV2624->mDiagResult.mnDiagK + 719));
+ Re = 478.43 * (pDRV2624->mDiagResult.mnDiagZ /
+ (4 * pDRV2624->mDiagResult.mnDiagK + 719));
dev_dbg(pDRV2624->dev,
"%s: ZResult=0x%x, CurrentK=0x%x, Re = %d ohm\n",
- __func__,
- pDRV2624->mDiagResult.mnDiagZ,
- pDRV2624->mDiagResult.mnDiagK,
- Re);
+ __func__, pDRV2624->mDiagResult.mnDiagZ,
+ pDRV2624->mDiagResult.mnDiagK, Re);
}
end:
#ifdef ANDROID_TIMED_OUTPUT
static int vibrator_get_time(struct timed_output_dev *dev)
- {
- struct drv2624_data *pDRV2624 = container_of(dev, struct drv2624_data, to_dev);
+{
+ struct drv2624_data *pDRV2624 =
+ container_of(dev, struct drv2624_data, to_dev);
if (hrtimer_active(&pDRV2624->haptics_timer)) {
- ktime_t r = hrtimer_get_remaining(&pDRV2624->haptics_timer);
+ ktime_t r;
+
+ r = hrtimer_get_remaining(&pDRV2624->haptics_timer);
return ktime_to_ms(r);
}
return 0;
}
-static void vibrator_enable( struct timed_output_dev *dev, int value)
+static void vibrator_enable(struct timed_output_dev *dev, int value)
{
int nResult = 0;
struct drv2624_data *pDRV2624 =
if (nResult >= 0) {
value = (value > MAX_TIMEOUT) ? MAX_TIMEOUT : value;
hrtimer_start(&pDRV2624->haptics_timer,
- ns_to_ktime((u64)value * NSEC_PER_MSEC), HRTIMER_MODE_REL);
+ ns_to_ktime((u64)value * NSEC_PER_MSEC),
+ HRTIMER_MODE_REL);
pDRV2624->mnVibratorPlaying = YES;
if (pDRV2624->mbIRQUsed)
__func__, pDRV2624->mnWorkMode);
if (pDRV2624->mbIRQUsed) {
- pDRV2624->mnIntStatus = drv2624_reg_read(pDRV2624,DRV2624_REG_STATUS);
+ pDRV2624->mnIntStatus =
+ drv2624_reg_read(pDRV2624, DRV2624_REG_STATUS);
if (nResult < 0)
goto err;
__func__, pDRV2624->mnIntStatus);
if (status & OVERCURRENT_MASK)
- dev_err(pDRV2624->dev, "ERROR, Over Current detected!!\n");
+ dev_err(pDRV2624->dev,
+ "ERROR, Over Current detected!!\n");
if (status & OVERTEMPRATURE_MASK)
- dev_err(pDRV2624->dev, "ERROR, Over Temperature detected!!\n");
+ dev_err(pDRV2624->dev,
+ "ERROR, Over Temperature detected!!\n");
if (status & ULVO_MASK)
dev_err(pDRV2624->dev, "ERROR, VDD drop observed!!\n");
drv2624_stop(pDRV2624);
} else if (pDRV2624->mnWorkMode == DRV2624_RAM_MODE) {
status = drv2624_reg_read(pDRV2624, DRV2624_REG_GO);
- if ((status < 0) || (status == STOP) || !pDRV2624->mnVibratorPlaying) {
+ if ((status < 0) || (status == STOP)
+ || !pDRV2624->mnVibratorPlaying) {
drv2624_stop(pDRV2624);
} else {
if (!hrtimer_active(&pDRV2624->haptics_timer)) {
- dev_dbg(pDRV2624->dev, "will check GO bit after %d ms\n", GO_BIT_CHECK_INTERVAL);
+ dev_dbg(pDRV2624->dev,
+ "will check GO bit after %dms\n",
+ GO_BIT_CHECK_INTERVAL);
hrtimer_start(&pDRV2624->haptics_timer,
- ns_to_ktime((u64)GO_BIT_CHECK_INTERVAL * NSEC_PER_MSEC), HRTIMER_MODE_REL);
+ ns_to_ktime((u64)GO_BIT_CHECK_INTERVAL
+ * NSEC_PER_MSEC),
+ HRTIMER_MODE_REL);
}
}
}
dev_info(pDRV2624->dev, "%s enter!\n", __func__);
- /* Set MODE register to Auto Level Calibration Routine
- * and choose Trigger Function Internal */
-
-
- nResult = drv2624_reg_write(pDRV2624,
- DRV2624_REG_MODE,
- DRV2624_CALIBRATION_MODE_CFG);
+/**
+ * Set MODE register to Auto Level Calibration Routine
+ * and choose Trigger Function Internal
+ **/
+ nResult = drv2624_reg_write(pDRV2624,
+ DRV2624_REG_MODE, DRV2624_CALIBRATION_MODE_CFG);
if (nResult < 0)
goto end;
nResult = drv2624_change_mode(pDRV2624, MODE_CALIBRATION);
- if(nResult < 0)
- {
- dev_err(pDRV2624->dev, "%s: change mode Done nResult = %d\n",
+ if (nResult < 0) {
+ dev_err(pDRV2624->dev,
+ "%s: change mode not Done nResult= %d\n",
__func__, nResult);
goto end;
}
nResult = drv2624_set_bits(pDRV2624,
- AUTO_CAL_TIME_REG,
- AUTO_CAL_TIME_MASK,
- AUTO_CAL_TIME_AUTO_TRIGGER);
- if (nResult < 0)
- {
- dev_err(pDRV2624->dev, "%s: set bits Done nResult = %d\n",
- __func__, nResult);
+ AUTO_CAL_TIME_REG, AUTO_CAL_TIME_MASK,
+ AUTO_CAL_TIME_AUTO_TRIGGER);
+ if (nResult < 0) {
+ dev_err(pDRV2624->dev,
+ "%s: set bits not Done nResult = %d\n",
+ __func__, nResult);
goto end;
}
nResult = drv2624_set_go_bit(pDRV2624, GO);
- if (nResult < 0)
- {
- dev_err(pDRV2624->dev, "%s: calibrate go bit Done nResult = %d\n",
- __func__, nResult);
+ if (nResult < 0) {
+ dev_err(pDRV2624->dev,
+ "%s: calibrate go bit not Done nResult = %d\n",
+ __func__, nResult);
goto end;
}
msleep(1000); /* waiting auto calibration finished */
return nResult;
end:
- dev_err(pDRV2624->dev, "%s: Calibtion Done nResult = %d\n",
- __func__, nResult);
+ dev_err(pDRV2624->dev,
+ "%s: Calibtion Done nResult = %d\n", __func__, nResult);
return nResult;
}
dev_dbg(pDRV2624->dev, "%s: enter!\n", __func__);
- nResult = drv2624_reg_read(pDRV2624,DRV2624_REG_STATUS);
+ nResult = drv2624_reg_read(pDRV2624, DRV2624_REG_STATUS);
if (nResult < 0)
goto end;
- pDRV2624->mnIntStatus = nResult;
-
+ //pDRV2624->mnIntStatus = nResult;
+ pDRV2624->mAutoCalResult.mnResult = nResult;
cal_comp = drv2624_reg_read(pDRV2624, DRV2624_REG_CAL_COMP);
if (cal_comp < 0)
goto end;
goto end;
pDRV2624->mAutoCalResult.mnCalBemf = cal_bemf;
- cal_gain = drv2624_reg_read(pDRV2624, DRV2624_REG_LOOP_CONTROL) & BEMFGAIN_MASK;
+ cal_gain = drv2624_reg_read(pDRV2624,
+ DRV2624_REG_LOOP_CONTROL) & BEMFGAIN_MASK;
if (cal_gain < 0)
goto end;
pDRV2624->mAutoCalResult.mnCalGain = cal_gain;
end:
- dev_dbg(pDRV2624->dev, "%s: nResult = %d\n", __func__, nResult);
- return nResult;
+ dev_dbg(pDRV2624->dev, "%s: nResult = %d\n", __func__, nResult);
+ return nResult;
}
/*show calibrtion*/
static ssize_t
drv2624_show(struct device *dev, struct device_attribute *attr, char *buf)
{
- int nResult = 0;
- struct drv2624_data *pDRV2624 = dev_get_drvdata(dev);
- //return snprintf(buf, 100 ,"Cal_Result: 0x%x, CalComp: 0x%x, CalBemf: 0x%x, CalGain: 0x%x\n"
- //, nResult, cal_comp, cal_bemf, cal_gain);
+ int nResult = 0;
+ struct drv2624_data *pDRV2624 = dev_get_drvdata(dev);
- nResult = drv2624_get_calibration_result(pDRV2624);
- if (nResult < 0)
+ nResult = drv2624_get_calibration_result(pDRV2624);
+ if (nResult < 0)
goto end;
- dev_dbg(pDRV2624->dev,
+ dev_dbg(pDRV2624->dev,
"%s: Cal_Result: 0x%x, CalComp: 0x%x, CalBemf: 0x%x, CalGain: 0x%x\n",
- __func__, pDRV2624->mnIntStatus, pDRV2624->mAutoCalResult.mnCalComp,
- pDRV2624->mAutoCalResult.mnCalBemf, pDRV2624->mAutoCalResult.mnCalGain);
-
- return snprintf(buf, 100 ,"Cal_Result: 0x%x, CalComp: 0x%x, CalBemf: 0x%x, CalGain: 0x%x\n",
- pDRV2624->mnIntStatus, pDRV2624->mAutoCalResult.mnCalComp,
- pDRV2624->mAutoCalResult.mnCalBemf, pDRV2624->mAutoCalResult.mnCalGain);
+ __func__, pDRV2624->mAutoCalResult.mnResult,
+ pDRV2624->mAutoCalResult.mnCalComp,
+ pDRV2624->mAutoCalResult.mnCalBemf,
+ pDRV2624->mAutoCalResult.mnCalGain);
+ return snprintf(buf, 100,
+ "Cal_Result: 0x%x, CalComp: 0x%x, CalBemf: 0x%x, CalGain: 0x%x\n",
+ pDRV2624->mAutoCalResult.mnResult,
+ pDRV2624->mAutoCalResult.mnCalComp,
+ pDRV2624->mAutoCalResult.mnCalBemf,
+ pDRV2624->mAutoCalResult.mnCalGain);
end:
- return nResult;
+ return nResult;
}
/* store calibration*/
nResult = drv2624_change_mode(pDRV2624, DRV2624_DIAG_MODE);
if (nResult < 0)
goto end;
-
nResult = drv2624_set_go_bit(pDRV2624, GO);
if (nResult < 0)
goto end;
- dev_dbg(pDRV2624->dev, "%s: Diag start\n", __func__);
+ dev_dbg(pDRV2624->dev, "%s: Diag start\n", __func__);
pDRV2624->mnVibratorPlaying = YES;
value = drv2624_reg_read(pDRV2624, DRV2624_REG_STATUS);
- if (value < 0) {
+ if (value < 0)
return value;
- }
- drv2624_get_diag_result(pDRV2624, value);
+
+ dev_dbg(pDRV2624->dev, "%s:DRV2624_REG_STATUS=0x%x\n", __func__, value);
+
+ drv2624_get_diag_result(pDRV2624, value);
end:
return nResult;
}
dev_dbg(pDRV2624->dev, "effects start\n");
pDRV2624->mnVibratorPlaying = YES;
- if (!pDRV2624->mbIRQUsed) {
+ if (!pDRV2624->mbIRQUsed)
schedule_work(&pDRV2624->vibrator_work);
- }
end:
return nResult;
len++;
if (pSequencer->msWaveform[i].mnEffect != 0) {
if (i < 4)
- loop[0] |= (pSequencer->msWaveform[i].mnLoop << (2*i));
+ loop[0] |=
+ (pSequencer->msWaveform[i].mnLoop << (2*i));
else
- loop[1] |= (pSequencer->msWaveform[i].mnLoop << (2*(i-4)));
+ loop[1] |=
+ (pSequencer->msWaveform[i].mnLoop << (2*(i-4)));
effects[i] = pSequencer->msWaveform[i].mnEffect;
} else
}
if (len == 1)
- nResult = drv2624_reg_write(pDRV2624, DRV2624_REG_SEQUENCER_1, 0);
+ nResult = drv2624_reg_write(pDRV2624,
+ DRV2624_REG_SEQUENCER_1, 0);
else
- nResult = drv2624_bulk_write(pDRV2624, DRV2624_REG_SEQUENCER_1, effects, len);
+ nResult = drv2624_bulk_write(pDRV2624,
+ DRV2624_REG_SEQUENCER_1, effects, len);
if (nResult < 0) {
dev_err(pDRV2624->dev, "sequence error\n");
if (len > 1) {
if ((len-1) <= 4)
- drv2624_reg_write(pDRV2624, DRV2624_REG_SEQ_LOOP_1, loop[0]);
+ drv2624_reg_write(pDRV2624,
+ DRV2624_REG_SEQ_LOOP_1, loop[0]);
else
- drv2624_bulk_write(pDRV2624, DRV2624_REG_SEQ_LOOP_1, loop, 2);
+ drv2624_bulk_write(pDRV2624,
+ DRV2624_REG_SEQ_LOOP_1, loop, 2);
}
end:
static int fw_chksum(const struct firmware *fw)
{
int sum = 0;
- int i=0;
+ int i = 0;
int size = fw->size;
const unsigned char *pBuf = fw->data;
- for (i=0; i < size; i++) {
+ for (i = 0; i < size; i++) {
if ((i <= 11) || (i >= 16))
sum += pBuf[i];
}
return sum;
}
-static int drv2624_get_effect_timems(struct drv2624_data *pDRV2624, unsigned char effect)
+static int
+drv2624_get_effect_timems(struct drv2624_data *pDRV2624, unsigned char effect)
{
unsigned char *fw = &pDRV2624->mnFwRam[0];
u16 header_address, tmp;
@@ -696,28 +725,30 @@ static int drv2624_get_effect_timems(struct drv2624_data *pDRV2624, unsigned cha
effect_repeats = (fw[header_address+2] & 0xe0) >> 5;
effect_size = fw[header_address+2] & 0x1f;
- for (i = 0; i< effect_size/2; i++) {
+ for (i = 0; i < effect_size/2; i++)
ticks += fw[address + (i * 2) + 1];
- }
- playback_interval = (pDRV2624->msWaveformSetting.mnInterval == INTERVAL_5MS) ? 5 : 1;
+
+ playback_interval =
+ (pDRV2624->msWaveformSetting.mnInterval == INTERVAL_5MS) ? 5 : 1;
return ticks * (effect_repeats + 1) * playback_interval;
}
-/* drv2624_firmware_load:
-* This function is called by the
-* request_firmware_nowait function as soon
-* as the firmware has been loaded from the file.
-* The firmware structure contains the data and$
-* the size of the firmware loaded.
-*
-* @fw: pointer to firmware file to be dowloaded
-* @context: pointer variable to drv2624 data
-*/
+/**
+ * drv2624_firmware_load:
+ * This function is called by the
+ * request_firmware_nowait function as soon
+ * as the firmware has been loaded from the file.
+ * The firmware structure contains the data and$
+ * the size of the firmware loaded.
+ *
+ * @fw: pointer to firmware file to be dowloaded
+ * @context: pointer variable to drv2624 data
+ **/
static void drv2624_firmware_load(const struct firmware *fw, void *context)
{
struct drv2624_data *pDRV2624 = context;
- int size = 0, fwsize = 0, i=0;
+ int size = 0, fwsize = 0, i = 0;
const unsigned char *pBuf = NULL;
mutex_lock(&pDRV2624->lock);
pBuf = fw->data;
size = fw->size;
if (size > 1024) {
- dev_err(pDRV2624->dev,"%s, ERROR!! firmware size %d too big\n",
+ dev_err(pDRV2624->dev,
+ "%s, ERROR!! firmware size %d too big\n",
__func__, size);
} else {
- memcpy(&(pDRV2624->fw_header), pBuf, sizeof(struct drv2624_fw_header));
+ memcpy(&(pDRV2624->fw_header), pBuf,
+ sizeof(struct drv2624_fw_header));
if ((pDRV2624->fw_header.fw_magic != DRV2624_MAGIC)
|| (pDRV2624->fw_header.fw_size != size)
- || (pDRV2624->fw_header.fw_chksum != fw_chksum(fw))) {
+ || (pDRV2624->fw_header.fw_chksum !=
+ fw_chksum(fw))) {
dev_err(pDRV2624->dev,
- "%s, ERROR!! firmware not right:Magic=0x%x, Size=%d, chksum=0x%x\n",
- __func__, pDRV2624->fw_header.fw_magic,
- pDRV2624->fw_header.fw_size, pDRV2624->fw_header.fw_chksum);
+ "%s, ERROR!! firmware not right: Magic=0x%x, Size=%d, chksum=0x%x\n",
+ __func__, pDRV2624->fw_header.fw_magic,
+ pDRV2624->fw_header.fw_size,
+ pDRV2624->fw_header.fw_chksum);
} else {
- dev_info(pDRV2624->dev,"%s, firmware good\n", __func__);
+ dev_info(pDRV2624->dev, "%s, firmware good\n",
+ __func__);
//pDRV2624->play.effect_count = pDRV2624->fw_header.fw_effCount;
pBuf += sizeof(struct drv2624_fw_header);
- drv2624_reg_write(pDRV2624, DRV2624_REG_RAM_ADDR_UPPER, 0);
- drv2624_reg_write(pDRV2624, DRV2624_REG_RAM_ADDR_LOWER, 0);
-
- fwsize = size - sizeof(struct drv2624_fw_header);
- for(i = 0; i < fwsize; i++)
- drv2624_reg_write(pDRV2624, DRV2624_REG_RAM_DATA, pBuf[i]);
-
- memset(&pDRV2624->mnFwRam[0], 0, DRV2624_RAM_SIZE);
+ drv2624_reg_write(pDRV2624,
+ DRV2624_REG_RAM_ADDR_UPPER, 0);
+ drv2624_reg_write(pDRV2624,
+ DRV2624_REG_RAM_ADDR_LOWER, 0);
+
+ fwsize =
+ size - sizeof(struct drv2624_fw_header);
+ for (i = 0; i < fwsize; i++)
+ drv2624_reg_write(pDRV2624,
+ DRV2624_REG_RAM_DATA, pBuf[i]);
+ memset(&pDRV2624->mnFwRam[0],
+ 0, DRV2624_RAM_SIZE);
memcpy(&pDRV2624->mnFwRam[0], pBuf, fwsize);
for (i = 0; i < pDRV2624->fw_header.fw_effCount; i++)
- pDRV2624->mnEffectTimems[i] = drv2624_get_effect_timems(pDRV2624, i);
+ pDRV2624->mnEffectTimems[i] =
+ drv2624_get_effect_timems(pDRV2624, i);
}
}
} else
- dev_err(pDRV2624->dev, "%s, ERROR!! firmware not found\n", __func__);
+ dev_err(pDRV2624->dev,
+ "%s, ERROR!! firmware not found\n", __func__);
release_firmware(fw);
if (!try_module_get(THIS_MODULE))
return -ENODEV;
- file->private_data = (void*)g_DRV2624data;
+ file->private_data = (void *)g_DRV2624data;
return 0;
}
static int drv2624_file_release(struct inode *inode, struct file *file)
{
- file->private_data = (void*)NULL;
+ file->private_data = (void *)NULL;
module_put(THIS_MODULE);
return 0;
}
-static long drv2624_file_unlocked_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
+static long drv2624_file_unlocked_ioctl(struct file *file,
+ unsigned int cmd, unsigned long arg)
{
struct drv2624_data *pDRV2624 = file->private_data;
//void __user *user_arg = (void __user *)arg;
@@ -799,9 +842,11 @@ static long drv2624_file_unlocked_ioctl(struct file *file, unsigned int cmd, uns
return nResult;
}
-static ssize_t drv2624_file_read(struct file* filp, char* buff, size_t length, loff_t* offset)
+static ssize_t drv2624_file_read(struct file *filp,
+ char *buff, size_t length, loff_t *offset)
{
- struct drv2624_data *pDRV2624 = (struct drv2624_data *)filp->private_data;
+ struct drv2624_data *pDRV2624 =
+ (struct drv2624_data *)filp->private_data;
int nResult = 0;
unsigned char value = 0;
unsigned char *p_kBuf = NULL;
@@ -811,13 +856,15 @@ static ssize_t drv2624_file_read(struct file* filp, char* buff, size_t length, l
switch (pDRV2624->mnFileCmd) {
case HAPTIC_CMDID_REG_READ:
if (length == 1) {
- nResult = drv2624_reg_read(pDRV2624, pDRV2624->mnCurrentReg);
+ nResult = drv2624_reg_read(pDRV2624,
+ pDRV2624->mnCurrentReg);
if (nResult >= 0) {
value = nResult;
nResult = copy_to_user(buff, &value, 1);
- if (0 != nResult) {
+ if (nResult != 0) {
/* Failed to copy all the data, exit */
- dev_err(pDRV2624->dev, "copy to user fail %d\n", nResult);
+ dev_err(pDRV2624->dev,
+ "copy to user fail %d\n", nResult);
}
}
} else if (length > 1) {
@@ -826,10 +873,13 @@ static ssize_t drv2624_file_read(struct file* filp, char* buff, size_t length, l
nResult = drv2624_bulk_read(pDRV2624,
pDRV2624->mnCurrentReg, p_kBuf, length);
if (nResult >= 0) {
- nResult = copy_to_user(buff, p_kBuf, length);
- if (0 != nResult) {
- /* Failed to copy all the data, exit */
- dev_err(pDRV2624->dev, "copy to user fail %d\n", nResult);
+ nResult =
+ copy_to_user(buff, p_kBuf, length);
+ if (nResult != 0) {
+ /* Failed to copy all the data, exit */
+ dev_err(pDRV2624->dev,
+ "copy to user fail %d\n",
+ nResult);
}
}
@@ -851,15 +901,16 @@ static ssize_t drv2624_file_read(struct file* filp, char* buff, size_t length, l
buf[1] = pDRV2624->mDiagResult.mnDiagZ;
buf[2] = pDRV2624->mDiagResult.mnDiagK;
nResult = copy_to_user(buff, buf, 3);
- if (0 != nResult) {
+ if (nResult != 0) {
/* Failed to copy all the data, exit */
- dev_err(pDRV2624->dev, "copy to user fail %d\n", nResult);
+ dev_err(pDRV2624->dev,
+ "copy to user fail %d\n", nResult);
}
}
break;
case HAPTIC_CMDID_RUN_CALIBRATION:
- if (pDRV2624->mnVibratorPlaying)
+ if (!pDRV2624->mnVibratorPlaying)
length = 0;
else {
unsigned char buf[4];
@@ -869,26 +920,26 @@ static ssize_t drv2624_file_read(struct file* filp, char* buff, size_t length, l
buf[2] = pDRV2624->mAutoCalResult.mnCalBemf;
buf[3] = pDRV2624->mAutoCalResult.mnCalGain;
nResult = copy_to_user(buff, buf, 4);
- if (0 != nResult) {
+ if (nResult != 0) {
/* Failed to copy all the data, exit */
- dev_err(pDRV2624->dev, "copy to user fail %d\n", nResult);
+ dev_err(pDRV2624->dev,
+ "copy to user fail %d\n", nResult);
}
}
break;
-
default:
pDRV2624->mnFileCmd = 0;
break;
}
-
mutex_unlock(&pDRV2624->lock);
- return length;
+ return length;
}
-
-static ssize_t drv2624_file_write(struct file* filp, const char* buff, size_t len, loff_t* off)
+static ssize_t
+drv2624_file_write(struct file *filp, const char *buff, size_t len, loff_t *off)
{
- struct drv2624_data *pDRV2624 = (struct drv2624_data *)filp->private_data;
+ struct drv2624_data *pDRV2624 =
+ (struct drv2624_data *)filp->private_data;
unsigned char *p_kBuf = NULL;
int nResult = 0;
@@ -896,31 +947,34 @@ static ssize_t drv2624_file_write(struct file* filp, const char* buff, size_t le
p_kBuf = (unsigned char *)kzalloc(len, GFP_KERNEL);
if (p_kBuf == NULL) {
- dev_err(pDRV2624->dev, "write no mem\n");
+ //dev_err(pDRV2624->dev, "write no mem\n");
goto err;
}
nResult = copy_from_user(p_kBuf, buff, len);
- if (0 != nResult) {
- dev_err(pDRV2624->dev,"copy_from_user failed.\n");
+ if (nResult != 0) {
+ dev_err(pDRV2624->dev, "copy_from_user failed.\n");
goto err;
}
pDRV2624->mnFileCmd = p_kBuf[0];
- switch(pDRV2624->mnFileCmd) {
+ switch (pDRV2624->mnFileCmd) {
case HAPTIC_CMDID_REG_READ:
if (len == 2)
pDRV2624->mnCurrentReg = p_kBuf[1];
else
- dev_err(pDRV2624->dev, " read cmd len %lu err\n", (unsigned long)len);
+ dev_err(pDRV2624->dev,
+ " read cmd len %lu err\n", (unsigned long)len);
break;
case HAPTIC_CMDID_REG_WRITE:
if ((len - 1) == 2)
- nResult = drv2624_reg_write(pDRV2624, p_kBuf[1], p_kBuf[2]);
+ nResult = drv2624_reg_write(pDRV2624,
+ p_kBuf[1], p_kBuf[2]);
else if ((len - 1) > 2)
- nResult = drv2624_bulk_write(pDRV2624, p_kBuf[1], &p_kBuf[2], len-2);
+ nResult = drv2624_bulk_write(pDRV2624,
+ p_kBuf[1], &p_kBuf[2], len-2);
else
dev_err(pDRV2624->dev, "%s, reg_write len %lu error\n",
__func__, (unsigned long)len);
@@ -941,6 +995,7 @@ static ssize_t drv2624_file_write(struct file* filp, const char* buff, size_t le
break;
nResult = dev_auto_calibrate(pDRV2624);
+ nResult = drv2624_get_calibration_result(pDRV2624);
if ((nResult >= 0) && pDRV2624->mbIRQUsed)
drv2624_enableIRQ(pDRV2624, NO);
break;
if (p_kBuf != NULL)
kfree(p_kBuf);
- mutex_unlock(&pDRV2624->lock);
+ mutex_unlock(&pDRV2624->lock);
- return len;
+ return len;
}
-
static void upload_periodic_work_routine(struct work_struct *work)
{
struct drv2624_data *pDRV2624 =
mutex_lock(&pDRV2624->lock);
nResult = drv2624_stop(pDRV2624);
- if (nResult < 0) {
+ if (nResult < 0)
return;
- }
- nResult = drv2624_set_waveform(pDRV2624, &pDRV2624->msWaveformSequencer);
+ nResult =
+ drv2624_set_waveform(pDRV2624, &pDRV2624->msWaveformSequencer);
if (nResult < 0)
- dev_err(pDRV2624->dev, "Configurate predefined effect %d failed, nResult=%d\n",
- pDRV2624->msWaveformSequencer.msWaveform[0].mnEffect, nResult);
- dev_dbg(pDRV2624->dev, "Configurate predefined effect success, effect=%d\n",
+ dev_err(pDRV2624->dev,
+ "Configurate predefined effect %d failed, nResult=%d\n",
+ pDRV2624->msWaveformSequencer.msWaveform[0].mnEffect, nResult);
+ dev_dbg(pDRV2624->dev,
+ "Configurate predefined effect success, effect=%d\n",
pDRV2624->msWaveformSequencer.msWaveform[0].mnEffect);
mutex_unlock(&pDRV2624->lock);
s64 time_us;
uint time_ms = 0;
- pr_info("%s enter function \n", __func__);
+ pr_info("%s enter function\n", __func__);
mutex_lock(&pDRV2624->lock);
/* waiting last vibration to end */
- if (hrtimer_active(&pDRV2624->haptics_timer)) {
+ if (hrtimer_active(&pDRV2624->haptics_timer)) {
rem = hrtimer_get_remaining(&pDRV2624->haptics_timer);
time_us = ktime_to_us(rem);
dev_info(pDRV2624->dev,
"%s: waiting for playing finished: %lld us\n",
__func__, time_us);
usleep_range(time_us, time_us + 100);
- }
+
+ }
pDRV2624->mnEffectType = effect->type;
dev_info(pDRV2624->dev, "%s: mnEffectType: %d\n",
- __func__, pDRV2624->mnEffectType);
+ __func__, pDRV2624->mnEffectType);
switch (pDRV2624->mnEffectType) {
case FF_CONSTANT:
dev_info(pDRV2624->dev, "%s: length(%d), level(%d)\n",
__func__, play->length, play->rtp_input);
break;
-
case FF_PERIODIC:
#ifdef NEED_RELOAD_FIRMWARE
if (pDRV2624->fw_header.fw_magic == 0) {
GFP_KERNEL,
pDRV2624,
drv2624_firmware_load);
- dev_info(pDRV2624->dev,"%s:request_firmware_nowait nResult=%d\n", __func__, nResult);
-
+ dev_info(pDRV2624->dev,
+ "%s:request_firmware_nowait nResult=%d\n",
+ __func__, nResult);
}
#endif
if (effect->u.periodic.waveform != FF_CUSTOM) {
- dev_err(pDRV2624->dev, "Only accept custom waveforms\n");
+ dev_err(pDRV2624->dev, "Only accept custom waveform\n");
nResult = -EINVAL;
break;
}
if (copy_from_user(data, effect->u.periodic.custom_data,
- sizeof(u16) * CUSTOM_DATA_LEN)) {
+ sizeof(u16) * CUSTOM_DATA_LEN)) {
nResult = -EFAULT;
break;
}
play->magnitude = effect->u.periodic.magnitude;
pDRV2624->mnWorkMode = DRV2624_RAM_MODE;
dev_dbg(pDRV2624->dev, "%s: effect_id = %d, magnitude = %d\n",
- __func__, play->effect_id, play->magnitude);
+ __func__, play->effect_id, play->magnitude);
if ((play->effect_id < 0) ||
(play->effect_id > pDRV2624->fw_header.fw_effCount)) {
- dev_err(pDRV2624->dev, "%s: overflow effect_id = %d, max_effect_id = %d\n",
- __func__, play->effect_id, pDRV2624->fw_header.fw_effCount);
+ dev_err(pDRV2624->dev,
+ "%s: overflow effect_id=%d, max_effect_id=%d\n",
+ __func__, play->effect_id,
+ pDRV2624->fw_header.fw_effCount);
nResult = -EINVAL;
break;
}
- pr_info("%s next upload to use effect \n", __func__);
- memset(&pDRV2624->msWaveformSequencer, 0, sizeof(struct drv2624_waveform_sequencer));
- pDRV2624->msWaveformSequencer.msWaveform[0].mnEffect = data[CUSTOM_DATA_EFFECT_IDX];
+ pr_info("%s next upload to use effect\n", __func__);
+ memset(&pDRV2624->msWaveformSequencer, 0,
+ sizeof(struct drv2624_waveform_sequencer));
+ pDRV2624->msWaveformSequencer.msWaveform[0].mnEffect =
+ data[CUSTOM_DATA_EFFECT_IDX];
pDRV2624->msWaveformSequencer.msWaveform[0].mnLoop = 0;
pDRV2624->msWaveformSequencer.msWaveform[1].mnEffect = 0;
pDRV2624->msWaveformSequencer.msWaveform[1].mnLoop = 0;
dev_dbg(pDRV2624->dev, "upload to use effect %d\n",
data[CUSTOM_DATA_EFFECT_IDX]);
- time_ms = pDRV2624->mnEffectTimems[data[CUSTOM_DATA_EFFECT_IDX] - 1];
+ time_ms =
+ pDRV2624->mnEffectTimems[data[CUSTOM_DATA_EFFECT_IDX] - 1];
dev_dbg(pDRV2624->dev, "effect playing time_ms %d\n", time_ms);
data[CUSTOM_DATA_TIMEOUT_SEC_IDX] =
*/
if (copy_to_user(effect->u.periodic.custom_data, data,
sizeof(u16) * CUSTOM_DATA_LEN)) {
- pr_info("%s copy to user failed \n", __func__);
+ pr_info("%s copy to user failed\n", __func__);
nResult = -EFAULT;
break;
}
}
mutex_unlock(&pDRV2624->lock);
- dev_info(pDRV2624->dev, "%s exit \n", __func__);
+ dev_info(pDRV2624->dev, "%s exit\n", __func__);
return nResult;
}
mutex_lock(&pDRV2624->lock);
- dev_dbg(pDRV2624->dev, "%s enter effect.lenth(%d) \n",
+ dev_dbg(pDRV2624->dev, "%s enter effect.lenth(%d)\n",
__func__, pDRV2624->play.length);
nResult = drv2624_stop(pDRV2624);
- if (nResult < 0) {
+ if (nResult < 0) {
dev_err(pDRV2624->dev, "%s: stop faild!\n", __func__);
goto end;
- }
+ }
- switch(pDRV2624->mnEffectType) {
+ switch (pDRV2624->mnEffectType) {
case FF_PERIODIC:
nResult = drv2624_stop(pDRV2624);
if (nResult < 0)
case FF_CONSTANT:
drv2624_stop(pDRV2624);
- nResult = drv2624_change_mode(pDRV2624, DRV2624_RTP_MODE);
- if (nResult < 0){
+ nResult =
+ drv2624_change_mode(pDRV2624, DRV2624_RTP_MODE);
+ if (nResult < 0) {
dev_dbg(pDRV2624->dev,
"%s: change_mode nResult = %d\n",
__func__, nResult);
break;
}
- nResult = drv2624_reg_write(pDRV2624, DRV2624_REG_RTP_INPUT, 0x7f);
+ nResult = drv2624_reg_write(pDRV2624,
+ DRV2624_REG_RTP_INPUT, 0x7f);
if (nResult < 0)
break;
mutex_unlock(&pDRV2624->lock);
}
-static int drv2624_haptics_playback(struct input_dev *dev, int effect_id, int val)
+static int drv2624_haptics_playback(struct input_dev *dev,
+ int effect_id, int val)
{
- struct drv2624_data *pDRV2624 = input_get_drvdata(dev);
int nResult = 0;
+ struct drv2624_data *pDRV2624 = input_get_drvdata(dev);
- dev_dbg(pDRV2624->dev, "%s: mnEffectType(%d) WorkMode(%d)\n",
+ dev_dbg(pDRV2624->dev, "%s: mnEffectType(%d) WorkMode(%d)\n",
__func__, pDRV2624->mnEffectType, pDRV2624->mnWorkMode);
if ((pDRV2624->mnEffectType == FF_CONSTANT) &&
(pDRV2624->mnWorkMode == DRV2624_RTP_MODE)) {
- if(hrtimer_active(&pDRV2624->haptics_timer)){
+ if (hrtimer_active(&pDRV2624->haptics_timer))
hrtimer_cancel(&pDRV2624->haptics_timer);
- }
+
schedule_work(&pDRV2624->haptics_playback_work);
} else if ((pDRV2624->mnEffectType == FF_PERIODIC) &&
- (pDRV2624->mnWorkMode == DRV2624_RAM_MODE)){
+ (pDRV2624->mnWorkMode == DRV2624_RAM_MODE)) {
schedule_work(&pDRV2624->haptics_playback_work);
} else {
dev_err(pDRV2624->dev, "%s: effect_type(%d) not supported!\n",
mutex_lock(&pDRV2624->lock);
nResult = drv2624_stop(pDRV2624);
if (nResult < 0)
- dev_err(pDRV2624->dev, "failed to stop vibrator: %d\n", nResult);
+ dev_err(pDRV2624->dev, "failed to stop vibrator:%d\n", nResult);
mutex_unlock(&pDRV2624->lock);
return nResult;
struct drv2624_constant_playinfo *play = &pDRV2624->play;
mutex_lock(&pDRV2624->lock);
- nResult = drv2624_reg_write(pDRV2624, DRV2624_REG_RTP_INPUT, play->rtp_input);
+ nResult = drv2624_reg_write(pDRV2624,
+ DRV2624_REG_RTP_INPUT, play->rtp_input);
if (nResult < 0)
- dev_err(pDRV2624->dev, "Configurate RTP_INPUT failed, nResult=%d\n",
- nResult);
+ dev_err(pDRV2624->dev,
+ "Configurate RTP_INPUT failed, nResult=%d\n", nResult);
mutex_unlock(&pDRV2624->lock);
}
return;
else if (gain > 0x7f)
gain = 0x7f;
- dev_dbg(pDRV2624->dev, "drv2624_haptics_set_gain, gain=%d\n", gain);
- play->rtp_input = (gain - LIGHT_MAGNITUDE) * 255 / (STRONG_MAGNITUDE - LIGHT_MAGNITUDE);
+ dev_dbg(pDRV2624->dev, "%s, gain=%x\n", __func__, gain);
+ play->rtp_input =
+ (gain - LIGHT_MAGNITUDE) *
+ 255 / (STRONG_MAGNITUDE - LIGHT_MAGNITUDE);
//play->rtp_input = gain;
- dev_dbg(pDRV2624->dev, "upload constant effect, rtp_input=%d\n", play->rtp_input);
+ dev_dbg(pDRV2624->dev, "upload constant effect, rtp_input=%d\n",
+ play->rtp_input);
dev_dbg(pDRV2624->dev, "enter drv264_reg_write rtp_input\n");
schedule_work(&pDRV2624->haptics_set_gain_work);
}
-static struct file_operations fops =
-{
+static const struct file_operations fops = {
.owner = THIS_MODULE,
.read = drv2624_file_read,
.write = drv2624_file_write,
.release = drv2624_file_release,
};
-static struct miscdevice drv2624_misc =
-{
+static struct miscdevice drv2624_misc = {
.minor = MISC_DYNAMIC_MINOR,
.name = HAPTICS_DEVICE_NAME,
.fops = &fops,
nResult = timed_output_dev_register(&(pDRV2624->to_dev));
if (nResult < 0) {
- dev_err(pDRV2624->dev, "drv2624: fail to create timed output dev\n");
+ dev_err(pDRV2624->dev,
+ "drv2624: fail to create timed output dev\n");
return nResult;
}
#endif /* ANDROID_TIMED_OUTPUT */
nResult = device_create_file(pDRV2624->dev, &dev_attr_cali);
if (nResult < 0) {
- dev_info(pDRV2624->dev, "sys file creation failed nResult: %d\n", nResult);
+ dev_info(pDRV2624->dev,
+ "sys file creation failed nResult:%d\n", nResult);
return nResult;
}
- hrtimer_init(&pDRV2624->haptics_timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
+ hrtimer_init(&pDRV2624->haptics_timer,
+ CLOCK_MONOTONIC, HRTIMER_MODE_REL);
pDRV2624->haptics_timer.function = vibrator_timer_func;
INIT_WORK(&pDRV2624->vibrator_work, vibrator_work_routine);
- INIT_WORK(&pDRV2624->upload_periodic_work, upload_periodic_work_routine);
- INIT_WORK(&pDRV2624->haptics_playback_work, haptics_playback_work_routine);
- INIT_WORK(&pDRV2624->haptics_set_gain_work, haptics_set_gain_work_routine);
+ INIT_WORK(&pDRV2624->upload_periodic_work,
+ upload_periodic_work_routine);
+ INIT_WORK(&pDRV2624->haptics_playback_work,
+ haptics_playback_work_routine);
+ INIT_WORK(&pDRV2624->haptics_set_gain_work,
+ haptics_set_gain_work_routine);
mutex_init(&pDRV2624->lock);
return 0;
else if (actuator.mnActuatorType == LRA)
value_temp = LIB_LRA;
if (value_temp != 0)
- drv2624_set_bits(pDRV2624, DRV2624_REG_CONTROL2, LIB_MASK, value_temp<<LIB_SHIFT);
+ drv2624_set_bits(pDRV2624,
+ DRV2624_REG_CONTROL2, LIB_MASK, value_temp<<LIB_SHIFT);
if (actuator.mnRatedVoltage != 0)
- drv2624_reg_write(pDRV2624, DRV2624_REG_RATED_VOLTAGE, actuator.mnRatedVoltage);
+ drv2624_reg_write(pDRV2624,
+ DRV2624_REG_RATED_VOLTAGE, actuator.mnRatedVoltage);
else
dev_err(pDRV2624->dev, "%s, ERROR Rated ZERO\n", __func__);
-
if (actuator.mnOverDriveClampVoltage != 0)
- drv2624_reg_write(pDRV2624, DRV2624_REG_OVERDRIVE_CLAMP, actuator.mnOverDriveClampVoltage);
+ drv2624_reg_write(pDRV2624,
+ DRV2624_REG_OVERDRIVE_CLAMP,
+ actuator.mnOverDriveClampVoltage);
else
- dev_err(pDRV2624->dev,"%s, ERROR OverDriveVol ZERO\n", __func__);
-
+ dev_err(pDRV2624->dev,
+ "%s, ERROR OverDriveVol ZERO\n", __func__);
if (actuator.mnActuatorType == LRA) {
- unsigned char DriveTime = 5*(1000 - actuator.mnLRAFreq)/actuator.mnLRAFreq;
+ unsigned char DriveTime =
+ 5*(1000 - actuator.mnLRAFreq)/actuator.mnLRAFreq;
unsigned short openLoopPeriod =
- (unsigned short)((unsigned int)1000000000 / (24619 * actuator.mnLRAFreq));
+ (unsigned short)(1000000000 /
+ (24619 * actuator.mnLRAFreq));
if (actuator.mnLRAFreq < 125)
DriveTime |= (MINFREQ_SEL_45HZ << MINFREQ_SEL_SHIFT);
drv2624_set_bits(pDRV2624, DRV2624_REG_DRIVE_TIME,
- DRIVE_TIME_MASK | MINFREQ_SEL_MASK, DriveTime);
- drv2624_set_bits(pDRV2624, DRV2624_REG_OL_PERIOD_H, 0x03, (openLoopPeriod&0x0300)>>8);
- drv2624_reg_write(pDRV2624, DRV2624_REG_OL_PERIOD_L, (openLoopPeriod&0x00ff));
+ DRIVE_TIME_MASK | MINFREQ_SEL_MASK, DriveTime);
+ drv2624_set_bits(pDRV2624,
+ DRV2624_REG_OL_PERIOD_H, 0x03,
+ (openLoopPeriod&0x0300)>>8);
+ drv2624_reg_write(pDRV2624, DRV2624_REG_OL_PERIOD_L,
+ (openLoopPeriod&0x00ff));
dev_info(pDRV2624->dev, "%s, LRA = %d, DriveTime=0x%x\n",
- __func__, actuator.mnLRAFreq, DriveTime);
+ __func__, actuator.mnLRAFreq, DriveTime);
}
value = drv2624_reg_read(pDRV2624, DRV2624_REG_CONTROL2);
- wavesetting.mnLoop = drv2624_reg_read(pDRV2624, DRV2624_REG_MAIN_LOOP)&0x07;
+ wavesetting.mnLoop = drv2624_reg_read(pDRV2624,
+ DRV2624_REG_MAIN_LOOP)&0x07;
wavesetting.mnInterval = ((value&INTERVAL_MASK)>>INTERVAL_SHIFT);
wavesetting.mnScale = (value&SCALE_MASK);
- memcpy(&pDRV2624->msWaveformSetting, &wavesetting, sizeof(struct drv2624_wave_setting));
+ memcpy(&pDRV2624->msWaveformSetting,
+ &wavesetting,
+ sizeof(struct drv2624_wave_setting));
}
static irqreturn_t drv2624_irq_handler(int irq, void *dev_id)
@@ -1388,88 +1472,101 @@ static int drv2624_parse_dt(struct device *dev, struct drv2624_data *pDRV2624)
{
struct device_node *np = dev->of_node;
struct drv2624_platform_data *pPlatData = &pDRV2624->msPlatData;
- int rc= 0, nResult = 0;
+ int rc = 0, nResult = 0;
unsigned int value;
pPlatData->mnGpioNRST = of_get_named_gpio(np, "ti,reset-gpio", 0);
- if (pPlatData->mnGpioNRST < 0) {
- dev_err(pDRV2624->dev, "Looking up %s property in node %s failed %d\n",
+ if (pPlatData->mnGpioNRST >= 0) {
+ dev_dbg(pDRV2624->dev,
+ "ti,reset-gpio=%d\n", pPlatData->mnGpioNRST);
+ } else {
+ dev_err(pDRV2624->dev,
+ "Looking up %s property in node %s failed %d\n",
"ti,reset-gpio", np->full_name, pPlatData->mnGpioNRST);
return -EINVAL;
- } else
- dev_dbg(pDRV2624->dev, "ti,reset-gpio=%d\n", pPlatData->mnGpioNRST);
+ }
rc = of_property_read_u32(np, "ti,smart-loop", &value);
- if (rc) {
- dev_err(pDRV2624->dev, "Looking up %s property in node %s failed %d\n",
- "ti,smart-loop", np->full_name, rc);
- return -EINVAL;
- } else {
+ if (rc == 0) {
pPlatData->mnLoop = value & 0x01;
dev_dbg(pDRV2624->dev, "ti,smart-loop=%d\n", pPlatData->mnLoop);
+ } else {
+ dev_err(pDRV2624->dev,
+ "Looking up %s property in node %s failed %d\n",
+ "ti,smart-loop", np->full_name, rc);
+ return -EINVAL;
}
rc = of_property_read_u32(np, "ti,actuator", &value);
- if (rc) {
- dev_err(pDRV2624->dev, "Looking up %s property in node %s failed %d\n",
- "ti,actuator", np->full_name, rc);
- return -EINVAL;
- } else {
+ if (rc == 0) {
pPlatData->msActuator.mnActuatorType = value & 0x01;
dev_dbg(pDRV2624->dev, "ti,actuator=%d\n",
pPlatData->msActuator.mnActuatorType);
+ } else {
+ dev_err(pDRV2624->dev,
+ "Looking up %s property in node %s failed %d\n",
+ "ti,actuator", np->full_name, rc);
+ return -EINVAL;
}
rc = of_property_read_u32(np, "ti,rated-voltage", &value);
- if (rc) {
- dev_err(pDRV2624->dev, "Looking up %s property in node %s failed %d\n",
- "ti,rated-voltage", np->full_name, rc);
- return -EINVAL;
- }else{
- pPlatData->msActuator.mnRatedVoltage = drv2624_calculate_voltage(value);
+ if (rc == 0) {
+ pPlatData->msActuator.mnRatedVoltage =
+ drv2624_calculate_voltage(value);
dev_dbg(pDRV2624->dev, "ti,rated-voltage=0x%x\n",
pPlatData->msActuator.mnRatedVoltage);
+ } else {
+ dev_err(pDRV2624->dev,
+ "Looking up %s property in node %s failed %d\n",
+ "ti,rated-voltage", np->full_name, rc);
+ return -EINVAL;
}
rc = of_property_read_u32(np, "ti,odclamp-voltage", &value);
- if (rc) {
- dev_err(pDRV2624->dev, "Looking up %s property in node %s failed %d\n",
- "ti,odclamp-voltage", np->full_name, rc);
- return -EINVAL;
- } else {
+ if (rc == 0) {
pPlatData->msActuator.mnOverDriveClampVoltage =
drv2624_calculate_voltage(value);
dev_dbg(pDRV2624->dev, "ti,odclamp-voltage=0x%x\n",
pPlatData->msActuator.mnOverDriveClampVoltage);
+ } else {
+ dev_err(pDRV2624->dev,
+ "Looking up %s property in node %s failed %d\n",
+ "ti,odclamp-voltage", np->full_name, rc);
+ return -EINVAL;
+
}
if (pPlatData->msActuator.mnActuatorType == LRA) {
rc = of_property_read_u32(np, "ti,lra-frequency", &value);
- if (rc) {
- dev_err(pDRV2624->dev, "Looking up %s property in node %s failed %d\n",
- "ti,lra-frequency", np->full_name, rc);
- return -EINVAL;
- } else {
+ if (rc == 0) {
if ((value >= 45) && (value <= 300)) {
pPlatData->msActuator.mnLRAFreq = value;
dev_dbg(pDRV2624->dev, "ti,lra-frequency=%d\n",
pPlatData->msActuator.mnLRAFreq);
} else {
- dev_err(pDRV2624->dev, "ERROR, ti,lra-frequency=%d, out of range\n",
- pPlatData->msActuator.mnLRAFreq);
+ dev_err(pDRV2624->dev,
+ "ERROR, ti,lra-frequency=%d, out of range\n",
+ pPlatData->msActuator.mnLRAFreq);
return -EINVAL;
}
+ } else {
+ dev_err(pDRV2624->dev,
+ "Looking up %s property in node %s failed %d\n",
+ "ti,lra-frequency", np->full_name, rc);
+ return -EINVAL;
}
}
pPlatData->mnGpioINT = of_get_named_gpio(np, "ti,irq-gpio", 0);
- if (pPlatData->mnGpioINT < 0) {
- dev_err(pDRV2624->dev, "Looking up %s property in node %s failed %d\n",
+ if (pPlatData->mnGpioINT >= 0) {
+ dev_dbg(pDRV2624->dev,
+ "ti,irq-gpio=%d\n", pPlatData->mnGpioINT);
+ } else {
+ dev_err(pDRV2624->dev,
+ "Looking up %s property in node %s failed %d\n",
"ti,irq-gpio", np->full_name, pPlatData->mnGpioINT);
return -EINVAL;
- } else
- dev_dbg(pDRV2624->dev, "ti,irq-gpio=%d\n", pPlatData->mnGpioINT);
-
+ }
return nResult;
}
dev_dbg(pDRV2624->dev, "%s\n", __func__);
mutex_lock(&pDRV2624->lock);
- if (hrtimer_active(&pDRV2624->haptics_timer) || pDRV2624->mnVibratorPlaying)
+ if (hrtimer_active(&pDRV2624->haptics_timer)
+ || pDRV2624->mnVibratorPlaying)
drv2624_stop(pDRV2624);
mutex_unlock(&pDRV2624->lock);
- return;
}
/**
{
int nResult = 0;
- dev_dbg(pDRV2624->dev, "%s: enter! \n", __func__);
+ dev_dbg(pDRV2624->dev, "%s: enter!\n", __func__);
gpio_direction_output(pDRV2624->msPlatData.mnGpioNRST, 0);
mdelay(5);
return nResult;
}
-static int drv2624_i2c_probe(struct i2c_client* client, const struct i2c_device_id* id)
+static int drv2624_i2c_probe(struct i2c_client *client,
+ const struct i2c_device_id *id)
{
int nResult = 0;
struct drv2624_data *pDRV2624;
@@ -1524,22 +1622,23 @@ static int drv2624_i2c_probe(struct i2c_client* client, const struct i2c_device_
return -ENODEV;
}
- pDRV2624 = devm_kzalloc(&client->dev, sizeof(struct drv2624_data), GFP_KERNEL);
+ pDRV2624 = devm_kzalloc(&client->dev,
+ sizeof(struct drv2624_data), GFP_KERNEL);
if (pDRV2624 == NULL) {
- dev_err(&client->dev, "%s:no memory\n", __func__);
+ //dev_err(&client->dev, "%s: error\n", __func__);
return -ENOMEM;
}
pDRV2624->dev = &client->dev;
pDRV2624->client = client;
- i2c_set_clientdata(client,pDRV2624);
+ i2c_set_clientdata(client, pDRV2624);
dev_set_drvdata(&client->dev, pDRV2624);
pDRV2624->mpRegmap = devm_regmap_init_i2c(client, &drv2624_i2c_regmap);
if (IS_ERR(pDRV2624->mpRegmap)) {
nResult = PTR_ERR(pDRV2624->mpRegmap);
- dev_err(pDRV2624->dev, "%s:Failed to allocate register map: %d\n",
- __func__, nResult);
+ dev_err(pDRV2624->dev, "%s:Fail to allocate register map:%d\n",
+ __func__, nResult);
goto free_mem;
}
@@ -1548,23 +1647,26 @@ static int drv2624_i2c_probe(struct i2c_client* client, const struct i2c_device_
nResult = drv2624_parse_dt(&client->dev, pDRV2624);
if (nResult < 0) {
dev_err(pDRV2624->dev, "%s: parse_dt failed %d\n",
- __func__, nResult);
+ __func__, nResult);
goto free_gpio;
}
} else if (client->dev.platform_data) {
dev_dbg(pDRV2624->dev, "platform data parse\n");
memcpy(&pDRV2624->msPlatData, client->dev.platform_data,
- sizeof(struct drv2624_platform_data));
+ sizeof(struct drv2624_platform_data));
} else {
- dev_err(pDRV2624->dev, "%s: ERROR no platform data\n",__func__);
+ dev_err(pDRV2624->dev,
+ "%s: ERROR no platform data\n", __func__);
goto free_gpio;
}
if (gpio_is_valid(pDRV2624->msPlatData.mnGpioNRST)) {
- nResult = gpio_request(pDRV2624->msPlatData.mnGpioNRST,"DRV2624-NRST");
+ nResult = gpio_request(pDRV2624->msPlatData.mnGpioNRST,
+ "DRV2624-NRST");
if (nResult < 0) {
- dev_err(pDRV2624->dev, "%s: GPIO %d request NRST error\n",
- __func__, pDRV2624->msPlatData.mnGpioNRST);
+ dev_err(pDRV2624->dev,
+ "%s: GPIO %d request NRST error\n", __func__,
+ pDRV2624->msPlatData.mnGpioNRST);
goto free_gpio;
}
drv2624_hw_reset(pDRV2624);
@@ -1576,7 +1678,8 @@ static int drv2624_i2c_probe(struct i2c_client* client, const struct i2c_device_
if (nResult < 0)
goto destroy_mutex;
else {
- dev_info(pDRV2624->dev, "%s, ID status (0x%x)\n", __func__, nResult);
+ dev_info(pDRV2624->dev,
+ "%s, ID status (0x%x)\n", __func__, nResult);
pDRV2624->mnDeviceID = nResult;
}
@@ -1589,20 +1692,25 @@ static int drv2624_i2c_probe(struct i2c_client* client, const struct i2c_device_
drv2624_init(pDRV2624);
if (gpio_is_valid(pDRV2624->msPlatData.mnGpioINT)) {
- nResult = gpio_request(pDRV2624->msPlatData.mnGpioINT, "DRV2624-IRQ");
+ nResult =
+ gpio_request(pDRV2624->msPlatData.mnGpioINT, "DRV2624-IRQ");
if (nResult < 0) {
- dev_err(pDRV2624->dev, "%s: GPIO %d request INT error\n",
+ dev_err(pDRV2624->dev, "%s: GPIO %d request INT err\n",
__func__, pDRV2624->msPlatData.mnGpioINT);
goto destroy_mutex;
}
gpio_direction_input(pDRV2624->msPlatData.mnGpioINT);
pDRV2624->mnIRQ = gpio_to_irq(pDRV2624->msPlatData.mnGpioINT);
- dev_dbg(pDRV2624->dev, "irq = %d \n", pDRV2624->mnIRQ);
- nResult = request_threaded_irq(pDRV2624->mnIRQ, drv2624_irq_handler,
- NULL, IRQF_TRIGGER_FALLING | IRQF_ONESHOT, client->name, pDRV2624);
+ dev_dbg(pDRV2624->dev, "irq = %d\n", pDRV2624->mnIRQ);
+
+ nResult = request_threaded_irq(pDRV2624->mnIRQ,
+ drv2624_irq_handler, NULL,
+ IRQF_TRIGGER_FALLING | IRQF_ONESHOT,
+ client->name, pDRV2624);
if (nResult < 0) {
- dev_err(pDRV2624->dev, "request_irq failed, %d\n", nResult);
+ dev_err(pDRV2624->dev,
+ "request_irq failed, %d\n", nResult);
goto destroy_mutex;
}
if (gpio_is_valid(pDRV2624->msPlatData.mnGpioNRST))
gpio_free(pDRV2624->msPlatData.mnGpioNRST);
free_mem:
- if (NULL != pDRV2624)
- kfree(pDRV2624);
+ if (pDRV2624 != NULL)
+ kfree(pDRV2624);
return nResult;
}
-static int drv2624_i2c_remove(struct i2c_client* client)
+static int drv2624_i2c_remove(struct i2c_client *client)
{
struct drv2624_data *pDRV2624 = i2c_get_clientdata(client);
- if(pDRV2624->msPlatData.mnGpioNRST)
+ if (pDRV2624->msPlatData.mnGpioNRST)
gpio_free(pDRV2624->msPlatData.mnGpioNRST);
- if(pDRV2624->msPlatData.mnGpioINT)
+ if (pDRV2624->msPlatData.mnGpioINT)
gpio_free(pDRV2624->msPlatData.mnGpioINT);
misc_deregister(&drv2624_misc);
pDRV2624->mnVibratorPlaying) {
drv2624_stop(pDRV2624);
}
- /* set device to standby mode */
- drv2624_set_bits(pDRV2624,
+/*
+ * set device to standby mode
+ */
+ drv2624_set_bits(pDRV2624,
DRV2624_REG_CONTROL1,
DRV2624_AUTO_BRK_INTO_STBY_MASK,
DRV2624_STBY_MODE_WITH_AUTO_BRAKE);
dev_dbg(pDRV2624->dev, "%s enter!\n", __func__);
mutex_lock(&pDRV2624->lock);
- /* set device to active mode */
- drv2624_reg_write(pDRV2624,
+/* set device to active mode */
+ drv2624_reg_write(pDRV2624,
DRV2624_REG_CONTROL1,
DRV2624_REMOVE_STBY_MODE);
mutex_unlock(&pDRV2624->lock);
diff --git a/drv2624.h b/drv2624.h
index 602f5ae2ce77daa54c3c89db66faa0ab7c6f4226..06e017483051022c0073c82f50b40b10fc3829c9 100755 (executable)
--- a/drv2624.h
+++ b/drv2624.h
#define DRV2624_ID (0x02&DRV2624_ID_MASK)
#define DRV2624_REG_STATUS 0x01
-#define DIAG_MASK 0x80
+#define DIAG_MASK 0x80
#define DIAG_SUCCESS 0x00
-#define DIAG_SHIFT 0x07
-#define INT_MASK 0x1f
+#define DIAG_SHIFT 0x07
+#define INT_MASK 0x1f
#define PRG_ERR_MASK 0x10
#define PROCESS_DONE_MASK 0x08
-#define ULVO_MASK 0x04
+#define ULVO_MASK 0x04
#define OVERTEMPRATURE_MASK 0x02
#define OVERCURRENT_MASK 0x01
-#define DRV2624_REG_INT_ENABLE 0x02
+#define DRV2624_REG_INT_ENABLE 0x02
#define INT_MASK_ALL 0x1f
#define INT_ENABLE_ALL 0x00
#define INT_ENABLE_CRITICAL 0x08
#define DRV2624_REG_MODE 0x07
#define WORKMODE_MASK 0x03
-#define MODE_RTP 0x00
-#define MODE_WAVEFORM_SEQUENCER 0x01
+#define MODE_RTP 0x00
+#define MODE_WAVEFORM_SEQUENCER 0x01
#define MODE_DIAGNOSTIC 0x02
#define MODE_CALIBRATION 0x03
#define PINFUNC_MASK 0x0c
-#define PINFUNC_INT 0x02
+#define PINFUNC_INT 0x02
#define PINFUNC_SHIFT 0x02
#define DRV2624_CALIBRATION_MODE_CFG 0x4B
-#define DRV2624_REG_CONTROL1 0x08
+#define DRV2624_REG_CONTROL1 0x08
#define DRV2624_AUTO_BRK_INTO_STBY_MASK (0x01 << 3)
#define DRV2624_STBY_MODE_WITH_AUTO_BRAKE (0x01 << 3)
#define DRV2624_STBY_MODE_WITHOUT_AUTO_BRAKE 0x00
#define ACTUATOR_MASK 0x80
#define ACTUATOR_SHIFT 7
-#define LOOP_MASK 0x40
-#define LOOP_SHIFT 6
+#define LOOP_MASK 0x40
+#define LOOP_SHIFT 6
#define AUTOBRK_OK_MASK 0x10
#define AUTOBRK_OK_ENABLE 0x10
#define MINFREQ_SEL_MASK 0x80
#define MINFREQ_SEL_SHIFT 0x07
-#define DRV2624_REG_OL_PERIOD_H 0x2e
-#define DRV2624_REG_OL_PERIOD_L 0x2f
+#define DRV2624_REG_OL_PERIOD_H 0x2e
+#define DRV2624_REG_OL_PERIOD_L 0x2f
#define DRV2624_REG_DIAG_K 0x30
#define GO_BIT_POLL_INTERVAL 15
#define HAPTIC_CMDID_RTP_SEQUENCE 0x0d
#define HAPTIC_CMDID_GET_EFFECT_COUNT 0x10
#define HAPTIC_CMDID_UPDATE_FIRMWARE 0x11
-#define HAPTIC_CMDID_READ_FIRMWARE 0x12
+#define HAPTIC_CMDID_READ_FIRMWARE 0x12
#define HAPTIC_CMDID_RUN_CALIBRATION 0x13
#define HAPTIC_CMDID_CONFIG_WAVEFORM 0x14
#define HAPTIC_CMDID_SET_SEQUENCER 0x15