Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 2 | /* Copyright (C) 2012-2019 ARM Limited (or its affiliates). */ |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 3 | |
| 4 | #include <linux/kernel.h> |
| 5 | #include <linux/interrupt.h> |
| 6 | #include <linux/pm_runtime.h> |
| 7 | #include "cc_driver.h" |
| 8 | #include "cc_buffer_mgr.h" |
| 9 | #include "cc_request_mgr.h" |
| 10 | #include "cc_sram_mgr.h" |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 11 | #include "cc_hash.h" |
| 12 | #include "cc_pm.h" |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 13 | #include "cc_fips.h" |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 14 | |
| 15 | #define POWER_DOWN_ENABLE 0x01 |
| 16 | #define POWER_DOWN_DISABLE 0x00 |
| 17 | |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 18 | static int cc_pm_suspend(struct device *dev) |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 19 | { |
| 20 | struct cc_drvdata *drvdata = dev_get_drvdata(dev); |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 21 | |
| 22 | dev_dbg(dev, "set HOST_POWER_DOWN_EN\n"); |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 23 | fini_cc_regs(drvdata); |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 24 | cc_iowrite(drvdata, CC_REG(HOST_POWER_DOWN_EN), POWER_DOWN_ENABLE); |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 25 | clk_disable_unprepare(drvdata->clk); |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 26 | return 0; |
| 27 | } |
| 28 | |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 29 | static int cc_pm_resume(struct device *dev) |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 30 | { |
| 31 | int rc; |
| 32 | struct cc_drvdata *drvdata = dev_get_drvdata(dev); |
| 33 | |
| 34 | dev_dbg(dev, "unset HOST_POWER_DOWN_EN\n"); |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 35 | /* Enables the device source clk */ |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 36 | rc = clk_prepare_enable(drvdata->clk); |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 37 | if (rc) { |
| 38 | dev_err(dev, "failed getting clock back on. We're toast.\n"); |
| 39 | return rc; |
| 40 | } |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 41 | /* wait for Cryptocell reset completion */ |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 42 | if (!cc_wait_for_reset_completion(drvdata)) { |
| 43 | dev_err(dev, "Cryptocell reset not completed"); |
| 44 | return -EBUSY; |
| 45 | } |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 46 | |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 47 | cc_iowrite(drvdata, CC_REG(HOST_POWER_DOWN_EN), POWER_DOWN_DISABLE); |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 48 | rc = init_cc_regs(drvdata, false); |
| 49 | if (rc) { |
| 50 | dev_err(dev, "init_cc_regs (%x)\n", rc); |
| 51 | return rc; |
| 52 | } |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 53 | /* check if tee fips error occurred during power down */ |
| 54 | cc_tee_handle_fips_error(drvdata); |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 55 | |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 56 | cc_init_hash_sram(drvdata); |
| 57 | |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 58 | return 0; |
| 59 | } |
| 60 | |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 61 | const struct dev_pm_ops ccree_pm = { |
| 62 | SET_RUNTIME_PM_OPS(cc_pm_suspend, cc_pm_resume, NULL) |
| 63 | }; |
| 64 | |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 65 | int cc_pm_get(struct device *dev) |
| 66 | { |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 67 | int rc = pm_runtime_get_sync(dev); |
| 68 | if (rc < 0) { |
| 69 | pm_runtime_put_noidle(dev); |
| 70 | return rc; |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 71 | } |
Olivier Deprez | 0e64123 | 2021-09-23 10:07:05 +0200 | [diff] [blame] | 72 | |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 73 | return 0; |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 74 | } |
| 75 | |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 76 | void cc_pm_put_suspend(struct device *dev) |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 77 | { |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 78 | pm_runtime_mark_last_busy(dev); |
| 79 | pm_runtime_put_autosuspend(dev); |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 80 | } |