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