cc_pm.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. // SPDX-License-Identifier: GPL-2.0
  2. /* Copyright (C) 2012-2018 ARM Limited or its affiliates. */
  3. #include <linux/kernel.h>
  4. #include <linux/interrupt.h>
  5. #include <linux/pm_runtime.h>
  6. #include "cc_driver.h"
  7. #include "cc_buffer_mgr.h"
  8. #include "cc_request_mgr.h"
  9. #include "cc_sram_mgr.h"
  10. #include "cc_ivgen.h"
  11. #include "cc_hash.h"
  12. #include "cc_pm.h"
  13. #include "cc_fips.h"
  14. #define POWER_DOWN_ENABLE 0x01
  15. #define POWER_DOWN_DISABLE 0x00
  16. const struct dev_pm_ops ccree_pm = {
  17. SET_RUNTIME_PM_OPS(cc_pm_suspend, cc_pm_resume, NULL)
  18. };
  19. int cc_pm_suspend(struct device *dev)
  20. {
  21. struct cc_drvdata *drvdata = dev_get_drvdata(dev);
  22. dev_dbg(dev, "set HOST_POWER_DOWN_EN\n");
  23. fini_cc_regs(drvdata);
  24. cc_iowrite(drvdata, CC_REG(HOST_POWER_DOWN_EN), POWER_DOWN_ENABLE);
  25. cc_clk_off(drvdata);
  26. return 0;
  27. }
  28. int cc_pm_resume(struct device *dev)
  29. {
  30. int rc;
  31. struct cc_drvdata *drvdata = dev_get_drvdata(dev);
  32. dev_dbg(dev, "unset HOST_POWER_DOWN_EN\n");
  33. /* Enables the device source clk */
  34. rc = cc_clk_on(drvdata);
  35. if (rc) {
  36. dev_err(dev, "failed getting clock back on. We're toast.\n");
  37. return rc;
  38. }
  39. cc_iowrite(drvdata, CC_REG(HOST_POWER_DOWN_EN), POWER_DOWN_DISABLE);
  40. rc = init_cc_regs(drvdata, false);
  41. if (rc) {
  42. dev_err(dev, "init_cc_regs (%x)\n", rc);
  43. return rc;
  44. }
  45. /* check if tee fips error occurred during power down */
  46. cc_tee_handle_fips_error(drvdata);
  47. cc_init_hash_sram(drvdata);
  48. cc_init_iv_sram(drvdata);
  49. return 0;
  50. }
  51. int cc_pm_get(struct device *dev)
  52. {
  53. int rc = 0;
  54. struct cc_drvdata *drvdata = dev_get_drvdata(dev);
  55. if (drvdata->pm_on)
  56. rc = pm_runtime_get_sync(dev);
  57. return (rc == 1 ? 0 : rc);
  58. }
  59. int cc_pm_put_suspend(struct device *dev)
  60. {
  61. int rc = 0;
  62. struct cc_drvdata *drvdata = dev_get_drvdata(dev);
  63. if (drvdata->pm_on) {
  64. pm_runtime_mark_last_busy(dev);
  65. rc = pm_runtime_put_autosuspend(dev);
  66. }
  67. return rc;
  68. }
  69. int cc_pm_init(struct cc_drvdata *drvdata)
  70. {
  71. struct device *dev = drvdata_to_dev(drvdata);
  72. /* must be before the enabling to avoid resdundent suspending */
  73. pm_runtime_set_autosuspend_delay(dev, CC_SUSPEND_TIMEOUT);
  74. pm_runtime_use_autosuspend(dev);
  75. /* set us as active - note we won't do PM ops until cc_pm_go()! */
  76. return pm_runtime_set_active(dev);
  77. }
  78. /* enable the PM module*/
  79. void cc_pm_go(struct cc_drvdata *drvdata)
  80. {
  81. pm_runtime_enable(drvdata_to_dev(drvdata));
  82. drvdata->pm_on = true;
  83. }
  84. void cc_pm_fini(struct cc_drvdata *drvdata)
  85. {
  86. pm_runtime_disable(drvdata_to_dev(drvdata));
  87. drvdata->pm_on = false;
  88. }