1 #include <linux/module.h>
2 #include <linux/kernel.h>
5 #include <linux/gpio.h>
6 #include <linux/input.h>
7 #include <linux/platform_device.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>
17 #include <linux/delay.h>
18 #include <linux/poll.h>
19 #include <linux/wait.h>
20 #include <linux/wakelock.h>
21 #include <linux/workqueue.h>
22 #include <linux/sc6610.h>
24 #include <linux/slab.h>
25 #include <linux/earlysuspend.h>
27 MODULE_LICENSE("GPL");
31 #define MODEMDBG(x...) printk(x)
33 #define MODEMDBG(fmt,argss...)
38 struct rk29_sc6610_data *s_gpdata = NULL;
40 struct class *modem_class = NULL;
41 static int do_wakeup_irq = 0;
42 static struct wake_lock modem_wakelock;
43 //#define IRQ_BB_WAKEUP_AP_TRIGGER IRQF_TRIGGER_FALLING
44 #define IRQ_BB_WAKEUP_AP_TRIGGER IRQF_TRIGGER_RISING
45 int modem_poweron_off(int on_off)
47 struct rk29_sc6610_data *pdata = s_gpdata;
49 gpio_set_value(pdata->bp_power, GPIO_HIGH);
52 gpio_set_value(pdata->bp_power, GPIO_LOW);
57 static irqreturn_t detect_irq_handler(int irq, void *dev_id)
63 wake_lock_timeout(&modem_wakelock, 10 * HZ);
67 static int sc6610_open(struct inode *inode, struct file *file)
72 static int sc6610_release(struct inode *inode, struct file *file)
77 static long sc6610_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
79 struct rk29_sc6610_data *pdata = s_gpdata;
83 gpio_set_value(pdata->bp_reset, GPIO_LOW);
85 gpio_set_value(pdata->bp_reset, GPIO_HIGH);
88 modem_poweron_off(MODEM_ON);
91 modem_poweron_off(MODEM_OFF);
99 static struct file_operations sc6610_fops = {
100 .owner = THIS_MODULE,
102 .release = sc6610_release,
103 .unlocked_ioctl = sc6610_ioctl
106 static struct miscdevice sc6610_misc = {
107 .minor = MISC_DYNAMIC_MINOR,
112 static int sc6610_probe(struct platform_device *pdev)
114 struct rk29_sc6610_data *pdata = s_gpdata = pdev->dev.platform_data;
115 struct modem_dev *sc6610_data = NULL;
118 pdata->dev = &pdev->dev;
122 result = gpio_request(pdata->ap_wakeup_bp, "ap_wakeup_bp");
124 printk("failed to request ap_wakeup_bp gpio\n");
127 result = gpio_request(pdata->bp_power, "bp_power");
129 printk("failed to request bp_power gpio\n");
132 result = gpio_request(pdata->bp_wakeup_ap, "bp_wakeup_ap");
134 printk("failed to request bp_wakeup_ap gpio\n");
138 gpio_set_value(pdata->ap_wakeup_bp, GPIO_HIGH);
140 irq = gpio_to_irq(pdata->bp_wakeup_ap);
142 result = request_irq(irq, detect_irq_handler, IRQ_BB_WAKEUP_AP_TRIGGER, "bp_wakeup_ap", NULL);
144 printk("%s: request_irq(%d) failed\n", __func__, irq);
147 enable_irq_wake(irq);
148 wake_lock_init(&modem_wakelock, WAKE_LOCK_SUSPEND, "bp_wakeup_ap");
149 sc6610_data = kzalloc(sizeof(struct modem_dev), GFP_KERNEL);
150 if(sc6610_data == NULL)
152 printk("failed to request sc6610_data\n");
155 platform_set_drvdata(pdev, sc6610_data);
156 result = misc_register(&sc6610_misc);
159 printk("misc_register err\n");
161 modem_poweron_off(MODEM_ON);
165 gpio_free(pdata->ap_wakeup_bp);
167 gpio_free(pdata->bp_power);
169 gpio_free(pdata->bp_wakeup_ap);
175 int c6610_suspend(struct platform_device *pdev, pm_message_t state)
177 struct rk29_sc6610_data *pdata = s_gpdata = pdev->dev.platform_data;
178 pdata->dev = &pdev->dev;
180 gpio_set_value(pdata->ap_wakeup_bp, GPIO_LOW);
184 int c6610_resume(struct platform_device *pdev)
186 struct rk29_sc6610_data *pdata = s_gpdata = pdev->dev.platform_data;
187 pdata->dev = &pdev->dev;
188 gpio_set_value(pdata->ap_wakeup_bp, GPIO_HIGH);
192 void c6610_shutdown(struct platform_device *pdev)
194 struct rk29_sc6610_data *pdata = pdev->dev.platform_data;
195 struct modem_dev *sc6610_data = platform_get_drvdata(pdev);
196 modem_poweron_off(MODEM_OFF);
199 cancel_work_sync(&sc6610_data->work);
200 gpio_free(pdata->bp_power);
201 gpio_free(pdata->ap_wakeup_bp);
202 gpio_free(pdata->bp_wakeup_ap);
206 static struct platform_driver sc6610_driver = {
207 .probe = sc6610_probe,
208 .shutdown = c6610_shutdown,
209 .suspend = c6610_suspend,
210 .resume = c6610_resume,
213 .owner = THIS_MODULE,
217 static int __init sc6610_init(void)
220 return platform_driver_register(&sc6610_driver);
223 static void __exit sc6610_exit(void)
225 platform_driver_unregister(&sc6610_driver);
229 module_init(sc6610_init);
231 module_exit(sc6610_exit);