exynos-lpass.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  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/delay.h>
  17. #include <linux/io.h>
  18. #include <linux/module.h>
  19. #include <linux/mfd/syscon.h>
  20. #include <linux/mfd/syscon/exynos5-pmu.h>
  21. #include <linux/of.h>
  22. #include <linux/of_platform.h>
  23. #include <linux/platform_device.h>
  24. #include <linux/regmap.h>
  25. #include <linux/types.h>
  26. /* LPASS Top register definitions */
  27. #define SFR_LPASS_CORE_SW_RESET 0x08
  28. #define LPASS_SB_SW_RESET BIT(11)
  29. #define LPASS_UART_SW_RESET BIT(10)
  30. #define LPASS_PCM_SW_RESET BIT(9)
  31. #define LPASS_I2S_SW_RESET BIT(8)
  32. #define LPASS_WDT1_SW_RESET BIT(4)
  33. #define LPASS_WDT0_SW_RESET BIT(3)
  34. #define LPASS_TIMER_SW_RESET BIT(2)
  35. #define LPASS_MEM_SW_RESET BIT(1)
  36. #define LPASS_DMA_SW_RESET BIT(0)
  37. #define SFR_LPASS_INTR_CA5_MASK 0x48
  38. #define SFR_LPASS_INTR_CPU_MASK 0x58
  39. #define LPASS_INTR_APM BIT(9)
  40. #define LPASS_INTR_MIF BIT(8)
  41. #define LPASS_INTR_TIMER BIT(7)
  42. #define LPASS_INTR_DMA BIT(6)
  43. #define LPASS_INTR_GPIO BIT(5)
  44. #define LPASS_INTR_I2S BIT(4)
  45. #define LPASS_INTR_PCM BIT(3)
  46. #define LPASS_INTR_SLIMBUS BIT(2)
  47. #define LPASS_INTR_UART BIT(1)
  48. #define LPASS_INTR_SFR BIT(0)
  49. struct exynos_lpass {
  50. /* pointer to the Power Management Unit regmap */
  51. struct regmap *pmu;
  52. /* pointer to the LPASS TOP regmap */
  53. struct regmap *top;
  54. };
  55. static void exynos_lpass_core_sw_reset(struct exynos_lpass *lpass, int mask)
  56. {
  57. unsigned int val = 0;
  58. regmap_read(lpass->top, SFR_LPASS_CORE_SW_RESET, &val);
  59. val &= ~mask;
  60. regmap_write(lpass->top, SFR_LPASS_CORE_SW_RESET, val);
  61. usleep_range(100, 150);
  62. val |= mask;
  63. regmap_write(lpass->top, SFR_LPASS_CORE_SW_RESET, val);
  64. }
  65. static void exynos_lpass_enable(struct exynos_lpass *lpass)
  66. {
  67. /* Unmask SFR, DMA and I2S interrupt */
  68. regmap_write(lpass->top, SFR_LPASS_INTR_CA5_MASK,
  69. LPASS_INTR_SFR | LPASS_INTR_DMA | LPASS_INTR_I2S);
  70. regmap_write(lpass->top, SFR_LPASS_INTR_CPU_MASK,
  71. LPASS_INTR_SFR | LPASS_INTR_DMA | LPASS_INTR_I2S);
  72. /* Activate related PADs from retention state */
  73. regmap_write(lpass->pmu, EXYNOS5433_PAD_RETENTION_AUD_OPTION,
  74. EXYNOS5433_PAD_INITIATE_WAKEUP_FROM_LOWPWR);
  75. exynos_lpass_core_sw_reset(lpass, LPASS_I2S_SW_RESET);
  76. exynos_lpass_core_sw_reset(lpass, LPASS_DMA_SW_RESET);
  77. exynos_lpass_core_sw_reset(lpass, LPASS_MEM_SW_RESET);
  78. }
  79. static void exynos_lpass_disable(struct exynos_lpass *lpass)
  80. {
  81. /* Mask any unmasked IP interrupt sources */
  82. regmap_write(lpass->top, SFR_LPASS_INTR_CPU_MASK, 0);
  83. regmap_write(lpass->top, SFR_LPASS_INTR_CA5_MASK, 0);
  84. /* Deactivate related PADs from retention state */
  85. regmap_write(lpass->pmu, EXYNOS5433_PAD_RETENTION_AUD_OPTION, 0);
  86. }
  87. static const struct regmap_config exynos_lpass_reg_conf = {
  88. .reg_bits = 32,
  89. .reg_stride = 4,
  90. .val_bits = 32,
  91. .max_register = 0xfc,
  92. .fast_io = true,
  93. };
  94. static int exynos_lpass_probe(struct platform_device *pdev)
  95. {
  96. struct device *dev = &pdev->dev;
  97. struct exynos_lpass *lpass;
  98. void __iomem *base_top;
  99. struct resource *res;
  100. lpass = devm_kzalloc(dev, sizeof(*lpass), GFP_KERNEL);
  101. if (!lpass)
  102. return -ENOMEM;
  103. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  104. base_top = devm_ioremap_resource(dev, res);
  105. if (IS_ERR(base_top))
  106. return PTR_ERR(base_top);
  107. lpass->top = regmap_init_mmio(dev, base_top,
  108. &exynos_lpass_reg_conf);
  109. if (IS_ERR(lpass->top)) {
  110. dev_err(dev, "LPASS top regmap initialization failed\n");
  111. return PTR_ERR(lpass->top);
  112. }
  113. lpass->pmu = syscon_regmap_lookup_by_phandle(dev->of_node,
  114. "samsung,pmu-syscon");
  115. if (IS_ERR(lpass->pmu)) {
  116. dev_err(dev, "Failed to lookup PMU regmap\n");
  117. return PTR_ERR(lpass->pmu);
  118. }
  119. platform_set_drvdata(pdev, lpass);
  120. exynos_lpass_enable(lpass);
  121. return of_platform_populate(dev->of_node, NULL, NULL, dev);
  122. }
  123. static int __maybe_unused exynos_lpass_suspend(struct device *dev)
  124. {
  125. struct exynos_lpass *lpass = dev_get_drvdata(dev);
  126. exynos_lpass_disable(lpass);
  127. return 0;
  128. }
  129. static int __maybe_unused exynos_lpass_resume(struct device *dev)
  130. {
  131. struct exynos_lpass *lpass = dev_get_drvdata(dev);
  132. exynos_lpass_enable(lpass);
  133. return 0;
  134. }
  135. static SIMPLE_DEV_PM_OPS(lpass_pm_ops, exynos_lpass_suspend,
  136. exynos_lpass_resume);
  137. static const struct of_device_id exynos_lpass_of_match[] = {
  138. { .compatible = "samsung,exynos5433-lpass" },
  139. { },
  140. };
  141. MODULE_DEVICE_TABLE(of, exynos_lpass_of_match);
  142. static struct platform_driver exynos_lpass_driver = {
  143. .driver = {
  144. .name = "exynos-lpass",
  145. .pm = &lpass_pm_ops,
  146. .of_match_table = exynos_lpass_of_match,
  147. },
  148. .probe = exynos_lpass_probe,
  149. };
  150. module_platform_driver(exynos_lpass_driver);
  151. MODULE_DESCRIPTION("Samsung Low Power Audio Subsystem driver");
  152. MODULE_LICENSE("GPL v2");