1 /* SPDX-License-Identifier: GPL-2.0 */
3 * CZ.NIC's Turris Omnia MCU I2C interface commands definitions
5 * 2023 by Marek BehĂșn <kabel@kernel.org>
8 #ifndef __TURRIS_OMNIA_MCU_INTERFACE_H
9 #define __TURRIS_OMNIA_MCU_INTERFACE_H
11 #include <linux/bitops.h>
13 enum omnia_commands_e
{
14 CMD_GET_STATUS_WORD
= 0x01, /* slave sends status word back */
15 CMD_GENERAL_CONTROL
= 0x02,
16 CMD_LED_MODE
= 0x03, /* default/user */
17 CMD_LED_STATE
= 0x04, /* LED on/off */
18 CMD_LED_COLOR
= 0x05, /* LED number + RED + GREEN + BLUE */
19 CMD_USER_VOLTAGE
= 0x06,
20 CMD_SET_BRIGHTNESS
= 0x07,
21 CMD_GET_BRIGHTNESS
= 0x08,
23 CMD_GET_FW_VERSION_APP
= 0x0A, /* 20B git hash number */
24 CMD_SET_WATCHDOG_STATE
= 0x0B, /* 0 - disable
26 * after boot watchdog is started
27 * with 2 minutes timeout
30 /* CMD_WATCHDOG_STATUS = 0x0C, not implemented anymore */
32 CMD_GET_WATCHDOG_STATE
= 0x0D,
33 CMD_GET_FW_VERSION_BOOT
= 0x0E, /* 20B git hash number */
34 CMD_GET_FW_CHECKSUM
= 0x0F, /* 4B length, 4B checksum */
36 /* available if FEATURES_SUPPORTED bit set in status word */
37 CMD_GET_FEATURES
= 0x10,
39 /* available if EXT_CMD bit set in features */
40 CMD_GET_EXT_STATUS_DWORD
= 0x11,
41 CMD_EXT_CONTROL
= 0x12,
42 CMD_GET_EXT_CONTROL_STATUS
= 0x13,
44 /* available if NEW_INT_API bit set in features */
45 CMD_GET_INT_AND_CLEAR
= 0x14,
46 CMD_GET_INT_MASK
= 0x15,
47 CMD_SET_INT_MASK
= 0x16,
49 /* available if FLASHING bit set in features */
52 /* available if WDT_PING bit set in features */
53 CMD_SET_WDT_TIMEOUT
= 0x20,
54 CMD_GET_WDT_TIMELEFT
= 0x21,
56 /* available if POWEROFF_WAKEUP bit set in features */
57 CMD_SET_WAKEUP
= 0x22,
58 CMD_GET_UPTIME_AND_WAKEUP
= 0x23,
61 /* available if USB_OVC_PROT_SETTING bit set in features */
62 CMD_SET_USB_OVC_PROT
= 0x25,
63 CMD_GET_USB_OVC_PROT
= 0x26,
65 /* available if TRNG bit set in features */
66 CMD_TRNG_COLLECT_ENTROPY
= 0x28,
68 /* available if CRYPTO bit set in features */
69 CMD_CRYPTO_GET_PUBLIC_KEY
= 0x29,
70 CMD_CRYPTO_SIGN_MESSAGE
= 0x2A,
71 CMD_CRYPTO_COLLECT_SIGNATURE
= 0x2B,
73 /* available if BOARD_INFO it set in features */
74 CMD_BOARD_INFO_GET
= 0x2C,
75 CMD_BOARD_INFO_BURN
= 0x2D,
77 /* available only at address 0x2b (led-controller) */
78 /* available only if LED_GAMMA_CORRECTION bit set in features */
79 CMD_SET_GAMMA_CORRECTION
= 0x30,
80 CMD_GET_GAMMA_CORRECTION
= 0x31,
82 /* available only at address 0x2b (led-controller) */
83 /* available only if PER_LED_CORRECTION bit set in features */
84 /* available only if FROM_BIT_16_INVALID bit NOT set in features */
85 CMD_SET_LED_CORRECTIONS
= 0x32,
86 CMD_GET_LED_CORRECTIONS
= 0x33,
89 enum omnia_flashing_commands_e
{
90 FLASH_CMD_UNLOCK
= 0x01,
91 FLASH_CMD_SIZE_AND_CSUM
= 0x02,
92 FLASH_CMD_PROGRAM
= 0x03,
93 FLASH_CMD_RESET
= 0x04,
96 enum omnia_sts_word_e
{
97 STS_MCU_TYPE_MASK
= GENMASK(1, 0),
98 STS_MCU_TYPE_STM32
= 0 << 0,
99 STS_MCU_TYPE_GD32
= 1 << 0,
100 STS_MCU_TYPE_MKL
= 2 << 0,
101 STS_FEATURES_SUPPORTED
= BIT(2),
102 STS_USER_REGULATOR_NOT_SUPPORTED
= BIT(3),
103 STS_CARD_DET
= BIT(4),
104 STS_MSATA_IND
= BIT(5),
105 STS_USB30_OVC
= BIT(6),
106 STS_USB31_OVC
= BIT(7),
107 STS_USB30_PWRON
= BIT(8),
108 STS_USB31_PWRON
= BIT(9),
109 STS_ENABLE_4V5
= BIT(10),
110 STS_BUTTON_MODE
= BIT(11),
111 STS_BUTTON_PRESSED
= BIT(12),
112 STS_BUTTON_COUNTER_MASK
= GENMASK(15, 13)
115 enum omnia_ctl_byte_e
{
116 CTL_LIGHT_RST
= BIT(0),
117 CTL_HARD_RST
= BIT(1),
118 /* BIT(2) is currently reserved */
119 CTL_USB30_PWRON
= BIT(3),
120 CTL_USB31_PWRON
= BIT(4),
121 CTL_ENABLE_4V5
= BIT(5),
122 CTL_BUTTON_MODE
= BIT(6),
123 CTL_BOOTLOADER
= BIT(7)
126 enum omnia_features_e
{
127 FEAT_PERIPH_MCU
= BIT(0),
128 FEAT_EXT_CMDS
= BIT(1),
129 FEAT_WDT_PING
= BIT(2),
130 FEAT_LED_STATE_EXT_MASK
= GENMASK(4, 3),
131 FEAT_LED_STATE_EXT
= 1 << 3,
132 FEAT_LED_STATE_EXT_V32
= 2 << 3,
133 FEAT_LED_GAMMA_CORRECTION
= BIT(5),
134 FEAT_NEW_INT_API
= BIT(6),
135 FEAT_BOOTLOADER
= BIT(7),
136 FEAT_FLASHING
= BIT(8),
137 FEAT_NEW_MESSAGE_API
= BIT(9),
138 FEAT_BRIGHTNESS_INT
= BIT(10),
139 FEAT_POWEROFF_WAKEUP
= BIT(11),
140 FEAT_CAN_OLD_MESSAGE_API
= BIT(12),
142 FEAT_CRYPTO
= BIT(14),
143 FEAT_BOARD_INFO
= BIT(15),
146 * Orginally the features command replied only 16 bits. If more were
147 * read, either the I2C transaction failed or 0xff bytes were sent.
148 * Therefore to consider bits 16 - 31 valid, one bit (20) was reserved
152 /* Bits 16 - 19 correspond to bits 0 - 3 of status word */
153 FEAT_MCU_TYPE_MASK
= GENMASK(17, 16),
154 FEAT_MCU_TYPE_STM32
= 0 << 16,
155 FEAT_MCU_TYPE_GD32
= 1 << 16,
156 FEAT_MCU_TYPE_MKL
= 2 << 16,
157 FEAT_FEATURES_SUPPORTED
= BIT(18),
158 FEAT_USER_REGULATOR_NOT_SUPPORTED
= BIT(19),
160 /* must not be set */
161 FEAT_FROM_BIT_16_INVALID
= BIT(20),
163 FEAT_PER_LED_CORRECTION
= BIT(21),
164 FEAT_USB_OVC_PROT_SETTING
= BIT(22),
167 enum omnia_ext_sts_dword_e
{
168 EXT_STS_SFP_nDET
= BIT(0),
169 EXT_STS_LED_STATES_MASK
= GENMASK(31, 12),
170 EXT_STS_WLAN0_MSATA_LED
= BIT(12),
171 EXT_STS_WLAN1_LED
= BIT(13),
172 EXT_STS_WLAN2_LED
= BIT(14),
173 EXT_STS_WPAN0_LED
= BIT(15),
174 EXT_STS_WPAN1_LED
= BIT(16),
175 EXT_STS_WPAN2_LED
= BIT(17),
176 EXT_STS_WAN_LED0
= BIT(18),
177 EXT_STS_WAN_LED1
= BIT(19),
178 EXT_STS_LAN0_LED0
= BIT(20),
179 EXT_STS_LAN0_LED1
= BIT(21),
180 EXT_STS_LAN1_LED0
= BIT(22),
181 EXT_STS_LAN1_LED1
= BIT(23),
182 EXT_STS_LAN2_LED0
= BIT(24),
183 EXT_STS_LAN2_LED1
= BIT(25),
184 EXT_STS_LAN3_LED0
= BIT(26),
185 EXT_STS_LAN3_LED1
= BIT(27),
186 EXT_STS_LAN4_LED0
= BIT(28),
187 EXT_STS_LAN4_LED1
= BIT(29),
188 EXT_STS_LAN5_LED0
= BIT(30),
189 EXT_STS_LAN5_LED1
= BIT(31),
192 enum omnia_ext_ctl_e
{
193 EXT_CTL_nRES_MMC
= BIT(0),
194 EXT_CTL_nRES_LAN
= BIT(1),
195 EXT_CTL_nRES_PHY
= BIT(2),
196 EXT_CTL_nPERST0
= BIT(3),
197 EXT_CTL_nPERST1
= BIT(4),
198 EXT_CTL_nPERST2
= BIT(5),
199 EXT_CTL_PHY_SFP
= BIT(6),
200 EXT_CTL_PHY_SFP_AUTO
= BIT(7),
201 EXT_CTL_nVHV_CTRL
= BIT(8),
205 INT_CARD_DET
= BIT(0),
206 INT_MSATA_IND
= BIT(1),
207 INT_USB30_OVC
= BIT(2),
208 INT_USB31_OVC
= BIT(3),
209 INT_BUTTON_PRESSED
= BIT(4),
210 INT_SFP_nDET
= BIT(5),
211 INT_BRIGHTNESS_CHANGED
= BIT(6),
213 INT_MESSAGE_SIGNED
= BIT(8),
215 INT_LED_STATES_MASK
= GENMASK(31, 12),
216 INT_WLAN0_MSATA_LED
= BIT(12),
217 INT_WLAN1_LED
= BIT(13),
218 INT_WLAN2_LED
= BIT(14),
219 INT_WPAN0_LED
= BIT(15),
220 INT_WPAN1_LED
= BIT(16),
221 INT_WPAN2_LED
= BIT(17),
222 INT_WAN_LED0
= BIT(18),
223 INT_WAN_LED1
= BIT(19),
224 INT_LAN0_LED0
= BIT(20),
225 INT_LAN0_LED1
= BIT(21),
226 INT_LAN1_LED0
= BIT(22),
227 INT_LAN1_LED1
= BIT(23),
228 INT_LAN2_LED0
= BIT(24),
229 INT_LAN2_LED1
= BIT(25),
230 INT_LAN3_LED0
= BIT(26),
231 INT_LAN3_LED1
= BIT(27),
232 INT_LAN4_LED0
= BIT(28),
233 INT_LAN4_LED1
= BIT(29),
234 INT_LAN5_LED0
= BIT(30),
235 INT_LAN5_LED1
= BIT(31),
238 enum omnia_cmd_poweroff_e
{
239 CMD_POWER_OFF_POWERON_BUTTON
= BIT(0),
240 CMD_POWER_OFF_MAGIC
= 0xdead,
243 enum cmd_usb_ovc_prot_e
{
244 CMD_xET_USB_OVC_PROT_PORT_MASK
= GENMASK(3, 0),
245 CMD_xET_USB_OVC_PROT_ENABLE
= BIT(4),
248 #endif /* __TURRIS_OMNIA_MCU_INTERFACE_H */