I have created a platform driver referred from sgtl and other drivers
Below is the source, is it correct. but I a getting timeout when using aplay, but no audio record interface is present.
#include <linux/module.h>
#include <linux/of_platform.h>
#include <sound/soc.h>
#include <linux/of.h>
#include "imx-audmux.h"
struct imx_bt_data {
struct snd_soc_dai_link dai;
struct snd_soc_card card;
struct platform_device *pdev;
};
static int imx_bt_audio_probe(struct platform_device *pdev)
{
struct device_node *ssi_np, *np = pdev->dev.of_node;
struct imx_bt_data *data;
struct platform_device *ssi_pdev;
int ret = 0, int_port, ext_port;
/*
Get the int and ext port from the dtb
*/
ret = of_property_read_u32(np, "mux-int-port", &int_port);
if (ret) {
dev_err(&pdev->dev, "mux-int-port missing or invalid\n");
return ret;
}
ret = of_property_read_u32(np, "mux-ext-port", &ext_port);
if (ret) {
dev_err(&pdev->dev, "mux-ext-port missing or invalid\n");
return ret;
}
/*
* The port numbering in the hardware manual starts at 1, while
* the audmux API expects it starts at 0.
*/
int_port--;
ext_port--;
/*Configure the audmux*/
ret = imx_audmux_v2_configure_port(int_port,
IMX_AUDMUX_V2_PTCR_SYN |
IMX_AUDMUX_V2_PTCR_TFSEL(ext_port) |
IMX_AUDMUX_V2_PTCR_TCSEL(ext_port) |
IMX_AUDMUX_V2_PTCR_TFSDIR |
IMX_AUDMUX_V2_PTCR_TCLKDIR,
IMX_AUDMUX_V2_PDCR_RXDSEL(ext_port));
if (ret) {
dev_err(&pdev->dev, "audmux internal port setup failed\n");
return ret;
}
ret = imx_audmux_v2_configure_port(ext_port,
IMX_AUDMUX_V2_PTCR_SYN,
IMX_AUDMUX_V2_PDCR_RXDSEL(int_port));
if (ret) {
dev_err(&pdev->dev, "audmux external port setup failed\n");
return ret;
}
//Get the i2s controller from dtb
ssi_np = of_parse_phandle(pdev->dev.of_node, "ssi-controller", 0);
if (!ssi_np) {
dev_err(&pdev->dev, "phandle missing or invalid\n");
ret = -EINVAL;
goto fail;
}
//find the i2s node and get its pdev struct
ssi_pdev = of_find_device_by_node(ssi_np);
if (!ssi_pdev) {
dev_err(&pdev->dev, "failed to find SSI platform device\n");
ret = -EINVAL;
goto fail;
}
data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL);
if (!data) {
dev_err(&pdev->dev, "failed to allocate memory\n");
ret = -ENOMEM;
goto fail;
}
data->dai.name = "ESOM BT HiFi";
data->dai.stream_name = "Bluetooth Headphone";
data->dai.codec_dai_name = "snd-soc-dummy-dai";
data->dai.codec_name = "snd-soc-dummy";
data->dai.cpu_of_node = ssi_np;
data->dai.platform_of_node = ssi_np;
data->dai.dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
SND_SOC_DAIFMT_CBM_CFM;
data->card.dev = &pdev->dev;
data->card.num_links = 1;
data->card.dai_link = &data->dai;
data->pdev = platform_device_register_simple("bluetooth", -1, NULL, 0);
if (IS_ERR(data->pdev)) {
ret = PTR_ERR(data->pdev);
dev_err(&pdev->dev, "register failed: %d\n", ret);
goto fail;
}
//Fill in the card details
ret = snd_soc_of_parse_card_name(&data->card, "model");
if (ret)
goto fail;
data->card.num_links = 1;
data->card.owner = THIS_MODULE;
data->card.dai_link = &data->dai;
platform_set_drvdata(pdev, &data->card);
snd_soc_card_set_drvdata(&data->card, data);
ret = snd_soc_register_card(&data->card);
if (ret) {
dev_err(&pdev->dev, "snd_soc_register_card failed: %d\n", ret);
goto fail;
}
// Done, set the driver data.
platform_set_drvdata(pdev, data);
fail:
if (ssi_np)
of_node_put(ssi_np);
return ret;
}
static int imx_bt_audio_remove(struct platform_device *pdev)
{
struct snd_soc_card *card = platform_get_drvdata(pdev);
struct imx_bt_data *data = snd_soc_card_get_drvdata(card);
snd_soc_unregister_card(card);
platform_device_unregister(data->pdev);
return 0;
}
static const struct of_device_id imx_bt_dt_ids[] = {
{ .compatible = "fsl,imx-audio-bt", },
{ }
};
MODULE_DEVICE_TABLE(of, imx_bt_dt_ids);
static struct platform_driver imx_bt_driver = {
.driver = {
.name = "imx-audio-bt",
.owner = THIS_MODULE,
.pm = &snd_soc_pm_ops,
.of_match_table = imx_bt_dt_ids,
},
.probe = imx_bt_audio_probe,
.remove = imx_bt_audio_remove,
};
module_platform_driver(imx_bt_driver);@