9393#define SUN8I_I2S_CTRL_BCLK_OUT BIT(18)
9494#define SUN8I_I2S_CTRL_LRCK_OUT BIT(17)
9595
96+ #define SUN8I_I2S_CTRL_MODE_MASK GENMASK(5, 4)
97+ #define SUN8I_I2S_CTRL_MODE_RIGHT (2 << 4)
98+ #define SUN8I_I2S_CTRL_MODE_LEFT (1 << 4)
99+ #define SUN8I_I2S_CTRL_MODE_PCM (0 << 4)
100+
96101#define SUN8I_I2S_FMT0_LRCK_PERIOD_MASK GENMASK(17, 8)
97102#define SUN8I_I2S_FMT0_LRCK_PERIOD (period ) ((period - 1) << 8)
98103
@@ -121,9 +126,7 @@ struct sun4i_i2s;
121126 * struct sun4i_i2s_quirks - Differences between SoC variants.
122127 *
123128 * @has_reset: SoC needs reset deasserted.
124- * @has_slave_select_bit: SoC has a bit to enable slave mode.
125129 * @has_fmt_set_lrck_period: SoC requires lrclk period to be set.
126- * @has_chsel_offset: SoC uses offset for selecting dai operational mode.
127130 * @reg_offset_txdata: offset of the tx fifo.
128131 * @sun4i_i2s_regmap: regmap config to use.
129132 * @mclk_offset: Value by which mclkdiv needs to be adjusted.
@@ -133,13 +136,10 @@ struct sun4i_i2s;
133136 * @field_fmt_sr: regmap field to set sample resolution.
134137 * @field_fmt_bclk: regmap field to set clk polarity.
135138 * @field_fmt_lrclk: regmap field to set frame polarity.
136- * @field_fmt_mode: regmap field to set the operational mode.
137139 */
138140struct sun4i_i2s_quirks {
139141 bool has_reset ;
140- bool has_slave_select_bit ;
141142 bool has_fmt_set_lrck_period ;
142- bool has_chsel_offset ;
143143 unsigned int reg_offset_txdata ; /* TX FIFO */
144144 const struct regmap_config * sun4i_i2s_regmap ;
145145 unsigned int mclk_offset ;
@@ -151,12 +151,12 @@ struct sun4i_i2s_quirks {
151151 struct reg_field field_fmt_sr ;
152152 struct reg_field field_fmt_bclk ;
153153 struct reg_field field_fmt_lrclk ;
154- struct reg_field field_fmt_mode ;
155154
156155 s8 (* get_sr )(const struct sun4i_i2s * , int );
157156 s8 (* get_wss )(const struct sun4i_i2s * , int );
158157 int (* set_chan_cfg )(const struct sun4i_i2s * ,
159158 const struct snd_pcm_hw_params * );
159+ int (* set_fmt )(const struct sun4i_i2s * , unsigned int );
160160};
161161
162162struct sun4i_i2s {
@@ -176,7 +176,6 @@ struct sun4i_i2s {
176176 struct regmap_field * field_fmt_sr ;
177177 struct regmap_field * field_fmt_bclk ;
178178 struct regmap_field * field_fmt_lrclk ;
179- struct regmap_field * field_fmt_mode ;
180179
181180 const struct sun4i_i2s_quirks * variant ;
182181};
@@ -465,52 +464,117 @@ static int sun4i_i2s_hw_params(struct snd_pcm_substream *substream,
465464 params_width (params ));
466465}
467466
468- static int sun4i_i2s_set_fmt (struct snd_soc_dai * dai , unsigned int fmt )
467+ static int sun4i_i2s_set_soc_fmt (const struct sun4i_i2s * i2s ,
468+ unsigned int fmt )
469469{
470- struct sun4i_i2s * i2s = snd_soc_dai_get_drvdata (dai );
471470 u32 val ;
472- u32 offset = 0 ;
473- u32 bclk_polarity = SUN4I_I2S_FMT0_POLARITY_NORMAL ;
474- u32 lrclk_polarity = SUN4I_I2S_FMT0_POLARITY_NORMAL ;
475471
476472 /* DAI Mode */
477473 switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK ) {
478474 case SND_SOC_DAIFMT_I2S :
479475 val = SUN4I_I2S_FMT0_FMT_I2S ;
480- offset = 1 ;
481476 break ;
477+
482478 case SND_SOC_DAIFMT_LEFT_J :
483479 val = SUN4I_I2S_FMT0_FMT_LEFT_J ;
484480 break ;
481+
485482 case SND_SOC_DAIFMT_RIGHT_J :
486483 val = SUN4I_I2S_FMT0_FMT_RIGHT_J ;
487484 break ;
485+
488486 default :
489- dev_err (dai -> dev , "Unsupported format: %d\n" ,
490- fmt & SND_SOC_DAIFMT_FORMAT_MASK );
491487 return - EINVAL ;
492488 }
493489
494- if (i2s -> variant -> has_chsel_offset ) {
495- /*
496- * offset being set indicates that we're connected to an i2s
497- * device, however offset is only used on the sun8i block and
498- * i2s shares the same setting with the LJ format. Increment
499- * val so that the bit to value to write is correct.
500- */
501- if ( offset > 0 )
502- val ++ ;
503- /* blck offset determines whether i2s or LJ */
504- regmap_update_bits ( i2s -> regmap , SUN8I_I2S_TX_CHAN_SEL_REG ,
505- SUN8I_I2S_TX_CHAN_OFFSET_MASK ,
506- SUN8I_I2S_TX_CHAN_OFFSET ( offset )) ;
507-
508- regmap_update_bits ( i2s -> regmap , SUN8I_I2S_RX_CHAN_SEL_REG ,
509- SUN8I_I2S_TX_CHAN_OFFSET_MASK ,
510- SUN8I_I2S_TX_CHAN_OFFSET ( offset )) ;
490+ regmap_update_bits (i2s -> regmap , SUN4I_I2S_FMT0_REG ,
491+ SUN4I_I2S_FMT0_FMT_MASK , val );
492+
493+ /* DAI clock master masks */
494+ switch ( fmt & SND_SOC_DAIFMT_MASTER_MASK ) {
495+ case SND_SOC_DAIFMT_CBS_CFS :
496+ /* BCLK and LRCLK master */
497+ val = SUN4I_I2S_CTRL_MODE_MASTER ;
498+ break ;
499+
500+ case SND_SOC_DAIFMT_CBM_CFM :
501+ /* BCLK and LRCLK slave */
502+ val = SUN4I_I2S_CTRL_MODE_SLAVE ;
503+ break ;
504+
505+ default :
506+ return - EINVAL ;
511507 }
508+ regmap_update_bits (i2s -> regmap , SUN4I_I2S_CTRL_REG ,
509+ SUN4I_I2S_CTRL_MODE_MASK , val );
510+ return 0 ;
511+ }
512512
513- regmap_field_write (i2s -> field_fmt_mode , val );
513+ static int sun8i_i2s_set_soc_fmt (const struct sun4i_i2s * i2s ,
514+ unsigned int fmt )
515+ {
516+ u32 mode , val ;
517+ u8 offset ;
518+
519+ /* DAI Mode */
520+ switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK ) {
521+ case SND_SOC_DAIFMT_I2S :
522+ mode = SUN8I_I2S_CTRL_MODE_LEFT ;
523+ offset = 1 ;
524+ break ;
525+
526+ case SND_SOC_DAIFMT_LEFT_J :
527+ mode = SUN8I_I2S_CTRL_MODE_LEFT ;
528+ offset = 0 ;
529+ break ;
530+
531+ case SND_SOC_DAIFMT_RIGHT_J :
532+ mode = SUN8I_I2S_CTRL_MODE_RIGHT ;
533+ offset = 0 ;
534+ break ;
535+
536+ default :
537+ return - EINVAL ;
538+ }
539+
540+ regmap_update_bits (i2s -> regmap , SUN4I_I2S_CTRL_REG ,
541+ SUN8I_I2S_CTRL_MODE_MASK , mode );
542+ regmap_update_bits (i2s -> regmap , SUN8I_I2S_TX_CHAN_SEL_REG ,
543+ SUN8I_I2S_TX_CHAN_OFFSET_MASK ,
544+ SUN8I_I2S_TX_CHAN_OFFSET (offset ));
545+ regmap_update_bits (i2s -> regmap , SUN8I_I2S_RX_CHAN_SEL_REG ,
546+ SUN8I_I2S_TX_CHAN_OFFSET_MASK ,
547+ SUN8I_I2S_TX_CHAN_OFFSET (offset ));
548+
549+ /* DAI clock master masks */
550+ switch (fmt & SND_SOC_DAIFMT_MASTER_MASK ) {
551+ case SND_SOC_DAIFMT_CBS_CFS :
552+ /* BCLK and LRCLK master */
553+ val = SUN8I_I2S_CTRL_BCLK_OUT | SUN8I_I2S_CTRL_LRCK_OUT ;
554+ break ;
555+
556+ case SND_SOC_DAIFMT_CBM_CFM :
557+ /* BCLK and LRCLK slave */
558+ val = 0 ;
559+ break ;
560+
561+ default :
562+ return - EINVAL ;
563+ }
564+
565+ regmap_update_bits (i2s -> regmap , SUN4I_I2S_CTRL_REG ,
566+ SUN8I_I2S_CTRL_BCLK_OUT | SUN8I_I2S_CTRL_LRCK_OUT ,
567+ val );
568+
569+ return 0 ;
570+ }
571+
572+ static int sun4i_i2s_set_fmt (struct snd_soc_dai * dai , unsigned int fmt )
573+ {
574+ struct sun4i_i2s * i2s = snd_soc_dai_get_drvdata (dai );
575+ u32 bclk_polarity = SUN4I_I2S_FMT0_POLARITY_NORMAL ;
576+ u32 lrclk_polarity = SUN4I_I2S_FMT0_POLARITY_NORMAL ;
577+ int ret ;
514578
515579 /* DAI clock polarity */
516580 switch (fmt & SND_SOC_DAIFMT_INV_MASK ) {
@@ -538,50 +602,10 @@ static int sun4i_i2s_set_fmt(struct snd_soc_dai *dai, unsigned int fmt)
538602 regmap_field_write (i2s -> field_fmt_bclk , bclk_polarity );
539603 regmap_field_write (i2s -> field_fmt_lrclk , lrclk_polarity );
540604
541- if (i2s -> variant -> has_slave_select_bit ) {
542- /* DAI clock master masks */
543- switch (fmt & SND_SOC_DAIFMT_MASTER_MASK ) {
544- case SND_SOC_DAIFMT_CBS_CFS :
545- /* BCLK and LRCLK master */
546- val = SUN4I_I2S_CTRL_MODE_MASTER ;
547- break ;
548- case SND_SOC_DAIFMT_CBM_CFM :
549- /* BCLK and LRCLK slave */
550- val = SUN4I_I2S_CTRL_MODE_SLAVE ;
551- break ;
552- default :
553- dev_err (dai -> dev , "Unsupported slave setting: %d\n" ,
554- fmt & SND_SOC_DAIFMT_MASTER_MASK );
555- return - EINVAL ;
556- }
557- regmap_update_bits (i2s -> regmap , SUN4I_I2S_CTRL_REG ,
558- SUN4I_I2S_CTRL_MODE_MASK ,
559- val );
560- } else {
561- /*
562- * The newer i2s block does not have a slave select bit,
563- * instead the clk pins are configured as inputs.
564- */
565- /* DAI clock master masks */
566- switch (fmt & SND_SOC_DAIFMT_MASTER_MASK ) {
567- case SND_SOC_DAIFMT_CBS_CFS :
568- /* BCLK and LRCLK master */
569- val = SUN8I_I2S_CTRL_BCLK_OUT |
570- SUN8I_I2S_CTRL_LRCK_OUT ;
571- break ;
572- case SND_SOC_DAIFMT_CBM_CFM :
573- /* BCLK and LRCLK slave */
574- val = 0 ;
575- break ;
576- default :
577- dev_err (dai -> dev , "Unsupported slave setting: %d\n" ,
578- fmt & SND_SOC_DAIFMT_MASTER_MASK );
579- return - EINVAL ;
580- }
581- regmap_update_bits (i2s -> regmap , SUN4I_I2S_CTRL_REG ,
582- SUN8I_I2S_CTRL_BCLK_OUT |
583- SUN8I_I2S_CTRL_LRCK_OUT ,
584- val );
605+ ret = i2s -> variant -> set_fmt (i2s , fmt );
606+ if (ret ) {
607+ dev_err (dai -> dev , "Unsupported format configuration\n" );
608+ return ret ;
585609 }
586610
587611 /* Set significant bits in our FIFOs */
@@ -933,11 +957,10 @@ static const struct sun4i_i2s_quirks sun4i_a10_i2s_quirks = {
933957 .field_fmt_sr = REG_FIELD (SUN4I_I2S_FMT0_REG , 4 , 5 ),
934958 .field_fmt_bclk = REG_FIELD (SUN4I_I2S_FMT0_REG , 6 , 6 ),
935959 .field_fmt_lrclk = REG_FIELD (SUN4I_I2S_FMT0_REG , 7 , 7 ),
936- .has_slave_select_bit = true,
937- .field_fmt_mode = REG_FIELD (SUN4I_I2S_FMT0_REG , 0 , 1 ),
938960 .get_sr = sun4i_i2s_get_sr ,
939961 .get_wss = sun4i_i2s_get_wss ,
940962 .set_chan_cfg = sun4i_i2s_set_chan_cfg ,
963+ .set_fmt = sun4i_i2s_set_soc_fmt ,
941964};
942965
943966static const struct sun4i_i2s_quirks sun6i_a31_i2s_quirks = {
@@ -949,11 +972,10 @@ static const struct sun4i_i2s_quirks sun6i_a31_i2s_quirks = {
949972 .field_fmt_sr = REG_FIELD (SUN4I_I2S_FMT0_REG , 4 , 5 ),
950973 .field_fmt_bclk = REG_FIELD (SUN4I_I2S_FMT0_REG , 6 , 6 ),
951974 .field_fmt_lrclk = REG_FIELD (SUN4I_I2S_FMT0_REG , 7 , 7 ),
952- .has_slave_select_bit = true,
953- .field_fmt_mode = REG_FIELD (SUN4I_I2S_FMT0_REG , 0 , 1 ),
954975 .get_sr = sun4i_i2s_get_sr ,
955976 .get_wss = sun4i_i2s_get_wss ,
956977 .set_chan_cfg = sun4i_i2s_set_chan_cfg ,
978+ .set_fmt = sun4i_i2s_set_soc_fmt ,
957979};
958980
959981static const struct sun4i_i2s_quirks sun8i_a83t_i2s_quirks = {
@@ -965,11 +987,10 @@ static const struct sun4i_i2s_quirks sun8i_a83t_i2s_quirks = {
965987 .field_fmt_sr = REG_FIELD (SUN4I_I2S_FMT0_REG , 4 , 5 ),
966988 .field_fmt_bclk = REG_FIELD (SUN4I_I2S_FMT0_REG , 6 , 6 ),
967989 .field_fmt_lrclk = REG_FIELD (SUN4I_I2S_FMT0_REG , 7 , 7 ),
968- .has_slave_select_bit = true,
969- .field_fmt_mode = REG_FIELD (SUN4I_I2S_FMT0_REG , 0 , 1 ),
970990 .get_sr = sun8i_i2s_get_sr_wss ,
971991 .get_wss = sun8i_i2s_get_sr_wss ,
972992 .set_chan_cfg = sun8i_i2s_set_chan_cfg ,
993+ .set_fmt = sun8i_i2s_set_soc_fmt ,
973994};
974995
975996static const struct sun4i_i2s_quirks sun8i_h3_i2s_quirks = {
@@ -979,32 +1000,30 @@ static const struct sun4i_i2s_quirks sun8i_h3_i2s_quirks = {
9791000 .mclk_offset = 1 ,
9801001 .bclk_offset = 2 ,
9811002 .has_fmt_set_lrck_period = true,
982- .has_chsel_offset = true,
9831003 .field_clkdiv_mclk_en = REG_FIELD (SUN4I_I2S_CLK_DIV_REG , 8 , 8 ),
9841004 .field_fmt_wss = REG_FIELD (SUN4I_I2S_FMT0_REG , 0 , 2 ),
9851005 .field_fmt_sr = REG_FIELD (SUN4I_I2S_FMT0_REG , 4 , 6 ),
9861006 .field_fmt_bclk = REG_FIELD (SUN4I_I2S_FMT0_REG , 7 , 7 ),
9871007 .field_fmt_lrclk = REG_FIELD (SUN4I_I2S_FMT0_REG , 19 , 19 ),
988- .field_fmt_mode = REG_FIELD (SUN4I_I2S_CTRL_REG , 4 , 5 ),
9891008 .get_sr = sun8i_i2s_get_sr_wss ,
9901009 .get_wss = sun8i_i2s_get_sr_wss ,
9911010 .set_chan_cfg = sun8i_i2s_set_chan_cfg ,
1011+ .set_fmt = sun8i_i2s_set_soc_fmt ,
9921012};
9931013
9941014static const struct sun4i_i2s_quirks sun50i_a64_codec_i2s_quirks = {
9951015 .has_reset = true,
9961016 .reg_offset_txdata = SUN8I_I2S_FIFO_TX_REG ,
9971017 .sun4i_i2s_regmap = & sun4i_i2s_regmap_config ,
998- .has_slave_select_bit = true,
9991018 .field_clkdiv_mclk_en = REG_FIELD (SUN4I_I2S_CLK_DIV_REG , 7 , 7 ),
10001019 .field_fmt_wss = REG_FIELD (SUN4I_I2S_FMT0_REG , 2 , 3 ),
10011020 .field_fmt_sr = REG_FIELD (SUN4I_I2S_FMT0_REG , 4 , 5 ),
10021021 .field_fmt_bclk = REG_FIELD (SUN4I_I2S_FMT0_REG , 6 , 6 ),
10031022 .field_fmt_lrclk = REG_FIELD (SUN4I_I2S_FMT0_REG , 7 , 7 ),
1004- .field_fmt_mode = REG_FIELD (SUN4I_I2S_FMT0_REG , 0 , 1 ),
10051023 .get_sr = sun4i_i2s_get_sr ,
10061024 .get_wss = sun4i_i2s_get_wss ,
10071025 .set_chan_cfg = sun4i_i2s_set_chan_cfg ,
1026+ .set_fmt = sun4i_i2s_set_soc_fmt ,
10081027};
10091028
10101029static int sun4i_i2s_init_regmap_fields (struct device * dev ,
@@ -1040,12 +1059,6 @@ static int sun4i_i2s_init_regmap_fields(struct device *dev,
10401059 if (IS_ERR (i2s -> field_fmt_lrclk ))
10411060 return PTR_ERR (i2s -> field_fmt_lrclk );
10421061
1043- i2s -> field_fmt_mode =
1044- devm_regmap_field_alloc (dev , i2s -> regmap ,
1045- i2s -> variant -> field_fmt_mode );
1046- if (IS_ERR (i2s -> field_fmt_mode ))
1047- return PTR_ERR (i2s -> field_fmt_mode );
1048-
10491062 return 0 ;
10501063}
10511064
0 commit comments