exynos-lpass.c 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. /*
  2. * Copyright (C) 2015 - 2016 Samsung Electronics Co., Ltd.
  3. *
  4. * Authors: Inha Song <ideal.song@samsung.com>
  5. * Sylwester Nawrocki <s.nawrocki@samsung.com>
  6. *
  7. * Samsung Exynos SoC series Low Power Audio Subsystem driver.
  8. *
  9. * This module provides regmap for the Top SFR region and instantiates
  10. * devices for IP blocks like DMAC, I2S, UART.
  11. *
  12. * This program is free software; you can redistribute it and/or modify
  13. * it under the terms of the GNU General Public License version 2 and
  14. * only version 2 as published by the Free Software Foundation.
  15. */
  16. #include <linux/clk.h>
  17. #include <linux/delay.h>
  18. #include <linux/io.h>
  19. #include <linux/module.h>
  20. #include <linux/mfd/syscon.h>
  21. #include <linux/of.h>
  22. #include <linux/of_platform.h>
  23. #include <linux/platform_device.h>
  24. #include <linux/pm_runtime.h>
  25. #include <linux/regmap.h>
  26. #include <linux/soc/samsung/exynos-regs-pmu.h>
  27. #include <linux/types.h>
  28. /* LPASS Top register definitions */
  29. #define SFR_LPASS_CORE_SW_RESET 0x08
  30. #define LPASS_SB_SW_RESET BIT(11)
  31. #define LPASS_UART_SW_RESET BIT(10)
  32. #define LPASS_PCM_SW_RESET BIT(9)
  33. #define LPASS_I2S_SW_RESET BIT(8)
  34. #define LPASS_WDT1_SW_RESET BIT(4)
  35. #define LPASS_WDT0_SW_RESET BIT(3)
  36. #define LPASS_TIMER_SW_RESET BIT(2)
  37. #define LPASS_MEM_SW_RESET BIT(1)
  38. #define LPASS_DMA_SW_RESET BIT(0)
  39. #define SFR_LPASS_INTR_CA5_MASK 0x48
  40. #define SFR_LPASS_INTR_CPU_MASK 0x58
  41. #define LPASS_INTR_APM BIT(9)
  42. #define LPASS_INTR_MIF BIT(8)
  43. #define LPASS_INTR_TIMER BIT(7)
  44. #define LPASS_INTR_DMA BIT(6)
  45. #define LPASS_INTR_GPIO BIT(5)
  46. #define LPASS_INTR_I2S BIT(4)
  47. #define LPASS_INTR_PCM BIT(3)
  48. #define LPASS_INTR_SLIMBUS BIT(2)
  49. #define LPASS_INTR_UART BIT(1)
  50. #define LPASS_INTR_SFR BIT(0)
  51. struct exynos_lpass {
  52. /* pointer to the LPASS TOP regmap */
  53. struct regmap *top;
  54. struct clk *sfr0_clk;
  55. };
  56. static void exynos_lpass_core_sw_reset(struct exynos_lpass *lpass, int mask)
  57. {
  58. unsigned int val = 0;
  59. regmap_read(lpass->top, SFR_LPASS_CORE_SW_RESET, &val);
  60. val &= ~mask;
  61. regmap_write(lpass->top, SFR_LPASS_CORE_SW_RESET, val);
  62. usleep_range(100, 150);
  63. val |= mask;
  64. regmap_write(lpass->top, SFR_LPASS_CORE_SW_RESET, val);
  65. }
  66. static void exynos_lpass_enable(struct exynos_lpass *lpass)
  67. {
  68. clk_prepare_enable(lpass->sfr0_clk);
  69. /* Unmask SFR, DMA and I2S interrupt */
  70. regmap_write(lpass->top, SFR_LPASS_INTR_CA5_MASK,
  71. LPASS_INTR_SFR | LPASS_INTR_DMA | LPASS_INTR_I2S);
  72. regmap_write(lpass->top, SFR_LPASS_INTR_CPU_MASK,
  73. LPASS_INTR_SFR | LPASS_INTR_DMA | LPASS_INTR_I2S);
  74. exynos_lpass_core_sw_reset(lpass, LPASS_I2S_SW_RESET);
  75. exynos_lpass_core_sw_reset(lpass, LPASS_DMA_SW_RESET);
  76. exynos_lpass_core_sw_reset(lpass, LPASS_MEM_SW_RESET);
  77. }
  78. static void exynos_lpass_disable(struct exynos_lpass *lpass)
  79. {
  80. /* Mask any unmasked IP interrupt sources */
  81. regmap_write(lpass->top, SFR_LPASS_INTR_CPU_MASK, 0);
  82. regmap_write(lpass->top, SFR_LPASS_INTR_CA5_MASK, 0);
  83. clk_disable_unprepare(lpass->sfr0_clk);
  84. }
  85. static const struct regmap_config exynos_lpass_reg_conf = {
  86. .reg_bits = 32,
  87. .reg_stride = 4,
  88. .val_bits = 32,
  89. .max_register = 0xfc,
  90. .fast_io = true,
  91. };
  92. static int exynos_lpass_probe(struct platform_device *pdev)
  93. {
  94. struct device *dev = &pdev->dev;
  95. struct exynos_lpass *lpass;
  96. void __iomem *base_top;
  97. struct resource *res;
  98. lpass = devm_kzalloc(dev, sizeof(*lpass), GFP_KERNEL);
  99. if (!lpass)
  100. return -ENOMEM;
  101. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  102. base_top = devm_ioremap_resource(dev, res);
  103. if (IS_ERR(base_top))
  104. return PTR_ERR(base_top);
  105. lpass->sfr0_clk = devm_clk_get(dev, "sfr0_ctrl");
  106. if (IS_ERR(lpass->sfr0_clk))
  107. return PTR_ERR(lpass->sfr0_clk);
  108. lpass->top = regmap_init_mmio(dev, base_top,
  109. &exynos_lpass_reg_conf);
  110. if (IS_ERR(lpass->top)) {
  111. dev_err(dev, "LPASS top regmap initialization failed\n");
  112. return PTR_ERR(lpass->top);
  113. }
  114. platform_set_drvdata(pdev, lpass);
  115. pm_runtime_set_active(dev);
  116. pm_runtime_enable(dev);
  117. exynos_lpass_enable(lpass);
  118. return devm_of_platform_populate(dev);
  119. }
  120. static int exynos_lpass_remove(struct platform_device *pdev)
  121. {
  122. struct exynos_lpass *lpass = platform_get_drvdata(pdev);
  123. exynos_lpass_disable(lpass);
  124. pm_runtime_disable(&pdev->dev);
  125. if (!pm_runtime_status_suspended(&pdev->dev))
  126. exynos_lpass_disable(lpass);
  127. regmap_exit(lpass->top);
  128. return 0;
  129. }
  130. static int __maybe_unused exynos_lpass_suspend(struct device *dev)
  131. {
  132. struct exynos_lpass *lpass = dev_get_drvdata(dev);
  133. exynos_lpass_disable(lpass);
  134. return 0;
  135. }
  136. static int __maybe_unused exynos_lpass_resume(struct device *dev)
  137. {
  138. struct exynos_lpass *lpass = dev_get_drvdata(dev);
  139. exynos_lpass_enable(lpass);
  140. return 0;
  141. }
  142. static const struct dev_pm_ops lpass_pm_ops = {
  143. SET_RUNTIME_PM_OPS(exynos_lpass_suspend, exynos_lpass_resume, NULL)
  144. SET_LATE_SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend,
  145. pm_runtime_force_resume)
  146. };
  147. static const struct of_device_id exynos_lpass_of_match[] = {
  148. { .compatible = "samsung,exynos5433-lpass" },
  149. { },
  150. };
  151. MODULE_DEVICE_TABLE(of, exynos_lpass_of_match);
  152. static struct platform_driver exynos_lpass_driver = {
  153. .driver = {
  154. .name = "exynos-lpass",
  155. .pm = &lpass_pm_ops,
  156. .of_match_table = exynos_lpass_of_match,
  157. },
  158. .probe = exynos_lpass_probe,
  159. .remove = exynos_lpass_remove,
  160. };
  161. module_platform_driver(exynos_lpass_driver);
  162. MODULE_DESCRIPTION("Samsung Low Power Audio Subsystem driver");
  163. MODULE_LICENSE("GPL v2");