Merge tag 'u-boot-atmel-fixes-2020.07-a' of https://gitlab.denx.de/u-boot/custodians...
[oweals/u-boot.git] / arch / arm / mach-socfpga / include / mach / mailbox_s10.h
1 /* SPDX-License-Identifier: GPL-2.0
2  *
3  * Copyright (C) 2017-2018 Intel Corporation <www.intel.com>
4  *
5  */
6
7 #ifndef _MAILBOX_S10_H_
8 #define _MAILBOX_S10_H_
9
10 /* user define Uboot ID */
11 #include <linux/bitops.h>
12 #define MBOX_CLIENT_ID_UBOOT    0xB
13 #define MBOX_ID_UBOOT           0x1
14
15 #define MBOX_CMD_DIRECT 0
16 #define MBOX_CMD_INDIRECT       1
17
18 #define MBOX_MAX_CMD_INDEX      2047
19 #define MBOX_CMD_BUFFER_SIZE    32
20 #define MBOX_RESP_BUFFER_SIZE   16
21
22 #define MBOX_HDR_CMD_LSB        0
23 #define MBOX_HDR_CMD_MSK        (BIT(11) - 1)
24 #define MBOX_HDR_I_LSB          11
25 #define MBOX_HDR_I_MSK          BIT(11)
26 #define MBOX_HDR_LEN_LSB        12
27 #define MBOX_HDR_LEN_MSK        0x007FF000
28 #define MBOX_HDR_ID_LSB         24
29 #define MBOX_HDR_ID_MSK         0x0F000000
30 #define MBOX_HDR_CLIENT_LSB     28
31 #define MBOX_HDR_CLIENT_MSK     0xF0000000
32
33 /* Interrupt flags */
34 #define MBOX_FLAGS_INT_COE      BIT(0)  /* COUT update interrupt enable */
35 #define MBOX_FLAGS_INT_RIE      BIT(1)  /* RIN update interrupt enable */
36 #define MBOX_FLAGS_INT_UAE      BIT(8)  /* Urgent ACK interrupt enable */
37 #define MBOX_ALL_INTRS          (MBOX_FLAGS_INT_COE | \
38                                  MBOX_FLAGS_INT_RIE | \
39                                  MBOX_FLAGS_INT_UAE)
40
41 /* Status */
42 #define MBOX_STATUS_UA_MSK      BIT(8)
43
44 #define MBOX_CMD_HEADER(client, id, len, indirect, cmd)     \
45         ((((cmd) << MBOX_HDR_CMD_LSB) & MBOX_HDR_CMD_MSK) | \
46         (((indirect) << MBOX_HDR_I_LSB) & MBOX_HDR_I_MSK) | \
47         (((len) << MBOX_HDR_LEN_LSB) & MBOX_HDR_LEN_MSK)  | \
48         (((id) << MBOX_HDR_ID_LSB) & MBOX_HDR_ID_MSK)     | \
49         (((client) << MBOX_HDR_CLIENT_LSB) & MBOX_HDR_CLIENT_MSK))
50
51 #define MBOX_RESP_ERR_GET(resp)                         \
52         (((resp) & MBOX_HDR_CMD_MSK) >> MBOX_HDR_CMD_LSB)
53 #define MBOX_RESP_LEN_GET(resp)                 \
54         (((resp) & MBOX_HDR_LEN_MSK) >> MBOX_HDR_LEN_LSB)
55 #define MBOX_RESP_ID_GET(resp)                          \
56         (((resp) & MBOX_HDR_ID_MSK) >> MBOX_HDR_ID_LSB)
57 #define MBOX_RESP_CLIENT_GET(resp)                      \
58         (((resp) & MBOX_HDR_CLIENT_MSK) >> MBOX_HDR_CLIENT_LSB)
59
60 /* Response error list */
61 enum ALT_SDM_MBOX_RESP_CODE {
62         /* CMD completed successfully, but check resp ARGS for any errors */
63         MBOX_RESP_STATOK = 0,
64         /* CMD is incorrectly formatted in some way */
65         MBOX_RESP_INVALID_COMMAND = 1,
66         /* BootROM Command code not undesrtood */
67         MBOX_RESP_UNKNOWN_BR = 2,
68         /* CMD code not recognized by firmware */
69         MBOX_RESP_UNKNOWN = 3,
70         /* Indicates that the device is not configured */
71         MBOX_RESP_NOT_CONFIGURED = 256,
72         /* Indicates that the device is busy */
73         MBOX_RESP_DEVICE_BUSY = 0x1FF,
74         /* Indicates that there is no valid response available */
75         MBOX_RESP_NO_VALID_RESP_AVAILABLE = 0x2FF,
76         /* General Error */
77         MBOX_RESP_ERROR = 0x3FF,
78 };
79
80 /* Mailbox command list */
81 #define MBOX_RESTART            2
82 #define MBOX_CONFIG_STATUS      4
83 #define MBOX_RECONFIG           6
84 #define MBOX_RECONFIG_MSEL      7
85 #define MBOX_RECONFIG_DATA      8
86 #define MBOX_RECONFIG_STATUS    9
87 #define MBOX_QSPI_OPEN          50
88 #define MBOX_QSPI_CLOSE         51
89 #define MBOX_QSPI_DIRECT        59
90 #define MBOX_REBOOT_HPS         71
91
92 /* Mailbox registers */
93 #define MBOX_CIN                        0       /* command valid offset */
94 #define MBOX_ROUT                       4       /* response output offset */
95 #define MBOX_URG                        8       /* urgent command */
96 #define MBOX_FLAGS                      0x0c    /* interrupt enables */
97 #define MBOX_COUT                       0x20    /* command free offset */
98 #define MBOX_RIN                        0x24    /* respond valid offset */
99 #define MBOX_STATUS                     0x2c    /* mailbox status */
100 #define MBOX_CMD_BUF                    0x40    /* circular command buffer */
101 #define MBOX_RESP_BUF                   0xc0    /* circular response buffer */
102 #define MBOX_DOORBELL_TO_SDM            0x400   /* Doorbell to SDM */
103 #define MBOX_DOORBELL_FROM_SDM          0x480   /* Doorbell from SDM */
104
105 /* Status and bit information returned by RECONFIG_STATUS */
106 #define RECONFIG_STATUS_RESPONSE_LEN                    6
107 #define RECONFIG_STATUS_STATE                           0
108 #define RECONFIG_STATUS_PIN_STATUS                      2
109 #define RECONFIG_STATUS_SOFTFUNC_STATUS                 3
110
111 /* Macros for specifying number of arguments in mailbox command */
112 #define MBOX_NUM_ARGS(n, b)                             (((n) & 0xFF) << (b))
113 #define MBOX_DIRECT_COUNT(n)                            MBOX_NUM_ARGS((n), 0)
114 #define MBOX_ARG_DESC_COUNT(n)                          MBOX_NUM_ARGS((n), 8)
115 #define MBOX_RESP_DESC_COUNT(n)                         MBOX_NUM_ARGS((n), 16)
116
117 #define MBOX_CFGSTAT_STATE_IDLE                         0x00000000
118 #define MBOX_CFGSTAT_STATE_CONFIG                       0x10000000
119 #define MBOX_CFGSTAT_STATE_FAILACK                      0x08000000
120 #define MBOX_CFGSTAT_STATE_ERROR_INVALID                0xf0000001
121 #define MBOX_CFGSTAT_STATE_ERROR_CORRUPT                0xf0000002
122 #define MBOX_CFGSTAT_STATE_ERROR_AUTH                   0xf0000003
123 #define MBOX_CFGSTAT_STATE_ERROR_CORE_IO                0xf0000004
124 #define MBOX_CFGSTAT_STATE_ERROR_HARDWARE               0xf0000005
125 #define MBOX_CFGSTAT_STATE_ERROR_FAKE                   0xf0000006
126 #define MBOX_CFGSTAT_STATE_ERROR_BOOT_INFO              0xf0000007
127 #define MBOX_CFGSTAT_STATE_ERROR_QSPI_ERROR             0xf0000008
128
129 #define RCF_SOFTFUNC_STATUS_CONF_DONE                   BIT(0)
130 #define RCF_SOFTFUNC_STATUS_INIT_DONE                   BIT(1)
131 #define RCF_SOFTFUNC_STATUS_SEU_ERROR                   BIT(3)
132 #define RCF_PIN_STATUS_NSTATUS                          BIT(31)
133
134 int mbox_send_cmd(u8 id, u32 cmd, u8 is_indirect, u32 len, u32 *arg, u8 urgent,
135                   u32 *resp_buf_len, u32 *resp_buf);
136 int mbox_send_cmd_psci(u8 id, u32 cmd, u8 is_indirect, u32 len, u32 *arg,
137                        u8 urgent, u32 *resp_buf_len, u32 *resp_buf);
138 int mbox_send_cmd_only(u8 id, u32 cmd, u8 is_indirect, u32 len, u32 *arg);
139 int mbox_send_cmd_only_psci(u8 id, u32 cmd, u8 is_indirect, u32 len, u32 *arg);
140 int mbox_rcv_resp(u32 *resp_buf, u32 resp_buf_max_len);
141 int mbox_rcv_resp_psci(u32 *resp_buf, u32 resp_buf_max_len);
142 int mbox_init(void);
143
144 #ifdef CONFIG_CADENCE_QSPI
145 int mbox_qspi_close(void);
146 int mbox_qspi_open(void);
147 #endif
148
149 int mbox_reset_cold(void);
150 int mbox_get_fpga_config_status(u32 cmd);
151 int mbox_get_fpga_config_status_psci(u32 cmd);
152 #endif /* _MAILBOX_S10_H_ */