Skip to content

Commit 2cf7f9f

Browse files
bardliaoranj063
authored andcommitted
soundwire: cadence_master: set frame shape and divider based on actual clk freq
Frame shape and curr_dr_freq could be updated by sdw_compute_bus_params(). Peripherals will set curr_dr_freq as their frequency. Managers should do the same. Then update frame shape according to the actual bus frequency. Signed-off-by: Bard Liao <yung-chuan.liao@linux.intel.com>
1 parent 54d8adc commit 2cf7f9f

1 file changed

Lines changed: 21 additions & 3 deletions

File tree

drivers/soundwire/cadence_master.c

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1345,13 +1345,14 @@ static u32 cdns_set_initial_frame_shape(int n_rows, int n_cols)
13451345
return val;
13461346
}
13471347

1348-
static void cdns_init_clock_ctrl(struct sdw_cdns *cdns)
1348+
static int cdns_init_clock_ctrl(struct sdw_cdns *cdns)
13491349
{
13501350
struct sdw_bus *bus = &cdns->bus;
13511351
struct sdw_master_prop *prop = &bus->prop;
13521352
u32 val;
13531353
u32 ssp_interval;
13541354
int divider;
1355+
int freq;
13551356

13561357
dev_dbg(cdns->dev, "mclk %d max %d row %d col %d\n",
13571358
prop->mclk_freq,
@@ -1360,13 +1361,25 @@ static void cdns_init_clock_ctrl(struct sdw_cdns *cdns)
13601361
prop->default_col);
13611362

13621363
/* Set clock divider */
1363-
divider = (prop->mclk_freq / prop->max_clk_freq) - 1;
1364+
divider = (prop->mclk_freq * SDW_DOUBLE_RATE_FACTOR /
1365+
bus->params.curr_dr_freq) - 1;
1366+
freq = bus->params.curr_dr_freq >> 1;
13641367

13651368
cdns_updatel(cdns, CDNS_MCP_CLK_CTRL0,
13661369
CDNS_MCP_CLK_MCLKD_MASK, divider);
13671370
cdns_updatel(cdns, CDNS_MCP_CLK_CTRL1,
13681371
CDNS_MCP_CLK_MCLKD_MASK, divider);
13691372

1373+
/* Set frame shape base on the actual bus frequency. */
1374+
if (!prop->default_frame_rate || !prop->default_row) {
1375+
dev_err(cdns->dev, "Default frame_rate %d or row %d is invalid\n",
1376+
prop->default_frame_rate, prop->default_row);
1377+
return -EINVAL;
1378+
}
1379+
1380+
prop->default_col = freq * SDW_DOUBLE_RATE_FACTOR /
1381+
prop->default_frame_rate / prop->default_row;
1382+
13701383
/*
13711384
* Frame shape changes after initialization have to be done
13721385
* with the bank switch mechanism
@@ -1379,6 +1392,8 @@ static void cdns_init_clock_ctrl(struct sdw_cdns *cdns)
13791392
ssp_interval = prop->default_frame_rate / SDW_CADENCE_GSYNC_HZ;
13801393
cdns_writel(cdns, CDNS_MCP_SSP_CTRL0, ssp_interval);
13811394
cdns_writel(cdns, CDNS_MCP_SSP_CTRL1, ssp_interval);
1395+
1396+
return 0;
13821397
}
13831398

13841399
/**
@@ -1412,9 +1427,12 @@ EXPORT_SYMBOL(sdw_cdns_soft_reset);
14121427
*/
14131428
int sdw_cdns_init(struct sdw_cdns *cdns)
14141429
{
1430+
int ret;
14151431
u32 val;
14161432

1417-
cdns_init_clock_ctrl(cdns);
1433+
ret = cdns_init_clock_ctrl(cdns);
1434+
if (ret)
1435+
return ret;
14181436

14191437
sdw_cdns_check_self_clearing_bits(cdns, __func__, false, 0);
14201438

0 commit comments

Comments
 (0)