コード例 #1
0
static ssize_t write(struct file *file, const char *buf, size_t count,
					 loff_t *ppos)
{
	*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;
	}

	/*
	** Ignore packets that have size smaller than SPI_HEADER_SIZE or bigger than MAX_SPI_BUFFER_SIZE.
	** Please note that the daemon may send an empty buffer (count == SPI_HEADER_SIZE)
	** during quiet time between effects while playing a Timeline effect in order to maintain
	** correct timing: if "count" is equal to SPI_HEADER_SIZE, the call to VibeOSKernelLinuxStartTimer()
	** will just wait for the next timer tick.
	*/
	if ((count < SPI_HEADER_SIZE) || (count > MAX_SPI_BUFFER_SIZE))
	{
		DbgOut((KERN_ERR "tspdrv: invalid 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;
	}

	/* Extract force output samples and save them in an internal buffer */
	if (!SaveOutputData(g_cWriteBuffer, count))
	{
		DbgOut((KERN_ERR "tspdrv: SaveOutputData failed.\n"));
		return 0;
	}

	/* Start the timer after receiving new output force */
	g_bIsPlaying = true;

	VibeOSKernelLinuxStartTimer();

	return count;
}
コード例 #2
0
ファイル: tspdrv.c プロジェクト: hallometa/Gear_S_Kernel
static ssize_t write(struct file *file, const char *buf, size_t count, loff_t *ppos)
{
    *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((DBL_ERROR, "tspdrv: unauthorized write.\n"));
        return 0;
    }

    if(!is_ioctl_enable)
		pr_info("drv2604L : [%d-%d]writing after disable ioctl -0x%x,immvibespi:%d\n",
		raw_smp_processor_id(),current->pid,count==4?g_cWriteBuffer[3]:0xff,g_bAmpEnabled);
    /*
    ** Ignore packets that have size smaller than SPI_HEADER_SIZE or bigger than MAX_SPI_BUFFER_SIZE.
    ** Please note that the daemon may send an empty buffer (count == SPI_HEADER_SIZE)
    ** during quiet time between effects while playing a Timeline effect in order to maintain
    ** correct timing: if "count" is equal to SPI_HEADER_SIZE, the call to VibeOSKernelLinuxStartTimer()
    ** will just wait for the next timer tick.
    */
    if ((count < SPI_HEADER_SIZE) || (count > MAX_SPI_BUFFER_SIZE))
    {
        DbgOut((DBL_ERROR, "tspdrv: invalid 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((DBL_ERROR, "tspdrv: copy_from_user failed.\n"));
        return 0;
    }

#ifdef CONFIG_TSPDRV_HISTORY
	if (count == 4) {
#ifdef CONFIG_TSPDRV_HISTORY_DETAIL
		tspdrv_history[tspdrv_idx % TSPDRV_HISORY_MAX].write_value[tspdrv_write_idx % TSPDRV_WRITE_MAX] = g_cWriteBuffer[3];
#endif
		if(g_cWriteBuffer[3] == 0)
			tspdrv_zero_idx++;
	} else if (count == 3) {
#ifdef CONFIG_TSPDRV_HISTORY_DETAIL
		tspdrv_history[tspdrv_idx % TSPDRV_HISORY_MAX].write_value[tspdrv_write_idx % TSPDRV_WRITE_MAX] = 0xff;
#endif
		tspdrv_byte3_idx++;
	}
	tspdrv_write_idx++;
#endif

    /* Extract force output samples and save them in an internal buffer */
    if (!SaveOutputData(g_cWriteBuffer, count))
    {
        DbgOut((DBL_ERROR, "tspdrv: SaveOutputData failed.\n"));
        return 0;
    }

    /* Start the timer after receiving new output force */
    g_bIsPlaying = true;

    VibeOSKernelLinuxStartTimer();

    return count;
}