]> git.karo-electronics.de Git - karo-tx-linux.git/blob - sound/soc/stm/stm32_sai.c
Merge branch 'for-upstream' of git://git.kernel.org/pub/scm/linux/kernel/git/bluetoot...
[karo-tx-linux.git] / sound / soc / stm / stm32_sai.c
1 /*
2  * STM32 ALSA SoC Digital Audio Interface (SAI) driver.
3  *
4  * Copyright (C) 2016, STMicroelectronics - All Rights Reserved
5  * Author(s): Olivier Moysan <olivier.moysan@st.com> for STMicroelectronics.
6  *
7  * License terms: GPL V2.0.
8  *
9  * This program is free software; you can redistribute it and/or modify it
10  * under the terms of the GNU General Public License version 2 as published by
11  * the Free Software Foundation.
12  *
13  * This program is distributed in the hope that it will be useful, but
14  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
16  * details.
17  */
18
19 #include <linux/clk.h>
20 #include <linux/delay.h>
21 #include <linux/module.h>
22 #include <linux/of_platform.h>
23 #include <linux/reset.h>
24
25 #include <sound/dmaengine_pcm.h>
26 #include <sound/core.h>
27
28 #include "stm32_sai.h"
29
30 static const struct of_device_id stm32_sai_ids[] = {
31         { .compatible = "st,stm32f4-sai", .data = (void *)SAI_STM32F4 },
32         {}
33 };
34
35 static int stm32_sai_probe(struct platform_device *pdev)
36 {
37         struct device_node *np = pdev->dev.of_node;
38         struct stm32_sai_data *sai;
39         struct reset_control *rst;
40         struct resource *res;
41         void __iomem *base;
42         const struct of_device_id *of_id;
43
44         sai = devm_kzalloc(&pdev->dev, sizeof(*sai), GFP_KERNEL);
45         if (!sai)
46                 return -ENOMEM;
47
48         res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
49         base = devm_ioremap_resource(&pdev->dev, res);
50         if (IS_ERR(base))
51                 return PTR_ERR(base);
52
53         of_id = of_match_device(stm32_sai_ids, &pdev->dev);
54         if (of_id)
55                 sai->version = (enum stm32_sai_version)of_id->data;
56         else
57                 return -EINVAL;
58
59         sai->clk_x8k = devm_clk_get(&pdev->dev, "x8k");
60         if (IS_ERR(sai->clk_x8k)) {
61                 dev_err(&pdev->dev, "missing x8k parent clock\n");
62                 return PTR_ERR(sai->clk_x8k);
63         }
64
65         sai->clk_x11k = devm_clk_get(&pdev->dev, "x11k");
66         if (IS_ERR(sai->clk_x11k)) {
67                 dev_err(&pdev->dev, "missing x11k parent clock\n");
68                 return PTR_ERR(sai->clk_x11k);
69         }
70
71         /* init irqs */
72         sai->irq = platform_get_irq(pdev, 0);
73         if (sai->irq < 0) {
74                 dev_err(&pdev->dev, "no irq for node %s\n", pdev->name);
75                 return sai->irq;
76         }
77
78         /* reset */
79         rst = reset_control_get(&pdev->dev, NULL);
80         if (!IS_ERR(rst)) {
81                 reset_control_assert(rst);
82                 udelay(2);
83                 reset_control_deassert(rst);
84         }
85
86         sai->pdev = pdev;
87         platform_set_drvdata(pdev, sai);
88
89         return of_platform_populate(np, NULL, NULL, &pdev->dev);
90 }
91
92 static int stm32_sai_remove(struct platform_device *pdev)
93 {
94         of_platform_depopulate(&pdev->dev);
95
96         return 0;
97 }
98
99 MODULE_DEVICE_TABLE(of, stm32_sai_ids);
100
101 static struct platform_driver stm32_sai_driver = {
102         .driver = {
103                 .name = "st,stm32-sai",
104                 .of_match_table = stm32_sai_ids,
105         },
106         .probe = stm32_sai_probe,
107         .remove = stm32_sai_remove,
108 };
109
110 module_platform_driver(stm32_sai_driver);
111
112 MODULE_DESCRIPTION("STM32 Soc SAI Interface");
113 MODULE_AUTHOR("Olivier Moysan, <olivier.moysan@st.com>");
114 MODULE_ALIAS("platform:st,stm32-sai");
115 MODULE_LICENSE("GPL v2");