phonepad:add modem_sound and headset
authorroot <root@hzf-HP-Compaq-dx7518-MT.(none)>
Thu, 23 May 2013 03:21:54 +0000 (11:21 +0800)
committerroot <root@hzf-HP-Compaq-dx7518-MT.(none)>
Thu, 23 May 2013 03:22:52 +0000 (11:22 +0800)
drivers/headset_observe/rk_headset.c
drivers/headset_observe/rk_headset.h
drivers/misc/Kconfig
drivers/misc/modem_sound.c
drivers/misc/modem_sound.h

index bb1653b290f2970c7418c12de7199af5ef33c2de..8a017e662f1488cb435dd080fcb9f2d4633a948b 100755 (executable)
@@ -61,7 +61,7 @@
 #define enable 1
 #define disable 0
 
-#ifdef CONFIG_SND_RK_SOC_RK2928
+#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
@@ -88,6 +88,24 @@ struct headset_priv {
 };
 static struct headset_priv *headset_info;
 
+#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->Sw_mic_gpio, headset_info->pdata->Hp_mic_io_value);
+       else if(value == MAIN_MIC)
+               gpio_set_value(headset_info->pdata->Sw_mic_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->Sw_mic_gpio, headset_info->pdata->Hp_mic_io_value);
+       else
+               gpio_set_value(headset_info->pdata->Sw_mic_gpio,headset_info->pdata->Main_mic_io_value);
+}
+#endif
 int Headset_isMic(void)
 {
        return headset_info->isMic;
@@ -143,6 +161,7 @@ static irqreturn_t Hook_interrupt(int irq, void *dev_id)
 static void headsetobserve_work(struct work_struct *work)
 {
        int level = 0;
+       int level2 = 0;
        struct rk_headset_pdata *pdata = headset_info->pdata;
        static unsigned int old_status = 0;
        DBG("---headsetobserve_work---\n");
@@ -151,7 +170,12 @@ static void headsetobserve_work(struct work_struct *work)
        level = read_gpio(pdata->Headset_gpio);
        if(level < 0)
                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;
        if(pdata->headset_in_type == HEADSET_IN_HIGH)
                headset_info->headset_status = level?HEADSET_IN:HEADSET_OUT;
@@ -190,8 +214,8 @@ static void headsetobserve_work(struct work_struct *work)
                        headset_info->isHook_irq = disable;
                        disable_irq(headset_info->irq[HOOK]);           
                }       
-               headset_info->cur_headset_status = ~(BIT_HEADSET|BIT_HEADSET_NO_MIC);
-               //#ifdef CONFIG_SND_RK_SOC_RK2928
+               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_in_type == HEADSET_IN_HIGH)
@@ -201,11 +225,12 @@ static void headsetobserve_work(struct work_struct *work)
        }
        rk28_send_wakeup_key();
        switch_set_state(&headset_info->sdev, headset_info->cur_headset_status);        
-       #ifdef CONFIG_SND_RK_SOC_RK2928
+       #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);
@@ -316,9 +341,11 @@ static void headset_timer_callback(unsigned long arg)
                headset->isMic= 0;//No microphone
                
        printk("headset->isMic = %d\n",headset->isMic); 
-       headset_info->cur_headset_status = headset_info->isMic ? BIT_HEADSET:BIT_HEADSET_NO_MIC;
-       #ifdef CONFIG_SND_RK_SOC_RK2928
+       headset_info->cur_headset_status = headset_info->isMic ? 1:3;//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);
index f3e15094d38d64cd06f799ac2218b9674c03983a..6c5d7a6f1dca6150ca5a63d7a6417cfc496a66fe 100755 (executable)
@@ -15,6 +15,9 @@ struct io_info{
 
 struct rk_headset_pdata{
        unsigned int Hook_gpio;//Detection Headset--Must be set
+       unsigned int Sw_mic_gpio;
+       unsigned int Hp_mic_io_value;
+       unsigned int Main_mic_io_value;
        unsigned int Hook_adc_chn; //adc channel
        unsigned int Hook_down_type; //Hook key down status   
        int     hook_key_code;
index 9a4ee8cfb9d61d55e078630d59c1546aa6dafe31..3034dceb187de6dff10d48df758d1f2f9eac35ad 100755 (executable)
@@ -552,6 +552,10 @@ config TDSC8800
 config MODEM_SOUND
        bool "modem sound control driver"
        default n
+config MODEM_MIC_SWITCH
+       bool "3g modem mic switch control"
+       depends on MODEM_SOUND
+       default n
        
 config TCC_BT_DEV
        tristate "TCC Bluetooth dev Control power"
index f273f46b26b2739708dcade903c3f521a4046555..41ff7c3e8e1678243e53cd1079d87f8b35e788be 100755 (executable)
@@ -26,6 +26,28 @@ static struct modem_sound_data *modem_sound;
 #if defined(CONFIG_SND_RK_SOC_RK2928)|| defined(CONFIG_SND_RK29_SOC_RK610)\r
 extern void call_set_spk(int on);\r
 #endif\r
+#define HP_MIC 0\r
+#define MAIN_MIC 1\r
+#if defined(CONFIG_MODEM_MIC_SWITCH)\r
+extern void Modem_Mic_switch(int value);\r
+extern void Modem_Mic_release(void);\r
+void Modem_Sound_Mic_switch(int value)\r
+{\r
+       Modem_Mic_switch(value);\r
+}\r
+void Modem_Sound_Mic_release()\r
+{\r
+       Modem_Mic_release();\r
+}\r
+#else\r
+void Modem_Sound_Mic_switch(int value)\r
+{\r
+}\r
+void Modem_Sound_Mic_release()\r
+{\r
+}\r
+#endif\r
+\r
 int modem_sound_spkctl(int status)\r
 {\r
        if(status == ENABLE)\r
@@ -78,16 +100,19 @@ static long modem_sound_ioctl(struct file *filp, unsigned int cmd, unsigned long
        switch (cmd){\r
                case IOCTL_MODEM_EAR_PHOEN:\r
                        DBG("modem_sound_ioctl: MODEM_EAR_PHONE\n");\r
+                       Modem_Sound_Mic_switch(MAIN_MIC);\r
                        call_set_spk(3);\r
                        modem_sound_spkctl(DISABLE);\r
                        break;\r
                case IOCTL_MODEM_SPK_PHONE:\r
                        DBG("modem_sound_ioctl: MODEM_SPK_PHONE\n");\r
+                       Modem_Sound_Mic_switch(MAIN_MIC);\r
                        call_set_spk(1);\r
                        modem_sound_spkctl(ENABLE);\r
                        break;\r
-               case IOCTL_MODEM_HP_PHONE:\r
-                       DBG("modem_sound_ioctl: MODEM_HP_PHONE\n");\r
+               case IOCTL_MODEM_HP_WITHMIC_PHONE:\r
+                       DBG("modem_sound_ioctl: MODEM_HP_WITHMIC_PHONE\n");\r
+                       Modem_Sound_Mic_switch(HP_MIC);\r
                        call_set_spk(2);\r
                        modem_sound_spkctl(DISABLE);\r
                        break;\r
@@ -99,8 +124,17 @@ static long modem_sound_ioctl(struct file *filp, unsigned int cmd, unsigned long
                        break;\r
                case IOCTL_MODEM_STOP_PHONE:\r
                        DBG("modem_sound_ioctl: MODEM_STOP_PHONE\n");\r
+                       Modem_Sound_Mic_release();\r
                        call_set_spk(0);\r
+                       modem_sound_spkctl(ENABLE);\r
                        break;\r
+               case IOCTL_MODEM_HP_NOMIC_PHONE:\r
+                        DBG("modem_sound_ioctl: MODEM_HP_NOMIC_PHONE\n");\r
+                       Modem_Sound_Mic_switch(MAIN_MIC);\r
+                        call_set_spk(2);\r
+                        modem_sound_spkctl(DISABLE);\r
+                        break;\r
+\r
 \r
                default:\r
                        printk("unknown ioctl cmd!\n");\r
index 6de17fd20c354a45cb3decb056e03ad3bb5215e1..c3985661346c63d70fbe2aab0435d8fd5fd1f859 100755 (executable)
@@ -7,14 +7,16 @@
 \r
 #define IOCTL_MODEM_EAR_PHOEN                  _IO(MODEM_SOUND, 0x01)\r
 #define IOCTL_MODEM_SPK_PHONE                  _IO(MODEM_SOUND, 0x02) \r
-#define IOCTL_MODEM_HP_PHONE                   _IO(MODEM_SOUND, 0x03)\r
+#define IOCTL_MODEM_HP_WITHMIC_PHONE                   _IO(MODEM_SOUND, 0x03)\r
 #define IOCTL_MODEM_BT_PHONE                   _IO(MODEM_SOUND, 0x04)\r
 #define IOCTL_MODEM_STOP_PHONE             _IO(MODEM_SOUND, 0x05) \r
+#define IOCTL_MODEM_HP_NOMIC_PHONE             _IO(MODEM_SOUND, 0x06) \r
 \r
 #define IOCTL_SET_EAR_VALUME               _IO(MODEM_SOUND, 0x11) \r
 #define IOCTL_SET_SPK_VALUME               _IO(MODEM_SOUND, 0x12) \r
-#define IOCTL_SET_HP_VALUME                _IO(MODEM_SOUND, 0x13) \r
+#define IOCTL_SET_HP_WITHMIC_VALUME                _IO(MODEM_SOUND, 0x13) \r
 #define IOCTL_SET_BT_VALUME                _IO(MODEM_SOUND, 0x14) \r
+#define IOCTL_SET_HP_NOMIC_PHONE            _IO(MODEM_SOUND, 0x15)\r
  \r
 \r
 struct modem_sound_data {\r