From 1eb77f42db61a1046a1a900724cfa50f0d994ec7 Mon Sep 17 00:00:00 2001 From: =?utf8?q?=E8=B5=B5=E5=AD=90=E5=88=9D?= Date: Mon, 17 Sep 2012 11:27:34 +0800 Subject: [PATCH] phonepad:update mt6229 for new module --- arch/arm/mach-rk30/board-rk30-sdk.c | 14 ++- drivers/misc/3g_module/mt6229.c | 186 +++++++++++++++++----------- include/linux/mt6229.h | 6 +- 3 files changed, 130 insertions(+), 76 deletions(-) diff --git a/arch/arm/mach-rk30/board-rk30-sdk.c b/arch/arm/mach-rk30/board-rk30-sdk.c index 7da6525dda3a..49cb588e0331 100755 --- a/arch/arm/mach-rk30/board-rk30-sdk.c +++ b/arch/arm/mach-rk30/board-rk30-sdk.c @@ -334,7 +334,11 @@ static int mt6229_io_init(void) rk30_mux_api_set(GPIO4D2_SMCDATA10_TRACEDATA10_NAME, GPIO4D_GPIO4D2); rk30_mux_api_set(GPIO2B7_LCDC1DATA15_SMCADDR19_HSADCDATA7_NAME, GPIO2B_GPIO2B7); rk30_mux_api_set(GPIO2C0_LCDCDATA16_GPSCLK_HSADCCLKOUT_NAME, GPIO2C_GPIO2C0); + rk30_mux_api_set(GPIO2C1_LCDC1DATA17_SMCBLSN0_HSADCDATA6_NAME, GPIO2C_GPIO2C1); + rk30_mux_api_set(GPIO2C1_LCDC1DATA17_SMCBLSN0_HSADCDATA6_NAME, GPIO2C_GPIO2C1); return 0; + + return 0; } static int mt6229_io_deinit(void) @@ -347,10 +351,12 @@ struct rk29_mt6229_data rk29_mt6229_info = { .io_init = mt6229_io_init, .io_deinit = mt6229_io_deinit, .modem_power_en = RK30_PIN6_PB2, - .bp_power = RK30_PIN2_PB7, - .bp_reset = RK30_PIN4_PD2, - .ap_wakeup_bp = RK30_PIN2_PC0, - .bp_wakeup_ap = RK30_PIN6_PA0, + .bp_power = RK30_PIN2_PB6, + .modem_usb_en = RK30_PIN2_PC0, + .modem_uart_en = RK30_PIN2_PC1, + .bp_wakeup_ap = RK30_PIN6_PA1, + .ap_ready = RK30_PIN2_PB7, + }; struct platform_device rk29_device_mt6229 = { .name = "mt6229", diff --git a/drivers/misc/3g_module/mt6229.c b/drivers/misc/3g_module/mt6229.c index b34003faff29..3335f43eed11 100755 --- a/drivers/misc/3g_module/mt6229.c +++ b/drivers/misc/3g_module/mt6229.c @@ -41,24 +41,24 @@ struct rk29_mt6229_data *gpdata = NULL; struct class *modem_class = NULL; static int do_wakeup_irq = 0; static int modem_status; -int suspend_int =0; static void ap_wakeup_bp(struct platform_device *pdev, int wake) { struct rk29_mt6229_data *pdata = pdev->dev.platform_data; - - gpio_set_value(pdata->ap_wakeup_bp, wake); + + gpio_set_value(pdata->modem_usb_en,wake); + if(wake == 1) + wake = 0; + else + wake = 1; + gpio_set_value(pdata->modem_uart_en,wake); } extern void rk28_send_wakeup_key(void); static void do_wakeup(struct work_struct *work) { - if(suspend_int) - { - //gpio_set_value(gpdata->ap_wakeup_bp, 1); - suspend_int = 0; - } - + gpio_set_value(gpdata->ap_ready,GPIO_HIGH); + gpio_set_value(gpdata->modem_usb_en,GPIO_HIGH); } static DECLARE_DELAYED_WORK(wakeup_work, do_wakeup); @@ -68,7 +68,7 @@ static irqreturn_t detect_irq_handler(int irq, void *dev_id) { do_wakeup_irq = 0; wake_lock_timeout(&modem_wakelock, 10 * HZ); - schedule_delayed_work(&wakeup_work, 2*HZ); + //schedule_delayed_work(&wakeup_work, 2*HZ); } return IRQ_HANDLED; } @@ -78,15 +78,16 @@ int modem_poweron_off(int on_off) if(on_off) { gpio_set_value(pdata->bp_power, GPIO_LOW); - gpio_set_value(pdata->bp_power, GPIO_HIGH); - msleep(10); - gpio_set_value(pdata->bp_power, GPIO_LOW); - gpio_set_value(pdata->ap_wakeup_bp, GPIO_HIGH); + gpio_set_value(pdata->modem_usb_en, GPIO_HIGH); + gpio_set_value(pdata->modem_uart_en, GPIO_LOW); + gpio_set_value(pdata->ap_ready, GPIO_HIGH); } else { gpio_set_value(pdata->bp_power, GPIO_HIGH); - gpio_set_value(pdata->ap_wakeup_bp, GPIO_LOW); + gpio_set_value(pdata->modem_usb_en, GPIO_LOW); + gpio_set_value(pdata->modem_uart_en, GPIO_HIGH); + gpio_set_value(pdata->ap_ready, GPIO_LOW); } return 0; } @@ -96,7 +97,44 @@ static int mt6229_open(struct inode *inode, struct file *file) device_init_wakeup(pdata->dev, 1); return 0; } - +static ssize_t mt6229_write(struct file *file, const char __user *buf,size_t len, loff_t *off) +{ + static char cmd[2]; + int ret = 0; + if (len > 2) + { + return -EINVAL; + } + ret = copy_from_user(&cmd, buf, len); + if (ret != 0) { + return -EFAULT; + } + printk(" received cmd = %c\n",cmd[0]); + if (cmd[0] == '0') + { + gpio_set_value(gpdata->ap_ready, GPIO_LOW); + } + if (cmd[0] == '1') + { + gpio_set_value(gpdata->ap_ready, GPIO_HIGH); + } + if (cmd[0] == '2') + { + gpio_set_value(gpdata->modem_uart_en, GPIO_LOW); + } + if (cmd[0] == '3') + { + gpio_set_value(gpdata->modem_uart_en, GPIO_HIGH); + } + if (cmd[0] == '4') + { + gpio_set_value(gpdata->modem_usb_en, GPIO_HIGH); + }if (cmd[0] == '5') + { + gpio_set_value(gpdata->modem_usb_en, GPIO_LOW); + } + return len; +} static int mt6229_release(struct inode *inode, struct file *file) { return 0; @@ -108,11 +146,9 @@ static long mt6229_ioctl(struct file *file, unsigned int cmd, unsigned long arg) switch(cmd) { case MT6229_RESET: - gpio_set_value(pdata->bp_power, GPIO_LOW); gpio_set_value(pdata->bp_power, GPIO_HIGH); msleep(10); gpio_set_value(pdata->bp_power, GPIO_LOW); - gpio_set_value(pdata->ap_wakeup_bp, GPIO_LOW); break; default: break; @@ -123,6 +159,7 @@ static long mt6229_ioctl(struct file *file, unsigned int cmd, unsigned long arg) static struct file_operations mt6229_fops = { .owner = THIS_MODULE, .open = mt6229_open, + .write = mt6229_write, .release = mt6229_release, .unlocked_ioctl = mt6229_ioctl }; @@ -151,11 +188,13 @@ static ssize_t modem_status_write(struct class *cls, const char *_buf, size_t _c int new_state = simple_strtoul(_buf, NULL, 16); if(new_state == modem_status) return _count; if (new_state == 1){ - printk("%s, c(%d), open modem \n", __FUNCTION__, new_state); - modem_poweron_off(1); + printk("%s, c(%d), modem resume \n", __FUNCTION__, new_state); + gpio_set_value(gpdata->modem_usb_en, GPIO_HIGH); + gpio_set_value(gpdata->modem_uart_en,GPIO_LOW); }else if(new_state == 0){ - printk("%s, c(%d), close modem \n", __FUNCTION__, new_state); - modem_poweron_off(0); + printk("%s, c(%d), modem suspend \n", __FUNCTION__, new_state); + gpio_set_value(gpdata->modem_usb_en, GPIO_LOW); + gpio_set_value(gpdata->modem_uart_en,GPIO_HIGH); }else{ printk("%s, invalid parameter \n", __FUNCTION__); } @@ -163,24 +202,6 @@ static ssize_t modem_status_write(struct class *cls, const char *_buf, size_t _c return _count; } static CLASS_ATTR(modem_status, 0777, modem_status_read, modem_status_write); -static void rk29_early_suspend(struct early_suspend *h) -{ - -} -static void rk29_early_resume(struct early_suspend *h) -{ - if(suspend_int) - { - //gpio_set_value(gpdata->ap_wakeup_bp, 1); - suspend_int = 0; - } -} - -static struct early_suspend mt6229_early_suspend = { - .suspend = rk29_early_suspend, - .resume = rk29_early_resume, - .level = EARLY_SUSPEND_LEVEL_DISABLE_FB - 1, - }; static int mt6229_probe(struct platform_device *pdev) { struct rk29_mt6229_data *pdata = gpdata = pdev->dev.platform_data; @@ -189,46 +210,64 @@ static int mt6229_probe(struct platform_device *pdev) pdata->dev = &pdev->dev; if(pdata->io_init) pdata->io_init(); - gpio_set_value(pdata->modem_power_en, GPIO_HIGH); - msleep(1000); - modem_poweron_off(1); - modem_status = 1; - - register_early_suspend(&mt6229_early_suspend); mt6229_data = kzalloc(sizeof(struct modem_dev), GFP_KERNEL); if(mt6229_data == NULL) { printk("failed to request mt6229_data\n"); - goto err2; + goto err0; } - platform_set_drvdata(pdev, mt6229_data); - result = gpio_request(pdata->ap_wakeup_bp, "mt6229"); + platform_set_drvdata(pdev, mt6229_data); + result = gpio_request(pdata->modem_power_en,"modem_power_en"); + if(result){ + printk("failed to request modem_power_en gpio\n"); + goto err1; + } + gpio_set_value(pdata->modem_power_en, GPIO_HIGH); + msleep(1000); + result = gpio_request(pdata->bp_power,"modem_power"); + if(result){ + printk("failed to request modem_power gpio\n"); + goto err2; + } + result = gpio_request(pdata->modem_usb_en, "modem_usb_en"); if (result) { - printk("failed to request AP_BP_WAKEUP gpio\n"); - goto err1; + printk("failed to request modem_usb_en gpio\n"); + goto err3; } + result = gpio_request(pdata->modem_uart_en,"modem_uart_en"); + if(result){ + printk("failed to request modem_uart_en gpio\n"); + goto err4; + } + result = gpio_request(pdata->bp_wakeup_ap, "bp_wakeup_ap"); + if (result) { + printk("failed to request bp_wakeup_ap gpio\n"); + goto err5; + } + gpio_direction_input(pdata->bp_wakeup_ap); irq = gpio_to_irq(pdata->bp_wakeup_ap); - enable_irq_wake(irq); if(irq < 0) { gpio_free(pdata->bp_wakeup_ap); printk("failed to request bp_wakeup_ap\n"); } - result = gpio_request(pdata->bp_wakeup_ap, "bp_wakeup_ap"); - if (result < 0) { - printk("%s: gpio_request(%d) failed\n", __func__, pdata->bp_wakeup_ap); - } - wake_lock_init(&modem_wakelock, WAKE_LOCK_SUSPEND, "bp_wakeup_ap"); - gpio_direction_input(pdata->bp_wakeup_ap); - gpio_pull_updown(pdata->bp_wakeup_ap, 1); result = request_irq(irq, detect_irq_handler, IRQ_BB_WAKEUP_AP_TRIGGER, "bp_wakeup_ap", NULL); if (result < 0) { printk("%s: request_irq(%d) failed\n", __func__, irq); gpio_free(pdata->bp_wakeup_ap); - goto err0; + goto err5; + } + enable_irq_wake(irq); + wake_lock_init(&modem_wakelock, WAKE_LOCK_SUSPEND, "bp_wakeup_ap"); + result = gpio_request(pdata->ap_ready, "ap_ready"); + if (result < 0) { + printk("failed to request ap_ready gpio\n"); + goto err6; } - enable_irq_wake(gpio_to_irq(pdata->bp_wakeup_ap)); + modem_poweron_off(1); + modem_status = 1; + result = misc_register(&mt6229_misc); if(result) { @@ -236,26 +275,34 @@ static int mt6229_probe(struct platform_device *pdev) } return result; err0: - cancel_work_sync(&mt6229_data->work); - gpio_free(pdata->bp_wakeup_ap); + kfree(mt6229_data); err1: - gpio_free(pdata->ap_wakeup_bp); + gpio_free(pdata->modem_power_en); err2: - kfree(mt6229_data); + gpio_free(pdata->bp_power); +err3: + gpio_free(pdata->modem_usb_en); +err4: + gpio_free(pdata->modem_uart_en); +err5: + gpio_free(pdata->bp_wakeup_ap); +err6: + gpio_free(pdata->ap_ready); return 0; } int mt6229_suspend(struct platform_device *pdev, pm_message_t state) { - suspend_int = 1; do_wakeup_irq = 1; -// ap_wakeup_bp(pdev, 0); + ap_wakeup_bp(pdev, 0); + gpio_set_value(gpdata->ap_ready,0); return 0; } int mt6229_resume(struct platform_device *pdev) { -// ap_wakeup_bp(pdev, 1); + gpio_set_value(gpdata->modem_uart_en,GPIO_LOW); + schedule_delayed_work(&wakeup_work, 2*HZ); return 0; } @@ -271,7 +318,8 @@ void mt6229_shutdown(struct platform_device *pdev) cancel_work_sync(&mt6229_data->work); gpio_free(pdata->modem_power_en); gpio_free(pdata->bp_power); - gpio_free(pdata->ap_wakeup_bp); + gpio_free(pdata->modem_usb_en); + gpio_free(pdata->modem_uart_en); gpio_free(pdata->bp_wakeup_ap); kfree(mt6229_data); } diff --git a/include/linux/mt6229.h b/include/linux/mt6229.h index 21750e814f51..35595aede4ed 100644 --- a/include/linux/mt6229.h +++ b/include/linux/mt6229.h @@ -14,12 +14,12 @@ struct rk29_mt6229_data { int (*io_init)(void); int (*io_deinit)(void); unsigned int bp_power; - unsigned int bp_power_active_low; unsigned int bp_reset; - unsigned int bp_reset_active_low; unsigned int bp_wakeup_ap; - unsigned int ap_wakeup_bp; + unsigned int modem_usb_en; + unsigned int modem_uart_en; unsigned int modem_power_en; + unsigned int ap_ready; }; #define MODEM_NAME "mt6229" -- 2.34.1