Audio: Headset detection.
authorDeng BingX <bingx.deng@intel.com>
Tue, 8 Mar 2011 01:22:39 +0000 (09:22 +0800)
committerGross, Mark <mark.gross@intel.com>
Thu, 24 Nov 2011 13:01:22 +0000 (05:01 -0800)
Change-Id: I8245b11b2df3af3f2a0bca3eec6c1c3d4bdb185b
Signed-off-by: bdeng3X <bingx.deng@intel.com>
Reviewed-on: http://android.intel.com:8080/25152
Reviewed-by: buildbot <buildbot@intel.com>
Reviewed-by: Gross, Mark <mark.gross@intel.com>
Tested-by: Gross, Mark <mark.gross@intel.com>
arch/x86/platform/mrst/mrst.c
drivers/switch/Kconfig
drivers/switch/Makefile
drivers/switch/switch_mid.c [new file with mode: 0644]

index 72e748a..fad4b27 100644 (file)
@@ -1817,8 +1817,23 @@ static int __init sfi_parse_oemb(struct sfi_table_header *table)
                oemb->ifwi_minor_version);
        return 0;
 }
+
+#ifdef CONFIG_SWITCH_MID
+static struct platform_device switch_device = {
+       .name           = "switch-mid",
+       .id             = -1,
+};
+#endif
+
 static int __init mrst_platform_init(void)
 {
+#ifdef CONFIG_SWITCH_MID
+       int err;
+       err = platform_device_register(&switch_device);
+       if (err < 0)
+               pr_err("Fail to register switch-mid platform device.\n");
+#endif
+
        /* Get MFD Validation SFI OEMB Layout */
        sfi_table_parse(SFI_SIG_OEMB, NULL, NULL, sfi_parse_oemb);
        sfi_table_parse(SFI_SIG_GPIO, NULL, NULL, sfi_parse_gpio);
index 5238591..2d74e2b 100644 (file)
@@ -12,4 +12,9 @@ config SWITCH_GPIO
        help
          Say Y here to enable GPIO based switch support.
 
+config SWITCH_MID
+       tristate "MFLD Switch support"
+       help
+         Say Y here to support MFLD switch.
+
 endif # SWITCH
index f7606ed..23d6a66 100644 (file)
@@ -1,4 +1,5 @@
 # Switch Class Driver
 obj-$(CONFIG_SWITCH)           += switch_class.o
 obj-$(CONFIG_SWITCH_GPIO)      += switch_gpio.o
+obj-$(CONFIG_SWITCH_MID)       += switch_mid.o
 
diff --git a/drivers/switch/switch_mid.c b/drivers/switch/switch_mid.c
new file mode 100644 (file)
index 0000000..f302daa
--- /dev/null
@@ -0,0 +1,162 @@
+/*
+ *  drivers/switch/switch_mid.c
+ *
+ * Copyright (C) 2010 Intel.
+ *
+ * Based on drivers/switch/switch_gpio.c which from Google Android.
+ *
+ * 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 <linux/module.h>
+#include <linux/kernel.h>
+#include <linux/init.h>
+#include <linux/interrupt.h>
+#include <linux/platform_device.h>
+#include <linux/switch.h>
+#include <linux/workqueue.h>
+#include <linux/gpio.h>
+#include <linux/slab.h>
+
+struct mid_switch_data {
+       struct switch_dev sdev;
+};
+
+static char *name_hadsets_with_mic = "headsets_with_mic_insert";
+static char *name_hadsets_no_mic = "headsets_no_mic_insert";
+static char *name_hadsets_pull_out = "headsets_pull_out";
+static char *state_hadsets_with_mic = "1";
+static char *state_hadsets_no_mic = "2";
+static char *state_hadsets_pull_out = "0";
+
+static struct mid_switch_data *headset_switch_data;
+
+void mid_headset_report(int state)
+{
+       if (headset_switch_data)
+               switch_set_state(&headset_switch_data->sdev, state);
+}
+EXPORT_SYMBOL_GPL(mid_headset_report);
+
+static ssize_t headset_print_name(struct switch_dev *sdev, char *buf)
+{
+       const char *name;
+
+       if (!buf)
+               return -EINVAL;
+
+       switch (switch_get_state(sdev)) {
+       case 0:
+               name = name_hadsets_pull_out;
+               break;
+       case 1:
+               name = name_hadsets_with_mic;
+               break;
+       case 2:
+               name = name_hadsets_no_mic;
+               break;
+       default:
+               name = NULL;
+               break;
+       }
+
+       if (name)
+               return sprintf(buf, "%s\n", name);
+}
+
+static ssize_t headset_print_state(struct switch_dev *sdev, char *buf)
+{
+       const char *state;
+
+       if (!buf)
+               return -EINVAL;
+
+       switch (switch_get_state(sdev)) {
+       case 0:
+               state = state_hadsets_pull_out;
+               break;
+       case 1:
+               state = state_hadsets_with_mic;
+               break;
+       case 2:
+               state = state_hadsets_no_mic;
+               break;
+       default:
+               state = NULL;
+               break;
+       }
+
+       if (state)
+               return sprintf(buf, "%s\n", state);
+}
+
+static int mid_switch_probe(struct platform_device *pdev)
+{
+       struct mid_switch_data *switch_data;
+       int ret = 0;
+
+       switch_data = kzalloc(sizeof(struct mid_switch_data), GFP_KERNEL);
+       if (!switch_data)
+               return -ENOMEM;
+       headset_switch_data = switch_data;
+
+       switch_data->sdev.name = "h2w";
+       switch_data->sdev.print_name = headset_print_name;
+       switch_data->sdev.print_state = headset_print_state;
+
+       ret = switch_dev_register(&switch_data->sdev);
+       if (ret < 0)
+               goto err_switch_dev_register;
+
+       platform_set_drvdata(pdev, switch_data);
+       return 0;
+
+err_switch_dev_register:
+       kfree(switch_data);
+       return ret;
+}
+
+static int __devexit mid_switch_remove(struct platform_device *pdev)
+{
+       struct mid_switch_data *switch_data = platform_get_drvdata(pdev);
+
+       switch_dev_unregister(&switch_data->sdev);
+       kfree(switch_data);
+       headset_switch_data = NULL;
+
+       return 0;
+}
+
+static struct platform_driver mid_switch_driver = {
+       .probe          = mid_switch_probe,
+       .remove         = __devexit_p(mid_switch_remove),
+       .driver         = {
+               .name   = "switch-mid",
+               .owner  = THIS_MODULE,
+       },
+};
+
+static int __init mid_switch_init(void)
+{
+       return platform_driver_register(&mid_switch_driver);
+}
+
+static void __exit mid_switch_exit(void)
+{
+       platform_driver_unregister(&mid_switch_driver);
+}
+
+module_init(mid_switch_init);
+module_exit(mid_switch_exit);
+
+MODULE_AUTHOR("Deng, Bing (bingx.deng@intel.com)");
+MODULE_DESCRIPTION("Headset Switch driver");
+MODULE_LICENSE("GPL");