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