static ssize_t tspdrv_pwm_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t size) { int gain; sscanf(buf, "%d", &gain); if (gain > 128) gain = 127; else if (gain < -127) gain = -127; ImmVibeSPI_ForceOut_SetFrequency(0,0,gain); return size; }
static int ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg) #endif { switch (cmd) { case TSPDRV_SET_MAGIC_NUMBER: file->private_data = (void*)TSPDRV_MAGIC_NUMBER; break; case TSPDRV_ENABLE_AMP: ImmVibeSPI_ForceOut_AmpEnable(arg); #ifdef VIBE_RUNTIME_RECORD if (atomic_read(&g_bRuntimeRecord)) { DbgRecord((arg,";------- TSPDRV_ENABLE_AMP ---------\n")); } #else DbgRecorderReset((arg)); DbgRecord((arg,";------- TSPDRV_ENABLE_AMP ---------\n")); #endif break; case TSPDRV_DISABLE_AMP: ImmVibeSPI_ForceOut_AmpDisable(arg); #ifdef VIBE_RUNTIME_RECORD if (atomic_read(&g_bRuntimeRecord)) { DbgRecord((arg,";------- TSPDRV_DISABLE_AMP ---------\n")); } #endif break; case TSPDRV_GET_NUM_ACTUATORS: return NUM_ACTUATORS; case TSPDRV_SET_DBG_LEVEL: { long nDbgLevel; if (0 != copy_from_user((void *)&nDbgLevel, (const void __user *)arg, sizeof(long))) { /* Error copying the data */ DbgOut((DBL_ERROR, "copy_from_user failed to copy debug level data.\n")); return -1; } if (DBL_TEMP <= nDbgLevel && nDbgLevel <= DBL_OVERKILL) atomic_set(&g_nDebugLevel, nDbgLevel); else DbgOut((DBL_ERROR, "Invalid debug level requested, ignored.")); break; } case TSPDRV_GET_DBG_LEVEL: return atomic_read(&g_nDebugLevel); #ifdef VIBE_RUNTIME_RECORD case TSPDRV_SET_RUNTIME_RECORD_FLAG: { long nRecordFlag; if (0 != copy_from_user((void *)&nRecordFlag, (const void __user *)arg, sizeof(long))) { /* Error copying the data */ DbgOut((DBL_ERROR, "copy_from_user failed to copy runtime record flag.\n")); return -1; } atomic_set(&g_bRuntimeRecord, nRecordFlag); if (nRecordFlag) { int i; for (i = 0; i < NUM_ACTUATORS; i++) { DbgRecorderReset((i)); } } break; } case TSPDRV_GET_RUNTIME_RECORD_FLAG: return atomic_read(&g_bRuntimeRecord); case TSPDRV_SET_RUNTIME_RECORD_BUF_SIZE: { long nRecorderBufSize; if (0 != copy_from_user((void *)&nRecorderBufSize, (const void __user *)arg, sizeof(long))) { /* Error copying the data */ DbgOut((DBL_ERROR, "copy_from_user failed to copy recorder buffer size.\n")); return -1; } if (0 == DbgSetRecordBufferSize(nRecorderBufSize)) { DbgOut((DBL_ERROR, "DbgSetRecordBufferSize failed.\n")); return -1; } break; } case TSPDRV_GET_RUNTIME_RECORD_BUF_SIZE: return DbgGetRecordBufferSize(); #endif case TSPDRV_SET_DEVICE_PARAMETER: { device_parameter deviceParam; if (0 != copy_from_user((void *)&deviceParam, (const void __user *)arg, sizeof(deviceParam))) { /* Error copying the data */ DbgOut((DBL_ERROR, "tspdrv: copy_from_user failed to copy kernel parameter data.\n")); return -1; } switch (deviceParam.nDeviceParamID) { case VIBE_KP_CFG_UPDATE_RATE_MS: /* Update the timer period */ g_nTimerPeriodMs = deviceParam.nDeviceParamValue; #ifdef CONFIG_HIGH_RES_TIMERS /* For devices using high resolution timer we need to update the ktime period value */ g_ktTimerPeriod = ktime_set(0, g_nTimerPeriodMs * 1000000); #endif break; case VIBE_KP_CFG_FREQUENCY_PARAM1: case VIBE_KP_CFG_FREQUENCY_PARAM2: case VIBE_KP_CFG_FREQUENCY_PARAM3: case VIBE_KP_CFG_FREQUENCY_PARAM4: case VIBE_KP_CFG_FREQUENCY_PARAM5: case VIBE_KP_CFG_FREQUENCY_PARAM6: if (0 > ImmVibeSPI_ForceOut_SetFrequency(deviceParam.nDeviceIndex, deviceParam.nDeviceParamID, deviceParam.nDeviceParamValue)) { DbgOut((DBL_ERROR, "tspdrv: cannot set device frequency parameter.\n")); return -1; } break; } } } return 0; }
static long ioctl(struct file *file, unsigned int cmd, unsigned long arg) { /* DbgOut(KERN_INFO "tspdrv: ioctl cmd[0x%x].\n", cmd); */ switch (cmd) { case TSPDRV_SET_MAGIC_NUMBER: file->private_data = (void*)TSPDRV_MAGIC_NUMBER; break; case TSPDRV_ENABLE_AMP: wake_lock(&vib_wake_lock); ImmVibeSPI_ForceOut_AmpEnable(arg); DbgRecorderReset((arg)); DbgRecord((arg, ";------- TSPDRV_ENABLE_AMP ---------\n")); break; case TSPDRV_DISABLE_AMP: ImmVibeSPI_ForceOut_AmpDisable(arg); wake_unlock(&vib_wake_lock); break; case TSPDRV_GET_NUM_ACTUATORS: return NUM_ACTUATORS; case TSPDRV_SET_DBG_LEVEL: { long nDbgLevel; if (0 != copy_from_user((void *)&nDbgLevel, (const void __user *)arg, sizeof(long))) { /* Error copying the data */ DbgOut((KERN_ERR "copy_from_user failed to copy debug level data.\n")); return -1; } if (DBL_TEMP <= nDbgLevel && nDbgLevel <= DBL_OVERKILL) { atomic_set(&g_nDebugLevel, nDbgLevel); } else { DbgOut((KERN_DEBUG "Invalid debug level requested, ignored.")); } break; } case TSPDRV_GET_DBG_LEVEL: return atomic_read(&g_nDebugLevel); case TSPDRV_SET_DEVICE_PARAMETER: { device_parameter deviceParam; if (0 != copy_from_user((void *)&deviceParam, (const void __user *)arg, sizeof(deviceParam))) { /* Error copying the data */ DbgOut((KERN_ERR "tspdrv: copy_from_user failed to copy kernel parameter data.\n")); return -1; } switch (deviceParam.nDeviceParamID) { case VIBE_KP_CFG_UPDATE_RATE_MS: /* Update the timer period */ g_nTimerPeriodMs = deviceParam.nDeviceParamValue; #ifdef CONFIG_HIGH_RES_TIMERS /* For devices using high resolution timer we need to update the ktime period value */ g_ktTimerPeriod = ktime_set(0, g_nTimerPeriodMs * 950000/*1000000*/); #endif break; case VIBE_KP_CFG_FREQUENCY_PARAM1: case VIBE_KP_CFG_FREQUENCY_PARAM2: case VIBE_KP_CFG_FREQUENCY_PARAM3: case VIBE_KP_CFG_FREQUENCY_PARAM4: case VIBE_KP_CFG_FREQUENCY_PARAM5: case VIBE_KP_CFG_FREQUENCY_PARAM6: if (0 > ImmVibeSPI_ForceOut_SetFrequency(deviceParam.nDeviceIndex, deviceParam.nDeviceParamID, deviceParam.nDeviceParamValue)) { DbgOut((KERN_ERR "tspdrv: cannot set device frequency parameter.\n")); return -1; } break; } } } return 0; }