1811853daSPing-Ke Shih // SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause
2811853daSPing-Ke Shih /* Copyright(c) 2018-2019  Realtek Corporation
3811853daSPing-Ke Shih  */
4811853daSPing-Ke Shih 
5811853daSPing-Ke Shih #include "main.h"
6811853daSPing-Ke Shih #include "coex.h"
7811853daSPing-Ke Shih #include "fw.h"
8811853daSPing-Ke Shih #include "tx.h"
9811853daSPing-Ke Shih #include "rx.h"
10811853daSPing-Ke Shih #include "phy.h"
11811853daSPing-Ke Shih #include "rtw8723d.h"
12811853daSPing-Ke Shih #include "rtw8723d_table.h"
13811853daSPing-Ke Shih #include "mac.h"
14811853daSPing-Ke Shih #include "reg.h"
15811853daSPing-Ke Shih #include "debug.h"
16811853daSPing-Ke Shih 
171afb5eb7SPing-Ke Shih static void rtw8723d_cfg_ldo25(struct rtw_dev *rtwdev, bool enable)
181afb5eb7SPing-Ke Shih {
191afb5eb7SPing-Ke Shih 	u8 ldo_pwr;
201afb5eb7SPing-Ke Shih 
211afb5eb7SPing-Ke Shih 	ldo_pwr = rtw_read8(rtwdev, REG_LDO_EFUSE_CTRL + 3);
221afb5eb7SPing-Ke Shih 	if (enable) {
231afb5eb7SPing-Ke Shih 		ldo_pwr &= ~BIT_MASK_LDO25_VOLTAGE;
241afb5eb7SPing-Ke Shih 		ldo_pwr = (BIT_LDO25_VOLTAGE_V25 << 4) | BIT_LDO25_EN;
251afb5eb7SPing-Ke Shih 	} else {
261afb5eb7SPing-Ke Shih 		ldo_pwr &= ~BIT_LDO25_EN;
271afb5eb7SPing-Ke Shih 	}
281afb5eb7SPing-Ke Shih 	rtw_write8(rtwdev, REG_LDO_EFUSE_CTRL + 3, ldo_pwr);
291afb5eb7SPing-Ke Shih }
301afb5eb7SPing-Ke Shih 
3144baa97cSPing-Ke Shih static void rtw8723d_efuse_grant(struct rtw_dev *rtwdev, bool on)
3244baa97cSPing-Ke Shih {
3344baa97cSPing-Ke Shih 	if (on) {
3444baa97cSPing-Ke Shih 		rtw_write8(rtwdev, REG_EFUSE_ACCESS, EFUSE_ACCESS_ON);
3544baa97cSPing-Ke Shih 
3644baa97cSPing-Ke Shih 		rtw_write16_set(rtwdev, REG_SYS_FUNC_EN, BIT_FEN_ELDR);
3744baa97cSPing-Ke Shih 		rtw_write16_set(rtwdev, REG_SYS_CLKR, BIT_LOADER_CLK_EN | BIT_ANA8M);
3844baa97cSPing-Ke Shih 	} else {
3944baa97cSPing-Ke Shih 		rtw_write8(rtwdev, REG_EFUSE_ACCESS, EFUSE_ACCESS_OFF);
4044baa97cSPing-Ke Shih 	}
4144baa97cSPing-Ke Shih }
4244baa97cSPing-Ke Shih 
43811853daSPing-Ke Shih static struct rtw_chip_ops rtw8723d_ops = {
44e0c27cdbSPing-Ke Shih 	.read_rf		= rtw_phy_read_rf_sipi,
45e0c27cdbSPing-Ke Shih 	.write_rf		= rtw_phy_write_rf_reg_sipi,
46811853daSPing-Ke Shih 	.set_antenna		= NULL,
471afb5eb7SPing-Ke Shih 	.cfg_ldo25		= rtw8723d_cfg_ldo25,
4844baa97cSPing-Ke Shih 	.efuse_grant		= rtw8723d_efuse_grant,
4993ae973fSPing-Ke Shih 	.config_bfee		= NULL,
5093ae973fSPing-Ke Shih 	.set_gid_table		= NULL,
5193ae973fSPing-Ke Shih 	.cfg_csi_rate		= NULL,
52811853daSPing-Ke Shih };
53811853daSPing-Ke Shih 
54c57bd7c3SPing-Ke Shih static const struct rtw_pwr_seq_cmd trans_carddis_to_cardemu_8723d[] = {
55c57bd7c3SPing-Ke Shih 	{0x0005,
56c57bd7c3SPing-Ke Shih 	 RTW_PWR_CUT_ALL_MSK,
57c57bd7c3SPing-Ke Shih 	 RTW_PWR_INTF_ALL_MSK,
58c57bd7c3SPing-Ke Shih 	 RTW_PWR_ADDR_MAC,
59c57bd7c3SPing-Ke Shih 	 RTW_PWR_CMD_WRITE, BIT(3) | BIT(7), 0},
60c57bd7c3SPing-Ke Shih 	{0x0086,
61c57bd7c3SPing-Ke Shih 	 RTW_PWR_CUT_ALL_MSK,
62c57bd7c3SPing-Ke Shih 	 RTW_PWR_INTF_SDIO_MSK,
63c57bd7c3SPing-Ke Shih 	 RTW_PWR_ADDR_SDIO,
64c57bd7c3SPing-Ke Shih 	 RTW_PWR_CMD_WRITE, BIT(0), 0},
65c57bd7c3SPing-Ke Shih 	{0x0086,
66c57bd7c3SPing-Ke Shih 	 RTW_PWR_CUT_ALL_MSK,
67c57bd7c3SPing-Ke Shih 	 RTW_PWR_INTF_SDIO_MSK,
68c57bd7c3SPing-Ke Shih 	 RTW_PWR_ADDR_SDIO,
69c57bd7c3SPing-Ke Shih 	 RTW_PWR_CMD_POLLING, BIT(1), BIT(1)},
70c57bd7c3SPing-Ke Shih 	{0x004A,
71c57bd7c3SPing-Ke Shih 	 RTW_PWR_CUT_ALL_MSK,
72c57bd7c3SPing-Ke Shih 	 RTW_PWR_INTF_USB_MSK,
73c57bd7c3SPing-Ke Shih 	 RTW_PWR_ADDR_MAC,
74c57bd7c3SPing-Ke Shih 	 RTW_PWR_CMD_WRITE, BIT(0), 0},
75c57bd7c3SPing-Ke Shih 	{0x0005,
76c57bd7c3SPing-Ke Shih 	 RTW_PWR_CUT_ALL_MSK,
77c57bd7c3SPing-Ke Shih 	 RTW_PWR_INTF_ALL_MSK,
78c57bd7c3SPing-Ke Shih 	 RTW_PWR_ADDR_MAC,
79c57bd7c3SPing-Ke Shih 	 RTW_PWR_CMD_WRITE, BIT(3) | BIT(4), 0},
80c57bd7c3SPing-Ke Shih 	{0x0023,
81c57bd7c3SPing-Ke Shih 	 RTW_PWR_CUT_ALL_MSK,
82c57bd7c3SPing-Ke Shih 	 RTW_PWR_INTF_SDIO_MSK,
83c57bd7c3SPing-Ke Shih 	 RTW_PWR_ADDR_MAC,
84c57bd7c3SPing-Ke Shih 	 RTW_PWR_CMD_WRITE, BIT(4), 0},
85c57bd7c3SPing-Ke Shih 	{0x0301,
86c57bd7c3SPing-Ke Shih 	 RTW_PWR_CUT_ALL_MSK,
87c57bd7c3SPing-Ke Shih 	 RTW_PWR_INTF_PCI_MSK,
88c57bd7c3SPing-Ke Shih 	 RTW_PWR_ADDR_MAC,
89c57bd7c3SPing-Ke Shih 	 RTW_PWR_CMD_WRITE, 0xFF, 0},
90c57bd7c3SPing-Ke Shih 	{0xFFFF,
91c57bd7c3SPing-Ke Shih 	 RTW_PWR_CUT_ALL_MSK,
92c57bd7c3SPing-Ke Shih 	 RTW_PWR_INTF_ALL_MSK,
93c57bd7c3SPing-Ke Shih 	 0,
94c57bd7c3SPing-Ke Shih 	 RTW_PWR_CMD_END, 0, 0},
95c57bd7c3SPing-Ke Shih };
96c57bd7c3SPing-Ke Shih 
97c57bd7c3SPing-Ke Shih static const struct rtw_pwr_seq_cmd trans_cardemu_to_act_8723d[] = {
98c57bd7c3SPing-Ke Shih 	{0x0020,
99c57bd7c3SPing-Ke Shih 	 RTW_PWR_CUT_ALL_MSK,
100c57bd7c3SPing-Ke Shih 	 RTW_PWR_INTF_USB_MSK | RTW_PWR_INTF_SDIO_MSK,
101c57bd7c3SPing-Ke Shih 	 RTW_PWR_ADDR_MAC,
102c57bd7c3SPing-Ke Shih 	 RTW_PWR_CMD_WRITE, BIT(0), BIT(0)},
103c57bd7c3SPing-Ke Shih 	{0x0001,
104c57bd7c3SPing-Ke Shih 	 RTW_PWR_CUT_ALL_MSK,
105c57bd7c3SPing-Ke Shih 	 RTW_PWR_INTF_USB_MSK | RTW_PWR_INTF_SDIO_MSK,
106c57bd7c3SPing-Ke Shih 	 RTW_PWR_ADDR_MAC,
107c57bd7c3SPing-Ke Shih 	 RTW_PWR_CMD_DELAY, 1, RTW_PWR_DELAY_MS},
108c57bd7c3SPing-Ke Shih 	{0x0000,
109c57bd7c3SPing-Ke Shih 	 RTW_PWR_CUT_ALL_MSK,
110c57bd7c3SPing-Ke Shih 	 RTW_PWR_INTF_USB_MSK | RTW_PWR_INTF_SDIO_MSK,
111c57bd7c3SPing-Ke Shih 	 RTW_PWR_ADDR_MAC,
112c57bd7c3SPing-Ke Shih 	 RTW_PWR_CMD_WRITE, BIT(5), 0},
113c57bd7c3SPing-Ke Shih 	{0x0005,
114c57bd7c3SPing-Ke Shih 	 RTW_PWR_CUT_ALL_MSK,
115c57bd7c3SPing-Ke Shih 	 RTW_PWR_INTF_ALL_MSK,
116c57bd7c3SPing-Ke Shih 	 RTW_PWR_ADDR_MAC,
117c57bd7c3SPing-Ke Shih 	 RTW_PWR_CMD_WRITE, (BIT(4) | BIT(3) | BIT(2)), 0},
118c57bd7c3SPing-Ke Shih 	{0x0075,
119c57bd7c3SPing-Ke Shih 	 RTW_PWR_CUT_ALL_MSK,
120c57bd7c3SPing-Ke Shih 	 RTW_PWR_INTF_PCI_MSK,
121c57bd7c3SPing-Ke Shih 	 RTW_PWR_ADDR_MAC,
122c57bd7c3SPing-Ke Shih 	 RTW_PWR_CMD_WRITE, BIT(0), BIT(0)},
123c57bd7c3SPing-Ke Shih 	{0x0006,
124c57bd7c3SPing-Ke Shih 	 RTW_PWR_CUT_ALL_MSK,
125c57bd7c3SPing-Ke Shih 	 RTW_PWR_INTF_ALL_MSK,
126c57bd7c3SPing-Ke Shih 	 RTW_PWR_ADDR_MAC,
127c57bd7c3SPing-Ke Shih 	 RTW_PWR_CMD_POLLING, BIT(1), BIT(1)},
128c57bd7c3SPing-Ke Shih 	{0x0075,
129c57bd7c3SPing-Ke Shih 	 RTW_PWR_CUT_ALL_MSK,
130c57bd7c3SPing-Ke Shih 	 RTW_PWR_INTF_PCI_MSK,
131c57bd7c3SPing-Ke Shih 	 RTW_PWR_ADDR_MAC,
132c57bd7c3SPing-Ke Shih 	 RTW_PWR_CMD_WRITE, BIT(0), 0},
133c57bd7c3SPing-Ke Shih 	{0x0006,
134c57bd7c3SPing-Ke Shih 	 RTW_PWR_CUT_ALL_MSK,
135c57bd7c3SPing-Ke Shih 	 RTW_PWR_INTF_ALL_MSK,
136c57bd7c3SPing-Ke Shih 	 RTW_PWR_ADDR_MAC,
137c57bd7c3SPing-Ke Shih 	 RTW_PWR_CMD_WRITE, BIT(0), BIT(0)},
138c57bd7c3SPing-Ke Shih 	{0x0005,
139c57bd7c3SPing-Ke Shih 	 RTW_PWR_CUT_ALL_MSK,
140c57bd7c3SPing-Ke Shih 	 RTW_PWR_INTF_ALL_MSK,
141c57bd7c3SPing-Ke Shih 	 RTW_PWR_ADDR_MAC,
142c57bd7c3SPing-Ke Shih 	 RTW_PWR_CMD_POLLING, (BIT(1) | BIT(0)), 0},
143c57bd7c3SPing-Ke Shih 	{0x0005,
144c57bd7c3SPing-Ke Shih 	 RTW_PWR_CUT_ALL_MSK,
145c57bd7c3SPing-Ke Shih 	 RTW_PWR_INTF_ALL_MSK,
146c57bd7c3SPing-Ke Shih 	 RTW_PWR_ADDR_MAC,
147c57bd7c3SPing-Ke Shih 	 RTW_PWR_CMD_WRITE, BIT(7), 0},
148c57bd7c3SPing-Ke Shih 	{0x0005,
149c57bd7c3SPing-Ke Shih 	 RTW_PWR_CUT_ALL_MSK,
150c57bd7c3SPing-Ke Shih 	 RTW_PWR_INTF_ALL_MSK,
151c57bd7c3SPing-Ke Shih 	 RTW_PWR_ADDR_MAC,
152c57bd7c3SPing-Ke Shih 	 RTW_PWR_CMD_WRITE, (BIT(4) | BIT(3)), 0},
153c57bd7c3SPing-Ke Shih 	{0x0005,
154c57bd7c3SPing-Ke Shih 	 RTW_PWR_CUT_ALL_MSK,
155c57bd7c3SPing-Ke Shih 	 RTW_PWR_INTF_ALL_MSK,
156c57bd7c3SPing-Ke Shih 	 RTW_PWR_ADDR_MAC,
157c57bd7c3SPing-Ke Shih 	 RTW_PWR_CMD_WRITE, BIT(0), BIT(0)},
158c57bd7c3SPing-Ke Shih 	{0x0005,
159c57bd7c3SPing-Ke Shih 	 RTW_PWR_CUT_ALL_MSK,
160c57bd7c3SPing-Ke Shih 	 RTW_PWR_INTF_ALL_MSK,
161c57bd7c3SPing-Ke Shih 	 RTW_PWR_ADDR_MAC,
162c57bd7c3SPing-Ke Shih 	 RTW_PWR_CMD_POLLING, BIT(0), 0},
163c57bd7c3SPing-Ke Shih 	{0x0010,
164c57bd7c3SPing-Ke Shih 	 RTW_PWR_CUT_ALL_MSK,
165c57bd7c3SPing-Ke Shih 	 RTW_PWR_INTF_ALL_MSK,
166c57bd7c3SPing-Ke Shih 	 RTW_PWR_ADDR_MAC,
167c57bd7c3SPing-Ke Shih 	 RTW_PWR_CMD_WRITE, BIT(6), BIT(6)},
168c57bd7c3SPing-Ke Shih 	{0x0049,
169c57bd7c3SPing-Ke Shih 	 RTW_PWR_CUT_ALL_MSK,
170c57bd7c3SPing-Ke Shih 	 RTW_PWR_INTF_ALL_MSK,
171c57bd7c3SPing-Ke Shih 	 RTW_PWR_ADDR_MAC,
172c57bd7c3SPing-Ke Shih 	 RTW_PWR_CMD_WRITE, BIT(1), BIT(1)},
173c57bd7c3SPing-Ke Shih 	{0x0063,
174c57bd7c3SPing-Ke Shih 	 RTW_PWR_CUT_ALL_MSK,
175c57bd7c3SPing-Ke Shih 	 RTW_PWR_INTF_ALL_MSK,
176c57bd7c3SPing-Ke Shih 	 RTW_PWR_ADDR_MAC,
177c57bd7c3SPing-Ke Shih 	 RTW_PWR_CMD_WRITE, BIT(1), BIT(1)},
178c57bd7c3SPing-Ke Shih 	{0x0062,
179c57bd7c3SPing-Ke Shih 	 RTW_PWR_CUT_ALL_MSK,
180c57bd7c3SPing-Ke Shih 	 RTW_PWR_INTF_ALL_MSK,
181c57bd7c3SPing-Ke Shih 	 RTW_PWR_ADDR_MAC,
182c57bd7c3SPing-Ke Shih 	 RTW_PWR_CMD_WRITE, BIT(1), 0},
183c57bd7c3SPing-Ke Shih 	{0x0058,
184c57bd7c3SPing-Ke Shih 	 RTW_PWR_CUT_ALL_MSK,
185c57bd7c3SPing-Ke Shih 	 RTW_PWR_INTF_ALL_MSK,
186c57bd7c3SPing-Ke Shih 	 RTW_PWR_ADDR_MAC,
187c57bd7c3SPing-Ke Shih 	 RTW_PWR_CMD_WRITE, BIT(0), BIT(0)},
188c57bd7c3SPing-Ke Shih 	{0x005A,
189c57bd7c3SPing-Ke Shih 	 RTW_PWR_CUT_ALL_MSK,
190c57bd7c3SPing-Ke Shih 	 RTW_PWR_INTF_ALL_MSK,
191c57bd7c3SPing-Ke Shih 	 RTW_PWR_ADDR_MAC,
192c57bd7c3SPing-Ke Shih 	 RTW_PWR_CMD_WRITE, BIT(1), BIT(1)},
193c57bd7c3SPing-Ke Shih 	{0x0068,
194c57bd7c3SPing-Ke Shih 	 RTW_PWR_CUT_TEST_MSK,
195c57bd7c3SPing-Ke Shih 	 RTW_PWR_INTF_ALL_MSK,
196c57bd7c3SPing-Ke Shih 	 RTW_PWR_ADDR_MAC,
197c57bd7c3SPing-Ke Shih 	 RTW_PWR_CMD_WRITE, BIT(3), BIT(3)},
198c57bd7c3SPing-Ke Shih 	{0x0069,
199c57bd7c3SPing-Ke Shih 	 RTW_PWR_CUT_ALL_MSK,
200c57bd7c3SPing-Ke Shih 	 RTW_PWR_INTF_ALL_MSK,
201c57bd7c3SPing-Ke Shih 	 RTW_PWR_ADDR_MAC,
202c57bd7c3SPing-Ke Shih 	 RTW_PWR_CMD_WRITE, BIT(6), BIT(6)},
203c57bd7c3SPing-Ke Shih 	{0x001f,
204c57bd7c3SPing-Ke Shih 	 RTW_PWR_CUT_ALL_MSK,
205c57bd7c3SPing-Ke Shih 	 RTW_PWR_INTF_ALL_MSK,
206c57bd7c3SPing-Ke Shih 	 RTW_PWR_ADDR_MAC,
207c57bd7c3SPing-Ke Shih 	 RTW_PWR_CMD_WRITE, 0xFF, 0x00},
208c57bd7c3SPing-Ke Shih 	{0x0077,
209c57bd7c3SPing-Ke Shih 	 RTW_PWR_CUT_ALL_MSK,
210c57bd7c3SPing-Ke Shih 	 RTW_PWR_INTF_ALL_MSK,
211c57bd7c3SPing-Ke Shih 	 RTW_PWR_ADDR_MAC,
212c57bd7c3SPing-Ke Shih 	 RTW_PWR_CMD_WRITE, 0xFF, 0x00},
213c57bd7c3SPing-Ke Shih 	{0x001f,
214c57bd7c3SPing-Ke Shih 	 RTW_PWR_CUT_ALL_MSK,
215c57bd7c3SPing-Ke Shih 	 RTW_PWR_INTF_ALL_MSK,
216c57bd7c3SPing-Ke Shih 	 RTW_PWR_ADDR_MAC,
217c57bd7c3SPing-Ke Shih 	 RTW_PWR_CMD_WRITE, 0xFF, 0x07},
218c57bd7c3SPing-Ke Shih 	{0x0077,
219c57bd7c3SPing-Ke Shih 	 RTW_PWR_CUT_ALL_MSK,
220c57bd7c3SPing-Ke Shih 	 RTW_PWR_INTF_ALL_MSK,
221c57bd7c3SPing-Ke Shih 	 RTW_PWR_ADDR_MAC,
222c57bd7c3SPing-Ke Shih 	 RTW_PWR_CMD_WRITE, 0xFF, 0x07},
223c57bd7c3SPing-Ke Shih 	{0xFFFF,
224c57bd7c3SPing-Ke Shih 	 RTW_PWR_CUT_ALL_MSK,
225c57bd7c3SPing-Ke Shih 	 RTW_PWR_INTF_ALL_MSK,
226c57bd7c3SPing-Ke Shih 	 0,
227c57bd7c3SPing-Ke Shih 	 RTW_PWR_CMD_END, 0, 0},
228c57bd7c3SPing-Ke Shih };
229c57bd7c3SPing-Ke Shih 
230c57bd7c3SPing-Ke Shih static const struct rtw_pwr_seq_cmd *card_enable_flow_8723d[] = {
231c57bd7c3SPing-Ke Shih 	trans_carddis_to_cardemu_8723d,
232c57bd7c3SPing-Ke Shih 	trans_cardemu_to_act_8723d,
233c57bd7c3SPing-Ke Shih 	NULL
234c57bd7c3SPing-Ke Shih };
235c57bd7c3SPing-Ke Shih 
236c57bd7c3SPing-Ke Shih static const struct rtw_pwr_seq_cmd trans_act_to_lps_8723d[] = {
237c57bd7c3SPing-Ke Shih 	{0x0301,
238c57bd7c3SPing-Ke Shih 	 RTW_PWR_CUT_ALL_MSK,
239c57bd7c3SPing-Ke Shih 	 RTW_PWR_INTF_PCI_MSK,
240c57bd7c3SPing-Ke Shih 	 RTW_PWR_ADDR_MAC,
241c57bd7c3SPing-Ke Shih 	 RTW_PWR_CMD_WRITE, 0xFF, 0xFF},
242c57bd7c3SPing-Ke Shih 	{0x0522,
243c57bd7c3SPing-Ke Shih 	 RTW_PWR_CUT_ALL_MSK,
244c57bd7c3SPing-Ke Shih 	 RTW_PWR_INTF_ALL_MSK,
245c57bd7c3SPing-Ke Shih 	 RTW_PWR_ADDR_MAC,
246c57bd7c3SPing-Ke Shih 	 RTW_PWR_CMD_WRITE, 0xFF, 0xFF},
247c57bd7c3SPing-Ke Shih 	{0x05F8,
248c57bd7c3SPing-Ke Shih 	 RTW_PWR_CUT_ALL_MSK,
249c57bd7c3SPing-Ke Shih 	 RTW_PWR_INTF_ALL_MSK,
250c57bd7c3SPing-Ke Shih 	 RTW_PWR_ADDR_MAC,
251c57bd7c3SPing-Ke Shih 	 RTW_PWR_CMD_POLLING, 0xFF, 0},
252c57bd7c3SPing-Ke Shih 	{0x05F9,
253c57bd7c3SPing-Ke Shih 	 RTW_PWR_CUT_ALL_MSK,
254c57bd7c3SPing-Ke Shih 	 RTW_PWR_INTF_ALL_MSK,
255c57bd7c3SPing-Ke Shih 	 RTW_PWR_ADDR_MAC,
256c57bd7c3SPing-Ke Shih 	 RTW_PWR_CMD_POLLING, 0xFF, 0},
257c57bd7c3SPing-Ke Shih 	{0x05FA,
258c57bd7c3SPing-Ke Shih 	 RTW_PWR_CUT_ALL_MSK,
259c57bd7c3SPing-Ke Shih 	 RTW_PWR_INTF_ALL_MSK,
260c57bd7c3SPing-Ke Shih 	 RTW_PWR_ADDR_MAC,
261c57bd7c3SPing-Ke Shih 	 RTW_PWR_CMD_POLLING, 0xFF, 0},
262c57bd7c3SPing-Ke Shih 	{0x05FB,
263c57bd7c3SPing-Ke Shih 	 RTW_PWR_CUT_ALL_MSK,
264c57bd7c3SPing-Ke Shih 	 RTW_PWR_INTF_ALL_MSK,
265c57bd7c3SPing-Ke Shih 	 RTW_PWR_ADDR_MAC,
266c57bd7c3SPing-Ke Shih 	 RTW_PWR_CMD_POLLING, 0xFF, 0},
267c57bd7c3SPing-Ke Shih 	{0x0002,
268c57bd7c3SPing-Ke Shih 	 RTW_PWR_CUT_ALL_MSK,
269c57bd7c3SPing-Ke Shih 	 RTW_PWR_INTF_ALL_MSK,
270c57bd7c3SPing-Ke Shih 	 RTW_PWR_ADDR_MAC,
271c57bd7c3SPing-Ke Shih 	 RTW_PWR_CMD_WRITE, BIT(0), 0},
272c57bd7c3SPing-Ke Shih 	{0x0002,
273c57bd7c3SPing-Ke Shih 	 RTW_PWR_CUT_ALL_MSK,
274c57bd7c3SPing-Ke Shih 	 RTW_PWR_INTF_ALL_MSK,
275c57bd7c3SPing-Ke Shih 	 RTW_PWR_ADDR_MAC,
276c57bd7c3SPing-Ke Shih 	 RTW_PWR_CMD_DELAY, 0, RTW_PWR_DELAY_US},
277c57bd7c3SPing-Ke Shih 	{0x0002,
278c57bd7c3SPing-Ke Shih 	 RTW_PWR_CUT_ALL_MSK,
279c57bd7c3SPing-Ke Shih 	 RTW_PWR_INTF_ALL_MSK,
280c57bd7c3SPing-Ke Shih 	 RTW_PWR_ADDR_MAC,
281c57bd7c3SPing-Ke Shih 	 RTW_PWR_CMD_WRITE, BIT(1), 0},
282c57bd7c3SPing-Ke Shih 	{0x0100,
283c57bd7c3SPing-Ke Shih 	 RTW_PWR_CUT_ALL_MSK,
284c57bd7c3SPing-Ke Shih 	 RTW_PWR_INTF_ALL_MSK,
285c57bd7c3SPing-Ke Shih 	 RTW_PWR_ADDR_MAC,
286c57bd7c3SPing-Ke Shih 	 RTW_PWR_CMD_WRITE, 0xFF, 0x03},
287c57bd7c3SPing-Ke Shih 	{0x0101,
288c57bd7c3SPing-Ke Shih 	 RTW_PWR_CUT_ALL_MSK,
289c57bd7c3SPing-Ke Shih 	 RTW_PWR_INTF_ALL_MSK,
290c57bd7c3SPing-Ke Shih 	 RTW_PWR_ADDR_MAC,
291c57bd7c3SPing-Ke Shih 	 RTW_PWR_CMD_WRITE, BIT(1), 0},
292c57bd7c3SPing-Ke Shih 	{0x0093,
293c57bd7c3SPing-Ke Shih 	 RTW_PWR_CUT_ALL_MSK,
294c57bd7c3SPing-Ke Shih 	 RTW_PWR_INTF_SDIO_MSK,
295c57bd7c3SPing-Ke Shih 	 RTW_PWR_ADDR_MAC,
296c57bd7c3SPing-Ke Shih 	 RTW_PWR_CMD_WRITE, 0xFF, 0x00},
297c57bd7c3SPing-Ke Shih 	{0x0553,
298c57bd7c3SPing-Ke Shih 	 RTW_PWR_CUT_ALL_MSK,
299c57bd7c3SPing-Ke Shih 	 RTW_PWR_INTF_ALL_MSK,
300c57bd7c3SPing-Ke Shih 	 RTW_PWR_ADDR_MAC,
301c57bd7c3SPing-Ke Shih 	 RTW_PWR_CMD_WRITE, BIT(5), BIT(5)},
302c57bd7c3SPing-Ke Shih 	{0xFFFF,
303c57bd7c3SPing-Ke Shih 	 RTW_PWR_CUT_ALL_MSK,
304c57bd7c3SPing-Ke Shih 	 RTW_PWR_INTF_ALL_MSK,
305c57bd7c3SPing-Ke Shih 	 0,
306c57bd7c3SPing-Ke Shih 	 RTW_PWR_CMD_END, 0, 0},
307c57bd7c3SPing-Ke Shih };
308c57bd7c3SPing-Ke Shih 
309c57bd7c3SPing-Ke Shih static const struct rtw_pwr_seq_cmd trans_act_to_pre_carddis_8723d[] = {
310c57bd7c3SPing-Ke Shih 	{0x0003,
311c57bd7c3SPing-Ke Shih 	 RTW_PWR_CUT_ALL_MSK,
312c57bd7c3SPing-Ke Shih 	 RTW_PWR_INTF_ALL_MSK,
313c57bd7c3SPing-Ke Shih 	 RTW_PWR_ADDR_MAC,
314c57bd7c3SPing-Ke Shih 	 RTW_PWR_CMD_WRITE, BIT(2), 0},
315c57bd7c3SPing-Ke Shih 	{0x0080,
316c57bd7c3SPing-Ke Shih 	 RTW_PWR_CUT_ALL_MSK,
317c57bd7c3SPing-Ke Shih 	 RTW_PWR_INTF_ALL_MSK,
318c57bd7c3SPing-Ke Shih 	 RTW_PWR_ADDR_MAC,
319c57bd7c3SPing-Ke Shih 	 RTW_PWR_CMD_WRITE, 0xFF, 0},
320c57bd7c3SPing-Ke Shih 	{0xFFFF,
321c57bd7c3SPing-Ke Shih 	 RTW_PWR_CUT_ALL_MSK,
322c57bd7c3SPing-Ke Shih 	 RTW_PWR_INTF_ALL_MSK,
323c57bd7c3SPing-Ke Shih 	 0,
324c57bd7c3SPing-Ke Shih 	 RTW_PWR_CMD_END, 0, 0},
325c57bd7c3SPing-Ke Shih };
326c57bd7c3SPing-Ke Shih 
327c57bd7c3SPing-Ke Shih static const struct rtw_pwr_seq_cmd trans_act_to_cardemu_8723d[] = {
328c57bd7c3SPing-Ke Shih 	{0x0002,
329c57bd7c3SPing-Ke Shih 	 RTW_PWR_CUT_ALL_MSK,
330c57bd7c3SPing-Ke Shih 	 RTW_PWR_INTF_ALL_MSK,
331c57bd7c3SPing-Ke Shih 	 RTW_PWR_ADDR_MAC,
332c57bd7c3SPing-Ke Shih 	 RTW_PWR_CMD_WRITE, BIT(0), 0},
333c57bd7c3SPing-Ke Shih 	{0x0049,
334c57bd7c3SPing-Ke Shih 	 RTW_PWR_CUT_ALL_MSK,
335c57bd7c3SPing-Ke Shih 	 RTW_PWR_INTF_ALL_MSK,
336c57bd7c3SPing-Ke Shih 	 RTW_PWR_ADDR_MAC,
337c57bd7c3SPing-Ke Shih 	 RTW_PWR_CMD_WRITE, BIT(1), 0},
338c57bd7c3SPing-Ke Shih 	{0x0006,
339c57bd7c3SPing-Ke Shih 	 RTW_PWR_CUT_ALL_MSK,
340c57bd7c3SPing-Ke Shih 	 RTW_PWR_INTF_ALL_MSK,
341c57bd7c3SPing-Ke Shih 	 RTW_PWR_ADDR_MAC,
342c57bd7c3SPing-Ke Shih 	 RTW_PWR_CMD_WRITE, BIT(0), BIT(0)},
343c57bd7c3SPing-Ke Shih 	{0x0005,
344c57bd7c3SPing-Ke Shih 	 RTW_PWR_CUT_ALL_MSK,
345c57bd7c3SPing-Ke Shih 	 RTW_PWR_INTF_ALL_MSK,
346c57bd7c3SPing-Ke Shih 	 RTW_PWR_ADDR_MAC,
347c57bd7c3SPing-Ke Shih 	 RTW_PWR_CMD_WRITE, BIT(1), BIT(1)},
348c57bd7c3SPing-Ke Shih 	{0x0005,
349c57bd7c3SPing-Ke Shih 	 RTW_PWR_CUT_ALL_MSK,
350c57bd7c3SPing-Ke Shih 	 RTW_PWR_INTF_ALL_MSK,
351c57bd7c3SPing-Ke Shih 	 RTW_PWR_ADDR_MAC,
352c57bd7c3SPing-Ke Shih 	 RTW_PWR_CMD_POLLING, BIT(1), 0},
353c57bd7c3SPing-Ke Shih 	{0x0010,
354c57bd7c3SPing-Ke Shih 	 RTW_PWR_CUT_ALL_MSK,
355c57bd7c3SPing-Ke Shih 	 RTW_PWR_INTF_ALL_MSK,
356c57bd7c3SPing-Ke Shih 	 RTW_PWR_ADDR_MAC,
357c57bd7c3SPing-Ke Shih 	 RTW_PWR_CMD_WRITE, BIT(6), 0},
358c57bd7c3SPing-Ke Shih 	{0x0000,
359c57bd7c3SPing-Ke Shih 	 RTW_PWR_CUT_ALL_MSK,
360c57bd7c3SPing-Ke Shih 	 RTW_PWR_INTF_USB_MSK | RTW_PWR_INTF_SDIO_MSK,
361c57bd7c3SPing-Ke Shih 	 RTW_PWR_ADDR_MAC,
362c57bd7c3SPing-Ke Shih 	 RTW_PWR_CMD_WRITE, BIT(5), BIT(5)},
363c57bd7c3SPing-Ke Shih 	{0x0020,
364c57bd7c3SPing-Ke Shih 	 RTW_PWR_CUT_ALL_MSK,
365c57bd7c3SPing-Ke Shih 	 RTW_PWR_INTF_USB_MSK | RTW_PWR_INTF_SDIO_MSK,
366c57bd7c3SPing-Ke Shih 	 RTW_PWR_ADDR_MAC,
367c57bd7c3SPing-Ke Shih 	 RTW_PWR_CMD_WRITE, BIT(0), 0},
368c57bd7c3SPing-Ke Shih 	{0xFFFF,
369c57bd7c3SPing-Ke Shih 	 RTW_PWR_CUT_ALL_MSK,
370c57bd7c3SPing-Ke Shih 	 RTW_PWR_INTF_ALL_MSK,
371c57bd7c3SPing-Ke Shih 	 0,
372c57bd7c3SPing-Ke Shih 	 RTW_PWR_CMD_END, 0, 0},
373c57bd7c3SPing-Ke Shih };
374c57bd7c3SPing-Ke Shih 
375c57bd7c3SPing-Ke Shih static const struct rtw_pwr_seq_cmd trans_cardemu_to_carddis_8723d[] = {
376c57bd7c3SPing-Ke Shih 	{0x0007,
377c57bd7c3SPing-Ke Shih 	 RTW_PWR_CUT_ALL_MSK,
378c57bd7c3SPing-Ke Shih 	 RTW_PWR_INTF_SDIO_MSK,
379c57bd7c3SPing-Ke Shih 	 RTW_PWR_ADDR_MAC,
380c57bd7c3SPing-Ke Shih 	 RTW_PWR_CMD_WRITE, 0xFF, 0x20},
381c57bd7c3SPing-Ke Shih 	{0x0005,
382c57bd7c3SPing-Ke Shih 	 RTW_PWR_CUT_ALL_MSK,
383c57bd7c3SPing-Ke Shih 	 RTW_PWR_INTF_USB_MSK | RTW_PWR_INTF_SDIO_MSK,
384c57bd7c3SPing-Ke Shih 	 RTW_PWR_ADDR_MAC,
385c57bd7c3SPing-Ke Shih 	 RTW_PWR_CMD_WRITE, BIT(3) | BIT(4), BIT(3)},
386c57bd7c3SPing-Ke Shih 	{0x0005,
387c57bd7c3SPing-Ke Shih 	 RTW_PWR_CUT_ALL_MSK,
388c57bd7c3SPing-Ke Shih 	 RTW_PWR_INTF_PCI_MSK,
389c57bd7c3SPing-Ke Shih 	 RTW_PWR_ADDR_MAC,
390c57bd7c3SPing-Ke Shih 	 RTW_PWR_CMD_WRITE, BIT(2), BIT(2)},
391c57bd7c3SPing-Ke Shih 	{0x0005,
392c57bd7c3SPing-Ke Shih 	 RTW_PWR_CUT_ALL_MSK,
393c57bd7c3SPing-Ke Shih 	 RTW_PWR_INTF_PCI_MSK,
394c57bd7c3SPing-Ke Shih 	 RTW_PWR_ADDR_MAC,
395c57bd7c3SPing-Ke Shih 	 RTW_PWR_CMD_WRITE, BIT(3) | BIT(4), BIT(3) | BIT(4)},
396c57bd7c3SPing-Ke Shih 	{0x004A,
397c57bd7c3SPing-Ke Shih 	 RTW_PWR_CUT_ALL_MSK,
398c57bd7c3SPing-Ke Shih 	 RTW_PWR_INTF_USB_MSK,
399c57bd7c3SPing-Ke Shih 	 RTW_PWR_ADDR_MAC,
400c57bd7c3SPing-Ke Shih 	 RTW_PWR_CMD_WRITE, BIT(0), 1},
401c57bd7c3SPing-Ke Shih 	{0x0023,
402c57bd7c3SPing-Ke Shih 	 RTW_PWR_CUT_ALL_MSK,
403c57bd7c3SPing-Ke Shih 	 RTW_PWR_INTF_SDIO_MSK,
404c57bd7c3SPing-Ke Shih 	 RTW_PWR_ADDR_MAC,
405c57bd7c3SPing-Ke Shih 	 RTW_PWR_CMD_WRITE, BIT(4), BIT(4)},
406c57bd7c3SPing-Ke Shih 	{0x0086,
407c57bd7c3SPing-Ke Shih 	 RTW_PWR_CUT_ALL_MSK,
408c57bd7c3SPing-Ke Shih 	 RTW_PWR_INTF_SDIO_MSK,
409c57bd7c3SPing-Ke Shih 	 RTW_PWR_ADDR_SDIO,
410c57bd7c3SPing-Ke Shih 	 RTW_PWR_CMD_WRITE, BIT(0), BIT(0)},
411c57bd7c3SPing-Ke Shih 	{0x0086,
412c57bd7c3SPing-Ke Shih 	 RTW_PWR_CUT_ALL_MSK,
413c57bd7c3SPing-Ke Shih 	 RTW_PWR_INTF_SDIO_MSK,
414c57bd7c3SPing-Ke Shih 	 RTW_PWR_ADDR_SDIO,
415c57bd7c3SPing-Ke Shih 	 RTW_PWR_CMD_POLLING, BIT(1), 0},
416c57bd7c3SPing-Ke Shih 	{0xFFFF,
417c57bd7c3SPing-Ke Shih 	 RTW_PWR_CUT_ALL_MSK,
418c57bd7c3SPing-Ke Shih 	 RTW_PWR_INTF_ALL_MSK,
419c57bd7c3SPing-Ke Shih 	 0,
420c57bd7c3SPing-Ke Shih 	 RTW_PWR_CMD_END, 0, 0},
421c57bd7c3SPing-Ke Shih };
422c57bd7c3SPing-Ke Shih 
423c57bd7c3SPing-Ke Shih static const struct rtw_pwr_seq_cmd trans_act_to_post_carddis_8723d[] = {
424c57bd7c3SPing-Ke Shih 	{0x001D,
425c57bd7c3SPing-Ke Shih 	 RTW_PWR_CUT_ALL_MSK,
426c57bd7c3SPing-Ke Shih 	 RTW_PWR_INTF_ALL_MSK,
427c57bd7c3SPing-Ke Shih 	 RTW_PWR_ADDR_MAC,
428c57bd7c3SPing-Ke Shih 	 RTW_PWR_CMD_WRITE, BIT(0), 0},
429c57bd7c3SPing-Ke Shih 	{0x001D,
430c57bd7c3SPing-Ke Shih 	 RTW_PWR_CUT_ALL_MSK,
431c57bd7c3SPing-Ke Shih 	 RTW_PWR_INTF_ALL_MSK,
432c57bd7c3SPing-Ke Shih 	 RTW_PWR_ADDR_MAC,
433c57bd7c3SPing-Ke Shih 	 RTW_PWR_CMD_WRITE, BIT(0), BIT(0)},
434c57bd7c3SPing-Ke Shih 	{0x001C,
435c57bd7c3SPing-Ke Shih 	 RTW_PWR_CUT_ALL_MSK,
436c57bd7c3SPing-Ke Shih 	 RTW_PWR_INTF_ALL_MSK,
437c57bd7c3SPing-Ke Shih 	 RTW_PWR_ADDR_MAC,
438c57bd7c3SPing-Ke Shih 	 RTW_PWR_CMD_WRITE, 0xFF, 0x0E},
439c57bd7c3SPing-Ke Shih 	{0xFFFF,
440c57bd7c3SPing-Ke Shih 	 RTW_PWR_CUT_ALL_MSK,
441c57bd7c3SPing-Ke Shih 	 RTW_PWR_INTF_ALL_MSK,
442c57bd7c3SPing-Ke Shih 	 0,
443c57bd7c3SPing-Ke Shih 	 RTW_PWR_CMD_END, 0, 0},
444c57bd7c3SPing-Ke Shih };
445c57bd7c3SPing-Ke Shih 
446c57bd7c3SPing-Ke Shih static const struct rtw_pwr_seq_cmd *card_disable_flow_8723d[] = {
447c57bd7c3SPing-Ke Shih 	trans_act_to_lps_8723d,
448c57bd7c3SPing-Ke Shih 	trans_act_to_pre_carddis_8723d,
449c57bd7c3SPing-Ke Shih 	trans_act_to_cardemu_8723d,
450c57bd7c3SPing-Ke Shih 	trans_cardemu_to_carddis_8723d,
451c57bd7c3SPing-Ke Shih 	trans_act_to_post_carddis_8723d,
452c57bd7c3SPing-Ke Shih 	NULL
453c57bd7c3SPing-Ke Shih };
454c57bd7c3SPing-Ke Shih 
455e0c27cdbSPing-Ke Shih static const struct rtw_rf_sipi_addr rtw8723d_rf_sipi_addr[] = {
456e0c27cdbSPing-Ke Shih 	[RF_PATH_A] = { .hssi_1 = 0x820, .lssi_read    = 0x8a0,
457e0c27cdbSPing-Ke Shih 			.hssi_2 = 0x824, .lssi_read_pi = 0x8b8},
458e0c27cdbSPing-Ke Shih 	[RF_PATH_B] = { .hssi_1 = 0x828, .lssi_read    = 0x8a4,
459e0c27cdbSPing-Ke Shih 			.hssi_2 = 0x82c, .lssi_read_pi = 0x8bc},
460e0c27cdbSPing-Ke Shih };
461e0c27cdbSPing-Ke Shih 
4629874f685SPing-Ke Shih static const struct rtw_rfe_def rtw8723d_rfe_defs[] = {
4639874f685SPing-Ke Shih 	[0] = { .phy_pg_tbl	= &rtw8723d_bb_pg_tbl,
4649874f685SPing-Ke Shih 		.txpwr_lmt_tbl	= &rtw8723d_txpwr_lmt_tbl,},
4659874f685SPing-Ke Shih };
4669874f685SPing-Ke Shih 
467811853daSPing-Ke Shih struct rtw_chip_info rtw8723d_hw_spec = {
468811853daSPing-Ke Shih 	.ops = &rtw8723d_ops,
469811853daSPing-Ke Shih 	.id = RTW_CHIP_TYPE_8723D,
470811853daSPing-Ke Shih 	.fw_name = "rtw88/rtw8723d_fw.bin",
471811853daSPing-Ke Shih 	.tx_pkt_desc_sz = 40,
472811853daSPing-Ke Shih 	.tx_buf_desc_sz = 16,
473811853daSPing-Ke Shih 	.rx_pkt_desc_sz = 24,
474811853daSPing-Ke Shih 	.rx_buf_desc_sz = 8,
475811853daSPing-Ke Shih 	.phy_efuse_size = 512,
476811853daSPing-Ke Shih 	.log_efuse_size = 512,
477811853daSPing-Ke Shih 	.ptct_efuse_size = 96 + 1,
478811853daSPing-Ke Shih 	.txgi_factor = 1,
479811853daSPing-Ke Shih 	.is_pwr_by_rate_dec = true,
480811853daSPing-Ke Shih 	.max_power_index = 0x3f,
481811853daSPing-Ke Shih 	.csi_buf_pg_num = 0,
482811853daSPing-Ke Shih 	.band = RTW_BAND_2G,
483811853daSPing-Ke Shih 	.ht_supported = true,
484811853daSPing-Ke Shih 	.vht_supported = false,
485811853daSPing-Ke Shih 	.lps_deep_mode_supported = 0,
486811853daSPing-Ke Shih 	.sys_func_en = 0xFD,
487c57bd7c3SPing-Ke Shih 	.pwr_on_seq = card_enable_flow_8723d,
488c57bd7c3SPing-Ke Shih 	.pwr_off_seq = card_disable_flow_8723d,
489e0c27cdbSPing-Ke Shih 	.rf_sipi_addr = {0x840, 0x844},
490e0c27cdbSPing-Ke Shih 	.rf_sipi_read_addr = rtw8723d_rf_sipi_addr,
491e0c27cdbSPing-Ke Shih 	.fix_rf_phy_num = 2,
4929874f685SPing-Ke Shih 	.mac_tbl = &rtw8723d_mac_tbl,
4939874f685SPing-Ke Shih 	.agc_tbl = &rtw8723d_agc_tbl,
4949874f685SPing-Ke Shih 	.bb_tbl = &rtw8723d_bb_tbl,
4959874f685SPing-Ke Shih 	.rf_tbl = {&rtw8723d_rf_a_tbl},
4969874f685SPing-Ke Shih 	.rfe_defs = rtw8723d_rfe_defs,
4979874f685SPing-Ke Shih 	.rfe_defs_size = ARRAY_SIZE(rtw8723d_rfe_defs),
498811853daSPing-Ke Shih };
499811853daSPing-Ke Shih EXPORT_SYMBOL(rtw8723d_hw_spec);
500811853daSPing-Ke Shih 
501811853daSPing-Ke Shih MODULE_FIRMWARE("rtw88/rtw8723d_fw.bin");
502