/
sec_misc.c
executable file
·376 lines (304 loc) · 10.1 KB
/
sec_misc.c
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
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
/*
* driver/misc/sec_misc.c
*
* driver supporting miscellaneous functions for Samsung P3 device
*
* COPYRIGHT(C) Samsung Electronics Co., Ltd. 2006-2010 All Right Reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* 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.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include <linux/module.h>
#include <linux/device.h>
#include <linux/miscdevice.h>
#include <linux/vmalloc.h>
#include <linux/fs.h>
#include <linux/mm.h>
#include <linux/slab.h>
#include <linux/firmware.h>
#include <linux/wakelock.h>
#include <linux/blkdev.h>
#include <linux/kernel_sec_common.h>
#include <mach/gpio-sec.h>
#include <mach/gpio.h>
#include "sec_misc.h"
static struct wake_lock sec_misc_wake_lock;
static struct file_operations sec_misc_fops =
{
.owner = THIS_MODULE,
//.read = sec_misc_read,
//.ioctl = sec_misc_ioctl,
//.open = sec_misc_open,
//.release = sec_misc_release,
};
static struct miscdevice sec_misc_device = {
.minor = MISC_DYNAMIC_MINOR,
.name = "sec_misc",
.fops = &sec_misc_fops,
};
usb_path_type usb_sel_status = USB_SEL_AP_USB;
unsigned char emmc_checksum_done;
unsigned char emmc_checksum_pass;
void p3_set_usb_path(usb_path_type usb_path);
void p3_usb_path_init(void){
int usbsel1, usbsel2;
gpio_request(GPIO_USB_SEL1, "GPIO_USB_SEL1");
gpio_direction_output(GPIO_USB_SEL1, 0);
tegra_gpio_enable(GPIO_USB_SEL1);
gpio_request(GPIO_USB_SEL2, "GPIO_USB_SEL2");
gpio_direction_input(GPIO_USB_SEL2);
usbsel2 = gpio_get_value(GPIO_USB_SEL2);
gpio_direction_output(GPIO_USB_SEL2, 0);
tegra_gpio_enable(GPIO_USB_SEL2);
if (usbsel2 == 1) {
p3_set_usb_path(USB_SEL_AP_USB);
} else if (usbsel2 == 0) {
p3_set_usb_path(USB_SEL_CP_USB);
}
}
void p3_set_usb_path(usb_path_type usb_path)
{
if(usb_path == USB_SEL_AP_USB){
gpio_set_value(GPIO_USB_SEL1, 1);
gpio_set_value(GPIO_USB_SEL2, 1);
usb_sel_status = USB_SEL_AP_USB;
}
else if(usb_path == USB_SEL_CP_USB){
gpio_set_value(GPIO_USB_SEL1, 0);
gpio_set_value(GPIO_USB_SEL2, 0);
usb_sel_status = USB_SEL_CP_USB;
}
else if(usb_path == USB_SEL_ADC){
gpio_set_value(GPIO_USB_SEL1, 0);
gpio_set_value(GPIO_USB_SEL2, 1);
usb_sel_status = USB_SEL_ADC;
}
}
void p3_uart_path_init(void){
int uartsel;
gpio_request(GPIO_UART_SEL, "GPIO_UART_SEL");
gpio_direction_input(GPIO_UART_SEL);
uartsel = gpio_get_value(GPIO_UART_SEL);
gpio_direction_output(GPIO_UART_SEL, uartsel);
gpio_set_value(GPIO_UART_SEL, uartsel);
/*
#if defined(CONFIG_SAMSUNG_KEEP_CONSOLE)
gpio_set_value(GPIO_UART_SEL, 1); // Set UART path to AP
#else
#if defined(CONFIG_MACH_SAMSUNG_P5WIFI)
if(system_rev > 6)
gpio_set_value(GPIO_UART_SEL, 0); // Set UART path to CP
else
gpio_set_value(GPIO_UART_SEL, 1); // Set UART path to AP for temp support testmode
#else
gpio_set_value(GPIO_UART_SEL, 0); // Set UART path to CP
#endif
#endif
*/
tegra_gpio_enable(GPIO_UART_SEL);
}
static ssize_t uart_sel_show(struct device *dev, struct device_attribute *attr, char *buf)
{
ssize_t ret;
int PinValue=5;
PinValue = gpio_get_value(GPIO_UART_SEL);
if(PinValue == 0)
ret = sprintf(buf, "UART path => CP\n");
else if(PinValue == 1)
ret = sprintf(buf, "UART path => AP\n");
else
ret = sprintf(buf, "uart_sel_show\n");
return ret;
}
#if defined(CONFIG_SEC_KEYBOARD_DOCK)
extern bool g_keyboard;
#endif
static ssize_t uart_sel_store(struct device *dev, struct device_attribute *attr,const char *buf, size_t size)
{
int state;
if (sscanf(buf, "%i", &state) != 1 || (state < 0 || state > 1))
return -EINVAL;
#if defined(CONFIG_SEC_KEYBOARD_DOCK)
if (g_keyboard) {
pr_err("%s - the keyboard is connected.\n", __func__);
return size;
}
#endif
// prevents the system from entering suspend
wake_lock(&sec_misc_wake_lock);
if(state == 1)
{
printk("[denis]Set UART path to AP state : %d\n" ,state);
gpio_set_value(GPIO_UART_SEL, 1); // Set UART path to AP
klogi("Set UART path to AP\n");
sec_set_param(param_index_uartsel, &state);
}
else if(state == 0)
{
printk("[denis]Set UART path to CP state : %d\n",state);
gpio_set_value(GPIO_UART_SEL, 0); // Set UART path to CP
klogi("Set UART path to CP\n");
sec_set_param(param_index_uartsel, &state);
}
else
klogi("Enter 1(AP uart) or 0(CP uart)...\n");
wake_unlock(&sec_misc_wake_lock);
return size;
}
static DEVICE_ATTR(uartsel, S_IRUGO | S_IWUSR | S_IWGRP,
uart_sel_show, uart_sel_store);
static ssize_t usb_sel_show(struct device *dev, struct device_attribute *attr, char *buf)
{
ssize_t ret;
if(usb_sel_status == USB_SEL_ADC)
ret = sprintf(buf, "USB path => ADC\n");
else if(usb_sel_status == USB_SEL_AP_USB)
ret = sprintf(buf, "USB path => PDA\n");
else if (usb_sel_status==USB_SEL_CP_USB)
ret = sprintf(buf, "USB path => MODEM\n");
else
ret = sprintf(buf, "usb_sel_show\n");
return ret;
}
static ssize_t usb_sel_store(struct device *dev, struct device_attribute *attr,const char *buf, size_t size)
{
int state;
if (sscanf(buf, "%i", &state) != 1 || (state < 0 || state > 2))
return -EINVAL;
// prevents the system from entering suspend
wake_lock(&sec_misc_wake_lock);
if(state == 2) {
p3_set_usb_path(USB_SEL_ADC); // Set USB path to CP
klogi("Set USB path to ADC\n");
}
else if(state == 1) {
p3_set_usb_path(USB_SEL_AP_USB); // Set USB path to AP
klogi("Set USB path to AP\n");
}
else if(state == 0) {
p3_set_usb_path(USB_SEL_CP_USB); // Set USB path to CP
klogi("Set USB path to CP\n");
}
else
klogi("Enter 2(ADC usb) or 1(AP usb) or 0(CP usb)...\n");
if (state >= 0 && state <= 2)
sec_set_param(param_index_usbsel, &state);
wake_unlock(&sec_misc_wake_lock);
return size;
}
static DEVICE_ATTR(usbsel, S_IRUGO | S_IWUSR | S_IWGRP,
usb_sel_show, usb_sel_store);
int check_usb_status = CHARGER_BATTERY;
static ssize_t usb_state_show(struct device *dev, struct device_attribute *attr, char *buf)
{
return sprintf(buf, "%s\n", (check_usb_status == CHARGER_USB) ?
"USB_STATE_CONFIGURED" : "USB_STATE_NOTCONFIGURED");
}
static ssize_t usb_state_store(struct device *dev, struct device_attribute *attr,
const char *buf, size_t size)
{
return 0;
}
static DEVICE_ATTR(usb_state, S_IRUGO | S_IWUSR, usb_state_show, usb_state_store);
static ssize_t emmc_checksum_done_show(struct device *dev, struct device_attribute *attr, char *buf)
{
return sprintf(buf, "%d\n", emmc_checksum_done);
}
static ssize_t emmc_checksum_done_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t size)
{
int state;
if (sscanf(buf, "%i", &state) != 1 || (state < 0 || state > 1))
return -EINVAL;
emmc_checksum_done = (unsigned char)state;
return size;
}
/* /sys/class/sec/sec_misc/emmc_checksum_done
* This node should be created with 0644 to avoid CTS failure
*/
static DEVICE_ATTR(emmc_checksum_done, 0664, emmc_checksum_done_show, emmc_checksum_done_store);
static ssize_t emmc_checksum_pass_show(struct device *dev, struct device_attribute *attr, char *buf)
{
return sprintf(buf, "%d\n", emmc_checksum_pass);
}
static ssize_t emmc_checksum_pass_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t size)
{
int state;
if (sscanf(buf, "%i", &state) != 1 || (state < 0 || state > 1))
return -EINVAL;
emmc_checksum_pass = (unsigned char)state;
return size;
}
/* /sys/class/sec/sec_misc/emmc_checksum_pass
* This node should be created with 0644 to avoid CTS failure
*/
static DEVICE_ATTR(emmc_checksum_pass, 0664, emmc_checksum_pass_show, emmc_checksum_pass_store);
int check_jig_on(void)
{
u32 value = gpio_get_value(GPIO_IFCONSENSE);
return !value;
}
static void init_jig_on(void)
{
gpio_request(GPIO_IFCONSENSE, "GPIO_IFCONSENSE");
gpio_direction_input(GPIO_IFCONSENSE);
tegra_gpio_enable(GPIO_IFCONSENSE);
}
extern struct class *sec_class;
struct device *sec_misc_dev;
static int __init sec_misc_init(void)
{
int ret=0;
pr_info("%s\n", __func__);
ret = misc_register(&sec_misc_device);
if (ret<0) {
pr_err("misc_register failed!\n");
return ret;
}
sec_misc_dev = device_create(sec_class, NULL, 0, NULL, "sec_misc");
if (IS_ERR(sec_misc_dev)) {
pr_err("failed to create device!\n");
return -ENODEV;
}
if (device_create_file(sec_misc_dev, &dev_attr_uartsel) < 0)
pr_err("failed to create device file!(%s)!\n", dev_attr_uartsel.attr.name);
if (device_create_file(sec_misc_dev, &dev_attr_usbsel) < 0)
pr_err("failed to create device file!(%s)!\n", dev_attr_usbsel.attr.name);
if (device_create_file(sec_misc_dev, &dev_attr_usb_state) < 0)
pr_err("Failed to create device file(%s)!\n", dev_attr_usb_state.attr.name);
if (device_create_file(sec_misc_dev, &dev_attr_emmc_checksum_done) < 0)
pr_err("failed to create device file - %s\n", dev_attr_emmc_checksum_done.attr.name);
if (device_create_file(sec_misc_dev, &dev_attr_emmc_checksum_pass) < 0)
pr_err("failed to create device file - %s\n", dev_attr_emmc_checksum_pass.attr.name);
wake_lock_init(&sec_misc_wake_lock, WAKE_LOCK_SUSPEND, "sec_misc");
p3_uart_path_init();
p3_usb_path_init();
//p3_set_usb_path(USB_SEL_AP_USB);
init_jig_on();
return 0;
}
static void __exit sec_misc_exit(void)
{
wake_lock_destroy(&sec_misc_wake_lock);
device_remove_file(sec_misc_dev, &dev_attr_uartsel);
device_remove_file(sec_misc_dev, &dev_attr_usbsel);
device_remove_file(sec_misc_dev, &dev_attr_usb_state);
device_remove_file(sec_misc_dev, &dev_attr_emmc_checksum_done);
device_remove_file(sec_misc_dev, &dev_attr_emmc_checksum_pass);
}
module_init(sec_misc_init);
module_exit(sec_misc_exit);
/* Module information */
MODULE_AUTHOR("Samsung");
MODULE_DESCRIPTION("Samsung P3 misc. driver");
MODULE_LICENSE("GPL");