Thomas Gleixner | d2912cb | 2019-06-04 10:11:33 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
Ola Lilja | e069038 | 2012-06-12 08:50:08 +0200 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) ST-Ericsson SA 2012 |
| 4 | * |
| 5 | * Author: Ola Lilja (ola.o.lilja@stericsson.com) |
| 6 | * for ST-Ericsson. |
| 7 | * |
| 8 | * License terms: |
Ola Lilja | e069038 | 2012-06-12 08:50:08 +0200 | [diff] [blame] | 9 | */ |
| 10 | |
| 11 | #include <asm/mach-types.h> |
| 12 | |
| 13 | #include <linux/module.h> |
| 14 | #include <linux/io.h> |
| 15 | #include <linux/spi/spi.h> |
Lee Jones | 0af541ce | 2012-07-26 16:48:34 +0100 | [diff] [blame] | 16 | #include <linux/of.h> |
Ola Lilja | e069038 | 2012-06-12 08:50:08 +0200 | [diff] [blame] | 17 | |
| 18 | #include <sound/soc.h> |
| 19 | #include <sound/initval.h> |
| 20 | |
| 21 | #include "ux500_pcm.h" |
| 22 | #include "ux500_msp_dai.h" |
| 23 | |
Lee Jones | 9fc4cd8 | 2013-01-31 12:34:00 +0000 | [diff] [blame] | 24 | #include "mop500_ab8500.h" |
Ola Lilja | e069038 | 2012-06-12 08:50:08 +0200 | [diff] [blame] | 25 | |
| 26 | /* Define the whole MOP500 soundcard, linking platform to the codec-drivers */ |
Kuninori Morimoto | 8ad8d81 | 2019-06-06 13:18:14 +0900 | [diff] [blame] | 27 | SND_SOC_DAILINK_DEFS(link1, |
| 28 | DAILINK_COMP_ARRAY(COMP_CPU("ux500-msp-i2s.1")), |
Kuninori Morimoto | 0296de8 | 2019-06-28 10:49:40 +0900 | [diff] [blame] | 29 | DAILINK_COMP_ARRAY(COMP_CODEC("ab8500-codec.0", "ab8500-codec-dai.0")), |
| 30 | DAILINK_COMP_ARRAY(COMP_PLATFORM("ux500-msp-i2s.1"))); |
Kuninori Morimoto | 8ad8d81 | 2019-06-06 13:18:14 +0900 | [diff] [blame] | 31 | |
| 32 | SND_SOC_DAILINK_DEFS(link2, |
| 33 | DAILINK_COMP_ARRAY(COMP_CPU("ux500-msp-i2s.3")), |
Kuninori Morimoto | 0296de8 | 2019-06-28 10:49:40 +0900 | [diff] [blame] | 34 | DAILINK_COMP_ARRAY(COMP_CODEC("ab8500-codec.0", "ab8500-codec-dai.1")), |
| 35 | DAILINK_COMP_ARRAY(COMP_PLATFORM("ux500-msp-i2s.3"))); |
Kuninori Morimoto | 8ad8d81 | 2019-06-06 13:18:14 +0900 | [diff] [blame] | 36 | |
Lars-Peter Clausen | aba1e2b | 2013-05-14 22:19:55 +0200 | [diff] [blame] | 37 | static struct snd_soc_dai_link mop500_dai_links[] = { |
Ola Lilja | e069038 | 2012-06-12 08:50:08 +0200 | [diff] [blame] | 38 | { |
| 39 | .name = "ab8500_0", |
| 40 | .stream_name = "ab8500_0", |
Ola Lilja | e069038 | 2012-06-12 08:50:08 +0200 | [diff] [blame] | 41 | .init = mop500_ab8500_machine_init, |
| 42 | .ops = mop500_ab8500_ops, |
Kuninori Morimoto | 8ad8d81 | 2019-06-06 13:18:14 +0900 | [diff] [blame] | 43 | SND_SOC_DAILINK_REG(link1), |
Ola Lilja | e069038 | 2012-06-12 08:50:08 +0200 | [diff] [blame] | 44 | }, |
| 45 | { |
| 46 | .name = "ab8500_1", |
| 47 | .stream_name = "ab8500_1", |
Ola Lilja | e069038 | 2012-06-12 08:50:08 +0200 | [diff] [blame] | 48 | .init = NULL, |
| 49 | .ops = mop500_ab8500_ops, |
Kuninori Morimoto | 8ad8d81 | 2019-06-06 13:18:14 +0900 | [diff] [blame] | 50 | SND_SOC_DAILINK_REG(link2), |
Ola Lilja | e069038 | 2012-06-12 08:50:08 +0200 | [diff] [blame] | 51 | }, |
| 52 | }; |
| 53 | |
| 54 | static struct snd_soc_card mop500_card = { |
| 55 | .name = "MOP500-card", |
Wei Yongjun | e7c8c58 | 2013-07-02 17:25:37 +0800 | [diff] [blame] | 56 | .owner = THIS_MODULE, |
Ola Lilja | e069038 | 2012-06-12 08:50:08 +0200 | [diff] [blame] | 57 | .probe = NULL, |
| 58 | .dai_link = mop500_dai_links, |
| 59 | .num_links = ARRAY_SIZE(mop500_dai_links), |
| 60 | }; |
| 61 | |
Lee Jones | 39013bd | 2012-10-15 14:13:25 +0100 | [diff] [blame] | 62 | static void mop500_of_node_put(void) |
| 63 | { |
| 64 | int i; |
| 65 | |
Christophe JAILLET | 4e8748f | 2020-05-12 12:07:05 +0200 | [diff] [blame] | 66 | for (i = 0; i < 2; i++) |
Kuninori Morimoto | 8ad8d81 | 2019-06-06 13:18:14 +0900 | [diff] [blame] | 67 | of_node_put(mop500_dai_links[i].cpus->of_node); |
Christophe JAILLET | 4e8748f | 2020-05-12 12:07:05 +0200 | [diff] [blame] | 68 | |
| 69 | /* Both links use the same codec, which is refcounted only once */ |
| 70 | of_node_put(mop500_dai_links[0].codecs->of_node); |
Lee Jones | 39013bd | 2012-10-15 14:13:25 +0100 | [diff] [blame] | 71 | } |
| 72 | |
Bill Pemberton | da79487 | 2012-12-07 09:26:35 -0500 | [diff] [blame] | 73 | static int mop500_of_probe(struct platform_device *pdev, |
| 74 | struct device_node *np) |
Lee Jones | 0af541ce | 2012-07-26 16:48:34 +0100 | [diff] [blame] | 75 | { |
| 76 | struct device_node *codec_np, *msp_np[2]; |
| 77 | int i; |
| 78 | |
| 79 | msp_np[0] = of_parse_phandle(np, "stericsson,cpu-dai", 0); |
| 80 | msp_np[1] = of_parse_phandle(np, "stericsson,cpu-dai", 1); |
| 81 | codec_np = of_parse_phandle(np, "stericsson,audio-codec", 0); |
| 82 | |
| 83 | if (!(msp_np[0] && msp_np[1] && codec_np)) { |
| 84 | dev_err(&pdev->dev, "Phandle missing or invalid\n"); |
Christophe JAILLET | 4e8748f | 2020-05-12 12:07:05 +0200 | [diff] [blame] | 85 | for (i = 0; i < 2; i++) |
| 86 | of_node_put(msp_np[i]); |
| 87 | of_node_put(codec_np); |
Lee Jones | 0af541ce | 2012-07-26 16:48:34 +0100 | [diff] [blame] | 88 | return -EINVAL; |
| 89 | } |
| 90 | |
| 91 | for (i = 0; i < 2; i++) { |
Kuninori Morimoto | 8ad8d81 | 2019-06-06 13:18:14 +0900 | [diff] [blame] | 92 | mop500_dai_links[i].cpus->of_node = msp_np[i]; |
| 93 | mop500_dai_links[i].cpus->dai_name = NULL; |
Kuninori Morimoto | 0296de8 | 2019-06-28 10:49:40 +0900 | [diff] [blame] | 94 | mop500_dai_links[i].platforms->of_node = msp_np[i]; |
| 95 | mop500_dai_links[i].platforms->name = NULL; |
Kuninori Morimoto | 8ad8d81 | 2019-06-06 13:18:14 +0900 | [diff] [blame] | 96 | mop500_dai_links[i].codecs->of_node = codec_np; |
| 97 | mop500_dai_links[i].codecs->name = NULL; |
Lee Jones | 0af541ce | 2012-07-26 16:48:34 +0100 | [diff] [blame] | 98 | } |
| 99 | |
| 100 | snd_soc_of_parse_card_name(&mop500_card, "stericsson,card-name"); |
| 101 | |
| 102 | return 0; |
| 103 | } |
Lee Jones | 39013bd | 2012-10-15 14:13:25 +0100 | [diff] [blame] | 104 | |
Bill Pemberton | da79487 | 2012-12-07 09:26:35 -0500 | [diff] [blame] | 105 | static int mop500_probe(struct platform_device *pdev) |
Ola Lilja | e069038 | 2012-06-12 08:50:08 +0200 | [diff] [blame] | 106 | { |
Lee Jones | 0af541ce | 2012-07-26 16:48:34 +0100 | [diff] [blame] | 107 | struct device_node *np = pdev->dev.of_node; |
Ola Lilja | e069038 | 2012-06-12 08:50:08 +0200 | [diff] [blame] | 108 | int ret; |
| 109 | |
Ola Lilja | e069038 | 2012-06-12 08:50:08 +0200 | [diff] [blame] | 110 | dev_dbg(&pdev->dev, "%s: Enter.\n", __func__); |
| 111 | |
| 112 | mop500_card.dev = &pdev->dev; |
| 113 | |
Lee Jones | 0af541ce | 2012-07-26 16:48:34 +0100 | [diff] [blame] | 114 | if (np) { |
| 115 | ret = mop500_of_probe(pdev, np); |
| 116 | if (ret) |
| 117 | return ret; |
| 118 | } |
| 119 | |
Ola Lilja | e069038 | 2012-06-12 08:50:08 +0200 | [diff] [blame] | 120 | dev_dbg(&pdev->dev, "%s: Card %s: Set platform drvdata.\n", |
| 121 | __func__, mop500_card.name); |
Ola Lilja | e069038 | 2012-06-12 08:50:08 +0200 | [diff] [blame] | 122 | |
| 123 | snd_soc_card_set_drvdata(&mop500_card, NULL); |
| 124 | |
| 125 | dev_dbg(&pdev->dev, "%s: Card %s: num_links = %d\n", |
| 126 | __func__, mop500_card.name, mop500_card.num_links); |
| 127 | dev_dbg(&pdev->dev, "%s: Card %s: DAI-link 0: name = %s\n", |
| 128 | __func__, mop500_card.name, mop500_card.dai_link[0].name); |
| 129 | dev_dbg(&pdev->dev, "%s: Card %s: DAI-link 0: stream_name = %s\n", |
| 130 | __func__, mop500_card.name, |
| 131 | mop500_card.dai_link[0].stream_name); |
| 132 | |
| 133 | ret = snd_soc_register_card(&mop500_card); |
| 134 | if (ret) |
| 135 | dev_err(&pdev->dev, |
Lee Jones | 2087a69 | 2012-08-21 10:06:44 +0100 | [diff] [blame] | 136 | "Error: snd_soc_register_card failed (%d)!\n", ret); |
Ola Lilja | e069038 | 2012-06-12 08:50:08 +0200 | [diff] [blame] | 137 | |
| 138 | return ret; |
| 139 | } |
| 140 | |
Bill Pemberton | da79487 | 2012-12-07 09:26:35 -0500 | [diff] [blame] | 141 | static int mop500_remove(struct platform_device *pdev) |
Ola Lilja | e069038 | 2012-06-12 08:50:08 +0200 | [diff] [blame] | 142 | { |
Pierre-Louis Bossart | 5b920ab | 2021-03-26 16:59:26 -0500 | [diff] [blame] | 143 | struct snd_soc_card *card = platform_get_drvdata(pdev); |
Ola Lilja | e069038 | 2012-06-12 08:50:08 +0200 | [diff] [blame] | 144 | |
| 145 | pr_debug("%s: Enter.\n", __func__); |
| 146 | |
Pierre-Louis Bossart | 5b920ab | 2021-03-26 16:59:26 -0500 | [diff] [blame] | 147 | snd_soc_unregister_card(card); |
| 148 | mop500_ab8500_remove(card); |
Lee Jones | 39013bd | 2012-10-15 14:13:25 +0100 | [diff] [blame] | 149 | mop500_of_node_put(); |
Lee Jones | 2087a69 | 2012-08-21 10:06:44 +0100 | [diff] [blame] | 150 | |
Ola Lilja | e069038 | 2012-06-12 08:50:08 +0200 | [diff] [blame] | 151 | return 0; |
| 152 | } |
| 153 | |
Lee Jones | 0af541ce | 2012-07-26 16:48:34 +0100 | [diff] [blame] | 154 | static const struct of_device_id snd_soc_mop500_match[] = { |
| 155 | { .compatible = "stericsson,snd-soc-mop500", }, |
| 156 | {}, |
| 157 | }; |
Luis de Bethencourt | cfa7a38 | 2015-09-03 13:00:40 +0200 | [diff] [blame] | 158 | MODULE_DEVICE_TABLE(of, snd_soc_mop500_match); |
Lee Jones | 0af541ce | 2012-07-26 16:48:34 +0100 | [diff] [blame] | 159 | |
Ola Lilja | e069038 | 2012-06-12 08:50:08 +0200 | [diff] [blame] | 160 | static struct platform_driver snd_soc_mop500_driver = { |
| 161 | .driver = { |
Ola Lilja | e069038 | 2012-06-12 08:50:08 +0200 | [diff] [blame] | 162 | .name = "snd-soc-mop500", |
Lee Jones | 0af541ce | 2012-07-26 16:48:34 +0100 | [diff] [blame] | 163 | .of_match_table = snd_soc_mop500_match, |
Ola Lilja | e069038 | 2012-06-12 08:50:08 +0200 | [diff] [blame] | 164 | }, |
| 165 | .probe = mop500_probe, |
Bill Pemberton | da79487 | 2012-12-07 09:26:35 -0500 | [diff] [blame] | 166 | .remove = mop500_remove, |
Ola Lilja | e069038 | 2012-06-12 08:50:08 +0200 | [diff] [blame] | 167 | }; |
| 168 | |
| 169 | module_platform_driver(snd_soc_mop500_driver); |
Arnd Bergmann | 1783c9d | 2018-01-10 17:34:45 +0100 | [diff] [blame] | 170 | |
| 171 | MODULE_LICENSE("GPL v2"); |
| 172 | MODULE_DESCRIPTION("ASoC MOP500 board driver"); |
| 173 | MODULE_AUTHOR("Ola Lilja"); |