pm-imx7ulp.c 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright (C) 2016 Freescale Semiconductor, Inc.
  4. * Copyright 2017-2018 NXP
  5. * Author: Dong Aisheng <[email protected]>
  6. */
  7. #include <linux/io.h>
  8. #include <linux/of.h>
  9. #include <linux/of_address.h>
  10. #include "common.h"
  11. #define SMC_PMCTRL 0x10
  12. #define BP_PMCTRL_PSTOPO 16
  13. #define PSTOPO_PSTOP3 0x3
  14. #define PSTOPO_PSTOP2 0x2
  15. #define PSTOPO_PSTOP1 0x1
  16. #define BP_PMCTRL_RUNM 8
  17. #define RUNM_RUN 0
  18. #define BP_PMCTRL_STOPM 0
  19. #define STOPM_STOP 0
  20. #define BM_PMCTRL_PSTOPO (3 << BP_PMCTRL_PSTOPO)
  21. #define BM_PMCTRL_RUNM (3 << BP_PMCTRL_RUNM)
  22. #define BM_PMCTRL_STOPM (7 << BP_PMCTRL_STOPM)
  23. static void __iomem *smc1_base;
  24. int imx7ulp_set_lpm(enum ulp_cpu_pwr_mode mode)
  25. {
  26. u32 val = readl_relaxed(smc1_base + SMC_PMCTRL);
  27. /* clear all */
  28. val &= ~(BM_PMCTRL_RUNM | BM_PMCTRL_STOPM | BM_PMCTRL_PSTOPO);
  29. switch (mode) {
  30. case ULP_PM_RUN:
  31. /* system/bus clock enabled */
  32. val |= PSTOPO_PSTOP3 << BP_PMCTRL_PSTOPO;
  33. break;
  34. case ULP_PM_WAIT:
  35. /* system clock disabled, bus clock enabled */
  36. val |= PSTOPO_PSTOP2 << BP_PMCTRL_PSTOPO;
  37. break;
  38. case ULP_PM_STOP:
  39. /* system/bus clock disabled */
  40. val |= PSTOPO_PSTOP1 << BP_PMCTRL_PSTOPO;
  41. break;
  42. default:
  43. return -EINVAL;
  44. }
  45. writel_relaxed(val, smc1_base + SMC_PMCTRL);
  46. return 0;
  47. }
  48. void __init imx7ulp_pm_init(void)
  49. {
  50. struct device_node *np;
  51. np = of_find_compatible_node(NULL, NULL, "fsl,imx7ulp-smc1");
  52. smc1_base = of_iomap(np, 0);
  53. of_node_put(np);
  54. WARN_ON(!smc1_base);
  55. imx7ulp_set_lpm(ULP_PM_RUN);
  56. }