Skip to content

Commit 515fcfb

Browse files
mripardbroonie
authored andcommitted
ASoC: sun4i-i2s: Fix LRCK and BCLK polarity offsets on newer SoCs
The LRCK and BCLK polarity offsets on newer SoCs has been changed, yet the driver didn't take it into account for all of them. This was taken into account for the H3, but not the A83t. This was handled using a reg_field for the H3. However, the value in that field will not be the same, so reg_field is not adapted in that case. Let's change for proper calls with the regular values. Fixes: 21faaea ("ASoC: sun4i-i2s: Add support for A83T") Signed-off-by: Maxime Ripard <maxime.ripard@bootlin.com> Link: https://lore.kernel.org/r/9cbdde80a299288878e58225df4d7884e0301348.1566242458.git-series.maxime.ripard@bootlin.com Signed-off-by: Mark Brown <broonie@kernel.org>
1 parent cf2c0e1 commit 515fcfb

1 file changed

Lines changed: 60 additions & 58 deletions

File tree

‎sound/soc/sunxi/sun4i-i2s.c‎

Lines changed: 60 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,6 @@
4646
#define SUN4I_I2S_FMT0_FMT_RIGHT_J (2 << 0)
4747
#define SUN4I_I2S_FMT0_FMT_LEFT_J (1 << 0)
4848
#define SUN4I_I2S_FMT0_FMT_I2S (0 << 0)
49-
#define SUN4I_I2S_FMT0_POLARITY_INVERTED (1)
50-
#define SUN4I_I2S_FMT0_POLARITY_NORMAL (0)
5149

5250
#define SUN4I_I2S_FMT1_REG 0x08
5351
#define SUN4I_I2S_FIFO_TX_REG 0x0c
@@ -98,8 +96,14 @@
9896
#define SUN8I_I2S_CTRL_MODE_LEFT (1 << 4)
9997
#define SUN8I_I2S_CTRL_MODE_PCM (0 << 4)
10098

99+
#define SUN8I_I2S_FMT0_LRCLK_POLARITY_MASK BIT(19)
100+
#define SUN8I_I2S_FMT0_LRCLK_POLARITY_INVERTED (1 << 19)
101+
#define SUN8I_I2S_FMT0_LRCLK_POLARITY_NORMAL (0 << 19)
101102
#define SUN8I_I2S_FMT0_LRCK_PERIOD_MASK GENMASK(17, 8)
102103
#define SUN8I_I2S_FMT0_LRCK_PERIOD(period) ((period - 1) << 8)
104+
#define SUN8I_I2S_FMT0_BCLK_POLARITY_MASK BIT(7)
105+
#define SUN8I_I2S_FMT0_BCLK_POLARITY_INVERTED (1 << 7)
106+
#define SUN8I_I2S_FMT0_BCLK_POLARITY_NORMAL (0 << 7)
103107

104108
#define SUN8I_I2S_INT_STA_REG 0x0c
105109
#define SUN8I_I2S_FIFO_TX_REG 0x20
@@ -132,8 +136,6 @@ struct sun4i_i2s;
132136
* @field_clkdiv_mclk_en: regmap field to enable mclk output.
133137
* @field_fmt_wss: regmap field to set word select size.
134138
* @field_fmt_sr: regmap field to set sample resolution.
135-
* @field_fmt_bclk: regmap field to set clk polarity.
136-
* @field_fmt_lrclk: regmap field to set frame polarity.
137139
*/
138140
struct sun4i_i2s_quirks {
139141
bool has_reset;
@@ -145,8 +147,6 @@ struct sun4i_i2s_quirks {
145147
struct reg_field field_clkdiv_mclk_en;
146148
struct reg_field field_fmt_wss;
147149
struct reg_field field_fmt_sr;
148-
struct reg_field field_fmt_bclk;
149-
struct reg_field field_fmt_lrclk;
150150

151151
const struct sun4i_i2s_clk_div *bclk_dividers;
152152
unsigned int num_bclk_dividers;
@@ -176,8 +176,6 @@ struct sun4i_i2s {
176176
struct regmap_field *field_clkdiv_mclk_en;
177177
struct regmap_field *field_fmt_wss;
178178
struct regmap_field *field_fmt_sr;
179-
struct regmap_field *field_fmt_bclk;
180-
struct regmap_field *field_fmt_lrclk;
181179

182180
const struct sun4i_i2s_quirks *variant;
183181
};
@@ -498,6 +496,33 @@ static int sun4i_i2s_set_soc_fmt(const struct sun4i_i2s *i2s,
498496
{
499497
u32 val;
500498

499+
/* DAI clock polarity */
500+
switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
501+
case SND_SOC_DAIFMT_IB_IF:
502+
/* Invert both clocks */
503+
val = SUN4I_I2S_FMT0_BCLK_POLARITY_INVERTED |
504+
SUN4I_I2S_FMT0_LRCLK_POLARITY_INVERTED;
505+
break;
506+
case SND_SOC_DAIFMT_IB_NF:
507+
/* Invert bit clock */
508+
val = SUN4I_I2S_FMT0_BCLK_POLARITY_INVERTED;
509+
break;
510+
case SND_SOC_DAIFMT_NB_IF:
511+
/* Invert frame clock */
512+
val = SUN4I_I2S_FMT0_LRCLK_POLARITY_INVERTED;
513+
break;
514+
case SND_SOC_DAIFMT_NB_NF:
515+
val = 0;
516+
break;
517+
default:
518+
return -EINVAL;
519+
}
520+
521+
regmap_update_bits(i2s->regmap, SUN4I_I2S_FMT0_REG,
522+
SUN4I_I2S_FMT0_LRCLK_POLARITY_MASK |
523+
SUN4I_I2S_FMT0_BCLK_POLARITY_MASK,
524+
val);
525+
501526
/* DAI Mode */
502527
switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
503528
case SND_SOC_DAIFMT_I2S:
@@ -545,6 +570,33 @@ static int sun8i_i2s_set_soc_fmt(const struct sun4i_i2s *i2s,
545570
u32 mode, val;
546571
u8 offset;
547572

573+
/* DAI clock polarity */
574+
switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
575+
case SND_SOC_DAIFMT_IB_IF:
576+
/* Invert both clocks */
577+
val = SUN8I_I2S_FMT0_BCLK_POLARITY_INVERTED |
578+
SUN8I_I2S_FMT0_LRCLK_POLARITY_INVERTED;
579+
break;
580+
case SND_SOC_DAIFMT_IB_NF:
581+
/* Invert bit clock */
582+
val = SUN8I_I2S_FMT0_BCLK_POLARITY_INVERTED;
583+
break;
584+
case SND_SOC_DAIFMT_NB_IF:
585+
/* Invert frame clock */
586+
val = SUN8I_I2S_FMT0_LRCLK_POLARITY_INVERTED;
587+
break;
588+
case SND_SOC_DAIFMT_NB_NF:
589+
val = 0;
590+
break;
591+
default:
592+
return -EINVAL;
593+
}
594+
595+
regmap_update_bits(i2s->regmap, SUN4I_I2S_FMT0_REG,
596+
SUN8I_I2S_FMT0_LRCLK_POLARITY_MASK |
597+
SUN8I_I2S_FMT0_BCLK_POLARITY_MASK,
598+
val);
599+
548600
/* DAI Mode */
549601
switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
550602
case SND_SOC_DAIFMT_I2S:
@@ -601,36 +653,8 @@ static int sun8i_i2s_set_soc_fmt(const struct sun4i_i2s *i2s,
601653
static int sun4i_i2s_set_fmt(struct snd_soc_dai *dai, unsigned int fmt)
602654
{
603655
struct sun4i_i2s *i2s = snd_soc_dai_get_drvdata(dai);
604-
u32 bclk_polarity = SUN4I_I2S_FMT0_POLARITY_NORMAL;
605-
u32 lrclk_polarity = SUN4I_I2S_FMT0_POLARITY_NORMAL;
606656
int ret;
607657

608-
/* DAI clock polarity */
609-
switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
610-
case SND_SOC_DAIFMT_IB_IF:
611-
/* Invert both clocks */
612-
bclk_polarity = SUN4I_I2S_FMT0_POLARITY_INVERTED;
613-
lrclk_polarity = SUN4I_I2S_FMT0_POLARITY_INVERTED;
614-
break;
615-
case SND_SOC_DAIFMT_IB_NF:
616-
/* Invert bit clock */
617-
bclk_polarity = SUN4I_I2S_FMT0_POLARITY_INVERTED;
618-
break;
619-
case SND_SOC_DAIFMT_NB_IF:
620-
/* Invert frame clock */
621-
lrclk_polarity = SUN4I_I2S_FMT0_POLARITY_INVERTED;
622-
break;
623-
case SND_SOC_DAIFMT_NB_NF:
624-
break;
625-
default:
626-
dev_err(dai->dev, "Unsupported clock polarity: %d\n",
627-
fmt & SND_SOC_DAIFMT_INV_MASK);
628-
return -EINVAL;
629-
}
630-
631-
regmap_field_write(i2s->field_fmt_bclk, bclk_polarity);
632-
regmap_field_write(i2s->field_fmt_lrclk, lrclk_polarity);
633-
634658
ret = i2s->variant->set_fmt(i2s, fmt);
635659
if (ret) {
636660
dev_err(dai->dev, "Unsupported format configuration\n");
@@ -984,8 +1008,6 @@ static const struct sun4i_i2s_quirks sun4i_a10_i2s_quirks = {
9841008
.field_clkdiv_mclk_en = REG_FIELD(SUN4I_I2S_CLK_DIV_REG, 7, 7),
9851009
.field_fmt_wss = REG_FIELD(SUN4I_I2S_FMT0_REG, 2, 3),
9861010
.field_fmt_sr = REG_FIELD(SUN4I_I2S_FMT0_REG, 4, 5),
987-
.field_fmt_bclk = REG_FIELD(SUN4I_I2S_FMT0_REG, 6, 6),
988-
.field_fmt_lrclk = REG_FIELD(SUN4I_I2S_FMT0_REG, 7, 7),
9891011
.bclk_dividers = sun4i_i2s_bclk_div,
9901012
.num_bclk_dividers = ARRAY_SIZE(sun4i_i2s_bclk_div),
9911013
.mclk_dividers = sun4i_i2s_mclk_div,
@@ -1004,8 +1026,6 @@ static const struct sun4i_i2s_quirks sun6i_a31_i2s_quirks = {
10041026
.field_clkdiv_mclk_en = REG_FIELD(SUN4I_I2S_CLK_DIV_REG, 7, 7),
10051027
.field_fmt_wss = REG_FIELD(SUN4I_I2S_FMT0_REG, 2, 3),
10061028
.field_fmt_sr = REG_FIELD(SUN4I_I2S_FMT0_REG, 4, 5),
1007-
.field_fmt_bclk = REG_FIELD(SUN4I_I2S_FMT0_REG, 6, 6),
1008-
.field_fmt_lrclk = REG_FIELD(SUN4I_I2S_FMT0_REG, 7, 7),
10091029
.bclk_dividers = sun4i_i2s_bclk_div,
10101030
.num_bclk_dividers = ARRAY_SIZE(sun4i_i2s_bclk_div),
10111031
.mclk_dividers = sun4i_i2s_mclk_div,
@@ -1024,8 +1044,6 @@ static const struct sun4i_i2s_quirks sun8i_a83t_i2s_quirks = {
10241044
.field_clkdiv_mclk_en = REG_FIELD(SUN4I_I2S_CLK_DIV_REG, 7, 7),
10251045
.field_fmt_wss = REG_FIELD(SUN4I_I2S_FMT0_REG, 2, 3),
10261046
.field_fmt_sr = REG_FIELD(SUN4I_I2S_FMT0_REG, 4, 5),
1027-
.field_fmt_bclk = REG_FIELD(SUN4I_I2S_FMT0_REG, 6, 6),
1028-
.field_fmt_lrclk = REG_FIELD(SUN4I_I2S_FMT0_REG, 7, 7),
10291047
.bclk_dividers = sun8i_i2s_clk_div,
10301048
.num_bclk_dividers = ARRAY_SIZE(sun8i_i2s_clk_div),
10311049
.mclk_dividers = sun8i_i2s_clk_div,
@@ -1045,8 +1063,6 @@ static const struct sun4i_i2s_quirks sun8i_h3_i2s_quirks = {
10451063
.field_clkdiv_mclk_en = REG_FIELD(SUN4I_I2S_CLK_DIV_REG, 8, 8),
10461064
.field_fmt_wss = REG_FIELD(SUN4I_I2S_FMT0_REG, 0, 2),
10471065
.field_fmt_sr = REG_FIELD(SUN4I_I2S_FMT0_REG, 4, 6),
1048-
.field_fmt_bclk = REG_FIELD(SUN4I_I2S_FMT0_REG, 7, 7),
1049-
.field_fmt_lrclk = REG_FIELD(SUN4I_I2S_FMT0_REG, 19, 19),
10501066
.bclk_dividers = sun8i_i2s_clk_div,
10511067
.num_bclk_dividers = ARRAY_SIZE(sun8i_i2s_clk_div),
10521068
.mclk_dividers = sun8i_i2s_clk_div,
@@ -1065,8 +1081,6 @@ static const struct sun4i_i2s_quirks sun50i_a64_codec_i2s_quirks = {
10651081
.field_clkdiv_mclk_en = REG_FIELD(SUN4I_I2S_CLK_DIV_REG, 7, 7),
10661082
.field_fmt_wss = REG_FIELD(SUN4I_I2S_FMT0_REG, 2, 3),
10671083
.field_fmt_sr = REG_FIELD(SUN4I_I2S_FMT0_REG, 4, 5),
1068-
.field_fmt_bclk = REG_FIELD(SUN4I_I2S_FMT0_REG, 6, 6),
1069-
.field_fmt_lrclk = REG_FIELD(SUN4I_I2S_FMT0_REG, 7, 7),
10701084
.bclk_dividers = sun4i_i2s_bclk_div,
10711085
.num_bclk_dividers = ARRAY_SIZE(sun4i_i2s_bclk_div),
10721086
.mclk_dividers = sun4i_i2s_mclk_div,
@@ -1099,18 +1113,6 @@ static int sun4i_i2s_init_regmap_fields(struct device *dev,
10991113
if (IS_ERR(i2s->field_fmt_sr))
11001114
return PTR_ERR(i2s->field_fmt_sr);
11011115

1102-
i2s->field_fmt_bclk =
1103-
devm_regmap_field_alloc(dev, i2s->regmap,
1104-
i2s->variant->field_fmt_bclk);
1105-
if (IS_ERR(i2s->field_fmt_bclk))
1106-
return PTR_ERR(i2s->field_fmt_bclk);
1107-
1108-
i2s->field_fmt_lrclk =
1109-
devm_regmap_field_alloc(dev, i2s->regmap,
1110-
i2s->variant->field_fmt_lrclk);
1111-
if (IS_ERR(i2s->field_fmt_lrclk))
1112-
return PTR_ERR(i2s->field_fmt_lrclk);
1113-
11141116
return 0;
11151117
}
11161118

0 commit comments

Comments
 (0)