td8801:add reset modem
[firefly-linux-kernel-4.4.55.git] / drivers / misc / tdsc8800.c
1 #include <linux/module.h>
2 #include <linux/kernel.h>
3 #include <linux/i2c.h>
4 #include <linux/irq.h>
5 #include <linux/gpio.h>
6 #include <linux/input.h>
7 #include <linux/platform_device.h>
8 #include <linux/fs.h>
9 #include <linux/uaccess.h>
10 #include <linux/miscdevice.h>
11 #include <linux/circ_buf.h>
12 #include <linux/interrupt.h>
13 #include <linux/miscdevice.h>
14 #include <mach/iomux.h>
15 #include <mach/gpio.h>
16 #include <linux/delay.h>
17 #include <linux/poll.h>
18 #include <linux/wait.h>
19 #include <linux/slab.h>
20
21 #include <linux/workqueue.h>
22 #include <linux/mtk23d.h>
23
24
25 MODULE_LICENSE("GPL");
26
27 #define DEBUG
28 #ifdef DEBUG
29 #define MODEMDBG(x...) printk(x)
30 #else
31 #define MODEMDBG(fmt,argss...)
32 #endif
33
34 #define SLEEP 1
35 #define READY 0
36 #define RESET 1
37 struct rk2818_23d_data *gpdata = NULL;
38
39
40 int modem_poweron_off(int on_off)
41 {
42         struct rk2818_23d_data *pdata = gpdata;
43         
44         if(on_off)
45         {
46                 printk("tdsc8800_poweron\n");
47                 gpio_set_value(pdata->bp_power, pdata->bp_power_active_low? GPIO_HIGH:GPIO_LOW);  // power on enable
48
49         }
50         else
51         {
52                 printk("tdsc8800_poweroff\n");
53                 gpio_set_value(pdata->bp_power, pdata->bp_power_active_low? GPIO_LOW:GPIO_HIGH);
54         }
55         return 0;
56 }
57 static int tdsc8800_open(struct inode *inode, struct file *file)
58 {
59         modem_poweron_off(1);
60         device_init_wakeup(gpdata->dev, 1);
61
62         return 0;
63 }
64
65 static int tdsc8800_release(struct inode *inode, struct file *file)
66 {
67         MODEMDBG("tdsc8800_release\n");
68
69         return 0;
70 }
71 static long  tdsc8800_ioctl(struct file *file, unsigned int a, unsigned long b)
72 {
73         switch(a){
74                 case RESET:
75                         modem_poweron_off(0);
76                         msleep(1000);
77                         modem_poweron_off(1);
78                         break;
79                 default:
80                         MODEMDBG("cmd error !!!\n");
81                         break;
82         }
83         return 0;
84 }
85
86 static struct file_operations tdsc8800_fops = {
87         .owner = THIS_MODULE,
88         .open =tdsc8800_open,
89         .release =tdsc8800_release,
90         .unlocked_ioctl = tdsc8800_ioctl
91 };
92
93 static struct miscdevice tdsc8800_misc = {
94         .minor = MISC_DYNAMIC_MINOR,
95         .name = "tdsc8800",
96         .fops = &tdsc8800_fops
97 };
98
99 static int tdsc8800_probe(struct platform_device *pdev)
100 {
101         struct rk2818_23d_data *pdata = gpdata = pdev->dev.platform_data;
102         struct modem_dev *tdsc8800_data = NULL;
103         int result = 0; 
104         
105         MODEMDBG("tdsc8800_probe\n");
106
107         //pdata->io_init();
108
109         pdata->dev = &pdev->dev;
110         tdsc8800_data = kzalloc(sizeof(struct modem_dev), GFP_KERNEL);
111         if(NULL == tdsc8800_data)
112         {
113                 printk("failed to request tdsc8800_data\n");
114                 goto err6;
115         }
116         platform_set_drvdata(pdev, tdsc8800_data);
117
118         result = gpio_request(pdata->bp_power, "tdsc8800");
119         if (result) {
120                 printk("failed to request BP_POW_EN gpio\n");
121                 goto err1;
122         }
123         
124         
125         gpio_direction_output(pdata->bp_power, GPIO_LOW);
126
127         gpio_set_value(pdata->bp_power, pdata->bp_reset_active_low? GPIO_LOW:GPIO_HIGH);
128         result = misc_register(&tdsc8800_misc);
129         if(result)
130         {
131                 MODEMDBG("misc_register err\n");
132         }
133         MODEMDBG("mtk23d_probe ok\n");
134         
135         return result;
136 err1:
137         gpio_free(pdata->bp_power);
138 err6:
139         kfree(tdsc8800_data);
140         return result;
141 }
142
143 int tdsc8800_suspend(struct platform_device *pdev)
144 {
145         return 0;
146 }
147
148 int tdsc8800_resume(struct platform_device *pdev)
149 {
150         return 0;
151 }
152
153 void tdsc8800_shutdown(struct platform_device *pdev, pm_message_t state)
154 {
155         struct rk2818_23d_data *pdata = pdev->dev.platform_data;
156         struct modem_dev *mt6223d_data = platform_get_drvdata(pdev);
157         
158         MODEMDBG("%s \n", __FUNCTION__);
159
160         modem_poweron_off(0);  // power down
161         gpio_free(pdata->bp_power);
162         kfree(mt6223d_data);
163 }
164
165 static struct platform_driver tdsc8800_driver = {
166         .probe  = tdsc8800_probe,
167         .shutdown       = tdsc8800_shutdown,
168         .suspend        = tdsc8800_suspend,
169         .resume         = tdsc8800_resume,
170         .driver = {
171                 .name   = "tdsc8800",
172                 .owner  = THIS_MODULE,
173         },
174 };
175
176 static int __init tdsc8800_init(void)
177 {
178         int ret = platform_driver_register(&tdsc8800_driver);
179         MODEMDBG("tdsc8800_init ret=%d\n",ret);
180         return ret;
181 }
182
183 static void __exit tdsc8800_exit(void)
184 {
185         MODEMDBG("tdsc8800_exit\n");
186         platform_driver_unregister(&tdsc8800_driver);
187 }
188
189 module_init(tdsc8800_init);
190 module_exit(tdsc8800_exit);