1 /*
2  * Copyright (C) 2014 Felix Fietkau <nbd@openwrt.org>
3  * Copyright (C) 2015 Jakub Kicinski <kubakici@wp.pl>
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2
7  * as published by the Free Software Foundation
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  */
14 
15 #ifndef __MT7601U_MCU_H
16 #define __MT7601U_MCU_H
17 
18 struct mt7601u_dev;
19 
20 /* Register definitions */
21 #define MT_MCU_RESET_CTL		0x070C
22 #define MT_MCU_INT_LEVEL		0x0718
23 #define MT_MCU_COM_REG0			0x0730
24 #define MT_MCU_COM_REG1			0x0734
25 #define MT_MCU_COM_REG2			0x0738
26 #define MT_MCU_COM_REG3			0x073C
27 
28 #define MT_MCU_IVB_SIZE			0x40
29 #define MT_MCU_DLM_OFFSET		0x80000
30 
31 #define MT_MCU_MEMMAP_WLAN		0x00410000
32 #define MT_MCU_MEMMAP_BBP		0x40000000
33 #define MT_MCU_MEMMAP_RF		0x80000000
34 
35 #define INBAND_PACKET_MAX_LEN		192
36 
37 enum mcu_cmd {
38 	CMD_FUN_SET_OP = 1,
39 	CMD_LOAD_CR = 2,
40 	CMD_INIT_GAIN_OP = 3,
41 	CMD_DYNC_VGA_OP = 6,
42 	CMD_TDLS_CH_SW = 7,
43 	CMD_BURST_WRITE = 8,
44 	CMD_READ_MODIFY_WRITE = 9,
45 	CMD_RANDOM_READ = 10,
46 	CMD_BURST_READ = 11,
47 	CMD_RANDOM_WRITE = 12,
48 	CMD_LED_MODE_OP = 16,
49 	CMD_POWER_SAVING_OP = 20,
50 	CMD_WOW_CONFIG = 21,
51 	CMD_WOW_QUERY = 22,
52 	CMD_WOW_FEATURE = 24,
53 	CMD_CARRIER_DETECT_OP = 28,
54 	CMD_RADOR_DETECT_OP = 29,
55 	CMD_SWITCH_CHANNEL_OP = 30,
56 	CMD_CALIBRATION_OP = 31,
57 	CMD_BEACON_OP = 32,
58 	CMD_ANTENNA_OP = 33,
59 };
60 
61 enum mcu_function {
62 	Q_SELECT = 1,
63 	ATOMIC_TSSI_SETTING = 5,
64 };
65 
66 enum mcu_power_mode {
67 	RADIO_OFF = 0x30,
68 	RADIO_ON = 0x31,
69 	RADIO_OFF_AUTO_WAKEUP = 0x32,
70 	RADIO_OFF_ADVANCE = 0x33,
71 	RADIO_ON_ADVANCE = 0x34,
72 };
73 
74 enum mcu_calibrate {
75 	MCU_CAL_R = 1,
76 	MCU_CAL_DCOC,
77 	MCU_CAL_LC,
78 	MCU_CAL_LOFT,
79 	MCU_CAL_TXIQ,
80 	MCU_CAL_BW,
81 	MCU_CAL_DPD,
82 	MCU_CAL_RXIQ,
83 	MCU_CAL_TXDCOC,
84 };
85 
86 int mt7601u_mcu_init(struct mt7601u_dev *dev);
87 int mt7601u_mcu_cmd_init(struct mt7601u_dev *dev);
88 void mt7601u_mcu_cmd_deinit(struct mt7601u_dev *dev);
89 
90 int
91 mt7601u_mcu_calibrate(struct mt7601u_dev *dev, enum mcu_calibrate cal, u32 val);
92 int mt7601u_mcu_tssi_read_kick(struct mt7601u_dev *dev, int use_hvga);
93 
94 #endif
95