18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: ISC */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * Copyright (C) 2018 Lorenzo Bianconi <lorenzo.bianconi83@gmail.com>
48c2ecf20Sopenharmony_ci */
58c2ecf20Sopenharmony_ci
68c2ecf20Sopenharmony_ci#ifndef __MT76x02_MCU_H
78c2ecf20Sopenharmony_ci#define __MT76x02_MCU_H
88c2ecf20Sopenharmony_ci
98c2ecf20Sopenharmony_ci#include "mt76x02.h"
108c2ecf20Sopenharmony_ci
118c2ecf20Sopenharmony_ci#define MT_MCU_RESET_CTL		0x070C
128c2ecf20Sopenharmony_ci#define MT_MCU_INT_LEVEL		0x0718
138c2ecf20Sopenharmony_ci#define MT_MCU_COM_REG0			0x0730
148c2ecf20Sopenharmony_ci#define MT_MCU_COM_REG1			0x0734
158c2ecf20Sopenharmony_ci#define MT_MCU_COM_REG2			0x0738
168c2ecf20Sopenharmony_ci#define MT_MCU_COM_REG3			0x073C
178c2ecf20Sopenharmony_ci
188c2ecf20Sopenharmony_ci#define MT_INBAND_PACKET_MAX_LEN	192
198c2ecf20Sopenharmony_ci#define MT_MCU_MEMMAP_WLAN		0x410000
208c2ecf20Sopenharmony_ci
218c2ecf20Sopenharmony_ci#define MT_MCU_PCIE_REMAP_BASE4		0x074C
228c2ecf20Sopenharmony_ci
238c2ecf20Sopenharmony_ci#define MT_MCU_SEMAPHORE_00		0x07B0
248c2ecf20Sopenharmony_ci#define MT_MCU_SEMAPHORE_01		0x07B4
258c2ecf20Sopenharmony_ci#define MT_MCU_SEMAPHORE_02		0x07B8
268c2ecf20Sopenharmony_ci#define MT_MCU_SEMAPHORE_03		0x07BC
278c2ecf20Sopenharmony_ci
288c2ecf20Sopenharmony_ci#define MT_MCU_ILM_ADDR			0x80000
298c2ecf20Sopenharmony_ci
308c2ecf20Sopenharmony_cienum mcu_cmd {
318c2ecf20Sopenharmony_ci	CMD_FUN_SET_OP = 1,
328c2ecf20Sopenharmony_ci	CMD_LOAD_CR = 2,
338c2ecf20Sopenharmony_ci	CMD_INIT_GAIN_OP = 3,
348c2ecf20Sopenharmony_ci	CMD_DYNC_VGA_OP = 6,
358c2ecf20Sopenharmony_ci	CMD_TDLS_CH_SW = 7,
368c2ecf20Sopenharmony_ci	CMD_BURST_WRITE = 8,
378c2ecf20Sopenharmony_ci	CMD_READ_MODIFY_WRITE = 9,
388c2ecf20Sopenharmony_ci	CMD_RANDOM_READ = 10,
398c2ecf20Sopenharmony_ci	CMD_BURST_READ = 11,
408c2ecf20Sopenharmony_ci	CMD_RANDOM_WRITE = 12,
418c2ecf20Sopenharmony_ci	CMD_LED_MODE_OP = 16,
428c2ecf20Sopenharmony_ci	CMD_POWER_SAVING_OP = 20,
438c2ecf20Sopenharmony_ci	CMD_WOW_CONFIG = 21,
448c2ecf20Sopenharmony_ci	CMD_WOW_QUERY = 22,
458c2ecf20Sopenharmony_ci	CMD_WOW_FEATURE = 24,
468c2ecf20Sopenharmony_ci	CMD_CARRIER_DETECT_OP = 28,
478c2ecf20Sopenharmony_ci	CMD_RADOR_DETECT_OP = 29,
488c2ecf20Sopenharmony_ci	CMD_SWITCH_CHANNEL_OP = 30,
498c2ecf20Sopenharmony_ci	CMD_CALIBRATION_OP = 31,
508c2ecf20Sopenharmony_ci	CMD_BEACON_OP = 32,
518c2ecf20Sopenharmony_ci	CMD_ANTENNA_OP = 33,
528c2ecf20Sopenharmony_ci};
538c2ecf20Sopenharmony_ci
548c2ecf20Sopenharmony_cienum mcu_power_mode {
558c2ecf20Sopenharmony_ci	RADIO_OFF = 0x30,
568c2ecf20Sopenharmony_ci	RADIO_ON = 0x31,
578c2ecf20Sopenharmony_ci	RADIO_OFF_AUTO_WAKEUP = 0x32,
588c2ecf20Sopenharmony_ci	RADIO_OFF_ADVANCE = 0x33,
598c2ecf20Sopenharmony_ci	RADIO_ON_ADVANCE = 0x34,
608c2ecf20Sopenharmony_ci};
618c2ecf20Sopenharmony_ci
628c2ecf20Sopenharmony_cienum mcu_function {
638c2ecf20Sopenharmony_ci	Q_SELECT = 1,
648c2ecf20Sopenharmony_ci	BW_SETTING = 2,
658c2ecf20Sopenharmony_ci	USB2_SW_DISCONNECT = 2,
668c2ecf20Sopenharmony_ci	USB3_SW_DISCONNECT = 3,
678c2ecf20Sopenharmony_ci	LOG_FW_DEBUG_MSG = 4,
688c2ecf20Sopenharmony_ci	GET_FW_VERSION = 5,
698c2ecf20Sopenharmony_ci};
708c2ecf20Sopenharmony_ci
718c2ecf20Sopenharmony_cistruct mt76x02_fw_header {
728c2ecf20Sopenharmony_ci	__le32 ilm_len;
738c2ecf20Sopenharmony_ci	__le32 dlm_len;
748c2ecf20Sopenharmony_ci	__le16 build_ver;
758c2ecf20Sopenharmony_ci	__le16 fw_ver;
768c2ecf20Sopenharmony_ci	u8 pad[4];
778c2ecf20Sopenharmony_ci	char build_time[16];
788c2ecf20Sopenharmony_ci};
798c2ecf20Sopenharmony_ci
808c2ecf20Sopenharmony_cistruct mt76x02_patch_header {
818c2ecf20Sopenharmony_ci	char build_time[16];
828c2ecf20Sopenharmony_ci	char platform[4];
838c2ecf20Sopenharmony_ci	char hw_version[4];
848c2ecf20Sopenharmony_ci	char patch_version[4];
858c2ecf20Sopenharmony_ci	u8 pad[2];
868c2ecf20Sopenharmony_ci};
878c2ecf20Sopenharmony_ci
888c2ecf20Sopenharmony_ciint mt76x02_mcu_cleanup(struct mt76x02_dev *dev);
898c2ecf20Sopenharmony_ciint mt76x02_mcu_calibrate(struct mt76x02_dev *dev, int type, u32 param);
908c2ecf20Sopenharmony_ciint mt76x02_mcu_msg_send(struct mt76_dev *mdev, int cmd, const void *data,
918c2ecf20Sopenharmony_ci			 int len, bool wait_resp);
928c2ecf20Sopenharmony_ciint mt76x02_mcu_function_select(struct mt76x02_dev *dev, enum mcu_function func,
938c2ecf20Sopenharmony_ci				u32 val);
948c2ecf20Sopenharmony_ciint mt76x02_mcu_set_radio_state(struct mt76x02_dev *dev, bool on);
958c2ecf20Sopenharmony_civoid mt76x02_set_ethtool_fwver(struct mt76x02_dev *dev,
968c2ecf20Sopenharmony_ci			       const struct mt76x02_fw_header *h);
978c2ecf20Sopenharmony_ci
988c2ecf20Sopenharmony_ci#endif /* __MT76x02_MCU_H */
99