Files
kernel_xiaomi_sm8250/techpack/audio/asoc/codecs/rouleur/rouleur_slave.c
Michael Bestas 5850f8798e Merge tag 'LA.UM.9.15.r1-07300-KAMORTA.QSSI13.0' of https://git.codelinaro.org/clo/la/platform/vendor/opensource/audio-kernel into android13-4.19-kona
"LA.UM.9.15.r1-07300-KAMORTA.QSSI13.0"

* tag 'LA.UM.9.15.r1-07300-KAMORTA.QSSI13.0' of https://git.codelinaro.org/clo/la/platform/vendor/opensource/audio-kernel:
  ASoC: msm-pcm-q6-v2: Add dsp buf check
  ASoC: rouleur-mbhc: Enhance impedance calculation logic
  ASoC: rouleur-mbhc: Fix pop noise heard when headset insertion
  asoc: wsa881x: Fix to set the correct volume level
  soc: swr-mstr-ctrl: remove FIFO_Flush for overflow
  asoc: Add routing control for qrb5165 BT HFP usecase
  soc: swr-mstr: Store and compare dev_addr along with dev_num
  Asoc: fix integer overflow for long duration offload playback
  asoc: Correct the range of dev_token for usb headset.
  asoc: pcm-noirq: set substream state to disconnect when ssr happens
  soc: pinctrl-lpi-legacy : Add nullptr check
  asoc: msm-pcm-routing: Assign default topology when app_type is zero
  asoc: notify dp driver after disp codec probe
  asoc: codecs: fix race condition of core vote and reg access
  ASoC: wcd937x: Add check for ULP irrespective of the Class
  asoc: codecs: Add nullptr check
  ASoC: wcd937x: Update QCRG sequence for wcd937x
  asoc: changes to fix KW errors.
  asoc: changes to fix KW errors.
  ASoC: pcm-routing: Add WSA VI sense macro to support capture
  ASoC: wcd937x: Update EAR PA CnP FSM sequence
  soc: swr-mstr: update component and interrupt enable sequence
  ASoC: wcd937x: Update EAR PA CnP FSM sequence
  soc: add check condition before enabling irq
  ASoC: wcd937x: Add change for LDOL VOUT accuracy calibration
  ASoC: dsp: Synchronise adm commands
  ASoC: wcd937x: Add change to micbias reg for new tanggu fab id
  ASoC: wcd937x: Update register value for new fab id for tanggu
  dsp:q6afe: Resolve crash in q6afe_get_avcs_modules
  ASoC: wcd937x: Change resistor divider output for hph if fab id is enabled
  dsp: adm: add to check output/input channel value
  asoc: Parse wcd-datalane-mismatch property to update rx frame config for khaje
  asoc: wcd-cpe: Set the dma_mask for cpe_device
  asoc: Parse wcd-datalane-mismatch property to update rx frame config for khaje
  ASoC: msm8952: Defer until pcm voice probe done
  q6afe: Fix out of bound access of clkinfo_per_port
  asoc: Register CDC_DMA interface only if enabled
  config: sdm450: Disable CDC_DMA interfaces
  asoc: codecs: add null check before access
  asoc: fix KW issue of using uninitialized variable
  audio-kernel: enable wsa883x compilation on qrb5165
  ASoC: Enable wsa881x-temp-sensor for bengal
  ASoC: msm8952: avoid static route between cpu and codec dai
  asoc: codecs: Fix LPASS register access during bootup
  ASoC: wcd: Add check to stop invalid memory access
  afe: release codec port when afe starts failed
  ASoC: Changes to enable codec clk for wcd9335
  Asoc: check for invalid voice session id
  SoC: codecs: Fix slim_tx port configuration for wcd9335
  ASoC: Get the component handle for cpe and tasha
  ASoC: wcd937x: Change vbg fine voltage to 0.5V for wcd937x second source
  audio-kernel: enable wsa883x compilation on sxr2130
  dsp: fix out of bound access for cal_data size
  dsp: update size check for set/get VI param function
  config: sdm450: Disable TDM and AUXPCM interfaces
  asoc: msm_sdw: Revert adsp ready check for read/write
  ASoC: SDM660: Avoid static route between cpu and codec dai
  asoc: bolero: Update PCM_RATE based delay for amic
  ASoC: SDM660: Avoid static route between cpu and codec dai
  ASoC: Fix for SSR issue on msm8953
  ASoC: error check for backend index and MCLK src
  Asoc: sdm450: Add capture support for Multimedia10 FE
  asoc: add proxy ports for call screening in machine driver
  asoc: msm: Fix compilation error when enable TDM and disable MI2S
  Makefile: Correct TARGET_SUPPORT entry for qrb5165
  dsp: update size check for get VI param function
  asoc: codecs: add child devices after completing initialization
  asoc: bolero: Add core_vote before gfmux access
  dsp: Disable q6_pdr build for msm8937 and msm8953
  asoc: Fixed wsa881x codec machine driver callback
  asoc: codec: enable the cpe on tasha
  Use proper TARGET_SUPPORT entry for sxr2130
  asoc: wsa881x: Fix to set the correct volume level
  ASoC: ep92: Add external mclk support
  ASoC: msm: Add WCD interrupt config for SDA660
  dsp: Unload the BT modules when APR handle is NULL
  asoc: Update copy_to_user to requested buffer size
  ASoC: Audio bringup changes for msm8937_32go.
  asoc: Add check to handle negative value passed for num_app_cfg_type
  ASoC: QCS405: Additional TDM samplerates and channels
  asoc: qcs405: Add support for TDM interface
  asoc: Add support for QUAT and SEN TDM interface
  asoc: qcs405: Update clk src string from dts
  dsp: Add support to update and store clk src values
  dsp: afe topology deregister
  ASoC: qcs405: Add external mclk support
  ASoC: Add external mclk mixer support
  dsp: Fix improper mutex unlock in afe close
  ASoC: wsa883x: Handle PA_ERR interrupt on WSA speaker
  ASoC: Add support to send voice UI port id to afe
  Revert "dsp: avtimer: Add adsp ready check before accessing avtimer registers"
  asoc: wsa881x: Fix crash while capturing swr_slv codec dump
  dsp: add change to enable preemption at cal_utils_dealloc_cal
  asoc: msm_sdw: Handle locking for mclk enable flag
  asoc: codecs: sdm660_cdc: Fix LPASS register access during PDR
  ASoC: lagoon: add support for CPS speaker protection
  dsp: add change to enable preemption at cal_utils_dealloc_cal
  ASoC: tx-macro: Allow regcache sync during clock enablement
  ASoC: wsa883x: add function to get swr device number
  dsp: add change to handle use-after-free in cal_utils_is_cal_stale
  soc: swr-mstr: Check if fifo available before bulk write
  asoc: bolero: control wakeup of swr_tx during clock setup
  soc: swr-mstr: Resolve swr overflow, underflow errors for wsa
  soc: swr-mstr: Update soundwire state to SSR during UP
  dsp: add change to fix use-after-free issue
  asoc: msm-pcm-q6-v2: Update memset for period size
  asoc: va-macro: Allow swr switch at powerup/shutdown
  ASoC: SDM660: Avoid static route between cpu and codec dai
  soc: Synchronize RESET event and lpi ops in legacy driver
  ASoC: codec: Enable wcd-spi driver compilation
  asoc: wcd-spi: Set the dma_mask for spi_device
  ASoC: audio-ext-clk: Add pmi clk support for tasha
  asoc: add null check for pcm pointer of snd_pcm_volume
  dsp: add afe function to send cps configuration
  asoc: Add 32bit support in meta i2s
  asoc: va-macro: Update widget order for VA_MCLK and VA_SWR_PWR
  dsp: Add param header size based on the instance id support
  dsp: q6core: Check q6core avs state to be modules ready
  ASoC: dsp: Synchronise adm and rtac commands
  asoc: codecs: Add support to dump rouleur swr slave regs
  asoc: sdm660: Correct the dev_id for hdmi backend.
  Revert "ASoC: codecs: handle device disconnect during SSR/PDR"
  ASoC: wsa883x: Update register sequence to reduce CnP
  asoc: sdm660: add proxy ports for call screening in machine driver
  soc: swr-mstr: Fix headset detect issue due to master.num_dev not updated
  soc: swr-mstr: Fix random headset detection issue on scuba
  dsp: Feedback path cfg to support 3rd party spkr protection algorithms.
  ASOC: SPV4 set correct number of speakers.
  ASoC: wsa883x: enable vbat adc filter
  config: kona: Disable MI2S, TDM and AUXPCM interfaces
  dsp: fix compilation issue in q6lsm_callback function
  asoc: Register widgets and intercons only when supported
  soc: swr-mstr: Fix random headset detection issue on scuba
  ASoC: codecs: handle device disconnect during SSR
  asoc: dsp: Fix possible invalid memory access due to race condition
  ASoC: rouleur-mbhc: Fix impedance detection issue on rouleur
  dsp: Add support for GET_PARAMS

 Conflicts:
	techpack/audio/asoc/kona.c
	techpack/audio/asoc/msm-pcm-routing-v2.c
	techpack/audio/dsp/q6core.c
	techpack/audio/dsp/q6lsm.c
	techpack/audio/include/dsp/audio_cal_utils.h
	techpack/audio/soc/swr-mstr-ctrl.c
	techpack/audio/soc/swr-mstr-ctrl.h

Change-Id: Id77d1c17f36618427f929d7830200733a0e8b460
2023-04-01 01:07:23 +03:00

445 lines
9.9 KiB
C

// SPDX-License-Identifier: GPL-2.0-only
/*
* Copyright (c) 2020, The Linux Foundation. All rights reserved.
*/
#include <linux/module.h>
#include <linux/slab.h>
#include <linux/platform_device.h>
#include <linux/device.h>
#include <linux/kernel.h>
#include <linux/component.h>
#include <soc/soundwire.h>
#ifdef CONFIG_DEBUG_FS
#include <linux/debugfs.h>
#include <linux/uaccess.h>
#define SWR_SLV_MAX_REG_ADDR 0x2009
#define SWR_SLV_START_REG_ADDR 0x40
#define SWR_SLV_MAX_BUF_LEN 20
#define BYTES_PER_LINE 12
#define SWR_SLV_RD_BUF_LEN 8
#define SWR_SLV_WR_BUF_LEN 32
#define SWR_SLV_MAX_DEVICES 2
#endif /* CONFIG_DEBUG_FS */
struct rouleur_slave_priv {
struct swr_device *swr_slave;
#ifdef CONFIG_DEBUG_FS
struct dentry *debugfs_rouleur_dent;
struct dentry *debugfs_peek;
struct dentry *debugfs_poke;
struct dentry *debugfs_reg_dump;
unsigned int read_data;
#endif
};
#ifdef CONFIG_DEBUG_FS
static int codec_debug_open(struct inode *inode, struct file *file)
{
file->private_data = inode->i_private;
return 0;
}
static int get_parameters(char *buf, u32 *param1, int num_of_par)
{
char *token = NULL;
int base = 0, cnt = 0;
token = strsep(&buf, " ");
for (cnt = 0; cnt < num_of_par; cnt++) {
if (token) {
if ((token[1] == 'x') || (token[1] == 'X'))
base = 16;
else
base = 10;
if (kstrtou32(token, base, &param1[cnt]) != 0)
return -EINVAL;
token = strsep(&buf, " ");
} else {
return -EINVAL;
}
}
return 0;
}
static bool is_swr_slv_reg_readable(int reg)
{
int ret = true;
if (((reg > 0x46) && (reg < 0x4A)) ||
((reg > 0x4A) && (reg < 0x50)) ||
((reg > 0x55) && (reg < 0xD0)) ||
((reg > 0xD0) && (reg < 0xE0)) ||
((reg > 0xE0) && (reg < 0xF0)) ||
((reg > 0xF0) && (reg < 0x100)) ||
((reg > 0x105) && (reg < 0x120)) ||
((reg > 0x205) && (reg < 0x220)) ||
((reg > 0x305) && (reg < 0x320)) ||
((reg > 0x405) && (reg < 0x420)) ||
((reg > 0x128) && (reg < 0x130)) ||
((reg > 0x228) && (reg < 0x230)) ||
((reg > 0x328) && (reg < 0x330)) ||
((reg > 0x428) && (reg < 0x430)) ||
((reg > 0x138) && (reg < 0x205)) ||
((reg > 0x238) && (reg < 0x305)) ||
((reg > 0x338) && (reg < 0x405)) ||
((reg > 0x405) && (reg < 0xF00)) ||
((reg > 0xF05) && (reg < 0xF20)) ||
((reg > 0xF25) && (reg < 0xF30)) ||
((reg > 0xF35) && (reg < 0x2000)))
ret = false;
return ret;
}
static ssize_t rouleur_swrslave_reg_show(struct swr_device *pdev,
char __user *ubuf,
size_t count, loff_t *ppos)
{
int i, reg_val, len;
ssize_t total = 0;
char tmp_buf[SWR_SLV_MAX_BUF_LEN];
if (!ubuf || !ppos)
return 0;
for (i = (((int) *ppos/BYTES_PER_LINE) + SWR_SLV_START_REG_ADDR);
i <= SWR_SLV_MAX_REG_ADDR; i++) {
if (!is_swr_slv_reg_readable(i))
continue;
swr_read(pdev, pdev->dev_num, i, &reg_val, 1);
len = snprintf(tmp_buf, sizeof(tmp_buf), "0x%.3x: 0x%.2x\n", i,
(reg_val & 0xFF));
if (len < 0) {
pr_err("%s: fail to fill the buffer\n", __func__);
total = -EFAULT;
goto copy_err;
}
if (((total + len) >= count - 1) || (len < 0))
break;
if (copy_to_user((ubuf + total), tmp_buf, len)) {
pr_err("%s: fail to copy reg dump\n", __func__);
total = -EFAULT;
goto copy_err;
}
total += len;
*ppos += len;
}
copy_err:
*ppos = SWR_SLV_MAX_REG_ADDR * BYTES_PER_LINE;
return total;
}
static ssize_t codec_debug_dump(struct file *file, char __user *ubuf,
size_t count, loff_t *ppos)
{
struct swr_device *pdev;
if (!count || !file || !ppos || !ubuf)
return -EINVAL;
pdev = file->private_data;
if (!pdev)
return -EINVAL;
if (*ppos < 0)
return -EINVAL;
return rouleur_swrslave_reg_show(pdev, ubuf, count, ppos);
}
static ssize_t codec_debug_read(struct file *file, char __user *ubuf,
size_t count, loff_t *ppos)
{
char lbuf[SWR_SLV_RD_BUF_LEN];
struct swr_device *pdev = NULL;
struct rouleur_slave_priv *rouleur_slave = NULL;
if (!count || !file || !ppos || !ubuf)
return -EINVAL;
pdev = file->private_data;
if (!pdev)
return -EINVAL;
rouleur_slave = swr_get_dev_data(pdev);
if (!rouleur_slave)
return -EINVAL;
if (*ppos < 0)
return -EINVAL;
snprintf(lbuf, sizeof(lbuf), "0x%x\n",
(rouleur_slave->read_data & 0xFF));
return simple_read_from_buffer(ubuf, count, ppos, lbuf,
strnlen(lbuf, 7));
}
static ssize_t codec_debug_peek_write(struct file *file,
const char __user *ubuf, size_t cnt, loff_t *ppos)
{
char lbuf[SWR_SLV_WR_BUF_LEN];
int rc = 0;
u32 param[5];
struct swr_device *pdev = NULL;
struct rouleur_slave_priv *rouleur_slave = NULL;
if (!cnt || !file || !ppos || !ubuf)
return -EINVAL;
pdev = file->private_data;
if (!pdev)
return -EINVAL;
rouleur_slave = swr_get_dev_data(pdev);
if (!rouleur_slave)
return -EINVAL;
if (*ppos < 0)
return -EINVAL;
if (cnt > sizeof(lbuf) - 1)
return -EINVAL;
rc = copy_from_user(lbuf, ubuf, cnt);
if (rc)
return -EFAULT;
lbuf[cnt] = '\0';
rc = get_parameters(lbuf, param, 1);
if (!((param[0] <= SWR_SLV_MAX_REG_ADDR) && (rc == 0)))
return -EINVAL;
swr_read(pdev, pdev->dev_num, param[0], &rouleur_slave->read_data, 1);
if (rc == 0)
rc = cnt;
else
pr_err("%s: rc = %d\n", __func__, rc);
return rc;
}
static ssize_t codec_debug_write(struct file *file,
const char __user *ubuf, size_t cnt, loff_t *ppos)
{
char lbuf[SWR_SLV_WR_BUF_LEN];
int rc = 0;
u32 param[5];
struct swr_device *pdev;
if (!file || !ppos || !ubuf)
return -EINVAL;
pdev = file->private_data;
if (!pdev)
return -EINVAL;
if (cnt > sizeof(lbuf) - 1)
return -EINVAL;
rc = copy_from_user(lbuf, ubuf, cnt);
if (rc)
return -EFAULT;
lbuf[cnt] = '\0';
rc = get_parameters(lbuf, param, 2);
if (!((param[0] <= SWR_SLV_MAX_REG_ADDR) &&
(param[1] <= 0xFF) && (rc == 0)))
return -EINVAL;
swr_write(pdev, pdev->dev_num, param[0], &param[1]);
if (rc == 0)
rc = cnt;
else
pr_err("%s: rc = %d\n", __func__, rc);
return rc;
}
static const struct file_operations codec_debug_write_ops = {
.open = codec_debug_open,
.write = codec_debug_write,
};
static const struct file_operations codec_debug_read_ops = {
.open = codec_debug_open,
.read = codec_debug_read,
.write = codec_debug_peek_write,
};
static const struct file_operations codec_debug_dump_ops = {
.open = codec_debug_open,
.read = codec_debug_dump,
};
#endif
static int rouleur_slave_bind(struct device *dev,
struct device *master, void *data)
{
int ret = 0;
uint8_t devnum = 0;
struct swr_device *pdev = to_swr_device(dev);
if (pdev == NULL) {
dev_err(dev, "%s: pdev is NULL\n", __func__);
return -EINVAL;
}
ret = swr_get_logical_dev_num(pdev, pdev->addr, &devnum);
if (ret) {
dev_dbg(&pdev->dev,
"%s get devnum %d for dev addr %lx failed\n",
__func__, devnum, pdev->addr);
swr_remove_device(pdev);
return ret;
}
pdev->dev_num = devnum;
return ret;
}
static void rouleur_slave_unbind(struct device *dev,
struct device *master, void *data)
{
struct rouleur_slave_priv *rouleur_slave = NULL;
struct swr_device *pdev = to_swr_device(dev);
if (pdev == NULL) {
dev_err(dev, "%s: pdev is NULL\n", __func__);
return;
}
rouleur_slave = swr_get_dev_data(pdev);
if (!rouleur_slave) {
dev_err(&pdev->dev, "%s: rouleur_slave is NULL\n", __func__);
return;
}
}
static const struct swr_device_id rouleur_swr_id[] = {
{"rouleur-slave", 0},
{}
};
static const struct of_device_id rouleur_swr_dt_match[] = {
{
.compatible = "qcom,rouleur-slave",
},
{}
};
static const struct component_ops rouleur_slave_comp_ops = {
.bind = rouleur_slave_bind,
.unbind = rouleur_slave_unbind,
};
static int rouleur_swr_up(struct swr_device *pdev)
{
return 0;
}
static int rouleur_swr_down(struct swr_device *pdev)
{
return 0;
}
static int rouleur_swr_reset(struct swr_device *pdev)
{
return 0;
}
static int rouleur_swr_probe(struct swr_device *pdev)
{
struct rouleur_slave_priv *rouleur_slave = NULL;
rouleur_slave = devm_kzalloc(&pdev->dev,
sizeof(struct rouleur_slave_priv), GFP_KERNEL);
if (!rouleur_slave)
return -ENOMEM;
swr_set_dev_data(pdev, rouleur_slave);
rouleur_slave->swr_slave = pdev;
#ifdef CONFIG_DEBUG_FS
if (!rouleur_slave->debugfs_rouleur_dent) {
rouleur_slave->debugfs_rouleur_dent = debugfs_create_dir(
dev_name(&pdev->dev), 0);
if (!IS_ERR(rouleur_slave->debugfs_rouleur_dent)) {
rouleur_slave->debugfs_peek =
debugfs_create_file("swrslave_peek",
S_IFREG | 0444,
rouleur_slave->debugfs_rouleur_dent,
(void *) pdev,
&codec_debug_read_ops);
rouleur_slave->debugfs_poke =
debugfs_create_file("swrslave_poke",
S_IFREG | 0444,
rouleur_slave->debugfs_rouleur_dent,
(void *) pdev,
&codec_debug_write_ops);
rouleur_slave->debugfs_reg_dump =
debugfs_create_file(
"swrslave_reg_dump",
S_IFREG | 0444,
rouleur_slave->debugfs_rouleur_dent,
(void *) pdev,
&codec_debug_dump_ops);
}
}
#endif
return component_add(&pdev->dev, &rouleur_slave_comp_ops);
}
static int rouleur_swr_remove(struct swr_device *pdev)
{
#ifdef CONFIG_DEBUG_FS
struct rouleur_slave_priv *rouleur_slave = swr_get_dev_data(pdev);
if (rouleur_slave) {
debugfs_remove_recursive(rouleur_slave->debugfs_rouleur_dent);
rouleur_slave->debugfs_rouleur_dent = NULL;
}
#endif
component_del(&pdev->dev, &rouleur_slave_comp_ops);
swr_set_dev_data(pdev, NULL);
swr_remove_device(pdev);
return 0;
}
static struct swr_driver rouleur_slave_driver = {
.driver = {
.name = "rouleur-slave",
.owner = THIS_MODULE,
.of_match_table = rouleur_swr_dt_match,
},
.probe = rouleur_swr_probe,
.remove = rouleur_swr_remove,
.id_table = rouleur_swr_id,
.device_up = rouleur_swr_up,
.device_down = rouleur_swr_down,
.reset_device = rouleur_swr_reset,
};
static int __init rouleur_slave_init(void)
{
return swr_driver_register(&rouleur_slave_driver);
}
static void __exit rouleur_slave_exit(void)
{
swr_driver_unregister(&rouleur_slave_driver);
}
module_init(rouleur_slave_init);
module_exit(rouleur_slave_exit);
MODULE_DESCRIPTION("Rouleur Swr Slave driver");
MODULE_LICENSE("GPL v2");