1 /* drivers/misc/bp/chips/mu509.c
\r
3 * Copyright (C) 2012-2015 ROCKCHIP.
\r
4 * Author: luowei <lw@rock-chips.com>
\r
6 * This software is licensed under the terms of the GNU General Public
\r
7 * License version 2, as published by the Free Software Foundation, and
\r
8 * may be copied, distributed, and modified under those terms.
\r
10 * This program is distributed in the hope that it will be useful,
\r
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
13 * GNU General Public License for more details.
\r
16 #include <linux/module.h>
\r
17 #include <linux/kernel.h>
\r
18 #include <linux/i2c.h>
\r
19 #include <linux/irq.h>
\r
20 #include <linux/gpio.h>
\r
21 #include <linux/input.h>
\r
22 #include <linux/platform_device.h>
\r
23 #include <linux/fs.h>
\r
24 #include <linux/uaccess.h>
\r
25 #include <linux/miscdevice.h>
\r
26 #include <linux/circ_buf.h>
\r
27 #include <linux/interrupt.h>
\r
28 #include <linux/miscdevice.h>
\r
29 #include <mach/iomux.h>
\r
30 #include <mach/gpio.h>
\r
31 #include <asm/gpio.h>
\r
32 #include <linux/delay.h>
\r
33 #include <linux/poll.h>
\r
34 #include <linux/wait.h>
\r
35 #include <linux/wakelock.h>
\r
36 #include <linux/workqueue.h>
\r
37 #include <linux/slab.h>
\r
38 #include <linux/earlysuspend.h>
\r
40 #include <linux/bp-auto.h>
\r
44 #define DBG(x...) printk(x)
\r
51 /****************operate according to bp chip:start************/
\r
52 static int bp_active(struct bp_private_data *bp, int enable)
\r
54 printk("<-----SEW290 bp_active-------->\n");
\r
57 gpio_set_value(bp->ops->bp_power, GPIO_LOW);
\r
59 gpio_set_value(bp->ops->bp_power, GPIO_HIGH);
\r
61 gpio_set_value(bp->ops->bp_power, GPIO_LOW);
\r
62 gpio_set_value(bp->ops->ap_wakeup_bp, GPIO_LOW);
\r
66 gpio_set_value(bp->ops->bp_en, GPIO_HIGH);
\r
68 gpio_set_value(bp->ops->bp_en, GPIO_LOW);
\r
75 static int ap_wake_bp(struct bp_private_data *bp, int wake)
\r
79 gpio_set_value(bp->ops->ap_wakeup_bp, wake);
\r
85 static void ap_wake_bp_work(struct work_struct *work)
\r
87 struct delayed_work *wakeup_work = container_of(work, struct delayed_work, work);
\r
88 struct bp_private_data *bp = container_of(wakeup_work, struct bp_private_data, wakeup_work);
\r
90 if(bp->suspend_status)
\r
92 if(bp->ops->ap_wake_bp)
\r
93 bp->ops->ap_wake_bp(bp, 0);
\r
97 if(bp->ops->ap_wake_bp)
\r
98 bp->ops->ap_wake_bp(bp, 1);
\r
103 static int bp_init(struct bp_private_data *bp)
\r
105 printk("<-----SEW290 bp_init-------->\n");
\r
106 gpio_direction_output(bp->ops->bp_power, GPIO_HIGH);
\r
107 gpio_set_value(bp->ops->bp_power, GPIO_HIGH);
\r
109 //if(bp->ops->active)
\r
110 // bp->ops->active(bp, 1);
\r
111 gpio_direction_input(bp->ops->bp_wakeup_ap);
\r
112 gpio_direction_output(bp->ops->bp_reset, GPIO_LOW);
\r
113 gpio_direction_output(bp->ops->bp_en, GPIO_LOW);
\r
114 gpio_direction_output(bp->ops->ap_wakeup_bp, GPIO_HIGH);
\r
115 INIT_DELAYED_WORK(&bp->wakeup_work, ap_wake_bp_work);
\r
119 static int bp_reset(struct bp_private_data *bp)
\r
121 // gpio_direction_output(bp->ops->bp_power, GPIO_HIGH);
\r
123 gpio_set_value(bp->ops->bp_reset, GPIO_HIGH);
\r
125 gpio_set_value(bp->ops->bp_reset, GPIO_LOW);
\r
126 gpio_set_value(bp->ops->bp_en, GPIO_LOW);
\r
128 gpio_set_value(bp->ops->bp_en, GPIO_HIGH);
\r
130 gpio_set_value(bp->ops->bp_en, GPIO_LOW);
\r
131 gpio_set_value(bp->ops->ap_wakeup_bp, GPIO_LOW);
\r
136 static int bp_wake_ap(struct bp_private_data *bp)
\r
138 printk("<-----SEW290 bp_wake_ap-------->\n");
\r
140 bp->suspend_status = 0;
\r
141 wake_lock_timeout(&bp->bp_wakelock, 20* HZ);
\r
147 static int bp_shutdown(struct bp_private_data *bp)
\r
151 if(bp->ops->active)
\r
152 bp->ops->active(bp, 0);
\r
153 gpio_set_value(bp->ops->bp_power, GPIO_LOW);
\r
154 cancel_delayed_work_sync(&bp->wakeup_work);
\r
161 static int bp_suspend(struct bp_private_data *bp)
\r
164 printk("<-----SEW290 bp_suspend-------->\n");
\r
166 bp->suspend_status = 1;
\r
167 gpio_set_value(bp->ops->ap_wakeup_bp, GPIO_LOW);
\r
175 static int bp_resume(struct bp_private_data *bp)
\r
178 printk("<-----SEW290 bp_resume-------->\n");
\r
179 bp->suspend_status = 0;
\r
180 gpio_set_value(bp->ops->ap_wakeup_bp, GPIO_HIGH);
\r
187 struct bp_operate bp_sew290_ops = {
\r
188 #if defined(CONFIG_ARCH_RK2928)
\r
190 .bp_id = BP_ID_SEW290,
\r
191 .bp_bus = BP_BUS_TYPE_USB_UART,
\r
194 .bp_power = RK2928_PIN3_PC2, // 3g_power
\r
195 .bp_en = BP_UNKNOW_DATA, // 3g_en
\r
196 .bp_reset = RK2928_PIN1_PA3,
\r
197 .ap_ready = BP_UNKNOW_DATA, //
\r
198 .bp_ready = BP_UNKNOW_DATA,
\r
199 .ap_wakeup_bp = RK2928_PIN3_PC4,
\r
200 .bp_wakeup_ap = RK2928_PIN3_PC3, //
\r
201 .bp_uart_en = BP_UNKNOW_DATA, //EINT9
\r
202 .bp_usb_en = BP_UNKNOW_DATA, //W_disable
\r
203 .trig = IRQF_TRIGGER_FALLING,
\r
205 .active = bp_active,
\r
208 .ap_wake_bp = ap_wake_bp,
\r
209 .bp_wake_ap = bp_wake_ap,
\r
210 .shutdown = bp_shutdown,
\r
211 .read_status = NULL,
\r
212 .write_status = NULL,
\r
213 .suspend = bp_suspend,
\r
214 .resume = bp_resume,
\r
216 .private_miscdev = NULL,
\r
217 #elif defined(CONFIG_ARCH_RK30)
\r
219 .bp_id = BP_ID_SEW290,
\r
220 .bp_bus = BP_BUS_TYPE_USB_UART,
\r
223 .bp_power = BP_UNKNOW_DATA, // 3g_power
\r
224 .bp_en = BP_UNKNOW_DATA, // 3g_en
\r
225 .bp_reset = BP_UNKNOW_DATA,
\r
226 .ap_ready = BP_UNKNOW_DATA, //
\r
227 .bp_ready = BP_UNKNOW_DATA,
\r
228 .ap_wakeup_bp = RK30_PIN2_PC5,
\r
229 .bp_wakeup_ap = RK30_PIN2_PC4, //
\r
230 .bp_uart_en = BP_UNKNOW_DATA, //EINT9
\r
231 .bp_usb_en = BP_UNKNOW_DATA, //W_disable
\r
232 .trig = IRQF_TRIGGER_RISING,
\r
234 .active = bp_active,
\r
237 .ap_wake_bp = ap_wake_bp,
\r
238 .bp_wake_ap = bp_wake_ap,
\r
239 .shutdown = bp_shutdown,
\r
240 .read_status = NULL,
\r
241 .write_status = NULL,
\r
242 .suspend = bp_suspend,
\r
243 .resume = bp_resume,
\r
245 .private_miscdev = NULL,
\r
248 .bp_id = BP_ID_SEW290,
\r
249 .bp_bus = BP_BUS_TYPE_USB_UART,
\r
252 .bp_power = BP_UNKNOW_DATA,//RK2928_PIN3_PC2, // 3g_power
\r
253 .bp_en = BP_UNKNOW_DATA, // 3g_en
\r
254 .bp_reset = BP_UNKNOW_DATA,//RK2928_PIN1_PA3,
\r
255 .ap_ready = BP_UNKNOW_DATA, //
\r
256 .bp_ready = BP_UNKNOW_DATA,
\r
257 .ap_wakeup_bp = BP_UNKNOW_DATA,//RK2928_PIN3_PC4,
\r
258 .bp_wakeup_ap = BP_UNKNOW_DATA,//RK2928_PIN3_PC3, //
\r
259 .bp_uart_en = BP_UNKNOW_DATA, //EINT9
\r
260 .bp_usb_en = BP_UNKNOW_DATA, //W_disable
\r
261 .trig = IRQF_TRIGGER_FALLING,
\r
263 .active = bp_active,
\r
266 .ap_wake_bp = ap_wake_bp,
\r
267 .bp_wake_ap = bp_wake_ap,
\r
268 .shutdown = bp_shutdown,
\r
269 .read_status = NULL,
\r
270 .write_status = NULL,
\r
271 .suspend = bp_suspend,
\r
272 .resume = bp_resume,
\r
274 .private_miscdev = NULL,
\r
278 /****************operate according to bp chip:end************/
\r
280 //function name should not be changed
\r
281 static struct bp_operate *bp_get_ops(void)
\r
283 return &bp_sew290_ops;
\r
286 static int __init bp_sew290_init(void)
\r
288 struct bp_operate *ops = bp_get_ops();
\r
290 result = bp_register_slave(NULL, NULL, bp_get_ops);
\r
296 if(ops->private_miscdev)
\r
298 result = misc_register(ops->private_miscdev);
\r
300 printk("%s:misc_register err\n",__func__);
\r
305 DBG("%s\n",__func__);
\r
309 static void __exit bp_sew290_exit(void)
\r
311 //struct bp_operate *ops = bp_get_ops();
\r
312 bp_unregister_slave(NULL, NULL, bp_get_ops);
\r
316 subsys_initcall(bp_sew290_init);
\r
317 module_exit(bp_sew290_exit);
\r