mirror of
https://github.com/torvalds/linux.git
synced 2026-09-22 04:34:03 +02:00
ASoC: rt766: add RT766/RT767 SDCA driver
This patch adds the initial SDCA multi-function codec driver for the RT766 and RT767. Signed-off-by: Shuming Fan <shumingf@realtek.com> Reviewed-by: Charles Keepax <ckeepax@opensource.cirrus.com> Link: https://patch.msgid.link/20260804104828.557228-1-shumingf@realtek.com Signed-off-by: Mark Brown <broonie@kernel.org>
This commit is contained in:
parent
685e462ce9
commit
b50ecf5873
|
|
@ -238,6 +238,7 @@ config SND_SOC_ALL_CODECS
|
|||
imply SND_SOC_RT715_SDCA_SDW
|
||||
imply SND_SOC_RT721_SDCA_SDW
|
||||
imply SND_SOC_RT722_SDCA_SDW
|
||||
imply SND_SOC_RT766_SDCA_SDW
|
||||
imply SND_SOC_RT1308_SDW
|
||||
imply SND_SOC_RT1316_SDW
|
||||
imply SND_SOC_RT1318
|
||||
|
|
@ -1984,6 +1985,15 @@ config SND_SOC_RT715_SDCA_SDW
|
|||
select REGMAP_SOUNDWIRE
|
||||
select REGMAP_SOUNDWIRE_MBQ
|
||||
|
||||
config SND_SOC_RT766_SDCA_SDW
|
||||
tristate "Realtek RT766 SDCA Codec - SDW"
|
||||
depends on SOUNDWIRE
|
||||
depends on SND_SOC_SDCA
|
||||
select SND_SOC_SDCA_HID
|
||||
select SND_SOC_SDCA_IRQ
|
||||
select REGMAP_SOUNDWIRE
|
||||
select REGMAP_SOUNDWIRE_MBQ
|
||||
|
||||
config SND_SOC_RT9120
|
||||
tristate "Richtek RT9120 Stereo Class-D Amplifier"
|
||||
depends on I2C
|
||||
|
|
|
|||
|
|
@ -285,6 +285,7 @@ snd-soc-rt715-y := rt715.o rt715-sdw.o
|
|||
snd-soc-rt715-sdca-y := rt715-sdca.o rt715-sdca-sdw.o
|
||||
snd-soc-rt721-sdca-y := rt721-sdca.o rt721-sdca-sdw.o
|
||||
snd-soc-rt722-sdca-y := rt722-sdca.o rt722-sdca-sdw.o
|
||||
snd-soc-rt766-sdca-y := rt766-sdca.o rt766-sdca-sdw.o
|
||||
snd-soc-rt9120-y := rt9120.o
|
||||
snd-soc-rt9123-y := rt9123.o
|
||||
snd-soc-rt9123p-y := rt9123p.o
|
||||
|
|
@ -727,6 +728,7 @@ obj-$(CONFIG_SND_SOC_RT715) += snd-soc-rt715.o
|
|||
obj-$(CONFIG_SND_SOC_RT715_SDCA_SDW) += snd-soc-rt715-sdca.o
|
||||
obj-$(CONFIG_SND_SOC_RT721_SDCA_SDW) += snd-soc-rt721-sdca.o
|
||||
obj-$(CONFIG_SND_SOC_RT722_SDCA_SDW) += snd-soc-rt722-sdca.o
|
||||
obj-$(CONFIG_SND_SOC_RT766_SDCA_SDW) += snd-soc-rt766-sdca.o
|
||||
obj-$(CONFIG_SND_SOC_RT9120) += snd-soc-rt9120.o
|
||||
obj-$(CONFIG_SND_SOC_RT9123) += snd-soc-rt9123.o
|
||||
obj-$(CONFIG_SND_SOC_RT9123P) += snd-soc-rt9123p.o
|
||||
|
|
|
|||
339
sound/soc/codecs/rt766-sdca-sdw.c
Normal file
339
sound/soc/codecs/rt766-sdca-sdw.c
Normal file
|
|
@ -0,0 +1,339 @@
|
|||
// SPDX-License-Identifier: GPL-2.0-only
|
||||
//
|
||||
// rt766-sdca-sdw.c -- rt766 SDCA ALSA SoC audio driver
|
||||
//
|
||||
// Copyright(c) 2026 Realtek Semiconductor Corp.
|
||||
//
|
||||
//
|
||||
|
||||
#include <linux/delay.h>
|
||||
#include <linux/device.h>
|
||||
#include <linux/module.h>
|
||||
#include <linux/pm_runtime.h>
|
||||
#include <linux/soundwire/sdw_registers.h>
|
||||
#include <sound/sdca.h>
|
||||
#include <sound/sdca_function.h>
|
||||
#include "rt766-sdca.h"
|
||||
#include "rt766-sdca-sdw.h"
|
||||
|
||||
#define RT766_PROBE_TIMEOUT 5000
|
||||
|
||||
static bool rt766_sdca_readable_register(struct device *dev, unsigned int reg)
|
||||
{
|
||||
switch (reg) {
|
||||
case SDW_SCP_SDCA_INT1 ... SDW_SCP_SDCA_INTMASK4:
|
||||
case RT766_VERSION_ID ... RT766_BOND_LATCH_ID:
|
||||
case 0xc344 ... 0xc345:
|
||||
case 0xc900:
|
||||
case 0xc920:
|
||||
case 0xd540 ... 0xd542:
|
||||
case 0xf01e:
|
||||
case RT766_HP_POWER_STATE ... RT766_HP_FSM_CTL2_1:
|
||||
case 0x310100:
|
||||
case RT766_MCU_PATCH_ADDR1_START ... RT766_MCU_PATCH_ADDR1_END:
|
||||
case RT766_MCU_PATCH_ADDR2_START ... RT766_MCU_PATCH_ADDR2_END:
|
||||
case RT766_MUTE_REG(UAJ, USER_FU41, 1):
|
||||
case RT766_MUTE_REG(UAJ, USER_FU41, 2):
|
||||
case RT766_VOLUME_REG(UAJ, USER_FU41, 1):
|
||||
case RT766_VOLUME_REG(UAJ, USER_FU41, 2):
|
||||
case RT766_MUTE_REG(UAJ, USER_FU36, 1):
|
||||
case RT766_MUTE_REG(UAJ, USER_FU36, 2):
|
||||
case RT766_VOLUME_REG(UAJ, USER_FU36, 1):
|
||||
case RT766_VOLUME_REG(UAJ, USER_FU36, 2):
|
||||
case RT766_PDE_REQ_REG(UAJ, PDE47):
|
||||
case RT766_PDE_REQ_REG(UAJ, PDE34):
|
||||
case RT766_SDCA_CTL(UAJ, CS41, SDCA_CTL_CS_SAMPLERATEINDEX):
|
||||
case RT766_SDCA_CTL(UAJ, CS36, SDCA_CTL_CS_SAMPLERATEINDEX):
|
||||
case RT766_FUNC_STATUS_REG(UAJ): /* 0x40480000 */
|
||||
case RT766_PDE_ACTUAL_REG(UAJ, PDE47): /* 0x40481400 */
|
||||
case RT766_PDE_ACTUAL_REG(UAJ, PDE34): /* 0x40481480 */
|
||||
case RT766_GAIN_REG(UAJ, PLATFORM_FU33, 1):
|
||||
case RT766_GAIN_REG(UAJ, PLATFORM_FU33, 2):
|
||||
case RT766_SDCA_CTL(UAJ, GE49, SDCA_CTL_GE_SELECTED_MODE):
|
||||
case RT766_SDCA_CTL(UAJ, GE49, SDCA_CTL_GE_DETECTED_MODE): /* 0x40600490 */
|
||||
case RT766_PDE_REQ_REG(MIC, PDE11):
|
||||
case RT766_MUTE_REG(MIC, USER_FU113, 1):
|
||||
case RT766_MUTE_REG(MIC, USER_FU113, 2):
|
||||
case RT766_MUTE_REG(MIC, USER_FU113, 3):
|
||||
case RT766_MUTE_REG(MIC, USER_FU113, 4):
|
||||
case RT766_VOLUME_REG(MIC, USER_FU113, 1):
|
||||
case RT766_VOLUME_REG(MIC, USER_FU113, 2):
|
||||
case RT766_VOLUME_REG(MIC, USER_FU113, 3):
|
||||
case RT766_VOLUME_REG(MIC, USER_FU113, 4):
|
||||
case RT766_FUNC_STATUS_REG(MIC): /* 0x40880000 */
|
||||
case RT766_SDCA_CTL(MIC, CS113, SDCA_CTL_CS_SAMPLERATEINDEX):
|
||||
case RT766_PDE_ACTUAL_REG(MIC, PDE11): /* 0x40881500 */
|
||||
case RT766_FUNC_STATUS_REG(HID): /* 0x40c80000 */
|
||||
/* 0x40c80080 - 0x40c80098 */
|
||||
case RT766_SDCA_CTL(HID, HID101, SDCA_CTL_HIDE_HIDTX_CURRENTOWNER) ...
|
||||
RT766_SDCA_CTL(HID, HID101, SDCA_CTL_HIDE_HIDTX_MESSAGELENGTH):
|
||||
case RT766_MUTE_REG(AMP, USER_FU21, 1):
|
||||
case RT766_MUTE_REG(AMP, USER_FU21, 2):
|
||||
case RT766_VOLUME_REG(AMP, USER_FU21, 1):
|
||||
case RT766_VOLUME_REG(AMP, USER_FU21, 2):
|
||||
case RT766_PDE_REQ_REG(AMP, PDE23):
|
||||
case RT766_FUNC_STATUS_REG(AMP): /* 0x41080000 */
|
||||
case RT766_SDCA_CTL(AMP, PPU21, SDCA_CTL_PPU_POSTURENUMBER):
|
||||
case RT766_SDCA_CTL(AMP, CS21, SDCA_CTL_CS_SAMPLERATEINDEX):
|
||||
case RT766_PDE_ACTUAL_REG(AMP, PDE23): /* 0x41081980 */
|
||||
case RT766_BUF_ADDR_HID1 ... RT766_BUF_ADDR_HID2:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
static bool rt766_sdca_volatile_register(struct device *dev, unsigned int reg)
|
||||
{
|
||||
switch (reg) {
|
||||
case SDW_SCP_SDCA_INT1 ... SDW_SCP_SDCA_INTMASK4:
|
||||
case RT766_VERSION_ID ... RT766_BOND_LATCH_ID:
|
||||
case 0xc344 ... 0xc345:
|
||||
case 0xc900:
|
||||
case 0xc920:
|
||||
case 0xd540 ... 0xd542:
|
||||
case 0xf01e:
|
||||
case RT766_HP_POWER_STATE ... RT766_HP_FSM_CTL2_1:
|
||||
case 0x310100:
|
||||
case RT766_MCU_PATCH_ADDR1_START ... RT766_MCU_PATCH_ADDR1_END:
|
||||
case RT766_MCU_PATCH_ADDR2_START ... RT766_MCU_PATCH_ADDR2_END:
|
||||
case RT766_FUNC_STATUS_REG(UAJ):
|
||||
case RT766_PDE_ACTUAL_REG(UAJ, PDE47):
|
||||
case RT766_PDE_ACTUAL_REG(UAJ, PDE34):
|
||||
case RT766_SDCA_CTL(UAJ, GE49, SDCA_CTL_GE_DETECTED_MODE):
|
||||
case RT766_FUNC_STATUS_REG(MIC):
|
||||
case RT766_PDE_ACTUAL_REG(MIC, PDE11):
|
||||
case RT766_FUNC_STATUS_REG(HID):
|
||||
case RT766_SDCA_CTL(HID, HID101, SDCA_CTL_HIDE_HIDTX_CURRENTOWNER) ...
|
||||
RT766_SDCA_CTL(HID, HID101, SDCA_CTL_HIDE_HIDTX_MESSAGELENGTH):
|
||||
case RT766_FUNC_STATUS_REG(AMP):
|
||||
case RT766_PDE_ACTUAL_REG(AMP, PDE23):
|
||||
case RT766_BUF_ADDR_HID1 ... RT766_BUF_ADDR_HID2:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
static int rt766_sdca_mbq_size(struct device *dev, unsigned int reg)
|
||||
{
|
||||
switch (reg) {
|
||||
case RT766_VOLUME_REG(UAJ, USER_FU41, 1):
|
||||
case RT766_VOLUME_REG(UAJ, USER_FU41, 2):
|
||||
case RT766_VOLUME_REG(UAJ, USER_FU36, 1):
|
||||
case RT766_VOLUME_REG(UAJ, USER_FU36, 2):
|
||||
case RT766_GAIN_REG(UAJ, PLATFORM_FU33, 1):
|
||||
case RT766_GAIN_REG(UAJ, PLATFORM_FU33, 2):
|
||||
case RT766_VOLUME_REG(MIC, USER_FU113, 1):
|
||||
case RT766_VOLUME_REG(MIC, USER_FU113, 2):
|
||||
case RT766_VOLUME_REG(MIC, USER_FU113, 3):
|
||||
case RT766_VOLUME_REG(MIC, USER_FU113, 4):
|
||||
case RT766_VOLUME_REG(AMP, USER_FU21, 1):
|
||||
case RT766_VOLUME_REG(AMP, USER_FU21, 2):
|
||||
return 2;
|
||||
default:
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
static const struct regmap_sdw_mbq_cfg rt766_sdca_mbq_cfg = {
|
||||
.mbq_size = rt766_sdca_mbq_size,
|
||||
};
|
||||
|
||||
static const struct regmap_config rt766_sdca_regmap = {
|
||||
.reg_bits = 32,
|
||||
.val_bits = 16,
|
||||
.readable_reg = rt766_sdca_readable_register,
|
||||
.volatile_reg = rt766_sdca_volatile_register,
|
||||
.reg_defaults = rt766_sdca_defaults,
|
||||
.num_reg_defaults = ARRAY_SIZE(rt766_sdca_defaults),
|
||||
.max_register = SDW_SDCA_MAX_REGISTER,
|
||||
.cache_type = REGCACHE_MAPLE,
|
||||
.use_single_read = true,
|
||||
.use_single_write = true,
|
||||
};
|
||||
|
||||
static int rt766_sdca_update_status(struct sdw_slave *slave,
|
||||
enum sdw_slave_status status)
|
||||
{
|
||||
struct rt766_sdca_priv *rt766 = dev_get_drvdata(&slave->dev);
|
||||
|
||||
if (status == SDW_SLAVE_UNATTACHED)
|
||||
rt766->hw_init = false;
|
||||
|
||||
if (status == SDW_SLAVE_ATTACHED) {
|
||||
if (rt766->hs_jack) {
|
||||
/*
|
||||
* Due to the SCP_SDCA_INTMASK will be cleared by any reset, and then
|
||||
* if the device attached again, we will need to set the setting back.
|
||||
* It could avoid losing the jack detection interrupt.
|
||||
* This also could sync with the cache value as the rt766_sdca_jack_init set.
|
||||
*/
|
||||
sdw_write_no_pm(rt766->slave, SDW_SCP_SDCA_INTMASK3,
|
||||
SDW_SCP_SDCA_INTMASK_SDCA_16);
|
||||
sdw_write_no_pm(rt766->slave, SDW_SCP_SDCA_INTMASK4,
|
||||
SDW_SCP_SDCA_INTMASK_SDCA_24);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Perform initialization only if slave status is present and
|
||||
* hw_init flag is false
|
||||
*/
|
||||
if (rt766->hw_init || status != SDW_SLAVE_ATTACHED)
|
||||
return 0;
|
||||
|
||||
/* perform I/O transfers required for Slave initialization */
|
||||
return rt766_sdca_io_init(&slave->dev, slave);
|
||||
}
|
||||
|
||||
static int rt766_sdca_read_prop(struct sdw_slave *slave)
|
||||
{
|
||||
struct sdw_slave_prop *prop = &slave->prop;
|
||||
int ret;
|
||||
|
||||
ret = sdw_slave_read_prop(slave);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
|
||||
prop->scp_int1_mask = SDW_SCP_INT1_BUS_CLASH | SDW_SCP_INT1_PARITY;
|
||||
prop->quirks = SDW_SLAVE_QUIRKS_INVALID_INITIAL_PARITY;
|
||||
/*
|
||||
* SDCA interrupts are routed through SoundWire domain IRQ.
|
||||
*/
|
||||
prop->use_domain_irq = true;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const struct sdw_slave_ops rt766_sdca_slave_ops = {
|
||||
.read_prop = rt766_sdca_read_prop,
|
||||
.update_status = rt766_sdca_update_status,
|
||||
};
|
||||
|
||||
static int rt766_sdca_sdw_probe(struct sdw_slave *slave,
|
||||
const struct sdw_device_id *id)
|
||||
{
|
||||
struct regmap *regmap;
|
||||
|
||||
/* Regmap Initialization */
|
||||
regmap = devm_regmap_init_sdw_mbq_cfg(&slave->dev, slave,
|
||||
&rt766_sdca_regmap, &rt766_sdca_mbq_cfg);
|
||||
if (IS_ERR(regmap))
|
||||
return PTR_ERR(regmap);
|
||||
|
||||
return rt766_sdca_init(&slave->dev, regmap, slave);
|
||||
}
|
||||
|
||||
static void rt766_sdca_sdw_remove(struct sdw_slave *slave)
|
||||
{
|
||||
pm_runtime_disable(&slave->dev);
|
||||
}
|
||||
|
||||
static const struct sdw_device_id rt766_sdca_id[] = {
|
||||
SDW_SLAVE_ENTRY_EXT(0x025d, 0x766, 0x3, 0x1, 0),
|
||||
SDW_SLAVE_ENTRY_EXT(0x025d, 0x767, 0x3, 0x1, 0),
|
||||
{},
|
||||
};
|
||||
MODULE_DEVICE_TABLE(sdw, rt766_sdca_id);
|
||||
|
||||
static int rt766_sdca_dev_suspend(struct device *dev)
|
||||
{
|
||||
struct rt766_sdca_priv *rt766 = dev_get_drvdata(dev);
|
||||
|
||||
if (!rt766->hw_init)
|
||||
return 0;
|
||||
|
||||
regcache_cache_only(rt766->regmap, true);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int rt766_sdca_dev_system_suspend(struct device *dev)
|
||||
{
|
||||
struct rt766_sdca_priv *rt766 = dev_get_drvdata(dev);
|
||||
struct sdw_slave *slave = dev_to_sdw_dev(dev);
|
||||
int ret1, ret2;
|
||||
|
||||
if (!rt766->hw_init)
|
||||
return 0;
|
||||
|
||||
/*
|
||||
* prevent new interrupts from being handled after the
|
||||
* deferred work completes and before the parent disables
|
||||
* interrupts on the link
|
||||
*/
|
||||
mutex_lock(&rt766->disable_irq_lock);
|
||||
rt766->disable_irq = true;
|
||||
ret1 = sdw_update_no_pm(slave, SDW_SCP_SDCA_INTMASK3,
|
||||
SDW_SCP_SDCA_INTMASK_SDCA_16, 0);
|
||||
ret2 = sdw_update_no_pm(slave, SDW_SCP_SDCA_INTMASK4,
|
||||
SDW_SCP_SDCA_INTMASK_SDCA_24, 0);
|
||||
mutex_unlock(&rt766->disable_irq_lock);
|
||||
|
||||
if (ret1 < 0 || ret2 < 0) {
|
||||
/* log but don't prevent suspend from happening */
|
||||
dev_dbg(&slave->dev, "%s: could not disable SDCA interrupts\n:", __func__);
|
||||
}
|
||||
|
||||
return rt766_sdca_dev_suspend(dev);
|
||||
}
|
||||
|
||||
static int rt766_sdca_dev_resume(struct device *dev)
|
||||
{
|
||||
struct sdw_slave *slave = dev_to_sdw_dev(dev);
|
||||
struct rt766_sdca_priv *rt766 = dev_get_drvdata(dev);
|
||||
int ret;
|
||||
|
||||
if (!rt766->first_hw_init)
|
||||
return 0;
|
||||
|
||||
if (!slave->unattach_request) {
|
||||
mutex_lock(&rt766->disable_irq_lock);
|
||||
if (rt766->disable_irq == true) {
|
||||
sdw_write_no_pm(slave, SDW_SCP_SDCA_INTMASK3, SDW_SCP_SDCA_INTMASK_SDCA_16);
|
||||
sdw_write_no_pm(slave, SDW_SCP_SDCA_INTMASK4, SDW_SCP_SDCA_INTMASK_SDCA_24);
|
||||
rt766->disable_irq = false;
|
||||
}
|
||||
mutex_unlock(&rt766->disable_irq_lock);
|
||||
goto regmap_sync;
|
||||
}
|
||||
|
||||
ret = sdw_slave_wait_for_init(slave, RT766_PROBE_TIMEOUT);
|
||||
if (ret) {
|
||||
sdw_show_ping_status(slave->bus, true);
|
||||
return ret;
|
||||
}
|
||||
|
||||
regmap_sync:
|
||||
regcache_cache_only(rt766->regmap, false);
|
||||
ret = regcache_sync(rt766->regmap);
|
||||
if (ret) {
|
||||
regcache_cache_only(rt766->regmap, true);
|
||||
regcache_mark_dirty(rt766->regmap);
|
||||
return ret;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const struct dev_pm_ops rt766_sdca_pm = {
|
||||
SYSTEM_SLEEP_PM_OPS(rt766_sdca_dev_system_suspend, rt766_sdca_dev_resume)
|
||||
RUNTIME_PM_OPS(rt766_sdca_dev_suspend, rt766_sdca_dev_resume, NULL)
|
||||
};
|
||||
|
||||
static struct sdw_driver rt766_sdca_sdw_driver = {
|
||||
.driver = {
|
||||
.name = "rt766-sdca",
|
||||
.pm = pm_ptr(&rt766_sdca_pm),
|
||||
},
|
||||
.probe = rt766_sdca_sdw_probe,
|
||||
.remove = rt766_sdca_sdw_remove,
|
||||
.ops = &rt766_sdca_slave_ops,
|
||||
.id_table = rt766_sdca_id,
|
||||
};
|
||||
module_sdw_driver(rt766_sdca_sdw_driver);
|
||||
|
||||
MODULE_DESCRIPTION("ASoC RT766 SDCA SDW driver");
|
||||
MODULE_AUTHOR("Shuming Fan <shumingf@realtek.com>");
|
||||
MODULE_LICENSE("GPL");
|
||||
MODULE_IMPORT_NS("SND_SOC_SDCA");
|
||||
61
sound/soc/codecs/rt766-sdca-sdw.h
Normal file
61
sound/soc/codecs/rt766-sdca-sdw.h
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
/* SPDX-License-Identifier: GPL-2.0-only */
|
||||
/*
|
||||
* rt766-sdca-sdw.h -- RT766 SDCA ALSA SoC audio driver header
|
||||
*
|
||||
* Copyright(c) 2026 Realtek Semiconductor Corp.
|
||||
*/
|
||||
|
||||
#ifndef __RT766_SDW_H__
|
||||
#define __RT766_SDW_H__
|
||||
|
||||
#include <linux/regmap.h>
|
||||
#include <linux/soundwire/sdw_registers.h>
|
||||
|
||||
static const struct reg_default rt766_sdca_defaults[] = {
|
||||
/* 0x40400289 - 0x4040028a */
|
||||
{ RT766_MUTE_REG(UAJ, USER_FU41, 1), 0x01 },
|
||||
{ RT766_MUTE_REG(UAJ, USER_FU41, 2), 0x01 },
|
||||
/* 0x40400291 - 0x40400292 */
|
||||
{ RT766_VOLUME_REG(UAJ, USER_FU41, 1), 0x0000 },
|
||||
{ RT766_VOLUME_REG(UAJ, USER_FU41, 2), 0x0000 },
|
||||
/* 0x40400789 - 0x4040078a */
|
||||
{ RT766_MUTE_REG(UAJ, USER_FU36, 1), 0x01 },
|
||||
{ RT766_MUTE_REG(UAJ, USER_FU36, 2), 0x01 },
|
||||
/* 0x40400791 - 0x40400792 */
|
||||
{ RT766_VOLUME_REG(UAJ, USER_FU36, 1), 0x0000 },
|
||||
{ RT766_VOLUME_REG(UAJ, USER_FU36, 2), 0x0000 },
|
||||
{ RT766_PDE_REQ_REG(UAJ, PDE47), 0x03 }, /* 0x40401408 */
|
||||
{ RT766_PDE_REQ_REG(UAJ, PDE34), 0x03 }, /* 0x40401488 */
|
||||
{ RT766_SDCA_CTL(UAJ, CS41, SDCA_CTL_CS_SAMPLERATEINDEX), 0x09 }, /* 0x40480080 */
|
||||
{ RT766_SDCA_CTL(UAJ, CS36, SDCA_CTL_CS_SAMPLERATEINDEX), 0x09 }, /* 0x40480880 */
|
||||
/* 0x40600259 - 0x4060025a */
|
||||
{ RT766_GAIN_REG(UAJ, PLATFORM_FU33, 1), 0xfe00 },
|
||||
{ RT766_GAIN_REG(UAJ, PLATFORM_FU33, 2), 0xfe00 },
|
||||
{ RT766_SDCA_CTL(UAJ, GE49, SDCA_CTL_GE_SELECTED_MODE), 0x00 }, /* 0x40600488 */
|
||||
|
||||
{ RT766_PDE_REQ_REG(MIC, PDE11), 0x03 }, /* 0x40801508 */
|
||||
/* 0x40801809 - 0x4080180c */
|
||||
{ RT766_MUTE_REG(MIC, USER_FU113, 1), 0x01 },
|
||||
{ RT766_MUTE_REG(MIC, USER_FU113, 2), 0x01 },
|
||||
{ RT766_MUTE_REG(MIC, USER_FU113, 3), 0x01 },
|
||||
{ RT766_MUTE_REG(MIC, USER_FU113, 4), 0x01 },
|
||||
/* 0x40801811 - 0x40801814 */
|
||||
{ RT766_VOLUME_REG(MIC, USER_FU113, 1), 0x0000 },
|
||||
{ RT766_VOLUME_REG(MIC, USER_FU113, 2), 0x0000 },
|
||||
{ RT766_VOLUME_REG(MIC, USER_FU113, 3), 0x0000 },
|
||||
{ RT766_VOLUME_REG(MIC, USER_FU113, 4), 0x0000 },
|
||||
{ RT766_SDCA_CTL(MIC, CS113, SDCA_CTL_CS_SAMPLERATEINDEX), 0x09 }, /* 0x40880900 */
|
||||
|
||||
/* 0x41000189 - 0x4100018a */
|
||||
{ RT766_MUTE_REG(AMP, USER_FU21, 1), 0x01 },
|
||||
{ RT766_MUTE_REG(AMP, USER_FU21, 2), 0x01 },
|
||||
/* 0x41000191 - 0x41000192 */
|
||||
{ RT766_VOLUME_REG(AMP, USER_FU21, 1), 0x0000 },
|
||||
{ RT766_VOLUME_REG(AMP, USER_FU21, 2), 0x0000 },
|
||||
{ RT766_PDE_REQ_REG(AMP, PDE23), 0x03 }, /* 0x41001988 */
|
||||
{ RT766_SDCA_CTL(AMP, PPU21, SDCA_CTL_PPU_POSTURENUMBER), 0x00 }, /* 0x41080200 */
|
||||
{ RT766_SDCA_CTL(AMP, CS21, SDCA_CTL_CS_SAMPLERATEINDEX), 0x09 }, /* 0x41081080 */
|
||||
|
||||
};
|
||||
|
||||
#endif /* __RT766_SDW_H__ */
|
||||
1362
sound/soc/codecs/rt766-sdca.c
Normal file
1362
sound/soc/codecs/rt766-sdca.c
Normal file
File diff suppressed because it is too large
Load Diff
138
sound/soc/codecs/rt766-sdca.h
Normal file
138
sound/soc/codecs/rt766-sdca.h
Normal file
|
|
@ -0,0 +1,138 @@
|
|||
/* SPDX-License-Identifier: GPL-2.0-only */
|
||||
/*
|
||||
* rt766-sdca.h -- RT766 SDCA ALSA SoC audio driver header
|
||||
*
|
||||
* Copyright(c) 2026 Realtek Semiconductor Corp.
|
||||
*/
|
||||
|
||||
#ifndef __RT766_H__
|
||||
#define __RT766_H__
|
||||
|
||||
#include <linux/pm.h>
|
||||
#include <linux/regmap.h>
|
||||
#include <linux/soundwire/sdw.h>
|
||||
#include <linux/soundwire/sdw_type.h>
|
||||
#include <sound/soc.h>
|
||||
#include <linux/workqueue.h>
|
||||
|
||||
struct rt766_sdca_priv {
|
||||
struct regmap *regmap;
|
||||
struct snd_soc_component *component;
|
||||
struct sdw_slave *slave;
|
||||
bool hw_init;
|
||||
bool first_hw_init;
|
||||
struct snd_soc_jack *hs_jack;
|
||||
struct mutex disable_irq_lock; /* SDCA irq lock protection */
|
||||
bool disable_irq;
|
||||
int jack_type;
|
||||
bool fu41_dapm_mute;
|
||||
bool fu41_mixer_l_mute;
|
||||
bool fu41_mixer_r_mute;
|
||||
bool fu113_dapm_mute;
|
||||
bool fu113_mixer_mute[4];
|
||||
bool fu21_dapm_mute;
|
||||
bool fu21_mixer_l_mute;
|
||||
bool fu21_mixer_r_mute;
|
||||
bool fu36_dapm_mute;
|
||||
bool fu36_mixer_l_mute;
|
||||
bool fu36_mixer_r_mute;
|
||||
struct sdca_function_data *uaj_func_data;
|
||||
struct sdca_function_data *sm_func_data;
|
||||
struct sdca_function_data *sa_func_data;
|
||||
struct sdca_function_data *hid_func_data;
|
||||
struct sdca_interrupt_info *irq_info;
|
||||
};
|
||||
|
||||
/* vendor registers */
|
||||
#define RT766_VERSION_ID 0xc404
|
||||
#define RT766_DEV_ID1 0xc405
|
||||
#define RT766_DEV_ID0 0xc406
|
||||
#define RT766_BOND_LATCH_ID 0xc407
|
||||
|
||||
#define RT766_HP_POWER_STATE 0x1000004
|
||||
#define RT766_HP_FSM_CTL2_1 0x100000d
|
||||
|
||||
/* MCU Patch address */
|
||||
#define RT766_MCU_PATCH_ADDR1_START 0x10010000
|
||||
#define RT766_MCU_PATCH_ADDR1_END 0x10011fff
|
||||
#define RT766_MCU_PATCH_ADDR2_START 0x10020000
|
||||
#define RT766_MCU_PATCH_ADDR2_END 0x10023fff
|
||||
|
||||
/* Buffer address for HID */
|
||||
#define RT766_BUF_ADDR_HID1 0x44030000
|
||||
#define RT766_BUF_ADDR_HID2 0x44030020
|
||||
|
||||
/* SDCA (Channel) */
|
||||
#define RT766_CH_1 0x01
|
||||
#define RT766_CH_2 0x02
|
||||
#define RT766_CH_3 0x03
|
||||
#define RT766_CH_4 0x04
|
||||
|
||||
/* RT766 SDCA Control - function number */
|
||||
#define RT766_FUNC_NUM_UAJ 0x01
|
||||
#define RT766_FUNC_NUM_MIC 0x02
|
||||
#define RT766_FUNC_NUM_HID 0x03
|
||||
#define RT766_FUNC_NUM_AMP 0x04
|
||||
|
||||
/* RT766 SDCA entity */
|
||||
#define RT766_SDCA_ENT_0 0x00
|
||||
#define RT766_SDCA_ENT_HID101 0x01
|
||||
#define RT766_SDCA_ENT_GE49 0x49
|
||||
#define RT766_SDCA_ENT_USER_FU41 0x05
|
||||
#define RT766_SDCA_ENT_USER_FU36 0x0f
|
||||
#define RT766_SDCA_ENT_USER_FU21 0x03
|
||||
#define RT766_SDCA_ENT_USER_FU113 0x30
|
||||
#define RT766_SDCA_ENT_PDE23 0x33
|
||||
#define RT766_SDCA_ENT_PDE47 0x28
|
||||
#define RT766_SDCA_ENT_PDE11 0x2a
|
||||
#define RT766_SDCA_ENT_PDE34 0x29
|
||||
#define RT766_SDCA_ENT_CS41 0x01
|
||||
#define RT766_SDCA_ENT_CS36 0x11
|
||||
#define RT766_SDCA_ENT_CS113 0x12
|
||||
#define RT766_SDCA_ENT_CS21 0x21
|
||||
#define RT766_SDCA_ENT_PLATFORM_FU33 0x44
|
||||
#define RT766_SDCA_ENT_PPU21 0x04
|
||||
|
||||
/* sample frequency index */
|
||||
#define RT766_SDCA_RATE_44100HZ 0x08
|
||||
#define RT766_SDCA_RATE_48000HZ 0x09
|
||||
#define RT766_SDCA_RATE_96000HZ 0x0b
|
||||
#define RT766_SDCA_RATE_192000HZ 0x0d
|
||||
|
||||
/* SDCA Register macros */
|
||||
#define RT766_MUTE_REG(func, fu, ch) \
|
||||
SDW_SDCA_CTL(RT766_FUNC_NUM_##func, RT766_SDCA_ENT_##fu, SDCA_CTL_FU_MUTE, RT766_CH_##ch)
|
||||
|
||||
#define RT766_VOLUME_REG(func, fu, ch) \
|
||||
SDW_SDCA_CTL(RT766_FUNC_NUM_##func, RT766_SDCA_ENT_##fu, SDCA_CTL_FU_CHANNEL_VOLUME, RT766_CH_##ch)
|
||||
|
||||
#define RT766_GAIN_REG(func, fu, ch) \
|
||||
SDW_SDCA_CTL(RT766_FUNC_NUM_##func, RT766_SDCA_ENT_##fu, SDCA_CTL_FU_GAIN, RT766_CH_##ch)
|
||||
|
||||
#define RT766_PDE_REQ_REG(func, pde) \
|
||||
SDW_SDCA_CTL(RT766_FUNC_NUM_##func, RT766_SDCA_ENT_##pde, SDCA_CTL_PDE_REQUESTED_PS, 0)
|
||||
|
||||
#define RT766_PDE_ACTUAL_REG(func, pde) \
|
||||
SDW_SDCA_CTL(RT766_FUNC_NUM_##func, RT766_SDCA_ENT_##pde, SDCA_CTL_PDE_ACTUAL_PS, 0)
|
||||
|
||||
#define RT766_FUNC_STATUS_REG(func) \
|
||||
SDW_SDCA_CTL(RT766_FUNC_NUM_##func, RT766_SDCA_ENT_0, SDCA_CTL_ENTITY_0_FUNCTION_STATUS, 0)
|
||||
|
||||
#define RT766_SDCA_CTL(func, ent, ctl) \
|
||||
SDW_SDCA_CTL(RT766_FUNC_NUM_##func, RT766_SDCA_ENT_##ent, ctl, 0)
|
||||
|
||||
enum {
|
||||
RT766_AIF1,
|
||||
RT766_AIF2,
|
||||
RT766_AIF3,
|
||||
};
|
||||
|
||||
enum {
|
||||
RT766_DAI_UAJ,
|
||||
RT766_DAI_AMP,
|
||||
RT766_DAI_MIC,
|
||||
};
|
||||
|
||||
int rt766_sdca_io_init(struct device *dev, struct sdw_slave *slave);
|
||||
int rt766_sdca_init(struct device *dev, struct regmap *regmap, struct sdw_slave *slave);
|
||||
#endif /* __RT766_H__ */
|
||||
Loading…
Reference in New Issue
Block a user