Jon Smirl | a9262c4 | 2009-05-26 08:34:12 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Phytec pcm030 driver for the PSC of the Freescale MPC52xx |
| 3 | * configured as AC97 interface |
| 4 | * |
| 5 | * Copyright 2008 Jon Smirl, Digispeaker |
| 6 | * Author: Jon Smirl <jonsmirl@gmail.com> |
| 7 | * |
| 8 | * This file is licensed under the terms of the GNU General Public License |
| 9 | * version 2. This program is licensed "as is" without any warranty of any |
| 10 | * kind, whether express or implied. |
| 11 | */ |
| 12 | |
| 13 | #include <linux/init.h> |
| 14 | #include <linux/module.h> |
Jon Smirl | a9262c4 | 2009-05-26 08:34:12 -0400 | [diff] [blame] | 15 | #include <linux/device.h> |
Jon Smirl | a9262c4 | 2009-05-26 08:34:12 -0400 | [diff] [blame] | 16 | #include <linux/of_device.h> |
| 17 | #include <linux/of_platform.h> |
Jon Smirl | a9262c4 | 2009-05-26 08:34:12 -0400 | [diff] [blame] | 18 | |
Jon Smirl | a9262c4 | 2009-05-26 08:34:12 -0400 | [diff] [blame] | 19 | #include <sound/soc.h> |
Jon Smirl | a9262c4 | 2009-05-26 08:34:12 -0400 | [diff] [blame] | 20 | |
| 21 | #include "mpc5200_dma.h" |
Jon Smirl | a9262c4 | 2009-05-26 08:34:12 -0400 | [diff] [blame] | 22 | |
Takashi Iwai | afc5e65 | 2009-08-07 16:33:53 +0200 | [diff] [blame] | 23 | #define DRV_NAME "pcm030-audio-fabric" |
| 24 | |
Eric Millbrandt | c912fa9 | 2012-09-20 10:36:45 -0400 | [diff] [blame] | 25 | struct pcm030_audio_data { |
| 26 | struct snd_soc_card *card; |
| 27 | struct platform_device *codec_device; |
| 28 | }; |
| 29 | |
Jon Smirl | a9262c4 | 2009-05-26 08:34:12 -0400 | [diff] [blame] | 30 | static struct snd_soc_dai_link pcm030_fabric_dai[] = { |
| 31 | { |
Eric Millbrandt | c73adc7 | 2012-10-10 10:10:08 -0400 | [diff] [blame] | 32 | .name = "AC97.0", |
Jon Smirl | a9262c4 | 2009-05-26 08:34:12 -0400 | [diff] [blame] | 33 | .stream_name = "AC97 Analog", |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 34 | .codec_dai_name = "wm9712-hifi", |
| 35 | .cpu_dai_name = "mpc5200-psc-ac97.0", |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 36 | .codec_name = "wm9712-codec", |
Jon Smirl | a9262c4 | 2009-05-26 08:34:12 -0400 | [diff] [blame] | 37 | }, |
| 38 | { |
Eric Millbrandt | c73adc7 | 2012-10-10 10:10:08 -0400 | [diff] [blame] | 39 | .name = "AC97.1", |
Jon Smirl | a9262c4 | 2009-05-26 08:34:12 -0400 | [diff] [blame] | 40 | .stream_name = "AC97 IEC958", |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 41 | .codec_dai_name = "wm9712-aux", |
| 42 | .cpu_dai_name = "mpc5200-psc-ac97.1", |
Liam Girdwood | e94be5f | 2010-10-26 20:07:43 +0100 | [diff] [blame] | 43 | .codec_name = "wm9712-codec", |
Jon Smirl | a9262c4 | 2009-05-26 08:34:12 -0400 | [diff] [blame] | 44 | }, |
| 45 | }; |
| 46 | |
Eric Millbrandt | 0840116 | 2012-09-20 10:36:44 -0400 | [diff] [blame] | 47 | static struct snd_soc_card pcm030_card = { |
Axel Lin | 4c3c5df | 2011-12-22 21:04:54 +0800 | [diff] [blame] | 48 | .name = "pcm030", |
| 49 | .owner = THIS_MODULE, |
| 50 | .dai_link = pcm030_fabric_dai, |
| 51 | .num_links = ARRAY_SIZE(pcm030_fabric_dai), |
| 52 | }; |
| 53 | |
Eric Millbrandt | 0840116 | 2012-09-20 10:36:44 -0400 | [diff] [blame] | 54 | static int __init pcm030_fabric_probe(struct platform_device *op) |
Jon Smirl | a9262c4 | 2009-05-26 08:34:12 -0400 | [diff] [blame] | 55 | { |
Eric Millbrandt | 0840116 | 2012-09-20 10:36:44 -0400 | [diff] [blame] | 56 | struct device_node *np = op->dev.of_node; |
| 57 | struct device_node *platform_np; |
| 58 | struct snd_soc_card *card = &pcm030_card; |
Eric Millbrandt | c912fa9 | 2012-09-20 10:36:45 -0400 | [diff] [blame] | 59 | struct pcm030_audio_data *pdata; |
Eric Millbrandt | 0840116 | 2012-09-20 10:36:44 -0400 | [diff] [blame] | 60 | int ret; |
| 61 | int i; |
Jon Smirl | a9262c4 | 2009-05-26 08:34:12 -0400 | [diff] [blame] | 62 | |
Grant Likely | 71a157e | 2010-02-01 21:34:14 -0700 | [diff] [blame] | 63 | if (!of_machine_is_compatible("phytec,pcm030")) |
Jon Smirl | a9262c4 | 2009-05-26 08:34:12 -0400 | [diff] [blame] | 64 | return -ENODEV; |
| 65 | |
Eric Millbrandt | c912fa9 | 2012-09-20 10:36:45 -0400 | [diff] [blame] | 66 | pdata = devm_kzalloc(&op->dev, sizeof(struct pcm030_audio_data), |
| 67 | GFP_KERNEL); |
| 68 | if (!pdata) |
| 69 | return -ENOMEM; |
| 70 | |
Eric Millbrandt | 0840116 | 2012-09-20 10:36:44 -0400 | [diff] [blame] | 71 | card->dev = &op->dev; |
Eric Millbrandt | c912fa9 | 2012-09-20 10:36:45 -0400 | [diff] [blame] | 72 | platform_set_drvdata(op, pdata); |
| 73 | |
| 74 | pdata->card = card; |
Eric Millbrandt | 0840116 | 2012-09-20 10:36:44 -0400 | [diff] [blame] | 75 | |
| 76 | platform_np = of_parse_phandle(np, "asoc-platform", 0); |
| 77 | if (!platform_np) { |
| 78 | dev_err(&op->dev, "ac97 not registered\n"); |
Jon Smirl | a9262c4 | 2009-05-26 08:34:12 -0400 | [diff] [blame] | 79 | return -ENODEV; |
| 80 | } |
| 81 | |
Eric Millbrandt | 0840116 | 2012-09-20 10:36:44 -0400 | [diff] [blame] | 82 | for (i = 0; i < card->num_links; i++) |
| 83 | card->dai_link[i].platform_of_node = platform_np; |
Jon Smirl | a9262c4 | 2009-05-26 08:34:12 -0400 | [diff] [blame] | 84 | |
Eric Millbrandt | c912fa9 | 2012-09-20 10:36:45 -0400 | [diff] [blame] | 85 | ret = request_module("snd-soc-wm9712"); |
| 86 | if (ret) |
| 87 | dev_err(&op->dev, "request_module returned: %d\n", ret); |
| 88 | |
| 89 | pdata->codec_device = platform_device_alloc("wm9712-codec", -1); |
| 90 | if (!pdata->codec_device) |
| 91 | dev_err(&op->dev, "platform_device_alloc() failed\n"); |
| 92 | |
| 93 | ret = platform_device_add(pdata->codec_device); |
| 94 | if (ret) |
| 95 | dev_err(&op->dev, "platform_device_add() failed: %d\n", ret); |
| 96 | |
Eric Millbrandt | 0840116 | 2012-09-20 10:36:44 -0400 | [diff] [blame] | 97 | ret = snd_soc_register_card(card); |
| 98 | if (ret) |
| 99 | dev_err(&op->dev, "snd_soc_register_card() failed: %d\n", ret); |
| 100 | |
| 101 | return ret; |
Jon Smirl | a9262c4 | 2009-05-26 08:34:12 -0400 | [diff] [blame] | 102 | } |
| 103 | |
Eric Millbrandt | 0840116 | 2012-09-20 10:36:44 -0400 | [diff] [blame] | 104 | static int __devexit pcm030_fabric_remove(struct platform_device *op) |
| 105 | { |
Eric Millbrandt | c912fa9 | 2012-09-20 10:36:45 -0400 | [diff] [blame] | 106 | struct pcm030_audio_data *pdata = platform_get_drvdata(op); |
Eric Millbrandt | 0840116 | 2012-09-20 10:36:44 -0400 | [diff] [blame] | 107 | int ret; |
| 108 | |
Eric Millbrandt | c912fa9 | 2012-09-20 10:36:45 -0400 | [diff] [blame] | 109 | ret = snd_soc_unregister_card(pdata->card); |
| 110 | platform_device_unregister(pdata->codec_device); |
Eric Millbrandt | 0840116 | 2012-09-20 10:36:44 -0400 | [diff] [blame] | 111 | |
| 112 | return ret; |
| 113 | } |
| 114 | |
| 115 | static struct of_device_id pcm030_audio_match[] = { |
| 116 | { .compatible = "phytec,pcm030-audio-fabric", }, |
| 117 | {} |
| 118 | }; |
| 119 | MODULE_DEVICE_TABLE(of, pcm030_audio_match); |
| 120 | |
| 121 | static struct platform_driver pcm030_fabric_driver = { |
| 122 | .probe = pcm030_fabric_probe, |
| 123 | .remove = __devexit_p(pcm030_fabric_remove), |
| 124 | .driver = { |
| 125 | .name = DRV_NAME, |
| 126 | .owner = THIS_MODULE, |
| 127 | .of_match_table = pcm030_audio_match, |
| 128 | }, |
| 129 | }; |
| 130 | |
| 131 | module_platform_driver(pcm030_fabric_driver); |
Jon Smirl | a9262c4 | 2009-05-26 08:34:12 -0400 | [diff] [blame] | 132 | |
| 133 | |
| 134 | MODULE_AUTHOR("Jon Smirl <jonsmirl@gmail.com>"); |
| 135 | MODULE_DESCRIPTION(DRV_NAME ": mpc5200 pcm030 fabric driver"); |
| 136 | MODULE_LICENSE("GPL"); |
| 137 | |