2 * STM32 ALSA SoC Digital Audio Interface (SAI) driver.
4 * Copyright (C) 2016, STMicroelectronics - All Rights Reserved
5 * Author(s): Olivier Moysan <olivier.moysan@st.com> for STMicroelectronics.
7 * License terms: GPL V2.0.
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.
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
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>
25 #include <sound/dmaengine_pcm.h>
26 #include <sound/core.h>
28 #include "stm32_sai.h"
30 static const struct of_device_id stm32_sai_ids[] = {
31 { .compatible = "st,stm32f4-sai", .data = (void *)SAI_STM32F4 },
35 static int stm32_sai_probe(struct platform_device *pdev)
37 struct device_node *np = pdev->dev.of_node;
38 struct stm32_sai_data *sai;
39 struct reset_control *rst;
42 const struct of_device_id *of_id;
44 sai = devm_kzalloc(&pdev->dev, sizeof(*sai), GFP_KERNEL);
48 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
49 base = devm_ioremap_resource(&pdev->dev, res);
53 of_id = of_match_device(stm32_sai_ids, &pdev->dev);
55 sai->version = (enum stm32_sai_version)of_id->data;
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);
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);
72 sai->irq = platform_get_irq(pdev, 0);
74 dev_err(&pdev->dev, "no irq for node %s\n", pdev->name);
79 rst = reset_control_get(&pdev->dev, NULL);
81 reset_control_assert(rst);
83 reset_control_deassert(rst);
87 platform_set_drvdata(pdev, sai);
89 return of_platform_populate(np, NULL, NULL, &pdev->dev);
92 static int stm32_sai_remove(struct platform_device *pdev)
94 of_platform_depopulate(&pdev->dev);
99 MODULE_DEVICE_TABLE(of, stm32_sai_ids);
101 static struct platform_driver stm32_sai_driver = {
103 .name = "st,stm32-sai",
104 .of_match_table = stm32_sai_ids,
106 .probe = stm32_sai_probe,
107 .remove = stm32_sai_remove,
110 module_platform_driver(stm32_sai_driver);
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");