@@ -28,15 +28,16 @@ struct ctl_access_elem {
2828};
2929
3030/* CTL access strings and codes */
31+ /* place the multi-bit values on top - like read_write - for save */
3132static const struct ctl_access_elem ctl_access [] = {
33+ {"read_write" , SNDRV_CTL_ELEM_ACCESS_READWRITE },
34+ {"tlv_read_write" , SNDRV_CTL_ELEM_ACCESS_TLV_READWRITE },
3235 {"read" , SNDRV_CTL_ELEM_ACCESS_READ },
3336 {"write" , SNDRV_CTL_ELEM_ACCESS_WRITE },
34- {"read_write" , SNDRV_CTL_ELEM_ACCESS_READWRITE },
3537 {"volatile" , SNDRV_CTL_ELEM_ACCESS_VOLATILE },
3638 {"timestamp" , SNDRV_CTL_ELEM_ACCESS_TIMESTAMP },
3739 {"tlv_read" , SNDRV_CTL_ELEM_ACCESS_TLV_READ },
3840 {"tlv_write" , SNDRV_CTL_ELEM_ACCESS_TLV_WRITE },
39- {"tlv_read_write" , SNDRV_CTL_ELEM_ACCESS_TLV_READWRITE },
4041 {"tlv_command" , SNDRV_CTL_ELEM_ACCESS_TLV_COMMAND },
4142 {"inactive" , SNDRV_CTL_ELEM_ACCESS_INACTIVE },
4243 {"lock" , SNDRV_CTL_ELEM_ACCESS_LOCK },
@@ -103,6 +104,46 @@ int parse_access(snd_config_t *cfg,
103104 return err ;
104105}
105106
107+ /* Save Access */
108+ static int tplg_save_access (snd_tplg_t * tplg ATTRIBUTE_UNUSED ,
109+ struct snd_soc_tplg_ctl_hdr * hdr , char * * dst ,
110+ const char * pfx )
111+ {
112+ const char * last ;
113+ unsigned int j , count , access , cval ;
114+ int err ;
115+
116+ if (hdr -> access == 0 )
117+ return 0 ;
118+
119+ access = hdr -> access ;
120+ for (j = 0 , count = 0 , last = NULL ; j < ARRAY_SIZE (ctl_access ); j ++ ) {
121+ cval = ctl_access [j ].value ;
122+ if ((access & cval ) == cval ) {
123+ access &= ~cval ;
124+ last = ctl_access [j ].name ;
125+ count ++ ;
126+ }
127+ }
128+ if (count == 1 )
129+ return tplg_save_printf (dst , pfx , "access.0 %s\n" , last );
130+ err = tplg_save_printf (dst , pfx , "access [\n" );
131+ if (err < 0 )
132+ return err ;
133+ access = hdr -> access ;
134+ for (j = 0 ; j < ARRAY_SIZE (ctl_access ); j ++ ) {
135+ cval = ctl_access [j ].value ;
136+ if ((access & cval ) == cval ) {
137+ err = tplg_save_printf (dst , pfx , "\t%s\n" ,
138+ ctl_access [j ].name );
139+ if (err < 0 )
140+ return err ;
141+ access &= ~cval ;
142+ }
143+ }
144+ return tplg_save_printf (dst , pfx , "]\n" );
145+ }
146+
106147/* copy referenced TLV to the mixer control */
107148static int copy_tlv (struct tplg_elem * elem , struct tplg_elem * ref )
108149{
@@ -358,6 +399,37 @@ int tplg_parse_tlv(snd_tplg_t *tplg, snd_config_t *cfg,
358399 return err ;
359400}
360401
402+ /* save TLV data */
403+ int tplg_save_tlv (snd_tplg_t * tplg ATTRIBUTE_UNUSED ,
404+ struct tplg_elem * elem ,
405+ char * * dst , const char * pfx )
406+ {
407+ struct snd_soc_tplg_ctl_tlv * tlv = elem -> tlv ;
408+ struct snd_soc_tplg_tlv_dbscale * scale ;
409+ int err ;
410+
411+ if (tlv -> type != SNDRV_CTL_TLVT_DB_SCALE ) {
412+ SNDERR ("unknown TLV type" );
413+ return - EINVAL ;
414+ }
415+
416+ scale = & tlv -> scale ;
417+ err = tplg_save_printf (dst , NULL , "'%s' {\n" , elem -> id );
418+ if (err >= 0 )
419+ err = tplg_save_printf (dst , pfx , "\tscale {\n" );
420+ if (err >= 0 && scale -> min )
421+ err = tplg_save_printf (dst , pfx , "\t\tmin %i\n" , scale -> min );
422+ if (err >= 0 && scale -> step > 0 )
423+ err = tplg_save_printf (dst , pfx , "\t\tstep %i\n" , scale -> step );
424+ if (err >= 0 && scale -> mute > 0 )
425+ err = tplg_save_printf (dst , pfx , "\t\tmute %i\n" , scale -> mute );
426+ if (err >= 0 )
427+ err = tplg_save_printf (dst , pfx , "\t}\n" );
428+ if (err >= 0 )
429+ err = tplg_save_printf (dst , pfx , "}\n" );
430+ return err ;
431+ }
432+
361433/* Parse Control Bytes */
362434int tplg_parse_control_bytes (snd_tplg_t * tplg ,
363435 snd_config_t * cfg ,
@@ -430,7 +502,7 @@ int tplg_parse_control_bytes(snd_tplg_t *tplg,
430502 }
431503
432504 if (strcmp (id , "data" ) == 0 ) {
433- err = tplg_parse_data_refs (n , elem );
505+ err = tplg_parse_refs (n , elem , SND_TPLG_TYPE_DATA );
434506 if (err < 0 )
435507 return err ;
436508 continue ;
@@ -485,6 +557,49 @@ int tplg_parse_control_bytes(snd_tplg_t *tplg,
485557 return 0 ;
486558}
487559
560+ /* save control bytes */
561+ int tplg_save_control_bytes (snd_tplg_t * tplg ATTRIBUTE_UNUSED ,
562+ struct tplg_elem * elem ,
563+ char * * dst , const char * pfx )
564+ {
565+ struct snd_soc_tplg_bytes_control * be = elem -> bytes_ext ;
566+ char pfx2 [16 ];
567+ int err ;
568+
569+ if (!be )
570+ return 0 ;
571+
572+ snprintf (pfx2 , sizeof (pfx2 ), "%s\t" , pfx ?: "" );
573+ err = tplg_save_printf (dst , NULL , "'%s' {\n" , elem -> id );
574+ if (err < 0 )
575+ return err ;
576+ if (err >= 0 && elem -> index > 0 )
577+ err = tplg_save_printf (dst , pfx , "\tindex %u\n" , elem -> index );
578+ if (err >= 0 && be -> base > 0 )
579+ err = tplg_save_printf (dst , pfx , "\tbase %u\n" , be -> base );
580+ if (err >= 0 && be -> num_regs > 0 )
581+ err = tplg_save_printf (dst , pfx , "\tnum_regs %u\n" , be -> num_regs );
582+ if (err >= 0 && be -> max > 0 )
583+ err = tplg_save_printf (dst , pfx , "\tmax %u\n" , be -> max );
584+ if (err >= 0 && be -> mask > 0 )
585+ err = tplg_save_printf (dst , pfx , "\tmask %u\n" , be -> mask );
586+ if (err >= 0 )
587+ err = tplg_save_ops (tplg , & be -> hdr , dst , pfx2 );
588+ if (err >= 0 )
589+ err = tplg_save_ext_ops (tplg , be , dst , pfx2 );
590+ if (err >= 0 )
591+ err = tplg_save_access (tplg , & be -> hdr , dst , pfx2 );
592+ if (err >= 0 )
593+ err = tplg_save_refs (tplg , elem , SND_TPLG_TYPE_TLV ,
594+ "tlv" , dst , pfx2 );
595+ if (err >= 0 )
596+ err = tplg_save_refs (tplg , elem , SND_TPLG_TYPE_DATA ,
597+ "data" , dst , pfx2 );
598+ if (err >= 0 )
599+ err = tplg_save_printf (dst , pfx , "}\n" );
600+ return err ;
601+ }
602+
488603/* Parse Control Enums. */
489604int tplg_parse_control_enum (snd_tplg_t * tplg , snd_config_t * cfg ,
490605 void * private ATTRIBUTE_UNUSED )
@@ -559,7 +674,7 @@ int tplg_parse_control_enum(snd_tplg_t *tplg, snd_config_t *cfg,
559674 }
560675
561676 if (strcmp (id , "data" ) == 0 ) {
562- err = tplg_parse_data_refs (n , elem );
677+ err = tplg_parse_refs (n , elem , SND_TPLG_TYPE_DATA );
563678 if (err < 0 )
564679 return err ;
565680 continue ;
@@ -582,6 +697,42 @@ int tplg_parse_control_enum(snd_tplg_t *tplg, snd_config_t *cfg,
582697 return 0 ;
583698}
584699
700+ /* save control eunm */
701+ int tplg_save_control_enum (snd_tplg_t * tplg ATTRIBUTE_UNUSED ,
702+ struct tplg_elem * elem ,
703+ char * * dst , const char * pfx )
704+ {
705+ struct snd_soc_tplg_enum_control * ec = elem -> enum_ctrl ;
706+ char pfx2 [16 ];
707+ int err ;
708+
709+ if (!ec )
710+ return 0 ;
711+
712+ snprintf (pfx2 , sizeof (pfx2 ), "%s\t" , pfx ?: "" );
713+ err = tplg_save_printf (dst , NULL , "'%s' {\n" , elem -> id );
714+ if (err < 0 )
715+ return err ;
716+ if (err >= 0 && elem -> index > 0 )
717+ err = tplg_save_printf (dst , pfx , "\tindex %u\n" , elem -> index );
718+ if (err >= 0 )
719+ err = tplg_save_refs (tplg , elem , SND_TPLG_TYPE_TEXT ,
720+ "texts" , dst , pfx2 );
721+ if (err >= 0 )
722+ err = tplg_save_channels (tplg , ec -> channel , ec -> num_channels ,
723+ dst , pfx2 );
724+ if (err >= 0 )
725+ err = tplg_save_ops (tplg , & ec -> hdr , dst , pfx2 );
726+ if (err >= 0 )
727+ err = tplg_save_access (tplg , & ec -> hdr , dst , pfx2 );
728+ if (err >= 0 )
729+ err = tplg_save_refs (tplg , elem , SND_TPLG_TYPE_DATA ,
730+ "data" , dst , pfx2 );
731+ if (err >= 0 )
732+ err = tplg_save_printf (dst , pfx , "}\n" );
733+ return err ;
734+ }
735+
585736/* Parse Controls.
586737 *
587738 * Mixer control. Supports multiple channels.
@@ -683,7 +834,7 @@ int tplg_parse_control_mixer(snd_tplg_t *tplg,
683834 }
684835
685836 if (strcmp (id , "data" ) == 0 ) {
686- err = tplg_parse_data_refs (n , elem );
837+ err = tplg_parse_refs (n , elem , SND_TPLG_TYPE_DATA );
687838 if (err < 0 )
688839 return err ;
689840 continue ;
@@ -709,6 +860,46 @@ int tplg_parse_control_mixer(snd_tplg_t *tplg,
709860 return 0 ;
710861}
711862
863+ int tplg_save_control_mixer (snd_tplg_t * tplg ATTRIBUTE_UNUSED ,
864+ struct tplg_elem * elem , char * * dst ,
865+ const char * pfx )
866+ {
867+ struct snd_soc_tplg_mixer_control * mc = elem -> mixer_ctrl ;
868+ char pfx2 [16 ];
869+ int err ;
870+
871+ if (!mc )
872+ return 0 ;
873+ err = tplg_save_printf (dst , NULL , "'%s' {\n" , elem -> id );
874+ if (err < 0 )
875+ return err ;
876+ snprintf (pfx2 , sizeof (pfx2 ), "%s\t" , pfx ?: "" );
877+ if (err >= 0 && elem -> index > 0 )
878+ err = tplg_save_printf (dst , pfx , "\tindex %u\n" , elem -> index );
879+ if (err >= 0 )
880+ err = tplg_save_channels (tplg , mc -> channel , mc -> num_channels ,
881+ dst , pfx2 );
882+ if (err >= 0 && mc -> max > 0 )
883+ err = tplg_save_printf (dst , pfx , "\tmax %u\n" , mc -> max );
884+ if (err >= 0 && mc -> invert > 0 )
885+ err = tplg_save_printf (dst , pfx , "\tinvert 1\n" , mc -> max );
886+ if (err >= 0 && mc -> invert > 0 )
887+ err = tplg_save_printf (dst , pfx , "\tinvert 1\n" , mc -> max );
888+ if (err >= 0 )
889+ err = tplg_save_ops (tplg , & mc -> hdr , dst , pfx2 );
890+ if (err >= 0 )
891+ err = tplg_save_access (tplg , & mc -> hdr , dst , pfx2 );
892+ if (err >= 0 )
893+ err = tplg_save_refs (tplg , elem , SND_TPLG_TYPE_TLV ,
894+ "tlv" , dst , pfx2 );
895+ if (err >= 0 )
896+ err = tplg_save_refs (tplg , elem , SND_TPLG_TYPE_DATA ,
897+ "data" , dst , pfx2 );
898+ if (err >= 0 )
899+ err = tplg_save_printf (dst , pfx , "}\n" );
900+ return err ;
901+ }
902+
712903static int init_ctl_hdr (struct snd_soc_tplg_ctl_hdr * hdr ,
713904 struct snd_tplg_ctl_template * t )
714905{
0 commit comments