Index: uspace/drv/nic/ar9271/hw.c
===================================================================
--- uspace/drv/nic/ar9271/hw.c	(revision 053fc2bcb6fbea6b3e6edf10ca784c77402816d4)
+++ uspace/drv/nic/ar9271/hw.c	(revision 8a64320e304a59746f5987caeba986e6baf11dd7)
@@ -38,30 +38,28 @@
 #include <nic.h>
 #include <ieee80211.h>
-
 #include "hw.h"
 #include "wmi.h"
 
-/**
- * Try to wait for register value repeatedly until timeout is reached.
- * 
+/** Try to wait for register value repeatedly until timeout is reached.
+ *
  * @param ar9271 Device structure.
  * @param offset Registry offset (address) to be read.
- * @param mask Mask to apply on read result.
- * @param value Required value we are waiting for.
- * 
- * @return EOK if succeed, ETIMEOUT on timeout, negative error code otherwise.
+ * @param mask   Mask to apply on read result.
+ * @param value  Required value we are waiting for.
+ *
+ * @return EOK if succeed, ETIMEOUT on timeout,
+ *         negative error code otherwise.
+ *
  */
 static int hw_read_wait(ar9271_t *ar9271, uint32_t offset, uint32_t mask,
-	uint32_t value)
-{
-	uint32_t result;
-	
-	for(size_t i = 0; i < HW_WAIT_LOOPS; i++) {
+    uint32_t value)
+{
+	for (size_t i = 0; i < HW_WAIT_LOOPS; i++) {
 		udelay(HW_WAIT_TIME_US);
-
+		
+		uint32_t result;
 		wmi_reg_read(ar9271->htc_device, offset, &result);
-		if((result & mask) == value) {
+		if ((result & mask) == value)
 			return EOK;
-		}
 	}
 	
@@ -74,6 +72,6 @@
 		{
 			.offset = AR9271_RTC_FORCE_WAKE,
-			.value = AR9271_RTC_FORCE_WAKE_ENABLE | 
-				AR9271_RTC_FORCE_WAKE_ON_INT
+			.value = AR9271_RTC_FORCE_WAKE_ENABLE |
+			    AR9271_RTC_FORCE_WAKE_ON_INT
 		},
 		{
@@ -88,5 +86,5 @@
 	
 	wmi_reg_buffer_write(ar9271->htc_device, buffer,
-		sizeof(buffer) / sizeof(wmi_reg_t));
+	    sizeof(buffer) / sizeof(wmi_reg_t));
 	
 	udelay(2);
@@ -95,9 +93,9 @@
 	wmi_reg_write(ar9271->htc_device, AR9271_RTC_RESET, 1);
 	
-	int rc = hw_read_wait(ar9271, 
-		AR9271_RTC_STATUS, 
-		AR9271_RTC_STATUS_MASK, 
-		AR9271_RTC_STATUS_ON);
-	if(rc != EOK) {
+	int rc = hw_read_wait(ar9271,
+	    AR9271_RTC_STATUS,
+	    AR9271_RTC_STATUS_MASK,
+	    AR9271_RTC_STATUS_ON);
+	if (rc != EOK) {
 		usb_log_error("Failed to wait for RTC wake up register.\n");
 		return rc;
@@ -111,13 +109,12 @@
 	uint32_t reset_value = AR9271_RTC_RC_MAC_WARM;
 	
-	if(cold) {
+	if (cold)
 		reset_value |= AR9271_RTC_RC_MAC_COLD;
-	}
 	
 	wmi_reg_t buffer[] = {
 		{
 			.offset = AR9271_RTC_FORCE_WAKE,
-			.value = AR9271_RTC_FORCE_WAKE_ENABLE | 
-				AR9271_RTC_FORCE_WAKE_ON_INT
+			.value = AR9271_RTC_FORCE_WAKE_ENABLE |
+			    AR9271_RTC_FORCE_WAKE_ON_INT
 		},
 		{
@@ -131,6 +128,6 @@
 	};
 	
-	wmi_reg_buffer_write(ar9271->htc_device, buffer, 
-		sizeof(buffer) / sizeof(wmi_reg_t));
+	wmi_reg_buffer_write(ar9271->htc_device, buffer,
+	    sizeof(buffer) / sizeof(wmi_reg_t));
 	
 	udelay(100);
@@ -139,5 +136,5 @@
 	
 	int rc = hw_read_wait(ar9271, AR9271_RTC_RC, AR9271_RTC_RC_MASK, 0);
-	if(rc != EOK) {
+	if (rc != EOK) {
 		usb_log_error("Failed to wait for RTC RC register.\n");
 		return rc;
@@ -145,6 +142,6 @@
 	
 	wmi_reg_write(ar9271->htc_device, AR9271_RC, 0);
-	wmi_reg_clear_bit(ar9271->htc_device, AR9271_STATION_ID1, 
-		AR9271_STATION_ID1_POWER_SAVING);
+	wmi_reg_clear_bit(ar9271->htc_device, AR9271_STATION_ID1,
+	    AR9271_STATION_ID1_POWER_SAVING);
 	
 	return EOK;
@@ -156,8 +153,7 @@
 	nic_address_t ar9271_address;
 	
-	for(int i = 0; i < 3; i++) {
-		wmi_reg_read(ar9271->htc_device, 
-			AR9271_EEPROM_MAC_ADDR_START + i*4,
-			&value);
+	for (unsigned int i = 0; i < 3; i++) {
+		wmi_reg_read(ar9271->htc_device,
+		    AR9271_EEPROM_MAC_ADDR_START + i * 4, &value);
 		
 		uint16_t two_bytes = uint16_t_be2host(value);
@@ -169,5 +165,5 @@
 	
 	int rc = nic_report_address(nic, &ar9271_address);
-	if(rc != EOK) {
+	if (rc != EOK) {
 		usb_log_error("Failed to report NIC HW address.\n");
 		return rc;
@@ -179,22 +175,22 @@
 static int hw_gpio_set_output(ar9271_t *ar9271, uint32_t gpio, uint32_t type)
 {
-	uint32_t address, gpio_shift, temp;
-	
-	if(gpio > 11) {
+	uint32_t address;
+	
+	if (gpio > 11)
 		address = AR9271_GPIO_OUT_MUX3;
-	} else if(gpio > 5) {
+	else if (gpio > 5)
 		address = AR9271_GPIO_OUT_MUX2;
-	} else {
+	else
 		address = AR9271_GPIO_OUT_MUX1;
-	}
-	
-	gpio_shift = (gpio % 6) * 5;
-	
+	
+	uint32_t gpio_shift = (gpio % 6) * 5;
+	
+	uint32_t temp;
 	wmi_reg_read(ar9271->htc_device, address, &temp);
-
-	temp = ((temp & 0x1F0) << 1) | (temp & ~0x1F0);
+	
+	temp = ((temp & 0x1f0) << 1) | (temp & ~0x1f0);
 	temp &= ~(0x1f << gpio_shift);
 	temp |= (type << gpio_shift);
-
+	
 	wmi_reg_write(ar9271->htc_device, address, temp);
 	
@@ -202,6 +198,6 @@
 	
 	wmi_reg_set_clear_bit(ar9271->htc_device, AR9271_GPIO_OE_OUT,
-		AR9271_GPIO_OE_OUT_ALWAYS << gpio_shift, 
-		AR9271_GPIO_OE_OUT_ALWAYS << gpio_shift);
+	    AR9271_GPIO_OE_OUT_ALWAYS << gpio_shift,
+	    AR9271_GPIO_OE_OUT_ALWAYS << gpio_shift);
 	
 	return EOK;
@@ -211,19 +207,19 @@
 {
 	wmi_reg_set_clear_bit(ar9271->htc_device, AR9271_GPIO_IN_OUT,
-		(~value & 1) << gpio, 1 << gpio);
-	return EOK;
-}
-
-/**
- * Hardware init procedure of AR9271 device.
- * 
+	    (~value & 1) << gpio, 1 << gpio);
+	return EOK;
+}
+
+/**Hardware init procedure of AR9271 device.
+ *
  * @param ar9271 Device structure.
- * 
+ *
  * @return EOK if succeed, negative error code otherwise.
+ *
  */
 static int hw_init_proc(ar9271_t *ar9271)
 {
 	int rc = hw_reset_power_on(ar9271);
-	if(rc != EOK) {
+	if (rc != EOK) {
 		usb_log_error("Failed to HW reset power on.\n");
 		return rc;
@@ -231,5 +227,5 @@
 	
 	rc = hw_set_reset(ar9271, false);
-	if(rc != EOK) {
+	if (rc != EOK) {
 		usb_log_error("Failed to HW warm reset.\n");
 		return rc;
@@ -237,5 +233,5 @@
 	
 	rc = hw_addr_init(ar9271);
-	if(rc != EOK) {
+	if (rc != EOK) {
 		usb_log_error("Failed to init HW addr.\n");
 		return rc;
@@ -247,7 +243,7 @@
 static int hw_init_led(ar9271_t *ar9271)
 {
-	int rc = hw_gpio_set_output(ar9271, AR9271_LED_PIN, 
-		AR9271_GPIO_OUT_MUX_AS_OUT);
-	if(rc != EOK) {
+	int rc = hw_gpio_set_output(ar9271, AR9271_LED_PIN,
+	    AR9271_GPIO_OUT_MUX_AS_OUT);
+	if (rc != EOK) {
 		usb_log_error("Failed to set led GPIO to output.\n");
 		return rc;
@@ -255,5 +251,5 @@
 	
 	rc = hw_gpio_set_value(ar9271, AR9271_LED_PIN, 0);
-	if(rc != EOK) {
+	if (rc != EOK) {
 		usb_log_error("Failed to init bring up GPIO led.\n");
 		return rc;
@@ -271,26 +267,25 @@
 }
 
-static int hw_set_operating_mode(ar9271_t *ar9271, 
-	ieee80211_operating_mode_t op_mode)
+static int hw_set_operating_mode(ar9271_t *ar9271,
+    ieee80211_operating_mode_t op_mode)
 {
 	uint32_t set_bit = 0x10000000;
 	
 	switch(op_mode) {
-		case IEEE80211_OPMODE_ADHOC:
-			set_bit |= AR9271_OPMODE_ADHOC_MASK;
-			wmi_reg_set_bit(ar9271->htc_device, AR9271_CONFIG,
-				AR9271_CONFIG_ADHOC);
-			break;
-		case IEEE80211_OPMODE_MESH:
-		case IEEE80211_OPMODE_AP:
-			set_bit |= AR9271_OPMODE_STATION_AP_MASK;
-		case IEEE80211_OPMODE_STATION:
-			wmi_reg_clear_bit(ar9271->htc_device, AR9271_CONFIG,
-				AR9271_CONFIG_ADHOC);
+	case IEEE80211_OPMODE_ADHOC:
+		set_bit |= AR9271_OPMODE_ADHOC_MASK;
+		wmi_reg_set_bit(ar9271->htc_device, AR9271_CONFIG,
+		    AR9271_CONFIG_ADHOC);
+		break;
+	case IEEE80211_OPMODE_MESH:
+	case IEEE80211_OPMODE_AP:
+		set_bit |= AR9271_OPMODE_STATION_AP_MASK;
+	case IEEE80211_OPMODE_STATION:
+		wmi_reg_clear_bit(ar9271->htc_device, AR9271_CONFIG,
+		    AR9271_CONFIG_ADHOC);
 	}
 	
 	wmi_reg_set_clear_bit(ar9271->htc_device, AR9271_STATION_ID1,
-		set_bit, 
-		AR9271_OPMODE_STATION_AP_MASK | AR9271_OPMODE_ADHOC_MASK);
+	    set_bit, AR9271_OPMODE_STATION_AP_MASK | AR9271_OPMODE_ADHOC_MASK);
 	
 	ieee80211_report_current_op_mode(ar9271->ieee80211_dev, op_mode);
@@ -302,5 +297,5 @@
 {
 	int rc = hw_set_operating_mode(ar9271, IEEE80211_OPMODE_STATION);
-	if(rc != EOK) {
+	if (rc != EOK) {
 		usb_log_error("Failed to set opmode to station.\n");
 		return rc;
@@ -314,32 +309,34 @@
 	uint32_t value;
 	wmi_reg_read(ar9271->htc_device, AR9271_PHY_CAL, &value);
-	value &= 0xFFFFFE00;
-	value |= (((uint32_t) AR9271_CALIB_NOMINAL_VALUE_2GHZ << 1) & 0x1FF);
+	
+	value &= 0xfffffe00;
+	value |= (((uint32_t) AR9271_CALIB_NOMINAL_VALUE_2GHZ << 1) & 0x1ff);
+	
 	wmi_reg_write(ar9271->htc_device, AR9271_PHY_CAL, value);
 	
-	wmi_reg_clear_bit(ar9271->htc_device, AR9271_AGC_CONTROL, 
-		AR9271_AGC_CONTROL_NF_CALIB_EN);
-	
-	wmi_reg_clear_bit(ar9271->htc_device, AR9271_AGC_CONTROL, 
-		AR9271_AGC_CONTROL_NF_NOT_UPDATE);
-	
-	wmi_reg_set_bit(ar9271->htc_device, AR9271_AGC_CONTROL, 
-		AR9271_AGC_CONTROL_NF_CALIB);
-	
-	int rc = hw_read_wait(ar9271, AR9271_AGC_CONTROL, 
-		AR9271_AGC_CONTROL_NF_CALIB, 0);
-	if(rc != EOK) {
+	wmi_reg_clear_bit(ar9271->htc_device, AR9271_AGC_CONTROL,
+	    AR9271_AGC_CONTROL_NF_CALIB_EN);
+	
+	wmi_reg_clear_bit(ar9271->htc_device, AR9271_AGC_CONTROL,
+	    AR9271_AGC_CONTROL_NF_NOT_UPDATE);
+	
+	wmi_reg_set_bit(ar9271->htc_device, AR9271_AGC_CONTROL,
+	    AR9271_AGC_CONTROL_NF_CALIB);
+	
+	int rc = hw_read_wait(ar9271, AR9271_AGC_CONTROL,
+	    AR9271_AGC_CONTROL_NF_CALIB, 0);
+	if (rc != EOK) {
 		usb_log_error("Failed to wait for NF calibration.\n");
 		return rc;
 	}
 	
-	wmi_reg_set_bit(ar9271->htc_device, AR9271_AGC_CONTROL, 
-		AR9271_AGC_CONTROL_NF_CALIB_EN);
-	
-	wmi_reg_clear_bit(ar9271->htc_device, AR9271_AGC_CONTROL, 
-		AR9271_AGC_CONTROL_NF_NOT_UPDATE);
-	
-	wmi_reg_set_bit(ar9271->htc_device, AR9271_AGC_CONTROL, 
-		AR9271_AGC_CONTROL_NF_CALIB);
+	wmi_reg_set_bit(ar9271->htc_device, AR9271_AGC_CONTROL,
+	    AR9271_AGC_CONTROL_NF_CALIB_EN);
+	
+	wmi_reg_clear_bit(ar9271->htc_device, AR9271_AGC_CONTROL,
+	    AR9271_AGC_CONTROL_NF_NOT_UPDATE);
+	
+	wmi_reg_set_bit(ar9271->htc_device, AR9271_AGC_CONTROL,
+	    AR9271_AGC_CONTROL_NF_CALIB);
 	
 	return EOK;
@@ -349,22 +346,20 @@
 {
 	/* Not supported channel frequency. */
-	if(freq < IEEE80211_FIRST_FREQ || freq > IEEE80211_MAX_FREQ) {
+	if ((freq < IEEE80211_FIRST_FREQ) || (freq > IEEE80211_MAX_FREQ))
 		return EINVAL;
-	}
 	
 	/* Not supported channel frequency. */
-	if((freq - IEEE80211_FIRST_FREQ) % IEEE80211_CHANNEL_GAP != 0) {
+	if ((freq - IEEE80211_FIRST_FREQ) % IEEE80211_CHANNEL_GAP != 0)
 		return EINVAL;
-	}
 	
 	uint32_t tx_control;
 	wmi_reg_read(ar9271->htc_device, AR9271_PHY_CCK_TX_CTRL, &tx_control);
 	wmi_reg_write(ar9271->htc_device, AR9271_PHY_CCK_TX_CTRL,
-		tx_control & ~AR9271_PHY_CCK_TX_CTRL_JAPAN);
+	    tx_control & ~AR9271_PHY_CCK_TX_CTRL_JAPAN);
 	
 	/* Some magic here. */
 	uint32_t synth_ctl;
 	wmi_reg_read(ar9271->htc_device, AR9271_PHY_SYNTH_CONTROL, &synth_ctl);
-	synth_ctl &= 0xC0000000;
+	synth_ctl &= 0xc0000000;
 	uint32_t channel_select = (freq * 0x10000) / 15;
 	synth_ctl = synth_ctl | (1 << 29) | (1 << 28) | channel_select;
@@ -382,5 +377,5 @@
 	
 	int rc = hw_read_wait(ar9271, AR9271_PHY_RFBUS_GRANT, 0x1, 0x1);
-	if(rc != EOK) {
+	if (rc != EOK) {
 		usb_log_error("Failed to kill RF bus.\n");
 		return rc;
@@ -388,5 +383,5 @@
 	
 	rc = hw_set_freq(ar9271, freq);
-	if(rc != EOK) {
+	if (rc != EOK) {
 		usb_log_error("Failed to HW set frequency.\n");
 		return rc;
@@ -394,5 +389,5 @@
 	
 	rc = hw_activate_phy(ar9271);
-	if(rc != EOK) {
+	if (rc != EOK) {
 		usb_log_error("Failed to activate physical layer.\n");
 		return rc;
@@ -403,5 +398,5 @@
 	
 	rc = hw_noise_floor_calibration(ar9271);
-	if(rc != EOK) {
+	if (rc != EOK) {
 		usb_log_error("Failed to do NF calibration.\n");
 		return rc;
@@ -413,16 +408,14 @@
 int hw_set_rx_filter(ar9271_t *ar9271, bool assoc)
 {
-	uint32_t filter_bits;
-	
 	uint32_t additional_bits = 0;
 	
-	if(assoc) {
+	if (assoc)
 		additional_bits |= AR9271_RX_FILTER_MYBEACON;
-	} else {
+	else
 		additional_bits |= AR9271_RX_FILTER_BEACON;
-	}
-	
-	filter_bits = AR9271_RX_FILTER_UNI | AR9271_RX_FILTER_MULTI | 
-		AR9271_RX_FILTER_BROAD | additional_bits;
+	
+	uint32_t filter_bits = AR9271_RX_FILTER_UNI |
+	    AR9271_RX_FILTER_MULTI | AR9271_RX_FILTER_BROAD |
+	    additional_bits;
 	
 	wmi_reg_write(ar9271->htc_device, AR9271_RX_FILTER, filter_bits);
@@ -441,10 +434,10 @@
 	uint16_t *last_2bytes = (uint16_t *) &bssid.address[4];
 	
-	wmi_reg_write(ar9271->htc_device, AR9271_BSSID0, 
-		uint32_t_le2host(*first_4bytes));
-	
-	wmi_reg_write(ar9271->htc_device, AR9271_BSSID1, 
-		uint16_t_le2host(*last_2bytes) | 
-		((ieee80211_get_aid(ieee80211_dev) & 0x3FFF) << 16));
+	wmi_reg_write(ar9271->htc_device, AR9271_BSSID0,
+	    uint32_t_le2host(*first_4bytes));
+	
+	wmi_reg_write(ar9271->htc_device, AR9271_BSSID1,
+	    uint16_t_le2host(*last_2bytes) |
+	    ((ieee80211_get_aid(ieee80211_dev) & 0x3fff) << 16));
 	
 	return EOK;
@@ -453,9 +446,9 @@
 int hw_rx_init(ar9271_t *ar9271)
 {
-	wmi_reg_write(ar9271->htc_device, AR9271_COMMAND, 
-		AR9271_COMMAND_RX_ENABLE);
+	wmi_reg_write(ar9271->htc_device, AR9271_COMMAND,
+	    AR9271_COMMAND_RX_ENABLE);
 	
 	int rc = hw_set_rx_filter(ar9271, false);
-	if(rc != EOK) {
+	if (rc != EOK) {
 		usb_log_error("Failed to set RX filtering.\n");
 		return rc;
@@ -473,15 +466,13 @@
 static int hw_init_pll(ar9271_t *ar9271)
 {
-	uint32_t pll;
-	
 	/* Some magic here (set for 2GHz channels). But VERY important :-) */
-	pll = (0x5 << 10) | 0x2C;
+	uint32_t pll = (0x5 << 10) | 0x2c;
 	
 	wmi_reg_write(ar9271->htc_device, AR9271_RTC_PLL_CONTROL, pll);
 	
 	wmi_reg_write(ar9271->htc_device, AR9271_RTC_SLEEP_CLOCK,
-		AR9271_RTC_SLEEP_CLOCK_FORCE_DERIVED);
+	    AR9271_RTC_SLEEP_CLOCK_FORCE_DERIVED);
 	wmi_reg_set_bit(ar9271->htc_device, AR9271_RTC_FORCE_WAKE,
-		AR9271_RTC_FORCE_WAKE_ENABLE);
+	    AR9271_RTC_FORCE_WAKE_ENABLE);
 	
 	return EOK;
@@ -490,9 +481,10 @@
 static void hw_set_init_values(ar9271_t *ar9271)
 {
-	uint32_t reg_offset, reg_value;
-	
-	int size = ARRAY_SIZE(ar9271_2g_mode_array);
-	
-	for(int i = 0; i < size; i++) {
+	uint32_t reg_offset;
+	uint32_t reg_value;
+	
+	size_t size = ARRAY_SIZE(ar9271_2g_mode_array);
+	
+	for (size_t i = 0; i < size; i++) {
 		reg_offset = ar9271_2g_mode_array[i][0];
 		reg_value = ar9271_2g_mode_array[i][1];
@@ -502,5 +494,5 @@
 	size = ARRAY_SIZE(ar9271_2g_tx_array);
 	
-	for(int i = 0; i < size; i++) {
+	for (size_t i = 0; i < size; i++) {
 		reg_offset = ar9271_2g_tx_array[i][0];
 		reg_value = ar9271_2g_tx_array[i][1];
@@ -510,5 +502,5 @@
 	size = ARRAY_SIZE(ar9271_init_array);
 	
-	for(int i = 0; i < size; i++) {
+	for (size_t i = 0; i < size; i++) {
 		reg_offset = ar9271_init_array[i][0];
 		reg_value = ar9271_init_array[i][1];
@@ -520,17 +512,17 @@
 {
 	wmi_reg_set_bit(ar9271->htc_device, AR9271_CARRIER_LEAK_CONTROL,
-		AR9271_CARRIER_LEAK_CALIB);
+	    AR9271_CARRIER_LEAK_CALIB);
 	wmi_reg_clear_bit(ar9271->htc_device, AR9271_ADC_CONTROL,
-		AR9271_ADC_CONTROL_OFF_PWDADC);
+	    AR9271_ADC_CONTROL_OFF_PWDADC);
 	wmi_reg_set_bit(ar9271->htc_device, AR9271_AGC_CONTROL,
-		AR9271_AGC_CONTROL_TX_CALIB);
+	    AR9271_AGC_CONTROL_TX_CALIB);
 	wmi_reg_set_bit(ar9271->htc_device, AR9271_PHY_TPCRG1,
-		AR9271_PHY_TPCRG1_PD_CALIB);
+	    AR9271_PHY_TPCRG1_PD_CALIB);
 	wmi_reg_set_bit(ar9271->htc_device, AR9271_AGC_CONTROL,
-		AR9271_AGC_CONTROL_CALIB);
-	
-	int rc = hw_read_wait(ar9271, AR9271_AGC_CONTROL, 
-		AR9271_AGC_CONTROL_CALIB, 0);
-	if(rc != EOK) {
+	    AR9271_AGC_CONTROL_CALIB);
+	
+	int rc = hw_read_wait(ar9271, AR9271_AGC_CONTROL,
+	    AR9271_AGC_CONTROL_CALIB, 0);
+	if (rc != EOK) {
 		usb_log_error("Failed to wait on calibrate completion.\n");
 		return rc;
@@ -538,14 +530,14 @@
 	
 	wmi_reg_set_bit(ar9271->htc_device, AR9271_ADC_CONTROL,
-		AR9271_ADC_CONTROL_OFF_PWDADC);
+	    AR9271_ADC_CONTROL_OFF_PWDADC);
 	wmi_reg_clear_bit(ar9271->htc_device, AR9271_CARRIER_LEAK_CONTROL,
-		AR9271_CARRIER_LEAK_CALIB);
+	    AR9271_CARRIER_LEAK_CALIB);
 	wmi_reg_clear_bit(ar9271->htc_device, AR9271_AGC_CONTROL,
-		AR9271_AGC_CONTROL_TX_CALIB);
-	
-	return EOK;
-}
-
-int hw_reset(ar9271_t *ar9271) 
+	    AR9271_AGC_CONTROL_TX_CALIB);
+	
+	return EOK;
+}
+
+int hw_reset(ar9271_t *ar9271)
 {
 	/* Set physical layer as deactivated. */
@@ -553,8 +545,8 @@
 	
 	if(ar9271->starting_up) {
-		wmi_reg_write(ar9271->htc_device, 
-			AR9271_RESET_POWER_DOWN_CONTROL,
-			AR9271_RADIO_RF_RESET);
-
+		wmi_reg_write(ar9271->htc_device,
+		    AR9271_RESET_POWER_DOWN_CONTROL,
+		    AR9271_RADIO_RF_RESET);
+		
 		udelay(50);
 	}
@@ -563,10 +555,9 @@
 	uint32_t config_reg;
 	wmi_reg_read(ar9271->htc_device, AR9271_COMMAND, &config_reg);
-	if(config_reg & AR9271_COMMAND_RX_ENABLE) {
+	if (config_reg & AR9271_COMMAND_RX_ENABLE)
 		hw_set_reset(ar9271, true);
-	}
 	
 	int rc = hw_init_pll(ar9271);
-	if(rc != EOK) {
+	if (rc != EOK) {
 		usb_log_error("Failed to init PLL.\n");
 		return rc;
@@ -575,14 +566,14 @@
 	udelay(500);
 	
-	wmi_reg_write(ar9271->htc_device, AR9271_CLOCK_CONTROL,	
-		AR9271_MAX_CPU_CLOCK);
+	wmi_reg_write(ar9271->htc_device, AR9271_CLOCK_CONTROL,
+	    AR9271_MAX_CPU_CLOCK);
 	
 	udelay(100);
 	
-	if(ar9271->starting_up) {
-		wmi_reg_write(ar9271->htc_device, 
-			AR9271_RESET_POWER_DOWN_CONTROL,
-			AR9271_GATE_MAC_CONTROL);
-
+	if (ar9271->starting_up) {
+		wmi_reg_write(ar9271->htc_device,
+		    AR9271_RESET_POWER_DOWN_CONTROL,
+		    AR9271_GATE_MAC_CONTROL);
+		
 		udelay(50);
 	}
@@ -591,10 +582,10 @@
 	
 	/* Set physical layer mode. */
-	wmi_reg_write(ar9271->htc_device, AR9271_PHY_MODE, 
-		AR9271_PHY_MODE_DYNAMIC);
+	wmi_reg_write(ar9271->htc_device, AR9271_PHY_MODE,
+	    AR9271_PHY_MODE_DYNAMIC);
 	
 	/* Reset device operating mode. */
 	rc = hw_reset_operating_mode(ar9271);
-	if(rc != EOK) {
+	if (rc != EOK) {
 		usb_log_error("Failed to reset operating mode.\n");
 		return rc;
@@ -603,5 +594,5 @@
 	/* Set initial channel frequency. */
 	rc = hw_set_freq(ar9271, IEEE80211_FIRST_FREQ);
-	if(rc != EOK) {
+	if (rc != EOK) {
 		usb_log_error("Failed to set channel.\n");
 		return rc;
@@ -609,13 +600,12 @@
 	
 	/* Initialize transmission queues. */
-	for(int i = 0; i < AR9271_QUEUES_COUNT; i++) {
-		wmi_reg_write(ar9271->htc_device, 
-			AR9271_QUEUE_BASE_MASK + (i << 2),
-			1 << i);
+	for (unsigned int i = 0; i < AR9271_QUEUES_COUNT; i++) {
+		wmi_reg_write(ar9271->htc_device,
+		    AR9271_QUEUE_BASE_MASK + (i << 2), 1 << i);
 	}
 	
 	/* Activate physical layer. */
 	rc = hw_activate_phy(ar9271);
-	if(rc != EOK) {
+	if (rc != EOK) {
 		usb_log_error("Failed to activate physical layer.\n");
 		return rc;
@@ -624,5 +614,5 @@
 	/* Calibration. */
 	rc = hw_calibration(ar9271);
-	if(rc != EOK) {
+	if (rc != EOK) {
 		usb_log_error("Failed to calibrate device.\n");
 		return rc;
@@ -630,5 +620,5 @@
 	
 	rc = hw_noise_floor_calibration(ar9271);
-	if(rc != EOK) {
+	if (rc != EOK) {
 		usb_log_error("Failed to calibrate noise floor.\n");
 		return rc;
@@ -641,9 +631,8 @@
 }
 
-/**
- * Initialize hardware of AR9271 device.
- * 
+/** Initialize hardware of AR9271 device.
+ *
  * @param ar9271 Device structure.
- * 
+ *
  * @return EOK if succeed, negative error code otherwise.
  */
@@ -651,5 +640,5 @@
 {
 	int rc = hw_init_proc(ar9271);
-	if(rc != EOK) {
+	if (rc != EOK) {
 		usb_log_error("Failed to HW reset device.\n");
 		return rc;
@@ -657,5 +646,5 @@
 	
 	rc = hw_init_led(ar9271);
-	if(rc != EOK) {
+	if (rc != EOK) {
 		usb_log_error("Failed to HW init led.\n");
 		return rc;
