From e678c7499efd66c171c1356f8dce4f4f3b02f95f Mon Sep 17 00:00:00 2001 From: zzy Date: Tue, 21 May 2013 14:45:03 +0800 Subject: [PATCH] kernel for u7501 3G modem --- drivers/misc/bp/chips/Kconfig | 3 + drivers/misc/bp/chips/Makefile | 1 + drivers/misc/bp/chips/u7501.c | 261 ++++++++++++++++++++++++++++++++ drivers/usb/serial/usb-serial.c | 2 +- 4 files changed, 266 insertions(+), 1 deletion(-) create mode 100644 drivers/misc/bp/chips/u7501.c diff --git a/drivers/misc/bp/chips/Kconfig b/drivers/misc/bp/chips/Kconfig index 29e63cc71fee..ba45f960ebef 100755 --- a/drivers/misc/bp/chips/Kconfig +++ b/drivers/misc/bp/chips/Kconfig @@ -19,3 +19,6 @@ bool "modem c66a" config BP_AUTO_SEW290 bool "modem sew290" default n +config BP_AUTO_U7501 +bool "modem u7501" + default n diff --git a/drivers/misc/bp/chips/Makefile b/drivers/misc/bp/chips/Makefile index 12fd8870b140..404addb1692b 100755 --- a/drivers/misc/bp/chips/Makefile +++ b/drivers/misc/bp/chips/Makefile @@ -7,3 +7,4 @@ obj-$(CONFIG_BP_AUTO) += m51.o obj-$(CONFIG_BP_AUTO) += mtk6250.o obj-$(CONFIG_BP_AUTO) += c66a.o obj-$(CONFIG_BP_AUTO) += sew290.o +obj-$(CONFIG_BP_AUTO) += u7501.o diff --git a/drivers/misc/bp/chips/u7501.c b/drivers/misc/bp/chips/u7501.c new file mode 100644 index 000000000000..6fe4574f22f6 --- /dev/null +++ b/drivers/misc/bp/chips/u7501.c @@ -0,0 +1,261 @@ +/* drivers/misc/bp/chips/U7501.c + * + * Copyright (C) 2012-2015 ROCKCHIP. + * Author: luowei + * + * This software is licensed under the terms of the GNU General Public + * License version 2, as published by the Free Software Foundation, and + * may be copied, distributed, and modified under those terms. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + */ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + + +#if 0 +#define DBG(x...) printk(x) + +#else +#define DBG(x...) +#endif + + +/****************operate according to bp chip:start************/ +static int bp_active(struct bp_private_data *bp, int enable) +{ + printk("<-----U7501 bp_active-------->\n"); + if(enable) + { + printk("<-----U7501 bp_active---enable---HIGH-->\n"); + gpio_set_value(bp->ops->bp_power, GPIO_LOW); + msleep(1000); + gpio_set_value(bp->ops->bp_power, GPIO_HIGH); + msleep(2500); + gpio_set_value(bp->ops->bp_power, GPIO_LOW); + gpio_set_value(bp->ops->ap_wakeup_bp, GPIO_HIGH); + } + else + { + printk("<-----U7501 bp_active---disenable----->\n"); + gpio_set_value(bp->ops->bp_en, GPIO_HIGH); + msleep(4000); + gpio_set_value(bp->ops->bp_en, GPIO_LOW); + + } + + return 0; +} + +static int ap_wake_bp(struct bp_private_data *bp, int wake) +{ + printk("<-----U7501 ap_wake_bp-------->\n"); + + int result = 0; + + gpio_set_value(bp->ops->ap_wakeup_bp, wake); + + return result; + +} + +static void ap_wake_bp_work(struct work_struct *work) +{ + struct delayed_work *wakeup_work = container_of(work, struct delayed_work, work); + struct bp_private_data *bp = container_of(wakeup_work, struct bp_private_data, wakeup_work); + + if(bp->suspend_status) + { + if(bp->ops->ap_wake_bp) + bp->ops->ap_wake_bp(bp, 0); + } + else + { + if(bp->ops->ap_wake_bp) + bp->ops->ap_wake_bp(bp, 1); + } +} + + +static int bp_init(struct bp_private_data *bp) +{ + printk("<-----U7501 bp_init-------->\n"); + gpio_direction_output(bp->ops->bp_power, GPIO_HIGH); + gpio_set_value(bp->ops->bp_power, GPIO_HIGH); + msleep(500); + //if(bp->ops->active) + // bp->ops->active(bp, 1); + gpio_direction_input(bp->ops->bp_wakeup_ap); + gpio_direction_output(bp->ops->bp_reset, GPIO_LOW); + gpio_direction_output(bp->ops->bp_en, GPIO_LOW); + gpio_direction_output(bp->ops->ap_wakeup_bp, GPIO_HIGH); + INIT_DELAYED_WORK(&bp->wakeup_work, ap_wake_bp_work); + return 0; +} + +static int bp_reset(struct bp_private_data *bp) +{ +// gpio_direction_output(bp->ops->bp_power, GPIO_HIGH); +// msleep(500); + gpio_set_value(bp->ops->bp_reset, GPIO_HIGH); + msleep(100); + gpio_set_value(bp->ops->bp_reset, GPIO_LOW); + gpio_set_value(bp->ops->bp_en, GPIO_LOW); + msleep(1000); + gpio_set_value(bp->ops->bp_en, GPIO_HIGH); + msleep(700); + gpio_set_value(bp->ops->bp_en, GPIO_LOW); + gpio_set_value(bp->ops->ap_wakeup_bp, GPIO_LOW); + + return 0; +} + +static int bp_wake_ap(struct bp_private_data *bp) +{ + printk("<-----U7501 bp_wake_ap-------->\n"); + + bp->suspend_status = 0; + wake_lock_timeout(&bp->bp_wakelock, 20* HZ); + + return 0; +} + + +static int bp_shutdown(struct bp_private_data *bp) +{ + int result = 0; + + if(bp->ops->active) + bp->ops->active(bp, 0); + gpio_set_value(bp->ops->bp_power, GPIO_LOW); + cancel_delayed_work_sync(&bp->wakeup_work); + + return result; +} + + + +static int bp_suspend(struct bp_private_data *bp) +{ + + printk("<-----U7501 bp_suspend---000000----->\n"); + + bp->suspend_status = 1; + gpio_set_value(bp->ops->ap_wakeup_bp, GPIO_LOW); + + return 0; +} + + + + +static int bp_resume(struct bp_private_data *bp) +{ + printk("<-----U7501 bp_resume-----hhhh--->\n"); + bp->suspend_status = 0; + gpio_set_value(bp->ops->ap_wakeup_bp, GPIO_HIGH); + + + return 0; +} + + +struct bp_operate bp_U7501_ops = { + .name = "U7501", + .bp_id = BP_ID_U7501, + .bp_bus = BP_BUS_TYPE_USB_UART, + .bp_pid = 0, + .bp_vid = 0, + .bp_power = BP_UNKNOW_DATA, // 3g_power + .bp_en = BP_UNKNOW_DATA, // 3g_en + .bp_reset = BP_UNKNOW_DATA, + .ap_ready = BP_UNKNOW_DATA, // + .bp_ready = BP_UNKNOW_DATA, + .ap_wakeup_bp = RK30_PIN2_PC4, + .bp_wakeup_ap = RK30_PIN2_PC5, // + .bp_uart_en = BP_UNKNOW_DATA, //EINT9 + .bp_usb_en = BP_UNKNOW_DATA, //W_disable + .trig = IRQF_TRIGGER_RISING, + + .active = bp_active, + .init = bp_init, + .reset = bp_reset, + .ap_wake_bp = ap_wake_bp, + .bp_wake_ap = bp_wake_ap, + .shutdown = bp_shutdown, + .read_status = NULL, + .write_status = NULL, + .suspend = bp_suspend, + .resume = bp_resume, + .misc_name = NULL, + .private_miscdev = NULL, +}; + +/****************operate according to bp chip:end************/ + +//function name should not be changed +static struct bp_operate *bp_get_ops(void) +{ + return &bp_U7501_ops; +} + +static int __init bp_U7501_init(void) +{ + struct bp_operate *ops = bp_get_ops(); + int result = 0; + result = bp_register_slave(NULL, NULL, bp_get_ops); + if(result) + { + return result; + } + + if(ops->private_miscdev) + { + result = misc_register(ops->private_miscdev); + if (result < 0) { + printk("%s:misc_register err\n",__func__); + return result; + } + } + + DBG("%s\n",__func__); + return result; +} + +static void __exit bp_U7501_exit(void) +{ + //struct bp_operate *ops = bp_get_ops(); + bp_unregister_slave(NULL, NULL, bp_get_ops); +} + + +subsys_initcall(bp_U7501_init); +module_exit(bp_U7501_exit); + diff --git a/drivers/usb/serial/usb-serial.c b/drivers/usb/serial/usb-serial.c index 83e6259314d2..ce256507bb61 100644 --- a/drivers/usb/serial/usb-serial.c +++ b/drivers/usb/serial/usb-serial.c @@ -1075,7 +1075,7 @@ int usb_serial_probe(struct usb_interface *interface, } #ifdef CONFIG_BP_AUTO int bp_id = get_current_bp_id(); - if (((le16_to_cpu(dev->descriptor.idVendor) == 0x1782 ) && (le16_to_cpu(dev->descriptor.idProduct) == 0x0002) && (bp_id == 2)) + if (((le16_to_cpu(dev->descriptor.idVendor) == 0x1782 ) && (le16_to_cpu(dev->descriptor.idProduct) == 0x0002) && (bp_id == 12)) || ((le16_to_cpu(dev->descriptor.idVendor) == 0x19f5) && (le16_to_cpu(dev->descriptor.idProduct) == 0x9013) && (bp_id == 4)) || ((le16_to_cpu(dev->descriptor.idVendor) == 0x0E8D) && (le16_to_cpu(dev->descriptor.idProduct) == 0x00A2) && (bp_id == 1)) || ((le16_to_cpu(dev->descriptor.idVendor) == 0x21f5) && (le16_to_cpu(dev->descriptor.idProduct) == 0x2012) && (bp_id == 10)) -- 2.34.1