Skip to content

Commit 4a15b24

Browse files
wensbroonie
authored andcommitted
ASoC: sun4i-codec: Add support for H3 codec
The codec on the H3 is similar to the one found on the A31. One key difference is the analog path controls are routed through the PRCM block. This is supported by the sun8i-codec-analog driver, and tied into this codec driver with the audio card's aux_dev. In addition, the H3 has no HP (headphone) and HBIAS support, and no MIC3 input. The FIFO related registers are slightly rearranged. Signed-off-by: Chen-Yu Tsai <[email protected]> Acked-by: Rob Herring <[email protected]> Acked-by: Maxime Ripard <[email protected]> Signed-off-by: Mark Brown <[email protected]>
1 parent dac5f86 commit 4a15b24

File tree

2 files changed

+74
-0
lines changed

2 files changed

+74
-0
lines changed

Documentation/devicetree/bindings/sound/sun4i-codec.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ Required properties:
66
- "allwinner,sun6i-a31-codec"
77
- "allwinner,sun7i-a20-codec"
88
- "allwinner,sun8i-a23-codec"
9+
- "allwinner,sun8i-h3-codec"
910
- reg: must contain the registers location and length
1011
- interrupts: must contain the codec interrupt
1112
- dmas: DMA channels for tx and rx dma. See the DMA client binding,
@@ -23,6 +24,7 @@ Optional properties:
2324
Required properties for the following compatibles:
2425
- "allwinner,sun6i-a31-codec"
2526
- "allwinner,sun8i-a23-codec"
27+
- "allwinner,sun8i-h3-codec"
2628
- resets: phandle to the reset control for this device
2729
- allwinner,audio-routing: A list of the connections between audio components.
2830
Each entry is a pair of strings, the first being the
@@ -52,6 +54,7 @@ Required properties for the following compatibles:
5254

5355
Required properties for the following compatibles:
5456
- "allwinner,sun8i-a23-codec"
57+
- "allwinner,sun8i-h3-codec"
5558
- allwinner,codec-analog-controls: A phandle to the codec analog controls
5659
block in the PRCM.
5760

sound/soc/sunxi/sun4i-codec.c

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,13 @@
217217
#define SUN8I_A23_CODEC_DAC_TXCNT (0x1c)
218218
#define SUN8I_A23_CODEC_ADC_RXCNT (0x20)
219219

220+
/* TX FIFO moved on H3 */
221+
#define SUN8I_H3_CODEC_DAC_TXDATA (0x20)
222+
#define SUN8I_H3_CODEC_DAC_DBG (0x48)
223+
#define SUN8I_H3_CODEC_ADC_DBG (0x4c)
224+
225+
/* TODO H3 DAP (Digital Audio Processing) bits */
226+
220227
struct sun4i_codec {
221228
struct device *dev;
222229
struct regmap *regmap;
@@ -1293,6 +1300,44 @@ static struct snd_soc_card *sun8i_a23_codec_create_card(struct device *dev)
12931300
return card;
12941301
};
12951302

1303+
static struct snd_soc_card *sun8i_h3_codec_create_card(struct device *dev)
1304+
{
1305+
struct snd_soc_card *card;
1306+
int ret;
1307+
1308+
card = devm_kzalloc(dev, sizeof(*card), GFP_KERNEL);
1309+
if (!card)
1310+
return ERR_PTR(-ENOMEM);
1311+
1312+
aux_dev.codec_of_node = of_parse_phandle(dev->of_node,
1313+
"allwinner,codec-analog-controls",
1314+
0);
1315+
if (!aux_dev.codec_of_node) {
1316+
dev_err(dev, "Can't find analog controls for codec.\n");
1317+
return ERR_PTR(-EINVAL);
1318+
};
1319+
1320+
card->dai_link = sun4i_codec_create_link(dev, &card->num_links);
1321+
if (!card->dai_link)
1322+
return ERR_PTR(-ENOMEM);
1323+
1324+
card->dev = dev;
1325+
card->name = "H3 Audio Codec";
1326+
card->dapm_widgets = sun6i_codec_card_dapm_widgets;
1327+
card->num_dapm_widgets = ARRAY_SIZE(sun6i_codec_card_dapm_widgets);
1328+
card->dapm_routes = sun8i_codec_card_routes;
1329+
card->num_dapm_routes = ARRAY_SIZE(sun8i_codec_card_routes);
1330+
card->aux_dev = &aux_dev;
1331+
card->num_aux_devs = 1;
1332+
card->fully_routed = true;
1333+
1334+
ret = snd_soc_of_parse_audio_routing(card, "allwinner,audio-routing");
1335+
if (ret)
1336+
dev_warn(dev, "failed to parse audio-routing: %d\n", ret);
1337+
1338+
return card;
1339+
};
1340+
12961341
static const struct regmap_config sun4i_codec_regmap_config = {
12971342
.reg_bits = 32,
12981343
.reg_stride = 4,
@@ -1321,6 +1366,13 @@ static const struct regmap_config sun8i_a23_codec_regmap_config = {
13211366
.max_register = SUN8I_A23_CODEC_ADC_RXCNT,
13221367
};
13231368

1369+
static const struct regmap_config sun8i_h3_codec_regmap_config = {
1370+
.reg_bits = 32,
1371+
.reg_stride = 4,
1372+
.val_bits = 32,
1373+
.max_register = SUN8I_H3_CODEC_ADC_DBG,
1374+
};
1375+
13241376
struct sun4i_codec_quirks {
13251377
const struct regmap_config *regmap_config;
13261378
const struct snd_soc_codec_driver *codec;
@@ -1369,6 +1421,21 @@ static const struct sun4i_codec_quirks sun8i_a23_codec_quirks = {
13691421
.has_reset = true,
13701422
};
13711423

1424+
static const struct sun4i_codec_quirks sun8i_h3_codec_quirks = {
1425+
.regmap_config = &sun8i_h3_codec_regmap_config,
1426+
/*
1427+
* TODO Share the codec structure with A23 for now.
1428+
* This should be split out when adding digital audio
1429+
* processing support for the H3.
1430+
*/
1431+
.codec = &sun8i_a23_codec_codec,
1432+
.create_card = sun8i_h3_codec_create_card,
1433+
.reg_adc_fifoc = REG_FIELD(SUN6I_CODEC_ADC_FIFOC, 0, 31),
1434+
.reg_dac_txdata = SUN8I_H3_CODEC_DAC_TXDATA,
1435+
.reg_adc_rxdata = SUN6I_CODEC_ADC_RXDATA,
1436+
.has_reset = true,
1437+
};
1438+
13721439
static const struct of_device_id sun4i_codec_of_match[] = {
13731440
{
13741441
.compatible = "allwinner,sun4i-a10-codec",
@@ -1386,6 +1453,10 @@ static const struct of_device_id sun4i_codec_of_match[] = {
13861453
.compatible = "allwinner,sun8i-a23-codec",
13871454
.data = &sun8i_a23_codec_quirks,
13881455
},
1456+
{
1457+
.compatible = "allwinner,sun8i-h3-codec",
1458+
.data = &sun8i_h3_codec_quirks,
1459+
},
13891460
{}
13901461
};
13911462
MODULE_DEVICE_TABLE(of, sun4i_codec_of_match);

0 commit comments

Comments
 (0)