@@ -813,6 +813,16 @@ void sdw_extract_slave_id(struct sdw_bus *bus,
813813}
814814EXPORT_SYMBOL (sdw_extract_slave_id );
815815
816+ bool is_clock_scaling_supported_by_slave (struct sdw_slave * slave )
817+ {
818+ /*
819+ * Dynamic scaling is a defined by SDCA. However, some devices expose the class ID but
820+ * can't support dynamic scaling. We might need a quirk to handle such devices.
821+ */
822+ return slave -> id .class_id ;
823+ }
824+ EXPORT_SYMBOL (is_clock_scaling_supported_by_slave );
825+
816826static int sdw_program_device_num (struct sdw_bus * bus , bool * programmed )
817827{
818828 u8 buf [SDW_NUM_DEV_ID_REGISTERS ] = {0 };
@@ -1276,23 +1286,12 @@ int sdw_configure_dpn_intr(struct sdw_slave *slave,
12761286 return ret ;
12771287}
12781288
1279- static int sdw_slave_set_frequency (struct sdw_slave * slave )
1289+ int sdw_slave_get_scale_index (struct sdw_slave * slave , u8 * base )
12801290{
12811291 u32 mclk_freq = slave -> bus -> prop .mclk_freq ;
12821292 u32 curr_freq = slave -> bus -> params .curr_dr_freq >> 1 ;
12831293 unsigned int scale ;
12841294 u8 scale_index ;
1285- u8 base ;
1286- int ret ;
1287-
1288- /*
1289- * frequency base and scale registers are required for SDCA
1290- * devices. They may also be used for 1.2+/non-SDCA devices.
1291- * Driver can set the property, we will need a DisCo property
1292- * to discover this case from platform firmware.
1293- */
1294- if (!slave -> id .class_id && !slave -> prop .clock_reg_supported )
1295- return 0 ;
12961295
12971296 if (!mclk_freq ) {
12981297 dev_err (& slave -> dev ,
@@ -1311,19 +1310,19 @@ static int sdw_slave_set_frequency(struct sdw_slave *slave)
13111310 */
13121311 if (!(19200000 % mclk_freq )) {
13131312 mclk_freq = 19200000 ;
1314- base = SDW_SCP_BASE_CLOCK_19200000_HZ ;
1313+ * base = SDW_SCP_BASE_CLOCK_19200000_HZ ;
13151314 } else if (!(22579200 % mclk_freq )) {
13161315 mclk_freq = 22579200 ;
1317- base = SDW_SCP_BASE_CLOCK_22579200_HZ ;
1316+ * base = SDW_SCP_BASE_CLOCK_22579200_HZ ;
13181317 } else if (!(24576000 % mclk_freq )) {
13191318 mclk_freq = 24576000 ;
1320- base = SDW_SCP_BASE_CLOCK_24576000_HZ ;
1319+ * base = SDW_SCP_BASE_CLOCK_24576000_HZ ;
13211320 } else if (!(32000000 % mclk_freq )) {
13221321 mclk_freq = 32000000 ;
1323- base = SDW_SCP_BASE_CLOCK_32000000_HZ ;
1322+ * base = SDW_SCP_BASE_CLOCK_32000000_HZ ;
13241323 } else if (!(96000000 % mclk_freq )) {
13251324 mclk_freq = 24000000 ;
1326- base = SDW_SCP_BASE_CLOCK_24000000_HZ ;
1325+ * base = SDW_SCP_BASE_CLOCK_24000000_HZ ;
13271326 } else {
13281327 dev_err (& slave -> dev ,
13291328 "Unsupported clock base, mclk %d\n" ,
@@ -1354,6 +1353,34 @@ static int sdw_slave_set_frequency(struct sdw_slave *slave)
13541353 }
13551354 scale_index ++ ;
13561355
1356+ dev_dbg (& slave -> dev ,
1357+ "Configured bus base %d, scale %d, mclk %d, curr_freq %d\n" ,
1358+ * base , scale_index , mclk_freq , curr_freq );
1359+
1360+ return scale_index ;
1361+ }
1362+ EXPORT_SYMBOL (sdw_slave_get_scale_index );
1363+
1364+ static int sdw_slave_set_frequency (struct sdw_slave * slave )
1365+ {
1366+ int scale_index ;
1367+ u8 base ;
1368+ int ret ;
1369+
1370+ /*
1371+ * frequency base and scale registers are required for SDCA
1372+ * devices. They may also be used for 1.2+/non-SDCA devices.
1373+ * Driver can set the property directly, for now there's no
1374+ * DisCo property to discover support for the scaling registers
1375+ * from platform firmware.
1376+ */
1377+ if (!slave -> id .class_id && !slave -> prop .clock_reg_supported )
1378+ return 0 ;
1379+
1380+ scale_index = sdw_slave_get_scale_index (slave , & base );
1381+ if (scale_index < 0 )
1382+ return scale_index ;
1383+
13571384 ret = sdw_write_no_pm (slave , SDW_SCP_BUS_CLOCK_BASE , base );
13581385 if (ret < 0 ) {
13591386 dev_err (& slave -> dev ,
@@ -1373,10 +1400,6 @@ static int sdw_slave_set_frequency(struct sdw_slave *slave)
13731400 dev_err (& slave -> dev ,
13741401 "SDW_SCP_BUSCLOCK_SCALE_B1 write failed:%d\n" , ret );
13751402
1376- dev_dbg (& slave -> dev ,
1377- "Configured bus base %d, scale %d, mclk %d, curr_freq %d\n" ,
1378- base , scale_index , mclk_freq , curr_freq );
1379-
13801403 return ret ;
13811404}
13821405
0 commit comments