// SPDX-License-Identifier: GPL-2.0
//
// ASoC Audio Graph Card2 support
//
// Copyright (C) 2020 Renesas Electronics Corp.
// Copyright (C) 2020 Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
//
// based on ${LINUX}/sound/soc/generic/audio-graph-card.c
#include <linux/clk.h>
#include <linux/device.h>
#include <linux/gpio.h>
#include <linux/gpio/consumer.h>
#include <linux/module.h>
#include <linux/of.h>
#include <linux/of_graph.h>
#include <linux/platform_device.h>
#include <linux/string.h>
#include <sound/graph_card.h>
/************************************
daifmt
************************************
ports {
format = "left_j";
port@0 {
bitclock-master;
sample0: endpoint@0 {
frame-master;
};
sample1: endpoint@1 {
format = "i2s";
};
};
...
};
You can set daifmt at ports/port/endpoint.
It uses *latest* format, and *share* master settings.
In above case,
sample0: left_j, bitclock-master, frame-master
sample1: i2s, bitclock-master
If there was no settings, *Codec* will be
bitclock/frame provider as default.
see
graph_parse_daifmt().
"format" property is no longer needed on DT if both CPU/Codec drivers are
supporting snd_soc_dai_ops :: .auto_selectable_formats.
see
snd_soc_runtime_get_dai_fmt()
sample driver
linux/sound/soc/sh/rcar/core.c
linux/sound/soc/codecs/ak4613.c
linux/sound/soc/codecs/pcm3168a.c
linux/sound/soc/soc-utils.c
linux/sound/soc/generic/test-component.c
************************************
Normal Audio-Graph
************************************
CPU <---> Codec
sound {
compatible = "audio-graph-card2";
links = <&cpu>;
};
CPU {
cpu: port {
bitclock-master;
frame-master;
cpu_ep: endpoint { remote-endpoint = <&codec_ep>; }; };
};
Codec {
port { codec_ep: endpoint { remote-endpoint = <&cpu_ep>; }; };
};
************************************
Multi-CPU/Codec
************************************
It has link connection part (= X,x) and list part (= A,B,a,b).
"links" is connection part of CPU side (= @).
+----+ +---+
CPU1 --|A X| <-@----> |x a|-- Codec1
CPU2 --|B | | b|-- Codec2
+----+ +---+
sound {
compatible = "audio-graph-card2";
(@) links = <&mcpu>;
multi {
ports@0 {
(@) mcpu: port@0 { mcpu0_ep: endpoint { remote-endpoint = <&mcodec0_ep>; }; }; // (X) to pair
port@1 { mcpu1_ep: endpoint { remote-endpoint = <&cpu1_ep>; }; }; // (A) Multi Element
port@2 { mcpu2_ep: endpoint { remote-endpoint = <&cpu2_ep>; }; }; // (B) Multi Element
};
ports@1 {
port@0 { mcodec0_ep: endpoint { remote-endpoint = <&mcpu0_ep>; }; }; // (x) to pair
port@1 { mcodec1_ep: endpoint { remote-endpoint = <&codec1_ep>; }; }; // (a) Multi Element
port@2 { mcodec2_ep: endpoint { remote-endpoint = <&codec2_ep>; }; }; // (b) Multi Element
};
};
};
CPU {
ports {
bitclock-master;
frame-master;
port@0 { cpu1_ep: endpoint { remote-endpoint = <&mcpu1_ep>; }; };
port@1 { cpu2_ep: endpoint { remote-endpoint = <&mcpu2_ep>; }; };
};
};
Codec {
ports {
port@0 { codec1_ep: endpoint { remote-endpoint = <&mcodec1_ep>; }; };
port@1 { codec2_ep: endpoint { remote-endpoint = <&mcodec2_ep>; }; };
};
};
************************************
DPCM
************************************
DSP
************
PCM0 <--> * fe0 be0 * <--> DAI0: Codec Headset
PCM1 <--> * fe1 be1 * <--> DAI1: Codec Speakers
PCM2 <--> * fe2 be2 * <--> DAI2: MODEM
PCM3 <--> * f