UPSTREAM: drm: prime: Honour O_RDWR during prime-handle-to-fd
[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         modem_poweron_off(0);
69
70         return 0;
71 }
72 static long  tdsc8800_ioctl(struct file *file, unsigned int a, unsigned long b)
73 {
74         switch(a){
75                 case RESET:
76                         modem_poweron_off(0);
77                         msleep(1000);
78                         modem_poweron_off(1);
79                         break;
80                 default:
81                         MODEMDBG("cmd error !!!\n");
82                         break;
83         }
84         return 0;
85 }
86
87 static struct file_operations tdsc8800_fops = {
88         .owner = THIS_MODULE,
89         .open =tdsc8800_open,
90         .release =tdsc8800_release,
91         .unlocked_ioctl = tdsc8800_ioctl
92 };
93
94 static struct miscdevice tdsc8800_misc = {
95         .minor = MISC_DYNAMIC_MINOR,
96         .name = "tdsc8800",
97         .fops = &tdsc8800_fops
98 };
99
100 static int tdsc8800_probe(struct platform_device *pdev)
101 {
102         struct rk2818_23d_data *pdata = gpdata = pdev->dev.platform_data;
103         struct modem_dev *tdsc8800_data = NULL;
104         int result = 0; 
105         
106         MODEMDBG("tdsc8800_probe\n");
107
108         //pdata->io_init();
109
110         pdata->dev = &pdev->dev;
111         tdsc8800_data = kzalloc(sizeof(struct modem_dev), GFP_KERNEL);
112         if(NULL == tdsc8800_data)
113         {
114                 printk("failed to request tdsc8800_data\n");
115                 goto err6;
116         }
117         platform_set_drvdata(pdev, tdsc8800_data);
118
119         result = gpio_request(pdata->bp_power, "tdsc8800");
120         if (result) {
121                 printk("failed to request BP_POW_EN gpio\n");
122                 goto err1;
123         }
124         
125         
126         gpio_direction_output(pdata->bp_power, GPIO_LOW);
127
128         gpio_set_value(pdata->bp_power, pdata->bp_power_active_low? GPIO_LOW:GPIO_HIGH);
129         result = misc_register(&tdsc8800_misc);
130         if(result)
131         {
132                 MODEMDBG("misc_register err\n");
133         }
134         MODEMDBG("mtk23d_probe ok\n");
135         
136         return result;
137 err1:
138         gpio_free(pdata->bp_power);
139 err6:
140         kfree(tdsc8800_data);
141         return result;
142 }
143
144 int tdsc8800_suspend(struct platform_device *pdev)
145 {
146         return 0;
147 }
148
149 int tdsc8800_resume(struct platform_device *pdev)
150 {
151         return 0;
152 }
153
154 void tdsc8800_shutdown(struct platform_device *pdev, pm_message_t state)
155 {
156         struct rk2818_23d_data *pdata = pdev->dev.platform_data;
157         struct modem_dev *mt6223d_data = platform_get_drvdata(pdev);
158         
159         MODEMDBG("%s \n", __FUNCTION__);
160
161         modem_poweron_off(0);  // power down
162         gpio_free(pdata->bp_power);
163         kfree(mt6223d_data);
164 }
165
166 static struct platform_driver tdsc8800_driver = {
167         .probe  = tdsc8800_probe,
168         .shutdown       = tdsc8800_shutdown,
169         .suspend        = tdsc8800_suspend,
170         .resume         = tdsc8800_resume,
171         .driver = {
172                 .name   = "tdsc8800",
173                 .owner  = THIS_MODULE,
174         },
175 };
176
177 static int __init tdsc8800_init(void)
178 {
179         int ret = platform_driver_register(&tdsc8800_driver);
180         MODEMDBG("tdsc8800_init ret=%d\n",ret);
181         return ret;
182 }
183
184 static void __exit tdsc8800_exit(void)
185 {
186         MODEMDBG("tdsc8800_exit\n");
187         platform_driver_unregister(&tdsc8800_driver);
188 }
189
190 module_init(tdsc8800_init);
191 module_exit(tdsc8800_exit);