aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/wireless/rt2x00/rt73usb.c
diff options
context:
space:
mode:
authorIvo van Doorn <IvDoorn@gmail.com>2008-06-03 12:58:56 -0400
committerJohn W. Linville <linville@tuxdriver.com>2008-06-14 12:17:55 -0400
commit2b08da3fb595432f87b5206c1c77dcb72300cacf (patch)
treeb165baf29c47a5e58ac7f9d755942aca5d519614 /drivers/net/wireless/rt2x00/rt73usb.c
parent9dad92b9ba49eaab72513d821ae43298bcf93b90 (diff)
rt2x00: Cleanup/optimize set_state() function callback function
* Reduce goto usage * Mark if-statements which are true on hardware error unlikely() * Cleanup debug messages This makes the code look nicer and be better optimized since the chance of hardware errors should be very small. Signed-off-by: Ivo van Doorn <IvDoorn@gmail.com> Signed-off-by: John W. Linville <linville@tuxdriver.com>
Diffstat (limited to 'drivers/net/wireless/rt2x00/rt73usb.c')
-rw-r--r--drivers/net/wireless/rt2x00/rt73usb.c49
1 files changed, 28 insertions, 21 deletions
diff --git a/drivers/net/wireless/rt2x00/rt73usb.c b/drivers/net/wireless/rt2x00/rt73usb.c
index 26c2e0a1a308..aabdc67c8555 100644
--- a/drivers/net/wireless/rt2x00/rt73usb.c
+++ b/drivers/net/wireless/rt2x00/rt73usb.c
@@ -1084,25 +1084,32 @@ static int rt73usb_init_registers(struct rt2x00_dev *rt2x00dev)
1084 return 0; 1084 return 0;
1085} 1085}
1086 1086
1087static int rt73usb_init_bbp(struct rt2x00_dev *rt2x00dev) 1087static int rt73usb_wait_bbp_ready(struct rt2x00_dev *rt2x00dev)
1088{ 1088{
1089 unsigned int i; 1089 unsigned int i;
1090 u16 eeprom;
1091 u8 reg_id;
1092 u8 value; 1090 u8 value;
1093 1091
1094 for (i = 0; i < REGISTER_BUSY_COUNT; i++) { 1092 for (i = 0; i < REGISTER_BUSY_COUNT; i++) {
1095 rt73usb_bbp_read(rt2x00dev, 0, &value); 1093 rt73usb_bbp_read(rt2x00dev, 0, &value);
1096 if ((value != 0xff) && (value != 0x00)) 1094 if ((value != 0xff) && (value != 0x00))
1097 goto continue_csr_init; 1095 return 0;
1098 NOTICE(rt2x00dev, "Waiting for BBP register.\n");
1099 udelay(REGISTER_BUSY_DELAY); 1096 udelay(REGISTER_BUSY_DELAY);
1100 } 1097 }
1101 1098
1102 ERROR(rt2x00dev, "BBP register access failed, aborting.\n"); 1099 ERROR(rt2x00dev, "BBP register access failed, aborting.\n");
1103 return -EACCES; 1100 return -EACCES;
1101}
1102
1103static int rt73usb_init_bbp(struct rt2x00_dev *rt2x00dev)
1104{
1105 unsigned int i;
1106 u16 eeprom;
1107 u8 reg_id;
1108 u8 value;
1109
1110 if (unlikely(rt73usb_wait_bbp_ready(rt2x00dev)))
1111 return -EACCES;
1104 1112
1105continue_csr_init:
1106 rt73usb_bbp_write(rt2x00dev, 3, 0x80); 1113 rt73usb_bbp_write(rt2x00dev, 3, 0x80);
1107 rt73usb_bbp_write(rt2x00dev, 15, 0x30); 1114 rt73usb_bbp_write(rt2x00dev, 15, 0x30);
1108 rt73usb_bbp_write(rt2x00dev, 21, 0xc8); 1115 rt73usb_bbp_write(rt2x00dev, 21, 0xc8);
@@ -1152,7 +1159,8 @@ static void rt73usb_toggle_rx(struct rt2x00_dev *rt2x00dev,
1152 1159
1153 rt73usb_register_read(rt2x00dev, TXRX_CSR0, &reg); 1160 rt73usb_register_read(rt2x00dev, TXRX_CSR0, &reg);
1154 rt2x00_set_field32(&reg, TXRX_CSR0_DISABLE_RX, 1161 rt2x00_set_field32(&reg, TXRX_CSR0_DISABLE_RX,
1155 state == STATE_RADIO_RX_OFF); 1162 (state == STATE_RADIO_RX_OFF) ||
1163 (state == STATE_RADIO_RX_OFF_LINK));
1156 rt73usb_register_write(rt2x00dev, TXRX_CSR0, reg); 1164 rt73usb_register_write(rt2x00dev, TXRX_CSR0, reg);
1157} 1165}
1158 1166
@@ -1161,11 +1169,9 @@ static int rt73usb_enable_radio(struct rt2x00_dev *rt2x00dev)
1161 /* 1169 /*
1162 * Initialize all registers. 1170 * Initialize all registers.
1163 */ 1171 */
1164 if (rt73usb_init_registers(rt2x00dev) || 1172 if (unlikely(rt73usb_init_registers(rt2x00dev) ||
1165 rt73usb_init_bbp(rt2x00dev)) { 1173 rt73usb_init_bbp(rt2x00dev)))
1166 ERROR(rt2x00dev, "Register initialization failed.\n");
1167 return -EIO; 1174 return -EIO;
1168 }
1169 1175
1170 return 0; 1176 return 0;
1171} 1177}
@@ -1187,7 +1193,6 @@ static int rt73usb_set_state(struct rt2x00_dev *rt2x00dev, enum dev_state state)
1187 u32 reg; 1193 u32 reg;
1188 unsigned int i; 1194 unsigned int i;
1189 char put_to_sleep; 1195 char put_to_sleep;
1190 char current_state;
1191 1196
1192 put_to_sleep = (state != STATE_AWAKE); 1197 put_to_sleep = (state != STATE_AWAKE);
1193 1198
@@ -1203,16 +1208,12 @@ static int rt73usb_set_state(struct rt2x00_dev *rt2x00dev, enum dev_state state)
1203 */ 1208 */
1204 for (i = 0; i < REGISTER_BUSY_COUNT; i++) { 1209 for (i = 0; i < REGISTER_BUSY_COUNT; i++) {
1205 rt73usb_register_read(rt2x00dev, MAC_CSR12, &reg); 1210 rt73usb_register_read(rt2x00dev, MAC_CSR12, &reg);
1206 current_state = 1211 state = rt2x00_get_field32(reg, MAC_CSR12_BBP_CURRENT_STATE);
1207 rt2x00_get_field32(reg, MAC_CSR12_BBP_CURRENT_STATE); 1212 if (state == !put_to_sleep)
1208 if (current_state == !put_to_sleep)
1209 return 0; 1213 return 0;
1210 msleep(10); 1214 msleep(10);
1211 } 1215 }
1212 1216
1213 NOTICE(rt2x00dev, "Device failed to enter state %d, "
1214 "current device state %d.\n", !put_to_sleep, current_state);
1215
1216 return -EBUSY; 1217 return -EBUSY;
1217} 1218}
1218 1219
@@ -1230,11 +1231,13 @@ static int rt73usb_set_device_state(struct rt2x00_dev *rt2x00dev,
1230 break; 1231 break;
1231 case STATE_RADIO_RX_ON: 1232 case STATE_RADIO_RX_ON:
1232 case STATE_RADIO_RX_ON_LINK: 1233 case STATE_RADIO_RX_ON_LINK:
1233 rt73usb_toggle_rx(rt2x00dev, STATE_RADIO_RX_ON);
1234 break;
1235 case STATE_RADIO_RX_OFF: 1234 case STATE_RADIO_RX_OFF:
1236 case STATE_RADIO_RX_OFF_LINK: 1235 case STATE_RADIO_RX_OFF_LINK:
1237 rt73usb_toggle_rx(rt2x00dev, STATE_RADIO_RX_OFF); 1236 rt73usb_toggle_rx(rt2x00dev, state);
1237 break;
1238 case STATE_RADIO_IRQ_ON:
1239 case STATE_RADIO_IRQ_OFF:
1240 /* No support, but no error either */
1238 break; 1241 break;
1239 case STATE_DEEP_SLEEP: 1242 case STATE_DEEP_SLEEP:
1240 case STATE_SLEEP: 1243 case STATE_SLEEP:
@@ -1247,6 +1250,10 @@ static int rt73usb_set_device_state(struct rt2x00_dev *rt2x00dev,
1247 break; 1250 break;
1248 } 1251 }
1249 1252
1253 if (unlikely(retval))
1254 ERROR(rt2x00dev, "Device failed to enter state %d (%d).\n",
1255 state, retval);
1256
1250 return retval; 1257 return retval;
1251} 1258}
1252 1259