Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0+ */ |
Beniamino Galvani | 38e1a60 | 2016-05-08 08:30:17 +0200 | [diff] [blame] | 2 | /* |
| 3 | * (C) Copyright 2016 - Beniamino Galvani <b.galvani@gmail.com> |
Beniamino Galvani | 38e1a60 | 2016-05-08 08:30:17 +0200 | [diff] [blame] | 4 | */ |
| 5 | |
| 6 | #ifndef __MESON_SM_H__ |
| 7 | #define __MESON_SM_H__ |
| 8 | |
Alexey Romanov | 616df00 | 2023-01-10 13:56:46 +0300 | [diff] [blame] | 9 | /** |
| 10 | * meson_sm_read_efuse - read efuse memory into buffer |
| 11 | * |
| 12 | * @offset: offset from the start efuse memory |
| 13 | * @buffer: pointer to buffer |
| 14 | * @size: number of bytes to read |
| 15 | * @return: number of bytes read |
| 16 | */ |
Beniamino Galvani | 38e1a60 | 2016-05-08 08:30:17 +0200 | [diff] [blame] | 17 | ssize_t meson_sm_read_efuse(uintptr_t offset, void *buffer, size_t size); |
Neil Armstrong | b4acf5a | 2019-06-12 11:49:07 +0200 | [diff] [blame] | 18 | |
Alexey Romanov | 616df00 | 2023-01-10 13:56:46 +0300 | [diff] [blame] | 19 | /** |
| 20 | * meson_sm_write_efuse - write into efuse memory from buffer |
| 21 | * |
| 22 | * @offset: offset from the start efuse memory |
| 23 | * @buffer: pointer to buffer |
| 24 | * @size: number of bytes to write |
| 25 | * @return: number of bytes written |
| 26 | */ |
| 27 | ssize_t meson_sm_write_efuse(uintptr_t offset, void *buffer, size_t size); |
| 28 | |
Neil Armstrong | b4acf5a | 2019-06-12 11:49:07 +0200 | [diff] [blame] | 29 | #define SM_SERIAL_SIZE 12 |
| 30 | |
Alexey Romanov | 616df00 | 2023-01-10 13:56:46 +0300 | [diff] [blame] | 31 | /** |
| 32 | * meson_sm_get_serial - read chip unique id into buffer |
| 33 | * |
| 34 | * @buffer: pointer to buffer |
| 35 | * @size: buffer size. |
| 36 | * @return: zero on success or -errno on failure |
| 37 | */ |
Neil Armstrong | 63f475c | 2019-06-12 11:49:06 +0200 | [diff] [blame] | 38 | int meson_sm_get_serial(void *buffer, size_t size); |
Beniamino Galvani | 38e1a60 | 2016-05-08 08:30:17 +0200 | [diff] [blame] | 39 | |
Neil Armstrong | 385309c | 2019-08-06 17:28:36 +0200 | [diff] [blame] | 40 | enum { |
| 41 | REBOOT_REASON_COLD = 0, |
| 42 | REBOOT_REASON_NORMAL = 1, |
| 43 | REBOOT_REASON_RECOVERY = 2, |
| 44 | REBOOT_REASON_UPDATE = 3, |
| 45 | REBOOT_REASON_FASTBOOT = 4, |
| 46 | REBOOT_REASON_SUSPEND_OFF = 5, |
| 47 | REBOOT_REASON_HIBERNATE = 6, |
| 48 | REBOOT_REASON_BOOTLOADER = 7, |
| 49 | REBOOT_REASON_SHUTDOWN_REBOOT = 8, |
| 50 | REBOOT_REASON_RPMBP = 9, |
| 51 | REBOOT_REASON_CRASH_DUMP = 11, |
| 52 | REBOOT_REASON_KERNEL_PANIC = 12, |
| 53 | REBOOT_REASON_WATCHDOG_REBOOT = 13, |
| 54 | }; |
| 55 | |
Alexey Romanov | 616df00 | 2023-01-10 13:56:46 +0300 | [diff] [blame] | 56 | /** |
| 57 | * meson_sm_get_reboot_reason - get reboot reason |
| 58 | */ |
Neil Armstrong | 385309c | 2019-08-06 17:28:36 +0200 | [diff] [blame] | 59 | int meson_sm_get_reboot_reason(void); |
| 60 | |
Alexey Romanov | 92404a1 | 2023-05-31 12:31:54 +0300 | [diff] [blame] | 61 | #define PWRDM_OFF 0 |
| 62 | #define PWRDM_ON 1 |
| 63 | |
| 64 | /** |
| 65 | * meson_sm_pwrdm_set - do command at specified power domain. |
| 66 | * |
| 67 | * @index: power domain index. |
| 68 | * @cmd: command index. |
| 69 | * @return: zero on success or error code on failure. |
| 70 | */ |
| 71 | int meson_sm_pwrdm_set(size_t index, int cmd); |
| 72 | |
| 73 | /** |
| 74 | * meson_sm_pwrdm_off - disable specified power domain. |
| 75 | * |
| 76 | * @index: power domain index. |
| 77 | * @return: zero on success or error code on failure. |
| 78 | */ |
| 79 | #define meson_sm_pwrdm_off(index) \ |
| 80 | meson_sm_pwrdm_set(index, PWRDM_OFF) |
| 81 | |
| 82 | /** |
| 83 | * meson_sm_pwrdm_on - enable specified power domain. |
| 84 | * |
| 85 | * @index: power domain index. |
| 86 | * @return: zero on success or error code on failure. |
| 87 | */ |
| 88 | #define meson_sm_pwrdm_on(index) \ |
| 89 | meson_sm_pwrdm_set(index, PWRDM_ON) |
| 90 | |
Beniamino Galvani | 38e1a60 | 2016-05-08 08:30:17 +0200 | [diff] [blame] | 91 | #endif /* __MESON_SM_H__ */ |