cc_pm.c 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. // SPDX-License-Identifier: GPL-2.0
  2. /* Copyright (C) 2012-2019 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_hash.h"
  11. #include "cc_pm.h"
  12. #include "cc_fips.h"
  13. #define POWER_DOWN_ENABLE 0x01
  14. #define POWER_DOWN_DISABLE 0x00
  15. static int cc_pm_suspend(struct device *dev)
  16. {
  17. struct cc_drvdata *drvdata = dev_get_drvdata(dev);
  18. dev_dbg(dev, "set HOST_POWER_DOWN_EN\n");
  19. fini_cc_regs(drvdata);
  20. cc_iowrite(drvdata, CC_REG(HOST_POWER_DOWN_EN), POWER_DOWN_ENABLE);
  21. clk_disable_unprepare(drvdata->clk);
  22. return 0;
  23. }
  24. static int cc_pm_resume(struct device *dev)
  25. {
  26. int rc;
  27. struct cc_drvdata *drvdata = dev_get_drvdata(dev);
  28. dev_dbg(dev, "unset HOST_POWER_DOWN_EN\n");
  29. /* Enables the device source clk */
  30. rc = clk_prepare_enable(drvdata->clk);
  31. if (rc) {
  32. dev_err(dev, "failed getting clock back on. We're toast.\n");
  33. return rc;
  34. }
  35. /* wait for Cryptocell reset completion */
  36. if (!cc_wait_for_reset_completion(drvdata)) {
  37. dev_err(dev, "Cryptocell reset not completed");
  38. clk_disable_unprepare(drvdata->clk);
  39. return -EBUSY;
  40. }
  41. cc_iowrite(drvdata, CC_REG(HOST_POWER_DOWN_EN), POWER_DOWN_DISABLE);
  42. rc = init_cc_regs(drvdata);
  43. if (rc) {
  44. dev_err(dev, "init_cc_regs (%x)\n", rc);
  45. clk_disable_unprepare(drvdata->clk);
  46. return rc;
  47. }
  48. /* check if tee fips error occurred during power down */
  49. cc_tee_handle_fips_error(drvdata);
  50. cc_init_hash_sram(drvdata);
  51. return 0;
  52. }
  53. const struct dev_pm_ops ccree_pm = {
  54. SET_RUNTIME_PM_OPS(cc_pm_suspend, cc_pm_resume, NULL)
  55. };
  56. int cc_pm_get(struct device *dev)
  57. {
  58. int rc = pm_runtime_get_sync(dev);
  59. if (rc < 0) {
  60. pm_runtime_put_noidle(dev);
  61. return rc;
  62. }
  63. return 0;
  64. }
  65. void cc_pm_put_suspend(struct device *dev)
  66. {
  67. pm_runtime_put_autosuspend(dev);
  68. }