1 /*
2  * Copyright (C) 2016 Felix Fietkau <nbd@nbd.name>
3  *
4  * Permission to use, copy, modify, and/or distribute this software for any
5  * purpose with or without fee is hereby granted, provided that the above
6  * copyright notice and this permission notice appear in all copies.
7  *
8  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15  */
16 
17 #ifndef __MT76x2_MCU_H
18 #define __MT76x2_MCU_H
19 
20 #include "../mt76x02_mcu.h"
21 
22 /* Register definitions */
23 #define MT_MCU_CPU_CTL			0x0704
24 #define MT_MCU_CLOCK_CTL		0x0708
25 #define MT_MCU_PCIE_REMAP_BASE1		0x0740
26 #define MT_MCU_PCIE_REMAP_BASE2		0x0744
27 #define MT_MCU_PCIE_REMAP_BASE3		0x0748
28 
29 #define MT_LED_CTRL			0x0770
30 #define MT_LED_CTRL_REPLAY(_n)		BIT(0 + (8 * (_n)))
31 #define MT_LED_CTRL_POLARITY(_n)	BIT(1 + (8 * (_n)))
32 #define MT_LED_CTRL_TX_BLINK_MODE(_n)	BIT(2 + (8 * (_n)))
33 #define MT_LED_CTRL_KICK(_n)		BIT(7 + (8 * (_n)))
34 
35 #define MT_LED_TX_BLINK_0		0x0774
36 #define MT_LED_TX_BLINK_1		0x0778
37 
38 #define MT_LED_S0_BASE			0x077C
39 #define MT_LED_S0(_n)			(MT_LED_S0_BASE + 8 * (_n))
40 #define MT_LED_S1_BASE			0x0780
41 #define MT_LED_S1(_n)			(MT_LED_S1_BASE + 8 * (_n))
42 #define MT_LED_STATUS_OFF_MASK		GENMASK(31, 24)
43 #define MT_LED_STATUS_OFF(_v)		(((_v) << __ffs(MT_LED_STATUS_OFF_MASK)) & \
44 					 MT_LED_STATUS_OFF_MASK)
45 #define MT_LED_STATUS_ON_MASK		GENMASK(23, 16)
46 #define MT_LED_STATUS_ON(_v)		(((_v) << __ffs(MT_LED_STATUS_ON_MASK)) & \
47 					 MT_LED_STATUS_ON_MASK)
48 #define MT_LED_STATUS_DURATION_MASK	GENMASK(15, 8)
49 #define MT_LED_STATUS_DURATION(_v)	(((_v) << __ffs(MT_LED_STATUS_DURATION_MASK)) & \
50 					 MT_LED_STATUS_DURATION_MASK)
51 
52 #define MT_MCU_ROM_PATCH_OFFSET		0x80000
53 #define MT_MCU_ROM_PATCH_ADDR		0x90000
54 
55 #define MT_MCU_ILM_OFFSET		0x80000
56 
57 #define MT_MCU_DLM_OFFSET		0x100000
58 #define MT_MCU_DLM_ADDR			0x90000
59 #define MT_MCU_DLM_ADDR_E3		0x90800
60 
61 enum mcu_calibration {
62 	MCU_CAL_R = 1,
63 	MCU_CAL_TEMP_SENSOR,
64 	MCU_CAL_RXDCOC,
65 	MCU_CAL_RC,
66 	MCU_CAL_SX_LOGEN,
67 	MCU_CAL_LC,
68 	MCU_CAL_TX_LOFT,
69 	MCU_CAL_TXIQ,
70 	MCU_CAL_TSSI,
71 	MCU_CAL_TSSI_COMP,
72 	MCU_CAL_DPD,
73 	MCU_CAL_RXIQC_FI,
74 	MCU_CAL_RXIQC_FD,
75 	MCU_CAL_PWRON,
76 	MCU_CAL_TX_SHAPING,
77 };
78 
79 enum mt76x2_mcu_cr_mode {
80 	MT_RF_CR,
81 	MT_BBP_CR,
82 	MT_RF_BBP_CR,
83 	MT_HL_TEMP_CR_UPDATE,
84 };
85 
86 struct mt76x2_tssi_comp {
87 	u8 pa_mode;
88 	u8 cal_mode;
89 	u16 pad;
90 
91 	u8 slope0;
92 	u8 slope1;
93 	u8 offset0;
94 	u8 offset1;
95 } __packed __aligned(4);
96 
97 int mt76x2_mcu_tssi_comp(struct mt76x02_dev *dev, struct mt76x2_tssi_comp *tssi_data);
98 int mt76x2_mcu_init_gain(struct mt76x02_dev *dev, u8 channel, u32 gain,
99 			 bool force);
100 
101 #endif
102