Andra Danciu | 6e3398c | 2019-04-05 14:50:08 +0300 | [diff] [blame] | 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> |
Jon Smirl | a9262c4 | 2009-05-26 08:34:12 -0400 | [diff] [blame] | 8 | |
| 9 | #include <linux/init.h> |
| 10 | #include <linux/module.h> |
Jon Smirl | a9262c4 | 2009-05-26 08:34:12 -0400 | [diff] [blame] | 11 | #include <linux/device.h> |
Jon Smirl | a9262c4 | 2009-05-26 08:34:12 -0400 | [diff] [blame] | 12 | #include <linux/of_device.h> |
| 13 | #include <linux/of_platform.h> |
Jon Smirl | a9262c4 | 2009-05-26 08:34:12 -0400 | [diff] [blame] | 14 | |
Jon Smirl | a9262c4 | 2009-05-26 08:34:12 -0400 | [diff] [blame] | 15 | #include <sound/soc.h> |
Jon Smirl | a9262c4 | 2009-05-26 08:34:12 -0400 | [diff] [blame] | 16 | |
| 17 | #include "mpc5200_dma.h" |
Jon Smirl | a9262c4 | 2009-05-26 08:34:12 -0400 | [diff] [blame] | 18 | |
Takashi Iwai | afc5e65 | 2009-08-07 16:33:53 +0200 | [diff] [blame] | 19 | #define DRV_NAME "pcm030-audio-fabric" |
| 20 | |
Eric Millbrandt | c912fa9 | 2012-09-20 10:36:45 -0400 | [diff] [blame] | 21 | struct pcm030_audio_data { |
| 22 | struct snd_soc_card *card; |
| 23 | struct platform_device *codec_device; |
| 24 | }; |
| 25 | |
Kuninori Morimoto | 61c2931 | 2019-06-06 13:16:14 +0900 | [diff] [blame] | 26 | SND_SOC_DAILINK_DEFS(analog, |
| 27 | DAILINK_COMP_ARRAY(COMP_CPU("mpc5200-psc-ac97.0")), |
| 28 | DAILINK_COMP_ARRAY(COMP_CODEC("wm9712-codec", "wm9712-hifi")), |
| 29 | DAILINK_COMP_ARRAY(COMP_EMPTY())); |
| 30 | |
| 31 | SND_SOC_DAILINK_DEFS(iec958, |
| 32 | DAILINK_COMP_ARRAY(COMP_CPU("mpc5200-psc-ac97.1")), |
| 33 | DAILINK_COMP_ARRAY(COMP_CODEC("wm9712-codec", "wm9712-aux")), |
| 34 | DAILINK_COMP_ARRAY(COMP_EMPTY())); |
| 35 | |
Jon Smirl | a9262c4 | 2009-05-26 08:34:12 -0400 | [diff] [blame] | 36 | static struct snd_soc_dai_link pcm030_fabric_dai[] = { |
| 37 | { |
Eric Millbrandt | c73adc7 | 2012-10-10 10:10:08 -0400 | [diff] [blame] | 38 | .name = "AC97.0", |
Jon Smirl | a9262c4 | 2009-05-26 08:34:12 -0400 | [diff] [blame] | 39 | .stream_name = "AC97 Analog", |
Kuninori Morimoto | 61c2931 | 2019-06-06 13:16:14 +0900 | [diff] [blame] | 40 | SND_SOC_DAILINK_REG(analog), |
Jon Smirl | a9262c4 | 2009-05-26 08:34:12 -0400 | [diff] [blame] | 41 | }, |
| 42 | { |
Eric Millbrandt | c73adc7 | 2012-10-10 10:10:08 -0400 | [diff] [blame] | 43 | .name = "AC97.1", |
Jon Smirl | a9262c4 | 2009-05-26 08:34:12 -0400 | [diff] [blame] | 44 | .stream_name = "AC97 IEC958", |
Kuninori Morimoto | 61c2931 | 2019-06-06 13:16:14 +0900 | [diff] [blame] | 45 | SND_SOC_DAILINK_REG(iec958), |
Jon Smirl | a9262c4 | 2009-05-26 08:34:12 -0400 | [diff] [blame] | 46 | }, |
| 47 | }; |
| 48 | |
Eric Millbrandt | 0840116 | 2012-09-20 10:36:44 -0400 | [diff] [blame] | 49 | static struct snd_soc_card pcm030_card = { |
Axel Lin | 4c3c5df | 2011-12-22 21:04:54 +0800 | [diff] [blame] | 50 | .name = "pcm030", |
| 51 | .owner = THIS_MODULE, |
| 52 | .dai_link = pcm030_fabric_dai, |
| 53 | .num_links = ARRAY_SIZE(pcm030_fabric_dai), |
| 54 | }; |
| 55 | |
Markus Pargmann | 34913fd | 2013-03-10 19:33:06 +0100 | [diff] [blame] | 56 | static int pcm030_fabric_probe(struct platform_device *op) |
Jon Smirl | a9262c4 | 2009-05-26 08:34:12 -0400 | [diff] [blame] | 57 | { |
Eric Millbrandt | 0840116 | 2012-09-20 10:36:44 -0400 | [diff] [blame] | 58 | struct device_node *np = op->dev.of_node; |
| 59 | struct device_node *platform_np; |
| 60 | struct snd_soc_card *card = &pcm030_card; |
Eric Millbrandt | c912fa9 | 2012-09-20 10:36:45 -0400 | [diff] [blame] | 61 | struct pcm030_audio_data *pdata; |
Kuninori Morimoto | 7fe072b | 2018-09-18 01:28:49 +0000 | [diff] [blame] | 62 | struct snd_soc_dai_link *dai_link; |
Eric Millbrandt | 0840116 | 2012-09-20 10:36:44 -0400 | [diff] [blame] | 63 | int ret; |
| 64 | int i; |
Jon Smirl | a9262c4 | 2009-05-26 08:34:12 -0400 | [diff] [blame] | 65 | |
Grant Likely | 71a157e | 2010-02-01 21:34:14 -0700 | [diff] [blame] | 66 | if (!of_machine_is_compatible("phytec,pcm030")) |
Jon Smirl | a9262c4 | 2009-05-26 08:34:12 -0400 | [diff] [blame] | 67 | return -ENODEV; |
| 68 | |
Eric Millbrandt | c912fa9 | 2012-09-20 10:36:45 -0400 | [diff] [blame] | 69 | pdata = devm_kzalloc(&op->dev, sizeof(struct pcm030_audio_data), |
| 70 | GFP_KERNEL); |
| 71 | if (!pdata) |
| 72 | return -ENOMEM; |
| 73 | |
Eric Millbrandt | 0840116 | 2012-09-20 10:36:44 -0400 | [diff] [blame] | 74 | card->dev = &op->dev; |
Eric Millbrandt | c912fa9 | 2012-09-20 10:36:45 -0400 | [diff] [blame] | 75 | |
| 76 | pdata->card = card; |
Eric Millbrandt | 0840116 | 2012-09-20 10:36:44 -0400 | [diff] [blame] | 77 | |
| 78 | platform_np = of_parse_phandle(np, "asoc-platform", 0); |
| 79 | if (!platform_np) { |
| 80 | dev_err(&op->dev, "ac97 not registered\n"); |
Jon Smirl | a9262c4 | 2009-05-26 08:34:12 -0400 | [diff] [blame] | 81 | return -ENODEV; |
| 82 | } |
| 83 | |
Kuninori Morimoto | 7fe072b | 2018-09-18 01:28:49 +0000 | [diff] [blame] | 84 | for_each_card_prelinks(card, i, dai_link) |
Kuninori Morimoto | 61c2931 | 2019-06-06 13:16:14 +0900 | [diff] [blame] | 85 | dai_link->platforms->of_node = platform_np; |
Jon Smirl | a9262c4 | 2009-05-26 08:34:12 -0400 | [diff] [blame] | 86 | |
Eric Millbrandt | c912fa9 | 2012-09-20 10:36:45 -0400 | [diff] [blame] | 87 | ret = request_module("snd-soc-wm9712"); |
| 88 | if (ret) |
| 89 | dev_err(&op->dev, "request_module returned: %d\n", ret); |
| 90 | |
| 91 | pdata->codec_device = platform_device_alloc("wm9712-codec", -1); |
| 92 | if (!pdata->codec_device) |
| 93 | dev_err(&op->dev, "platform_device_alloc() failed\n"); |
| 94 | |
| 95 | ret = platform_device_add(pdata->codec_device); |
Miaoqian Lin | fb25621 | 2022-01-27 13:13:34 +0000 | [diff] [blame] | 96 | if (ret) { |
Eric Millbrandt | c912fa9 | 2012-09-20 10:36:45 -0400 | [diff] [blame] | 97 | dev_err(&op->dev, "platform_device_add() failed: %d\n", ret); |
Miaoqian Lin | fb25621 | 2022-01-27 13:13:34 +0000 | [diff] [blame] | 98 | platform_device_put(pdata->codec_device); |
| 99 | } |
Eric Millbrandt | c912fa9 | 2012-09-20 10:36:45 -0400 | [diff] [blame] | 100 | |
Eric Millbrandt | 0840116 | 2012-09-20 10:36:44 -0400 | [diff] [blame] | 101 | ret = snd_soc_register_card(card); |
Miaoqian Lin | fb25621 | 2022-01-27 13:13:34 +0000 | [diff] [blame] | 102 | if (ret) { |
Eric Millbrandt | 0840116 | 2012-09-20 10:36:44 -0400 | [diff] [blame] | 103 | dev_err(&op->dev, "snd_soc_register_card() failed: %d\n", ret); |
Miaoqian Lin | fb25621 | 2022-01-27 13:13:34 +0000 | [diff] [blame] | 104 | platform_device_del(pdata->codec_device); |
| 105 | platform_device_put(pdata->codec_device); |
| 106 | } |
Eric Millbrandt | 0840116 | 2012-09-20 10:36:44 -0400 | [diff] [blame] | 107 | |
Wei Yongjun | 6c7ef41 | 2013-11-09 08:41:14 +0800 | [diff] [blame] | 108 | platform_set_drvdata(op, pdata); |
Eric Millbrandt | 0840116 | 2012-09-20 10:36:44 -0400 | [diff] [blame] | 109 | return ret; |
Miaoqian Lin | fb25621 | 2022-01-27 13:13:34 +0000 | [diff] [blame] | 110 | |
Jon Smirl | a9262c4 | 2009-05-26 08:34:12 -0400 | [diff] [blame] | 111 | } |
| 112 | |
Bill Pemberton | a0a3d51 | 2012-12-07 09:26:16 -0500 | [diff] [blame] | 113 | static int pcm030_fabric_remove(struct platform_device *op) |
Eric Millbrandt | 0840116 | 2012-09-20 10:36:44 -0400 | [diff] [blame] | 114 | { |
Eric Millbrandt | c912fa9 | 2012-09-20 10:36:45 -0400 | [diff] [blame] | 115 | struct pcm030_audio_data *pdata = platform_get_drvdata(op); |
Eric Millbrandt | 0840116 | 2012-09-20 10:36:44 -0400 | [diff] [blame] | 116 | int ret; |
| 117 | |
Eric Millbrandt | c912fa9 | 2012-09-20 10:36:45 -0400 | [diff] [blame] | 118 | ret = snd_soc_unregister_card(pdata->card); |
| 119 | platform_device_unregister(pdata->codec_device); |
Eric Millbrandt | 0840116 | 2012-09-20 10:36:44 -0400 | [diff] [blame] | 120 | |
| 121 | return ret; |
| 122 | } |
| 123 | |
Fabian Frederick | 6ffa84d | 2015-03-18 17:48:57 +0100 | [diff] [blame] | 124 | static const struct of_device_id pcm030_audio_match[] = { |
Eric Millbrandt | 0840116 | 2012-09-20 10:36:44 -0400 | [diff] [blame] | 125 | { .compatible = "phytec,pcm030-audio-fabric", }, |
| 126 | {} |
| 127 | }; |
| 128 | MODULE_DEVICE_TABLE(of, pcm030_audio_match); |
| 129 | |
| 130 | static struct platform_driver pcm030_fabric_driver = { |
| 131 | .probe = pcm030_fabric_probe, |
Bill Pemberton | a0a3d51 | 2012-12-07 09:26:16 -0500 | [diff] [blame] | 132 | .remove = pcm030_fabric_remove, |
Eric Millbrandt | 0840116 | 2012-09-20 10:36:44 -0400 | [diff] [blame] | 133 | .driver = { |
| 134 | .name = DRV_NAME, |
Eric Millbrandt | 0840116 | 2012-09-20 10:36:44 -0400 | [diff] [blame] | 135 | .of_match_table = pcm030_audio_match, |
| 136 | }, |
| 137 | }; |
| 138 | |
| 139 | module_platform_driver(pcm030_fabric_driver); |
Jon Smirl | a9262c4 | 2009-05-26 08:34:12 -0400 | [diff] [blame] | 140 | |
| 141 | |
| 142 | MODULE_AUTHOR("Jon Smirl <jonsmirl@gmail.com>"); |
| 143 | MODULE_DESCRIPTION(DRV_NAME ": mpc5200 pcm030 fabric driver"); |
| 144 | MODULE_LICENSE("GPL"); |
| 145 | |