1572ff6f6SMatthew Dillon /*
2572ff6f6SMatthew Dillon  * Copyright (c) 2002-2008 Sam Leffler, Errno Consulting
3572ff6f6SMatthew Dillon  * Copyright (c) 2002-2008 Atheros Communications, Inc.
4572ff6f6SMatthew Dillon  *
5572ff6f6SMatthew Dillon  * Permission to use, copy, modify, and/or distribute this software for any
6572ff6f6SMatthew Dillon  * purpose with or without fee is hereby granted, provided that the above
7572ff6f6SMatthew Dillon  * copyright notice and this permission notice appear in all copies.
8572ff6f6SMatthew Dillon  *
9572ff6f6SMatthew Dillon  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10572ff6f6SMatthew Dillon  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11572ff6f6SMatthew Dillon  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12572ff6f6SMatthew Dillon  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13572ff6f6SMatthew Dillon  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14572ff6f6SMatthew Dillon  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15572ff6f6SMatthew Dillon  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16572ff6f6SMatthew Dillon  *
17572ff6f6SMatthew Dillon  * $FreeBSD$
18572ff6f6SMatthew Dillon  */
19572ff6f6SMatthew Dillon #include "opt_ah.h"
20572ff6f6SMatthew Dillon 
21572ff6f6SMatthew Dillon #include "ah.h"
22572ff6f6SMatthew Dillon #include "ah_internal.h"
23572ff6f6SMatthew Dillon #include "ah_devid.h"
24572ff6f6SMatthew Dillon 
25572ff6f6SMatthew Dillon #include "ar5312/ar5312.h"
26572ff6f6SMatthew Dillon #include "ar5312/ar5312reg.h"
27572ff6f6SMatthew Dillon #include "ar5312/ar5312phy.h"
28572ff6f6SMatthew Dillon 
29572ff6f6SMatthew Dillon /* Add static register initialization vectors */
30572ff6f6SMatthew Dillon #define AH_5212_COMMON
31572ff6f6SMatthew Dillon #include "ar5212/ar5212.ini"
32572ff6f6SMatthew Dillon 
33572ff6f6SMatthew Dillon static  HAL_BOOL ar5312GetMacAddr(struct ath_hal *ah);
34572ff6f6SMatthew Dillon 
35572ff6f6SMatthew Dillon static void
ar5312AniSetup(struct ath_hal * ah)36572ff6f6SMatthew Dillon ar5312AniSetup(struct ath_hal *ah)
37572ff6f6SMatthew Dillon {
38572ff6f6SMatthew Dillon 	static const struct ar5212AniParams aniparams = {
39572ff6f6SMatthew Dillon 		.maxNoiseImmunityLevel	= 4,	/* levels 0..4 */
40572ff6f6SMatthew Dillon 		.totalSizeDesired	= { -41, -41, -48, -48, -48 },
41572ff6f6SMatthew Dillon 		.coarseHigh		= { -18, -18, -16, -14, -12 },
42572ff6f6SMatthew Dillon 		.coarseLow		= { -56, -56, -60, -60, -60 },
43572ff6f6SMatthew Dillon 		.firpwr			= { -72, -72, -75, -78, -80 },
44572ff6f6SMatthew Dillon 		.maxSpurImmunityLevel	= 2,
45572ff6f6SMatthew Dillon 		.cycPwrThr1		= { 2, 4, 6 },
46572ff6f6SMatthew Dillon 		.maxFirstepLevel	= 2,	/* levels 0..2 */
47572ff6f6SMatthew Dillon 		.firstep		= { 0, 4, 8 },
48572ff6f6SMatthew Dillon 		.ofdmTrigHigh		= 500,
49572ff6f6SMatthew Dillon 		.ofdmTrigLow		= 200,
50572ff6f6SMatthew Dillon 		.cckTrigHigh		= 200,
51572ff6f6SMatthew Dillon 		.cckTrigLow		= 100,
52572ff6f6SMatthew Dillon 		.rssiThrHigh		= 40,
53572ff6f6SMatthew Dillon 		.rssiThrLow		= 7,
54572ff6f6SMatthew Dillon 		.period			= 100,
55572ff6f6SMatthew Dillon 	};
56572ff6f6SMatthew Dillon 	ar5212AniAttach(ah, &aniparams, &aniparams, AH_TRUE);
57572ff6f6SMatthew Dillon }
58572ff6f6SMatthew Dillon 
59572ff6f6SMatthew Dillon /*
60572ff6f6SMatthew Dillon  * Attach for an AR5312 part.
61572ff6f6SMatthew Dillon  */
62572ff6f6SMatthew Dillon static struct ath_hal *
ar5312Attach(uint16_t devid,HAL_SOFTC sc,HAL_BUS_TAG st,HAL_BUS_HANDLE sh,uint16_t * eepromdata,HAL_OPS_CONFIG * ah_config,HAL_STATUS * status)63572ff6f6SMatthew Dillon ar5312Attach(uint16_t devid, HAL_SOFTC sc,
64572ff6f6SMatthew Dillon 	HAL_BUS_TAG st, HAL_BUS_HANDLE sh, uint16_t *eepromdata,
65*848b370cSMatthew Dillon 	HAL_OPS_CONFIG *ah_config, HAL_STATUS *status)
66572ff6f6SMatthew Dillon {
67572ff6f6SMatthew Dillon 	struct ath_hal_5212 *ahp = AH_NULL;
68572ff6f6SMatthew Dillon 	struct ath_hal *ah;
69572ff6f6SMatthew Dillon 	struct ath_hal_rf *rf;
70572ff6f6SMatthew Dillon 	uint32_t val;
71572ff6f6SMatthew Dillon 	uint16_t eeval;
72572ff6f6SMatthew Dillon 	HAL_STATUS ecode;
73572ff6f6SMatthew Dillon 
74572ff6f6SMatthew Dillon 	HALDEBUG(AH_NULL, HAL_DEBUG_ATTACH, "%s: sc %p st %p sh %p\n",
75572ff6f6SMatthew Dillon 		 __func__, sc, st, (void*) sh);
76572ff6f6SMatthew Dillon 
77572ff6f6SMatthew Dillon 	/* NB: memory is returned zero'd */
78572ff6f6SMatthew Dillon 	ahp = ath_hal_malloc(sizeof (struct ath_hal_5212));
79572ff6f6SMatthew Dillon 	if (ahp == AH_NULL) {
80572ff6f6SMatthew Dillon 		HALDEBUG(AH_NULL, HAL_DEBUG_ANY,
81572ff6f6SMatthew Dillon 		    "%s: cannot allocate memory for state block\n", __func__);
82572ff6f6SMatthew Dillon 		*status = HAL_ENOMEM;
83572ff6f6SMatthew Dillon 		return AH_NULL;
84572ff6f6SMatthew Dillon 	}
85572ff6f6SMatthew Dillon 	ar5212InitState(ahp, devid, sc, st, sh, status);
86572ff6f6SMatthew Dillon 	ah = &ahp->ah_priv.h;
87572ff6f6SMatthew Dillon 
88572ff6f6SMatthew Dillon 	/* override 5212 methods for our needs */
89572ff6f6SMatthew Dillon 	ah->ah_reset			= ar5312Reset;
90572ff6f6SMatthew Dillon 	ah->ah_phyDisable		= ar5312PhyDisable;
91572ff6f6SMatthew Dillon 	ah->ah_setLedState		= ar5312SetLedState;
92572ff6f6SMatthew Dillon 	ah->ah_detectCardPresent	= ar5312DetectCardPresent;
93572ff6f6SMatthew Dillon 	ah->ah_setPowerMode		= ar5312SetPowerMode;
94572ff6f6SMatthew Dillon 	ah->ah_getPowerMode		= ar5312GetPowerMode;
95572ff6f6SMatthew Dillon 	ah->ah_isInterruptPending	= ar5312IsInterruptPending;
96572ff6f6SMatthew Dillon 
97572ff6f6SMatthew Dillon 	ahp->ah_priv.ah_eepromRead	= ar5312EepromRead;
98572ff6f6SMatthew Dillon #ifdef AH_SUPPORT_WRITE_EEPROM
99572ff6f6SMatthew Dillon 	ahp->ah_priv.ah_eepromWrite	= ar5312EepromWrite;
100572ff6f6SMatthew Dillon #endif
101572ff6f6SMatthew Dillon #if ( AH_SUPPORT_2316 || AH_SUPPORT_2317)
102572ff6f6SMatthew Dillon 	if (IS_5315(ah)) {
103572ff6f6SMatthew Dillon 		ahp->ah_priv.ah_gpioCfgOutput	= ar5315GpioCfgOutput;
104572ff6f6SMatthew Dillon 		ahp->ah_priv.ah_gpioCfgInput	= ar5315GpioCfgInput;
105572ff6f6SMatthew Dillon 		ahp->ah_priv.ah_gpioGet		= ar5315GpioGet;
106572ff6f6SMatthew Dillon 		ahp->ah_priv.ah_gpioSet		= ar5315GpioSet;
107572ff6f6SMatthew Dillon 		ahp->ah_priv.ah_gpioSetIntr	= ar5315GpioSetIntr;
108572ff6f6SMatthew Dillon 	} else
109572ff6f6SMatthew Dillon #endif
110572ff6f6SMatthew Dillon 	{
111*848b370cSMatthew Dillon 		ahp->ah_priv.ah_gpioCfgOutput	= ar5312GpioCfgOutput;
112*848b370cSMatthew Dillon 		ahp->ah_priv.ah_gpioCfgInput	= ar5312GpioCfgInput;
113*848b370cSMatthew Dillon 		ahp->ah_priv.ah_gpioGet		= ar5312GpioGet;
114*848b370cSMatthew Dillon 		ahp->ah_priv.ah_gpioSet		= ar5312GpioSet;
115*848b370cSMatthew Dillon 		ahp->ah_priv.ah_gpioSetIntr	= ar5312GpioSetIntr;
116572ff6f6SMatthew Dillon 	}
117572ff6f6SMatthew Dillon 
118*848b370cSMatthew Dillon 	ah->ah_gpioCfgInput		= ahp->ah_priv.ah_gpioCfgInput;
119*848b370cSMatthew Dillon 	ah->ah_gpioCfgOutput		= ahp->ah_priv.ah_gpioCfgOutput;
120*848b370cSMatthew Dillon 	ah->ah_gpioGet			= ahp->ah_priv.ah_gpioGet;
121*848b370cSMatthew Dillon 	ah->ah_gpioSet			= ahp->ah_priv.ah_gpioSet;
122*848b370cSMatthew Dillon 	ah->ah_gpioSetIntr		= ahp->ah_priv.ah_gpioSetIntr;
123572ff6f6SMatthew Dillon 
124572ff6f6SMatthew Dillon 	/* setup common ini data; rf backends handle remainder */
125572ff6f6SMatthew Dillon 	HAL_INI_INIT(&ahp->ah_ini_modes, ar5212Modes, 6);
126572ff6f6SMatthew Dillon 	HAL_INI_INIT(&ahp->ah_ini_common, ar5212Common, 2);
127572ff6f6SMatthew Dillon 
128572ff6f6SMatthew Dillon 	if (!ar5312ChipReset(ah, AH_NULL)) {	/* reset chip */
129572ff6f6SMatthew Dillon 		HALDEBUG(ah, HAL_DEBUG_ANY, "%s: chip reset failed\n", __func__);
130572ff6f6SMatthew Dillon 		ecode = HAL_EIO;
131572ff6f6SMatthew Dillon 		goto bad;
132572ff6f6SMatthew Dillon 	}
133572ff6f6SMatthew Dillon 
134572ff6f6SMatthew Dillon #if ( AH_SUPPORT_2316 || AH_SUPPORT_2317)
135572ff6f6SMatthew Dillon 	if ((devid == AR5212_AR2315_REV6) ||
136572ff6f6SMatthew Dillon 	    (devid == AR5212_AR2315_REV7) ||
137572ff6f6SMatthew Dillon 	    (devid == AR5212_AR2317_REV1) ||
138572ff6f6SMatthew Dillon 	    (devid == AR5212_AR2317_REV2) ) {
139572ff6f6SMatthew Dillon 		val = ((OS_REG_READ(ah, (AR5315_RSTIMER_BASE -((uint32_t) sh)) + AR5315_WREV)) >> AR5315_WREV_S)
140572ff6f6SMatthew Dillon 			& AR5315_WREV_ID;
141572ff6f6SMatthew Dillon 		AH_PRIVATE(ah)->ah_macVersion = val >> AR5315_WREV_ID_S;
142572ff6f6SMatthew Dillon 		AH_PRIVATE(ah)->ah_macRev = val & AR5315_WREV_REVISION;
143572ff6f6SMatthew Dillon 		HALDEBUG(ah, HAL_DEBUG_ATTACH,
144572ff6f6SMatthew Dillon 		    "%s: Mac Chip Rev 0x%02x.%x\n" , __func__,
145572ff6f6SMatthew Dillon 		    AH_PRIVATE(ah)->ah_macVersion, AH_PRIVATE(ah)->ah_macRev);
146572ff6f6SMatthew Dillon 	} else
147572ff6f6SMatthew Dillon #endif
148572ff6f6SMatthew Dillon 	{
149572ff6f6SMatthew Dillon 		val = OS_REG_READ(ah, (AR5312_RSTIMER_BASE - ((uint32_t) sh)) + 0x0020);
150572ff6f6SMatthew Dillon 		val = OS_REG_READ(ah, (AR5312_RSTIMER_BASE - ((uint32_t) sh)) + 0x0080);
151572ff6f6SMatthew Dillon 		/* Read Revisions from Chips */
152572ff6f6SMatthew Dillon 		val = ((OS_REG_READ(ah, (AR5312_RSTIMER_BASE - ((uint32_t) sh)) + AR5312_WREV)) >> AR5312_WREV_S) & AR5312_WREV_ID;
153572ff6f6SMatthew Dillon 		AH_PRIVATE(ah)->ah_macVersion = val >> AR5312_WREV_ID_S;
154572ff6f6SMatthew Dillon 		AH_PRIVATE(ah)->ah_macRev = val & AR5312_WREV_REVISION;
155572ff6f6SMatthew Dillon 	}
156572ff6f6SMatthew Dillon 	/* XXX - THIS IS WRONG. NEEDS TO BE FIXED */
157572ff6f6SMatthew Dillon 	if (((AH_PRIVATE(ah)->ah_macVersion != AR_SREV_VERSION_VENICE &&
158572ff6f6SMatthew Dillon               AH_PRIVATE(ah)->ah_macVersion != AR_SREV_VERSION_VENICE) ||
159572ff6f6SMatthew Dillon              AH_PRIVATE(ah)->ah_macRev < AR_SREV_D2PLUS) &&
160572ff6f6SMatthew Dillon               AH_PRIVATE(ah)->ah_macVersion != AR_SREV_VERSION_COBRA) {
161572ff6f6SMatthew Dillon #ifdef AH_DEBUG
162572ff6f6SMatthew Dillon 		ath_hal_printf(ah, "%s: Mac Chip Rev 0x%02x.%x is not supported by "
163572ff6f6SMatthew Dillon                          "this driver\n", __func__,
164572ff6f6SMatthew Dillon                          AH_PRIVATE(ah)->ah_macVersion,
165572ff6f6SMatthew Dillon                          AH_PRIVATE(ah)->ah_macRev);
166572ff6f6SMatthew Dillon #endif
167572ff6f6SMatthew Dillon 		ecode = HAL_ENOTSUPP;
168572ff6f6SMatthew Dillon 		goto bad;
169572ff6f6SMatthew Dillon 	}
170572ff6f6SMatthew Dillon 
171572ff6f6SMatthew Dillon 	AH_PRIVATE(ah)->ah_phyRev = OS_REG_READ(ah, AR_PHY_CHIP_ID);
172572ff6f6SMatthew Dillon 
173572ff6f6SMatthew Dillon 	if (!ar5212ChipTest(ah)) {
174572ff6f6SMatthew Dillon 		HALDEBUG(ah, HAL_DEBUG_ANY, "%s: hardware self-test failed\n",
175572ff6f6SMatthew Dillon 		    __func__);
176572ff6f6SMatthew Dillon 		ecode = HAL_ESELFTEST;
177572ff6f6SMatthew Dillon 		goto bad;
178572ff6f6SMatthew Dillon 	}
179572ff6f6SMatthew Dillon 
180572ff6f6SMatthew Dillon 	/*
181572ff6f6SMatthew Dillon 	 * Set correct Baseband to analog shift
182572ff6f6SMatthew Dillon 	 * setting to access analog chips.
183572ff6f6SMatthew Dillon 	 */
184572ff6f6SMatthew Dillon 	OS_REG_WRITE(ah, AR_PHY(0), 0x00000007);
185572ff6f6SMatthew Dillon 
186572ff6f6SMatthew Dillon 	/* Read Radio Chip Rev Extract */
187572ff6f6SMatthew Dillon 	AH_PRIVATE(ah)->ah_analog5GhzRev = ar5212GetRadioRev(ah);
188572ff6f6SMatthew Dillon 
189572ff6f6SMatthew Dillon 	rf = ath_hal_rfprobe(ah, &ecode);
190572ff6f6SMatthew Dillon 	if (rf == AH_NULL)
191572ff6f6SMatthew Dillon 		goto bad;
192572ff6f6SMatthew Dillon 	if (IS_RAD5112(ah) && !IS_RADX112_REV2(ah)) {
193572ff6f6SMatthew Dillon #ifdef AH_DEBUG
194572ff6f6SMatthew Dillon 		ath_hal_printf(ah, "%s: 5112 Rev 1 is not supported by this "
195572ff6f6SMatthew Dillon                          "driver (analog5GhzRev 0x%x)\n", __func__,
196572ff6f6SMatthew Dillon                          AH_PRIVATE(ah)->ah_analog5GhzRev);
197572ff6f6SMatthew Dillon #endif
198572ff6f6SMatthew Dillon 		ecode = HAL_ENOTSUPP;
199572ff6f6SMatthew Dillon 		goto bad;
200572ff6f6SMatthew Dillon 	}
201572ff6f6SMatthew Dillon 
202572ff6f6SMatthew Dillon 	ecode = ath_hal_legacyEepromAttach(ah);
203572ff6f6SMatthew Dillon 	if (ecode != HAL_OK) {
204572ff6f6SMatthew Dillon 		goto bad;
205572ff6f6SMatthew Dillon 	}
206572ff6f6SMatthew Dillon 
207572ff6f6SMatthew Dillon 	/*
208572ff6f6SMatthew Dillon 	 * If Bmode and AR5212, verify 2.4 analog exists
209572ff6f6SMatthew Dillon 	 */
210572ff6f6SMatthew Dillon 	if (ath_hal_eepromGetFlag(ah, AR_EEP_BMODE) &&
211572ff6f6SMatthew Dillon 	    (AH_PRIVATE(ah)->ah_analog5GhzRev & 0xF0) == AR_RAD5111_SREV_MAJOR) {
212572ff6f6SMatthew Dillon 		/*
213572ff6f6SMatthew Dillon 		 * Set correct Baseband to analog shift
214572ff6f6SMatthew Dillon 		 * setting to access analog chips.
215572ff6f6SMatthew Dillon 		 */
216572ff6f6SMatthew Dillon 		OS_REG_WRITE(ah, AR_PHY(0), 0x00004007);
217572ff6f6SMatthew Dillon 		OS_DELAY(2000);
218572ff6f6SMatthew Dillon 		AH_PRIVATE(ah)->ah_analog2GhzRev = ar5212GetRadioRev(ah);
219572ff6f6SMatthew Dillon 
220572ff6f6SMatthew Dillon 		/* Set baseband for 5GHz chip */
221572ff6f6SMatthew Dillon 		OS_REG_WRITE(ah, AR_PHY(0), 0x00000007);
222572ff6f6SMatthew Dillon 		OS_DELAY(2000);
223572ff6f6SMatthew Dillon 		if ((AH_PRIVATE(ah)->ah_analog2GhzRev & 0xF0) != AR_RAD2111_SREV_MAJOR) {
224572ff6f6SMatthew Dillon #ifdef AH_DEBUG
225572ff6f6SMatthew Dillon 			ath_hal_printf(ah, "%s: 2G Radio Chip Rev 0x%02X is not "
226572ff6f6SMatthew Dillon 				"supported by this driver\n", __func__,
227572ff6f6SMatthew Dillon 				AH_PRIVATE(ah)->ah_analog2GhzRev);
228572ff6f6SMatthew Dillon #endif
229572ff6f6SMatthew Dillon 			ecode = HAL_ENOTSUPP;
230572ff6f6SMatthew Dillon 			goto bad;
231572ff6f6SMatthew Dillon 		}
232572ff6f6SMatthew Dillon 	}
233572ff6f6SMatthew Dillon 
234572ff6f6SMatthew Dillon 	ecode = ath_hal_eepromGet(ah, AR_EEP_REGDMN_0, &eeval);
235572ff6f6SMatthew Dillon 	if (ecode != HAL_OK) {
236572ff6f6SMatthew Dillon 		HALDEBUG(ah, HAL_DEBUG_ANY,
237572ff6f6SMatthew Dillon 		    "%s: cannot read regulatory domain from EEPROM\n",
238572ff6f6SMatthew Dillon 		    __func__);
239572ff6f6SMatthew Dillon 		goto bad;
240572ff6f6SMatthew Dillon         }
241572ff6f6SMatthew Dillon 	AH_PRIVATE(ah)->ah_currentRD = eeval;
242572ff6f6SMatthew Dillon 	/* XXX record serial number */
243572ff6f6SMatthew Dillon 
244572ff6f6SMatthew Dillon 	/* XXX other capabilities */
245572ff6f6SMatthew Dillon 	/*
246572ff6f6SMatthew Dillon 	 * Got everything we need now to setup the capabilities.
247572ff6f6SMatthew Dillon 	 */
248572ff6f6SMatthew Dillon 	if (!ar5212FillCapabilityInfo(ah)) {
249572ff6f6SMatthew Dillon 		HALDEBUG(ah, HAL_DEBUG_ANY,
250572ff6f6SMatthew Dillon 		    "%s: failed ar5212FillCapabilityInfo\n", __func__);
251572ff6f6SMatthew Dillon 		ecode = HAL_EEREAD;
252572ff6f6SMatthew Dillon 		goto bad;
253572ff6f6SMatthew Dillon 	}
254572ff6f6SMatthew Dillon 
255572ff6f6SMatthew Dillon 	if (!rf->attach(ah, &ecode)) {
256572ff6f6SMatthew Dillon 		HALDEBUG(ah, HAL_DEBUG_ANY, "%s: RF setup failed, status %u\n",
257572ff6f6SMatthew Dillon 		    __func__, ecode);
258572ff6f6SMatthew Dillon 		goto bad;
259572ff6f6SMatthew Dillon 	}
260572ff6f6SMatthew Dillon 	/* arrange a direct call instead of thunking */
261572ff6f6SMatthew Dillon 	AH_PRIVATE(ah)->ah_getNfAdjust = ahp->ah_rfHal->getNfAdjust;
262572ff6f6SMatthew Dillon 
263572ff6f6SMatthew Dillon 	/* Initialize gain ladder thermal calibration structure */
264572ff6f6SMatthew Dillon 	ar5212InitializeGainValues(ah);
265572ff6f6SMatthew Dillon 
266572ff6f6SMatthew Dillon         /* BSP specific call for MAC address of this WMAC device */
267572ff6f6SMatthew Dillon         if (!ar5312GetMacAddr(ah)) {
268572ff6f6SMatthew Dillon                 ecode = HAL_EEBADMAC;
269572ff6f6SMatthew Dillon                 goto bad;
270572ff6f6SMatthew Dillon         }
271572ff6f6SMatthew Dillon 
272572ff6f6SMatthew Dillon 	ar5312AniSetup(ah);
273572ff6f6SMatthew Dillon 	ar5212InitNfCalHistBuffer(ah);
274572ff6f6SMatthew Dillon 
275572ff6f6SMatthew Dillon 	/* XXX EAR stuff goes here */
276572ff6f6SMatthew Dillon 	return ah;
277572ff6f6SMatthew Dillon 
278572ff6f6SMatthew Dillon bad:
279572ff6f6SMatthew Dillon 	if (ahp)
280572ff6f6SMatthew Dillon 		ar5212Detach((struct ath_hal *) ahp);
281572ff6f6SMatthew Dillon 	if (status)
282572ff6f6SMatthew Dillon 		*status = ecode;
283572ff6f6SMatthew Dillon 	return AH_NULL;
284572ff6f6SMatthew Dillon }
285572ff6f6SMatthew Dillon 
286572ff6f6SMatthew Dillon static HAL_BOOL
ar5312GetMacAddr(struct ath_hal * ah)287572ff6f6SMatthew Dillon ar5312GetMacAddr(struct ath_hal *ah)
288572ff6f6SMatthew Dillon {
289572ff6f6SMatthew Dillon 	const struct ar531x_boarddata *board = AR5312_BOARDCONFIG(ah);
290572ff6f6SMatthew Dillon         int wlanNum = AR5312_UNIT(ah);
291572ff6f6SMatthew Dillon         const uint8_t *macAddr;
292572ff6f6SMatthew Dillon 
293572ff6f6SMatthew Dillon 	switch (wlanNum) {
294572ff6f6SMatthew Dillon 	case 0:
295572ff6f6SMatthew Dillon 		macAddr = board->wlan0Mac;
296572ff6f6SMatthew Dillon 		break;
297572ff6f6SMatthew Dillon 	case 1:
298572ff6f6SMatthew Dillon 		macAddr = board->wlan1Mac;
299572ff6f6SMatthew Dillon 		break;
300572ff6f6SMatthew Dillon 	default:
301572ff6f6SMatthew Dillon #ifdef AH_DEBUG
302572ff6f6SMatthew Dillon 		ath_hal_printf(ah, "Invalid WLAN wmac index (%d)\n",
303572ff6f6SMatthew Dillon 			       wlanNum);
304572ff6f6SMatthew Dillon #endif
305572ff6f6SMatthew Dillon 		return AH_FALSE;
306572ff6f6SMatthew Dillon 	}
307572ff6f6SMatthew Dillon 	OS_MEMCPY(AH5212(ah)->ah_macaddr, macAddr, 6);
308572ff6f6SMatthew Dillon 	return AH_TRUE;
309572ff6f6SMatthew Dillon }
310572ff6f6SMatthew Dillon 
311572ff6f6SMatthew Dillon static const char*
ar5312Probe(uint16_t vendorid,uint16_t devid)312572ff6f6SMatthew Dillon ar5312Probe(uint16_t vendorid, uint16_t devid)
313572ff6f6SMatthew Dillon {
314572ff6f6SMatthew Dillon 	if (vendorid == ATHEROS_VENDOR_ID) {
315572ff6f6SMatthew Dillon 		switch (devid) {
316572ff6f6SMatthew Dillon 		case AR5212_AR5312_REV2:
317572ff6f6SMatthew Dillon 		case AR5212_AR5312_REV7:
318572ff6f6SMatthew Dillon 			return "Atheros 5312 WiSoC";
319572ff6f6SMatthew Dillon 		case AR5212_AR2313_REV8:
320572ff6f6SMatthew Dillon 			return "Atheros 2313 WiSoC";
321572ff6f6SMatthew Dillon 		case AR5212_AR2315_REV6:
322572ff6f6SMatthew Dillon 		case AR5212_AR2315_REV7:
323572ff6f6SMatthew Dillon 			return "Atheros 2315 WiSoC";
324572ff6f6SMatthew Dillon 		case AR5212_AR2317_REV1:
325572ff6f6SMatthew Dillon 		case AR5212_AR2317_REV2:
326572ff6f6SMatthew Dillon 			return "Atheros 2317 WiSoC";
327572ff6f6SMatthew Dillon 		case AR5212_AR2413:
328572ff6f6SMatthew Dillon 			return "Atheros 2413";
329572ff6f6SMatthew Dillon 		case AR5212_AR2417:
330572ff6f6SMatthew Dillon 			return "Atheros 2417";
331572ff6f6SMatthew Dillon 		}
332572ff6f6SMatthew Dillon 	}
333572ff6f6SMatthew Dillon 	return AH_NULL;
334572ff6f6SMatthew Dillon }
335572ff6f6SMatthew Dillon AH_CHIP(AR5312, ar5312Probe, ar5312Attach);
336