Skip to content

Commit d70be62

Browse files
mripardbroonie
authored andcommitted
ASoC: sun4i-i2s: Move the channel configuration to a callback
The two main generations of our I2S controller require a slightly different channel configuration, mostly because of a quite different register layout and some additional registers being needed on the newer generation. This used to be controlled through a bunch of booleans, however this proved to be quite impractical, especially since a bunch of SoCs forgot to set those parameters and therefore were broken from that point of view. Fixes: 21faaea ("ASoC: sun4i-i2s: Add support for A83T") Signed-off-by: Maxime Ripard <maxime.ripard@bootlin.com> Link: https://lore.kernel.org/r/6414463de69584e8227fa495b13aa5f4798e1f0e.1566242458.git-series.maxime.ripard@bootlin.com Signed-off-by: Mark Brown <broonie@kernel.org>
1 parent dd28d54 commit d70be62

1 file changed

Lines changed: 69 additions & 87 deletions

File tree

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

Lines changed: 69 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@
8080
#define SUN4I_I2S_TX_CNT_REG 0x2c
8181

8282
#define SUN4I_I2S_TX_CHAN_SEL_REG 0x30
83+
#define SUN4I_I2S_CHAN_SEL_MASK GENMASK(2, 0)
8384
#define SUN4I_I2S_CHAN_SEL(num_chan) (((num_chan) - 1) << 0)
8485

8586
#define SUN4I_I2S_TX_CHAN_MAP_REG 0x34
@@ -122,8 +123,6 @@ struct sun4i_i2s;
122123
* @has_reset: SoC needs reset deasserted.
123124
* @has_slave_select_bit: SoC has a bit to enable slave mode.
124125
* @has_fmt_set_lrck_period: SoC requires lrclk period to be set.
125-
* @has_chcfg: tx and rx slot number need to be set.
126-
* @has_chsel_tx_chen: SoC requires that the tx channels are enabled.
127126
* @has_chsel_offset: SoC uses offset for selecting dai operational mode.
128127
* @reg_offset_txdata: offset of the tx fifo.
129128
* @sun4i_i2s_regmap: regmap config to use.
@@ -135,17 +134,11 @@ struct sun4i_i2s;
135134
* @field_fmt_bclk: regmap field to set clk polarity.
136135
* @field_fmt_lrclk: regmap field to set frame polarity.
137136
* @field_fmt_mode: regmap field to set the operational mode.
138-
* @field_txchanmap: location of the tx channel mapping register.
139-
* @field_rxchanmap: location of the rx channel mapping register.
140-
* @field_txchansel: location of the tx channel select bit fields.
141-
* @field_rxchansel: location of the rx channel select bit fields.
142137
*/
143138
struct sun4i_i2s_quirks {
144139
bool has_reset;
145140
bool has_slave_select_bit;
146141
bool has_fmt_set_lrck_period;
147-
bool has_chcfg;
148-
bool has_chsel_tx_chen;
149142
bool has_chsel_offset;
150143
unsigned int reg_offset_txdata; /* TX FIFO */
151144
const struct regmap_config *sun4i_i2s_regmap;
@@ -159,13 +152,11 @@ struct sun4i_i2s_quirks {
159152
struct reg_field field_fmt_bclk;
160153
struct reg_field field_fmt_lrclk;
161154
struct reg_field field_fmt_mode;
162-
struct reg_field field_txchanmap;
163-
struct reg_field field_rxchanmap;
164-
struct reg_field field_txchansel;
165-
struct reg_field field_rxchansel;
166155

167156
s8 (*get_sr)(const struct sun4i_i2s *, int);
168157
s8 (*get_wss)(const struct sun4i_i2s *, int);
158+
int (*set_chan_cfg)(const struct sun4i_i2s *,
159+
const struct snd_pcm_hw_params *);
169160
};
170161

171162
struct sun4i_i2s {
@@ -186,10 +177,6 @@ struct sun4i_i2s {
186177
struct regmap_field *field_fmt_bclk;
187178
struct regmap_field *field_fmt_lrclk;
188179
struct regmap_field *field_fmt_mode;
189-
struct regmap_field *field_txchanmap;
190-
struct regmap_field *field_rxchanmap;
191-
struct regmap_field *field_txchansel;
192-
struct regmap_field *field_rxchansel;
193180

194181
const struct sun4i_i2s_quirks *variant;
195182
};
@@ -380,44 +367,77 @@ static s8 sun8i_i2s_get_sr_wss(const struct sun4i_i2s *i2s, int width)
380367
return (width - 8) / 4 + 1;
381368
}
382369

383-
static int sun4i_i2s_hw_params(struct snd_pcm_substream *substream,
384-
struct snd_pcm_hw_params *params,
385-
struct snd_soc_dai *dai)
370+
static int sun4i_i2s_set_chan_cfg(const struct sun4i_i2s *i2s,
371+
const struct snd_pcm_hw_params *params)
386372
{
387-
struct sun4i_i2s *i2s = snd_soc_dai_get_drvdata(dai);
388-
int sr, wss, channels;
389-
u32 width;
373+
unsigned int channels = params_channels(params);
390374

391-
channels = params_channels(params);
392-
if (channels != 2) {
393-
dev_err(dai->dev, "Unsupported number of channels: %d\n",
394-
channels);
375+
if (channels != 2)
395376
return -EINVAL;
396-
}
397377

398-
if (i2s->variant->has_chcfg) {
399-
regmap_update_bits(i2s->regmap, SUN8I_I2S_CHAN_CFG_REG,
400-
SUN8I_I2S_CHAN_CFG_TX_SLOT_NUM_MASK,
401-
SUN8I_I2S_CHAN_CFG_TX_SLOT_NUM(channels));
402-
regmap_update_bits(i2s->regmap, SUN8I_I2S_CHAN_CFG_REG,
403-
SUN8I_I2S_CHAN_CFG_RX_SLOT_NUM_MASK,
404-
SUN8I_I2S_CHAN_CFG_RX_SLOT_NUM(channels));
405-
}
378+
/* Map the channels for playback and capture */
379+
regmap_write(i2s->regmap, SUN4I_I2S_TX_CHAN_MAP_REG, 0x76543210);
380+
regmap_write(i2s->regmap, SUN4I_I2S_RX_CHAN_MAP_REG, 0x00003210);
381+
382+
/* Configure the channels */
383+
regmap_update_bits(i2s->regmap, SUN4I_I2S_TX_CHAN_SEL_REG,
384+
SUN4I_I2S_CHAN_SEL_MASK,
385+
SUN4I_I2S_CHAN_SEL(channels));
386+
regmap_update_bits(i2s->regmap, SUN4I_I2S_RX_CHAN_SEL_REG,
387+
SUN4I_I2S_CHAN_SEL_MASK,
388+
SUN4I_I2S_CHAN_SEL(channels));
389+
390+
return 0;
391+
}
392+
393+
static int sun8i_i2s_set_chan_cfg(const struct sun4i_i2s *i2s,
394+
const struct snd_pcm_hw_params *params)
395+
{
396+
unsigned int channels = params_channels(params);
397+
398+
if (channels != 2)
399+
return -EINVAL;
406400

407401
/* Map the channels for playback and capture */
408-
regmap_field_write(i2s->field_txchanmap, 0x76543210);
409-
regmap_field_write(i2s->field_rxchanmap, 0x00003210);
402+
regmap_write(i2s->regmap, SUN8I_I2S_TX_CHAN_MAP_REG, 0x76543210);
403+
regmap_write(i2s->regmap, SUN8I_I2S_RX_CHAN_MAP_REG, 0x76543210);
410404

411405
/* Configure the channels */
412-
regmap_field_write(i2s->field_txchansel,
406+
regmap_update_bits(i2s->regmap, SUN8I_I2S_TX_CHAN_SEL_REG,
407+
SUN4I_I2S_CHAN_SEL_MASK,
413408
SUN4I_I2S_CHAN_SEL(channels));
414-
regmap_field_write(i2s->field_rxchansel,
409+
410+
regmap_update_bits(i2s->regmap, SUN8I_I2S_RX_CHAN_SEL_REG,
411+
SUN4I_I2S_CHAN_SEL_MASK,
415412
SUN4I_I2S_CHAN_SEL(channels));
416413

417-
if (i2s->variant->has_chsel_tx_chen)
418-
regmap_update_bits(i2s->regmap, SUN8I_I2S_TX_CHAN_SEL_REG,
419-
SUN8I_I2S_TX_CHAN_EN_MASK,
420-
SUN8I_I2S_TX_CHAN_EN(channels));
414+
regmap_update_bits(i2s->regmap, SUN8I_I2S_CHAN_CFG_REG,
415+
SUN8I_I2S_CHAN_CFG_TX_SLOT_NUM_MASK,
416+
SUN8I_I2S_CHAN_CFG_TX_SLOT_NUM(channels));
417+
regmap_update_bits(i2s->regmap, SUN8I_I2S_CHAN_CFG_REG,
418+
SUN8I_I2S_CHAN_CFG_RX_SLOT_NUM_MASK,
419+
SUN8I_I2S_CHAN_CFG_RX_SLOT_NUM(channels));
420+
421+
regmap_update_bits(i2s->regmap, SUN8I_I2S_TX_CHAN_SEL_REG,
422+
SUN8I_I2S_TX_CHAN_EN_MASK,
423+
SUN8I_I2S_TX_CHAN_EN(channels));
424+
425+
return 0;
426+
}
427+
428+
static int sun4i_i2s_hw_params(struct snd_pcm_substream *substream,
429+
struct snd_pcm_hw_params *params,
430+
struct snd_soc_dai *dai)
431+
{
432+
struct sun4i_i2s *i2s = snd_soc_dai_get_drvdata(dai);
433+
int ret, sr, wss;
434+
u32 width;
435+
436+
ret = i2s->variant->set_chan_cfg(i2s, params);
437+
if (ret < 0) {
438+
dev_err(dai->dev, "Invalid channel configuration\n");
439+
return ret;
440+
}
421441

422442
switch (params_physical_width(params)) {
423443
case 16:
@@ -915,12 +935,9 @@ static const struct sun4i_i2s_quirks sun4i_a10_i2s_quirks = {
915935
.field_fmt_lrclk = REG_FIELD(SUN4I_I2S_FMT0_REG, 7, 7),
916936
.has_slave_select_bit = true,
917937
.field_fmt_mode = REG_FIELD(SUN4I_I2S_FMT0_REG, 0, 1),
918-
.field_txchanmap = REG_FIELD(SUN4I_I2S_TX_CHAN_MAP_REG, 0, 31),
919-
.field_rxchanmap = REG_FIELD(SUN4I_I2S_RX_CHAN_MAP_REG, 0, 31),
920-
.field_txchansel = REG_FIELD(SUN4I_I2S_TX_CHAN_SEL_REG, 0, 2),
921-
.field_rxchansel = REG_FIELD(SUN4I_I2S_RX_CHAN_SEL_REG, 0, 2),
922938
.get_sr = sun4i_i2s_get_sr,
923939
.get_wss = sun4i_i2s_get_wss,
940+
.set_chan_cfg = sun4i_i2s_set_chan_cfg,
924941
};
925942

926943
static const struct sun4i_i2s_quirks sun6i_a31_i2s_quirks = {
@@ -934,12 +951,9 @@ static const struct sun4i_i2s_quirks sun6i_a31_i2s_quirks = {
934951
.field_fmt_lrclk = REG_FIELD(SUN4I_I2S_FMT0_REG, 7, 7),
935952
.has_slave_select_bit = true,
936953
.field_fmt_mode = REG_FIELD(SUN4I_I2S_FMT0_REG, 0, 1),
937-
.field_txchanmap = REG_FIELD(SUN4I_I2S_TX_CHAN_MAP_REG, 0, 31),
938-
.field_rxchanmap = REG_FIELD(SUN4I_I2S_RX_CHAN_MAP_REG, 0, 31),
939-
.field_txchansel = REG_FIELD(SUN4I_I2S_TX_CHAN_SEL_REG, 0, 2),
940-
.field_rxchansel = REG_FIELD(SUN4I_I2S_RX_CHAN_SEL_REG, 0, 2),
941954
.get_sr = sun4i_i2s_get_sr,
942955
.get_wss = sun4i_i2s_get_wss,
956+
.set_chan_cfg = sun4i_i2s_set_chan_cfg,
943957
};
944958

945959
static const struct sun4i_i2s_quirks sun8i_a83t_i2s_quirks = {
@@ -953,12 +967,9 @@ static const struct sun4i_i2s_quirks sun8i_a83t_i2s_quirks = {
953967
.field_fmt_lrclk = REG_FIELD(SUN4I_I2S_FMT0_REG, 7, 7),
954968
.has_slave_select_bit = true,
955969
.field_fmt_mode = REG_FIELD(SUN4I_I2S_FMT0_REG, 0, 1),
956-
.field_txchanmap = REG_FIELD(SUN4I_I2S_TX_CHAN_MAP_REG, 0, 31),
957-
.field_rxchanmap = REG_FIELD(SUN4I_I2S_RX_CHAN_MAP_REG, 0, 31),
958-
.field_txchansel = REG_FIELD(SUN4I_I2S_TX_CHAN_SEL_REG, 0, 2),
959-
.field_rxchansel = REG_FIELD(SUN4I_I2S_RX_CHAN_SEL_REG, 0, 2),
960970
.get_sr = sun8i_i2s_get_sr_wss,
961971
.get_wss = sun8i_i2s_get_sr_wss,
972+
.set_chan_cfg = sun8i_i2s_set_chan_cfg,
962973
};
963974

964975
static const struct sun4i_i2s_quirks sun8i_h3_i2s_quirks = {
@@ -968,21 +979,16 @@ static const struct sun4i_i2s_quirks sun8i_h3_i2s_quirks = {
968979
.mclk_offset = 1,
969980
.bclk_offset = 2,
970981
.has_fmt_set_lrck_period = true,
971-
.has_chcfg = true,
972-
.has_chsel_tx_chen = true,
973982
.has_chsel_offset = true,
974983
.field_clkdiv_mclk_en = REG_FIELD(SUN4I_I2S_CLK_DIV_REG, 8, 8),
975984
.field_fmt_wss = REG_FIELD(SUN4I_I2S_FMT0_REG, 0, 2),
976985
.field_fmt_sr = REG_FIELD(SUN4I_I2S_FMT0_REG, 4, 6),
977986
.field_fmt_bclk = REG_FIELD(SUN4I_I2S_FMT0_REG, 7, 7),
978987
.field_fmt_lrclk = REG_FIELD(SUN4I_I2S_FMT0_REG, 19, 19),
979988
.field_fmt_mode = REG_FIELD(SUN4I_I2S_CTRL_REG, 4, 5),
980-
.field_txchanmap = REG_FIELD(SUN8I_I2S_TX_CHAN_MAP_REG, 0, 31),
981-
.field_rxchanmap = REG_FIELD(SUN8I_I2S_RX_CHAN_MAP_REG, 0, 31),
982-
.field_txchansel = REG_FIELD(SUN8I_I2S_TX_CHAN_SEL_REG, 0, 2),
983-
.field_rxchansel = REG_FIELD(SUN8I_I2S_RX_CHAN_SEL_REG, 0, 2),
984989
.get_sr = sun8i_i2s_get_sr_wss,
985990
.get_wss = sun8i_i2s_get_sr_wss,
991+
.set_chan_cfg = sun8i_i2s_set_chan_cfg,
986992
};
987993

988994
static const struct sun4i_i2s_quirks sun50i_a64_codec_i2s_quirks = {
@@ -996,12 +1002,9 @@ static const struct sun4i_i2s_quirks sun50i_a64_codec_i2s_quirks = {
9961002
.field_fmt_bclk = REG_FIELD(SUN4I_I2S_FMT0_REG, 6, 6),
9971003
.field_fmt_lrclk = REG_FIELD(SUN4I_I2S_FMT0_REG, 7, 7),
9981004
.field_fmt_mode = REG_FIELD(SUN4I_I2S_FMT0_REG, 0, 1),
999-
.field_txchanmap = REG_FIELD(SUN4I_I2S_TX_CHAN_MAP_REG, 0, 31),
1000-
.field_rxchanmap = REG_FIELD(SUN4I_I2S_RX_CHAN_MAP_REG, 0, 31),
1001-
.field_txchansel = REG_FIELD(SUN4I_I2S_TX_CHAN_SEL_REG, 0, 2),
1002-
.field_rxchansel = REG_FIELD(SUN4I_I2S_RX_CHAN_SEL_REG, 0, 2),
10031005
.get_sr = sun4i_i2s_get_sr,
10041006
.get_wss = sun4i_i2s_get_wss,
1007+
.set_chan_cfg = sun4i_i2s_set_chan_cfg,
10051008
};
10061009

10071010
static int sun4i_i2s_init_regmap_fields(struct device *dev,
@@ -1043,28 +1046,7 @@ static int sun4i_i2s_init_regmap_fields(struct device *dev,
10431046
if (IS_ERR(i2s->field_fmt_mode))
10441047
return PTR_ERR(i2s->field_fmt_mode);
10451048

1046-
i2s->field_txchanmap =
1047-
devm_regmap_field_alloc(dev, i2s->regmap,
1048-
i2s->variant->field_txchanmap);
1049-
if (IS_ERR(i2s->field_txchanmap))
1050-
return PTR_ERR(i2s->field_txchanmap);
1051-
1052-
i2s->field_rxchanmap =
1053-
devm_regmap_field_alloc(dev, i2s->regmap,
1054-
i2s->variant->field_rxchanmap);
1055-
if (IS_ERR(i2s->field_rxchanmap))
1056-
return PTR_ERR(i2s->field_rxchanmap);
1057-
1058-
i2s->field_txchansel =
1059-
devm_regmap_field_alloc(dev, i2s->regmap,
1060-
i2s->variant->field_txchansel);
1061-
if (IS_ERR(i2s->field_txchansel))
1062-
return PTR_ERR(i2s->field_txchansel);
1063-
1064-
i2s->field_rxchansel =
1065-
devm_regmap_field_alloc(dev, i2s->regmap,
1066-
i2s->variant->field_rxchansel);
1067-
return PTR_ERR_OR_ZERO(i2s->field_rxchansel);
1049+
return 0;
10681050
}
10691051

10701052
static int sun4i_i2s_probe(struct platform_device *pdev)

0 commit comments

Comments
 (0)