128128#define MAX_FREQ_NUM 1
129129#define TIMEOUT_MS 100
130130#define QCOM_SWRM_MAX_RD_LEN 0x1
131- #define QCOM_SDW_MAX_PORTS 14
132131#define DEFAULT_CLK_FREQ 9600000
133132#define SWRM_MAX_DAIS 0xF
134133#define SWR_INVALID_PARAM 0xFF
@@ -195,14 +194,15 @@ struct qcom_swrm_ctrl {
195194 int wake_irq ;
196195 int num_din_ports ;
197196 int num_dout_ports ;
197+ int nports ;
198198 int cols_index ;
199199 int rows_index ;
200200 unsigned long port_mask ;
201201 u32 intr_mask ;
202202 u8 rcmd_id ;
203203 u8 wcmd_id ;
204204 /* Port numbers are 1 - 14 */
205- struct qcom_swrm_port_config pconfig [ QCOM_SDW_MAX_PORTS + 1 ] ;
205+ struct qcom_swrm_port_config * pconfig ;
206206 struct sdw_stream_runtime * sruntime [SWRM_MAX_DAIS ];
207207 enum sdw_slave_status status [SDW_MAX_DEVICES + 1 ];
208208 int (* reg_read )(struct qcom_swrm_ctrl * ctrl , int reg , u32 * val );
@@ -1153,7 +1153,6 @@ static int qcom_swrm_stream_alloc_ports(struct qcom_swrm_ctrl *ctrl,
11531153 struct snd_pcm_hw_params * params ,
11541154 int direction )
11551155{
1156- struct sdw_port_config pconfig [QCOM_SDW_MAX_PORTS ];
11571156 struct sdw_stream_config sconfig ;
11581157 struct sdw_master_runtime * m_rt ;
11591158 struct sdw_slave_runtime * s_rt ;
@@ -1162,6 +1161,10 @@ static int qcom_swrm_stream_alloc_ports(struct qcom_swrm_ctrl *ctrl,
11621161 unsigned long * port_mask ;
11631162 int maxport , pn , nports = 0 , ret = 0 ;
11641163 unsigned int m_port ;
1164+ struct sdw_port_config * pconfig __free (kfree ) = kcalloc (ctrl -> nports ,
1165+ sizeof (* pconfig ), GFP_KERNEL );
1166+ if (!pconfig )
1167+ return - ENOMEM ;
11651168
11661169 if (direction == SNDRV_PCM_STREAM_CAPTURE )
11671170 sconfig .direction = SDW_DATA_DIR_TX ;
@@ -1186,8 +1189,7 @@ static int qcom_swrm_stream_alloc_ports(struct qcom_swrm_ctrl *ctrl,
11861189 continue ;
11871190
11881191 port_mask = & ctrl -> port_mask ;
1189- maxport = ctrl -> num_dout_ports + ctrl -> num_din_ports ;
1190-
1192+ maxport = ctrl -> nports ;
11911193
11921194 list_for_each_entry (s_rt , & m_rt -> slave_rt_list , m_rt_node ) {
11931195 slave = s_rt -> slave ;
@@ -1347,106 +1349,87 @@ static int qcom_swrm_register_dais(struct qcom_swrm_ctrl *ctrl)
13471349static int qcom_swrm_get_port_config (struct qcom_swrm_ctrl * ctrl )
13481350{
13491351 struct device_node * np = ctrl -> dev -> of_node ;
1350- u8 off1 [QCOM_SDW_MAX_PORTS ];
1351- u8 off2 [QCOM_SDW_MAX_PORTS ];
1352- u16 si [QCOM_SDW_MAX_PORTS ];
1353- u8 bp_mode [QCOM_SDW_MAX_PORTS ] = { 0 , };
1354- u8 hstart [QCOM_SDW_MAX_PORTS ];
1355- u8 hstop [QCOM_SDW_MAX_PORTS ];
1356- u8 word_length [QCOM_SDW_MAX_PORTS ];
1357- u8 blk_group_count [QCOM_SDW_MAX_PORTS ];
1358- u8 lane_control [QCOM_SDW_MAX_PORTS ];
1359- int i , ret , nports , val ;
1360- bool si_16 = false;
1352+ struct qcom_swrm_port_config * pcfg ;
1353+ int i , ret , val ;
13611354
13621355 ctrl -> reg_read (ctrl , SWRM_COMP_PARAMS , & val );
13631356
13641357 ctrl -> num_dout_ports = FIELD_GET (SWRM_COMP_PARAMS_DOUT_PORTS_MASK , val );
13651358 ctrl -> num_din_ports = FIELD_GET (SWRM_COMP_PARAMS_DIN_PORTS_MASK , val );
13661359
13671360 ret = of_property_read_u32 (np , "qcom,din-ports" , & val );
1368- if (ret )
1369- return ret ;
1370-
1371- if ( val > ctrl -> num_din_ports )
1372- return - EINVAL ;
1361+ if (! ret ) { /* only if present */
1362+ if ( val != ctrl -> num_din_ports ) {
1363+ dev_err ( ctrl -> dev , "din-ports (%d) mismatch with controller (%d)" ,
1364+ val , ctrl -> num_din_ports );
1365+ }
13731366
1374- ctrl -> num_din_ports = val ;
1367+ ctrl -> num_din_ports = val ;
1368+ }
13751369
13761370 ret = of_property_read_u32 (np , "qcom,dout-ports" , & val );
1377- if (ret )
1378- return ret ;
1371+ if (!ret ) { /* only if present */
1372+ if (val != ctrl -> num_dout_ports ) {
1373+ dev_err (ctrl -> dev , "dout-ports (%d) mismatch with controller (%d)" ,
1374+ val , ctrl -> num_dout_ports );
1375+ }
13791376
1380- if ( val > ctrl -> num_dout_ports )
1381- return - EINVAL ;
1377+ ctrl -> num_dout_ports = val ;
1378+ }
13821379
1383- ctrl -> num_dout_ports = val ;
1380+ ctrl -> nports = ctrl -> num_dout_ports + ctrl -> num_din_ports ;
13841381
1385- nports = ctrl -> num_dout_ports + ctrl -> num_din_ports ;
1386- if (nports > QCOM_SDW_MAX_PORTS )
1387- return - EINVAL ;
1382+ ctrl -> pconfig = devm_kcalloc (ctrl -> dev , ctrl -> nports + 1 ,
1383+ sizeof (* ctrl -> pconfig ), GFP_KERNEL );
1384+ if (!ctrl -> pconfig )
1385+ return - ENOMEM ;
13881386
1389- /* Valid port numbers are from 1-14, so mask out port 0 explicitly */
13901387 set_bit (0 , & ctrl -> port_mask );
1388+ /* Valid port numbers are from 1, so mask out port 0 explicitly */
1389+ for (i = 0 ; i < ctrl -> nports ; i ++ ) {
1390+ pcfg = & ctrl -> pconfig [i + 1 ];
13911391
1392- ret = of_property_read_u8_array (np , "qcom,ports-offset1" ,
1393- off1 , nports );
1394- if (ret )
1395- return ret ;
1396-
1397- ret = of_property_read_u8_array (np , "qcom,ports-offset2" ,
1398- off2 , nports );
1399- if (ret )
1400- return ret ;
1401-
1402- ret = of_property_read_u8_array (np , "qcom,ports-sinterval-low" ,
1403- (u8 * )si , nports );
1404- if (ret ) {
1405- ret = of_property_read_u16_array (np , "qcom,ports-sinterval" ,
1406- si , nports );
1392+ ret = of_property_read_u8_index (np , "qcom,ports-offset1" , i , & pcfg -> off1 );
14071393 if (ret )
14081394 return ret ;
1409- si_16 = true;
1410- }
14111395
1412- ret = of_property_read_u8_array (np , "qcom,ports-block-pack-mode" ,
1413- bp_mode , nports );
1414- if (ret ) {
1415- if (ctrl -> version <= SWRM_VERSION_1_3_0 )
1416- memset (bp_mode , SWR_INVALID_PARAM , QCOM_SDW_MAX_PORTS );
1417- else
1396+ ret = of_property_read_u8_index (np , "qcom,ports-offset2" , i , & pcfg -> off2 );
1397+ if (ret )
14181398 return ret ;
1419- }
14201399
1421- memset (hstart , SWR_INVALID_PARAM , QCOM_SDW_MAX_PORTS );
1422- of_property_read_u8_array (np , "qcom,ports-hstart" , hstart , nports );
1400+ ret = of_property_read_u8_index (np , "qcom,ports-sinterval-low" , i , (u8 * )& pcfg -> si );
1401+ if (ret ) {
1402+ ret = of_property_read_u16_index (np , "qcom,ports-sinterval" , i , & pcfg -> si );
1403+ if (ret )
1404+ return ret ;
1405+ }
1406+
1407+ ret = of_property_read_u8_index (np , "qcom,ports-block-pack-mode" ,
1408+ i , & pcfg -> bp_mode );
1409+ if (ret ) {
1410+ if (ctrl -> version <= SWRM_VERSION_1_3_0 )
1411+ pcfg -> bp_mode = SWR_INVALID_PARAM ;
1412+ else
1413+ return ret ;
1414+ }
14231415
1424- memset (hstop , SWR_INVALID_PARAM , QCOM_SDW_MAX_PORTS );
1425- of_property_read_u8_array (np , "qcom,ports-hstop" , hstop , nports );
1416+ /* Optional properties */
1417+ pcfg -> hstart = SWR_INVALID_PARAM ;
1418+ pcfg -> hstop = SWR_INVALID_PARAM ;
1419+ pcfg -> word_length = SWR_INVALID_PARAM ;
1420+ pcfg -> blk_group_count = SWR_INVALID_PARAM ;
1421+ pcfg -> lane_control = SWR_INVALID_PARAM ;
14261422
1427- memset (word_length , SWR_INVALID_PARAM , QCOM_SDW_MAX_PORTS );
1428- of_property_read_u8_array (np , "qcom,ports-word-length" , word_length , nports );
1423+ of_property_read_u8_index (np , "qcom,ports-hstart" , i , & pcfg -> hstart );
14291424
1430- memset (blk_group_count , SWR_INVALID_PARAM , QCOM_SDW_MAX_PORTS );
1431- of_property_read_u8_array (np , "qcom,ports-block-group-count" , blk_group_count , nports );
1425+ of_property_read_u8_index (np , "qcom,ports-hstop" , i , & pcfg -> hstop );
14321426
1433- memset (lane_control , SWR_INVALID_PARAM , QCOM_SDW_MAX_PORTS );
1434- of_property_read_u8_array (np , "qcom,ports-lane-control" , lane_control , nports );
1427+ of_property_read_u8_index (np , "qcom,ports-word-length" , i , & pcfg -> word_length );
14351428
1436- for (i = 0 ; i < nports ; i ++ ) {
1437- /* Valid port number range is from 1-14 */
1438- if (si_16 )
1439- ctrl -> pconfig [i + 1 ].si = si [i ];
1440- else
1441- ctrl -> pconfig [i + 1 ].si = ((u8 * )si )[i ];
1442- ctrl -> pconfig [i + 1 ].off1 = off1 [i ];
1443- ctrl -> pconfig [i + 1 ].off2 = off2 [i ];
1444- ctrl -> pconfig [i + 1 ].bp_mode = bp_mode [i ];
1445- ctrl -> pconfig [i + 1 ].hstart = hstart [i ];
1446- ctrl -> pconfig [i + 1 ].hstop = hstop [i ];
1447- ctrl -> pconfig [i + 1 ].word_length = word_length [i ];
1448- ctrl -> pconfig [i + 1 ].blk_group_count = blk_group_count [i ];
1449- ctrl -> pconfig [i + 1 ].lane_control = lane_control [i ];
1429+ of_property_read_u8_index (np , "qcom,ports-block-group-count" ,
1430+ i , & pcfg -> blk_group_count );
1431+
1432+ of_property_read_u8_index (np , "qcom,ports-lane-control" , i , & pcfg -> lane_control );
14501433 }
14511434
14521435 return 0 ;
0 commit comments