static int set_vibetonz(int timeout) { int8_t strength; if (!timeout) { if (vibrator_drvdata.vib_model == HAPTIC_PWM) { strength = 0; ImmVibeSPI_ForceOut_SetSamples(0, 8, 1, &strength); } else { /* HAPTIC_MOTOR */ ImmVibeSPI_ForceOut_AmpDisable(0); } } else { DbgOut((KERN_INFO "tspdrv: ENABLE\n")); if (vibrator_drvdata.vib_model == HAPTIC_PWM) { strength = 126; /* 90% duty cycle */ ImmVibeSPI_ForceOut_SetSamples(0, 8, 1, &strength); } else { /* HAPTIC_MOTOR */ DbgOut((KERN_INFO "tspdrv: ampenable\n")); ImmVibeSPI_ForceOut_AmpEnable(0); } } vibrator_value = timeout; return 0; }
static int set_vibetonz(int timeout) { int8_t strength; if (!timeout) { if (vibrator_drvdata.vib_model == HAPTIC_PWM) { strength = 0; ImmVibeSPI_ForceOut_SetSamples(0, 8, 1, &strength); } else { /* HAPTIC_MOTOR */ ImmVibeSPI_ForceOut_AmpDisable(0); } } else { DbgOut((KERN_INFO "tspdrv: ENABLE\n")); if (vibrator_drvdata.vib_model == HAPTIC_PWM) { #if defined(CONFIG_MACH_JF_TMO) strength = 79; #else strength = 119; #endif /* 90% duty cycle */ ImmVibeSPI_ForceOut_SetSamples(0, 8, 1, &strength); } else { /* HAPTIC_MOTOR */ ImmVibeSPI_ForceOut_AmpEnable(0); } } vibrator_value = timeout; return 0; }
bool SendOutputData(void) { int i; bool ret = 0; for (i = 0; i < NUM_ACTUATORS; i++) { actuator_samples_buffer *pCurrentActuatorSample = &(g_SamplesBuffer[i]); if (pCurrentActuatorSample->nBufferSize) { /* DbgOut((DBL_ERROR, "SendOutputData: 2: Size, BitDepth: %d, Buffer: %d, dataBuffer[0]:%d\n", pCurrentActuatorSample->nBitDepth, pCurrentActuatorSample->nBufferSize, pCurrentActuatorSample->dataBuffer[0]));*/ /* Play the current buffer */ ImmVibeSPI_ForceOut_SetSamples( i, pCurrentActuatorSample->nBitDepth, pCurrentActuatorSample->nBufferSize, pCurrentActuatorSample->dataBuffer); ret = 1; /* The current buffer is emptied */ pCurrentActuatorSample->nBufferSize = 0; } } return ret; }
static int set_vibetonz(int timeout) { int8_t strength; if(!timeout) { strength = 0; ImmVibeSPI_ForceOut_SetSamples(0,8,1,&strength); } else { DbgOut((KERN_INFO "tspdrv: ENABLE\n")); strength = 126; ImmVibeSPI_ForceOut_SetSamples(0,8,1,&strength); } vibrator_value = timeout; return 0; }
static int set_vibetonz(int timeout) { int8_t strength; if (!timeout) { if (vibrator_drvdata.vib_model == HAPTIC_PWM) { strength = 0; ImmVibeSPI_ForceOut_SetSamples(0, 8, 1, &strength); } else { /* HAPTIC_MOTOR */ ImmVibeSPI_ForceOut_AmpDisable(0); } } else { DbgOut((KERN_DEBUG "tspdrv: ENABLE\n")); if (vibrator_drvdata.vib_model == HAPTIC_PWM) { strength = (int8_t) (MAX_STRENGTH * pwm_value / 100); ImmVibeSPI_ForceOut_SetSamples(0, 8, 1, &strength); } else { /* HAPTIC_MOTOR */ DbgOut((KERN_DEBUG "tspdrv: ampenable\n")); ImmVibeSPI_ForceOut_AmpEnable(0); } } vibrator_value = timeout; return 0; }
bool SendOutputData(void) { if (g_bOutputDataBufferEmpty) { #ifdef VIBE_RUNTIME_RECORD if (atomic_read(&g_bRuntimeRecord)) { DbgRecord((0,"0\n")); } #endif return 0; } ImmVibeSPI_ForceOut_SetSamples(0, 8, 1, &g_nOutputData); /* Reset the buffer */ g_nOutputData = 0; g_bOutputDataBufferEmpty = 1; return 1; }
static ssize_t write(struct file *file, const char *buf, size_t count, loff_t *ppos) { int i = 0; *ppos = 0; /* file position not used, always set to 0 */ /* ** Prevent unauthorized caller to write data. ** TouchSense service is the only valid caller. */ if (file->private_data != (void *)TSPDRV_MAGIC_NUMBER) { DbgOut((KERN_ERR "tspdrv: unauthorized write.\n")); return 0; } /* Check buffer size */ if ((count <= SPI_HEADER_SIZE) || (count > SPI_BUFFER_SIZE)) { DbgOut((KERN_ERR "tspdrv: invalid write buffer size.\n")); return 0; } /* Copy immediately the input buffer */ if (0 != copy_from_user(g_cWriteBuffer, buf, count)) { /* Failed to copy all the data, exit */ DbgOut((KERN_ERR "tspdrv: copy_from_user failed.\n")); return 0; } while (i < count) { int nIndexFreeBuffer; /* initialized below */ samples_buffer* pInputBuffer = (samples_buffer *) (&g_cWriteBuffer[i]); if ((i + SPI_HEADER_SIZE) >= count) { /* ** Index is about to go beyond the buffer size. ** (Should never happen). */ DbgOut((KERN_EMERG "tspdrv: invalid buffer index.\n")); } /* Check bit depth */ if (8 != pInputBuffer->nBitDepth) DbgOut((KERN_WARNING "tspdrv: invalid bit depth." "Use default value (8)\n")); /* The above code not valid if SPI header size is not 3 */ #if (SPI_HEADER_SIZE != 3) #error "SPI_HEADER_SIZE expected to be 3" #endif /* Check buffer size */ if ((i + SPI_HEADER_SIZE + pInputBuffer->nBufferSize) > count) { /* ** Index is about to go beyond the buffer size. ** (Should never happen). */ DbgOut((KERN_EMERG "tspdrv: invalid data size.\n")); } /* Check actuator index */ if (NUM_ACTUATORS <= pInputBuffer->nActuatorIndex) { DbgOut((KERN_ERR "tspdrv: invalid actuator index.\n")); i += (SPI_HEADER_SIZE + pInputBuffer->nBufferSize); continue; } if (0 == g_SamplesBuffer[pInputBuffer->nActuatorIndex]. actuatorSamples[0].nBufferSize) { nIndexFreeBuffer = 0; } else if (0 == g_SamplesBuffer[pInputBuffer->nActuatorIndex]. actuatorSamples[1].nBufferSize) { nIndexFreeBuffer = 1; } else { /* No room to store new samples */ DbgOut((KERN_ERR "tspdrv: no room to store new samples.\n")); return 0; } /* Store the data in the free buffer of the given actuator */ memcpy(&(g_SamplesBuffer[pInputBuffer->nActuatorIndex]. actuatorSamples[nIndexFreeBuffer]), &g_cWriteBuffer[i], (SPI_HEADER_SIZE + pInputBuffer->nBufferSize)); /* if the no buffer is playing, prepare to play * g_SamplesBuffer[pInputBuffer->nActuatorIndex]. * actuatorSamples[nIndexFreeBuffer] */ if (-1 == g_SamplesBuffer[pInputBuffer-> nActuatorIndex].nIndexPlayingBuffer) { g_SamplesBuffer[pInputBuffer->nActuatorIndex]. nIndexPlayingBuffer = nIndexFreeBuffer; g_SamplesBuffer[pInputBuffer->nActuatorIndex]. nIndexOutputValue = 0; } /* Call SPI */ ImmVibeSPI_ForceOut_SetSamples(pInputBuffer->nActuatorIndex, pInputBuffer->nBitDepth, pInputBuffer->nBufferSize, &(g_SamplesBuffer[pInputBuffer->nActuatorIndex].actuatorSamples[nIndexFreeBuffer].dataBuffer[0])); /* Increment buffer index */ i += (SPI_HEADER_SIZE + pInputBuffer->nBufferSize); } #ifdef QA_TEST g_nForceLog[g_nForceLogIndex++] = g_cSPIBuffer[0]; if (g_nForceLogIndex >= FORCE_LOG_BUFFER_SIZE) { for (i = 0; i < FORCE_LOG_BUFFER_SIZE; i++) { printk(KERN_DEBUG "<6>%d\t%d\n", g_nTime, g_nForceLog[i]); g_nTime += TIME_INCREMENT; } g_nForceLogIndex = 0; } #endif /* Start the timer after receiving new output force */ g_bIsPlaying = true; VibeOSKernelLinuxStartTimer(); return count; }
static int VibeOSKernelProcessData(void* data) { int i; int nActuatorNotPlaying = 0; for (i = 0; i < NUM_ACTUATORS; i++) { actuator_samples_buffer *pCurrentActuatorSample = &(g_SamplesBuffer[i]); if (-1 == pCurrentActuatorSample->nIndexPlayingBuffer) { nActuatorNotPlaying++; if ((NUM_ACTUATORS == nActuatorNotPlaying) && ((++g_nWatchdogCounter) > WATCHDOG_TIMEOUT)) { VibeInt8 cZero[1] = {0}; /* Nothing to play for all actuators, turn off the timer when we reach the watchdog tick count limit */ ImmVibeSPI_ForceOut_SetSamples(i, 8, 1, cZero); ImmVibeSPI_ForceOut_AmpDisable(i); VibeOSKernelLinuxStopTimer(); /* Reset watchdog counter */ g_nWatchdogCounter = 0; } } else { /* Play the current buffer */ if (VIBE_E_FAIL == ImmVibeSPI_ForceOut_SetSamples( pCurrentActuatorSample->actuatorSamples[(int)pCurrentActuatorSample->nIndexPlayingBuffer].nActuatorIndex, pCurrentActuatorSample->actuatorSamples[(int)pCurrentActuatorSample->nIndexPlayingBuffer].nBitDepth, pCurrentActuatorSample->actuatorSamples[(int)pCurrentActuatorSample->nIndexPlayingBuffer].nBufferSize, pCurrentActuatorSample->actuatorSamples[(int)pCurrentActuatorSample->nIndexPlayingBuffer].dataBuffer)) { /* VIBE_E_FAIL means NAK has been handled. Schedule timer to restart 5 ms from now */ mod_timer(&g_timerList, jiffies + TIMER_INCR); } pCurrentActuatorSample->nIndexOutputValue += pCurrentActuatorSample->actuatorSamples[(int)pCurrentActuatorSample->nIndexPlayingBuffer].nBufferSize; if (pCurrentActuatorSample->nIndexOutputValue >= pCurrentActuatorSample->actuatorSamples[(int)pCurrentActuatorSample->nIndexPlayingBuffer].nBufferSize) { /* Reach the end of the current buffer */ pCurrentActuatorSample->actuatorSamples[(int)pCurrentActuatorSample->nIndexPlayingBuffer].nBufferSize = 0; /* Switch buffer */ (pCurrentActuatorSample->nIndexPlayingBuffer) ^= 1; pCurrentActuatorSample->nIndexOutputValue = 0; /* Finished playing, disable amp for actuator (i) */ if (g_bStopRequested) { pCurrentActuatorSample->nIndexPlayingBuffer = -1; ImmVibeSPI_ForceOut_AmpDisable(i); } } } } /* If finished playing, stop timer */ if (g_bStopRequested) { VibeOSKernelLinuxStopTimer(); /* Reset watchdog counter */ g_nWatchdogCounter = 0; if (VibeSemIsLocked(&g_hMutex)) up(&g_hMutex); return 1; /* tell the caller this is the last iteration */ } return 0; }
static int VibeOSKernelProcessData(void *data) { int i; int nactuator_not_playing = 0; for (i = 0; i < NUM_ACTUATORS; i++) { actuator_samples_buffer *pcurrent_actuator_sample = &(g_samples_buffer[i]); if (-1 == pcurrent_actuator_sample->nindex_playing_buffer) { nactuator_not_playing++; if ((NUM_ACTUATORS == nactuator_not_playing) && ((++g_nwatchdog_counter) > WATCHDOG_TIMEOUT)) { int8_t czero[1] = {0}; /* ** Nothing to play for all actuators, ** turn off the timer ** when we reach the watchdog tick count limit */ ImmVibeSPI_ForceOut_SetSamples(i, 8, 1, czero); printk(KERN_INFO ": %s : 1.calls ImmVibeSPI_ForceOut_AmpDisable(i=%d)\n", __func__,i); ImmVibeSPI_ForceOut_AmpDisable(i); VibeOSKernelLinuxStopTimer(); /* Reset watchdog counter */ g_nwatchdog_counter = 0; } } else { /* Play the current buffer */ if (VIBE_E_FAIL == ImmVibeSPI_ForceOut_SetSamples( pcurrent_actuator_sample->actuator_samples [(int)pcurrent_actuator_sample->nindex_playing_buffer] .nactuator_index, pcurrent_actuator_sample->actuator_samples [(int)pcurrent_actuator_sample->nindex_playing_buffer] .nbit_depth, pcurrent_actuator_sample->actuator_samples [(int)pcurrent_actuator_sample->nindex_playing_buffer] .nbuffer_size, pcurrent_actuator_sample->actuator_samples [(int)pcurrent_actuator_sample->nindex_playing_buffer] .data_buffer)) { /* VIBE_E_FAIL means NAK has been handled. Schedule timer to restart 5 ms from now */ hrtimer_forward_now(&g_tsptimer, g_ktfivems); } pcurrent_actuator_sample->nindex_output_value += pcurrent_actuator_sample->actuator_samples [(int)pcurrent_actuator_sample->nindex_playing_buffer] .nbuffer_size; if (pcurrent_actuator_sample->nindex_output_value >= pcurrent_actuator_sample->actuator_samples [(int)pcurrent_actuator_sample ->nindex_playing_buffer] .nbuffer_size) { /* Reach the end of the current buffer */ pcurrent_actuator_sample->actuator_samples [(int)pcurrent_actuator_sample ->nindex_playing_buffer] .nbuffer_size = 0; /* Switch buffer */ (pcurrent_actuator_sample ->nindex_playing_buffer) ^= 1; pcurrent_actuator_sample ->nindex_output_value = 0; /* Finished playing, disable amp for actuator (i) */ if (g_bstoprequested) { pcurrent_actuator_sample ->nindex_playing_buffer = -1; printk(KERN_INFO ": %s : 2.calls ImmVibeSPI_ForceOut_AmpDisable(i=%d)\n", __func__,i); ImmVibeSPI_ForceOut_AmpDisable(i); } } } } /* If finished playing, stop timer */ if (g_bstoprequested) { VibeOSKernelLinuxStopTimer(); /* Reset watchdog counter */ g_nwatchdog_counter = 0; if (VibeSemIsLocked(&g_mutex)) up(&g_mutex); return 1; /* tell the caller this is the last iteration */ } return 0; }