mirror of
https://github.com/torvalds/linux.git
synced 2026-09-23 22:14:03 +02:00
ASoC: rt712-sdca: reconfigure PLL2 to fix calibration time-out
Add pll2 reconfiguration sequence in order to fix calibration time-out issue and to support 24.576MHz MCLK on specific platforms. Signed-off-by: Jack Yu <jack.yu@realtek.com> Link: https://patch.msgid.link/20260909085449.862350-1-jack.yu@realtek.com Signed-off-by: Mark Brown <broonie@kernel.org>
This commit is contained in:
parent
88c4aff394
commit
d56fe35c1b
|
|
@ -18,12 +18,16 @@
|
|||
static bool rt712_sdca_readable_register(struct device *dev, unsigned int reg)
|
||||
{
|
||||
switch (reg) {
|
||||
case 0x004d:
|
||||
case 0x201a ... 0x201f:
|
||||
case 0x2029 ... 0x202a:
|
||||
case 0x202d ... 0x2034:
|
||||
case 0x2230 ... 0x2232:
|
||||
case 0x2f01 ... 0x2f0a:
|
||||
case 0x2f35 ... 0x2f36:
|
||||
case 0x2f3a:
|
||||
case 0x2f3d:
|
||||
case 0x2f41:
|
||||
case 0x2f50:
|
||||
case 0x2f54:
|
||||
case 0x2f58 ... 0x2f5d:
|
||||
|
|
@ -48,6 +52,7 @@ static bool rt712_sdca_readable_register(struct device *dev, unsigned int reg)
|
|||
static bool rt712_sdca_volatile_register(struct device *dev, unsigned int reg)
|
||||
{
|
||||
switch (reg) {
|
||||
case 0x004d:
|
||||
case 0x201b:
|
||||
case 0x201c:
|
||||
case 0x201d:
|
||||
|
|
@ -56,6 +61,9 @@ static bool rt712_sdca_volatile_register(struct device *dev, unsigned int reg)
|
|||
case 0x2230:
|
||||
case 0x2f01:
|
||||
case 0x2f35:
|
||||
case 0x2f3a:
|
||||
case 0x2f3d:
|
||||
case 0x2f41:
|
||||
case 0x320c:
|
||||
case SDW_SDCA_CTL(FUNC_NUM_JACK_CODEC, RT712_SDCA_ENT_GE49, RT712_SDCA_CTL_DETECTED_MODE, 0):
|
||||
case SDW_SDCA_CTL(FUNC_NUM_HID, RT712_SDCA_ENT_HID01, RT712_SDCA_CTL_HIDTX_CURRENT_OWNER, 0) ...
|
||||
|
|
|
|||
|
|
@ -73,14 +73,57 @@ static int rt712_sdca_index_update_bits(struct rt712_sdca_priv *rt712,
|
|||
return rt712_sdca_index_write(rt712, nid, reg, tmp);
|
||||
}
|
||||
|
||||
static void rt712_sdca_clk_patch(struct rt712_sdca_priv *rt712)
|
||||
{
|
||||
rt712_sdca_index_write(rt712, RT712_VENDOR_REG, 0x65, 0x0000);
|
||||
regmap_write(rt712->regmap, RT712_SDW_ROOT_CLK, 0x03);
|
||||
usleep_range(1000, 1100);
|
||||
regmap_write(rt712->regmap, RT712_SDW_ROOT_CLK, 0x02);
|
||||
usleep_range(1000, 1100);
|
||||
regmap_update_bits(rt712->regmap, RT712_PLL2_CONF2, 0x0080, 0x0000);
|
||||
regmap_update_bits(rt712->regmap, RT712_PLL2_CONF2, 0x001f, 0x0017);
|
||||
regmap_update_bits(rt712->regmap, RT712_PLL2_CONF3, 0x0010, 0x0000);
|
||||
regmap_update_bits(rt712->regmap, RT712_PLL2_CONF1, 0x0081, 0x0001);
|
||||
regmap_write(rt712->regmap, RT712_SDW_ROOT_CLK, 0x03);
|
||||
usleep_range(1000, 1100);
|
||||
regmap_update_bits(rt712->regmap, RT712_PLL2_CONF1, 0x0081, 0x0081);
|
||||
regmap_update_bits(rt712->regmap, RT712_PLL2_CONF2, 0x0080, 0x0080);
|
||||
regmap_update_bits(rt712->regmap, RT712_PLL2_CONF2, 0x001f, 0x0000);
|
||||
regmap_update_bits(rt712->regmap, RT712_PLL2_CONF3, 0x0010, 0x0010);
|
||||
usleep_range(1000, 1100);
|
||||
rt712_sdca_index_write(rt712, RT712_VENDOR_REG, 0x65, 0x0081);
|
||||
}
|
||||
|
||||
static void rt712_sdca_clk_patch2(struct rt712_sdca_priv *rt712)
|
||||
{
|
||||
rt712_sdca_index_update_bits(rt712, RT712_VENDOR_REG, 0x49, 0x0800,
|
||||
0x0000);
|
||||
rt712_sdca_index_update_bits(rt712, RT712_VENDOR_REG, 0x49, 0xf000,
|
||||
0x0000);
|
||||
rt712_sdca_index_write(rt712, RT712_VENDOR_REG, 0x65, 0x0000);
|
||||
rt712_sdca_index_update_bits(rt712, RT712_VENDOR_ANALOG_CTL, 0x0c, 0xc000,
|
||||
0xc000);
|
||||
rt712_sdca_index_update_bits(rt712, RT712_VENDOR_ANALOG_CTL, 0x00, 0xc000,
|
||||
0xc000);
|
||||
rt712_sdca_index_write(rt712, RT712_VENDOR_REG, 0x65, 0x0081);
|
||||
regmap_write(rt712->regmap, RT712_SDW_ROOT_CLK, 0x02);
|
||||
usleep_range(1000, 1100);
|
||||
regmap_write(rt712->regmap, RT712_SDW_ROOT_CLK, 0x03);
|
||||
usleep_range(1000, 1100);
|
||||
rt712_sdca_index_write(rt712, RT712_VENDOR_REG, 0x65, 0x0000);
|
||||
}
|
||||
|
||||
static int rt712_sdca_calibration(struct rt712_sdca_priv *rt712)
|
||||
{
|
||||
unsigned int val, loop_rc = 0, loop_dc = 0;
|
||||
struct device *dev;
|
||||
struct regmap *regmap = rt712->regmap;
|
||||
unsigned int clk_base;
|
||||
int chk_cnt = 100;
|
||||
int ret = 0;
|
||||
|
||||
regmap_read(rt712->regmap, RT712_SDW_ROOT_CLK, &clk_base);
|
||||
|
||||
mutex_lock(&rt712->calibrate_mutex);
|
||||
dev = regmap_get_device(regmap);
|
||||
|
||||
|
|
@ -109,8 +152,35 @@ static int rt712_sdca_calibration(struct rt712_sdca_priv *rt712)
|
|||
if (ret < 0)
|
||||
goto _cali_fail_;
|
||||
}
|
||||
if (loop_dc == chk_cnt)
|
||||
dev_err(dev, "%s, calibration time-out!\n", __func__);
|
||||
|
||||
if (loop_dc == chk_cnt) {
|
||||
if (clk_base == RT712_CLK_FREQ_24_576MHZ) {
|
||||
rt712_sdca_clk_patch(rt712);
|
||||
rt712_sdca_clk_patch2(rt712);
|
||||
}
|
||||
rt712_sdca_index_write(rt712, RT712_VENDOR_REG, RT712_FSM_CTL, 0x4100);
|
||||
rt712_sdca_index_write(rt712, RT712_VENDOR_CALI,
|
||||
RT712_DAC_DC_CALI_CTL1, 0x7883);
|
||||
rt712_sdca_index_write(rt712, RT712_VENDOR_CALI,
|
||||
RT712_DAC_DC_CALI_CTL1, 0xf893);
|
||||
rt712_sdca_index_read(rt712, RT712_VENDOR_CALI,
|
||||
RT712_DAC_DC_CALI_CTL1, &val);
|
||||
|
||||
for (loop_dc = 0; loop_dc < chk_cnt &&
|
||||
(val & RT712_DAC_DC_CALI_TRIGGER); loop_dc++) {
|
||||
usleep_range(10000, 11000);
|
||||
ret = rt712_sdca_index_read(rt712, RT712_VENDOR_CALI,
|
||||
RT712_DAC_DC_CALI_CTL1, &val);
|
||||
|
||||
if (ret < 0)
|
||||
goto _cali_fail_;
|
||||
}
|
||||
|
||||
if (loop_dc == chk_cnt)
|
||||
dev_err(dev, "%s, calibration time-out!\n", __func__);
|
||||
else
|
||||
dev_dbg(dev, "%s, calibration success!\n", __func__);
|
||||
}
|
||||
|
||||
if (loop_dc == chk_cnt || loop_rc == chk_cnt)
|
||||
ret = -ETIMEDOUT;
|
||||
|
|
@ -1759,9 +1829,13 @@ static void rt712_sdca_va_io_init(struct rt712_sdca_priv *rt712)
|
|||
|
||||
static void rt712_sdca_vb_io_init(struct rt712_sdca_priv *rt712)
|
||||
{
|
||||
int ret = 0;
|
||||
unsigned int jack_func_status, mic_func_status, amp_func_status;
|
||||
struct device *dev = &rt712->slave->dev;
|
||||
unsigned int clk_base;
|
||||
int ret = 0;
|
||||
|
||||
regmap_read(rt712->regmap, RT712_SDW_ROOT_CLK, &clk_base);
|
||||
dev_dbg(dev, "%s clk_base=%x", __func__, clk_base);
|
||||
|
||||
regmap_read(rt712->regmap,
|
||||
SDW_SDCA_CTL(FUNC_NUM_JACK_CODEC, RT712_SDCA_ENT0, RT712_SDCA_CTL_FUNC_STATUS, 0), &jack_func_status);
|
||||
|
|
@ -1773,6 +1847,12 @@ static void rt712_sdca_vb_io_init(struct rt712_sdca_priv *rt712)
|
|||
__func__, jack_func_status, mic_func_status, amp_func_status);
|
||||
|
||||
rt712_sdca_index_write(rt712, RT712_VENDOR_REG, RT712_JD_CTL3, 0x7778);
|
||||
|
||||
if (clk_base == RT712_CLK_FREQ_24_576MHZ) {
|
||||
rt712_sdca_clk_patch(rt712);
|
||||
rt712_sdca_clk_patch2(rt712);
|
||||
}
|
||||
|
||||
/* DMIC */
|
||||
if ((mic_func_status & FUNCTION_NEEDS_INITIALIZATION) || (!rt712->first_hw_init)) {
|
||||
rt712_sdca_index_write(rt712, RT712_VENDOR_HDA_CTL, RT712_DMIC2_FU_IT_FLOAT_CTL, 0x1526);
|
||||
|
|
|
|||
|
|
@ -162,6 +162,16 @@ struct rt712_dmic_kctrl_priv {
|
|||
#define RT712_EAPD_HIGH 0x2
|
||||
#define RT712_EAPD_LOW 0x0
|
||||
|
||||
/* SDW clock root frequency */
|
||||
#define RT712_SDW_ROOT_CLK 0x004d
|
||||
#define RT712_SDW_SCALE_CLK0 0x0062
|
||||
#define RT712_SDW_SCALE_CLK1 0x0072
|
||||
|
||||
/* PLL2 config */
|
||||
#define RT712_PLL2_CONF1 0x2f3a
|
||||
#define RT712_PLL2_CONF2 0x2f3d
|
||||
#define RT712_PLL2_CONF3 0x2f41
|
||||
|
||||
/* RC Calibration register */
|
||||
#define RT712_RC_CAL 0x3201
|
||||
|
||||
|
|
@ -254,6 +264,14 @@ enum rt712_sdca_version {
|
|||
RT712_VB,
|
||||
};
|
||||
|
||||
enum {
|
||||
RT712_CLK_FREQ_19_2_MHZ = 1,
|
||||
RT712_CLK_FREQ_24MHZ = 2,
|
||||
RT712_CLK_FREQ_24_576MHZ = 3,
|
||||
RT712_CLK_FREQ_22_5792MHZ = 4,
|
||||
};
|
||||
|
||||
|
||||
int rt712_sdca_io_init(struct device *dev, struct sdw_slave *slave);
|
||||
int rt712_sdca_init(struct device *dev, struct regmap *regmap,
|
||||
struct regmap *mbq_regmap, struct sdw_slave *slave);
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user