void report_key_event(struct ssp_data *data)
{
	input_event(data->key_input_dev, EV_KEY, KEY_HOMEPAGE, 1);
	input_sync(data->key_input_dev);
	ssp_charging_motion(data, 0);

	msleep(10);

	input_event(data->key_input_dev, EV_KEY, KEY_HOMEPAGE, 0);
	input_sync(data->key_input_dev);
	ssp_charging_motion(data, 1);

	wake_lock_timeout(&data->ssp_wake_lock, 3 * HZ);
}
static void lpm_motion_work_func(struct work_struct *work)
{
	struct ssp_data *data =
		container_of(work, struct ssp_data, work_lpm_motion);

	input_event(data->key_input_dev, EV_KEY, KEY_HOMEPAGE, 1);
	input_sync(data->key_input_dev);
	ssp_charging_motion(data, 0);

	msleep(10);

	input_event(data->key_input_dev, EV_KEY, KEY_HOMEPAGE, 0);
	input_sync(data->key_input_dev);
	ssp_charging_motion(data, 1);

	wake_lock_timeout(&data->ssp_wake_lock, 3 * HZ);

}
Esempio n. 3
0
static int ssp_probe(struct spi_device *spi)
{
	int iRet = 0;
	struct ssp_data *data;

	pr_info("\n#####################################################\n");
	data = kzalloc(sizeof(*data), GFP_KERNEL);
	if (data == NULL) {
		pr_err("[SSP]: %s - failed to allocate memory for data\n",
			__func__);
		iRet = -ENOMEM;
		goto exit;
	}

	iRet = initialize_platformdata(data, spi->dev.platform_data);
	if (iRet < 0) {
		pr_err("[SSP]: %s - failed initialize pdata\n", __func__);
		iRet = -ENOMEM;
		goto err_init_pdata;
	}

	mutex_init(&data->comm_mutex);
	mutex_init(&data->wakeup_mutex);
	mutex_init(&data->reset_mutex);
	mutex_init(&data->enable_mutex);

	spi->mode = SPI_MODE_1;
	if (spi_setup(spi)) {
		pr_err("failed to setup spi for ssp_spi\n");
		goto err_setup;
	}
	data->spi = spi;
	spi_set_drvdata(spi, data);
	initialize_variable(data);

	INIT_DELAYED_WORK(&data->work_firmware, work_function_firmware_update);

	/* check boot loader binary */
	data->fw_dl_state = check_fwbl(data);
	if (data->fw_dl_state == FW_DL_STATE_NONE) {
		iRet = startup_mcu(data);
		if (iRet == ERROR) {
			data->uResetCnt++;
			toggle_mcu_reset(data);
			msleep(SSP_SW_RESET_TIME);
			iRet = startup_mcu(data);
		}

		if (iRet != SUCCESS) {
			pr_err("[SSP]: %s - startup_mcu failed\n", __func__);
			goto err_read_reg;
		}
	}

	wake_lock_init(&data->ssp_wake_lock,
		WAKE_LOCK_SUSPEND, "ssp_wake_lock");

	iRet = initialize_debug_timer(data);
	if (iRet < 0) {
		pr_err("[SSP]: %s - could not create workqueue\n", __func__);
		goto err_create_workqueue;
	}

	iRet = initialize_irq(data);
	if (iRet < 0) {
		pr_err("[SSP]: %s - could not create irq\n", __func__);
		goto err_setup_irq;
	}

	iRet = initialize_sensors(data);
	if (iRet < 0) {
		pr_err("[SSP]: %s - could not initialize sensor\n", __func__);
		goto err_init_sensor;
	}

	/* init sensorhub device */
	iRet = ssp_sensorhub_initialize(data);
	if (iRet < 0) {
		pr_err("%s: ssp_sensorhub_initialize err(%d)", __func__, iRet);
		ssp_sensorhub_remove(data);
	}

	ssp_enable(data, true);
	data->bProbeIsDone = true;
	pr_info("[SSP]: %s - probe success!\n", __func__);

	enable_debug_timer(data);

	if (data->fw_dl_state == FW_DL_STATE_NEED_TO_SCHEDULE) {
		pr_info("[SSP]: Firmware update is scheduled\n");
		schedule_delayed_work(&data->work_firmware,
				msecs_to_jiffies(1000));
		data->fw_dl_state = FW_DL_STATE_SCHEDULED;
	} else if (data->fw_dl_state == FW_DL_STATE_FAIL) {
		data->bSspShutdown = true;
	}

	iRet = 0;

	if (data->check_lpmode() == true) {
		ssp_charging_motion(data, 1);
		data->bLpModeEnabled = true;
		pr_info("[SSP]: LPM Charging...\n");
	} else {
		data->bLpModeEnabled = false;
		pr_info("[SSP]: Normal Booting OK\n");
	}

	goto exit;

err_init_sensor:
	free_irq(data->iIrq, data);
	gpio_free(data->spi->irq);
err_setup_irq:
	destroy_workqueue(data->debug_wq);
err_create_workqueue:
err_input_register_device:
	wake_lock_destroy(&data->ssp_wake_lock);
err_read_reg:
err_reset_null:
err_setup:
	mutex_destroy(&data->enable_mutex);
	mutex_destroy(&data->reset_mutex);
	mutex_destroy(&data->wakeup_mutex);
	mutex_destroy(&data->comm_mutex);
err_init_pdata:
	kfree(data);
	pr_err("[SSP]: %s - probe failed!\n", __func__);
exit:
	pr_info("#####################################################\n\n");
	return iRet;
}