stm32_sai.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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. #include <linux/clk.h>
  19. #include <linux/delay.h>
  20. #include <linux/module.h>
  21. #include <linux/of_platform.h>
  22. #include <linux/reset.h>
  23. #include <sound/dmaengine_pcm.h>
  24. #include <sound/core.h>
  25. #include "stm32_sai.h"
  26. static const struct stm32_sai_conf stm32_sai_conf_f4 = {
  27. .version = SAI_STM32F4,
  28. };
  29. static const struct stm32_sai_conf stm32_sai_conf_h7 = {
  30. .version = SAI_STM32H7,
  31. };
  32. static const struct of_device_id stm32_sai_ids[] = {
  33. { .compatible = "st,stm32f4-sai", .data = (void *)&stm32_sai_conf_f4 },
  34. { .compatible = "st,stm32h7-sai", .data = (void *)&stm32_sai_conf_h7 },
  35. {}
  36. };
  37. static int stm32_sai_probe(struct platform_device *pdev)
  38. {
  39. struct device_node *np = pdev->dev.of_node;
  40. struct stm32_sai_data *sai;
  41. struct reset_control *rst;
  42. struct resource *res;
  43. void __iomem *base;
  44. const struct of_device_id *of_id;
  45. sai = devm_kzalloc(&pdev->dev, sizeof(*sai), GFP_KERNEL);
  46. if (!sai)
  47. return -ENOMEM;
  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. of_id = of_match_device(stm32_sai_ids, &pdev->dev);
  53. if (of_id)
  54. sai->conf = (struct stm32_sai_conf *)of_id->data;
  55. else
  56. return -EINVAL;
  57. sai->clk_x8k = devm_clk_get(&pdev->dev, "x8k");
  58. if (IS_ERR(sai->clk_x8k)) {
  59. dev_err(&pdev->dev, "missing x8k parent clock\n");
  60. return PTR_ERR(sai->clk_x8k);
  61. }
  62. sai->clk_x11k = devm_clk_get(&pdev->dev, "x11k");
  63. if (IS_ERR(sai->clk_x11k)) {
  64. dev_err(&pdev->dev, "missing x11k parent clock\n");
  65. return PTR_ERR(sai->clk_x11k);
  66. }
  67. /* init irqs */
  68. sai->irq = platform_get_irq(pdev, 0);
  69. if (sai->irq < 0) {
  70. dev_err(&pdev->dev, "no irq for node %s\n", pdev->name);
  71. return sai->irq;
  72. }
  73. /* reset */
  74. rst = reset_control_get_exclusive(&pdev->dev, NULL);
  75. if (!IS_ERR(rst)) {
  76. reset_control_assert(rst);
  77. udelay(2);
  78. reset_control_deassert(rst);
  79. }
  80. sai->pdev = pdev;
  81. platform_set_drvdata(pdev, sai);
  82. return of_platform_populate(np, NULL, NULL, &pdev->dev);
  83. }
  84. static int stm32_sai_remove(struct platform_device *pdev)
  85. {
  86. of_platform_depopulate(&pdev->dev);
  87. return 0;
  88. }
  89. MODULE_DEVICE_TABLE(of, stm32_sai_ids);
  90. static struct platform_driver stm32_sai_driver = {
  91. .driver = {
  92. .name = "st,stm32-sai",
  93. .of_match_table = stm32_sai_ids,
  94. },
  95. .probe = stm32_sai_probe,
  96. .remove = stm32_sai_remove,
  97. };
  98. module_platform_driver(stm32_sai_driver);
  99. MODULE_DESCRIPTION("STM32 Soc SAI Interface");
  100. MODULE_AUTHOR("Olivier Moysan <olivier.moysan@st.com>");
  101. MODULE_ALIAS("platform:st,stm32-sai");
  102. MODULE_LICENSE("GPL v2");