asoc: swr-haptics: add control to set VMAX
Add control to set VMAX to adjust different vibrator setting from userspace. Change-Id: I7300e4f0ae57e403c8fc79db38598946289effb6 Signed-off-by: Meng Wang <mengw@codeaurora.org>
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
// SPDX-License-Identifier: GPL-2.0-only
|
// SPDX-License-Identifier: GPL-2.0-only
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2020, The Linux Foundation. All rights reserved.
|
* Copyright (c) 2020-2021, The Linux Foundation. All rights reserved.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <linux/device.h>
|
#include <linux/device.h>
|
||||||
@@ -77,6 +77,7 @@ struct swr_haptics_dev {
|
|||||||
struct regmap *regmap;
|
struct regmap *regmap;
|
||||||
struct swr_port port;
|
struct swr_port port;
|
||||||
struct regulator *vdd;
|
struct regulator *vdd;
|
||||||
|
u8 vmax;
|
||||||
};
|
};
|
||||||
|
|
||||||
static bool swr_hap_volatile_register(struct device *dev, unsigned int reg)
|
static bool swr_hap_volatile_register(struct device *dev, unsigned int reg)
|
||||||
@@ -169,6 +170,15 @@ static int hap_enable_swr_dac_port(struct snd_soc_dapm_widget *w,
|
|||||||
|
|
||||||
switch (event) {
|
switch (event) {
|
||||||
case SND_SOC_DAPM_PRE_PMU:
|
case SND_SOC_DAPM_PRE_PMU:
|
||||||
|
rc = regmap_write(swr_hap->regmap, SWR_VMAX_REG, swr_hap->vmax);
|
||||||
|
if (rc) {
|
||||||
|
dev_err(swr_hap->dev, "%s: SWR_VMAX update failed, rc=%d\n",
|
||||||
|
__func__, rc);
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
|
regmap_read(swr_hap->regmap, SWR_VMAX_REG, &val);
|
||||||
|
regmap_read(swr_hap->regmap, SWR_READ_DATA_REG, &val);
|
||||||
|
dev_dbg(swr_hap->dev, "%s: swr_vmax is set to 0x%x\n", __func__, val);
|
||||||
swr_device_wakeup_vote(swr_hap->swr_slave);
|
swr_device_wakeup_vote(swr_hap->swr_slave);
|
||||||
swr_connect_port(swr_hap->swr_slave, &port_id, num_port,
|
swr_connect_port(swr_hap->swr_slave, &port_id, num_port,
|
||||||
&ch_mask, &ch_rate, &num_ch, &port_type);
|
&ch_mask, &ch_rate, &num_ch, &port_type);
|
||||||
@@ -209,6 +219,39 @@ static int hap_enable_swr_dac_port(struct snd_soc_dapm_widget *w,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int haptics_vmax_get(struct snd_kcontrol *kcontrol,
|
||||||
|
struct snd_ctl_elem_value *ucontrol)
|
||||||
|
{
|
||||||
|
struct snd_soc_component *component =
|
||||||
|
snd_soc_kcontrol_component(kcontrol);
|
||||||
|
struct swr_haptics_dev *swr_hap =
|
||||||
|
snd_soc_component_get_drvdata(component);
|
||||||
|
|
||||||
|
pr_debug("%s: vmax %u\n", __func__, swr_hap->vmax);
|
||||||
|
ucontrol->value.integer.value[0] = swr_hap->vmax;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int haptics_vmax_put(struct snd_kcontrol *kcontrol,
|
||||||
|
struct snd_ctl_elem_value *ucontrol)
|
||||||
|
{
|
||||||
|
struct snd_soc_component *component =
|
||||||
|
snd_soc_kcontrol_component(kcontrol);
|
||||||
|
struct swr_haptics_dev *swr_hap =
|
||||||
|
snd_soc_component_get_drvdata(component);
|
||||||
|
|
||||||
|
swr_hap->vmax = ucontrol->value.integer.value[0];
|
||||||
|
pr_debug("%s: vmax %u\n", __func__, swr_hap->vmax);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static const struct snd_kcontrol_new haptics_snd_controls[] = {
|
||||||
|
SOC_SINGLE_EXT("Haptics Amplitude Step", SND_SOC_NOPM, 0, 100, 0,
|
||||||
|
haptics_vmax_get, haptics_vmax_put),
|
||||||
|
};
|
||||||
|
|
||||||
static const struct snd_soc_dapm_widget haptics_comp_dapm_widgets[] = {
|
static const struct snd_soc_dapm_widget haptics_comp_dapm_widgets[] = {
|
||||||
SND_SOC_DAPM_INPUT("HAP_IN"),
|
SND_SOC_DAPM_INPUT("HAP_IN"),
|
||||||
SND_SOC_DAPM_MIXER_E("SWR DAC_Port", SND_SOC_NOPM, 0, 0,
|
SND_SOC_DAPM_MIXER_E("SWR DAC_Port", SND_SOC_NOPM, 0, 0,
|
||||||
@@ -255,6 +298,8 @@ static const struct snd_soc_component_driver swr_haptics_component = {
|
|||||||
.name = "swr-haptics",
|
.name = "swr-haptics",
|
||||||
.probe = haptics_comp_probe,
|
.probe = haptics_comp_probe,
|
||||||
.remove = haptics_comp_remove,
|
.remove = haptics_comp_remove,
|
||||||
|
.controls = haptics_snd_controls,
|
||||||
|
.num_controls = ARRAY_SIZE(haptics_snd_controls),
|
||||||
.dapm_widgets = haptics_comp_dapm_widgets,
|
.dapm_widgets = haptics_comp_dapm_widgets,
|
||||||
.num_dapm_widgets = ARRAY_SIZE(haptics_comp_dapm_widgets),
|
.num_dapm_widgets = ARRAY_SIZE(haptics_comp_dapm_widgets),
|
||||||
.dapm_routes = haptics_comp_dapm_route,
|
.dapm_routes = haptics_comp_dapm_route,
|
||||||
@@ -321,6 +366,8 @@ static int swr_haptics_probe(struct swr_device *sdev)
|
|||||||
if (!swr_hap)
|
if (!swr_hap)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
||||||
|
/* VMAX default to 5V */
|
||||||
|
swr_hap->vmax = 100;
|
||||||
swr_hap->swr_slave = sdev;
|
swr_hap->swr_slave = sdev;
|
||||||
swr_hap->dev = &sdev->dev;
|
swr_hap->dev = &sdev->dev;
|
||||||
swr_set_dev_data(sdev, swr_hap);
|
swr_set_dev_data(sdev, swr_hap);
|
||||||
|
Reference in New Issue
Block a user