162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */
262306a36Sopenharmony_ci/* ZD1211 USB-WLAN driver for Linux
362306a36Sopenharmony_ci *
462306a36Sopenharmony_ci * Copyright (C) 2005-2007 Ulrich Kunitz <kune@deine-taler.de>
562306a36Sopenharmony_ci * Copyright (C) 2006-2007 Daniel Drake <dsd@gentoo.org>
662306a36Sopenharmony_ci */
762306a36Sopenharmony_ci
862306a36Sopenharmony_ci#ifndef _ZD_CHIP_H
962306a36Sopenharmony_ci#define _ZD_CHIP_H
1062306a36Sopenharmony_ci
1162306a36Sopenharmony_ci#include <net/mac80211.h>
1262306a36Sopenharmony_ci
1362306a36Sopenharmony_ci#include "zd_rf.h"
1462306a36Sopenharmony_ci#include "zd_usb.h"
1562306a36Sopenharmony_ci
1662306a36Sopenharmony_ci/* Header for the Media Access Controller (MAC) and the Baseband Processor
1762306a36Sopenharmony_ci * (BBP). It appears that the ZD1211 wraps the old ZD1205 with USB glue and
1862306a36Sopenharmony_ci * adds a processor for handling the USB protocol.
1962306a36Sopenharmony_ci */
2062306a36Sopenharmony_ci
2162306a36Sopenharmony_ci/* Address space */
2262306a36Sopenharmony_cienum {
2362306a36Sopenharmony_ci	/* CONTROL REGISTERS */
2462306a36Sopenharmony_ci	CR_START			= 0x9000,
2562306a36Sopenharmony_ci
2662306a36Sopenharmony_ci
2762306a36Sopenharmony_ci	/* FIRMWARE */
2862306a36Sopenharmony_ci	FW_START			= 0xee00,
2962306a36Sopenharmony_ci
3062306a36Sopenharmony_ci
3162306a36Sopenharmony_ci	/* EEPROM */
3262306a36Sopenharmony_ci	E2P_START			= 0xf800,
3362306a36Sopenharmony_ci	E2P_LEN				= 0x800,
3462306a36Sopenharmony_ci
3562306a36Sopenharmony_ci	/* EEPROM layout */
3662306a36Sopenharmony_ci	E2P_LOAD_CODE_LEN		= 0xe,		/* base 0xf800 */
3762306a36Sopenharmony_ci	E2P_LOAD_VECT_LEN		= 0x9,		/* base 0xf80e */
3862306a36Sopenharmony_ci	/* E2P_DATA indexes into this */
3962306a36Sopenharmony_ci	E2P_DATA_LEN			= 0x7e,		/* base 0xf817 */
4062306a36Sopenharmony_ci	E2P_BOOT_CODE_LEN		= 0x760,	/* base 0xf895 */
4162306a36Sopenharmony_ci	E2P_INTR_VECT_LEN		= 0xb,		/* base 0xfff5 */
4262306a36Sopenharmony_ci
4362306a36Sopenharmony_ci	/* Some precomputed offsets into the EEPROM */
4462306a36Sopenharmony_ci	E2P_DATA_OFFSET			= E2P_LOAD_CODE_LEN + E2P_LOAD_VECT_LEN,
4562306a36Sopenharmony_ci	E2P_BOOT_CODE_OFFSET		= E2P_DATA_OFFSET + E2P_DATA_LEN,
4662306a36Sopenharmony_ci};
4762306a36Sopenharmony_ci
4862306a36Sopenharmony_ci#define CTL_REG(offset) ((zd_addr_t)(CR_START + (offset)))
4962306a36Sopenharmony_ci#define E2P_DATA(offset) ((zd_addr_t)(E2P_START + E2P_DATA_OFFSET + (offset)))
5062306a36Sopenharmony_ci#define FWRAW_DATA(offset) ((zd_addr_t)(FW_START + (offset)))
5162306a36Sopenharmony_ci
5262306a36Sopenharmony_ci/* 8-bit hardware registers */
5362306a36Sopenharmony_ci#define ZD_CR0   CTL_REG(0x0000)
5462306a36Sopenharmony_ci#define ZD_CR1   CTL_REG(0x0004)
5562306a36Sopenharmony_ci#define ZD_CR2   CTL_REG(0x0008)
5662306a36Sopenharmony_ci#define ZD_CR3   CTL_REG(0x000C)
5762306a36Sopenharmony_ci
5862306a36Sopenharmony_ci#define ZD_CR5   CTL_REG(0x0010)
5962306a36Sopenharmony_ci/*	bit 5: if set short preamble used
6062306a36Sopenharmony_ci *	bit 6: filter band - Japan channel 14 on, else off
6162306a36Sopenharmony_ci */
6262306a36Sopenharmony_ci#define ZD_CR6   CTL_REG(0x0014)
6362306a36Sopenharmony_ci#define ZD_CR7   CTL_REG(0x0018)
6462306a36Sopenharmony_ci#define ZD_CR8   CTL_REG(0x001C)
6562306a36Sopenharmony_ci
6662306a36Sopenharmony_ci#define ZD_CR4   CTL_REG(0x0020)
6762306a36Sopenharmony_ci
6862306a36Sopenharmony_ci#define ZD_CR9   CTL_REG(0x0024)
6962306a36Sopenharmony_ci/*	bit 2: antenna switch (together with ZD_CR10) */
7062306a36Sopenharmony_ci#define ZD_CR10  CTL_REG(0x0028)
7162306a36Sopenharmony_ci/*	bit 1: antenna switch (together with ZD_CR9)
7262306a36Sopenharmony_ci *	RF2959 controls with ZD_CR11 radion on and off
7362306a36Sopenharmony_ci */
7462306a36Sopenharmony_ci#define ZD_CR11  CTL_REG(0x002C)
7562306a36Sopenharmony_ci/*	bit 6:  TX power control for OFDM
7662306a36Sopenharmony_ci *	RF2959 controls with ZD_CR10 radio on and off
7762306a36Sopenharmony_ci */
7862306a36Sopenharmony_ci#define ZD_CR12  CTL_REG(0x0030)
7962306a36Sopenharmony_ci#define ZD_CR13  CTL_REG(0x0034)
8062306a36Sopenharmony_ci#define ZD_CR14  CTL_REG(0x0038)
8162306a36Sopenharmony_ci#define ZD_CR15  CTL_REG(0x003C)
8262306a36Sopenharmony_ci#define ZD_CR16  CTL_REG(0x0040)
8362306a36Sopenharmony_ci#define ZD_CR17  CTL_REG(0x0044)
8462306a36Sopenharmony_ci#define ZD_CR18  CTL_REG(0x0048)
8562306a36Sopenharmony_ci#define ZD_CR19  CTL_REG(0x004C)
8662306a36Sopenharmony_ci#define ZD_CR20  CTL_REG(0x0050)
8762306a36Sopenharmony_ci#define ZD_CR21  CTL_REG(0x0054)
8862306a36Sopenharmony_ci#define ZD_CR22  CTL_REG(0x0058)
8962306a36Sopenharmony_ci#define ZD_CR23  CTL_REG(0x005C)
9062306a36Sopenharmony_ci#define ZD_CR24  CTL_REG(0x0060)	/* CCA threshold */
9162306a36Sopenharmony_ci#define ZD_CR25  CTL_REG(0x0064)
9262306a36Sopenharmony_ci#define ZD_CR26  CTL_REG(0x0068)
9362306a36Sopenharmony_ci#define ZD_CR27  CTL_REG(0x006C)
9462306a36Sopenharmony_ci#define ZD_CR28  CTL_REG(0x0070)
9562306a36Sopenharmony_ci#define ZD_CR29  CTL_REG(0x0074)
9662306a36Sopenharmony_ci#define ZD_CR30  CTL_REG(0x0078)
9762306a36Sopenharmony_ci#define ZD_CR31  CTL_REG(0x007C)	/* TX power control for RF in
9862306a36Sopenharmony_ci					 * CCK mode
9962306a36Sopenharmony_ci					 */
10062306a36Sopenharmony_ci#define ZD_CR32  CTL_REG(0x0080)
10162306a36Sopenharmony_ci#define ZD_CR33  CTL_REG(0x0084)
10262306a36Sopenharmony_ci#define ZD_CR34  CTL_REG(0x0088)
10362306a36Sopenharmony_ci#define ZD_CR35  CTL_REG(0x008C)
10462306a36Sopenharmony_ci#define ZD_CR36  CTL_REG(0x0090)
10562306a36Sopenharmony_ci#define ZD_CR37  CTL_REG(0x0094)
10662306a36Sopenharmony_ci#define ZD_CR38  CTL_REG(0x0098)
10762306a36Sopenharmony_ci#define ZD_CR39  CTL_REG(0x009C)
10862306a36Sopenharmony_ci#define ZD_CR40  CTL_REG(0x00A0)
10962306a36Sopenharmony_ci#define ZD_CR41  CTL_REG(0x00A4)
11062306a36Sopenharmony_ci#define ZD_CR42  CTL_REG(0x00A8)
11162306a36Sopenharmony_ci#define ZD_CR43  CTL_REG(0x00AC)
11262306a36Sopenharmony_ci#define ZD_CR44  CTL_REG(0x00B0)
11362306a36Sopenharmony_ci#define ZD_CR45  CTL_REG(0x00B4)
11462306a36Sopenharmony_ci#define ZD_CR46  CTL_REG(0x00B8)
11562306a36Sopenharmony_ci#define ZD_CR47  CTL_REG(0x00BC)	/* CCK baseband gain
11662306a36Sopenharmony_ci					 * (patch value might be in EEPROM)
11762306a36Sopenharmony_ci					 */
11862306a36Sopenharmony_ci#define ZD_CR48  CTL_REG(0x00C0)
11962306a36Sopenharmony_ci#define ZD_CR49  CTL_REG(0x00C4)
12062306a36Sopenharmony_ci#define ZD_CR50  CTL_REG(0x00C8)
12162306a36Sopenharmony_ci#define ZD_CR51  CTL_REG(0x00CC)	/* TX power control for RF in
12262306a36Sopenharmony_ci					 * 6-36M modes
12362306a36Sopenharmony_ci					 */
12462306a36Sopenharmony_ci#define ZD_CR52  CTL_REG(0x00D0)	/* TX power control for RF in
12562306a36Sopenharmony_ci					 * 48M mode
12662306a36Sopenharmony_ci					 */
12762306a36Sopenharmony_ci#define ZD_CR53  CTL_REG(0x00D4)	/* TX power control for RF in
12862306a36Sopenharmony_ci					 * 54M mode
12962306a36Sopenharmony_ci					 */
13062306a36Sopenharmony_ci#define ZD_CR54  CTL_REG(0x00D8)
13162306a36Sopenharmony_ci#define ZD_CR55  CTL_REG(0x00DC)
13262306a36Sopenharmony_ci#define ZD_CR56  CTL_REG(0x00E0)
13362306a36Sopenharmony_ci#define ZD_CR57  CTL_REG(0x00E4)
13462306a36Sopenharmony_ci#define ZD_CR58  CTL_REG(0x00E8)
13562306a36Sopenharmony_ci#define ZD_CR59  CTL_REG(0x00EC)
13662306a36Sopenharmony_ci#define ZD_CR60  CTL_REG(0x00F0)
13762306a36Sopenharmony_ci#define ZD_CR61  CTL_REG(0x00F4)
13862306a36Sopenharmony_ci#define ZD_CR62  CTL_REG(0x00F8)
13962306a36Sopenharmony_ci#define ZD_CR63  CTL_REG(0x00FC)
14062306a36Sopenharmony_ci#define ZD_CR64  CTL_REG(0x0100)
14162306a36Sopenharmony_ci#define ZD_CR65  CTL_REG(0x0104) /* OFDM 54M calibration */
14262306a36Sopenharmony_ci#define ZD_CR66  CTL_REG(0x0108) /* OFDM 48M calibration */
14362306a36Sopenharmony_ci#define ZD_CR67  CTL_REG(0x010C) /* OFDM 36M calibration */
14462306a36Sopenharmony_ci#define ZD_CR68  CTL_REG(0x0110) /* CCK calibration */
14562306a36Sopenharmony_ci#define ZD_CR69  CTL_REG(0x0114)
14662306a36Sopenharmony_ci#define ZD_CR70  CTL_REG(0x0118)
14762306a36Sopenharmony_ci#define ZD_CR71  CTL_REG(0x011C)
14862306a36Sopenharmony_ci#define ZD_CR72  CTL_REG(0x0120)
14962306a36Sopenharmony_ci#define ZD_CR73  CTL_REG(0x0124)
15062306a36Sopenharmony_ci#define ZD_CR74  CTL_REG(0x0128)
15162306a36Sopenharmony_ci#define ZD_CR75  CTL_REG(0x012C)
15262306a36Sopenharmony_ci#define ZD_CR76  CTL_REG(0x0130)
15362306a36Sopenharmony_ci#define ZD_CR77  CTL_REG(0x0134)
15462306a36Sopenharmony_ci#define ZD_CR78  CTL_REG(0x0138)
15562306a36Sopenharmony_ci#define ZD_CR79  CTL_REG(0x013C)
15662306a36Sopenharmony_ci#define ZD_CR80  CTL_REG(0x0140)
15762306a36Sopenharmony_ci#define ZD_CR81  CTL_REG(0x0144)
15862306a36Sopenharmony_ci#define ZD_CR82  CTL_REG(0x0148)
15962306a36Sopenharmony_ci#define ZD_CR83  CTL_REG(0x014C)
16062306a36Sopenharmony_ci#define ZD_CR84  CTL_REG(0x0150)
16162306a36Sopenharmony_ci#define ZD_CR85  CTL_REG(0x0154)
16262306a36Sopenharmony_ci#define ZD_CR86  CTL_REG(0x0158)
16362306a36Sopenharmony_ci#define ZD_CR87  CTL_REG(0x015C)
16462306a36Sopenharmony_ci#define ZD_CR88  CTL_REG(0x0160)
16562306a36Sopenharmony_ci#define ZD_CR89  CTL_REG(0x0164)
16662306a36Sopenharmony_ci#define ZD_CR90  CTL_REG(0x0168)
16762306a36Sopenharmony_ci#define ZD_CR91  CTL_REG(0x016C)
16862306a36Sopenharmony_ci#define ZD_CR92  CTL_REG(0x0170)
16962306a36Sopenharmony_ci#define ZD_CR93  CTL_REG(0x0174)
17062306a36Sopenharmony_ci#define ZD_CR94  CTL_REG(0x0178)
17162306a36Sopenharmony_ci#define ZD_CR95  CTL_REG(0x017C)
17262306a36Sopenharmony_ci#define ZD_CR96  CTL_REG(0x0180)
17362306a36Sopenharmony_ci#define ZD_CR97  CTL_REG(0x0184)
17462306a36Sopenharmony_ci#define ZD_CR98  CTL_REG(0x0188)
17562306a36Sopenharmony_ci#define ZD_CR99  CTL_REG(0x018C)
17662306a36Sopenharmony_ci#define ZD_CR100 CTL_REG(0x0190)
17762306a36Sopenharmony_ci#define ZD_CR101 CTL_REG(0x0194)
17862306a36Sopenharmony_ci#define ZD_CR102 CTL_REG(0x0198)
17962306a36Sopenharmony_ci#define ZD_CR103 CTL_REG(0x019C)
18062306a36Sopenharmony_ci#define ZD_CR104 CTL_REG(0x01A0)
18162306a36Sopenharmony_ci#define ZD_CR105 CTL_REG(0x01A4)
18262306a36Sopenharmony_ci#define ZD_CR106 CTL_REG(0x01A8)
18362306a36Sopenharmony_ci#define ZD_CR107 CTL_REG(0x01AC)
18462306a36Sopenharmony_ci#define ZD_CR108 CTL_REG(0x01B0)
18562306a36Sopenharmony_ci#define ZD_CR109 CTL_REG(0x01B4)
18662306a36Sopenharmony_ci#define ZD_CR110 CTL_REG(0x01B8)
18762306a36Sopenharmony_ci#define ZD_CR111 CTL_REG(0x01BC)
18862306a36Sopenharmony_ci#define ZD_CR112 CTL_REG(0x01C0)
18962306a36Sopenharmony_ci#define ZD_CR113 CTL_REG(0x01C4)
19062306a36Sopenharmony_ci#define ZD_CR114 CTL_REG(0x01C8)
19162306a36Sopenharmony_ci#define ZD_CR115 CTL_REG(0x01CC)
19262306a36Sopenharmony_ci#define ZD_CR116 CTL_REG(0x01D0)
19362306a36Sopenharmony_ci#define ZD_CR117 CTL_REG(0x01D4)
19462306a36Sopenharmony_ci#define ZD_CR118 CTL_REG(0x01D8)
19562306a36Sopenharmony_ci#define ZD_CR119 CTL_REG(0x01DC)
19662306a36Sopenharmony_ci#define ZD_CR120 CTL_REG(0x01E0)
19762306a36Sopenharmony_ci#define ZD_CR121 CTL_REG(0x01E4)
19862306a36Sopenharmony_ci#define ZD_CR122 CTL_REG(0x01E8)
19962306a36Sopenharmony_ci#define ZD_CR123 CTL_REG(0x01EC)
20062306a36Sopenharmony_ci#define ZD_CR124 CTL_REG(0x01F0)
20162306a36Sopenharmony_ci#define ZD_CR125 CTL_REG(0x01F4)
20262306a36Sopenharmony_ci#define ZD_CR126 CTL_REG(0x01F8)
20362306a36Sopenharmony_ci#define ZD_CR127 CTL_REG(0x01FC)
20462306a36Sopenharmony_ci#define ZD_CR128 CTL_REG(0x0200)
20562306a36Sopenharmony_ci#define ZD_CR129 CTL_REG(0x0204)
20662306a36Sopenharmony_ci#define ZD_CR130 CTL_REG(0x0208)
20762306a36Sopenharmony_ci#define ZD_CR131 CTL_REG(0x020C)
20862306a36Sopenharmony_ci#define ZD_CR132 CTL_REG(0x0210)
20962306a36Sopenharmony_ci#define ZD_CR133 CTL_REG(0x0214)
21062306a36Sopenharmony_ci#define ZD_CR134 CTL_REG(0x0218)
21162306a36Sopenharmony_ci#define ZD_CR135 CTL_REG(0x021C)
21262306a36Sopenharmony_ci#define ZD_CR136 CTL_REG(0x0220)
21362306a36Sopenharmony_ci#define ZD_CR137 CTL_REG(0x0224)
21462306a36Sopenharmony_ci#define ZD_CR138 CTL_REG(0x0228)
21562306a36Sopenharmony_ci#define ZD_CR139 CTL_REG(0x022C)
21662306a36Sopenharmony_ci#define ZD_CR140 CTL_REG(0x0230)
21762306a36Sopenharmony_ci#define ZD_CR141 CTL_REG(0x0234)
21862306a36Sopenharmony_ci#define ZD_CR142 CTL_REG(0x0238)
21962306a36Sopenharmony_ci#define ZD_CR143 CTL_REG(0x023C)
22062306a36Sopenharmony_ci#define ZD_CR144 CTL_REG(0x0240)
22162306a36Sopenharmony_ci#define ZD_CR145 CTL_REG(0x0244)
22262306a36Sopenharmony_ci#define ZD_CR146 CTL_REG(0x0248)
22362306a36Sopenharmony_ci#define ZD_CR147 CTL_REG(0x024C)
22462306a36Sopenharmony_ci#define ZD_CR148 CTL_REG(0x0250)
22562306a36Sopenharmony_ci#define ZD_CR149 CTL_REG(0x0254)
22662306a36Sopenharmony_ci#define ZD_CR150 CTL_REG(0x0258)
22762306a36Sopenharmony_ci#define ZD_CR151 CTL_REG(0x025C)
22862306a36Sopenharmony_ci#define ZD_CR152 CTL_REG(0x0260)
22962306a36Sopenharmony_ci#define ZD_CR153 CTL_REG(0x0264)
23062306a36Sopenharmony_ci#define ZD_CR154 CTL_REG(0x0268)
23162306a36Sopenharmony_ci#define ZD_CR155 CTL_REG(0x026C)
23262306a36Sopenharmony_ci#define ZD_CR156 CTL_REG(0x0270)
23362306a36Sopenharmony_ci#define ZD_CR157 CTL_REG(0x0274)
23462306a36Sopenharmony_ci#define ZD_CR158 CTL_REG(0x0278)
23562306a36Sopenharmony_ci#define ZD_CR159 CTL_REG(0x027C)
23662306a36Sopenharmony_ci#define ZD_CR160 CTL_REG(0x0280)
23762306a36Sopenharmony_ci#define ZD_CR161 CTL_REG(0x0284)
23862306a36Sopenharmony_ci#define ZD_CR162 CTL_REG(0x0288)
23962306a36Sopenharmony_ci#define ZD_CR163 CTL_REG(0x028C)
24062306a36Sopenharmony_ci#define ZD_CR164 CTL_REG(0x0290)
24162306a36Sopenharmony_ci#define ZD_CR165 CTL_REG(0x0294)
24262306a36Sopenharmony_ci#define ZD_CR166 CTL_REG(0x0298)
24362306a36Sopenharmony_ci#define ZD_CR167 CTL_REG(0x029C)
24462306a36Sopenharmony_ci#define ZD_CR168 CTL_REG(0x02A0)
24562306a36Sopenharmony_ci#define ZD_CR169 CTL_REG(0x02A4)
24662306a36Sopenharmony_ci#define ZD_CR170 CTL_REG(0x02A8)
24762306a36Sopenharmony_ci#define ZD_CR171 CTL_REG(0x02AC)
24862306a36Sopenharmony_ci#define ZD_CR172 CTL_REG(0x02B0)
24962306a36Sopenharmony_ci#define ZD_CR173 CTL_REG(0x02B4)
25062306a36Sopenharmony_ci#define ZD_CR174 CTL_REG(0x02B8)
25162306a36Sopenharmony_ci#define ZD_CR175 CTL_REG(0x02BC)
25262306a36Sopenharmony_ci#define ZD_CR176 CTL_REG(0x02C0)
25362306a36Sopenharmony_ci#define ZD_CR177 CTL_REG(0x02C4)
25462306a36Sopenharmony_ci#define ZD_CR178 CTL_REG(0x02C8)
25562306a36Sopenharmony_ci#define ZD_CR179 CTL_REG(0x02CC)
25662306a36Sopenharmony_ci#define ZD_CR180 CTL_REG(0x02D0)
25762306a36Sopenharmony_ci#define ZD_CR181 CTL_REG(0x02D4)
25862306a36Sopenharmony_ci#define ZD_CR182 CTL_REG(0x02D8)
25962306a36Sopenharmony_ci#define ZD_CR183 CTL_REG(0x02DC)
26062306a36Sopenharmony_ci#define ZD_CR184 CTL_REG(0x02E0)
26162306a36Sopenharmony_ci#define ZD_CR185 CTL_REG(0x02E4)
26262306a36Sopenharmony_ci#define ZD_CR186 CTL_REG(0x02E8)
26362306a36Sopenharmony_ci#define ZD_CR187 CTL_REG(0x02EC)
26462306a36Sopenharmony_ci#define ZD_CR188 CTL_REG(0x02F0)
26562306a36Sopenharmony_ci#define ZD_CR189 CTL_REG(0x02F4)
26662306a36Sopenharmony_ci#define ZD_CR190 CTL_REG(0x02F8)
26762306a36Sopenharmony_ci#define ZD_CR191 CTL_REG(0x02FC)
26862306a36Sopenharmony_ci#define ZD_CR192 CTL_REG(0x0300)
26962306a36Sopenharmony_ci#define ZD_CR193 CTL_REG(0x0304)
27062306a36Sopenharmony_ci#define ZD_CR194 CTL_REG(0x0308)
27162306a36Sopenharmony_ci#define ZD_CR195 CTL_REG(0x030C)
27262306a36Sopenharmony_ci#define ZD_CR196 CTL_REG(0x0310)
27362306a36Sopenharmony_ci#define ZD_CR197 CTL_REG(0x0314)
27462306a36Sopenharmony_ci#define ZD_CR198 CTL_REG(0x0318)
27562306a36Sopenharmony_ci#define ZD_CR199 CTL_REG(0x031C)
27662306a36Sopenharmony_ci#define ZD_CR200 CTL_REG(0x0320)
27762306a36Sopenharmony_ci#define ZD_CR201 CTL_REG(0x0324)
27862306a36Sopenharmony_ci#define ZD_CR202 CTL_REG(0x0328)
27962306a36Sopenharmony_ci#define ZD_CR203 CTL_REG(0x032C)	/* I2C bus template value & flash
28062306a36Sopenharmony_ci					 * control
28162306a36Sopenharmony_ci					 */
28262306a36Sopenharmony_ci#define ZD_CR204 CTL_REG(0x0330)
28362306a36Sopenharmony_ci#define ZD_CR205 CTL_REG(0x0334)
28462306a36Sopenharmony_ci#define ZD_CR206 CTL_REG(0x0338)
28562306a36Sopenharmony_ci#define ZD_CR207 CTL_REG(0x033C)
28662306a36Sopenharmony_ci#define ZD_CR208 CTL_REG(0x0340)
28762306a36Sopenharmony_ci#define ZD_CR209 CTL_REG(0x0344)
28862306a36Sopenharmony_ci#define ZD_CR210 CTL_REG(0x0348)
28962306a36Sopenharmony_ci#define ZD_CR211 CTL_REG(0x034C)
29062306a36Sopenharmony_ci#define ZD_CR212 CTL_REG(0x0350)
29162306a36Sopenharmony_ci#define ZD_CR213 CTL_REG(0x0354)
29262306a36Sopenharmony_ci#define ZD_CR214 CTL_REG(0x0358)
29362306a36Sopenharmony_ci#define ZD_CR215 CTL_REG(0x035C)
29462306a36Sopenharmony_ci#define ZD_CR216 CTL_REG(0x0360)
29562306a36Sopenharmony_ci#define ZD_CR217 CTL_REG(0x0364)
29662306a36Sopenharmony_ci#define ZD_CR218 CTL_REG(0x0368)
29762306a36Sopenharmony_ci#define ZD_CR219 CTL_REG(0x036C)
29862306a36Sopenharmony_ci#define ZD_CR220 CTL_REG(0x0370)
29962306a36Sopenharmony_ci#define ZD_CR221 CTL_REG(0x0374)
30062306a36Sopenharmony_ci#define ZD_CR222 CTL_REG(0x0378)
30162306a36Sopenharmony_ci#define ZD_CR223 CTL_REG(0x037C)
30262306a36Sopenharmony_ci#define ZD_CR224 CTL_REG(0x0380)
30362306a36Sopenharmony_ci#define ZD_CR225 CTL_REG(0x0384)
30462306a36Sopenharmony_ci#define ZD_CR226 CTL_REG(0x0388)
30562306a36Sopenharmony_ci#define ZD_CR227 CTL_REG(0x038C)
30662306a36Sopenharmony_ci#define ZD_CR228 CTL_REG(0x0390)
30762306a36Sopenharmony_ci#define ZD_CR229 CTL_REG(0x0394)
30862306a36Sopenharmony_ci#define ZD_CR230 CTL_REG(0x0398)
30962306a36Sopenharmony_ci#define ZD_CR231 CTL_REG(0x039C)
31062306a36Sopenharmony_ci#define ZD_CR232 CTL_REG(0x03A0)
31162306a36Sopenharmony_ci#define ZD_CR233 CTL_REG(0x03A4)
31262306a36Sopenharmony_ci#define ZD_CR234 CTL_REG(0x03A8)
31362306a36Sopenharmony_ci#define ZD_CR235 CTL_REG(0x03AC)
31462306a36Sopenharmony_ci#define ZD_CR236 CTL_REG(0x03B0)
31562306a36Sopenharmony_ci
31662306a36Sopenharmony_ci#define ZD_CR240 CTL_REG(0x03C0)
31762306a36Sopenharmony_ci/*             bit 7: host-controlled RF register writes
31862306a36Sopenharmony_ci * ZD_CR241-ZD_CR245: for hardware controlled writing of RF bits, not needed for
31962306a36Sopenharmony_ci *                    USB
32062306a36Sopenharmony_ci */
32162306a36Sopenharmony_ci#define ZD_CR241 CTL_REG(0x03C4)
32262306a36Sopenharmony_ci#define ZD_CR242 CTL_REG(0x03C8)
32362306a36Sopenharmony_ci#define ZD_CR243 CTL_REG(0x03CC)
32462306a36Sopenharmony_ci#define ZD_CR244 CTL_REG(0x03D0)
32562306a36Sopenharmony_ci#define ZD_CR245 CTL_REG(0x03D4)
32662306a36Sopenharmony_ci
32762306a36Sopenharmony_ci#define ZD_CR251 CTL_REG(0x03EC)	/* only used for activation and
32862306a36Sopenharmony_ci					 * deactivation of Airoha RFs AL2230
32962306a36Sopenharmony_ci					 * and AL7230B
33062306a36Sopenharmony_ci					 */
33162306a36Sopenharmony_ci#define ZD_CR252 CTL_REG(0x03F0)
33262306a36Sopenharmony_ci#define ZD_CR253 CTL_REG(0x03F4)
33362306a36Sopenharmony_ci#define ZD_CR254 CTL_REG(0x03F8)
33462306a36Sopenharmony_ci#define ZD_CR255 CTL_REG(0x03FC)
33562306a36Sopenharmony_ci
33662306a36Sopenharmony_ci#define CR_MAX_PHY_REG 255
33762306a36Sopenharmony_ci
33862306a36Sopenharmony_ci/* Taken from the ZYDAS driver, not all of them are relevant for the ZD1211
33962306a36Sopenharmony_ci * driver.
34062306a36Sopenharmony_ci */
34162306a36Sopenharmony_ci
34262306a36Sopenharmony_ci#define CR_RF_IF_CLK			CTL_REG(0x0400)
34362306a36Sopenharmony_ci#define CR_RF_IF_DATA			CTL_REG(0x0404)
34462306a36Sopenharmony_ci#define CR_PE1_PE2			CTL_REG(0x0408)
34562306a36Sopenharmony_ci#define CR_PE2_DLY			CTL_REG(0x040C)
34662306a36Sopenharmony_ci#define CR_LE1				CTL_REG(0x0410)
34762306a36Sopenharmony_ci#define CR_LE2				CTL_REG(0x0414)
34862306a36Sopenharmony_ci/* Seems to enable/disable GPI (General Purpose IO?) */
34962306a36Sopenharmony_ci#define CR_GPI_EN			CTL_REG(0x0418)
35062306a36Sopenharmony_ci#define CR_RADIO_PD			CTL_REG(0x042C)
35162306a36Sopenharmony_ci#define CR_RF2948_PD			CTL_REG(0x042C)
35262306a36Sopenharmony_ci#define CR_ENABLE_PS_MANUAL_AGC		CTL_REG(0x043C)
35362306a36Sopenharmony_ci#define CR_CONFIG_PHILIPS		CTL_REG(0x0440)
35462306a36Sopenharmony_ci#define CR_SA2400_SER_AP		CTL_REG(0x0444)
35562306a36Sopenharmony_ci#define CR_I2C_WRITE			CTL_REG(0x0444)
35662306a36Sopenharmony_ci#define CR_SA2400_SER_RP		CTL_REG(0x0448)
35762306a36Sopenharmony_ci#define CR_RADIO_PE			CTL_REG(0x0458)
35862306a36Sopenharmony_ci#define CR_RST_BUS_MASTER		CTL_REG(0x045C)
35962306a36Sopenharmony_ci#define CR_RFCFG			CTL_REG(0x0464)
36062306a36Sopenharmony_ci#define CR_HSTSCHG			CTL_REG(0x046C)
36162306a36Sopenharmony_ci#define CR_PHY_ON			CTL_REG(0x0474)
36262306a36Sopenharmony_ci#define CR_RX_DELAY			CTL_REG(0x0478)
36362306a36Sopenharmony_ci#define CR_RX_PE_DELAY			CTL_REG(0x047C)
36462306a36Sopenharmony_ci#define CR_GPIO_1			CTL_REG(0x0490)
36562306a36Sopenharmony_ci#define CR_GPIO_2			CTL_REG(0x0494)
36662306a36Sopenharmony_ci#define CR_EncryBufMux			CTL_REG(0x04A8)
36762306a36Sopenharmony_ci#define CR_PS_CTRL			CTL_REG(0x0500)
36862306a36Sopenharmony_ci#define CR_ADDA_PWR_DWN			CTL_REG(0x0504)
36962306a36Sopenharmony_ci#define CR_ADDA_MBIAS_WARMTIME		CTL_REG(0x0508)
37062306a36Sopenharmony_ci#define CR_MAC_PS_STATE			CTL_REG(0x050C)
37162306a36Sopenharmony_ci
37262306a36Sopenharmony_ci#define CR_INTERRUPT			CTL_REG(0x0510)
37362306a36Sopenharmony_ci#define INT_TX_COMPLETE			(1 <<  0)
37462306a36Sopenharmony_ci#define INT_RX_COMPLETE			(1 <<  1)
37562306a36Sopenharmony_ci#define INT_RETRY_FAIL			(1 <<  2)
37662306a36Sopenharmony_ci#define INT_WAKEUP			(1 <<  3)
37762306a36Sopenharmony_ci#define INT_DTIM_NOTIFY			(1 <<  5)
37862306a36Sopenharmony_ci#define INT_CFG_NEXT_BCN		(1 <<  6)
37962306a36Sopenharmony_ci#define INT_BUS_ABORT			(1 <<  7)
38062306a36Sopenharmony_ci#define INT_TX_FIFO_READY		(1 <<  8)
38162306a36Sopenharmony_ci#define INT_UART			(1 <<  9)
38262306a36Sopenharmony_ci#define INT_TX_COMPLETE_EN		(1 << 16)
38362306a36Sopenharmony_ci#define INT_RX_COMPLETE_EN		(1 << 17)
38462306a36Sopenharmony_ci#define INT_RETRY_FAIL_EN		(1 << 18)
38562306a36Sopenharmony_ci#define INT_WAKEUP_EN			(1 << 19)
38662306a36Sopenharmony_ci#define INT_DTIM_NOTIFY_EN		(1 << 21)
38762306a36Sopenharmony_ci#define INT_CFG_NEXT_BCN_EN		(1 << 22)
38862306a36Sopenharmony_ci#define INT_BUS_ABORT_EN		(1 << 23)
38962306a36Sopenharmony_ci#define INT_TX_FIFO_READY_EN		(1 << 24)
39062306a36Sopenharmony_ci#define INT_UART_EN			(1 << 25)
39162306a36Sopenharmony_ci
39262306a36Sopenharmony_ci#define CR_TSF_LOW_PART			CTL_REG(0x0514)
39362306a36Sopenharmony_ci#define CR_TSF_HIGH_PART		CTL_REG(0x0518)
39462306a36Sopenharmony_ci
39562306a36Sopenharmony_ci/* Following three values are in time units (1024us)
39662306a36Sopenharmony_ci * Following condition must be met:
39762306a36Sopenharmony_ci * atim < tbtt < bcn
39862306a36Sopenharmony_ci */
39962306a36Sopenharmony_ci#define CR_ATIM_WND_PERIOD		CTL_REG(0x051C)
40062306a36Sopenharmony_ci#define CR_BCN_INTERVAL			CTL_REG(0x0520)
40162306a36Sopenharmony_ci#define CR_PRE_TBTT			CTL_REG(0x0524)
40262306a36Sopenharmony_ci/* in units of TU(1024us) */
40362306a36Sopenharmony_ci
40462306a36Sopenharmony_ci/* for UART support */
40562306a36Sopenharmony_ci#define CR_UART_RBR_THR_DLL		CTL_REG(0x0540)
40662306a36Sopenharmony_ci#define CR_UART_DLM_IER			CTL_REG(0x0544)
40762306a36Sopenharmony_ci#define CR_UART_IIR_FCR			CTL_REG(0x0548)
40862306a36Sopenharmony_ci#define CR_UART_LCR			CTL_REG(0x054c)
40962306a36Sopenharmony_ci#define CR_UART_MCR			CTL_REG(0x0550)
41062306a36Sopenharmony_ci#define CR_UART_LSR			CTL_REG(0x0554)
41162306a36Sopenharmony_ci#define CR_UART_MSR			CTL_REG(0x0558)
41262306a36Sopenharmony_ci#define CR_UART_ECR			CTL_REG(0x055c)
41362306a36Sopenharmony_ci#define CR_UART_STATUS			CTL_REG(0x0560)
41462306a36Sopenharmony_ci
41562306a36Sopenharmony_ci#define CR_PCI_TX_ADDR_P1		CTL_REG(0x0600)
41662306a36Sopenharmony_ci#define CR_PCI_TX_AddR_P2		CTL_REG(0x0604)
41762306a36Sopenharmony_ci#define CR_PCI_RX_AddR_P1		CTL_REG(0x0608)
41862306a36Sopenharmony_ci#define CR_PCI_RX_AddR_P2		CTL_REG(0x060C)
41962306a36Sopenharmony_ci
42062306a36Sopenharmony_ci/* must be overwritten if custom MAC address will be used */
42162306a36Sopenharmony_ci#define CR_MAC_ADDR_P1			CTL_REG(0x0610)
42262306a36Sopenharmony_ci#define CR_MAC_ADDR_P2			CTL_REG(0x0614)
42362306a36Sopenharmony_ci#define CR_BSSID_P1			CTL_REG(0x0618)
42462306a36Sopenharmony_ci#define CR_BSSID_P2			CTL_REG(0x061C)
42562306a36Sopenharmony_ci#define CR_BCN_PLCP_CFG			CTL_REG(0x0620)
42662306a36Sopenharmony_ci
42762306a36Sopenharmony_ci/* Group hash table for filtering incoming packets.
42862306a36Sopenharmony_ci *
42962306a36Sopenharmony_ci * The group hash table is 64 bit large and split over two parts. The first
43062306a36Sopenharmony_ci * part is the lower part. The upper 6 bits of the last byte of the target
43162306a36Sopenharmony_ci * address are used as index. Packets are received if the hash table bit is
43262306a36Sopenharmony_ci * set. This is used for multicast handling, but for broadcasts (address
43362306a36Sopenharmony_ci * ff:ff:ff:ff:ff:ff) the highest bit in the second table must also be set.
43462306a36Sopenharmony_ci */
43562306a36Sopenharmony_ci#define CR_GROUP_HASH_P1		CTL_REG(0x0624)
43662306a36Sopenharmony_ci#define CR_GROUP_HASH_P2		CTL_REG(0x0628)
43762306a36Sopenharmony_ci
43862306a36Sopenharmony_ci#define CR_RX_TIMEOUT			CTL_REG(0x062C)
43962306a36Sopenharmony_ci
44062306a36Sopenharmony_ci/* Basic rates supported by the BSS. When producing ACK or CTS messages, the
44162306a36Sopenharmony_ci * device will use a rate in this table that is less than or equal to the rate
44262306a36Sopenharmony_ci * of the incoming frame which prompted the response. */
44362306a36Sopenharmony_ci#define CR_BASIC_RATE_TBL		CTL_REG(0x0630)
44462306a36Sopenharmony_ci#define CR_RATE_1M	(1 <<  0)	/* 802.11b */
44562306a36Sopenharmony_ci#define CR_RATE_2M	(1 <<  1)	/* 802.11b */
44662306a36Sopenharmony_ci#define CR_RATE_5_5M	(1 <<  2)	/* 802.11b */
44762306a36Sopenharmony_ci#define CR_RATE_11M	(1 <<  3)	/* 802.11b */
44862306a36Sopenharmony_ci#define CR_RATE_6M      (1 <<  8)	/* 802.11g */
44962306a36Sopenharmony_ci#define CR_RATE_9M      (1 <<  9)	/* 802.11g */
45062306a36Sopenharmony_ci#define CR_RATE_12M	(1 << 10)	/* 802.11g */
45162306a36Sopenharmony_ci#define CR_RATE_18M	(1 << 11)	/* 802.11g */
45262306a36Sopenharmony_ci#define CR_RATE_24M     (1 << 12)	/* 802.11g */
45362306a36Sopenharmony_ci#define CR_RATE_36M     (1 << 13)	/* 802.11g */
45462306a36Sopenharmony_ci#define CR_RATE_48M     (1 << 14)	/* 802.11g */
45562306a36Sopenharmony_ci#define CR_RATE_54M     (1 << 15)	/* 802.11g */
45662306a36Sopenharmony_ci#define CR_RATES_80211G	0xff00
45762306a36Sopenharmony_ci#define CR_RATES_80211B	0x000f
45862306a36Sopenharmony_ci
45962306a36Sopenharmony_ci/* Mandatory rates required in the BSS. When producing ACK or CTS messages, if
46062306a36Sopenharmony_ci * the device could not find an appropriate rate in CR_BASIC_RATE_TBL, it will
46162306a36Sopenharmony_ci * look for a rate in this table that is less than or equal to the rate of
46262306a36Sopenharmony_ci * the incoming frame. */
46362306a36Sopenharmony_ci#define CR_MANDATORY_RATE_TBL		CTL_REG(0x0634)
46462306a36Sopenharmony_ci#define CR_RTS_CTS_RATE			CTL_REG(0x0638)
46562306a36Sopenharmony_ci
46662306a36Sopenharmony_ci/* These are all bit indexes in CR_RTS_CTS_RATE, so remember to shift. */
46762306a36Sopenharmony_ci#define RTSCTS_SH_RTS_RATE		0
46862306a36Sopenharmony_ci#define RTSCTS_SH_EXP_CTS_RATE		4
46962306a36Sopenharmony_ci#define RTSCTS_SH_RTS_MOD_TYPE		8
47062306a36Sopenharmony_ci#define RTSCTS_SH_RTS_PMB_TYPE		9
47162306a36Sopenharmony_ci#define RTSCTS_SH_CTS_RATE		16
47262306a36Sopenharmony_ci#define RTSCTS_SH_CTS_MOD_TYPE		24
47362306a36Sopenharmony_ci#define RTSCTS_SH_CTS_PMB_TYPE		25
47462306a36Sopenharmony_ci
47562306a36Sopenharmony_ci#define CR_WEP_PROTECT			CTL_REG(0x063C)
47662306a36Sopenharmony_ci#define CR_RX_THRESHOLD			CTL_REG(0x0640)
47762306a36Sopenharmony_ci
47862306a36Sopenharmony_ci/* register for controlling the LEDS */
47962306a36Sopenharmony_ci#define CR_LED				CTL_REG(0x0644)
48062306a36Sopenharmony_ci/* masks for controlling LEDs */
48162306a36Sopenharmony_ci#define LED1				(1 <<  8)
48262306a36Sopenharmony_ci#define LED2				(1 <<  9)
48362306a36Sopenharmony_ci#define LED_SW				(1 << 10)
48462306a36Sopenharmony_ci
48562306a36Sopenharmony_ci/* Seems to indicate that the configuration is over.
48662306a36Sopenharmony_ci */
48762306a36Sopenharmony_ci#define CR_AFTER_PNP			CTL_REG(0x0648)
48862306a36Sopenharmony_ci#define CR_ACK_TIME_80211		CTL_REG(0x0658)
48962306a36Sopenharmony_ci
49062306a36Sopenharmony_ci#define CR_RX_OFFSET			CTL_REG(0x065c)
49162306a36Sopenharmony_ci
49262306a36Sopenharmony_ci#define CR_BCN_LENGTH			CTL_REG(0x0664)
49362306a36Sopenharmony_ci#define CR_PHY_DELAY			CTL_REG(0x066C)
49462306a36Sopenharmony_ci#define CR_BCN_FIFO			CTL_REG(0x0670)
49562306a36Sopenharmony_ci#define CR_SNIFFER_ON			CTL_REG(0x0674)
49662306a36Sopenharmony_ci
49762306a36Sopenharmony_ci#define CR_ENCRYPTION_TYPE		CTL_REG(0x0678)
49862306a36Sopenharmony_ci#define NO_WEP				0
49962306a36Sopenharmony_ci#define WEP64				1
50062306a36Sopenharmony_ci#define WEP128				5
50162306a36Sopenharmony_ci#define WEP256				6
50262306a36Sopenharmony_ci#define ENC_SNIFFER			8
50362306a36Sopenharmony_ci
50462306a36Sopenharmony_ci#define CR_ZD1211_RETRY_MAX		CTL_REG(0x067C)
50562306a36Sopenharmony_ci
50662306a36Sopenharmony_ci#define CR_REG1				CTL_REG(0x0680)
50762306a36Sopenharmony_ci/* Setting the bit UNLOCK_PHY_REGS disallows the write access to physical
50862306a36Sopenharmony_ci * registers, so one could argue it is a LOCK bit. But calling it
50962306a36Sopenharmony_ci * LOCK_PHY_REGS makes it confusing.
51062306a36Sopenharmony_ci */
51162306a36Sopenharmony_ci#define UNLOCK_PHY_REGS			(1 << 7)
51262306a36Sopenharmony_ci
51362306a36Sopenharmony_ci#define CR_DEVICE_STATE			CTL_REG(0x0684)
51462306a36Sopenharmony_ci#define CR_UNDERRUN_CNT			CTL_REG(0x0688)
51562306a36Sopenharmony_ci
51662306a36Sopenharmony_ci#define CR_RX_FILTER			CTL_REG(0x068c)
51762306a36Sopenharmony_ci#define RX_FILTER_ASSOC_REQUEST		(1 <<  0)
51862306a36Sopenharmony_ci#define RX_FILTER_ASSOC_RESPONSE	(1 <<  1)
51962306a36Sopenharmony_ci#define RX_FILTER_REASSOC_REQUEST	(1 <<  2)
52062306a36Sopenharmony_ci#define RX_FILTER_REASSOC_RESPONSE	(1 <<  3)
52162306a36Sopenharmony_ci#define RX_FILTER_PROBE_REQUEST		(1 <<  4)
52262306a36Sopenharmony_ci#define RX_FILTER_PROBE_RESPONSE	(1 <<  5)
52362306a36Sopenharmony_ci/* bits 6 and 7 reserved */
52462306a36Sopenharmony_ci#define RX_FILTER_BEACON		(1 <<  8)
52562306a36Sopenharmony_ci#define RX_FILTER_ATIM			(1 <<  9)
52662306a36Sopenharmony_ci#define RX_FILTER_DISASSOC		(1 << 10)
52762306a36Sopenharmony_ci#define RX_FILTER_AUTH			(1 << 11)
52862306a36Sopenharmony_ci#define RX_FILTER_DEAUTH		(1 << 12)
52962306a36Sopenharmony_ci#define RX_FILTER_PSPOLL		(1 << 26)
53062306a36Sopenharmony_ci#define RX_FILTER_RTS			(1 << 27)
53162306a36Sopenharmony_ci#define RX_FILTER_CTS			(1 << 28)
53262306a36Sopenharmony_ci#define RX_FILTER_ACK			(1 << 29)
53362306a36Sopenharmony_ci#define RX_FILTER_CFEND			(1 << 30)
53462306a36Sopenharmony_ci#define RX_FILTER_CFACK			(1 << 31)
53562306a36Sopenharmony_ci
53662306a36Sopenharmony_ci/* Enable bits for all frames you are interested in. */
53762306a36Sopenharmony_ci#define STA_RX_FILTER	(RX_FILTER_ASSOC_REQUEST | RX_FILTER_ASSOC_RESPONSE | \
53862306a36Sopenharmony_ci	RX_FILTER_REASSOC_REQUEST | RX_FILTER_REASSOC_RESPONSE | \
53962306a36Sopenharmony_ci	RX_FILTER_PROBE_REQUEST | RX_FILTER_PROBE_RESPONSE | \
54062306a36Sopenharmony_ci	(0x3 << 6) /* vendor driver sets these reserved bits */ | \
54162306a36Sopenharmony_ci	RX_FILTER_BEACON | RX_FILTER_ATIM | RX_FILTER_DISASSOC | \
54262306a36Sopenharmony_ci	RX_FILTER_AUTH | RX_FILTER_DEAUTH | \
54362306a36Sopenharmony_ci	(0x7 << 13) /* vendor driver sets these reserved bits */ | \
54462306a36Sopenharmony_ci	RX_FILTER_PSPOLL | RX_FILTER_ACK) /* 0x2400ffff */
54562306a36Sopenharmony_ci
54662306a36Sopenharmony_ci#define RX_FILTER_CTRL (RX_FILTER_RTS | RX_FILTER_CTS | \
54762306a36Sopenharmony_ci	RX_FILTER_CFEND | RX_FILTER_CFACK)
54862306a36Sopenharmony_ci
54962306a36Sopenharmony_ci#define BCN_MODE_AP			0x1000000
55062306a36Sopenharmony_ci#define BCN_MODE_IBSS			0x2000000
55162306a36Sopenharmony_ci
55262306a36Sopenharmony_ci/* Monitor mode sets filter to 0xfffff */
55362306a36Sopenharmony_ci
55462306a36Sopenharmony_ci#define CR_ACK_TIMEOUT_EXT		CTL_REG(0x0690)
55562306a36Sopenharmony_ci#define CR_BCN_FIFO_SEMAPHORE		CTL_REG(0x0694)
55662306a36Sopenharmony_ci
55762306a36Sopenharmony_ci#define CR_IFS_VALUE			CTL_REG(0x0698)
55862306a36Sopenharmony_ci#define IFS_VALUE_DIFS_SH		0
55962306a36Sopenharmony_ci#define IFS_VALUE_EIFS_SH		12
56062306a36Sopenharmony_ci#define IFS_VALUE_SIFS_SH		24
56162306a36Sopenharmony_ci#define IFS_VALUE_DEFAULT		((  50 << IFS_VALUE_DIFS_SH) | \
56262306a36Sopenharmony_ci					 (1148 << IFS_VALUE_EIFS_SH) | \
56362306a36Sopenharmony_ci					 (  10 << IFS_VALUE_SIFS_SH))
56462306a36Sopenharmony_ci
56562306a36Sopenharmony_ci#define CR_RX_TIME_OUT			CTL_REG(0x069C)
56662306a36Sopenharmony_ci#define CR_TOTAL_RX_FRM			CTL_REG(0x06A0)
56762306a36Sopenharmony_ci#define CR_CRC32_CNT			CTL_REG(0x06A4)
56862306a36Sopenharmony_ci#define CR_CRC16_CNT			CTL_REG(0x06A8)
56962306a36Sopenharmony_ci#define CR_DECRYPTION_ERR_UNI		CTL_REG(0x06AC)
57062306a36Sopenharmony_ci#define CR_RX_FIFO_OVERRUN		CTL_REG(0x06B0)
57162306a36Sopenharmony_ci
57262306a36Sopenharmony_ci#define CR_DECRYPTION_ERR_MUL		CTL_REG(0x06BC)
57362306a36Sopenharmony_ci
57462306a36Sopenharmony_ci#define CR_NAV_CNT			CTL_REG(0x06C4)
57562306a36Sopenharmony_ci#define CR_NAV_CCA			CTL_REG(0x06C8)
57662306a36Sopenharmony_ci#define CR_RETRY_CNT			CTL_REG(0x06CC)
57762306a36Sopenharmony_ci
57862306a36Sopenharmony_ci#define CR_READ_TCB_ADDR		CTL_REG(0x06E8)
57962306a36Sopenharmony_ci#define CR_READ_RFD_ADDR		CTL_REG(0x06EC)
58062306a36Sopenharmony_ci#define CR_CWMIN_CWMAX			CTL_REG(0x06F0)
58162306a36Sopenharmony_ci#define CR_TOTAL_TX_FRM			CTL_REG(0x06F4)
58262306a36Sopenharmony_ci
58362306a36Sopenharmony_ci/* CAM: Continuous Access Mode (power management) */
58462306a36Sopenharmony_ci#define CR_CAM_MODE			CTL_REG(0x0700)
58562306a36Sopenharmony_ci#define MODE_IBSS			0x0
58662306a36Sopenharmony_ci#define MODE_AP				0x1
58762306a36Sopenharmony_ci#define MODE_STA			0x2
58862306a36Sopenharmony_ci#define MODE_AP_WDS			0x3
58962306a36Sopenharmony_ci
59062306a36Sopenharmony_ci#define CR_CAM_ROLL_TB_LOW		CTL_REG(0x0704)
59162306a36Sopenharmony_ci#define CR_CAM_ROLL_TB_HIGH		CTL_REG(0x0708)
59262306a36Sopenharmony_ci#define CR_CAM_ADDRESS			CTL_REG(0x070C)
59362306a36Sopenharmony_ci#define CR_CAM_DATA			CTL_REG(0x0710)
59462306a36Sopenharmony_ci
59562306a36Sopenharmony_ci#define CR_ROMDIR			CTL_REG(0x0714)
59662306a36Sopenharmony_ci
59762306a36Sopenharmony_ci#define CR_DECRY_ERR_FLG_LOW		CTL_REG(0x0714)
59862306a36Sopenharmony_ci#define CR_DECRY_ERR_FLG_HIGH		CTL_REG(0x0718)
59962306a36Sopenharmony_ci
60062306a36Sopenharmony_ci#define CR_WEPKEY0			CTL_REG(0x0720)
60162306a36Sopenharmony_ci#define CR_WEPKEY1			CTL_REG(0x0724)
60262306a36Sopenharmony_ci#define CR_WEPKEY2			CTL_REG(0x0728)
60362306a36Sopenharmony_ci#define CR_WEPKEY3			CTL_REG(0x072C)
60462306a36Sopenharmony_ci#define CR_WEPKEY4			CTL_REG(0x0730)
60562306a36Sopenharmony_ci#define CR_WEPKEY5			CTL_REG(0x0734)
60662306a36Sopenharmony_ci#define CR_WEPKEY6			CTL_REG(0x0738)
60762306a36Sopenharmony_ci#define CR_WEPKEY7			CTL_REG(0x073C)
60862306a36Sopenharmony_ci#define CR_WEPKEY8			CTL_REG(0x0740)
60962306a36Sopenharmony_ci#define CR_WEPKEY9			CTL_REG(0x0744)
61062306a36Sopenharmony_ci#define CR_WEPKEY10			CTL_REG(0x0748)
61162306a36Sopenharmony_ci#define CR_WEPKEY11			CTL_REG(0x074C)
61262306a36Sopenharmony_ci#define CR_WEPKEY12			CTL_REG(0x0750)
61362306a36Sopenharmony_ci#define CR_WEPKEY13			CTL_REG(0x0754)
61462306a36Sopenharmony_ci#define CR_WEPKEY14			CTL_REG(0x0758)
61562306a36Sopenharmony_ci#define CR_WEPKEY15			CTL_REG(0x075c)
61662306a36Sopenharmony_ci#define CR_TKIP_MODE			CTL_REG(0x0760)
61762306a36Sopenharmony_ci
61862306a36Sopenharmony_ci#define CR_EEPROM_PROTECT0		CTL_REG(0x0758)
61962306a36Sopenharmony_ci#define CR_EEPROM_PROTECT1		CTL_REG(0x075C)
62062306a36Sopenharmony_ci
62162306a36Sopenharmony_ci#define CR_DBG_FIFO_RD			CTL_REG(0x0800)
62262306a36Sopenharmony_ci#define CR_DBG_SELECT			CTL_REG(0x0804)
62362306a36Sopenharmony_ci#define CR_FIFO_Length			CTL_REG(0x0808)
62462306a36Sopenharmony_ci
62562306a36Sopenharmony_ci
62662306a36Sopenharmony_ci#define CR_RSSI_MGC			CTL_REG(0x0810)
62762306a36Sopenharmony_ci
62862306a36Sopenharmony_ci#define CR_PON				CTL_REG(0x0818)
62962306a36Sopenharmony_ci#define CR_RX_ON			CTL_REG(0x081C)
63062306a36Sopenharmony_ci#define CR_TX_ON			CTL_REG(0x0820)
63162306a36Sopenharmony_ci#define CR_CHIP_EN			CTL_REG(0x0824)
63262306a36Sopenharmony_ci#define CR_LO_SW			CTL_REG(0x0828)
63362306a36Sopenharmony_ci#define CR_TXRX_SW			CTL_REG(0x082C)
63462306a36Sopenharmony_ci#define CR_S_MD				CTL_REG(0x0830)
63562306a36Sopenharmony_ci
63662306a36Sopenharmony_ci#define CR_USB_DEBUG_PORT		CTL_REG(0x0888)
63762306a36Sopenharmony_ci#define CR_ZD1211B_CWIN_MAX_MIN_AC0	CTL_REG(0x0b00)
63862306a36Sopenharmony_ci#define CR_ZD1211B_CWIN_MAX_MIN_AC1	CTL_REG(0x0b04)
63962306a36Sopenharmony_ci#define CR_ZD1211B_CWIN_MAX_MIN_AC2	CTL_REG(0x0b08)
64062306a36Sopenharmony_ci#define CR_ZD1211B_CWIN_MAX_MIN_AC3	CTL_REG(0x0b0c)
64162306a36Sopenharmony_ci#define CR_ZD1211B_AIFS_CTL1		CTL_REG(0x0b10)
64262306a36Sopenharmony_ci#define CR_ZD1211B_AIFS_CTL2		CTL_REG(0x0b14)
64362306a36Sopenharmony_ci#define CR_ZD1211B_TXOP			CTL_REG(0x0b20)
64462306a36Sopenharmony_ci#define CR_ZD1211B_RETRY_MAX		CTL_REG(0x0b28)
64562306a36Sopenharmony_ci
64662306a36Sopenharmony_ci/* Value for CR_ZD1211_RETRY_MAX & CR_ZD1211B_RETRY_MAX. Vendor driver uses 2,
64762306a36Sopenharmony_ci * we use 0. The first rate is tried (count+2), then all next rates are tried
64862306a36Sopenharmony_ci * twice, until 1 Mbits is tried. */
64962306a36Sopenharmony_ci#define	ZD1211_RETRY_COUNT		0
65062306a36Sopenharmony_ci#define	ZD1211B_RETRY_COUNT	\
65162306a36Sopenharmony_ci	(ZD1211_RETRY_COUNT <<  0)|	\
65262306a36Sopenharmony_ci	(ZD1211_RETRY_COUNT <<  8)|	\
65362306a36Sopenharmony_ci	(ZD1211_RETRY_COUNT << 16)|	\
65462306a36Sopenharmony_ci	(ZD1211_RETRY_COUNT << 24)
65562306a36Sopenharmony_ci
65662306a36Sopenharmony_ci/* Used to detect PLL lock */
65762306a36Sopenharmony_ci#define UW2453_INTR_REG			((zd_addr_t)0x85c1)
65862306a36Sopenharmony_ci
65962306a36Sopenharmony_ci#define CWIN_SIZE			0x007f043f
66062306a36Sopenharmony_ci
66162306a36Sopenharmony_ci
66262306a36Sopenharmony_ci#define HWINT_ENABLED			\
66362306a36Sopenharmony_ci	(INT_TX_COMPLETE_EN|		\
66462306a36Sopenharmony_ci	 INT_RX_COMPLETE_EN|		\
66562306a36Sopenharmony_ci	 INT_RETRY_FAIL_EN|		\
66662306a36Sopenharmony_ci	 INT_WAKEUP_EN|			\
66762306a36Sopenharmony_ci	 INT_CFG_NEXT_BCN_EN)
66862306a36Sopenharmony_ci
66962306a36Sopenharmony_ci#define HWINT_DISABLED			0
67062306a36Sopenharmony_ci
67162306a36Sopenharmony_ci#define E2P_PWR_INT_GUARD		8
67262306a36Sopenharmony_ci#define E2P_CHANNEL_COUNT		14
67362306a36Sopenharmony_ci
67462306a36Sopenharmony_ci/* If you compare this addresses with the ZYDAS orignal driver, please notify
67562306a36Sopenharmony_ci * that we use word mapping for the EEPROM.
67662306a36Sopenharmony_ci */
67762306a36Sopenharmony_ci
67862306a36Sopenharmony_ci/*
67962306a36Sopenharmony_ci * Upper 16 bit contains the regulatory domain.
68062306a36Sopenharmony_ci */
68162306a36Sopenharmony_ci#define E2P_SUBID		E2P_DATA(0x00)
68262306a36Sopenharmony_ci#define E2P_POD			E2P_DATA(0x02)
68362306a36Sopenharmony_ci#define E2P_MAC_ADDR_P1		E2P_DATA(0x04)
68462306a36Sopenharmony_ci#define E2P_MAC_ADDR_P2		E2P_DATA(0x06)
68562306a36Sopenharmony_ci#define E2P_PWR_CAL_VALUE1	E2P_DATA(0x08)
68662306a36Sopenharmony_ci#define E2P_PWR_CAL_VALUE2	E2P_DATA(0x0a)
68762306a36Sopenharmony_ci#define E2P_PWR_CAL_VALUE3	E2P_DATA(0x0c)
68862306a36Sopenharmony_ci#define E2P_PWR_CAL_VALUE4      E2P_DATA(0x0e)
68962306a36Sopenharmony_ci#define E2P_PWR_INT_VALUE1	E2P_DATA(0x10)
69062306a36Sopenharmony_ci#define E2P_PWR_INT_VALUE2	E2P_DATA(0x12)
69162306a36Sopenharmony_ci#define E2P_PWR_INT_VALUE3	E2P_DATA(0x14)
69262306a36Sopenharmony_ci#define E2P_PWR_INT_VALUE4	E2P_DATA(0x16)
69362306a36Sopenharmony_ci
69462306a36Sopenharmony_ci/* Contains a bit for each allowed channel. It gives for Europe (ETSI 0x30)
69562306a36Sopenharmony_ci * also only 11 channels. */
69662306a36Sopenharmony_ci#define E2P_ALLOWED_CHANNEL	E2P_DATA(0x18)
69762306a36Sopenharmony_ci
69862306a36Sopenharmony_ci#define E2P_DEVICE_VER		E2P_DATA(0x20)
69962306a36Sopenharmony_ci#define E2P_PHY_REG		E2P_DATA(0x25)
70062306a36Sopenharmony_ci#define E2P_36M_CAL_VALUE1	E2P_DATA(0x28)
70162306a36Sopenharmony_ci#define E2P_36M_CAL_VALUE2      E2P_DATA(0x2a)
70262306a36Sopenharmony_ci#define E2P_36M_CAL_VALUE3      E2P_DATA(0x2c)
70362306a36Sopenharmony_ci#define E2P_36M_CAL_VALUE4	E2P_DATA(0x2e)
70462306a36Sopenharmony_ci#define E2P_11A_INT_VALUE1	E2P_DATA(0x30)
70562306a36Sopenharmony_ci#define E2P_11A_INT_VALUE2	E2P_DATA(0x32)
70662306a36Sopenharmony_ci#define E2P_11A_INT_VALUE3	E2P_DATA(0x34)
70762306a36Sopenharmony_ci#define E2P_11A_INT_VALUE4	E2P_DATA(0x36)
70862306a36Sopenharmony_ci#define E2P_48M_CAL_VALUE1	E2P_DATA(0x38)
70962306a36Sopenharmony_ci#define E2P_48M_CAL_VALUE2	E2P_DATA(0x3a)
71062306a36Sopenharmony_ci#define E2P_48M_CAL_VALUE3	E2P_DATA(0x3c)
71162306a36Sopenharmony_ci#define E2P_48M_CAL_VALUE4	E2P_DATA(0x3e)
71262306a36Sopenharmony_ci#define E2P_48M_INT_VALUE1	E2P_DATA(0x40)
71362306a36Sopenharmony_ci#define E2P_48M_INT_VALUE2	E2P_DATA(0x42)
71462306a36Sopenharmony_ci#define E2P_48M_INT_VALUE3	E2P_DATA(0x44)
71562306a36Sopenharmony_ci#define E2P_48M_INT_VALUE4	E2P_DATA(0x46)
71662306a36Sopenharmony_ci#define E2P_54M_CAL_VALUE1	E2P_DATA(0x48)	/* ??? */
71762306a36Sopenharmony_ci#define E2P_54M_CAL_VALUE2	E2P_DATA(0x4a)
71862306a36Sopenharmony_ci#define E2P_54M_CAL_VALUE3	E2P_DATA(0x4c)
71962306a36Sopenharmony_ci#define E2P_54M_CAL_VALUE4	E2P_DATA(0x4e)
72062306a36Sopenharmony_ci#define E2P_54M_INT_VALUE1	E2P_DATA(0x50)
72162306a36Sopenharmony_ci#define E2P_54M_INT_VALUE2	E2P_DATA(0x52)
72262306a36Sopenharmony_ci#define E2P_54M_INT_VALUE3	E2P_DATA(0x54)
72362306a36Sopenharmony_ci#define E2P_54M_INT_VALUE4	E2P_DATA(0x56)
72462306a36Sopenharmony_ci
72562306a36Sopenharmony_ci/* This word contains the base address of the FW_REG_ registers below */
72662306a36Sopenharmony_ci#define FWRAW_REGS_ADDR		FWRAW_DATA(0x1d)
72762306a36Sopenharmony_ci
72862306a36Sopenharmony_ci/* All 16 bit values, offset from the address in FWRAW_REGS_ADDR */
72962306a36Sopenharmony_cienum {
73062306a36Sopenharmony_ci	FW_REG_FIRMWARE_VER	= 0,
73162306a36Sopenharmony_ci	/* non-zero if USB high speed connection */
73262306a36Sopenharmony_ci	FW_REG_USB_SPEED	= 1,
73362306a36Sopenharmony_ci	FW_REG_FIX_TX_RATE	= 2,
73462306a36Sopenharmony_ci	/* Seems to be able to control LEDs over the firmware */
73562306a36Sopenharmony_ci	FW_REG_LED_LINK_STATUS	= 3,
73662306a36Sopenharmony_ci	FW_REG_SOFT_RESET	= 4,
73762306a36Sopenharmony_ci	FW_REG_FLASH_CHK	= 5,
73862306a36Sopenharmony_ci};
73962306a36Sopenharmony_ci
74062306a36Sopenharmony_ci/* Values for FW_LINK_STATUS */
74162306a36Sopenharmony_ci#define FW_LINK_OFF		0x0
74262306a36Sopenharmony_ci#define FW_LINK_TX		0x1
74362306a36Sopenharmony_ci/* 0x2 - link led on? */
74462306a36Sopenharmony_ci
74562306a36Sopenharmony_cienum {
74662306a36Sopenharmony_ci	/* indices for ofdm_cal_values */
74762306a36Sopenharmony_ci	OFDM_36M_INDEX = 0,
74862306a36Sopenharmony_ci	OFDM_48M_INDEX = 1,
74962306a36Sopenharmony_ci	OFDM_54M_INDEX = 2,
75062306a36Sopenharmony_ci};
75162306a36Sopenharmony_ci
75262306a36Sopenharmony_cistruct zd_chip {
75362306a36Sopenharmony_ci	struct zd_usb usb;
75462306a36Sopenharmony_ci	struct zd_rf rf;
75562306a36Sopenharmony_ci	struct mutex mutex;
75662306a36Sopenharmony_ci	/* Base address of FW_REG_ registers */
75762306a36Sopenharmony_ci	zd_addr_t fw_regs_base;
75862306a36Sopenharmony_ci	/* EepSetPoint in the vendor driver */
75962306a36Sopenharmony_ci	u8 pwr_cal_values[E2P_CHANNEL_COUNT];
76062306a36Sopenharmony_ci	/* integration values in the vendor driver */
76162306a36Sopenharmony_ci	u8 pwr_int_values[E2P_CHANNEL_COUNT];
76262306a36Sopenharmony_ci	/* SetPointOFDM in the vendor driver */
76362306a36Sopenharmony_ci	u8 ofdm_cal_values[3][E2P_CHANNEL_COUNT];
76462306a36Sopenharmony_ci	u16 link_led;
76562306a36Sopenharmony_ci	unsigned int pa_type:4,
76662306a36Sopenharmony_ci		patch_cck_gain:1, patch_cr157:1, patch_6m_band_edge:1,
76762306a36Sopenharmony_ci		new_phy_layout:1, al2230s_bit:1,
76862306a36Sopenharmony_ci		supports_tx_led:1;
76962306a36Sopenharmony_ci};
77062306a36Sopenharmony_ci
77162306a36Sopenharmony_cistatic inline struct zd_chip *zd_usb_to_chip(struct zd_usb *usb)
77262306a36Sopenharmony_ci{
77362306a36Sopenharmony_ci	return container_of(usb, struct zd_chip, usb);
77462306a36Sopenharmony_ci}
77562306a36Sopenharmony_ci
77662306a36Sopenharmony_cistatic inline struct zd_chip *zd_rf_to_chip(struct zd_rf *rf)
77762306a36Sopenharmony_ci{
77862306a36Sopenharmony_ci	return container_of(rf, struct zd_chip, rf);
77962306a36Sopenharmony_ci}
78062306a36Sopenharmony_ci
78162306a36Sopenharmony_ci#define zd_chip_dev(chip) (&(chip)->usb.intf->dev)
78262306a36Sopenharmony_ci
78362306a36Sopenharmony_civoid zd_chip_init(struct zd_chip *chip,
78462306a36Sopenharmony_ci	         struct ieee80211_hw *hw,
78562306a36Sopenharmony_ci	         struct usb_interface *intf);
78662306a36Sopenharmony_civoid zd_chip_clear(struct zd_chip *chip);
78762306a36Sopenharmony_ciint zd_chip_read_mac_addr_fw(struct zd_chip *chip, u8 *addr);
78862306a36Sopenharmony_ciint zd_chip_init_hw(struct zd_chip *chip);
78962306a36Sopenharmony_ciint zd_chip_reset(struct zd_chip *chip);
79062306a36Sopenharmony_ci
79162306a36Sopenharmony_cistatic inline int zd_chip_is_zd1211b(struct zd_chip *chip)
79262306a36Sopenharmony_ci{
79362306a36Sopenharmony_ci	return chip->usb.is_zd1211b;
79462306a36Sopenharmony_ci}
79562306a36Sopenharmony_ci
79662306a36Sopenharmony_cistatic inline int zd_ioread16v_locked(struct zd_chip *chip, u16 *values,
79762306a36Sopenharmony_ci	                              const zd_addr_t *addresses,
79862306a36Sopenharmony_ci				      unsigned int count)
79962306a36Sopenharmony_ci{
80062306a36Sopenharmony_ci	ZD_ASSERT(mutex_is_locked(&chip->mutex));
80162306a36Sopenharmony_ci	return zd_usb_ioread16v(&chip->usb, values, addresses, count);
80262306a36Sopenharmony_ci}
80362306a36Sopenharmony_ci
80462306a36Sopenharmony_cistatic inline int zd_ioread16_locked(struct zd_chip *chip, u16 *value,
80562306a36Sopenharmony_ci	                             const zd_addr_t addr)
80662306a36Sopenharmony_ci{
80762306a36Sopenharmony_ci	ZD_ASSERT(mutex_is_locked(&chip->mutex));
80862306a36Sopenharmony_ci	return zd_usb_ioread16(&chip->usb, value, addr);
80962306a36Sopenharmony_ci}
81062306a36Sopenharmony_ci
81162306a36Sopenharmony_ciint zd_ioread32v_locked(struct zd_chip *chip, u32 *values,
81262306a36Sopenharmony_ci	                const zd_addr_t *addresses, unsigned int count);
81362306a36Sopenharmony_ci
81462306a36Sopenharmony_cistatic inline int zd_ioread32_locked(struct zd_chip *chip, u32 *value,
81562306a36Sopenharmony_ci	                             const zd_addr_t addr)
81662306a36Sopenharmony_ci{
81762306a36Sopenharmony_ci	return zd_ioread32v_locked(chip, value, &addr, 1);
81862306a36Sopenharmony_ci}
81962306a36Sopenharmony_ci
82062306a36Sopenharmony_cistatic inline int zd_iowrite16_locked(struct zd_chip *chip, u16 value,
82162306a36Sopenharmony_ci	                              zd_addr_t addr)
82262306a36Sopenharmony_ci{
82362306a36Sopenharmony_ci	struct zd_ioreq16 ioreq;
82462306a36Sopenharmony_ci
82562306a36Sopenharmony_ci	ZD_ASSERT(mutex_is_locked(&chip->mutex));
82662306a36Sopenharmony_ci	ioreq.addr = addr;
82762306a36Sopenharmony_ci	ioreq.value = value;
82862306a36Sopenharmony_ci
82962306a36Sopenharmony_ci	return zd_usb_iowrite16v(&chip->usb, &ioreq, 1);
83062306a36Sopenharmony_ci}
83162306a36Sopenharmony_ci
83262306a36Sopenharmony_ciint zd_iowrite16a_locked(struct zd_chip *chip,
83362306a36Sopenharmony_ci                         const struct zd_ioreq16 *ioreqs, unsigned int count);
83462306a36Sopenharmony_ci
83562306a36Sopenharmony_ciint _zd_iowrite32v_locked(struct zd_chip *chip, const struct zd_ioreq32 *ioreqs,
83662306a36Sopenharmony_ci			  unsigned int count);
83762306a36Sopenharmony_ci
83862306a36Sopenharmony_cistatic inline int zd_iowrite32_locked(struct zd_chip *chip, u32 value,
83962306a36Sopenharmony_ci	                              zd_addr_t addr)
84062306a36Sopenharmony_ci{
84162306a36Sopenharmony_ci	struct zd_ioreq32 ioreq;
84262306a36Sopenharmony_ci
84362306a36Sopenharmony_ci	ioreq.addr = addr;
84462306a36Sopenharmony_ci	ioreq.value = value;
84562306a36Sopenharmony_ci
84662306a36Sopenharmony_ci	return _zd_iowrite32v_locked(chip, &ioreq, 1);
84762306a36Sopenharmony_ci}
84862306a36Sopenharmony_ci
84962306a36Sopenharmony_ciint zd_iowrite32a_locked(struct zd_chip *chip,
85062306a36Sopenharmony_ci	                 const struct zd_ioreq32 *ioreqs, unsigned int count);
85162306a36Sopenharmony_ci
85262306a36Sopenharmony_cistatic inline int zd_rfwrite_locked(struct zd_chip *chip, u32 value, u8 bits)
85362306a36Sopenharmony_ci{
85462306a36Sopenharmony_ci	ZD_ASSERT(mutex_is_locked(&chip->mutex));
85562306a36Sopenharmony_ci	return zd_usb_rfwrite(&chip->usb, value, bits);
85662306a36Sopenharmony_ci}
85762306a36Sopenharmony_ci
85862306a36Sopenharmony_ciint zd_rfwrite_cr_locked(struct zd_chip *chip, u32 value);
85962306a36Sopenharmony_ci
86062306a36Sopenharmony_ciint zd_rfwritev_locked(struct zd_chip *chip,
86162306a36Sopenharmony_ci	               const u32* values, unsigned int count, u8 bits);
86262306a36Sopenharmony_ciint zd_rfwritev_cr_locked(struct zd_chip *chip,
86362306a36Sopenharmony_ci	                  const u32* values, unsigned int count);
86462306a36Sopenharmony_ci
86562306a36Sopenharmony_ci/* Locking functions for reading and writing registers.
86662306a36Sopenharmony_ci * The different parameters are intentional.
86762306a36Sopenharmony_ci */
86862306a36Sopenharmony_ciint zd_ioread16(struct zd_chip *chip, zd_addr_t addr, u16 *value);
86962306a36Sopenharmony_ciint zd_iowrite16(struct zd_chip *chip, zd_addr_t addr, u16 value);
87062306a36Sopenharmony_ciint zd_ioread32(struct zd_chip *chip, zd_addr_t addr, u32 *value);
87162306a36Sopenharmony_ciint zd_iowrite32(struct zd_chip *chip, zd_addr_t addr, u32 value);
87262306a36Sopenharmony_ciint zd_ioread32v(struct zd_chip *chip, const zd_addr_t *addresses,
87362306a36Sopenharmony_ci	          u32 *values, unsigned int count);
87462306a36Sopenharmony_ciint zd_iowrite32a(struct zd_chip *chip, const struct zd_ioreq32 *ioreqs,
87562306a36Sopenharmony_ci	           unsigned int count);
87662306a36Sopenharmony_ci
87762306a36Sopenharmony_ciint zd_chip_set_channel(struct zd_chip *chip, u8 channel);
87862306a36Sopenharmony_cistatic inline u8 _zd_chip_get_channel(struct zd_chip *chip)
87962306a36Sopenharmony_ci{
88062306a36Sopenharmony_ci	return chip->rf.channel;
88162306a36Sopenharmony_ci}
88262306a36Sopenharmony_ciu8  zd_chip_get_channel(struct zd_chip *chip);
88362306a36Sopenharmony_ciint zd_read_regdomain(struct zd_chip *chip, u8 *regdomain);
88462306a36Sopenharmony_ciint zd_write_mac_addr(struct zd_chip *chip, const u8 *mac_addr);
88562306a36Sopenharmony_ciint zd_write_bssid(struct zd_chip *chip, const u8 *bssid);
88662306a36Sopenharmony_ciint zd_chip_switch_radio_on(struct zd_chip *chip);
88762306a36Sopenharmony_ciint zd_chip_switch_radio_off(struct zd_chip *chip);
88862306a36Sopenharmony_ciint zd_chip_enable_int(struct zd_chip *chip);
88962306a36Sopenharmony_civoid zd_chip_disable_int(struct zd_chip *chip);
89062306a36Sopenharmony_ciint zd_chip_enable_rxtx(struct zd_chip *chip);
89162306a36Sopenharmony_civoid zd_chip_disable_rxtx(struct zd_chip *chip);
89262306a36Sopenharmony_ciint zd_chip_enable_hwint(struct zd_chip *chip);
89362306a36Sopenharmony_ciint zd_chip_disable_hwint(struct zd_chip *chip);
89462306a36Sopenharmony_ciint zd_chip_generic_patch_6m_band(struct zd_chip *chip, int channel);
89562306a36Sopenharmony_ciint zd_chip_set_rts_cts_rate_locked(struct zd_chip *chip, int preamble);
89662306a36Sopenharmony_ci
89762306a36Sopenharmony_cistatic inline int zd_get_encryption_type(struct zd_chip *chip, u32 *type)
89862306a36Sopenharmony_ci{
89962306a36Sopenharmony_ci	return zd_ioread32(chip, CR_ENCRYPTION_TYPE, type);
90062306a36Sopenharmony_ci}
90162306a36Sopenharmony_ci
90262306a36Sopenharmony_cistatic inline int zd_set_encryption_type(struct zd_chip *chip, u32 type)
90362306a36Sopenharmony_ci{
90462306a36Sopenharmony_ci	return zd_iowrite32(chip, CR_ENCRYPTION_TYPE, type);
90562306a36Sopenharmony_ci}
90662306a36Sopenharmony_ci
90762306a36Sopenharmony_cistatic inline int zd_chip_get_basic_rates(struct zd_chip *chip, u16 *cr_rates)
90862306a36Sopenharmony_ci{
90962306a36Sopenharmony_ci	return zd_ioread16(chip, CR_BASIC_RATE_TBL, cr_rates);
91062306a36Sopenharmony_ci}
91162306a36Sopenharmony_ci
91262306a36Sopenharmony_ciint zd_chip_set_basic_rates(struct zd_chip *chip, u16 cr_rates);
91362306a36Sopenharmony_ci
91462306a36Sopenharmony_ciint zd_chip_lock_phy_regs(struct zd_chip *chip);
91562306a36Sopenharmony_ciint zd_chip_unlock_phy_regs(struct zd_chip *chip);
91662306a36Sopenharmony_ci
91762306a36Sopenharmony_cienum led_status {
91862306a36Sopenharmony_ci	ZD_LED_OFF = 0,
91962306a36Sopenharmony_ci	ZD_LED_SCANNING = 1,
92062306a36Sopenharmony_ci	ZD_LED_ASSOCIATED = 2,
92162306a36Sopenharmony_ci};
92262306a36Sopenharmony_ci
92362306a36Sopenharmony_ciint zd_chip_control_leds(struct zd_chip *chip, enum led_status status);
92462306a36Sopenharmony_ci
92562306a36Sopenharmony_ciint zd_set_beacon_interval(struct zd_chip *chip, u16 interval, u8 dtim_period,
92662306a36Sopenharmony_ci			   int type);
92762306a36Sopenharmony_ci
92862306a36Sopenharmony_cistatic inline int zd_get_beacon_interval(struct zd_chip *chip, u32 *interval)
92962306a36Sopenharmony_ci{
93062306a36Sopenharmony_ci	return zd_ioread32(chip, CR_BCN_INTERVAL, interval);
93162306a36Sopenharmony_ci}
93262306a36Sopenharmony_ci
93362306a36Sopenharmony_cistruct rx_status;
93462306a36Sopenharmony_ci
93562306a36Sopenharmony_ciu8 zd_rx_rate(const void *rx_frame, const struct rx_status *status);
93662306a36Sopenharmony_ci
93762306a36Sopenharmony_cistruct zd_mc_hash {
93862306a36Sopenharmony_ci	u32 low;
93962306a36Sopenharmony_ci	u32 high;
94062306a36Sopenharmony_ci};
94162306a36Sopenharmony_ci
94262306a36Sopenharmony_cistatic inline void zd_mc_clear(struct zd_mc_hash *hash)
94362306a36Sopenharmony_ci{
94462306a36Sopenharmony_ci	hash->low = 0;
94562306a36Sopenharmony_ci	/* The interfaces must always received broadcasts.
94662306a36Sopenharmony_ci	 * The hash of the broadcast address ff:ff:ff:ff:ff:ff is 63.
94762306a36Sopenharmony_ci	 */
94862306a36Sopenharmony_ci	hash->high = 0x80000000;
94962306a36Sopenharmony_ci}
95062306a36Sopenharmony_ci
95162306a36Sopenharmony_cistatic inline void zd_mc_add_all(struct zd_mc_hash *hash)
95262306a36Sopenharmony_ci{
95362306a36Sopenharmony_ci	hash->low = hash->high = 0xffffffff;
95462306a36Sopenharmony_ci}
95562306a36Sopenharmony_ci
95662306a36Sopenharmony_cistatic inline void zd_mc_add_addr(struct zd_mc_hash *hash, u8 *addr)
95762306a36Sopenharmony_ci{
95862306a36Sopenharmony_ci	unsigned int i = addr[5] >> 2;
95962306a36Sopenharmony_ci	if (i < 32) {
96062306a36Sopenharmony_ci		hash->low |= 1 << i;
96162306a36Sopenharmony_ci	} else {
96262306a36Sopenharmony_ci		hash->high |= 1 << (i-32);
96362306a36Sopenharmony_ci	}
96462306a36Sopenharmony_ci}
96562306a36Sopenharmony_ci
96662306a36Sopenharmony_ciint zd_chip_set_multicast_hash(struct zd_chip *chip,
96762306a36Sopenharmony_ci	                       struct zd_mc_hash *hash);
96862306a36Sopenharmony_ci
96962306a36Sopenharmony_ciu64 zd_chip_get_tsf(struct zd_chip *chip);
97062306a36Sopenharmony_ci
97162306a36Sopenharmony_ci#endif /* _ZD_CHIP_H */
972