1 /* drivers/misc/bp/chips/mw100.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
50 /****************operate according to bp chip:start************/
\r
51 static int bp_active(struct bp_private_data *bp, int enable)
\r
56 printk("mw100 power on \n");
\r
57 /* gpio_set_value(bp->ops->bp_power, GPIO_HIGH);
\r
59 gpio_set_value(bp->ops->bp_en, GPIO_LOW);
\r
60 gpio_set_value(bp->ops->bp_reset, GPIO_LOW);
\r
63 gpio_set_value(bp->ops->bp_en, GPIO_HIGH);
\r
64 gpio_set_value(bp->ops->bp_reset, GPIO_HIGH);
\r
67 //gpio_set_value(bp->ops->bp_en, GPIO_LOW);
\r
69 gpio_set_value(bp->ops->bp_power, GPIO_HIGH);
\r
71 gpio_set_value(bp->ops->bp_reset, GPIO_HIGH);
\r
73 gpio_set_value(bp->ops->bp_reset, GPIO_LOW);
\r
74 gpio_set_value(bp->ops->bp_en, GPIO_HIGH);
\r
76 //gpio_set_value(bp->ops->bp_en, GPIO_LOW);
\r
80 printk("mw100 power off \n");
\r
81 gpio_set_value(bp->ops->bp_power, GPIO_LOW);
\r
82 gpio_set_value(bp->ops->bp_en, GPIO_LOW);
\r
83 gpio_set_value(bp->ops->bp_reset, GPIO_LOW);
\r
91 static void ap_wake_bp_work(struct work_struct *work)
\r
95 static int bp_wake_ap(struct bp_private_data *bp)
\r
99 bp->suspend_status = 0;
\r
100 wake_lock_timeout(&bp->bp_wakelock, 10 * HZ);
\r
104 static int bp_init(struct bp_private_data *bp)
\r
107 //if(bp->ops->active)
\r
108 // bp->ops->active(bp, 1);
\r
109 //if(!bp->pdata->gpio_valid){
\r
110 //rk30_mux_api_set(GPIO1A3_I2S_LRCKTX_NAME,GPIO1A_GPIO1A3);
\r
112 gpio_direction_output(bp->ops->bp_power,GPIO_LOW);
\r
113 gpio_direction_output(bp->ops->bp_en,GPIO_LOW);
\r
114 gpio_direction_output(bp->ops->bp_reset,GPIO_LOW);
\r
115 gpio_direction_output(bp->ops->ap_wakeup_bp,GPIO_HIGH);
\r
116 gpio_direction_input(bp->ops->bp_wakeup_ap);
\r
117 INIT_DELAYED_WORK(&bp->wakeup_work, ap_wake_bp_work);
\r
121 static int bp_reset(struct bp_private_data *bp)
\r
123 printk("ioctrl mw100 reset !!! \n");
\r
124 gpio_set_value(bp->ops->bp_en, GPIO_LOW);
\r
125 gpio_set_value(bp->ops->bp_power, GPIO_HIGH);
\r
126 //gpio_set_value(bp->ops->bp_reset, GPIO_HIGH);
\r
128 gpio_set_value(bp->ops->bp_reset, GPIO_LOW);
\r
130 gpio_set_value(bp->ops->bp_reset, GPIO_HIGH);
\r
134 static int bp_shutdown(struct bp_private_data *bp)
\r
138 if(bp->ops->active)
\r
139 bp->ops->active(bp, 0);
\r
141 cancel_delayed_work_sync(&bp->wakeup_work);
\r
145 static int bp_suspend(struct bp_private_data *bp)
\r
149 if(!bp->suspend_status)
\r
151 bp->suspend_status = 1;
\r
152 gpio_set_value(bp->ops->ap_wakeup_bp, GPIO_LOW);
\r
157 static int bp_resume(struct bp_private_data *bp)
\r
160 bp->suspend_status = 0;
\r
161 gpio_set_value(bp->ops->ap_wakeup_bp, GPIO_HIGH);
\r
168 struct bp_operate bp_mw100_ops = {
\r
169 #if defined(CONFIG_ARCH_RK2928)
\r
171 .bp_id = BP_ID_MW100,
\r
172 .bp_bus = BP_BUS_TYPE_USB,
\r
175 .bp_power = RK2928_PIN3_PC2, // 3g_power
\r
176 .bp_en = RK2928_PIN3_PC5, // 3g_en
\r
177 .bp_reset = RK2928_PIN1_PA3,
\r
178 .ap_ready = BP_UNKNOW_DATA, //
\r
179 .bp_ready = BP_UNKNOW_DATA,
\r
180 .ap_wakeup_bp = RK2928_PIN3_PC4,
\r
181 .bp_wakeup_ap = RK2928_PIN3_PC3, //
\r
182 .bp_uart_en = BP_UNKNOW_DATA, //EINT9
\r
183 .bp_usb_en = BP_UNKNOW_DATA, //W_disable
\r
184 .trig = IRQF_TRIGGER_FALLING,
\r
186 .active = bp_active,
\r
189 .ap_wake_bp = NULL,
\r
190 .bp_wake_ap = bp_wake_ap,
\r
191 .shutdown = bp_shutdown,
\r
192 .read_status = NULL,
\r
193 .write_status = NULL,
\r
194 .suspend = bp_suspend,
\r
195 .resume = bp_resume,
\r
197 .private_miscdev = NULL,
\r
198 #elif defined(CONFIG_ARCH_RK30)
\r
200 .bp_id = BP_ID_MW100,
\r
201 .bp_bus = BP_BUS_TYPE_USB,
\r
204 .bp_power = BP_UNKNOW_DATA,//RK2928_PIN3_PC2, // 3g_power
\r
205 .bp_en = BP_UNKNOW_DATA,//RK2928_PIN3_PC5, // 3g_en
\r
206 .bp_reset = BP_UNKNOW_DATA,//RK2928_PIN1_PA3,
\r
207 .ap_ready = BP_UNKNOW_DATA, //
\r
208 .bp_ready = BP_UNKNOW_DATA,
\r
209 .ap_wakeup_bp = BP_UNKNOW_DATA,//RK2928_PIN3_PC4,
\r
210 .bp_wakeup_ap = BP_UNKNOW_DATA,//RK2928_PIN3_PC3, //
\r
211 .bp_uart_en = BP_UNKNOW_DATA, //EINT9
\r
212 .bp_usb_en = BP_UNKNOW_DATA, //W_disable
\r
213 .trig = IRQF_TRIGGER_FALLING,
\r
215 .active = bp_active,
\r
218 .ap_wake_bp = NULL,
\r
219 .bp_wake_ap = bp_wake_ap,
\r
220 .shutdown = bp_shutdown,
\r
221 .read_status = NULL,
\r
222 .write_status = NULL,
\r
223 .suspend = bp_suspend,
\r
224 .resume = bp_resume,
\r
226 .private_miscdev = NULL,
\r
229 .bp_id = BP_ID_MW100,
\r
230 .bp_bus = BP_BUS_TYPE_USB,
\r
233 .bp_power = BP_UNKNOW_DATA,//RK2928_PIN3_PC2, // 3g_power
\r
234 .bp_en = BP_UNKNOW_DATA,//RK2928_PIN3_PC5, // 3g_en
\r
235 .bp_reset = BP_UNKNOW_DATA,//RK2928_PIN1_PA3,
\r
236 .ap_ready = BP_UNKNOW_DATA, //
\r
237 .bp_ready = BP_UNKNOW_DATA,
\r
238 .ap_wakeup_bp = BP_UNKNOW_DATA,//RK2928_PIN3_PC4,
\r
239 .bp_wakeup_ap = BP_UNKNOW_DATA,//RK2928_PIN3_PC3, //
\r
240 .bp_uart_en = BP_UNKNOW_DATA, //EINT9
\r
241 .bp_usb_en = BP_UNKNOW_DATA, //W_disable
\r
242 .trig = IRQF_TRIGGER_FALLING,
\r
244 .active = bp_active,
\r
247 .ap_wake_bp = NULL,
\r
248 .bp_wake_ap = bp_wake_ap,
\r
249 .shutdown = bp_shutdown,
\r
250 .read_status = NULL,
\r
251 .write_status = NULL,
\r
252 .suspend = bp_suspend,
\r
253 .resume = bp_resume,
\r
255 .private_miscdev = NULL,
\r
259 /****************operate according to bp chip:end************/
\r
261 //function name should not be changed
\r
262 static struct bp_operate *bp_get_ops(void)
\r
264 return &bp_mw100_ops;
\r
267 static int __init bp_mw100_init(void)
\r
269 struct bp_operate *ops = bp_get_ops();
\r
271 result = bp_register_slave(NULL, NULL, bp_get_ops);
\r
277 if(ops->private_miscdev)
\r
279 result = misc_register(ops->private_miscdev);
\r
281 printk("%s:misc_register err\n",__func__);
\r
286 DBG("%s\n",__func__);
\r
290 static void __exit bp_mw100_exit(void)
\r
292 //struct bp_operate *ops = bp_get_ops();
\r
293 bp_unregister_slave(NULL, NULL, bp_get_ops);
\r
297 subsys_initcall(bp_mw100_init);
\r
298 module_exit(bp_mw100_exit);
\r