modem_sim_slot_switch.c 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. #include <linux/kernel.h>
  2. #include <linux/module.h>
  3. #include <linux/slab.h>
  4. #include <linux/i2c.h>
  5. #include <linux/gpio.h>
  6. #include <linux/delay.h>
  7. #include <linux/err.h>
  8. #include <linux/workqueue.h>
  9. #include <asm/io.h>
  10. #include <linux/uaccess.h>
  11. #include <linux/syscalls.h>
  12. //#include <plat/gpio-cfg.h>
  13. //#include <mach/msm8930-gpio.h>
  14. extern struct class *sec_class;
  15. struct device *slot_switch_dev;
  16. struct slot_switch_wq {
  17. struct delayed_work work_q;
  18. // struct fsa9480_info *sdata;
  19. struct list_head entry;
  20. };
  21. #ifdef CONFIG_MACH_H3GDUOS_CTC
  22. #define GPIO_SIM_SEL 142
  23. #define GPIO_GG_SEL 115
  24. #else
  25. #define GPIO_SIM_SEL 123
  26. #define GPIO_GG_SEL 0
  27. #endif
  28. static ssize_t get_slot_switch(struct device *dev, struct device_attribute *attr, char *buf)
  29. {
  30. int value;
  31. //return '0' slot path is '||', return '1' slot path is 'X'
  32. value = gpio_get_value(GPIO_SIM_SEL);
  33. printk("Current Slot is %x\n", value);
  34. return sprintf(buf, "%d\n", value);
  35. }
  36. // 1 : BCOM
  37. // 0 : SPRD
  38. static ssize_t set_slot_switch(struct device *dev, struct device_attribute *attr, const char *buf, size_t size)
  39. {
  40. int value;
  41. int fd;
  42. char buffer[2]={0};
  43. mm_segment_t fs;
  44. sscanf(buf, "%d", &value);
  45. fs = get_fs();
  46. set_fs(get_ds());
  47. if ((fd = sys_open("/efs/slot_witch.bin", O_CREAT|O_WRONLY, 0)) < 0)
  48. {
  49. printk("%s :: open failed %s ,fd=0x%x\n", __func__, "/efs/slot_witch.bin", fd);
  50. } else {
  51. printk("%s :: open success %s ,fd=0x%x\n", __func__, "/efs/slot_witch.bin", fd);
  52. }
  53. printk("%s : value = %d \n", __func__,value);
  54. switch(value) {
  55. case 0:
  56. gpio_set_value(GPIO_SIM_SEL, 0);
  57. sprintf(buffer, "%s", "0");
  58. printk("set slot switch to %x\n", gpio_get_value(GPIO_SIM_SEL));
  59. break;
  60. case 1:
  61. gpio_set_value(GPIO_SIM_SEL, 1);
  62. sprintf(buffer, "1");
  63. printk("set slot switch to %x\n", gpio_get_value(GPIO_SIM_SEL));
  64. break;
  65. default:
  66. printk("Enter 0 or 1!!\n");
  67. }
  68. sys_write(fd, buffer, strlen(buffer));
  69. sys_close(fd);
  70. set_fs(fs);
  71. return size;
  72. }
  73. static DEVICE_ATTR(slot_sel, S_IRUGO | S_IWUSR | S_IWGRP, get_slot_switch, set_slot_switch);
  74. static void slot_switch_init_work(struct work_struct *work)
  75. {
  76. struct delayed_work *dw = container_of(work, struct delayed_work, work);
  77. struct slot_switch_wq *wq = container_of(dw, struct slot_switch_wq, work_q);
  78. // struct fsa9480_info *usbsw = wq->sdata;
  79. int fd;
  80. int ret;
  81. char buffer[2]={0};
  82. mm_segment_t fs;
  83. printk("[slot switch]: %s :: \n",__func__);
  84. fs = get_fs();
  85. set_fs(get_ds());
  86. if ((fd = sys_open("/efs/slot_switch.bin", O_CREAT|O_RDWR ,0664)) < 0)
  87. {
  88. schedule_delayed_work(&wq->work_q, msecs_to_jiffies(2000));
  89. printk("[slot switch]: %s :: open failed %s ,fd=0x%x\n",__func__,"/efs/slot_switch.bin",fd);
  90. if(fd < 0){
  91. sys_close(fd);
  92. set_fs(fs);
  93. }
  94. } else {
  95. cancel_delayed_work(&wq->work_q);
  96. printk("[slot switch]: %s :: open success %s ,fd=0x%x\n",__func__,"/efs/slot_switch.bin",fd);
  97. }
  98. ret = sys_read(fd, buffer, 1);
  99. if(ret < 0) {
  100. printk("slot_switch READ FAIL!\n");
  101. sys_close(fd);
  102. set_fs(fs);
  103. return;
  104. }
  105. printk("slot switch buffer : %s\n", buffer);
  106. #if 0//!defined(CONFIG_MACH_MELIUS_CHN_CTC) && !defined(CONFIG_MACH_CRATER_CHN_CTC)
  107. if (!strcmp(buffer, "0"))//SPRD
  108. {
  109. gpio_set_value(GPIO_SIM_SEL, 0);
  110. printk("set slot switch to %x\n", gpio_get_value(GPIO_SIM_SEL));
  111. } else if(!strcmp(buffer, "1")){//BCOM
  112. gpio_set_value(GPIO_SIM_SEL, 1);
  113. printk("set slot switch to %x\n", gpio_get_value(GPIO_SIM_SEL));
  114. }
  115. #endif
  116. sys_close(fd);
  117. set_fs(fs);
  118. return;
  119. }
  120. static int __init slot_switch_manager_init(void)
  121. {
  122. int ret = 0;
  123. int err = 0;
  124. int gpio = 0;
  125. struct slot_switch_wq *wq;
  126. printk("slot_switch_manager_init\n");
  127. //initailize uim_sim_switch gpio
  128. printk("%s start \n",__func__);
  129. gpio = GPIO_SIM_SEL;
  130. err = gpio_request(gpio, "SIM_SEL");
  131. if (err) {
  132. pr_err("fail to request gpio %s, gpio %d, errno %d\n",
  133. "PDA_ACTIVE", GPIO_SIM_SEL, err);
  134. } else {
  135. gpio_tlmm_config(GPIO_CFG(GPIO_SIM_SEL, 0, GPIO_CFG_OUTPUT, GPIO_CFG_NO_PULL, GPIO_CFG_2MA), GPIO_CFG_ENABLE);
  136. gpio_direction_output(gpio, 0);
  137. gpio_export(gpio, 0);
  138. gpio_set_value(GPIO_SIM_SEL, 0);
  139. printk("%s end \n",__func__);
  140. }
  141. #ifdef CONFIG_MACH_H3GDUOS_CTC
  142. gpio = GPIO_GG_SEL;
  143. err = gpio_request(gpio, "GG_SEL");
  144. if (err) {
  145. pr_err("fail to request gpio %s, gpio %d, errno %d\n",
  146. "PDA_ACTIVE", GPIO_GG_SEL, err);
  147. } else {
  148. gpio_tlmm_config(GPIO_CFG(GPIO_GG_SEL, 0, GPIO_CFG_OUTPUT, GPIO_CFG_NO_PULL, GPIO_CFG_2MA), GPIO_CFG_ENABLE);
  149. gpio_direction_output(gpio, 0);
  150. gpio_export(gpio, 0);
  151. gpio_set_value(GPIO_GG_SEL, 1); // fixed to '1' from '0' by jw01.yoo
  152. printk("%s end \n",__func__);
  153. }
  154. #endif
  155. //initailize slot switch device
  156. slot_switch_dev = device_create(sec_class,
  157. NULL, 0, NULL, "slot_switch");
  158. if (IS_ERR(slot_switch_dev))
  159. pr_err("Failed to create device(switch)!\n");
  160. if (device_create_file(slot_switch_dev, &dev_attr_slot_sel) < 0)
  161. pr_err("Failed to create device file(%s)!\n",
  162. dev_attr_slot_sel.attr.name);
  163. wq = kmalloc(sizeof(struct slot_switch_wq), GFP_ATOMIC);
  164. if (wq) {
  165. // wq->sdata = usbsw;
  166. INIT_DELAYED_WORK(&wq->work_q, slot_switch_init_work);
  167. schedule_delayed_work(&wq->work_q, msecs_to_jiffies(100));
  168. } else
  169. return -ENOMEM;
  170. return ret;
  171. }
  172. static void __exit slot_switch_manager_exit(void)
  173. {
  174. }
  175. module_init(slot_switch_manager_init);
  176. module_exit(slot_switch_manager_exit);
  177. MODULE_AUTHOR("SAMSUNG ELECTRONICS CO., LTD");
  178. MODULE_DESCRIPTION("Slot Switch");
  179. MODULE_LICENSE("GPL");