static int simdet_switch_probe(struct platform_device *pdev)
{
	struct gpio_switch_platform_data *pdata = pdev->dev.platform_data;
	int ret = -EBUSY;

	if (!pdata)
		return -EBUSY;

	switch_data = kzalloc(sizeof(struct simdet_switch_data), GFP_KERNEL);
	if (!switch_data)
		return -ENOMEM;

	switch_data->gpio = pdata->gpio;
	switch_data->irq = gpio_to_irq(pdata->gpio);
	switch_data->sdev.print_state = switch_print_state;
	switch_data->sdev.name = DRIVER_NAME;
	switch_data->sdev.print_name = switch_print_name;
	ret = switch_dev_register(&switch_data->sdev);
	if (ret < 0) {
		printk("simdetect: switch_dev_register failed");
		goto err_register_switch;
	}

	// For ThreeG wakeup pin
	if (threegwake_data == NULL) {
		threegwake_data = kzalloc(sizeof(struct threegwake_data), GFP_KERNEL);
		if (!threegwake_data)
			return -ENOMEM;
	}

	threegwake_data->gpio = TEGRA_GPIO_PC7;
	threegwake_data->irq = gpio_to_irq(TEGRA_GPIO_PC7);

	printk("simdetect: 3G_WAKE irq is %d\n", threegwake_data->irq);
	if (threegwake_data->irq < 0) {
		ret = threegwake_data->irq;
		goto err_detect_irq_num_failed;
	}

	tegra_gpio_enable(switch_data->gpio);
	tegra_gpio_enable(threegwake_data->gpio);

	ret = gpio_request(switch_data->gpio, pdev->name);
	if (ret < 0) {
		printk("simdetect: gpio_request failed");
		goto err_request_gpio;
	}

	ret = gpio_request(threegwake_data->gpio, "3G_WAKE");
	if (ret < 0) {
		printk("simdetect: TRGRA_GPIO_PC7 gpio_request failed");
		goto err_request_gpio;
	}

	ret = gpio_direction_input(switch_data->gpio);
	if (ret < 0) {
		printk("simdetect: gpio_direction_input");
		goto err_set_gpio_input;
	}

	ret = gpio_direction_input(threegwake_data->gpio);
	if (ret < 0) {
		printk("simdetect: TEGRA_GPIO_PC7 gpio_direction_input failed");
		goto err_set_gpio_input;
	}

	INIT_WORK(&switch_data->work, simdet_switch_work);

	INIT_WORK(&threegwake_data->work, threeG_wakeup_work);

	switch_data->irq = gpio_to_irq(switch_data->gpio);
	printk("simdetect: irq is %d\n", switch_data->irq);
	if (switch_data->irq < 0) {
		ret = switch_data->irq;
		goto err_detect_irq_num_failed;
	}

#if defined(CONFIG_ARCH_ACER_T30)
	irq_set_irq_type(switch_data->irq, IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING);

	irq_set_irq_type(threegwake_data->irq, IRQF_TRIGGER_LOW);
#endif

	ret = request_irq(switch_data->irq, simdet_interrupt, IRQF_DISABLED | IRQF_TRIGGER_FALLING | IRQF_TRIGGER_RISING,
			"simdetect", switch_data);
	if(ret)
	{
		printk("simdetect: simdet_switch request irq failed\n");
		goto err_request_irq;
	}

	ret = request_irq(threegwake_data->irq, ThreeGwake_interrupt, IRQF_DISABLED | IRQF_TRIGGER_LOW,
			"3G_WAKE", threegwake_data);
	if (ret) {
		printk("simdetect: ThreeGwake request irq failed\n");
		goto err_request_irq;
	}

	// set current status
	simdet_switch_work(&switch_data->work);

	threeG_wakeup_work(&threegwake_data->work);

	// hrtimer
	switch_data->debounce_time = ktime_set(0, SIMDET_DEBOUNCE_TIME_MS*1000000);
	hrtimer_init(&switch_data->timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
	switch_data->timer.function = detect_event_timer_func;

	threegwake_data->debounce_time = ktime_set(0, THREEGWAKE_DEBOUNCE_TIME_MS*1000000);
	hrtimer_init(&threegwake_data->timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
	threegwake_data->timer.function = wake_event_timer_func;

#ifdef CONFIG_HAS_EARLYSUSPEND
	switch_data_priv = switch_data;

	simdet_early_suspend.level = EARLY_SUSPEND_LEVEL_BLANK_SCREEN + 1;
	simdet_early_suspend.suspend = func_simdet_early_suspend;
	simdet_early_suspend.resume = func_simdet_late_resume;
	register_early_suspend(&simdet_early_suspend);
#endif

	return 0;

err_request_irq:
err_detect_irq_num_failed:
err_set_gpio_input:
	free_irq(switch_data->irq, switch_data);
err_request_gpio:
	switch_dev_unregister(&switch_data->sdev);
err_register_switch:
	kfree(switch_data);
	return ret;
}
Beispiel #2
0
static int simdet_switch_probe(struct platform_device *pdev)
{
    struct gpio_switch_platform_data *pdata = pdev->dev.platform_data;
    struct simdet_switch_data *switch_data;
    int ret = -EBUSY;

    if (!pdata)
        return -EBUSY;

    switch_data = kzalloc(sizeof(struct simdet_switch_data), GFP_KERNEL);
    if (!switch_data)
        return -ENOMEM;

    switch_data->gpio = pdata->gpio;
    switch_data->irq = gpio_to_irq(pdata->gpio);
    switch_data->sdev.print_state = switch_print_state;
    switch_data->sdev.name = DRIVER_NAME;
    switch_data->sdev.print_name = switch_print_name;
    ret = switch_dev_register(&switch_data->sdev);
    if (ret < 0)
        goto err_register_switch;

    ret = gpio_request(switch_data->gpio, pdev->name);
    if (ret < 0)
        goto err_request_gpio;

    ret = gpio_direction_input(switch_data->gpio);
    if (ret < 0)
        goto err_set_gpio_input;

    INIT_WORK(&switch_data->work, simdet_switch_work);

    switch_data->irq = gpio_to_irq(switch_data->gpio);
    if (switch_data->irq < 0) {
        ret = switch_data->irq;
	goto err_detect_irq_num_failed;
    }

    ret = request_irq(switch_data->irq, simdet_interrupt, IRQF_DISABLED | IRQF_TRIGGER_FALLING | IRQF_TRIGGER_RISING,
                 "simdetect", switch_data);
    if(ret)
    {
	printk("simdet_switch request irq failed\n");
        goto err_request_irq;
    }

    // set current status
    simdet_switch_work(&switch_data->work);

    // hrtimer
    switch_data->debounce_time = ktime_set(0, SIMDET_DEBOUNCE_TIME_MS*1000000);
    hrtimer_init(&switch_data->timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
    switch_data->timer.function = detect_event_timer_func;

#ifdef CONFIG_HAS_EARLYSUSPEND
    switch_data_priv = switch_data;

    simdet_early_suspend.level = EARLY_SUSPEND_LEVEL_BLANK_SCREEN + 1;
    simdet_early_suspend.suspend = func_simdet_early_suspend;
    simdet_early_suspend.resume = func_simdet_late_resume;
    register_early_suspend(&simdet_early_suspend);
#endif

    return 0;

err_request_irq:
err_detect_irq_num_failed:
err_set_gpio_input:
    free_irq(switch_data->irq, switch_data);
err_request_gpio:
    switch_dev_unregister(&switch_data->sdev);
err_register_switch:
    kfree(switch_data);
    return ret;
}