コード例 #1
0
static int set_vibetonz(int timeout)
{
	struct regulator *regulator;

	if (!timeout) {
		vibe_control_max8997(Immvib_pwm, 0);

		if (regulator_hapticmotor_enabled == 1) {
			regulator = regulator_get(NULL, "vmotor");

			if (IS_ERR(regulator)) {
				DbgOut((KERN_ERR "Failed to get vmoter regulator.\n"));
				return 0;
			}

			regulator_force_disable(regulator);
			regulator_put(regulator);

			regulator_hapticmotor_enabled = 0;

			DbgOut((KERN_INFO "tspdrv: DISABLE\n"));
			wake_unlock(&vib_wake_lock);
		}
	} else {
		wake_lock(&vib_wake_lock);
#if defined(CONFIG_BUILD_TARGET_CM7)
    _pwm_config(Immvib_pwm, vibrator_duty_levels[vibrator_level], VIBRATOR_PERIOD);
#else
		_pwm_config(Immvib_pwm, VIBRATOR_DUTY, VIBRATOR_PERIOD);
#endif
		vibe_control_max8997(Immvib_pwm, 1);

		regulator = regulator_get(NULL, "vmotor");

		if (IS_ERR(regulator)) {
			DbgOut((KERN_ERR "Failed to get vmoter regulator.\n"));
			return 0;
		}

		regulator_enable(regulator);
		regulator_put(regulator);

		regulator_hapticmotor_enabled = 1;

		DbgOut((KERN_INFO "tspdrv: ENABLE\n"));
	}

	vibrator_value = timeout;

	printk(KERN_DEBUG "tspdrv: %s (%d)\n", __func__, regulator_hapticmotor_enabled);

	return 0;
}
コード例 #2
0
static int set_vibetonz(int timeout)
{
#ifndef CONFIG_MACH_Q1_REV02
    struct regulator *regulator;
#endif

    if (!timeout) {
        vibe_control_max8997(Immvib_pwm, 0);

        if (regulator_hapticmotor_enabled == 1) {
#ifdef CONFIG_MACH_Q1_REV02
            gpio_direction_output(GPIO_MOTOR_EN, 0);
#else
            regulator = regulator_get(NULL, "vmotor");

            if (IS_ERR(regulator)) {
                DbgOut((KERN_ERR "Failed to get vmoter regulator.\n"));
                return 0;
            }

            regulator_force_disable(regulator);
            regulator_put(regulator);

            regulator_hapticmotor_enabled = 0;
#endif
            DbgOut((KERN_INFO "tspdrv: DISABLE\n"));
            wake_unlock(&vib_wake_lock);
        }
    } else {
        wake_lock(&vib_wake_lock);

        _pwm_config(Immvib_pwm, VIBRATOR_DUTY, VIBRATOR_PERIOD);
        vibe_control_max8997(Immvib_pwm, 1);
#ifdef CONFIG_MACH_Q1_REV02
        gpio_direction_output(GPIO_MOTOR_EN, 1);
#else
        regulator = regulator_get(NULL, "vmotor");

        if (IS_ERR(regulator)) {
            DbgOut((KERN_ERR "Failed to get vmoter regulator.\n"));
            return 0;
        }

        regulator_enable(regulator);
        regulator_put(regulator);
#endif
        regulator_hapticmotor_enabled = 1;

        DbgOut((KERN_INFO "tspdrv: ENABLE\n"));
    }

    vibrator_value = timeout;

    printk(KERN_DEBUG "tspdrv: %s (%d)\n", __func__, regulator_hapticmotor_enabled);

    return 0;
}
コード例 #3
0
/*
** Called to disable amp (disable output force)
*/
IMMVIBESPIAPI VibeStatus ImmVibeSPI_ForceOut_AmpDisable(VibeUInt8 nActuatorIndex)
{
#if 0
	if (g_bAmpEnabled) {
		DbgOut((KERN_DEBUG "ImmVibeSPI_ForceOut_AmpDisable.\n"));

		g_bAmpEnabled = false;

		/* Disable amp */


		/* Disable PWM CLK */

	}
#endif

	if (g_bAmpEnabled) {
		struct regulator *regulator;

		g_bAmpEnabled = false;
		_pwm_config(Immvib_pwm, freq_count/2, freq_count);

		if (regulator_hapticmotor_enabled == 1) {
			regulator = regulator_get(NULL, "vmotor");

			if (IS_ERR(regulator)) {
				DbgOut((KERN_ERR"Failed to get vmoter regulator.\n"));
				return 0;
			}

			regulator_disable(regulator);
			regulator_put(regulator);

			regulator_hapticmotor_enabled = 0;
		}

		vibe_control_max8997(Immvib_pwm, 0);
	}

	return VIBE_S_SUCCESS;
}
コード例 #4
0
/*
** Called at initialization time to set PWM freq, disable amp, etc...
*/
IMMVIBESPIAPI VibeStatus ImmVibeSPI_ForceOut_Initialize(void)
{
	DbgOut((KERN_DEBUG "ImmVibeSPI_ForceOut_Initialize.\n"));

	g_bAmpEnabled = true;   /* to force ImmVibeSPI_ForceOut_AmpDisable disabling the amp */

	/*
	** Disable amp.
	** If multiple actuators are supported, please make sure to call
	** ImmVibeSPI_ForceOut_AmpDisable for each actuator (provide the actuator index as
	** input argument).
	*/

	Immvib_pwm = pwm_request(PWM_DEVICE, "Immvibtonz");
	_pwm_config(Immvib_pwm, freq_count/2, freq_count);

	ImmVibeSPI_ForceOut_AmpDisable(0);

	regulator_hapticmotor_enabled = 0;

	return VIBE_S_SUCCESS;
}
コード例 #5
0
/*
** Called to enable amp (enable output force)
*/
IMMVIBESPIAPI VibeStatus ImmVibeSPI_ForceOut_AmpEnable(VibeUInt8 nActuatorIndex)
{
#if 0
	if (!g_bAmpEnabled)	{
		DbgOut((KERN_DEBUG "ImmVibeSPI_ForceOut_AmpEnable.\n"));

		g_bAmpEnabled = true;

		/* Generate PWM CLK with proper frequency(ex. 22400Hz) and 50% duty cycle.*/


		/* Enable amp */

	}
#endif

	if (!g_bAmpEnabled) {
		struct regulator *regulator;

		g_bAmpEnabled = true;

		_pwm_config(Immvib_pwm, freq_count/2, freq_count);
		vibe_control_max8997(Immvib_pwm, 1);

		regulator = regulator_get(NULL, "vmotor");

		if (IS_ERR(regulator)) {
			DbgOut((KERN_ERR"Failed to get vmoter regulator.\n"));
			return 0;
		}

		regulator_enable(regulator);
		regulator_put(regulator);

		regulator_hapticmotor_enabled = 1;
	}

	return VIBE_S_SUCCESS;
}
コード例 #6
0
/*
** Called by the real-time loop to set PWM duty cycle
*/
IMMVIBESPIAPI VibeStatus ImmVibeSPI_ForceOut_SetSamples(VibeUInt8 nActuatorIndex,
							VibeUInt16 nOutputSignalBitDepth,
							VibeUInt16 nBufferSizeInBytes,
							VibeInt8 * pForceOutputBuffer)
{
#if 0
	VibeInt8 nForce;

	switch (nOutputSignalBitDepth) {
	case 8:
		/* pForceOutputBuffer is expected to contain 1 byte */
		if (nBufferSizeInBytes != 1) {
			DbgOut((KERN_ERR "[ImmVibeSPI] ImmVibeSPI_ForceOut_SetSamples nBufferSizeInBytes =  %d\n", nBufferSizeInBytes));
			return VIBE_E_FAIL;
		}
		nForce = pForceOutputBuffer[0];
		break;
	case 16:
		/* pForceOutputBuffer is expected to contain 2 byte */
		if (nBufferSizeInBytes != 2)
			return VIBE_E_FAIL;

		/* Map 16-bit value to 8-bit */
		nForce = ((VibeInt16 *)pForceOutputBuffer)[0] >> 8;
		break;
	default:
		/* Unexpected bit depth */
		return VIBE_E_FAIL;
	}

	if (nForce == 0)
		/* Set 50% duty cycle or disable amp */
	else
		/* Map force from [-127, 127] to [0, PWM_DUTY_MAX] */


#endif

	VibeInt8 nForce;
	int pwm_duty;

	switch (nOutputSignalBitDepth) {
	case 8:
		/* pForceOutputBuffer is expected to contain 1 byte */
		if (nBufferSizeInBytes != 1) {
			DbgOut((KERN_ERR "[ImmVibeSPI] ImmVibeSPI_ForceOut_SetSamples nBufferSizeInBytes =  %d\n", nBufferSizeInBytes));
			return VIBE_E_FAIL;
		}
		nForce = pForceOutputBuffer[0];
		break;
	case 16:
		/* pForceOutputBuffer is expected to contain 2 byte */
		if (nBufferSizeInBytes != 2)
			return VIBE_E_FAIL;

		/* Map 16-bit value to 8-bit */
		nForce = ((VibeInt16 *)pForceOutputBuffer)[0] >> 8;
		break;
	default:
		/* Unexpected bit depth */
		return VIBE_E_FAIL;
	}

	pwm_duty = freq_count/2 + ((freq_count/2 - 2) * nForce)/127;

	if (nForce == 0) {
		/* Set 50% duty cycle or disable amp */
		ImmVibeSPI_ForceOut_AmpDisable(0);
	} else {
		/* Map force from [-127, 127] to [0, PWM_DUTY_MAX] */
		ImmVibeSPI_ForceOut_AmpEnable(0);
		_pwm_config(Immvib_pwm, pwm_duty, freq_count);
	}

	return VIBE_S_SUCCESS;
}