diff options
Diffstat (limited to 'sound/soc/codecs')
-rw-r--r-- | sound/soc/codecs/Kconfig | 6 | ||||
-rw-r--r-- | sound/soc/codecs/Makefile | 2 | ||||
-rw-r--r-- | sound/soc/codecs/tfa9890.c | 476 | ||||
-rw-r--r-- | sound/soc/codecs/tfa9890.h | 63 | ||||
-rw-r--r-- | sound/soc/codecs/wcd-mbhc-v2.c | 20 | ||||
-rw-r--r-- | sound/soc/codecs/wcd-mbhc-v2.h | 2 | ||||
-rw-r--r-- | sound/soc/codecs/wcd9335.c | 7 |
7 files changed, 568 insertions, 8 deletions
diff --git a/sound/soc/codecs/Kconfig b/sound/soc/codecs/Kconfig index 8f3e787501f1..edd84f0f9db3 100644 --- a/sound/soc/codecs/Kconfig +++ b/sound/soc/codecs/Kconfig @@ -994,6 +994,12 @@ config SND_SOC_MSM_HDMI_CODEC_RX HDMI audio drivers should be built only if the platform supports hdmi panel. +config NXP_TFA98xx + depends on I2C + tristate "NXP TFA98xx Support" + ---help--- + The NXP TFA98xx chip is used as a smart PA Controller. + source "sound/soc/codecs/sdm660_cdc/Kconfig" source "sound/soc/codecs/msm_sdw/Kconfig" diff --git a/sound/soc/codecs/Makefile b/sound/soc/codecs/Makefile index 5305cc6071e8..24d9c3b4106b 100644 --- a/sound/soc/codecs/Makefile +++ b/sound/soc/codecs/Makefile @@ -214,6 +214,7 @@ obj-$(CONFIG_SND_SOC_MSM_HDMI_CODEC_RX) := msm_hdmi_codec_rx.o snd-soc-max9877-objs := max9877.o snd-soc-tpa6130a2-objs := tpa6130a2.o snd-soc-tas2552-objs := tas2552.o +snd-soc-tfa98xx-objs := tfa9890.o obj-$(CONFIG_SND_SOC_88PM860X) += snd-soc-88pm860x.o obj-$(CONFIG_SND_SOC_AB8500_CODEC) += snd-soc-ab8500-codec.o @@ -425,5 +426,6 @@ obj-$(CONFIG_SND_SOC_MSM_STUB) += snd-soc-msm-stub.o # Amp obj-$(CONFIG_SND_SOC_MAX9877) += snd-soc-max9877.o obj-$(CONFIG_SND_SOC_TPA6130A2) += snd-soc-tpa6130a2.o +obj-$(CONFIG_NXP_TFA98xx) += snd-soc-tfa98xx.o obj-y += sdm660_cdc/ obj-y += msm_sdw/ diff --git a/sound/soc/codecs/tfa9890.c b/sound/soc/codecs/tfa9890.c new file mode 100644 index 000000000000..d5aa6975c453 --- /dev/null +++ b/sound/soc/codecs/tfa9890.c @@ -0,0 +1,476 @@ +/* + * Synaptics DSX touchscreen driver + * + * Copyright (C) 2012 Synaptics Incorporated + * + * Copyright (C) 2012 Alexandra Chin <alexandra.chin@tw.synaptics.com> + * Copyright (C) 2012 Scott Lin <scott.lin@tw.synaptics.com> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * 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/kernel.h> +#include <linux/module.h> +#include <linux/io.h> +#include <asm/uaccess.h> +#include <linux/fs.h> +#include <linux/slab.h> +#include <linux/init.h> +#include <linux/i2c.h> +#include <linux/i2c-dev.h> +#include <linux/interrupt.h> +#include <linux/delay.h> +#include <linux/input.h> +#include <linux/gpio.h> +#include <linux/miscdevice.h> +#include <linux/regulator/consumer.h> +#include <linux/of_gpio.h> +#include "tfa9890.h" +#ifdef KERNEL_ABOVE_2_6_38 +#include <linux/input/mt.h> +#endif + +#define DRIVER_NAME "tfa9890" +#define MAX_BUFFER_SIZE 512 +#define GPIO_SLEEP_LOW_US 10 +#define RESET_DELAY 500 + +struct tfa9890_dev { + wait_queue_head_t read_wq; + struct mutex read_mutex; + struct device *dev; + struct i2c_client *i2c_client; + struct miscdevice tfa9890_device; + unsigned int ven_gpio; + unsigned int firm_gpio; + unsigned int irq_gpio; + unsigned int irq_flags; + unsigned int irq; + unsigned int reset_gpio; + unsigned int reset_flags; + bool i2c_pull_up; + struct regulator *vdd; + struct regulator *vcc_i2c; + bool do_reading; + bool irq_enabled; + bool cancel_read; + bool first_open; +}; + +static ssize_t tfa9890_dev_read(struct file *filp, char __user *buf, + size_t count, loff_t *offset) +{ + struct tfa9890_dev *tfa9890_dev = filp->private_data; + char tmp[MAX_BUFFER_SIZE]; + int ret; + + if (count > MAX_BUFFER_SIZE) + count = MAX_BUFFER_SIZE; + + + mutex_lock(&tfa9890_dev->read_mutex); + + /* Read data */ + ret = i2c_master_recv(tfa9890_dev->i2c_client, tmp, count); + + if (ret < 0) { + pr_err("%s: i2c_master_recv returned %d\n", __func__, ret); + mutex_unlock(&tfa9890_dev->read_mutex); + return ret; + } + if (ret > count) { + pr_err("%s: received too many bytes from i2c (%d)\n", + __func__, ret); + mutex_unlock(&tfa9890_dev->read_mutex); + return -EIO; + } + + if (copy_to_user(buf, tmp, ret)) { + pr_warning("%s : failed to copy to user space\n", __func__); + mutex_unlock(&tfa9890_dev->read_mutex); + return -EFAULT; + } + mutex_unlock(&tfa9890_dev->read_mutex); + return ret; + +} + +static ssize_t tfa9890_dev_write(struct file *filp, const char __user *buf, + size_t count, loff_t *offset) +{ + struct tfa9890_dev *tfa9890_dev = filp->private_data; + char tmp[MAX_BUFFER_SIZE]; + int ret; + + if (count > MAX_BUFFER_SIZE) + count = MAX_BUFFER_SIZE; + + if (copy_from_user(tmp, buf, count)) { + pr_err("%s : failed to copy from user space\n", __func__); + return -EFAULT; + } + + /* Write data */ + ret = i2c_master_send(tfa9890_dev->i2c_client, tmp, count); + if (ret != count) { + pr_err("%s : i2c_master_send returned %d\n", __func__, ret); + ret = -EIO; + } + return ret; +} + +static int tfa9890_dev_open(struct inode *inode, struct file *filp) +{ + int ret; + + struct tfa9890_dev *tfa9890_dev = container_of(filp->private_data, + struct tfa9890_dev, + tfa9890_device); + + filp->private_data = tfa9890_dev; + pr_err("%s : %d,%d\n", __func__, imajor(inode), iminor(inode)); + + if (tfa9890_dev->first_open) { + if (gpio_is_valid(tfa9890_dev->reset_gpio)) { + /* configure tfa9890s reset out gpio */ + ret = gpio_request(tfa9890_dev->reset_gpio, + "tfa9890_reset_gpio"); + if (ret) { + dev_err(&tfa9890_dev->i2c_client->dev, "unable to request gpio [%d]\n", + tfa9890_dev->reset_gpio); + goto err_reset_gpio_dir; + } + + ret = gpio_direction_output(tfa9890_dev->reset_gpio, 1); + if (ret) { + dev_err(&tfa9890_dev->i2c_client->dev, + "unable to set direction for gpio [%d]\n", + tfa9890_dev->reset_gpio); + goto err_reset_gpio_dir; + } + + gpio_set_value(tfa9890_dev->reset_gpio, 1); + mdelay(GPIO_SLEEP_LOW_US); + gpio_set_value(tfa9890_dev->reset_gpio, 0); + mdelay(RESET_DELAY); + } + tfa9890_dev->first_open = false; + printk("%s enter, reset PA at first open\n", __func__); + } + + return 0; + +err_reset_gpio_dir: + if (gpio_is_valid(tfa9890_dev->reset_gpio)) + gpio_free(tfa9890_dev->reset_gpio); + + return ret; +} + +static long tfa9890_dev_ioctl(struct file *filp, + unsigned int cmd, unsigned long arg) +{ + struct tfa9890_dev *tfa9890_dev = filp->private_data; + switch(cmd) + { + case I2C_SLAVE: + { + tfa9890_dev->i2c_client->addr = arg; + break; + } + case ENABLE_MI2S_CLK: + { + udelay(500); + msm_q6_enable_mi2s_clocks(arg); + //printk("[%s][%d]\n",__func__,__LINE__); + break; + } + default: + break; + } + + return 0; +} + +static const struct file_operations tfa9890_dev_fops = { + .owner = THIS_MODULE, + .llseek = no_llseek, + .read = tfa9890_dev_read, + .write = tfa9890_dev_write, + .open = tfa9890_dev_open, + .unlocked_ioctl = tfa9890_dev_ioctl, +}; + +static int tfa9890_parse_dt(struct device *dev, + struct tfa9890_i2c_platform_data *pdata) +{ + int ret = 0; + struct device_node *np = dev->of_node; + + /* reset, irq gpio info */ + pdata->reset_gpio = of_get_named_gpio_flags(np, + "reset-gpio", 0, &pdata->reset_flags); + pr_info("%s,pdata->reset_gpio = %d\n", __func__, pdata->reset_gpio); + pdata->irq_gpio = of_get_named_gpio_flags(np, + "irq-gpio", 0, &pdata->irq_flags); + pr_info("%s,pdata->irq_gpio = %d\n", __func__, pdata->irq_gpio); + + pdata->i2c_pull_up = of_property_read_bool(np, + "tfa9890,i2c-pull-up"); + pr_info("%s,pdata->i2c_pull_up = %d\n", __func__, pdata->i2c_pull_up); + return ret; +} + + /** + * nxp_tfa9890_probe() + * + * Called by the kernel when an association with an I2C device of the + * same name is made (after doing i2c_add_driver). + * + * This funtion allocates and initializes the resources for the driver + * as an input driver, turns on the power to the sensor, queries the + * sensor for its supported Functions and characteristics, registers + * the driver to the input subsystem, sets up the interrupt, handles + * the registration of the early_suspend and late_resume functions, + * and creates a work queue for detection of other expansion Function + * modules. + */ +static int nxp_tfa9890_probe(struct i2c_client *client, + const struct i2c_device_id *dev_id) +{ + int ret = 0; + struct tfa9890_i2c_platform_data *platform_data; + struct tfa9890_dev *tfa9890_dev; + + printk("%s\n", __func__); + + if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) { + pr_err("%s: i2c check failed\n", __func__); + ret = -ENODEV; + goto err_i2c; + } + + if (client->dev.of_node) { + platform_data = devm_kzalloc(&client->dev, + sizeof(*platform_data), + GFP_KERNEL); + if (!platform_data) { + dev_err(&client->dev, "Failed to allocate memory\n"); + return -ENOMEM; + } + + ret = tfa9890_parse_dt(&client->dev, platform_data); + if (ret) + return ret; + } else { + platform_data = client->dev.platform_data; + } + + + tfa9890_dev = kzalloc(sizeof(*tfa9890_dev), GFP_KERNEL); + if (tfa9890_dev == NULL) { + pr_err("failed to allocate memory for module data\n"); + ret = -ENOMEM; + goto err_exit; + } + + tfa9890_dev->i2c_client = client; + tfa9890_dev->dev = &client->dev; + tfa9890_dev->do_reading = 0; + + /* Initialise mutex and work queue */ + init_waitqueue_head(&tfa9890_dev->read_wq); + mutex_init(&tfa9890_dev->read_mutex); + + tfa9890_dev->irq_enabled = false; + tfa9890_dev->tfa9890_device.minor = MISC_DYNAMIC_MINOR; + tfa9890_dev->tfa9890_device.name = "tfa9890"; + tfa9890_dev->tfa9890_device.fops = &tfa9890_dev_fops; + + if (gpio_is_valid(platform_data->reset_gpio)) { + /* configure tfa9890s reset out gpio */ + ret = gpio_request(platform_data->reset_gpio, + "tfa9890_reset_gpio"); + if (ret) { + dev_err(&client->dev, "unable to request gpio [%d]\n", + platform_data->reset_gpio); + goto err_reset_gpio_dir; + } + + ret = gpio_direction_output(platform_data->reset_gpio, 1); + if (ret) { + dev_err(&client->dev, + "unable to set direction for gpio [%d]\n", + platform_data->reset_gpio); + goto err_reset_gpio_dir; + } + + gpio_set_value(platform_data->reset_gpio, 1); + mdelay(GPIO_SLEEP_LOW_US); + gpio_set_value(platform_data->reset_gpio, 0); + mdelay(RESET_DELAY); + } + + ret = misc_register(&tfa9890_dev->tfa9890_device); + if (ret) { + pr_err("%s : misc_register failed\n", __FILE__); + goto err_misc_register; + } + + printk("%s Done\n", __func__); + + return 0; + +err_misc_register: + misc_deregister(&tfa9890_dev->tfa9890_device); + mutex_destroy(&tfa9890_dev->read_mutex); + kfree(tfa9890_dev); + +#if 1 +err_reset_gpio_dir: + if (gpio_is_valid(platform_data->reset_gpio)) + gpio_free(platform_data->reset_gpio); +#endif + +err_exit: +err_i2c: + kfree(platform_data); + + return ret; +} + + /** + * nxp_tfa9890_remove() + * + * Called by the kernel when the association with an I2C device of the + * same name is broken (when the driver is unloaded). + * + * This funtion terminates the work queue, stops sensor data acquisition, + * frees the interrupt, unregisters the driver from the input subsystem, + * turns off the power to the sensor, and frees other allocated resources. + */ +static int nxp_tfa9890_remove(struct i2c_client *client) +{ + struct tfa9890_dev *tfa9890_dev; + + pr_info("%s\n", __func__); + tfa9890_dev = i2c_get_clientdata(client); + misc_deregister(&tfa9890_dev->tfa9890_device); + mutex_destroy(&tfa9890_dev->read_mutex); + + kfree(tfa9890_dev); + + return 0; +} + +#ifdef CONFIG_PM + /** + * nxp_tfa9890_suspend() + * + * Called by the kernel during the suspend phase when the system + * enters suspend. + * + * This function stops finger data acquisition and puts the sensor to + * sleep (if not already done so during the early suspend phase), + * disables the interrupt, and turns off the power to the sensor. + */ +static int nxp_tfa9890_suspend(struct device *dev) +{ + pr_info(KERN_ALERT "----------------suspend"); + + return 0; +} + + /** + * nxp_tfa9890_resume() + * + * Called by the kernel during the resume phase when the system + * wakes up from suspend. + * + * This function turns on the power to the sensor, wakes the sensor + * from sleep, enables the interrupt, and starts finger data + * acquisition. + */ +static int nxp_tfa9890_resume(struct device *dev) +{ + return 0; +} + +static const struct dev_pm_ops nxp_tfa9890_dev_pm_ops = { + .suspend = nxp_tfa9890_suspend, + .resume = nxp_tfa9890_resume, +}; +#endif + +static const struct i2c_device_id nxp_tfa9890_id_table[] = { + {DRIVER_NAME, 0}, + {}, +}; +MODULE_DEVICE_TABLE(i2c, nxp_tfa9890_id_table); + +#ifdef CONFIG_OF +static struct of_device_id tfa9890_match_table[] = { + { .compatible = "nxp,tfa9890",}, + { }, +}; +#else +#define tfa9890_match_table NULL +#endif + +static struct i2c_driver nxp_tfa9890_driver = { + .driver = { + .name = DRIVER_NAME, + .owner = THIS_MODULE, + .of_match_table = tfa9890_match_table, +#ifdef CONFIG_PM + .pm = &nxp_tfa9890_dev_pm_ops, +#endif + }, + .probe = nxp_tfa9890_probe, + .remove =nxp_tfa9890_remove, + .id_table = nxp_tfa9890_id_table, +}; + + /** + * nxp_tfa9890_init() + * + * Called by the kernel during do_initcalls (if built-in) + * or when the driver is loaded (if a module). + * + * This function registers the driver to the I2C subsystem. + * + */ +static int __init nxp_tfa9890_init(void) +{ + printk("%s\n",__func__); + return i2c_add_driver(&nxp_tfa9890_driver); +} + + /** + * nxp_tfa9890_exit() + * + * Called by the kernel when the driver is unloaded. + * + * This funtion unregisters the driver from the I2C subsystem. + * + */ +static void __exit nxp_tfa9890_exit(void) +{ + i2c_del_driver(&nxp_tfa9890_driver); + + return; +} + +module_init(nxp_tfa9890_init); +module_exit(nxp_tfa9890_exit); + +MODULE_AUTHOR("NXP, Inc."); +MODULE_DESCRIPTION("NXP TFA9885 I2C Touch Driver"); +MODULE_LICENSE("GPL v2"); diff --git a/sound/soc/codecs/tfa9890.h b/sound/soc/codecs/tfa9890.h new file mode 100644 index 000000000000..14932a2e14e0 --- /dev/null +++ b/sound/soc/codecs/tfa9890.h @@ -0,0 +1,63 @@ +/* + * Synaptics DSX touchscreen driver + * + * Copyright (C) 2012 Synaptics Incorporated + * + * Copyright (C) 2012 Alexandra Chin <alexandra.chin@tw.synaptics.com> + * Copyright (C) 2012 Scott Lin <scott.lin@tw.synaptics.com> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * 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. + */ +#ifndef _NXP_TFA9890_I2C_H_ +#define _NXP_TFA9890_I2C_H_ + +#include <linux/version.h> +#ifdef CONFIG_HAS_EARLYSUSPEND +#include <linux/earlysuspend.h> +#endif + +#if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 38)) +#define KERNEL_ABOVE_2_6_38 +#endif + +#ifdef KERNEL_ABOVE_2_6_38 +#define sstrtoul(...) kstrtoul(__VA_ARGS__) +#else +#define sstrtoul(...) strict_strtoul(__VA_ARGS__) +#endif + +#define TFA9890_VTG_MIN_UV 1800000 +#define TFA9890_VTG_MAX_UV 1800000 +#define TFA9890_ACTIVE_LOAD_UA 10000 //15000 +#define TFA9890_LPM_LOAD_UA 10 + +#define TFA9890_I2C_VTG_MIN_UV 1800000 +#define TFA9890_I2C_VTG_MAX_UV 1800000 +#define TFA9890_I2C_LOAD_UA 10000 +#define TFA9890_I2C_LPM_LOAD_UA 10 + +extern int msm_q6_enable_mi2s_clocks(bool enable); + +struct tfa9890_i2c_platform_data { + struct i2c_client *i2c_client; + bool i2c_pull_up; + bool regulator_en; + u32 reset_flags; + u32 irq_flags; + unsigned int irq; + unsigned int reset_gpio_test; + unsigned int reset_gpio; + unsigned int irq_gpio; + int (*driver_opened)(void); + void (*driver_closed)(void); +}; + +#endif diff --git a/sound/soc/codecs/wcd-mbhc-v2.c b/sound/soc/codecs/wcd-mbhc-v2.c index dd4e3533a015..69b4c0ecd83f 100644 --- a/sound/soc/codecs/wcd-mbhc-v2.c +++ b/sound/soc/codecs/wcd-mbhc-v2.c @@ -45,7 +45,7 @@ #define MBHC_BUTTON_PRESS_THRESHOLD_MIN 250 #define GND_MIC_SWAP_THRESHOLD 4 #define WCD_FAKE_REMOVAL_MIN_PERIOD_MS 100 -#define HS_VREF_MIN_VAL 1400 +#define HS_VREF_MIN_VAL 1200 #define FW_READ_ATTEMPTS 15 #define FW_READ_TIMEOUT 4000000 #define FAKE_REM_RETRY_ATTEMPTS 3 @@ -533,6 +533,11 @@ static void wcd_mbhc_set_and_turnoff_hph_padac(struct wcd_mbhc *mbhc) WCD_MBHC_REG_READ(WCD_MBHC_HPH_CNP_WG_TIME, wg_time); wg_time += 1; + if (mbhc->mbhc_cfg->default_gnd_mic && + mbhc->mbhc_cfg->default_gnd_mic(mbhc->codec)) { + pr_debug("%s: US_EU gpio present,set to default switch\n" + , __func__); + } /* If headphone PA is on, check if userspace receives * removal event to sync-up PA's state */ @@ -1999,10 +2004,23 @@ static irqreturn_t wcd_mbhc_btn_press_handler(int irq, void *data) struct wcd_mbhc *mbhc = data; int mask; unsigned long msec_val; + unsigned long msec_delta; + static unsigned long msec_first = 0; pr_debug("%s: enter\n", __func__); complete(&mbhc->btn_press_compl); WCD_MBHC_RSC_LOCK(mbhc); + + msec_delta = jiffies_to_msecs(jiffies - msec_first); + if(msec_delta < 100){ + pr_err("%s:cancel repeat press,msec_delta = %ld\n", __func__,msec_delta); + goto done; + } + msec_first = jiffies; + + /* send event to sw intr handler*/ + mbhc->is_btn_press = true; + wcd_cancel_btn_work(mbhc); if (wcd_swch_level_remove(mbhc)) { pr_debug("%s: Switch level is low ", __func__); diff --git a/sound/soc/codecs/wcd-mbhc-v2.h b/sound/soc/codecs/wcd-mbhc-v2.h index 09b9307ad61d..4342a1b5122e 100644 --- a/sound/soc/codecs/wcd-mbhc-v2.h +++ b/sound/soc/codecs/wcd-mbhc-v2.h @@ -270,6 +270,7 @@ struct wcd_mbhc_config { bool detect_extn_cable; bool mono_stero_detection; bool (*swap_gnd_mic)(struct snd_soc_codec *codec); + bool (*default_gnd_mic)(struct snd_soc_codec *codec); bool hs_ext_micbias; bool gnd_det_en; int key_code[WCD_MBHC_KEYCODE_NUM]; @@ -280,6 +281,7 @@ struct wcd_mbhc_config { bool enable_anc_mic_detect; u32 enable_usbc_analog; struct usbc_ana_audio_config usbc_analog_cfg; + struct regulator *vdd; }; struct wcd_mbhc_intr { diff --git a/sound/soc/codecs/wcd9335.c b/sound/soc/codecs/wcd9335.c index bb99e98f34e2..bc82d70c2852 100644 --- a/sound/soc/codecs/wcd9335.c +++ b/sound/soc/codecs/wcd9335.c @@ -5948,13 +5948,6 @@ static int tasha_codec_enable_dec(struct snd_soc_dapm_widget *w, break; case SND_SOC_DAPM_POST_PMU: snd_soc_update_bits(codec, hpf_gate_reg, 0x01, 0x00); - - if (decimator == 0) { - snd_soc_write(codec, WCD9335_MBHC_ZDET_RAMP_CTL, 0x83); - snd_soc_write(codec, WCD9335_MBHC_ZDET_RAMP_CTL, 0xA3); - snd_soc_write(codec, WCD9335_MBHC_ZDET_RAMP_CTL, 0x83); - snd_soc_write(codec, WCD9335_MBHC_ZDET_RAMP_CTL, 0x03); - } /* schedule work queue to Remove Mute */ schedule_delayed_work(&tasha->tx_mute_dwork[decimator].dwork, msecs_to_jiffies(tx_unmute_delay)); |