Path: blob/master/sound/soc/generic/audio-graph-card2-custom-sample.c
26424 views
// SPDX-License-Identifier: GPL-2.01//2// audio-graph-card2-custom-sample.c3//4// Copyright (C) 2020 Renesas Electronics Corp.5// Copyright (C) 2020 Kuninori Morimoto <[email protected]>6//7#include <linux/device.h>8#include <linux/mod_devicetable.h>9#include <linux/module.h>10#include <linux/platform_device.h>11#include <sound/graph_card.h>1213/*14* Custom driver can have own priv15* which includes simple_util_priv.16*/17struct custom_priv {18struct simple_util_priv simple_priv;1920/* custom driver's own params */21int custom_params;22};2324/* You can get custom_priv from simple_priv */25#define simple_to_custom(simple) container_of((simple), struct custom_priv, simple_priv)2627static int custom_card_probe(struct snd_soc_card *card)28{29struct simple_util_priv *simple_priv = snd_soc_card_get_drvdata(card);30struct custom_priv *custom_priv = simple_to_custom(simple_priv);31struct device *dev = simple_priv_to_dev(simple_priv);3233dev_info(dev, "custom probe\n");3435custom_priv->custom_params = 1;3637/* you can use generic probe function */38return graph_util_card_probe(card);39}4041static int custom_hook_pre(struct simple_util_priv *priv)42{43struct device *dev = simple_priv_to_dev(priv);4445/* You can custom before parsing */46dev_info(dev, "hook : %s\n", __func__);4748return 0;49}5051static int custom_hook_post(struct simple_util_priv *priv)52{53struct device *dev = simple_priv_to_dev(priv);54struct snd_soc_card *card;5556/* You can custom after parsing */57dev_info(dev, "hook : %s\n", __func__);5859/* overwrite .probe sample */60card = simple_priv_to_card(priv);61card->probe = custom_card_probe;6263return 0;64}6566static int custom_normal(struct simple_util_priv *priv,67struct device_node *lnk,68struct link_info *li)69{70struct device *dev = simple_priv_to_dev(priv);7172/*73* You can custom Normal parsing74* before/affter audio_graph2_link_normal()75*/76dev_info(dev, "hook : %s\n", __func__);7778return audio_graph2_link_normal(priv, lnk, li);79}8081static int custom_dpcm(struct simple_util_priv *priv,82struct device_node *lnk,83struct link_info *li)84{85struct device *dev = simple_priv_to_dev(priv);8687/*88* You can custom DPCM parsing89* before/affter audio_graph2_link_dpcm()90*/91dev_info(dev, "hook : %s\n", __func__);9293return audio_graph2_link_dpcm(priv, lnk, li);94}9596static int custom_c2c(struct simple_util_priv *priv,97struct device_node *lnk,98struct link_info *li)99{100struct device *dev = simple_priv_to_dev(priv);101102/*103* You can custom Codec2Codec parsing104* before/affter audio_graph2_link_c2c()105*/106dev_info(dev, "hook : %s\n", __func__);107108return audio_graph2_link_c2c(priv, lnk, li);109}110111/*112* audio-graph-card2 has many hooks for your customizing.113*/114static struct graph2_custom_hooks custom_hooks = {115.hook_pre = custom_hook_pre,116.hook_post = custom_hook_post,117.custom_normal = custom_normal,118.custom_dpcm = custom_dpcm,119.custom_c2c = custom_c2c,120};121122static int custom_startup(struct snd_pcm_substream *substream)123{124struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream);125struct simple_util_priv *priv = snd_soc_card_get_drvdata(rtd->card);126struct device *dev = simple_priv_to_dev(priv);127128dev_info(dev, "custom startup\n");129130return simple_util_startup(substream);131}132133/* You can use custom ops */134static const struct snd_soc_ops custom_ops = {135.startup = custom_startup,136.shutdown = simple_util_shutdown,137.hw_params = simple_util_hw_params,138};139140static int custom_probe(struct platform_device *pdev)141{142struct custom_priv *custom_priv;143struct simple_util_priv *simple_priv;144struct device *dev = &pdev->dev;145int ret;146147custom_priv = devm_kzalloc(dev, sizeof(*custom_priv), GFP_KERNEL);148if (!custom_priv)149return -ENOMEM;150151simple_priv = &custom_priv->simple_priv;152simple_priv->ops = &custom_ops; /* customize dai_link ops */153154/* "audio-graph-card2-custom-sample" is too long */155simple_priv->snd_card.name = "card2-custom";156157/* use audio-graph-card2 parsing with own custom hooks */158ret = audio_graph2_parse_of(simple_priv, dev, &custom_hooks);159if (ret < 0)160return ret;161162/* customize more if needed */163164return 0;165}166167static const struct of_device_id custom_of_match[] = {168{ .compatible = "audio-graph-card2-custom-sample", },169{},170};171MODULE_DEVICE_TABLE(of, custom_of_match);172173static struct platform_driver custom_card = {174.driver = {175.name = "audio-graph-card2-custom-sample",176.of_match_table = custom_of_match,177},178.probe = custom_probe,179.remove = simple_util_remove,180};181module_platform_driver(custom_card);182183MODULE_ALIAS("platform:asoc-audio-graph-card2-custom-sample");184MODULE_LICENSE("GPL v2");185MODULE_DESCRIPTION("ASoC Audio Graph Card2 Custom Sample");186MODULE_AUTHOR("Kuninori Morimoto <[email protected]>");187188189