Remove empty DragonFly CVS IDs.
[dragonfly.git] / sys / dev / netif / ath / hal / ath_hal / ar5416 / ar9160_attach.c
blobdf44a784251810e1e4b104b46ebfaba09d3fac1c
1 /*
2 * Copyright (c) 2008 Sam Leffler, Errno Consulting
3 * Copyright (c) 2008 Atheros Communications, Inc.
5 * Permission to use, copy, modify, and/or distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 * $FreeBSD: head/sys/dev/ath/ath_hal/ar5416/ar9160_attach.c 203882 2010-02-14 16:26:32Z rpaulo $
19 #include "opt_ah.h"
21 #include "ah.h"
22 #include "ah_internal.h"
23 #include "ah_devid.h"
25 #include "ar5416/ar5416.h"
26 #include "ar5416/ar5416reg.h"
27 #include "ar5416/ar5416phy.h"
29 #include "ar5416/ar9160.ini"
31 static const HAL_PERCAL_DATA ar9160_iq_cal = { /* multi sample */
32 .calName = "IQ", .calType = IQ_MISMATCH_CAL,
33 .calNumSamples = MAX_CAL_SAMPLES,
34 .calCountMax = PER_MIN_LOG_COUNT,
35 .calCollect = ar5416IQCalCollect,
36 .calPostProc = ar5416IQCalibration
38 static const HAL_PERCAL_DATA ar9160_adc_gain_cal = { /* multi sample */
39 .calName = "ADC Gain", .calType = ADC_GAIN_CAL,
40 .calNumSamples = MAX_CAL_SAMPLES,
41 .calCountMax = PER_MIN_LOG_COUNT,
42 .calCollect = ar5416AdcGainCalCollect,
43 .calPostProc = ar5416AdcGainCalibration
45 static const HAL_PERCAL_DATA ar9160_adc_dc_cal = { /* multi sample */
46 .calName = "ADC DC", .calType = ADC_DC_CAL,
47 .calNumSamples = MAX_CAL_SAMPLES,
48 .calCountMax = PER_MIN_LOG_COUNT,
49 .calCollect = ar5416AdcDcCalCollect,
50 .calPostProc = ar5416AdcDcCalibration
52 static const HAL_PERCAL_DATA ar9160_adc_init_dc_cal = {
53 .calName = "ADC Init DC", .calType = ADC_DC_INIT_CAL,
54 .calNumSamples = MIN_CAL_SAMPLES,
55 .calCountMax = INIT_LOG_COUNT,
56 .calCollect = ar5416AdcDcCalCollect,
57 .calPostProc = ar5416AdcDcCalibration
60 static HAL_BOOL ar9160FillCapabilityInfo(struct ath_hal *ah);
62 static void
63 ar9160AniSetup(struct ath_hal *ah)
65 static const struct ar5212AniParams aniparams = {
66 .maxNoiseImmunityLevel = 4, /* levels 0..4 */
67 .totalSizeDesired = { -55, -55, -55, -55, -62 },
68 .coarseHigh = { -14, -14, -14, -14, -12 },
69 .coarseLow = { -64, -64, -64, -64, -70 },
70 .firpwr = { -78, -78, -78, -78, -80 },
71 .maxSpurImmunityLevel = 2,
72 .cycPwrThr1 = { 2, 4, 6 },
73 .maxFirstepLevel = 2, /* levels 0..2 */
74 .firstep = { 0, 4, 8 },
75 .ofdmTrigHigh = 500,
76 .ofdmTrigLow = 200,
77 .cckTrigHigh = 200,
78 .cckTrigLow = 100,
79 .rssiThrHigh = 40,
80 .rssiThrLow = 7,
81 .period = 100,
83 /* NB: ANI is not enabled yet */
84 ar5212AniAttach(ah, &aniparams, &aniparams, AH_FALSE);
88 * Attach for an AR9160 part.
90 static struct ath_hal *
91 ar9160Attach(uint16_t devid, HAL_SOFTC sc,
92 HAL_BUS_TAG st, HAL_BUS_HANDLE sh, HAL_STATUS *status)
94 struct ath_hal_5416 *ahp5416;
95 struct ath_hal_5212 *ahp;
96 struct ath_hal *ah;
97 uint32_t val;
98 HAL_STATUS ecode;
99 HAL_BOOL rfStatus;
101 HALDEBUG(AH_NULL, HAL_DEBUG_ATTACH, "%s: sc %p st %p sh %p\n",
102 __func__, sc, (void*) st, (void*) sh);
104 /* NB: memory is returned zero'd */
105 ahp5416 = ath_hal_malloc(sizeof (struct ath_hal_5416));
106 if (ahp5416 == AH_NULL) {
107 HALDEBUG(AH_NULL, HAL_DEBUG_ANY,
108 "%s: cannot allocate memory for state block\n", __func__);
109 *status = HAL_ENOMEM;
110 return AH_NULL;
112 ar5416InitState(ahp5416, devid, sc, st, sh, status);
113 ahp = &ahp5416->ah_5212;
114 ah = &ahp->ah_priv.h;
116 /* XXX override with 9160 specific state */
117 /* override 5416 methods for our needs */
119 AH5416(ah)->ah_cal.iqCalData.calData = &ar9160_iq_cal;
120 AH5416(ah)->ah_cal.adcGainCalData.calData = &ar9160_adc_gain_cal;
121 AH5416(ah)->ah_cal.adcDcCalData.calData = &ar9160_adc_dc_cal;
122 AH5416(ah)->ah_cal.adcDcCalInitData.calData = &ar9160_adc_init_dc_cal;
123 AH5416(ah)->ah_cal.suppCals = ADC_GAIN_CAL | ADC_DC_CAL | IQ_MISMATCH_CAL;
125 if (!ar5416SetResetReg(ah, HAL_RESET_POWER_ON)) {
126 /* reset chip */
127 HALDEBUG(ah, HAL_DEBUG_ANY, "%s: couldn't reset chip\n",
128 __func__);
129 ecode = HAL_EIO;
130 goto bad;
133 if (!ar5416SetPowerMode(ah, HAL_PM_AWAKE, AH_TRUE)) {
134 HALDEBUG(ah, HAL_DEBUG_ANY, "%s: couldn't wakeup chip\n",
135 __func__);
136 ecode = HAL_EIO;
137 goto bad;
139 /* Read Revisions from Chips before taking out of reset */
140 val = OS_REG_READ(ah, AR_SREV);
141 HALDEBUG(ah, HAL_DEBUG_ATTACH,
142 "%s: ID 0x%x VERSION 0x%x TYPE 0x%x REVISION 0x%x\n",
143 __func__, MS(val, AR_XSREV_ID), MS(val, AR_XSREV_VERSION),
144 MS(val, AR_XSREV_TYPE), MS(val, AR_XSREV_REVISION));
145 /* NB: include chip type to differentiate from pre-Sowl versions */
146 AH_PRIVATE(ah)->ah_macVersion =
147 (val & AR_XSREV_VERSION) >> AR_XSREV_TYPE_S;
148 AH_PRIVATE(ah)->ah_macRev = MS(val, AR_XSREV_REVISION);
149 AH_PRIVATE(ah)->ah_ispcie = (val & AR_XSREV_TYPE_HOST_MODE) == 0;
151 /* setup common ini data; rf backends handle remainder */
152 HAL_INI_INIT(&ahp->ah_ini_modes, ar9160Modes, 6);
153 HAL_INI_INIT(&ahp->ah_ini_common, ar9160Common, 2);
155 HAL_INI_INIT(&AH5416(ah)->ah_ini_bb_rfgain, ar9160BB_RfGain, 3);
156 HAL_INI_INIT(&AH5416(ah)->ah_ini_bank0, ar9160Bank0, 2);
157 HAL_INI_INIT(&AH5416(ah)->ah_ini_bank1, ar9160Bank1, 2);
158 HAL_INI_INIT(&AH5416(ah)->ah_ini_bank2, ar9160Bank2, 2);
159 HAL_INI_INIT(&AH5416(ah)->ah_ini_bank3, ar9160Bank3, 3);
160 HAL_INI_INIT(&AH5416(ah)->ah_ini_bank6, ar9160Bank6, 3);
161 HAL_INI_INIT(&AH5416(ah)->ah_ini_bank7, ar9160Bank7, 2);
162 if (AR_SREV_SOWL_11(ah))
163 HAL_INI_INIT(&AH5416(ah)->ah_ini_addac, ar9160Addac_1_1, 2);
164 else
165 HAL_INI_INIT(&AH5416(ah)->ah_ini_addac, ar9160Addac, 2);
167 ecode = ath_hal_v14EepromAttach(ah);
168 if (ecode != HAL_OK)
169 goto bad;
171 HAL_INI_INIT(&AH5416(ah)->ah_ini_pcieserdes, ar9160PciePhy, 2);
172 ar5416AttachPCIE(ah);
174 if (!ar5416ChipReset(ah, AH_NULL)) { /* reset chip */
175 HALDEBUG(ah, HAL_DEBUG_ANY, "%s: chip reset failed\n", __func__);
176 ecode = HAL_EIO;
177 goto bad;
180 AH_PRIVATE(ah)->ah_phyRev = OS_REG_READ(ah, AR_PHY_CHIP_ID);
182 if (!ar5212ChipTest(ah)) {
183 HALDEBUG(ah, HAL_DEBUG_ANY, "%s: hardware self-test failed\n",
184 __func__);
185 ecode = HAL_ESELFTEST;
186 goto bad;
190 * Set correct Baseband to analog shift
191 * setting to access analog chips.
193 OS_REG_WRITE(ah, AR_PHY(0), 0x00000007);
195 /* Read Radio Chip Rev Extract */
196 AH_PRIVATE(ah)->ah_analog5GhzRev = ar5416GetRadioRev(ah);
197 switch (AH_PRIVATE(ah)->ah_analog5GhzRev & AR_RADIO_SREV_MAJOR) {
198 case AR_RAD2133_SREV_MAJOR: /* Sowl: 2G/3x3 */
199 case AR_RAD5133_SREV_MAJOR: /* Sowl: 2+5G/3x3 */
200 break;
201 default:
202 if (AH_PRIVATE(ah)->ah_analog5GhzRev == 0) {
203 AH_PRIVATE(ah)->ah_analog5GhzRev =
204 AR_RAD5133_SREV_MAJOR;
205 break;
207 #ifdef AH_DEBUG
208 HALDEBUG(ah, HAL_DEBUG_ANY,
209 "%s: 5G Radio Chip Rev 0x%02X is not supported by "
210 "this driver\n", __func__,
211 AH_PRIVATE(ah)->ah_analog5GhzRev);
212 ecode = HAL_ENOTSUPP;
213 goto bad;
214 #endif
216 rfStatus = ar2133RfAttach(ah, &ecode);
217 if (!rfStatus) {
218 HALDEBUG(ah, HAL_DEBUG_ANY, "%s: RF setup failed, status %u\n",
219 __func__, ecode);
220 goto bad;
224 * Got everything we need now to setup the capabilities.
226 if (!ar9160FillCapabilityInfo(ah)) {
227 ecode = HAL_EEREAD;
228 goto bad;
231 ecode = ath_hal_eepromGet(ah, AR_EEP_MACADDR, ahp->ah_macaddr);
232 if (ecode != HAL_OK) {
233 HALDEBUG(ah, HAL_DEBUG_ANY,
234 "%s: error getting mac address from EEPROM\n", __func__);
235 goto bad;
237 /* XXX How about the serial number ? */
238 /* Read Reg Domain */
239 AH_PRIVATE(ah)->ah_currentRD =
240 ath_hal_eepromGet(ah, AR_EEP_REGDMN_0, AH_NULL);
243 * ah_miscMode is populated by ar5416FillCapabilityInfo()
244 * starting from griffin. Set here to make sure that
245 * AR_MISC_MODE_MIC_NEW_LOC_ENABLE is set before a GTK is
246 * placed into hardware.
248 if (ahp->ah_miscMode != 0)
249 OS_REG_WRITE(ah, AR_MISC_MODE, ahp->ah_miscMode);
251 ar9160AniSetup(ah); /* Anti Noise Immunity */
252 ar5416InitNfHistBuff(AH5416(ah)->ah_cal.nfCalHist);
254 HALDEBUG(ah, HAL_DEBUG_ATTACH, "%s: return\n", __func__);
256 return ah;
257 bad:
258 if (ahp)
259 ar5416Detach((struct ath_hal *) ahp);
260 if (status)
261 *status = ecode;
262 return AH_NULL;
266 * Fill all software cached or static hardware state information.
267 * Return failure if capabilities are to come from EEPROM and
268 * cannot be read.
270 static HAL_BOOL
271 ar9160FillCapabilityInfo(struct ath_hal *ah)
273 HAL_CAPABILITIES *pCap = &AH_PRIVATE(ah)->ah_caps;
275 if (!ar5416FillCapabilityInfo(ah))
276 return AH_FALSE;
277 pCap->halCSTSupport = AH_TRUE;
278 pCap->halRifsRxSupport = AH_TRUE;
279 pCap->halRifsTxSupport = AH_TRUE;
280 pCap->halRtsAggrLimit = 64*1024; /* 802.11n max */
281 pCap->halExtChanDfsSupport = AH_TRUE;
282 pCap->halAutoSleepSupport = AH_FALSE; /* XXX? */
283 return AH_TRUE;
286 static const char*
287 ar9160Probe(uint16_t vendorid, uint16_t devid)
289 if (vendorid == ATHEROS_VENDOR_ID && devid == AR9160_DEVID_PCI)
290 return "Atheros 9160";
291 return AH_NULL;
293 AH_CHIP(AR9160, ar9160Probe, ar9160Attach);