Merge branch 'develop-3.0' of ssh://192.168.1.29/rk/kernel into develop-3.0
[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 struct rk2818_23d_data *gpdata = NULL;
37
38
39 int modem_poweron_off(int on_off)
40 {
41         struct rk2818_23d_data *pdata = gpdata;
42         
43         if(on_off)
44         {
45                 printk("tdsc8800_poweron\n");
46                 gpio_set_value(pdata->bp_power, pdata->bp_power_active_low? GPIO_HIGH:GPIO_LOW);  // power on enable
47
48         }
49         else
50         {
51                 printk("tdsc8800_poweroff\n");
52                 gpio_set_value(pdata->bp_power, pdata->bp_power_active_low? GPIO_LOW:GPIO_HIGH);
53         }
54         return 0;
55 }
56 static int tdsc8800_open(struct inode *inode, struct file *file)
57 {
58         modem_poweron_off(1);
59         device_init_wakeup(gpdata->dev, 1);
60
61         return 0;
62 }
63
64 static int tdsc8800_release(struct inode *inode, struct file *file)
65 {
66         MODEMDBG("tdsc8800_release\n");
67
68         return 0;
69 }
70 static long  tdsc8800_ioctl(struct file *file, unsigned int a, unsigned long b)
71 {
72         return 0;
73 }
74
75 static struct file_operations tdsc8800_fops = {
76         .owner = THIS_MODULE,
77         .open =tdsc8800_open,
78         .release =tdsc8800_release,
79         .unlocked_ioctl = tdsc8800_ioctl
80 };
81
82 static struct miscdevice tdsc8800_misc = {
83         .minor = MISC_DYNAMIC_MINOR,
84         .name = "tdsc8800",
85         .fops = &tdsc8800_fops
86 };
87
88 static int tdsc8800_probe(struct platform_device *pdev)
89 {
90         struct rk2818_23d_data *pdata = gpdata = pdev->dev.platform_data;
91         struct modem_dev *tdsc8800_data = NULL;
92         int result = 0; 
93         
94         MODEMDBG("tdsc8800_probe\n");
95
96         //pdata->io_init();
97
98         pdata->dev = &pdev->dev;
99         tdsc8800_data = kzalloc(sizeof(struct modem_dev), GFP_KERNEL);
100         if(NULL == tdsc8800_data)
101         {
102                 printk("failed to request tdsc8800_data\n");
103                 goto err6;
104         }
105         platform_set_drvdata(pdev, tdsc8800_data);
106
107         result = gpio_request(pdata->bp_power, "tdsc8800");
108         if (result) {
109                 printk("failed to request BP_POW_EN gpio\n");
110                 goto err1;
111         }
112         
113         
114         gpio_direction_output(pdata->bp_power, GPIO_LOW);
115
116         gpio_set_value(pdata->bp_power, pdata->bp_reset_active_low? GPIO_LOW:GPIO_HIGH);
117         result = misc_register(&tdsc8800_misc);
118         if(result)
119         {
120                 MODEMDBG("misc_register err\n");
121         }
122         MODEMDBG("mtk23d_probe ok\n");
123         
124         return result;
125 err1:
126         gpio_free(pdata->bp_power);
127 err6:
128         kfree(tdsc8800_data);
129         return result;
130 }
131
132 int tdsc8800_suspend(struct platform_device *pdev)
133 {
134         return 0;
135 }
136
137 int tdsc8800_resume(struct platform_device *pdev)
138 {
139         return 0;
140 }
141
142 void tdsc8800_shutdown(struct platform_device *pdev, pm_message_t state)
143 {
144         struct rk2818_23d_data *pdata = pdev->dev.platform_data;
145         struct modem_dev *mt6223d_data = platform_get_drvdata(pdev);
146         
147         MODEMDBG("%s \n", __FUNCTION__);
148
149         modem_poweron_off(0);  // power down
150         gpio_free(pdata->bp_power);
151         kfree(mt6223d_data);
152 }
153
154 static struct platform_driver tdsc8800_driver = {
155         .probe  = tdsc8800_probe,
156         .shutdown       = tdsc8800_shutdown,
157         .suspend        = tdsc8800_suspend,
158         .resume         = tdsc8800_resume,
159         .driver = {
160                 .name   = "tdsc8800",
161                 .owner  = THIS_MODULE,
162         },
163 };
164
165 static int __init tdsc8800_init(void)
166 {
167         int ret = platform_driver_register(&tdsc8800_driver);
168         MODEMDBG("tdsc8800_init ret=%d\n",ret);
169         return ret;
170 }
171
172 static void __exit tdsc8800_exit(void)
173 {
174         MODEMDBG("tdsc8800_exit\n");
175         platform_driver_unregister(&tdsc8800_driver);
176 }
177
178 module_init(tdsc8800_init);
179 module_exit(tdsc8800_exit);