tizen 2.3.1 release
[kernel/linux-3.0.git] / drivers / misc / modem_if / modem_sim_slot_switch.c
1 #include <linux/i2c.h>
2 #include <linux/gpio.h>
3 #include <linux/delay.h>
4 #include <linux/err.h>
5
6 #include <plat/gpio-cfg.h>
7
8 #include <mach/gpio.h>
9
10 extern struct class *sec_class;
11 struct device *slot_switch_dev;
12
13 static ssize_t get_slot_switch(struct device *dev, struct device_attribute *attr, char *buf)
14 {
15         int value;
16
17         //return '0' slot path is '||', return '1' slot path is 'X'
18         value = gpio_get_value(GPIO_UIM_SIM_SEL);
19 #if defined(CONFIG_MACH_T0_CHN_CTC)
20         if (system_rev < 7)
21                 value = (~value & 0x1);
22 #endif
23         printk("Current Slot is %x\n", value);
24
25         return sprintf(buf, "%d\n", value);
26 }
27
28 static ssize_t set_slot_switch(struct device *dev, struct device_attribute *attr,   const char *buf, size_t size)
29 {
30         int value;
31
32         sscanf(buf, "%d", &value);
33
34         switch(value) {
35                 case 0:
36 #if defined(CONFIG_MACH_T0_CHN_CTC)
37                         if (system_rev < 7)
38                                 gpio_set_value(GPIO_UIM_SIM_SEL, 1);
39                         else
40 #endif
41                         gpio_set_value(GPIO_UIM_SIM_SEL, 0);
42                         printk("set slot switch to %x\n", gpio_get_value(GPIO_UIM_SIM_SEL));
43                         break;
44                 case 1:
45 #if defined(CONFIG_MACH_T0_CHN_CTC)
46                         if (system_rev < 7)
47                                 gpio_set_value(GPIO_UIM_SIM_SEL, 0);
48                         else
49 #endif
50                         gpio_set_value(GPIO_UIM_SIM_SEL, 1);
51                         printk("set slot switch to %x\n", gpio_get_value(GPIO_UIM_SIM_SEL));
52                         break;
53                 default:
54                         printk("Enter 0 or 1!!\n");
55         }
56
57         return size;
58 }
59
60 static DEVICE_ATTR(slot_sel, S_IRUGO | S_IWUSR | S_IWGRP,
61         get_slot_switch, set_slot_switch);
62
63 static int __init slot_switch_manager_init(void)
64 {
65         int ret = 0;
66         int err = 0;
67
68         printk("slot_switch_manager_init\n");
69
70     //initailize uim_sim_switch gpio
71         err = gpio_request(GPIO_UIM_SIM_SEL, "PDA_ACTIVE");
72         if (err) {
73                 pr_err("fail to request gpio %s, gpio %d, errno %d\n",
74                                         "PDA_ACTIVE", GPIO_UIM_SIM_SEL, err);
75         } else {
76                 gpio_direction_output(GPIO_UIM_SIM_SEL, 1);
77                 s3c_gpio_setpull(GPIO_UIM_SIM_SEL, S3C_GPIO_PULL_NONE);
78 #if defined(CONFIG_MACH_T0_CHN_CTC)
79         if (system_rev < 7)
80                 gpio_set_value(GPIO_UIM_SIM_SEL, 1);
81         else
82 #endif
83                 gpio_set_value(GPIO_UIM_SIM_SEL, 0);
84         }
85
86         //initailize slot switch device
87         slot_switch_dev = device_create(sec_class,
88                                     NULL, 0, NULL, "slot_switch");
89         if (IS_ERR(slot_switch_dev))
90                 pr_err("Failed to create device(switch)!\n");
91
92         if (device_create_file(slot_switch_dev, &dev_attr_slot_sel) < 0)
93                 pr_err("Failed to create device file(%s)!\n",
94                                         dev_attr_slot_sel.attr.name);
95
96         return ret;
97 }
98
99 static void __exit slot_switch_manager_exit(void)
100 {
101 }
102
103 module_init(slot_switch_manager_init);
104 module_exit(slot_switch_manager_exit);
105
106 MODULE_AUTHOR("SAMSUNG ELECTRONICS CO., LTD");
107 MODULE_DESCRIPTION("Slot Switch");
108 MODULE_LICENSE("GPL");