aboutsummaryrefslogtreecommitdiffstats
path: root/arch/arm/mach-exynos/midas-wacom.c
blob: 725b8b3218c3ebd27c049b891021fb1634cbb535 (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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
/*
 * linux/arch/arm/mach-exynos/midas-wacom.c
 *
 * Copyright (c) 2011 Samsung Electronics Co., Ltd.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as
 * published by the Free Software Foundation.
 */

#include <linux/i2c.h>

#include <linux/err.h>
#include <linux/gpio.h>

#include <linux/wacom_i2c.h>

#include <linux/regulator/consumer.h>
#include <plat/gpio-cfg.h>

#ifdef CONFIG_CPU_FREQ_GOV_ONDEMAND_FLEXRATE
#include <linux/cpufreq.h>
#endif

static struct wacom_g5_callbacks *wacom_callbacks;

#ifdef CONFIG_MACH_KONA
#define GPIO_WACOM_LDO_EN	GPIO_PEN_LDO_EN
#define GPIO_WACOM_SENSE	GPIO_PEN_DETECT
#endif

static int wacom_early_suspend_hw(void)
{
#ifndef CONFIG_MACH_KONA
	gpio_set_value(GPIO_PEN_RESET_N, 0);
#endif

#if defined(CONFIG_MACH_T0_EUR_OPEN)
	if (system_rev >= 10)
		gpio_direction_output(GPIO_WACOM_LDO_EN, 0);
	else
		gpio_direction_output(GPIO_WACOM_LDO_EN, 1);
#else
	gpio_direction_output(GPIO_WACOM_LDO_EN, 0);
#endif
	/* Set GPIO_PEN_IRQ to pull-up to reduce leakage */
	s3c_gpio_setpull(GPIO_PEN_IRQ, S3C_GPIO_PULL_UP);

	return 0;
}

static int wacom_late_resume_hw(void)
{
	s3c_gpio_setpull(GPIO_PEN_IRQ, S3C_GPIO_PULL_NONE);
	gpio_direction_output(GPIO_WACOM_LDO_EN, 1);
	msleep(100);
#ifndef CONFIG_MACH_KONA
	gpio_set_value(GPIO_PEN_RESET_N, 1);
#endif

	return 0;
}

static int wacom_suspend_hw(void)
{
	return wacom_early_suspend_hw();
}

static int wacom_resume_hw(void)
{
	return wacom_late_resume_hw();
}

static int wacom_reset_hw(void)
{
	wacom_early_suspend_hw();
	msleep(200);
	wacom_late_resume_hw();

	return 0;
}

static void wacom_register_callbacks(struct wacom_g5_callbacks *cb)
{
	wacom_callbacks = cb;
};


static struct wacom_g5_platform_data wacom_platform_data = {
#if defined(CONFIG_MACH_KONA)
	.x_invert = 0,
	.y_invert = 0,
	.xy_switch = 0,
	.min_x = WACOM_POSX_OFFSET,
	.max_x = WACOM_POSY_MAX,
	.min_y = WACOM_POSY_OFFSET,
	.max_y = WACOM_POSX_MAX,
#else
	.x_invert = 1,
	.y_invert = 0,
	.xy_switch = 1,
	.min_x = 0,
	.max_x = WACOM_POSX_MAX,
	.min_y = 0,
	.max_y = WACOM_POSY_MAX,
#endif
	.min_pressure = 0,
	.max_pressure = WACOM_PRESSURE_MAX,
	.gpio_pendct = GPIO_PEN_PDCT,
#ifdef WACOM_STATE_CHECK
#if defined(CONFIG_TARGET_LOCALE_KOR)
#if defined(CONFIG_MACH_T0) && defined(CONFIG_TDMB_ANT_DET)
	.gpio_esd_check = GPIO_TDMB_ANT_DET_REV08,
#endif
#endif
#endif
	/*.init_platform_hw = midas_wacom_init,*/
	/*      .exit_platform_hw =,    */
	.suspend_platform_hw = wacom_suspend_hw,
	.resume_platform_hw = wacom_resume_hw,
	.early_suspend_platform_hw = wacom_early_suspend_hw,
	.late_resume_platform_hw = wacom_late_resume_hw,
	.reset_platform_hw = wacom_reset_hw,
	.register_cb = wacom_register_callbacks,
#ifdef WACOM_PEN_DETECT
	.gpio_pen_insert = GPIO_WACOM_SENSE,
#endif
};
/* I2C Setting */
#if defined(CONFIG_MACH_KONA)
/* I2C6 */
static struct i2c_board_info i2c_devs6[] __initdata = {
	{
		I2C_BOARD_INFO("wacom_g5sp_i2c", 0x56),
			.platform_data = &wacom_platform_data,
	},
};
#elif defined(CONFIG_MACH_T0)
#if defined(CONFIG_MACH_T0_EUR_OPEN) ||\
	(defined(CONFIG_TARGET_LOCALE_CHN) && !defined(CONFIG_MACH_T0_CHN_CTC))
/* I2C5 */
static struct i2c_board_info i2c_devs5[] __initdata = {
	{
		I2C_BOARD_INFO("wacom_g5sp_i2c", 0x56),
			.platform_data = &wacom_platform_data,
	},
};
#else
/* I2C2 */
static struct i2c_board_info i2c_devs2[] __initdata = {
	{
		I2C_BOARD_INFO("wacom_g5sp_i2c", 0x56),
		.platform_data = &wacom_platform_data,
	},
};
#endif
#endif

void __init midas_wacom_init(void)
{
	int gpio;
	int ret;

#ifndef CONFIG_MACH_KONA
	/*RESET*/
	gpio = GPIO_PEN_RESET_N;
	ret = gpio_request(gpio, "PEN_RESET");
	s3c_gpio_cfgpin(gpio, S3C_GPIO_OUTPUT);
	gpio_direction_output(gpio, 0);
#endif
	
#if defined(CONFIG_MACH_KONA)
	printk(KERN_INFO "[E-PEN] Use FWE\n");
	gpio = GPIO_PEN_FWE1;
	ret = gpio_request(gpio, "PEN_FWE1");
	if (ret) {
		printk(KERN_ERR "[E-PEN] failed to request PEN_FWE1.(%d)\n",
			ret);
		return ;
	}
	s3c_gpio_cfgpin(gpio, S3C_GPIO_SFN(0x1));
	s3c_gpio_setpull(gpio, S3C_GPIO_PULL_NONE);
#else
	/*SLP & FWE1*/
	if (system_rev < WACOM_FWE1_HWID) {
		printk(KERN_INFO "[E-PEN] Use SLP\n");
		gpio = GPIO_PEN_SLP;
		ret = gpio_request(gpio, "PEN_SLP");
		s3c_gpio_cfgpin(gpio, S3C_GPIO_SFN(0x1));
		s3c_gpio_setpull(gpio, S3C_GPIO_PULL_UP);
	} else {
		printk(KERN_INFO "[E-PEN] Use FWE\n");
		gpio = GPIO_PEN_FWE1;
		ret = gpio_request(gpio, "PEN_FWE1");
		s3c_gpio_cfgpin(gpio, S3C_GPIO_SFN(0x1));
		s3c_gpio_setpull(gpio, S3C_GPIO_PULL_NONE);
	}
#endif
	gpio_direction_output(gpio, 0);

	/*PDCT*/
	gpio = GPIO_PEN_PDCT;
	ret = gpio_request(gpio, "PEN_PDCT");
	s3c_gpio_cfgpin(gpio, S3C_GPIO_SFN(0xf));
	s3c_gpio_setpull(gpio, S3C_GPIO_PULL_UP);
	s5p_register_gpio_interrupt(gpio);
	gpio_direction_input(gpio);

	irq_set_irq_type(gpio_to_irq(gpio), IRQ_TYPE_EDGE_BOTH);

	/*IRQ*/
	gpio = GPIO_PEN_IRQ;
	ret = gpio_request(gpio, "PEN_IRQ");
	s3c_gpio_setpull(gpio, S3C_GPIO_PULL_NONE);
	s5p_register_gpio_interrupt(gpio);
	gpio_direction_input(gpio);

#if defined(CONFIG_MACH_KONA)
	i2c_devs6[0].irq = gpio_to_irq(gpio);
	irq_set_irq_type(i2c_devs6[0].irq, IRQ_TYPE_EDGE_RISING);
#elif defined(CONFIG_MACH_T0_EUR_OPEN) || \
	(defined(CONFIG_TARGET_LOCALE_CHN) && !defined(CONFIG_MACH_T0_CHN_CTC))
	i2c_devs5[0].irq = gpio_to_irq(gpio);
	irq_set_irq_type(i2c_devs5[0].irq, IRQ_TYPE_EDGE_RISING);
#else
	i2c_devs2[0].irq = gpio_to_irq(gpio);
	irq_set_irq_type(i2c_devs2[0].irq, IRQ_TYPE_EDGE_RISING);
#endif

	s3c_gpio_cfgpin(gpio, S3C_GPIO_SFN(0xf));

	/*LDO_EN*/
	gpio = GPIO_WACOM_LDO_EN;
	ret = gpio_request(gpio, "PEN_LDO_EN");
	s3c_gpio_cfgpin(gpio, S3C_GPIO_OUTPUT);
	gpio_direction_output(gpio, 0);

#if defined(CONFIG_MACH_KONA)
	i2c_register_board_info(6, i2c_devs6, ARRAY_SIZE(i2c_devs6));
#elif defined(CONFIG_MACH_T0_EUR_OPEN) ||\
	(defined(CONFIG_TARGET_LOCALE_CHN) && !defined(CONFIG_MACH_T0_CHN_CTC))
	i2c_register_board_info(5, i2c_devs5, ARRAY_SIZE(i2c_devs5));
#else
	i2c_register_board_info(2, i2c_devs2, ARRAY_SIZE(i2c_devs2));
#endif

	printk(KERN_INFO "[E-PEN] : wacom IC initialized.\n");
}