drm/rockchip: dw-mipi: Add reset control for APB
[firefly-linux-kernel-4.4.55.git] / drivers / headset_observe / rk_headset.c
index e9f39d805ed6dd0e21194b940d980c2804203614..e6b6a289a548d993d31227cc09a31c565126887d 100755 (executable)
@@ -14,7 +14,6 @@
  */
 
 #include <linux/module.h>
-#include <linux/sysdev.h>
 #include <linux/device.h>
 #include <linux/fs.h>
 #include <linux/interrupt.h>
 #include <linux/err.h>
 #include <linux/hrtimer.h>
 #include <linux/switch.h>
-#include <linux/input.h>
 #include <linux/debugfs.h>
 #include <linux/wakelock.h>
-#include <asm/gpio.h>
+#include <linux/gpio.h>
 #include <asm/atomic.h>
-#include <asm/mach-types.h>
+#include <linux/pm.h>
+#include <linux/i2c.h>
+#include <linux/spi/spi.h>
 #include "rk_headset.h"
+#ifdef CONFIG_HAS_EARLYSUSPEND
 #include <linux/earlysuspend.h>
-#include <linux/gpio.h>
-#include <mach/board.h>
-#include <linux/slab.h>
+#endif
 
 /* Debug */
 #if 0
 
 #define HEADSET_IN 1
 #define HEADSET_OUT 0
-#define HOOK_DOWN 0
-#define HOOK_UP 1
+#define HOOK_DOWN 1
+#define HOOK_UP 0
 #define enable 1
 #define disable 0
 
-
+#if defined(CONFIG_SND_RK_SOC_RK2928) || defined(CONFIG_SND_RK29_SOC_RK610)
+extern void rk2928_codec_set_spk(bool on);
+#endif
 #ifdef CONFIG_SND_SOC_WM8994
 extern int wm8994_set_status(void);
 #endif
@@ -86,11 +87,45 @@ struct headset_priv {
 };
 static struct headset_priv *headset_info;
 
-int Headset_isMic(void)
+#ifdef CONFIG_MODEM_MIC_SWITCH
+#define HP_MIC 0
+#define MAIN_MIC 1
+void Modem_Mic_switch(int value)
+{
+       if(value == HP_MIC)
+               gpio_set_value(headset_info->pdata->mic_switch_gpio, headset_info->pdata->hp_mic_io_value);
+       else if(value == MAIN_MIC)
+               gpio_set_value(headset_info->pdata->mic_switch_gpio,headset_info->pdata->main_mic_io_value);
+}
+void Modem_Mic_release(void)
+{
+       if(headset_info->cur_headset_status == 1)
+               gpio_set_value(headset_info->pdata->mic_switch_gpio, headset_info->pdata->hp_mic_io_value);
+       else
+               gpio_set_value(headset_info->pdata->mic_switch_gpio,headset_info->pdata->main_mic_io_value);
+}
+#endif
+
+static int read_gpio(int gpio)
 {
-       return headset_info->isMic;
+       int i,level;
+       for(i=0; i<3; i++)
+       {
+               level = gpio_get_value(gpio);
+               if(level < 0)
+               {
+                       printk("%s:get pin level again,pin=%d,i=%d\n",__FUNCTION__,gpio,i);
+                       msleep(1);
+                       continue;
+               }
+               else
+               break;
+       }
+       if(level < 0)
+               printk("%s:get pin level  err!\n",__FUNCTION__);
+
+       return level;
 }
-EXPORT_SYMBOL_GPL(Headset_isMic);
 
 static irqreturn_t headset_interrupt(int irq, void *dev_id)
 {
@@ -99,7 +134,7 @@ static irqreturn_t headset_interrupt(int irq, void *dev_id)
        return IRQ_HANDLED;
 }
 
-static irqreturn_t Hook_interrupt(int irq, void *dev_id)
+static irqreturn_t hook_interrupt(int irq, void *dev_id)
 {
        DBG("---Hook_interrupt---\n");  
 //     disable_irq_nosync(headset_info->irq[HOOK]);
@@ -107,217 +142,141 @@ static irqreturn_t Hook_interrupt(int irq, void *dev_id)
        return IRQ_HANDLED;
 }
 
-static int headset_change_irqtype(int type,unsigned int irq_type)
-{
-       int ret = 0;
-       DBG("--------%s----------\n",__FUNCTION__);
-       free_irq(headset_info->irq[type],NULL);
-       
-       switch(type)
-       {
-       case HOOK:
-               ret = request_irq(headset_info->irq[type], Hook_interrupt, irq_type, "headset_input", NULL);
-               break;
-       case HEADSET:
-               ret = request_irq(headset_info->irq[type], headset_interrupt, irq_type, "headset_hook", NULL);
-               break;
-       default:
-               ret = -1;
-               break;
-       }
-
-       if (ret<0) 
-       {
-               DBG("headset_change_irqtype: request irq failed\n");
-        return ret;
-       }
-       return ret;
-}
-
 static void headsetobserve_work(struct work_struct *work)
 {
-       int i,level = 0;
+       int level = 0;
+       int level2 = 0;
        struct rk_headset_pdata *pdata = headset_info->pdata;
        static unsigned int old_status = 0;
        DBG("---headsetobserve_work---\n");
        mutex_lock(&headset_info->mutex_lock[HEADSET]);
 
-       for(i=0; i<3; i++)
-       {
-               level = gpio_get_value(pdata->Headset_gpio);
-               if(level < 0)
-               {
-                       printk("%s:get pin level again,pin=%d,i=%d\n",__FUNCTION__,pdata->Headset_gpio,i);
-                       msleep(1);
-                       continue;
-               }
-               else
-               break;
-       }
+       level = read_gpio(pdata->headset_gpio);
        if(level < 0)
-       {
-               printk("%s:get pin level  err!\n",__FUNCTION__);
-               goto RE_ERROR;
-       }
-
+               goto out;
+       msleep(100);    
+       level2 = read_gpio(pdata->headset_gpio);
+       if(level2 < 0)
+               goto out;
+       if(level2 != level)
+               goto out;
        old_status = headset_info->headset_status;
-       switch(pdata->headset_in_type)
-       {
-       case HEADSET_IN_HIGH:
-               if(level > 0)
-                       headset_info->headset_status = HEADSET_IN;
-               else if(level == 0)
-                       headset_info->headset_status = HEADSET_OUT;     
-               break;
-       case HEADSET_IN_LOW:
-               if(level == 0)
-                       headset_info->headset_status = HEADSET_IN;
-               else if(level > 0)
-                       headset_info->headset_status = HEADSET_OUT;             
-               break;                  
-       default:
-               DBG("---- ERROR: on headset headset_in_type error -----\n");
-               break;                  
-       }
-       if(old_status == headset_info->headset_status)
-       {
+       if(pdata->headset_insert_type == HEADSET_IN_HIGH)
+               headset_info->headset_status = level?HEADSET_IN:HEADSET_OUT;
+       else
+               headset_info->headset_status = level?HEADSET_OUT:HEADSET_IN;
+
+       if(old_status == headset_info->headset_status)  {
                DBG("old_status == headset_info->headset_status\n");
-               goto RE_ERROR;
+               goto out;
        }
-
-       switch(pdata->headset_in_type)
+       
+       DBG("(headset in is %s)headset status is %s\n",
+               pdata->headset_insert_type?"high level":"low level",
+               headset_info->headset_status?"in":"out");
+               
+       if(headset_info->headset_status == HEADSET_IN)
        {
-       case HEADSET_IN_HIGH:
-               if(level > 0)
-               {//in--High level
-                       DBG("--- HEADSET_IN_HIGH headset in HIGH---\n");
-                       headset_info->cur_headset_status = BIT_HEADSET_NO_MIC;
-                       headset_change_irqtype(HEADSET,IRQF_TRIGGER_FALLING);//
-                       if (pdata->Hook_gpio) {
-                               del_timer(&headset_info->headset_timer);//Start the timer, wait for switch to the headphone channel
-                       //      headset_info->headset_timer.expires = jiffies + 500;
-                               headset_info->headset_timer.expires = jiffies + 10;
-                               add_timer(&headset_info->headset_timer);
-                       }
-               }
-               else if(level == 0)
-               {//out--Low level
-                       DBG("---HEADSET_IN_HIGH headset out HIGH---\n");        
-                       if(headset_info->isHook_irq == enable)
-                       {
-                               DBG("disable headset_hook irq\n");
-                               headset_info->isHook_irq = disable;
-                               disable_irq(headset_info->irq[HOOK]);           
-                       }       
-                       headset_info->cur_headset_status = ~(BIT_HEADSET|BIT_HEADSET_NO_MIC);
-                       headset_change_irqtype(HEADSET,IRQF_TRIGGER_RISING);//
-                       rk28_send_wakeup_key();
-                       switch_set_state(&headset_info->sdev, headset_info->cur_headset_status);        
-                       DBG("headset_info->cur_headset_status = %d\n",headset_info->cur_headset_status);                        
-               }
-               break;
-       case HEADSET_IN_LOW:
-               if(level == 0)
-               {//in--High level
-                       DBG("---HEADSET_IN_LOW headset in LOW ---\n");
-                       headset_info->cur_headset_status = BIT_HEADSET_NO_MIC;
-                       headset_change_irqtype(HEADSET,IRQF_TRIGGER_RISING);//
-                       if (pdata->Hook_gpio) {                 
-                               del_timer(&headset_info->headset_timer);//Start the timer, wait for switch to the headphone channel
-                       //      headset_info->headset_timer.expires = jiffies + 500;
-                               headset_info->headset_timer.expires = jiffies + 10;
-                               add_timer(&headset_info->headset_timer);
-                       }
-               }
-               else if(level > 0)
-               {//out--High level
-                       DBG("---HEADSET_IN_LOW headset out LOW ---\n");
-                       if(headset_info->isHook_irq == enable)
-                       {
-                               DBG("disable headset_hook irq\n");
-                               headset_info->isHook_irq = disable;
-                               disable_irq(headset_info->irq[HOOK]);           
-                       }                               
-                       headset_info->cur_headset_status = ~(BIT_HEADSET|BIT_HEADSET_NO_MIC);
-                       headset_change_irqtype(HEADSET,IRQF_TRIGGER_FALLING);//
-                       rk28_send_wakeup_key();
-                       switch_set_state(&headset_info->sdev, headset_info->cur_headset_status);        
-                       DBG("headset_info->cur_headset_status = %d\n",headset_info->cur_headset_status);                        
+               headset_info->cur_headset_status = BIT_HEADSET_NO_MIC;
+               if(pdata->headset_insert_type == HEADSET_IN_HIGH)
+                       irq_set_irq_type(headset_info->irq[HEADSET],IRQF_TRIGGER_FALLING);
+               else
+                       irq_set_irq_type(headset_info->irq[HEADSET],IRQF_TRIGGER_RISING);
+               if (pdata->hook_gpio) {
+                       del_timer(&headset_info->headset_timer);//Start the timer, wait for switch to the headphone channel
+                       headset_info->headset_timer.expires = jiffies + 100;
+                       add_timer(&headset_info->headset_timer);
+                       goto out;
                }
-               break;                  
-       default:
-               DBG("---- ERROR: on headset headset_in_type error -----\n");
-               break;                  
        }
-       
+       else if(headset_info->headset_status == HEADSET_OUT)
+       {       
+               headset_info->hook_status = HOOK_UP;
+               if(headset_info->isHook_irq == enable)
+               {
+                       DBG("disable headset_hook irq\n");
+                       headset_info->isHook_irq = disable;
+                       disable_irq(headset_info->irq[HOOK]);           
+               }       
+               headset_info->cur_headset_status = 0;//~(BIT_HEADSET|BIT_HEADSET_NO_MIC);
+               //#if defined(CONFIG_SND_RK_SOC_RK2928) || defined(CONFIG_SOC_RK3028)
+               //rk2928_codec_set_spk(HEADSET_OUT);
+               //#endif                                                
+               if(pdata->headset_insert_type == HEADSET_IN_HIGH)
+                       irq_set_irq_type(headset_info->irq[HEADSET],IRQF_TRIGGER_RISING);
+               else
+                       irq_set_irq_type(headset_info->irq[HEADSET],IRQF_TRIGGER_FALLING);
+       }
+//     rk28_send_wakeup_key();
+       switch_set_state(&headset_info->sdev, headset_info->cur_headset_status);        
+       #if defined(CONFIG_SND_RK_SOC_RK2928) || defined(CONFIG_SND_RK29_SOC_RK610)
+       if (headset_info->headset_status == HEADSET_OUT)
+       {
+               mdelay(200);
+               rk2928_codec_set_spk(HEADSET_OUT);
+               gpio_set_value(pdata->Sw_mic_gpio, headset_info->pdata->Main_mic_io_value);
+       }
+       #endif
+       DBG("headset_info->cur_headset_status = %d\n",headset_info->cur_headset_status);
 
-RE_ERROR:
+out:
        mutex_unlock(&headset_info->mutex_lock[HEADSET]);       
 }
 
-static void Hook_work(struct work_struct *work)
+static void hook_work(struct work_struct *work)
 {
-       int i,level = 0;
+       int level = 0;
        struct rk_headset_pdata *pdata = headset_info->pdata;
        static unsigned int old_status = HOOK_UP;
 
-       DBG("---Hook_work---\n");
        mutex_lock(&headset_info->mutex_lock[HOOK]);
-       if(headset_info->headset_status == HEADSET_OUT)
-       {
+       
+       if(headset_info->headset_status == HEADSET_OUT){
                DBG("Headset is out\n");
                goto RE_ERROR;
-       }       
+       }
+       
        #ifdef CONFIG_SND_SOC_WM8994
-       if(wm8994_set_status() != 0)
-       {
+       if(wm8994_set_status() != 0)    {
                DBG("wm8994 is not set on heatset channel or suspend\n");
                goto RE_ERROR;
        }
        #endif
-       for(i=0; i<3; i++)
-       {
-               level = gpio_get_value(pdata->Hook_gpio);
-               if(level < 0)
-               {
-                       printk("%s:get pin level again,pin=%d,i=%d\n",__FUNCTION__,pdata->Hook_gpio,i);
-                       msleep(1);
-                       continue;
-               }
-               else
-               break;
-       }
+       
+       level = read_gpio(pdata->hook_gpio);
        if(level < 0)
-       {
-               printk("%s:get pin level  err!\n",__FUNCTION__);
                goto RE_ERROR;
-       }
        
        old_status = headset_info->hook_status;
+       DBG("Hook_work -- level = %d\n",level);
+       
        if(level == 0)
-               headset_info->hook_status = HOOK_UP;
+               headset_info->hook_status = pdata->hook_down_type == HOOK_DOWN_HIGH?HOOK_UP:HOOK_DOWN;
        else if(level > 0)      
-               headset_info->hook_status = HOOK_DOWN;
+               headset_info->hook_status = pdata->hook_down_type == HOOK_DOWN_HIGH?HOOK_DOWN:HOOK_UP;
+               
        if(old_status == headset_info->hook_status)
        {
                DBG("old_status == headset_info->hook_status\n");
                goto RE_ERROR;
        }       
-       
-       if(level == 0)
+       DBG("Hook_work -- level = %d  hook status is %s\n",level,headset_info->hook_status?"key down":"key up");        
+       if(headset_info->hook_status == HOOK_DOWN)
        {
-               DBG("---HOOK Down ---\n");
-               headset_change_irqtype(HOOK,IRQF_TRIGGER_RISING);//
-               input_report_key(headset_info->input_dev,pdata->hook_key_code,headset_info->hook_status);
-               input_sync(headset_info->input_dev);
+               if(pdata->hook_down_type == HOOK_DOWN_HIGH)
+                       irq_set_irq_type(headset_info->irq[HOOK],IRQF_TRIGGER_FALLING);
+               else
+                       irq_set_irq_type(headset_info->irq[HOOK],IRQF_TRIGGER_RISING);          
        }
-       else if(level > 0)
+       else
        {
-               DBG("---HOOK Up ---\n");                
-               headset_change_irqtype(HOOK,IRQF_TRIGGER_FALLING);//
-               input_report_key(headset_info->input_dev,pdata->hook_key_code,headset_info->hook_status);
-               input_sync(headset_info->input_dev);
+               if(pdata->hook_down_type == HOOK_DOWN_HIGH)
+                       irq_set_irq_type(headset_info->irq[HOOK],IRQF_TRIGGER_RISING);
+               else
+                       irq_set_irq_type(headset_info->irq[HOOK],IRQF_TRIGGER_FALLING);
        }
+       input_report_key(headset_info->input_dev,HOOK_KEY_CODE,headset_info->hook_status);
+       input_sync(headset_info->input_dev);    
 RE_ERROR:
        mutex_unlock(&headset_info->mutex_lock[HOOK]);
 }
@@ -326,7 +285,7 @@ static void headset_timer_callback(unsigned long arg)
 {
        struct headset_priv *headset = (struct headset_priv *)(arg);
        struct rk_headset_pdata *pdata = headset->pdata;
-       int i,level = 0;
+       int level = 0;
        
 //     printk("headset_timer_callback,headset->headset_status=%d\n",headset->headset_status);  
 
@@ -345,42 +304,36 @@ static void headset_timer_callback(unsigned long arg)
                goto out;
        }
        #endif
-       for(i=0; i<3; i++)
-       {
-               level = gpio_get_value(pdata->Hook_gpio);
-               if(level < 0)
-               {
-                       printk("%s:get pin level again,pin=%d,i=%d\n",__FUNCTION__,pdata->Hook_gpio,i);
-                       msleep(1);
-                       continue;
-               }
-               else
-               break;
-       }
+       level = read_gpio(pdata->hook_gpio);
        if(level < 0)
-       {
-               printk("%s:get pin level  err!\n",__FUNCTION__);
                goto out;
-       }
-
-       if(level == 0)
+       if((level > 0 && pdata->hook_down_type == HOOK_DOWN_LOW)
+               || (level == 0 && pdata->hook_down_type == HOOK_DOWN_HIGH))
        {
-               headset->isMic= 0;//No microphone
-               headset_info->cur_headset_status = BIT_HEADSET_NO_MIC;
-               printk("headset->isMic = %d\n",headset->isMic);         
-       }       
-       else if(level > 0)      
-       {       
                headset->isMic = 1;//have mic
                DBG("enable headset_hook irq\n");
                enable_irq(headset_info->irq[HOOK]);
                headset->isHook_irq = enable;
-               headset_info->cur_headset_status = BIT_HEADSET; 
-               printk("headset->isMic = %d\n",headset->isMic);         
-       }
+               headset_info->hook_status = HOOK_UP;
+               if(pdata->hook_down_type == HOOK_DOWN_HIGH)
+                       irq_set_irq_type(headset_info->irq[HOOK],IRQF_TRIGGER_RISING);
+               else
+                       irq_set_irq_type(headset_info->irq[HOOK],IRQF_TRIGGER_FALLING);
+
+       }       
+       else    
+               headset->isMic= 0;//No microphone
+               
+       printk("headset->isMic = %d\n",headset->isMic); 
+       headset_info->cur_headset_status = headset_info->isMic ? 1:2;//BIT_HEADSET:BIT_HEADSET_NO_MIC;//
+       #if defined(CONFIG_SND_RK_SOC_RK2928) || defined(CONFIG_SND_RK29_SOC_RK610)
+       rk2928_codec_set_spk(HEADSET_IN);
+       if(headset_info->cur_headset_status == 1)
+               gpio_set_value(pdata->Sw_mic_gpio, pdata->Hp_mic_io_value);
+       #endif
+//     rk28_send_wakeup_key();
+       switch_set_state(&headset_info->sdev, headset_info->cur_headset_status);
        
-       rk28_send_wakeup_key();
-       switch_set_state(&headset_info->sdev, headset_info->cur_headset_status);        
        DBG("headset_info->cur_headset_status = %d\n",headset_info->cur_headset_status);        
 
 out:
@@ -402,33 +355,32 @@ static void headset_early_resume(struct early_suspend *h)
 static struct early_suspend hs_early_suspend;
 #endif
 
-static int rk_Hskey_open(struct input_dev *dev)
+static int rk_hskey_open(struct input_dev *dev)
 {
        //struct rk28_adckey *adckey = input_get_drvdata(dev);
 //     DBG("===========rk_Hskey_open===========\n");
        return 0;
 }
 
-static void rk_Hskey_close(struct input_dev *dev)
+static void rk_hskey_close(struct input_dev *dev)
 {
 //     DBG("===========rk_Hskey_close===========\n");
 //     struct rk28_adckey *adckey = input_get_drvdata(dev);
 
 }
 
-static int rockchip_headsetobserve_probe(struct platform_device *pdev)
+int rk_headset_probe(struct platform_device *pdev,struct rk_headset_pdata *pdata)
 {
        int ret;
        struct headset_priv *headset;
-       struct rk_headset_pdata *pdata;
        
        headset = kzalloc(sizeof(struct headset_priv), GFP_KERNEL);
        if (headset == NULL) {
                dev_err(&pdev->dev, "failed to allocate driver data\n");
                return -ENOMEM;
-       }       
-       headset->pdata = pdev->dev.platform_data;
-       pdata = headset->pdata;
+       }
+
+       headset->pdata = pdata;
        headset->headset_status = HEADSET_OUT;
        headset->hook_status = HOOK_UP;
        headset->isHook_irq = disable;
@@ -443,17 +395,11 @@ static int rockchip_headsetobserve_probe(struct platform_device *pdev)
        mutex_init(&headset->mutex_lock[HOOK]);
        
        INIT_DELAYED_WORK(&headset->h_delayed_work[HEADSET], headsetobserve_work);
-       INIT_DELAYED_WORK(&headset->h_delayed_work[HOOK], Hook_work);
+       INIT_DELAYED_WORK(&headset->h_delayed_work[HOOK], hook_work);
 
-//     init_timer(&headset->headset_timer);
-//     headset->headset_timer.function = headset_timer_callback;
-//     headset->headset_timer.data = (unsigned long)headset;
-//     headset->headset_timer.expires = jiffies + 3000;
        headset->isMic = 0;
        setup_timer(&headset->headset_timer, headset_timer_callback, (unsigned long)headset);
-//     headset->headset_timer.expires = jiffies + 1000;
-//     add_timer(&headset->headset_timer);     
-       
+//------------------------------------------------------------------   
        // Create and register the input driver. 
        headset->input_dev = input_allocate_device();
        if (!headset->input_dev) {
@@ -462,8 +408,8 @@ static int rockchip_headsetobserve_probe(struct platform_device *pdev)
                goto failed_free;
        }       
        headset->input_dev->name = pdev->name;
-       headset->input_dev->open = rk_Hskey_open;
-       headset->input_dev->close = rk_Hskey_close;
+       headset->input_dev->open = rk_hskey_open;
+       headset->input_dev->close = rk_hskey_close;
        headset->input_dev->dev.parent = &pdev->dev;
        //input_dev->phys = KEY_PHYS_NAME;
        headset->input_dev->id.vendor = 0x0001;
@@ -475,22 +421,7 @@ static int rockchip_headsetobserve_probe(struct platform_device *pdev)
                dev_err(&pdev->dev, "failed to register input device\n");
                goto failed_free_dev;
        }
-
-
-//     headset->input_dev->keycode = headset->keycodes;
-//     headset->input_dev->keycodesize = sizeof(unsigned char);
-//     headset->input_dev->keycodemax = 2;
-       
-//     set_bit(KEY_MEDIA, headset->input_dev->keybit);
-//     clear_bit(0, headset->input_dev->keybit);
-       input_set_capability(headset->input_dev, EV_KEY, pdata->hook_key_code);
-//     input_set_capability(headset->input_dev, EV_SW, SW_HEADPHONE_INSERT);
-//     input_set_capability(headset->input_dev, EV_KEY, KEY_END);
-
-//     headset->input_dev->evbit[0] = BIT_MASK(EV_KEY);
-       
-       headset_info = headset;
-       schedule_delayed_work(&headset->h_delayed_work[HEADSET], msecs_to_jiffies(500));        
+       input_set_capability(headset->input_dev, EV_KEY,HOOK_KEY_CODE);
 
 #ifdef CONFIG_HAS_EARLYSUSPEND
        hs_early_suspend.suspend = NULL;
@@ -498,44 +429,40 @@ static int rockchip_headsetobserve_probe(struct platform_device *pdev)
        hs_early_suspend.level = ~0x0;
        register_early_suspend(&hs_early_suspend);
 #endif
-
        //------------------------------------------------------------------
-       if (pdata->Headset_gpio) {
-               ret = gpio_request(pdata->Headset_gpio, NULL);
-               if (ret) 
+       if (pdata->headset_gpio) {
+               if(!pdata->headset_gpio){
+                       dev_err(&pdev->dev,"failed init headset,please full hook_io_init function in board\n");
                        goto failed_free_dev;
-               gpio_pull_updown(pdata->Headset_gpio, PullDisable);
-               gpio_direction_input(pdata->Headset_gpio);
-               headset->irq[HEADSET] = gpio_to_irq(pdata->Headset_gpio);
+               }       
+
+               headset->irq[HEADSET] = gpio_to_irq(pdata->headset_gpio);
 
-               if(pdata->headset_in_type == HEADSET_IN_HIGH)
+               if(pdata->headset_insert_type == HEADSET_IN_HIGH)
                        headset->irq_type[HEADSET] = IRQF_TRIGGER_RISING;
                else
                        headset->irq_type[HEADSET] = IRQF_TRIGGER_FALLING;
                ret = request_irq(headset->irq[HEADSET], headset_interrupt, headset->irq_type[HEADSET], "headset_input", NULL);
                if (ret) 
                        goto failed_free_dev;
-               enable_irq_wake(headset->irq[HEADSET]);
+               if (pdata->headset_wakeup)
+                       enable_irq_wake(headset->irq[HEADSET]);
        }
        else
                goto failed_free_dev;
 //------------------------------------------------------------------
-       if (pdata->Hook_gpio) {
-               ret = gpio_request(pdata->Hook_gpio , NULL);
-               if (ret) 
-                       goto failed_free_dev;
-               gpio_pull_updown(pdata->Hook_gpio, PullDisable);
-               gpio_direction_input(pdata->Hook_gpio);
-               headset->irq[HOOK] = gpio_to_irq(pdata->Hook_gpio);
-               headset->irq_type[HOOK] = IRQF_TRIGGER_FALLING;
-       
-               ret = request_irq(headset->irq[HOOK], Hook_interrupt, headset->irq_type[HOOK] , "headset_hook", NULL);
+       if (pdata->hook_gpio) {
+               headset->irq[HOOK] = gpio_to_irq(pdata->hook_gpio);
+               headset->irq_type[HOOK] = pdata->hook_down_type == HOOK_DOWN_HIGH ? IRQF_TRIGGER_RISING : IRQF_TRIGGER_FALLING;
+                       
+               ret = request_irq(headset->irq[HOOK], hook_interrupt, headset->irq_type[HOOK] , "headset_hook", NULL);
                if (ret) 
                        goto failed_free_dev;
                disable_irq(headset->irq[HOOK]);
        }
 //------------------------------------------------------------------   
-
+       headset_info = headset;
+       schedule_delayed_work(&headset->h_delayed_work[HEADSET], msecs_to_jiffies(500));                
        return 0;       
        
 failed_free_dev:
@@ -547,39 +474,5 @@ failed_free:
        return ret;
 }
 
-static int rockchip_headsetobserve_suspend(struct platform_device *pdev, pm_message_t state)
-{
-       DBG("%s----%d\n",__FUNCTION__,__LINE__);
-       disable_irq(headset_info->irq[HEADSET]);
-       disable_irq(headset_info->irq[HOOK]);
 
-       return 0;
-}
 
-static int rockchip_headsetobserve_resume(struct platform_device *pdev)
-{
-       DBG("%s----%d\n",__FUNCTION__,__LINE__);        
-       enable_irq(headset_info->irq[HEADSET]);
-       enable_irq(headset_info->irq[HOOK]);
-       
-       return 0;
-}
-
-static struct platform_driver rockchip_headsetobserve_driver = {
-       .probe  = rockchip_headsetobserve_probe,
-//     .resume =       rockchip_headsetobserve_resume, 
-//     .suspend =      rockchip_headsetobserve_suspend,        
-       .driver = {
-               .name   = "rk_headsetdet",
-               .owner  = THIS_MODULE,
-       },
-};
-
-static int __init rockchip_headsetobserve_init(void)
-{
-       platform_driver_register(&rockchip_headsetobserve_driver);
-       return 0;
-}
-module_init(rockchip_headsetobserve_init);
-MODULE_DESCRIPTION("Rockchip Headset Driver");
-MODULE_LICENSE("GPL");