Ola Lilja | e069038 | 2012-06-12 08:50:08 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) ST-Ericsson SA 2012 |
| 3 | * |
| 4 | * Author: Ola Lilja (ola.o.lilja@stericsson.com) |
| 5 | * for ST-Ericsson. |
| 6 | * |
| 7 | * License terms: |
| 8 | * |
| 9 | * This program is free software; you can redistribute it and/or modify |
| 10 | * it under the terms of the GNU General Public License version 2 as published |
| 11 | * by the Free Software Foundation. |
| 12 | */ |
| 13 | |
| 14 | #include <asm/mach-types.h> |
| 15 | |
| 16 | #include <linux/module.h> |
| 17 | #include <linux/io.h> |
| 18 | #include <linux/spi/spi.h> |
Lee Jones | 0af541c | 2012-07-26 16:48:34 +0100 | [diff] [blame] | 19 | #include <linux/of.h> |
Ola Lilja | e069038 | 2012-06-12 08:50:08 +0200 | [diff] [blame] | 20 | |
| 21 | #include <sound/soc.h> |
| 22 | #include <sound/initval.h> |
| 23 | |
| 24 | #include "ux500_pcm.h" |
| 25 | #include "ux500_msp_dai.h" |
| 26 | |
Lee Jones | 9fc4cd8 | 2013-01-31 12:34:00 +0000 | [diff] [blame] | 27 | #include "mop500_ab8500.h" |
Ola Lilja | e069038 | 2012-06-12 08:50:08 +0200 | [diff] [blame] | 28 | |
| 29 | /* Define the whole MOP500 soundcard, linking platform to the codec-drivers */ |
Lars-Peter Clausen | aba1e2b | 2013-05-14 22:19:55 +0200 | [diff] [blame] | 30 | static struct snd_soc_dai_link mop500_dai_links[] = { |
Ola Lilja | e069038 | 2012-06-12 08:50:08 +0200 | [diff] [blame] | 31 | { |
| 32 | .name = "ab8500_0", |
| 33 | .stream_name = "ab8500_0", |
| 34 | .cpu_dai_name = "ux500-msp-i2s.1", |
| 35 | .codec_dai_name = "ab8500-codec-dai.0", |
Lee Jones | 1428c20 | 2012-11-23 13:05:41 +0000 | [diff] [blame] | 36 | .platform_name = "ux500-msp-i2s.1", |
Ola Lilja | e069038 | 2012-06-12 08:50:08 +0200 | [diff] [blame] | 37 | .codec_name = "ab8500-codec.0", |
| 38 | .init = mop500_ab8500_machine_init, |
| 39 | .ops = mop500_ab8500_ops, |
| 40 | }, |
| 41 | { |
| 42 | .name = "ab8500_1", |
| 43 | .stream_name = "ab8500_1", |
| 44 | .cpu_dai_name = "ux500-msp-i2s.3", |
| 45 | .codec_dai_name = "ab8500-codec-dai.1", |
Lee Jones | 1428c20 | 2012-11-23 13:05:41 +0000 | [diff] [blame] | 46 | .platform_name = "ux500-msp-i2s.3", |
Ola Lilja | e069038 | 2012-06-12 08:50:08 +0200 | [diff] [blame] | 47 | .codec_name = "ab8500-codec.0", |
| 48 | .init = NULL, |
| 49 | .ops = mop500_ab8500_ops, |
| 50 | }, |
| 51 | }; |
| 52 | |
| 53 | static struct snd_soc_card mop500_card = { |
| 54 | .name = "MOP500-card", |
| 55 | .probe = NULL, |
| 56 | .dai_link = mop500_dai_links, |
| 57 | .num_links = ARRAY_SIZE(mop500_dai_links), |
| 58 | }; |
| 59 | |
Lee Jones | 39013bd | 2012-10-15 14:13:25 +0100 | [diff] [blame] | 60 | static void mop500_of_node_put(void) |
| 61 | { |
| 62 | int i; |
| 63 | |
| 64 | for (i = 0; i < 2; i++) { |
| 65 | if (mop500_dai_links[i].cpu_of_node) |
| 66 | of_node_put((struct device_node *) |
| 67 | mop500_dai_links[i].cpu_of_node); |
| 68 | if (mop500_dai_links[i].codec_of_node) |
| 69 | of_node_put((struct device_node *) |
| 70 | mop500_dai_links[i].codec_of_node); |
| 71 | } |
| 72 | } |
| 73 | |
Bill Pemberton | da79487 | 2012-12-07 09:26:35 -0500 | [diff] [blame] | 74 | static int mop500_of_probe(struct platform_device *pdev, |
| 75 | struct device_node *np) |
Lee Jones | 0af541c | 2012-07-26 16:48:34 +0100 | [diff] [blame] | 76 | { |
| 77 | struct device_node *codec_np, *msp_np[2]; |
| 78 | int i; |
| 79 | |
| 80 | msp_np[0] = of_parse_phandle(np, "stericsson,cpu-dai", 0); |
| 81 | msp_np[1] = of_parse_phandle(np, "stericsson,cpu-dai", 1); |
| 82 | codec_np = of_parse_phandle(np, "stericsson,audio-codec", 0); |
| 83 | |
| 84 | if (!(msp_np[0] && msp_np[1] && codec_np)) { |
| 85 | dev_err(&pdev->dev, "Phandle missing or invalid\n"); |
Lee Jones | 39013bd | 2012-10-15 14:13:25 +0100 | [diff] [blame] | 86 | mop500_of_node_put(); |
Lee Jones | 0af541c | 2012-07-26 16:48:34 +0100 | [diff] [blame] | 87 | return -EINVAL; |
| 88 | } |
| 89 | |
| 90 | for (i = 0; i < 2; i++) { |
| 91 | mop500_dai_links[i].cpu_of_node = msp_np[i]; |
| 92 | mop500_dai_links[i].cpu_dai_name = NULL; |
| 93 | mop500_dai_links[i].codec_of_node = codec_np; |
| 94 | mop500_dai_links[i].codec_name = NULL; |
| 95 | } |
| 96 | |
| 97 | snd_soc_of_parse_card_name(&mop500_card, "stericsson,card-name"); |
| 98 | |
| 99 | return 0; |
| 100 | } |
Lee Jones | 39013bd | 2012-10-15 14:13:25 +0100 | [diff] [blame] | 101 | |
Bill Pemberton | da79487 | 2012-12-07 09:26:35 -0500 | [diff] [blame] | 102 | static int mop500_probe(struct platform_device *pdev) |
Ola Lilja | e069038 | 2012-06-12 08:50:08 +0200 | [diff] [blame] | 103 | { |
Lee Jones | 0af541c | 2012-07-26 16:48:34 +0100 | [diff] [blame] | 104 | struct device_node *np = pdev->dev.of_node; |
Ola Lilja | e069038 | 2012-06-12 08:50:08 +0200 | [diff] [blame] | 105 | int ret; |
| 106 | |
Ola Lilja | e069038 | 2012-06-12 08:50:08 +0200 | [diff] [blame] | 107 | dev_dbg(&pdev->dev, "%s: Enter.\n", __func__); |
| 108 | |
| 109 | mop500_card.dev = &pdev->dev; |
| 110 | |
Lee Jones | 0af541c | 2012-07-26 16:48:34 +0100 | [diff] [blame] | 111 | if (np) { |
| 112 | ret = mop500_of_probe(pdev, np); |
| 113 | if (ret) |
| 114 | return ret; |
| 115 | } |
| 116 | |
Ola Lilja | e069038 | 2012-06-12 08:50:08 +0200 | [diff] [blame] | 117 | dev_dbg(&pdev->dev, "%s: Card %s: Set platform drvdata.\n", |
| 118 | __func__, mop500_card.name); |
| 119 | platform_set_drvdata(pdev, &mop500_card); |
| 120 | |
| 121 | snd_soc_card_set_drvdata(&mop500_card, NULL); |
| 122 | |
| 123 | dev_dbg(&pdev->dev, "%s: Card %s: num_links = %d\n", |
| 124 | __func__, mop500_card.name, mop500_card.num_links); |
| 125 | dev_dbg(&pdev->dev, "%s: Card %s: DAI-link 0: name = %s\n", |
| 126 | __func__, mop500_card.name, mop500_card.dai_link[0].name); |
| 127 | dev_dbg(&pdev->dev, "%s: Card %s: DAI-link 0: stream_name = %s\n", |
| 128 | __func__, mop500_card.name, |
| 129 | mop500_card.dai_link[0].stream_name); |
| 130 | |
| 131 | ret = snd_soc_register_card(&mop500_card); |
| 132 | if (ret) |
| 133 | dev_err(&pdev->dev, |
Lee Jones | 2087a69 | 2012-08-21 10:06:44 +0100 | [diff] [blame] | 134 | "Error: snd_soc_register_card failed (%d)!\n", ret); |
Ola Lilja | e069038 | 2012-06-12 08:50:08 +0200 | [diff] [blame] | 135 | |
| 136 | return ret; |
| 137 | } |
| 138 | |
Bill Pemberton | da79487 | 2012-12-07 09:26:35 -0500 | [diff] [blame] | 139 | static int mop500_remove(struct platform_device *pdev) |
Ola Lilja | e069038 | 2012-06-12 08:50:08 +0200 | [diff] [blame] | 140 | { |
| 141 | struct snd_soc_card *mop500_card = platform_get_drvdata(pdev); |
| 142 | |
| 143 | pr_debug("%s: Enter.\n", __func__); |
| 144 | |
| 145 | snd_soc_unregister_card(mop500_card); |
| 146 | mop500_ab8500_remove(mop500_card); |
Lee Jones | 39013bd | 2012-10-15 14:13:25 +0100 | [diff] [blame] | 147 | mop500_of_node_put(); |
Lee Jones | 2087a69 | 2012-08-21 10:06:44 +0100 | [diff] [blame] | 148 | |
Ola Lilja | e069038 | 2012-06-12 08:50:08 +0200 | [diff] [blame] | 149 | return 0; |
| 150 | } |
| 151 | |
Lee Jones | 0af541c | 2012-07-26 16:48:34 +0100 | [diff] [blame] | 152 | static const struct of_device_id snd_soc_mop500_match[] = { |
| 153 | { .compatible = "stericsson,snd-soc-mop500", }, |
| 154 | {}, |
| 155 | }; |
| 156 | |
Ola Lilja | e069038 | 2012-06-12 08:50:08 +0200 | [diff] [blame] | 157 | static struct platform_driver snd_soc_mop500_driver = { |
| 158 | .driver = { |
| 159 | .owner = THIS_MODULE, |
| 160 | .name = "snd-soc-mop500", |
Lee Jones | 0af541c | 2012-07-26 16:48:34 +0100 | [diff] [blame] | 161 | .of_match_table = snd_soc_mop500_match, |
Ola Lilja | e069038 | 2012-06-12 08:50:08 +0200 | [diff] [blame] | 162 | }, |
| 163 | .probe = mop500_probe, |
Bill Pemberton | da79487 | 2012-12-07 09:26:35 -0500 | [diff] [blame] | 164 | .remove = mop500_remove, |
Ola Lilja | e069038 | 2012-06-12 08:50:08 +0200 | [diff] [blame] | 165 | }; |
| 166 | |
| 167 | module_platform_driver(snd_soc_mop500_driver); |