1 // SPDX-License-Identifier: GPL-2.0 2 // 3 // Phytec pcm030 driver for the PSC of the Freescale MPC52xx 4 // configured as AC97 interface 5 // 6 // Copyright 2008 Jon Smirl, Digispeaker 7 // Author: Jon Smirl <jonsmirl@gmail.com> 8 9 #include <linux/init.h> 10 #include <linux/module.h> 11 #include <linux/device.h> 12 #include <linux/of.h> 13 14 #include <sound/soc.h> 15 16 #define DRV_NAME "pcm030-audio-fabric" 17 18 struct pcm030_audio_data { 19 struct snd_soc_card *card; 20 struct platform_device *codec_device; 21 }; 22 23 SND_SOC_DAILINK_DEFS(analog, 24 DAILINK_COMP_ARRAY(COMP_CPU("mpc5200-psc-ac97.0")), 25 DAILINK_COMP_ARRAY(COMP_CODEC("wm9712-codec", "wm9712-hifi")), 26 DAILINK_COMP_ARRAY(COMP_EMPTY())); 27 28 SND_SOC_DAILINK_DEFS(iec958, 29 DAILINK_COMP_ARRAY(COMP_CPU("mpc5200-psc-ac97.1")), 30 DAILINK_COMP_ARRAY(COMP_CODEC("wm9712-codec", "wm9712-aux")), 31 DAILINK_COMP_ARRAY(COMP_EMPTY())); 32 33 static struct snd_soc_dai_link pcm030_fabric_dai[] = { 34 { 35 .name = "AC97.0", 36 .stream_name = "AC97 Analog", 37 SND_SOC_DAILINK_REG(analog), 38 }, 39 { 40 .name = "AC97.1", 41 .stream_name = "AC97 IEC958", 42 SND_SOC_DAILINK_REG(iec958), 43 }, 44 }; 45 46 static struct snd_soc_card pcm030_card = { 47 .name = "pcm030", 48 .owner = THIS_MODULE, 49 .dai_link = pcm030_fabric_dai, 50 .num_links = ARRAY_SIZE(pcm030_fabric_dai), 51 }; 52 53 static int pcm030_fabric_probe(struct platform_device *op) 54 { 55 struct device_node *np = op->dev.of_node; 56 struct device_node *platform_np; 57 struct snd_soc_card *card = &pcm030_card; 58 struct pcm030_audio_data *pdata; 59 struct snd_soc_dai_link *dai_link; 60 int ret; 61 int i; 62 63 if (!of_machine_is_compatible("phytec,pcm030")) 64 return -ENODEV; 65 66 pdata = devm_kzalloc(&op->dev, sizeof(struct pcm030_audio_data), 67 GFP_KERNEL); 68 if (!pdata) 69 return -ENOMEM; 70 71 card->dev = &op->dev; 72 73 pdata->card = card; 74 75 platform_np = of_parse_phandle(np, "asoc-platform", 0); 76 if (!platform_np) { 77 dev_err(&op->dev, "ac97 not registered\n"); 78 return -ENODEV; 79 } 80 81 for_each_card_prelinks(card, i, dai_link) 82 dai_link->platforms->of_node = platform_np; 83 84 ret = request_module("snd-soc-wm9712"); 85 if (ret) 86 dev_err(&op->dev, "request_module returned: %d\n", ret); 87 88 pdata->codec_device = platform_device_alloc("wm9712-codec", -1); 89 if (!pdata->codec_device) 90 dev_err(&op->dev, "platform_device_alloc() failed\n"); 91 92 ret = platform_device_add(pdata->codec_device); 93 if (ret) { 94 dev_err(&op->dev, "platform_device_add() failed: %d\n", ret); 95 platform_device_put(pdata->codec_device); 96 } 97 98 ret = snd_soc_register_card(card); 99 if (ret) { 100 dev_err(&op->dev, "snd_soc_register_card() failed: %d\n", ret); 101 platform_device_unregister(pdata->codec_device); 102 } 103 104 platform_set_drvdata(op, pdata); 105 return ret; 106 107 } 108 109 static void pcm030_fabric_remove(struct platform_device *op) 110 { 111 struct pcm030_audio_data *pdata = platform_get_drvdata(op); 112 113 snd_soc_unregister_card(pdata->card); 114 platform_device_unregister(pdata->codec_device); 115 } 116 117 static const struct of_device_id pcm030_audio_match[] = { 118 { .compatible = "phytec,pcm030-audio-fabric", }, 119 {} 120 }; 121 MODULE_DEVICE_TABLE(of, pcm030_audio_match); 122 123 static struct platform_driver pcm030_fabric_driver = { 124 .probe = pcm030_fabric_probe, 125 .remove = pcm030_fabric_remove, 126 .driver = { 127 .name = DRV_NAME, 128 .of_match_table = pcm030_audio_match, 129 }, 130 }; 131 132 module_platform_driver(pcm030_fabric_driver); 133 134 135 MODULE_AUTHOR("Jon Smirl <jonsmirl@gmail.com>"); 136 MODULE_DESCRIPTION(DRV_NAME ": mpc5200 pcm030 fabric driver"); 137 MODULE_LICENSE("GPL"); 138 139