blob: 4b1d564bc480bd546ca94b5e53ba0a5936f6cd28 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001/* SPDX-License-Identifier: GPL-2.0+ */
Beniamino Galvani38e1a602016-05-08 08:30:17 +02002/*
3 * (C) Copyright 2016 - Beniamino Galvani <b.galvani@gmail.com>
Beniamino Galvani38e1a602016-05-08 08:30:17 +02004 */
5
6#ifndef __MESON_SM_H__
7#define __MESON_SM_H__
8
Alexey Romanov616df002023-01-10 13:56:46 +03009/**
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 Galvani38e1a602016-05-08 08:30:17 +020017ssize_t meson_sm_read_efuse(uintptr_t offset, void *buffer, size_t size);
Neil Armstrongb4acf5a2019-06-12 11:49:07 +020018
Alexey Romanov616df002023-01-10 13:56:46 +030019/**
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 */
27ssize_t meson_sm_write_efuse(uintptr_t offset, void *buffer, size_t size);
28
Neil Armstrongb4acf5a2019-06-12 11:49:07 +020029#define SM_SERIAL_SIZE 12
30
Alexey Romanov616df002023-01-10 13:56:46 +030031/**
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 Armstrong63f475c2019-06-12 11:49:06 +020038int meson_sm_get_serial(void *buffer, size_t size);
Beniamino Galvani38e1a602016-05-08 08:30:17 +020039
Neil Armstrong385309c2019-08-06 17:28:36 +020040enum {
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 Romanov616df002023-01-10 13:56:46 +030056/**
57 * meson_sm_get_reboot_reason - get reboot reason
58 */
Neil Armstrong385309c2019-08-06 17:28:36 +020059int meson_sm_get_reboot_reason(void);
60
Alexey Romanov92404a12023-05-31 12:31:54 +030061#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 */
71int 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 Galvani38e1a602016-05-08 08:30:17 +020091#endif /* __MESON_SM_H__ */