mirror of
https://gitee.com/open-loongarch/linux-5.10.git
synced 2026-10-28 05:57:12 +08:00
Update to 742d8a881
2K300:sound/soc:ls-sound: Unify All ls-sound-<codec> to ls-sound
Code Dai Link automatic matching.
dts:
&sound {
loongson,audio-codec = <&codec>;
loongson,sound-card-name = "ES8388";
//随便写,但要保证同一型号板卡一致性,主要给 alsactl 识别
};
This commit is contained in:
@@ -820,7 +820,6 @@
|
||||
sound: sound{
|
||||
compatible = "loongson,ls-sound";
|
||||
loongson,i2s-controller = <&i2s>;
|
||||
loongson,audio-codec = <&audio>;
|
||||
status = "disabled";
|
||||
};
|
||||
};
|
||||
|
||||
@@ -261,5 +261,8 @@
|
||||
|
||||
&sound {
|
||||
status = "okay";
|
||||
loongson,audio-codec = <&codec>;
|
||||
// Easy Compatible for asound.state Configure
|
||||
loongson,sound-card-name = "ES8388";
|
||||
};
|
||||
|
||||
|
||||
@@ -469,7 +469,6 @@ CONFIG_SND_HDA_CODEC_HDMI=y
|
||||
CONFIG_SND_HDA_CODEC_CONEXANT=y
|
||||
CONFIG_SND_SOC=y
|
||||
CONFIG_SND_SOC_LOONGSON=y
|
||||
CONFIG_SND_SOC_LOONGSON_ES8388=y
|
||||
CONFIG_SND_LS=y
|
||||
CONFIG_SND_LS_PCM_GENERIC_DMA=y
|
||||
CONFIG_SND_SOC_ES8328_I2C=y
|
||||
|
||||
@@ -3,22 +3,6 @@ menuconfig SND_SOC_LOONGSON
|
||||
|
||||
if SND_SOC_LOONGSON
|
||||
|
||||
choice
|
||||
prompt "LOONGSON Codec select"
|
||||
default SND_SOC_LOONGSON_ES8323
|
||||
|
||||
config SND_SOC_LOONGSON_ES8388
|
||||
tristate "SoC I2S Audio support for ES8388 on LOONGSON"
|
||||
|
||||
config SND_SOC_LOONGSON_ES8323
|
||||
tristate "SoC I2S Audio support for ES8323 on LOONGSON"
|
||||
|
||||
config SND_SOC_LOONGSON_CJC8988
|
||||
tristate "SoC I2S Audio support for CJC8988 on LOONGSON"
|
||||
select SND_SOC_CJC8988
|
||||
|
||||
endchoice
|
||||
|
||||
config SND_LS
|
||||
tristate "SoC Audio for ls-i2s"
|
||||
help
|
||||
@@ -38,5 +22,9 @@ config SND_LS_PCM_GENERIC_DMA
|
||||
Say Y or M if you want to add support for codecs attached to
|
||||
the PCM interface. Select this by configuring the generic dma.
|
||||
|
||||
config SND_LS_DAILINK
|
||||
tristate "SoC Audio for Sound-Card/Dai-Link"
|
||||
depends on SND_LS
|
||||
default y
|
||||
|
||||
endif #SND_SOC_LOONGSON
|
||||
|
||||
@@ -1,11 +1,4 @@
|
||||
snd-soc-loongson-es8388-objs := ls-sound-es8388.o
|
||||
snd-soc-loongson-es8323-objs := ls-sound-es8323.o
|
||||
snd-soc-loongson-cjc8988-objs := ls-sound-cjc8988.o
|
||||
|
||||
obj-$(CONFIG_SND_SOC_LOONGSON_ES8388) += snd-soc-loongson-es8388.o
|
||||
obj-$(CONFIG_SND_SOC_LOONGSON_ES8323) += snd-soc-loongson-es8323.o
|
||||
obj-$(CONFIG_SND_SOC_LOONGSON_CJC8988) += snd-soc-loongson-cjc8988.o
|
||||
|
||||
obj-$(CONFIG_SND_LS) += ls-i2s.o
|
||||
obj-$(CONFIG_SND_LS_PCM) += ls-pcm.o
|
||||
obj-$(CONFIG_SND_LS_PCM_GENERIC_DMA) += ls-pcm-generic.o
|
||||
obj-$(CONFIG_SND_LS_DAILINK) += ls-sound.o
|
||||
|
||||
@@ -1,160 +0,0 @@
|
||||
#include <linux/module.h>
|
||||
#include <sound/soc.h>
|
||||
#include <sound/pcm_params.h>
|
||||
#include <linux/of_device.h>
|
||||
|
||||
#include <linux/pci_ids.h>
|
||||
#include <linux/pci.h>
|
||||
|
||||
static int loongson_hw_params(struct snd_pcm_substream *substream,
|
||||
struct snd_pcm_hw_params *params)
|
||||
{
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
static struct snd_soc_ops loongson_dai_link_ops = {
|
||||
.hw_params = loongson_hw_params,
|
||||
};
|
||||
|
||||
enum {
|
||||
PRI_PLAYBACK = 0,
|
||||
PRI_CAPTURE,
|
||||
};
|
||||
/*
|
||||
*SND_SOC_DAIFMT_CBS_CFS play ok, volume ok
|
||||
*SND_SOC_DAIFMT_CBM_CFM Codec's BCLK is Master,LRCLK is Master
|
||||
*/
|
||||
#define LOONGSON_DAI_FMT (SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_IB_NF | \
|
||||
SND_SOC_DAIFMT_CBS_CFS)
|
||||
|
||||
SND_SOC_DAILINK_DEFS(cjc8988_hifi,
|
||||
DAILINK_COMP_ARRAY(COMP_CPU("loongson-i2s-dai")),
|
||||
DAILINK_COMP_ARRAY(COMP_CODEC("cjc8988.1-001b", "cjc8988-hifi")),
|
||||
DAILINK_COMP_ARRAY(COMP_PLATFORM("loongson-i2s")));
|
||||
|
||||
// 驱动不完善,暂时只有播放
|
||||
static struct snd_soc_dai_link loongson_dai_link[] = {
|
||||
[PRI_PLAYBACK] = {
|
||||
/* Primary Playback i/f */
|
||||
.name = "CJC8988 Playback",
|
||||
.stream_name = "Playback",
|
||||
.dai_fmt = LOONGSON_DAI_FMT,
|
||||
.ops = &loongson_dai_link_ops,
|
||||
SND_SOC_DAILINK_REG(cjc8988_hifi),
|
||||
},
|
||||
[PRI_CAPTURE] = {
|
||||
/* Primary Capture i/f */
|
||||
.name = "CJC8988 Capture",
|
||||
.stream_name = "Capture",
|
||||
.dai_fmt = LOONGSON_DAI_FMT,
|
||||
.ops = &loongson_dai_link_ops,
|
||||
SND_SOC_DAILINK_REG(cjc8988_hifi),
|
||||
},
|
||||
};
|
||||
|
||||
static struct snd_soc_card cjc8988= {
|
||||
.name = "Chuanglong CJC8988",
|
||||
.owner = THIS_MODULE,
|
||||
.dai_link = loongson_dai_link,
|
||||
.num_links = ARRAY_SIZE(loongson_dai_link),
|
||||
|
||||
};
|
||||
|
||||
static void put_of_nodes(struct snd_soc_card *card)
|
||||
{
|
||||
struct snd_soc_dai_link *dai_link;
|
||||
int i;
|
||||
|
||||
for_each_card_prelinks(card, i, dai_link) {
|
||||
of_node_put(dai_link->cpus->of_node);
|
||||
of_node_put(dai_link->codecs->of_node);
|
||||
}
|
||||
}
|
||||
|
||||
static int ls_sound_drv_probe(struct platform_device *pdev)
|
||||
{
|
||||
struct device_node *np = pdev->dev.of_node;
|
||||
struct snd_soc_card *card;
|
||||
struct snd_soc_dai_link *dai_link;
|
||||
int ret;
|
||||
|
||||
card = (struct snd_soc_card *)of_device_get_match_data(&pdev->dev);
|
||||
card->dev = &pdev->dev;
|
||||
dai_link = card->dai_link;
|
||||
|
||||
dai_link->cpus->of_node = of_parse_phandle(np, "loongson,i2s-controller", 0);
|
||||
if (!dai_link->cpus->of_node) {
|
||||
dev_err(&pdev->dev,
|
||||
"Property 'loongson,i2s-controller' missing or invalid\n");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (!dai_link->platforms->name)
|
||||
dai_link->platforms->of_node = dai_link->cpus->of_node;
|
||||
|
||||
// name 已指定,不再指定 of_node,否则注册时报错
|
||||
// dai_link->codecs->of_node = of_parse_phandle(np, "loongson,audio-codec", 0);
|
||||
// if (!dai_link->codecs->of_node) {
|
||||
// dev_err(&pdev->dev,
|
||||
// "Property 'loongson,audio-codec' missing or invalid\n");
|
||||
// ret = -EINVAL;
|
||||
// goto err_put_of_nodes;
|
||||
// }
|
||||
|
||||
ret = devm_snd_soc_register_card(card->dev, card);
|
||||
if (ret) {
|
||||
if (ret != -EPROBE_DEFER)
|
||||
dev_err(&pdev->dev,
|
||||
"snd_soc_register_card() failed: %d\n", ret);
|
||||
goto err_put_of_nodes;
|
||||
}
|
||||
return 0;
|
||||
|
||||
err_put_of_nodes:
|
||||
put_of_nodes(card);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int ls_sound_drv_remove(struct platform_device *pdev)
|
||||
{
|
||||
struct snd_soc_card *card = platform_get_drvdata(pdev);
|
||||
|
||||
put_of_nodes(card);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const struct of_device_id snd_ls_sound_dt_match[] = {
|
||||
{ .compatible = "loongson,ls-sound", .data = &cjc8988},
|
||||
{},
|
||||
};
|
||||
MODULE_DEVICE_TABLE(of, snd_ls_sound_dt_match);
|
||||
|
||||
static struct platform_driver ls_sound_driver = {
|
||||
.probe = ls_sound_drv_probe,
|
||||
.remove = ls_sound_drv_remove,
|
||||
.driver = {
|
||||
.name = "ls-sound",
|
||||
.owner = THIS_MODULE,
|
||||
.of_match_table = of_match_ptr(snd_ls_sound_dt_match),
|
||||
},
|
||||
};
|
||||
|
||||
static int __init loongson_audio_init(void)
|
||||
{
|
||||
struct pci_dev *pdev;
|
||||
|
||||
return platform_driver_register(&ls_sound_driver);
|
||||
}
|
||||
module_init(loongson_audio_init);
|
||||
|
||||
static void __exit loongson_audio_exit(void)
|
||||
{
|
||||
platform_driver_unregister(&ls_sound_driver);
|
||||
}
|
||||
module_exit(loongson_audio_exit);
|
||||
|
||||
MODULE_SOFTDEP("pre: ls_pcm ls_i2s snd-soc-wm8988-objs");
|
||||
MODULE_AUTHOR("loongson");
|
||||
MODULE_DESCRIPTION("ALSA SoC loongson");
|
||||
MODULE_LICENSE("GPL");
|
||||
@@ -1,142 +0,0 @@
|
||||
#include <linux/module.h>
|
||||
#include <sound/soc.h>
|
||||
#include <sound/pcm_params.h>
|
||||
|
||||
#include <linux/pci_ids.h>
|
||||
#include <linux/pci.h>
|
||||
|
||||
|
||||
static int loongson_hw_params(struct snd_pcm_substream *substream,
|
||||
struct snd_pcm_hw_params *params)
|
||||
{
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
static struct snd_soc_ops loongson_ops = {
|
||||
.hw_params = loongson_hw_params,
|
||||
};
|
||||
|
||||
static int loongson_es8388_init_paiftx(struct snd_soc_pcm_runtime *rtd)
|
||||
{
|
||||
/* Enabling the microphone requires the fitting of a 0R
|
||||
* resistor to connect the line from the microphone jack.
|
||||
*/
|
||||
snd_soc_dapm_disable_pin(&rtd->card->dapm, "MicIn");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
enum {
|
||||
PRI_PLAYBACK = 0,
|
||||
PRI_CAPTURE,
|
||||
};
|
||||
/*
|
||||
*SND_SOC_DAIFMT_CBS_CFS play ok, volume ok
|
||||
*SND_SOC_DAIFMT_CBM_CFM Codec's BCLK is Master,LRCLK is Master
|
||||
*/
|
||||
#define LOONGSON_DAI_FMT (SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_IB_NF | \
|
||||
SND_SOC_DAIFMT_CBS_CFS)
|
||||
|
||||
static struct snd_soc_dai_link loongson_dai[] = {
|
||||
[PRI_PLAYBACK] = {
|
||||
/* Primary Playback i/f */
|
||||
.name = "ES8388 PAIF RX",
|
||||
.stream_name = "Playback",
|
||||
.cpu_dai_name = "loongson-i2s-dai",
|
||||
.codec_dai_name = "ES8323 HiFi",
|
||||
.platform_name = "loongson-i2s",
|
||||
.dai_fmt = LOONGSON_DAI_FMT,
|
||||
.ops = &loongson_ops,
|
||||
},
|
||||
[PRI_CAPTURE] = {
|
||||
/* Primary Capture i/f */
|
||||
.name = "ES8388 PAIF TX",
|
||||
.stream_name = "Capture",
|
||||
.cpu_dai_name = "loongson-i2s-dai",
|
||||
.codec_dai_name = "ES8323 HiFi",
|
||||
.platform_name = "loongson-i2s",
|
||||
.dai_fmt = LOONGSON_DAI_FMT,
|
||||
.init = loongson_es8388_init_paiftx,
|
||||
.ops = &loongson_ops,
|
||||
},
|
||||
};
|
||||
|
||||
static struct snd_soc_card loongson = {
|
||||
.name = "LOONGSON-I2S",
|
||||
.owner = THIS_MODULE,
|
||||
.dai_link = loongson_dai,
|
||||
.num_links = ARRAY_SIZE(loongson_dai),
|
||||
|
||||
};
|
||||
|
||||
static struct platform_device *loongson_snd_device;
|
||||
|
||||
static int ls_sound_drv_probe(struct platform_device *pdev)
|
||||
{
|
||||
int ret;
|
||||
|
||||
loongson_snd_device = platform_device_alloc("soc-audio", -1);
|
||||
if (!loongson_snd_device)
|
||||
return -ENOMEM;
|
||||
|
||||
platform_set_drvdata(loongson_snd_device, &loongson);
|
||||
ret = platform_device_add(loongson_snd_device);
|
||||
|
||||
if (ret)
|
||||
platform_device_put(loongson_snd_device);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int ls_sound_drv_remove(struct platform_device *pdev)
|
||||
{
|
||||
platform_device_unregister(loongson_snd_device);
|
||||
return 0;
|
||||
}
|
||||
static const struct of_device_id snd_ls_sound_dt_match[] = {
|
||||
{ .compatible = "loongson,ls-sound", },
|
||||
{ .compatible = "loongson,loongson2-sound", },
|
||||
{ .compatible = "loongson,ls7a-sound", },
|
||||
{},
|
||||
};
|
||||
MODULE_DEVICE_TABLE(of, snd_ls_sound_dt_match);
|
||||
|
||||
static struct platform_driver ls_sound_driver = {
|
||||
.probe = ls_sound_drv_probe,
|
||||
.remove = ls_sound_drv_remove,
|
||||
.driver = {
|
||||
.name = "ls-sound",
|
||||
.owner = THIS_MODULE,
|
||||
.of_match_table = of_match_ptr(snd_ls_sound_dt_match),
|
||||
},
|
||||
};
|
||||
|
||||
static int __init loongson_audio_init(void)
|
||||
{
|
||||
struct pci_dev *pdev;
|
||||
|
||||
pdev = pci_get_device(PCI_VENDOR_ID_LOONGSON, PCI_DEVICE_ID_LOONGSON_I2S, NULL);
|
||||
|
||||
if (pdev) {
|
||||
loongson_dai[0].codec_name = "i2c-ESSX8323:00";
|
||||
loongson_dai[1].codec_name = "i2c-ESSX8323:00";
|
||||
} else {
|
||||
loongson_dai[0].codec_name = "ES8323.3-0010";
|
||||
loongson_dai[1].codec_name = "ES8323.3-0010";
|
||||
}
|
||||
|
||||
return platform_driver_register(&ls_sound_driver);
|
||||
}
|
||||
module_init(loongson_audio_init);
|
||||
|
||||
static void __exit loongson_audio_exit(void)
|
||||
{
|
||||
platform_driver_unregister(&ls_sound_driver);
|
||||
}
|
||||
module_exit(loongson_audio_exit);
|
||||
|
||||
MODULE_SOFTDEP("pre: ls_pcm ls_i2s snd_soc_es8323_i2c");
|
||||
MODULE_AUTHOR("loongson");
|
||||
MODULE_DESCRIPTION("ALSA SoC loongson");
|
||||
MODULE_LICENSE("GPL");
|
||||
@@ -1,156 +0,0 @@
|
||||
#include <linux/module.h>
|
||||
#include <sound/soc.h>
|
||||
#include <sound/pcm_params.h>
|
||||
#include <linux/of_device.h>
|
||||
|
||||
#include <linux/pci_ids.h>
|
||||
#include <linux/pci.h>
|
||||
|
||||
static int loongson_hw_params(struct snd_pcm_substream *substream,
|
||||
struct snd_pcm_hw_params *params)
|
||||
{
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
static struct snd_soc_ops loongson_dai_link_ops = {
|
||||
.hw_params = loongson_hw_params,
|
||||
};
|
||||
|
||||
enum {
|
||||
PRI_PLAYBACK = 0,
|
||||
PRI_CAPTURE,
|
||||
};
|
||||
#define LOONGSON_DAI_FMT (SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF | \
|
||||
SND_SOC_DAIFMT_CBM_CFM)
|
||||
// SND_SOC_DAIFMT_CBS_CFS)
|
||||
|
||||
SND_SOC_DAILINK_DEFS(es8388_hifi,
|
||||
DAILINK_COMP_ARRAY(COMP_CPU("loongson-i2s-dai")),
|
||||
DAILINK_COMP_ARRAY(COMP_CODEC("es8328.2-0011", "es8328-hifi-analog")),
|
||||
DAILINK_COMP_ARRAY(COMP_PLATFORM("loongson-i2s")));
|
||||
|
||||
static struct snd_soc_dai_link loongson_dai_link[] = {
|
||||
[PRI_PLAYBACK] = {
|
||||
/* Primary Playback i/f */
|
||||
.name = "ES8388 PAIF RX",
|
||||
.stream_name = "Playback",
|
||||
.dai_fmt = LOONGSON_DAI_FMT,
|
||||
.ops = &loongson_dai_link_ops,
|
||||
SND_SOC_DAILINK_REG(es8388_hifi),
|
||||
},
|
||||
[PRI_CAPTURE] = {
|
||||
/* Primary Capture i/f */
|
||||
.name = "ES8388 PAIF TX",
|
||||
.stream_name = "Capture",
|
||||
.dai_fmt = LOONGSON_DAI_FMT,
|
||||
.ops = &loongson_dai_link_ops,
|
||||
SND_SOC_DAILINK_REG(es8388_hifi),
|
||||
},
|
||||
};
|
||||
|
||||
static struct snd_soc_card es8388= {
|
||||
.name = "PAI ES8388",
|
||||
.owner = THIS_MODULE,
|
||||
.dai_link = loongson_dai_link,
|
||||
.num_links = ARRAY_SIZE(loongson_dai_link),
|
||||
|
||||
};
|
||||
|
||||
static void put_of_nodes(struct snd_soc_card *card)
|
||||
{
|
||||
struct snd_soc_dai_link *dai_link;
|
||||
int i;
|
||||
|
||||
for_each_card_prelinks(card, i, dai_link) {
|
||||
of_node_put(dai_link->cpus->of_node);
|
||||
of_node_put(dai_link->codecs->of_node);
|
||||
}
|
||||
}
|
||||
|
||||
static int ls_sound_drv_probe(struct platform_device *pdev)
|
||||
{
|
||||
struct device_node *np = pdev->dev.of_node;
|
||||
struct snd_soc_card *card;
|
||||
struct snd_soc_dai_link *dai_link;
|
||||
int ret;
|
||||
|
||||
card = (struct snd_soc_card *)of_device_get_match_data(&pdev->dev);
|
||||
card->dev = &pdev->dev;
|
||||
dai_link = card->dai_link;
|
||||
|
||||
dai_link->cpus->of_node = of_parse_phandle(np, "loongson,i2s-controller", 0);
|
||||
if (!dai_link->cpus->of_node) {
|
||||
dev_err(&pdev->dev,
|
||||
"Property 'loongson,i2s-controller' missing or invalid\n");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (!dai_link->platforms->name)
|
||||
dai_link->platforms->of_node = dai_link->cpus->of_node;
|
||||
|
||||
// name 已指定,不再指定 of_node,否则注册时报错
|
||||
// dai_link->codecs->of_node = of_parse_phandle(np, "loongson,audio-codec", 0);
|
||||
// if (!dai_link->codecs->of_node) {
|
||||
// dev_err(&pdev->dev,
|
||||
// "Property 'loongson,audio-codec' missing or invalid\n");
|
||||
// ret = -EINVAL;
|
||||
// goto err_put_of_nodes;
|
||||
// }
|
||||
|
||||
ret = devm_snd_soc_register_card(card->dev, card);
|
||||
if (ret) {
|
||||
if (ret != -EPROBE_DEFER)
|
||||
dev_err(&pdev->dev,
|
||||
"snd_soc_register_card() failed: %d\n", ret);
|
||||
goto err_put_of_nodes;
|
||||
}
|
||||
return 0;
|
||||
|
||||
err_put_of_nodes:
|
||||
put_of_nodes(card);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int ls_sound_drv_remove(struct platform_device *pdev)
|
||||
{
|
||||
struct snd_soc_card *card = platform_get_drvdata(pdev);
|
||||
|
||||
put_of_nodes(card);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const struct of_device_id snd_ls_sound_dt_match[] = {
|
||||
{ .compatible = "loongson,ls-sound", .data = &es8388},
|
||||
{},
|
||||
};
|
||||
MODULE_DEVICE_TABLE(of, snd_ls_sound_dt_match);
|
||||
|
||||
static struct platform_driver ls_sound_driver = {
|
||||
.probe = ls_sound_drv_probe,
|
||||
.remove = ls_sound_drv_remove,
|
||||
.driver = {
|
||||
.name = "ls-sound",
|
||||
.owner = THIS_MODULE,
|
||||
.of_match_table = of_match_ptr(snd_ls_sound_dt_match),
|
||||
},
|
||||
};
|
||||
|
||||
static int __init loongson_audio_init(void)
|
||||
{
|
||||
struct pci_dev *pdev;
|
||||
|
||||
return platform_driver_register(&ls_sound_driver);
|
||||
}
|
||||
module_init(loongson_audio_init);
|
||||
|
||||
static void __exit loongson_audio_exit(void)
|
||||
{
|
||||
platform_driver_unregister(&ls_sound_driver);
|
||||
}
|
||||
module_exit(loongson_audio_exit);
|
||||
|
||||
MODULE_SOFTDEP("pre: ls_pcm ls_i2s snd-soc-wm8988-objs");
|
||||
MODULE_AUTHOR("loongson");
|
||||
MODULE_DESCRIPTION("ALSA SoC loongson");
|
||||
MODULE_LICENSE("GPL");
|
||||
@@ -2,7 +2,7 @@
|
||||
#include <sound/soc.h>
|
||||
#include <sound/pcm_params.h>
|
||||
#include <linux/of_device.h>
|
||||
|
||||
#include <linux/i2c.h>
|
||||
#include <linux/pci_ids.h>
|
||||
#include <linux/pci.h>
|
||||
|
||||
@@ -21,36 +21,34 @@ enum {
|
||||
PRI_PLAYBACK = 0,
|
||||
PRI_CAPTURE,
|
||||
};
|
||||
|
||||
#define LOONGSON_DAI_FMT (SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF | \
|
||||
SND_SOC_DAIFMT_CBS_CFS)
|
||||
SND_SOC_DAIFMT_CBM_CFM)
|
||||
// SND_SOC_DAIFMT_CBS_CFS)
|
||||
|
||||
SND_SOC_DAILINK_DEFS(es8388_hifi,
|
||||
DAILINK_COMP_ARRAY(COMP_CPU("loongson-i2s-dai")),
|
||||
DAILINK_COMP_ARRAY(COMP_CODEC("es8328.0-0011", "es8328-hifi-analog")),
|
||||
DAILINK_COMP_ARRAY(COMP_PLATFORM("loongson-i2s")));
|
||||
SND_SOC_DAILINK_DEF(ls_dai_cpus, COMP_CPU("loongson-i2s-dai"));
|
||||
SND_SOC_DAILINK_DEF(ls_dai_codecs, COMP_CODEC("", ""));
|
||||
SND_SOC_DAILINK_DEF(ls_dai_platforms, COMP_PLATFORM("loongson-i2s"));
|
||||
|
||||
static struct snd_soc_dai_link loongson_dai_link[] = {
|
||||
[PRI_PLAYBACK] = {
|
||||
/* Primary Playback i/f */
|
||||
.name = "ES8388 PAIF RX",
|
||||
.name = "Loongson Dai link RX",
|
||||
.stream_name = "Playback",
|
||||
.dai_fmt = LOONGSON_DAI_FMT,
|
||||
.ops = &loongson_dai_link_ops,
|
||||
SND_SOC_DAILINK_REG(es8388_hifi),
|
||||
SND_SOC_DAILINK_REG(ls_dai),
|
||||
},
|
||||
[PRI_CAPTURE] = {
|
||||
/* Primary Capture i/f */
|
||||
.name = "ES8388 PAIF TX",
|
||||
.name = "Loongson Dai link TX",
|
||||
.stream_name = "Capture",
|
||||
.dai_fmt = LOONGSON_DAI_FMT,
|
||||
.ops = &loongson_dai_link_ops,
|
||||
SND_SOC_DAILINK_REG(es8388_hifi),
|
||||
SND_SOC_DAILINK_REG(ls_dai),
|
||||
},
|
||||
};
|
||||
|
||||
static struct snd_soc_card es8388= {
|
||||
.name = "PAI ES8388",
|
||||
static struct snd_soc_card ls_sound_card = {
|
||||
.owner = THIS_MODULE,
|
||||
.dai_link = loongson_dai_link,
|
||||
.num_links = ARRAY_SIZE(loongson_dai_link),
|
||||
@@ -68,12 +66,43 @@ static void put_of_nodes(struct snd_soc_card *card)
|
||||
}
|
||||
}
|
||||
|
||||
static int ls_sound_init_codec_name(struct platform_device* pdev,
|
||||
struct i2c_client *codec_i2c)
|
||||
{
|
||||
char codec_name[32];
|
||||
const char* codec_dai_name;
|
||||
struct snd_soc_component *codec_component;
|
||||
struct snd_soc_dai *codec_dai;
|
||||
|
||||
// codec-name = <codec-i2c-driver-name>.<i2cx>-<i2c-addr>
|
||||
sprintf(codec_name, "%s.%d-%04x",
|
||||
codec_i2c->dev.driver->name,
|
||||
codec_i2c->adapter->nr, codec_i2c->addr);
|
||||
|
||||
// codec-dai-name = depends on codec driver
|
||||
codec_component = snd_soc_lookup_component(&codec_i2c->dev, NULL);
|
||||
for_each_component_dais(codec_component, codec_dai){
|
||||
codec_dai_name = codec_dai->name;
|
||||
break;
|
||||
}
|
||||
|
||||
ls_dai_codecs[0].name = codec_name;
|
||||
ls_dai_codecs[0].dai_name = codec_dai_name;
|
||||
|
||||
dev_info(&pdev->dev, "name,dai-name: %s,%s\n", codec_name, codec_dai_name);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int ls_sound_drv_probe(struct platform_device *pdev)
|
||||
{
|
||||
struct device_node *np = pdev->dev.of_node;
|
||||
struct snd_soc_card *card;
|
||||
struct snd_soc_dai_link *dai_link;
|
||||
int ret;
|
||||
struct device_node *codec_np;
|
||||
struct i2c_client *codec_i2c;
|
||||
const char* card_name;
|
||||
|
||||
card = (struct snd_soc_card *)of_device_get_match_data(&pdev->dev);
|
||||
card->dev = &pdev->dev;
|
||||
@@ -89,6 +118,29 @@ static int ls_sound_drv_probe(struct platform_device *pdev)
|
||||
if (!dai_link->platforms->name)
|
||||
dai_link->platforms->of_node = dai_link->cpus->of_node;
|
||||
|
||||
codec_np = of_parse_phandle(np, "loongson,audio-codec", 0);
|
||||
if (!codec_np) {
|
||||
dev_err(&pdev->dev,
|
||||
"Property 'loongson,audio-codec' missing or invalid\n");
|
||||
ret = -EINVAL;
|
||||
goto err_put_of_nodes;
|
||||
}
|
||||
|
||||
codec_i2c = of_find_i2c_device_by_node(codec_np);
|
||||
if (!codec_i2c)
|
||||
{
|
||||
dev_err(&pdev->dev,
|
||||
"Property 'loongson,audio-codec' is not a i2c device\n");
|
||||
ret = -EINVAL;
|
||||
goto err_put_of_nodes;
|
||||
}
|
||||
|
||||
of_property_read_string(np, "loongson,sound-card-name", &card_name);
|
||||
|
||||
card->name = card_name;
|
||||
|
||||
ls_sound_init_codec_name(pdev, codec_i2c);
|
||||
|
||||
ret = devm_snd_soc_register_card(card->dev, card);
|
||||
if (ret) {
|
||||
if (ret != -EPROBE_DEFER)
|
||||
@@ -112,7 +164,7 @@ static int ls_sound_drv_remove(struct platform_device *pdev)
|
||||
}
|
||||
|
||||
static const struct of_device_id snd_ls_sound_dt_match[] = {
|
||||
{ .compatible = "loongson,ls-sound", .data = &es8388},
|
||||
{ .compatible = "loongson,ls-sound", .data = &ls_sound_card},
|
||||
{},
|
||||
};
|
||||
MODULE_DEVICE_TABLE(of, snd_ls_sound_dt_match);
|
||||
|
||||
Reference in New Issue
Block a user