mfd: cpcap-3mm5: Improve support for Apple 3 button headsets
authorGreg Meiste <w30289@motorola.com>
Tue, 4 Jan 2011 17:42:42 +0000 (11:42 -0600)
committerRebecca Schultz Zavin <rebecca@android.com>
Thu, 6 Jan 2011 23:13:39 +0000 (15:13 -0800)
Previously when an Apple 3 button headset was inserted, the driver would
report the MEDIA key as always pressed.  When the volume keys were pressed,
a release was reported, and when the key was actually released, a press
was reported again.

This patch improves Apple headset support by sending the MEDIA key
press and releases correctly based on whether the volume key is actually
pressed or released.  The 3 buttons are still treated the same due to
hardware limitations.

Change-Id: I8bcc59f95f40a8c98e3748d90e257ea1ec0eeaf5
Signed-off-by: Greg Meiste <w30289@motorola.com>
drivers/mfd/cpcap-3mm5.c

index 709e415ede7c274a08b2d8ee31eaf874a8ddbe7e..088230563775562a3d8094bea8bf516e064b1f69 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2009 Motorola, Inc.
+ * Copyright (C) 2009-2011 Motorola, Inc.
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License version 2 as
@@ -40,6 +40,7 @@ struct cpcap_3mm5_data {
        struct cpcap_device *cpcap;
        struct switch_dev sdev;
        unsigned int key_state;
+       unsigned int mb2_idle;
        struct regulator *regulator;
        unsigned char audio_low_pwr_det;
        unsigned char audio_low_pwr_mac13;
@@ -132,8 +133,11 @@ static void hs_handler(enum cpcap_irqs irq, void *data)
                        /* Headset without mic and MFB is detected. (May also
                         * be a headset with the MFB pressed.) */
                        new_state = HEADSET_WITHOUT_MIC;
-               } else
+               } else {
                        new_state = HEADSET_WITH_MIC;
+                       data_3mm5->mb2_idle = cpcap_irq_sense(data_3mm5->cpcap,
+                                                             CPCAP_IRQ_MB2, 1);
+               }
 
                cpcap_irq_clear(data_3mm5->cpcap, CPCAP_IRQ_MB2);
                cpcap_irq_clear(data_3mm5->cpcap, CPCAP_IRQ_UC_PRIMACRO_5);
@@ -166,7 +170,7 @@ static void mb2_handler(enum cpcap_irqs irq, void *data)
                return;
        }
 
-       send_key_event(data_3mm5, 1);
+       send_key_event(data_3mm5, (data_3mm5->mb2_idle ? 1 : 0));
        cpcap_irq_unmask(data_3mm5->cpcap, CPCAP_IRQ_MB2);
 }
 
@@ -183,7 +187,7 @@ static void mac5_handler(enum cpcap_irqs irq, void *data)
                return;
        }
 
-       send_key_event(data_3mm5, 0);
+       send_key_event(data_3mm5, (data_3mm5->mb2_idle ? 0 : 1));
        cpcap_irq_unmask(data_3mm5->cpcap, CPCAP_IRQ_UC_PRIMACRO_5);
 }
 
@@ -329,6 +333,6 @@ static void __exit cpcap_3mm5_exit(void)
 module_exit(cpcap_3mm5_exit);
 
 MODULE_ALIAS("platform:cpcap_3mm5");
-MODULE_DESCRIPTION("CPCAP USB detection driver");
+MODULE_DESCRIPTION("CPCAP 3.5mm detection driver");
 MODULE_AUTHOR("Motorola");
 MODULE_LICENSE("GPL");