From: Deng BingX Date: Tue, 8 Mar 2011 01:22:39 +0000 (+0800) Subject: Audio: Headset detection. X-Git-Tag: 2.1b_release~1856 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=43c9d941d130245dd4c7412a80147577c2294ef4;p=kernel%2Fkernel-mfld-blackbay.git Audio: Headset detection. Change-Id: I8245b11b2df3af3f2a0bca3eec6c1c3d4bdb185b Signed-off-by: bdeng3X Reviewed-on: http://android.intel.com:8080/25152 Reviewed-by: buildbot Reviewed-by: Gross, Mark Tested-by: Gross, Mark --- diff --git a/arch/x86/platform/mrst/mrst.c b/arch/x86/platform/mrst/mrst.c index 72e748a..fad4b27 100644 --- a/arch/x86/platform/mrst/mrst.c +++ b/arch/x86/platform/mrst/mrst.c @@ -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); diff --git a/drivers/switch/Kconfig b/drivers/switch/Kconfig index 5238591..2d74e2b 100644 --- a/drivers/switch/Kconfig +++ b/drivers/switch/Kconfig @@ -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 diff --git a/drivers/switch/Makefile b/drivers/switch/Makefile index f7606ed..23d6a66 100644 --- a/drivers/switch/Makefile +++ b/drivers/switch/Makefile @@ -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 index 0000000..f302daa --- /dev/null +++ b/drivers/switch/switch_mid.c @@ -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 +#include +#include +#include +#include +#include +#include +#include +#include + +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");