aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/misc/modem_if_u1/modem_sim_slot_switch.c
blob: 366d0fa41a0aca33d06f357579bc2fb86eb7dc52 (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
#include <linux/i2c.h>
#include <linux/gpio.h>
#include <linux/delay.h>
#include <linux/err.h>

#include <plat/gpio-cfg.h>

#include <mach/gpio.h>

extern struct class *sec_class;
struct device *slot_switch_dev;

static ssize_t get_slot_switch(struct device *dev, struct device_attribute *attr, char *buf)
{
	int value;

	//return '0' slot path is '||', return '1' slot path is 'X'
	value = gpio_get_value(GPIO_UIM_SIM_SEL);
#if defined(CONFIG_MACH_T0_CHN_CTC)
	if (system_rev <= 7)
		value = (~value & 0x1);
#endif
	printk("Current Slot is %x\n", value);

	return sprintf(buf, "%d\n", value);
}

static ssize_t set_slot_switch(struct device *dev, struct device_attribute *attr,   const char *buf, size_t size)
{
	int value;

	sscanf(buf, "%d", &value);

	switch(value) {
		case 0:
#if defined(CONFIG_MACH_T0_CHN_CTC)
			if (system_rev <= 7)
				gpio_set_value(GPIO_UIM_SIM_SEL, 1);
			else
#endif
			gpio_set_value(GPIO_UIM_SIM_SEL, 0);
			printk("set slot switch to %x\n", gpio_get_value(GPIO_UIM_SIM_SEL));
			break;
		case 1:
#if defined(CONFIG_MACH_T0_CHN_CTC)
			if (system_rev <= 7)
				gpio_set_value(GPIO_UIM_SIM_SEL, 0);
			else
#endif
			gpio_set_value(GPIO_UIM_SIM_SEL, 1);
			printk("set slot switch to %x\n", gpio_get_value(GPIO_UIM_SIM_SEL));
			break;
		default:
			printk("Enter 0 or 1!!\n");
	}

	return size;
}

static DEVICE_ATTR(slot_sel, S_IRUGO | S_IWUSR | S_IWGRP,
	get_slot_switch, set_slot_switch);

static int __init slot_switch_manager_init(void)
{
	int ret = 0;
	int err = 0;

	printk("slot_switch_manager_init\n");

    //initailize uim_sim_switch gpio
	err = gpio_request(GPIO_UIM_SIM_SEL, "PDA_ACTIVE");
	if (err) {
		pr_err("fail to request gpio %s, gpio %d, errno %d\n",
					"PDA_ACTIVE", GPIO_UIM_SIM_SEL, err);
	} else {
		gpio_direction_output(GPIO_UIM_SIM_SEL, 1);
		s3c_gpio_setpull(GPIO_UIM_SIM_SEL, S3C_GPIO_PULL_NONE);
#if defined(CONFIG_MACH_T0_CHN_CTC)
	if (system_rev <= 7)
		gpio_set_value(GPIO_UIM_SIM_SEL, 1);
	else
#endif
		gpio_set_value(GPIO_UIM_SIM_SEL, 0);
	}

	//initailize slot switch device
	slot_switch_dev = device_create(sec_class,
                                    NULL, 0, NULL, "slot_switch");
	if (IS_ERR(slot_switch_dev))
		pr_err("Failed to create device(switch)!\n");

	if (device_create_file(slot_switch_dev, &dev_attr_slot_sel) < 0)
		pr_err("Failed to create device file(%s)!\n",
					dev_attr_slot_sel.attr.name);

	return ret;
}

static void __exit slot_switch_manager_exit(void)
{
}

module_init(slot_switch_manager_init);
module_exit(slot_switch_manager_exit);

MODULE_AUTHOR("SAMSUNG ELECTRONICS CO., LTD");
MODULE_DESCRIPTION("Slot Switch");
MODULE_LICENSE("GPL");