aboutsummaryrefslogtreecommitdiffstats
path: root/arch/arm/mach-s5pv210/herring-touchkey-led.c
blob: 91d86234fdae8809044d9535e26d51ebe6b92904 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/*
 * Copyright (C) 2010 Samsung Electronics Co. Ltd. All Rights Reserved.
 * Author: Rom Lemarchand <rlemarchand@sta.samsung.com>
 *
 * This software is licensed under the terms of the GNU General Public
 * License version 2, as published by the Free Software Foundation, and
 * may be copied, distributed, and modified under those terms.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 */

#include <linux/init.h>
#include <linux/gpio.h>
#include <linux/earlysuspend.h>
#include <linux/bln.h>
#include <asm/mach-types.h>

#include "herring.h"

static int led_gpios[] = { 2, 3, 6, 7 };

static void herring_touchkey_led_onoff(int onoff)
{
	int i;

	for (i = 0; i < ARRAY_SIZE(led_gpios); i++)
		gpio_direction_output(S5PV210_GPJ3(led_gpios[i]), !!onoff);
}

#ifdef CONFIG_GENERIC_BLN
static void herring_touchkey_bln_enable(void)
{
	herring_touchkey_led_onoff(1);
}

static void herring_touchkey_bln_disable(void)
{
	herring_touchkey_led_onoff(0);
}

static struct bln_implementation herring_touchkey_bln = {
	.enable = herring_touchkey_bln_enable,
	.disable = herring_touchkey_bln_disable,
};
#endif

static void herring_touchkey_led_early_suspend(struct early_suspend *h)
{
	herring_touchkey_led_onoff(0);
}

static void herring_touchkey_led_late_resume(struct early_suspend *h)
{
	herring_touchkey_led_onoff(1);
}

static struct early_suspend early_suspend = {
	.level = EARLY_SUSPEND_LEVEL_BLANK_SCREEN + 1,
	.suspend = herring_touchkey_led_early_suspend,
	.resume = herring_touchkey_led_late_resume,
};

static int __init herring_init_touchkey_led(void)
{
	int i;
	int ret = 0;
	u32 gpio;

	if (!machine_is_herring() || !herring_is_tft_dev())
		return 0;

	for (i = 0; i < ARRAY_SIZE(led_gpios); i++) {
		gpio = S5PV210_GPJ3(led_gpios[i]);
		ret = gpio_request(gpio, "touchkey led");
		if (ret) {
			pr_err("Failed to request touchkey led gpio %d\n", i);
			goto err_req;
		}
		s3c_gpio_setpull(gpio, S3C_GPIO_PULL_NONE);
		s3c_gpio_slp_cfgpin(gpio, S3C_GPIO_SLP_PREV);
		s3c_gpio_slp_setpull_updown(gpio, S3C_GPIO_PULL_NONE);
	}

	herring_touchkey_led_onoff(1);

	register_early_suspend(&early_suspend);

#ifdef CONFIG_GENERIC_BLN
	register_bln_implementation(&herring_touchkey_bln);
#endif

	return 0;

err_req:
	while (--i >= 0)
		gpio_free(S5PV210_GPJ3(led_gpios[i]));
	return ret;
}

device_initcall(herring_init_touchkey_led);