mirror of
https://github.com/AuxXxilium/linux_dsm_epyc7002.git
synced 2024-11-26 21:30:54 +07:00
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>
This commit is contained in:
parent
9dad92b9ba
commit
2b08da3fb5
@ -781,6 +781,22 @@ static int rt2400pci_init_registers(struct rt2x00_dev *rt2x00dev)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int rt2400pci_wait_bbp_ready(struct rt2x00_dev *rt2x00dev)
|
||||
{
|
||||
unsigned int i;
|
||||
u8 value;
|
||||
|
||||
for (i = 0; i < REGISTER_BUSY_COUNT; i++) {
|
||||
rt2400pci_bbp_read(rt2x00dev, 0, &value);
|
||||
if ((value != 0xff) && (value != 0x00))
|
||||
return 0;
|
||||
udelay(REGISTER_BUSY_DELAY);
|
||||
}
|
||||
|
||||
ERROR(rt2x00dev, "BBP register access failed, aborting.\n");
|
||||
return -EACCES;
|
||||
}
|
||||
|
||||
static int rt2400pci_init_bbp(struct rt2x00_dev *rt2x00dev)
|
||||
{
|
||||
unsigned int i;
|
||||
@ -788,18 +804,9 @@ static int rt2400pci_init_bbp(struct rt2x00_dev *rt2x00dev)
|
||||
u8 reg_id;
|
||||
u8 value;
|
||||
|
||||
for (i = 0; i < REGISTER_BUSY_COUNT; i++) {
|
||||
rt2400pci_bbp_read(rt2x00dev, 0, &value);
|
||||
if ((value != 0xff) && (value != 0x00))
|
||||
goto continue_csr_init;
|
||||
NOTICE(rt2x00dev, "Waiting for BBP register.\n");
|
||||
udelay(REGISTER_BUSY_DELAY);
|
||||
}
|
||||
if (unlikely(rt2400pci_wait_bbp_ready(rt2x00dev)))
|
||||
return -EACCES;
|
||||
|
||||
ERROR(rt2x00dev, "BBP register access failed, aborting.\n");
|
||||
return -EACCES;
|
||||
|
||||
continue_csr_init:
|
||||
rt2400pci_bbp_write(rt2x00dev, 1, 0x00);
|
||||
rt2400pci_bbp_write(rt2x00dev, 3, 0x27);
|
||||
rt2400pci_bbp_write(rt2x00dev, 4, 0x08);
|
||||
@ -838,7 +845,8 @@ static void rt2400pci_toggle_rx(struct rt2x00_dev *rt2x00dev,
|
||||
|
||||
rt2x00pci_register_read(rt2x00dev, RXCSR0, ®);
|
||||
rt2x00_set_field32(®, RXCSR0_DISABLE_RX,
|
||||
state == STATE_RADIO_RX_OFF);
|
||||
(state == STATE_RADIO_RX_OFF) ||
|
||||
(state == STATE_RADIO_RX_OFF_LINK));
|
||||
rt2x00pci_register_write(rt2x00dev, RXCSR0, reg);
|
||||
}
|
||||
|
||||
@ -875,17 +883,10 @@ static int rt2400pci_enable_radio(struct rt2x00_dev *rt2x00dev)
|
||||
/*
|
||||
* Initialize all registers.
|
||||
*/
|
||||
if (rt2400pci_init_queues(rt2x00dev) ||
|
||||
rt2400pci_init_registers(rt2x00dev) ||
|
||||
rt2400pci_init_bbp(rt2x00dev)) {
|
||||
ERROR(rt2x00dev, "Register initialization failed.\n");
|
||||
if (unlikely(rt2400pci_init_queues(rt2x00dev) ||
|
||||
rt2400pci_init_registers(rt2x00dev) ||
|
||||
rt2400pci_init_bbp(rt2x00dev)))
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
/*
|
||||
* Enable interrupts.
|
||||
*/
|
||||
rt2400pci_toggle_irq(rt2x00dev, STATE_RADIO_IRQ_ON);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -907,11 +908,6 @@ static void rt2400pci_disable_radio(struct rt2x00_dev *rt2x00dev)
|
||||
rt2x00pci_register_read(rt2x00dev, TXCSR0, ®);
|
||||
rt2x00_set_field32(®, TXCSR0_ABORT, 1);
|
||||
rt2x00pci_register_write(rt2x00dev, TXCSR0, reg);
|
||||
|
||||
/*
|
||||
* Disable interrupts.
|
||||
*/
|
||||
rt2400pci_toggle_irq(rt2x00dev, STATE_RADIO_IRQ_OFF);
|
||||
}
|
||||
|
||||
static int rt2400pci_set_state(struct rt2x00_dev *rt2x00dev,
|
||||
@ -946,10 +942,6 @@ static int rt2400pci_set_state(struct rt2x00_dev *rt2x00dev,
|
||||
msleep(10);
|
||||
}
|
||||
|
||||
NOTICE(rt2x00dev, "Device failed to enter state %d, "
|
||||
"current device state: bbp %d and rf %d.\n",
|
||||
state, bbp_state, rf_state);
|
||||
|
||||
return -EBUSY;
|
||||
}
|
||||
|
||||
@ -967,11 +959,13 @@ static int rt2400pci_set_device_state(struct rt2x00_dev *rt2x00dev,
|
||||
break;
|
||||
case STATE_RADIO_RX_ON:
|
||||
case STATE_RADIO_RX_ON_LINK:
|
||||
rt2400pci_toggle_rx(rt2x00dev, STATE_RADIO_RX_ON);
|
||||
break;
|
||||
case STATE_RADIO_RX_OFF:
|
||||
case STATE_RADIO_RX_OFF_LINK:
|
||||
rt2400pci_toggle_rx(rt2x00dev, STATE_RADIO_RX_OFF);
|
||||
rt2400pci_toggle_rx(rt2x00dev, state);
|
||||
break;
|
||||
case STATE_RADIO_IRQ_ON:
|
||||
case STATE_RADIO_IRQ_OFF:
|
||||
rt2400pci_toggle_irq(rt2x00dev, state);
|
||||
break;
|
||||
case STATE_DEEP_SLEEP:
|
||||
case STATE_SLEEP:
|
||||
@ -984,6 +978,10 @@ static int rt2400pci_set_device_state(struct rt2x00_dev *rt2x00dev,
|
||||
break;
|
||||
}
|
||||
|
||||
if (unlikely(retval))
|
||||
ERROR(rt2x00dev, "Device failed to enter state %d (%d).\n",
|
||||
state, retval);
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
@ -924,6 +924,22 @@ static int rt2500pci_init_registers(struct rt2x00_dev *rt2x00dev)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int rt2500pci_wait_bbp_ready(struct rt2x00_dev *rt2x00dev)
|
||||
{
|
||||
unsigned int i;
|
||||
u8 value;
|
||||
|
||||
for (i = 0; i < REGISTER_BUSY_COUNT; i++) {
|
||||
rt2500pci_bbp_read(rt2x00dev, 0, &value);
|
||||
if ((value != 0xff) && (value != 0x00))
|
||||
return 0;
|
||||
udelay(REGISTER_BUSY_DELAY);
|
||||
}
|
||||
|
||||
ERROR(rt2x00dev, "BBP register access failed, aborting.\n");
|
||||
return -EACCES;
|
||||
}
|
||||
|
||||
static int rt2500pci_init_bbp(struct rt2x00_dev *rt2x00dev)
|
||||
{
|
||||
unsigned int i;
|
||||
@ -931,18 +947,9 @@ static int rt2500pci_init_bbp(struct rt2x00_dev *rt2x00dev)
|
||||
u8 reg_id;
|
||||
u8 value;
|
||||
|
||||
for (i = 0; i < REGISTER_BUSY_COUNT; i++) {
|
||||
rt2500pci_bbp_read(rt2x00dev, 0, &value);
|
||||
if ((value != 0xff) && (value != 0x00))
|
||||
goto continue_csr_init;
|
||||
NOTICE(rt2x00dev, "Waiting for BBP register.\n");
|
||||
udelay(REGISTER_BUSY_DELAY);
|
||||
}
|
||||
if (unlikely(rt2500pci_wait_bbp_ready(rt2x00dev)))
|
||||
return -EACCES;
|
||||
|
||||
ERROR(rt2x00dev, "BBP register access failed, aborting.\n");
|
||||
return -EACCES;
|
||||
|
||||
continue_csr_init:
|
||||
rt2500pci_bbp_write(rt2x00dev, 3, 0x02);
|
||||
rt2500pci_bbp_write(rt2x00dev, 4, 0x19);
|
||||
rt2500pci_bbp_write(rt2x00dev, 14, 0x1c);
|
||||
@ -997,7 +1004,8 @@ static void rt2500pci_toggle_rx(struct rt2x00_dev *rt2x00dev,
|
||||
|
||||
rt2x00pci_register_read(rt2x00dev, RXCSR0, ®);
|
||||
rt2x00_set_field32(®, RXCSR0_DISABLE_RX,
|
||||
state == STATE_RADIO_RX_OFF);
|
||||
(state == STATE_RADIO_RX_OFF) ||
|
||||
(state == STATE_RADIO_RX_OFF_LINK));
|
||||
rt2x00pci_register_write(rt2x00dev, RXCSR0, reg);
|
||||
}
|
||||
|
||||
@ -1034,17 +1042,10 @@ static int rt2500pci_enable_radio(struct rt2x00_dev *rt2x00dev)
|
||||
/*
|
||||
* Initialize all registers.
|
||||
*/
|
||||
if (rt2500pci_init_queues(rt2x00dev) ||
|
||||
rt2500pci_init_registers(rt2x00dev) ||
|
||||
rt2500pci_init_bbp(rt2x00dev)) {
|
||||
ERROR(rt2x00dev, "Register initialization failed.\n");
|
||||
if (unlikely(rt2500pci_init_queues(rt2x00dev) ||
|
||||
rt2500pci_init_registers(rt2x00dev) ||
|
||||
rt2500pci_init_bbp(rt2x00dev)))
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
/*
|
||||
* Enable interrupts.
|
||||
*/
|
||||
rt2500pci_toggle_irq(rt2x00dev, STATE_RADIO_IRQ_ON);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -1066,11 +1067,6 @@ static void rt2500pci_disable_radio(struct rt2x00_dev *rt2x00dev)
|
||||
rt2x00pci_register_read(rt2x00dev, TXCSR0, ®);
|
||||
rt2x00_set_field32(®, TXCSR0_ABORT, 1);
|
||||
rt2x00pci_register_write(rt2x00dev, TXCSR0, reg);
|
||||
|
||||
/*
|
||||
* Disable interrupts.
|
||||
*/
|
||||
rt2500pci_toggle_irq(rt2x00dev, STATE_RADIO_IRQ_OFF);
|
||||
}
|
||||
|
||||
static int rt2500pci_set_state(struct rt2x00_dev *rt2x00dev,
|
||||
@ -1105,10 +1101,6 @@ static int rt2500pci_set_state(struct rt2x00_dev *rt2x00dev,
|
||||
msleep(10);
|
||||
}
|
||||
|
||||
NOTICE(rt2x00dev, "Device failed to enter state %d, "
|
||||
"current device state: bbp %d and rf %d.\n",
|
||||
state, bbp_state, rf_state);
|
||||
|
||||
return -EBUSY;
|
||||
}
|
||||
|
||||
@ -1126,11 +1118,13 @@ static int rt2500pci_set_device_state(struct rt2x00_dev *rt2x00dev,
|
||||
break;
|
||||
case STATE_RADIO_RX_ON:
|
||||
case STATE_RADIO_RX_ON_LINK:
|
||||
rt2500pci_toggle_rx(rt2x00dev, STATE_RADIO_RX_ON);
|
||||
break;
|
||||
case STATE_RADIO_RX_OFF:
|
||||
case STATE_RADIO_RX_OFF_LINK:
|
||||
rt2500pci_toggle_rx(rt2x00dev, STATE_RADIO_RX_OFF);
|
||||
rt2500pci_toggle_rx(rt2x00dev, state);
|
||||
break;
|
||||
case STATE_RADIO_IRQ_ON:
|
||||
case STATE_RADIO_IRQ_OFF:
|
||||
rt2500pci_toggle_irq(rt2x00dev, state);
|
||||
break;
|
||||
case STATE_DEEP_SLEEP:
|
||||
case STATE_SLEEP:
|
||||
@ -1143,6 +1137,10 @@ static int rt2500pci_set_device_state(struct rt2x00_dev *rt2x00dev,
|
||||
break;
|
||||
}
|
||||
|
||||
if (unlikely(retval))
|
||||
ERROR(rt2x00dev, "Device failed to enter state %d (%d).\n",
|
||||
state, retval);
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
@ -847,6 +847,22 @@ static int rt2500usb_init_registers(struct rt2x00_dev *rt2x00dev)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int rt2500usb_wait_bbp_ready(struct rt2x00_dev *rt2x00dev)
|
||||
{
|
||||
unsigned int i;
|
||||
u8 value;
|
||||
|
||||
for (i = 0; i < REGISTER_BUSY_COUNT; i++) {
|
||||
rt2500usb_bbp_read(rt2x00dev, 0, &value);
|
||||
if ((value != 0xff) && (value != 0x00))
|
||||
return 0;
|
||||
udelay(REGISTER_BUSY_DELAY);
|
||||
}
|
||||
|
||||
ERROR(rt2x00dev, "BBP register access failed, aborting.\n");
|
||||
return -EACCES;
|
||||
}
|
||||
|
||||
static int rt2500usb_init_bbp(struct rt2x00_dev *rt2x00dev)
|
||||
{
|
||||
unsigned int i;
|
||||
@ -854,18 +870,9 @@ static int rt2500usb_init_bbp(struct rt2x00_dev *rt2x00dev)
|
||||
u8 value;
|
||||
u8 reg_id;
|
||||
|
||||
for (i = 0; i < REGISTER_BUSY_COUNT; i++) {
|
||||
rt2500usb_bbp_read(rt2x00dev, 0, &value);
|
||||
if ((value != 0xff) && (value != 0x00))
|
||||
goto continue_csr_init;
|
||||
NOTICE(rt2x00dev, "Waiting for BBP register.\n");
|
||||
udelay(REGISTER_BUSY_DELAY);
|
||||
}
|
||||
if (unlikely(rt2500usb_wait_bbp_ready(rt2x00dev)))
|
||||
return -EACCES;
|
||||
|
||||
ERROR(rt2x00dev, "BBP register access failed, aborting.\n");
|
||||
return -EACCES;
|
||||
|
||||
continue_csr_init:
|
||||
rt2500usb_bbp_write(rt2x00dev, 3, 0x02);
|
||||
rt2500usb_bbp_write(rt2x00dev, 4, 0x19);
|
||||
rt2500usb_bbp_write(rt2x00dev, 14, 0x1c);
|
||||
@ -921,7 +928,8 @@ static void rt2500usb_toggle_rx(struct rt2x00_dev *rt2x00dev,
|
||||
|
||||
rt2500usb_register_read(rt2x00dev, TXRX_CSR2, ®);
|
||||
rt2x00_set_field16(®, TXRX_CSR2_DISABLE_RX,
|
||||
state == STATE_RADIO_RX_OFF);
|
||||
(state == STATE_RADIO_RX_OFF) ||
|
||||
(state == STATE_RADIO_RX_OFF_LINK));
|
||||
rt2500usb_register_write(rt2x00dev, TXRX_CSR2, reg);
|
||||
}
|
||||
|
||||
@ -930,11 +938,9 @@ static int rt2500usb_enable_radio(struct rt2x00_dev *rt2x00dev)
|
||||
/*
|
||||
* Initialize all registers.
|
||||
*/
|
||||
if (rt2500usb_init_registers(rt2x00dev) ||
|
||||
rt2500usb_init_bbp(rt2x00dev)) {
|
||||
ERROR(rt2x00dev, "Register initialization failed.\n");
|
||||
if (unlikely(rt2500usb_init_registers(rt2x00dev) ||
|
||||
rt2500usb_init_bbp(rt2x00dev)))
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -987,10 +993,6 @@ static int rt2500usb_set_state(struct rt2x00_dev *rt2x00dev,
|
||||
msleep(30);
|
||||
}
|
||||
|
||||
NOTICE(rt2x00dev, "Device failed to enter state %d, "
|
||||
"current device state: bbp %d and rf %d.\n",
|
||||
state, bbp_state, rf_state);
|
||||
|
||||
return -EBUSY;
|
||||
}
|
||||
|
||||
@ -1008,11 +1010,13 @@ static int rt2500usb_set_device_state(struct rt2x00_dev *rt2x00dev,
|
||||
break;
|
||||
case STATE_RADIO_RX_ON:
|
||||
case STATE_RADIO_RX_ON_LINK:
|
||||
rt2500usb_toggle_rx(rt2x00dev, STATE_RADIO_RX_ON);
|
||||
break;
|
||||
case STATE_RADIO_RX_OFF:
|
||||
case STATE_RADIO_RX_OFF_LINK:
|
||||
rt2500usb_toggle_rx(rt2x00dev, STATE_RADIO_RX_OFF);
|
||||
rt2500usb_toggle_rx(rt2x00dev, state);
|
||||
break;
|
||||
case STATE_RADIO_IRQ_ON:
|
||||
case STATE_RADIO_IRQ_OFF:
|
||||
/* No support, but no error either */
|
||||
break;
|
||||
case STATE_DEEP_SLEEP:
|
||||
case STATE_SLEEP:
|
||||
@ -1025,6 +1029,10 @@ static int rt2500usb_set_device_state(struct rt2x00_dev *rt2x00dev,
|
||||
break;
|
||||
}
|
||||
|
||||
if (unlikely(retval))
|
||||
ERROR(rt2x00dev, "Device failed to enter state %d (%d).\n",
|
||||
state, retval);
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
@ -112,6 +112,8 @@ int rt2x00lib_enable_radio(struct rt2x00_dev *rt2x00dev)
|
||||
if (status)
|
||||
return status;
|
||||
|
||||
rt2x00dev->ops->lib->set_device_state(rt2x00dev, STATE_RADIO_IRQ_ON);
|
||||
|
||||
rt2x00leds_led_radio(rt2x00dev, true);
|
||||
rt2x00led_led_activity(rt2x00dev, true);
|
||||
|
||||
@ -157,6 +159,7 @@ void rt2x00lib_disable_radio(struct rt2x00_dev *rt2x00dev)
|
||||
* Disable radio.
|
||||
*/
|
||||
rt2x00dev->ops->lib->set_device_state(rt2x00dev, STATE_RADIO_OFF);
|
||||
rt2x00dev->ops->lib->set_device_state(rt2x00dev, STATE_RADIO_IRQ_OFF);
|
||||
rt2x00led_led_activity(rt2x00dev, false);
|
||||
rt2x00leds_led_radio(rt2x00dev, false);
|
||||
}
|
||||
|
@ -1270,6 +1270,22 @@ static int rt61pci_init_registers(struct rt2x00_dev *rt2x00dev)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int rt61pci_wait_bbp_ready(struct rt2x00_dev *rt2x00dev)
|
||||
{
|
||||
unsigned int i;
|
||||
u8 value;
|
||||
|
||||
for (i = 0; i < REGISTER_BUSY_COUNT; i++) {
|
||||
rt61pci_bbp_read(rt2x00dev, 0, &value);
|
||||
if ((value != 0xff) && (value != 0x00))
|
||||
return 0;
|
||||
udelay(REGISTER_BUSY_DELAY);
|
||||
}
|
||||
|
||||
ERROR(rt2x00dev, "BBP register access failed, aborting.\n");
|
||||
return -EACCES;
|
||||
}
|
||||
|
||||
static int rt61pci_init_bbp(struct rt2x00_dev *rt2x00dev)
|
||||
{
|
||||
unsigned int i;
|
||||
@ -1277,18 +1293,9 @@ static int rt61pci_init_bbp(struct rt2x00_dev *rt2x00dev)
|
||||
u8 reg_id;
|
||||
u8 value;
|
||||
|
||||
for (i = 0; i < REGISTER_BUSY_COUNT; i++) {
|
||||
rt61pci_bbp_read(rt2x00dev, 0, &value);
|
||||
if ((value != 0xff) && (value != 0x00))
|
||||
goto continue_csr_init;
|
||||
NOTICE(rt2x00dev, "Waiting for BBP register.\n");
|
||||
udelay(REGISTER_BUSY_DELAY);
|
||||
}
|
||||
if (unlikely(rt61pci_wait_bbp_ready(rt2x00dev)))
|
||||
return -EACCES;
|
||||
|
||||
ERROR(rt2x00dev, "BBP register access failed, aborting.\n");
|
||||
return -EACCES;
|
||||
|
||||
continue_csr_init:
|
||||
rt61pci_bbp_write(rt2x00dev, 3, 0x00);
|
||||
rt61pci_bbp_write(rt2x00dev, 15, 0x30);
|
||||
rt61pci_bbp_write(rt2x00dev, 21, 0xc8);
|
||||
@ -1337,7 +1344,8 @@ static void rt61pci_toggle_rx(struct rt2x00_dev *rt2x00dev,
|
||||
|
||||
rt2x00pci_register_read(rt2x00dev, TXRX_CSR0, ®);
|
||||
rt2x00_set_field32(®, TXRX_CSR0_DISABLE_RX,
|
||||
state == STATE_RADIO_RX_OFF);
|
||||
(state == STATE_RADIO_RX_OFF) ||
|
||||
(state == STATE_RADIO_RX_OFF_LINK));
|
||||
rt2x00pci_register_write(rt2x00dev, TXRX_CSR0, reg);
|
||||
}
|
||||
|
||||
@ -1389,17 +1397,10 @@ static int rt61pci_enable_radio(struct rt2x00_dev *rt2x00dev)
|
||||
/*
|
||||
* Initialize all registers.
|
||||
*/
|
||||
if (rt61pci_init_queues(rt2x00dev) ||
|
||||
rt61pci_init_registers(rt2x00dev) ||
|
||||
rt61pci_init_bbp(rt2x00dev)) {
|
||||
ERROR(rt2x00dev, "Register initialization failed.\n");
|
||||
if (unlikely(rt61pci_init_queues(rt2x00dev) ||
|
||||
rt61pci_init_registers(rt2x00dev) ||
|
||||
rt61pci_init_bbp(rt2x00dev)))
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
/*
|
||||
* Enable interrupts.
|
||||
*/
|
||||
rt61pci_toggle_irq(rt2x00dev, STATE_RADIO_IRQ_ON);
|
||||
|
||||
/*
|
||||
* Enable RX.
|
||||
@ -1431,11 +1432,6 @@ static void rt61pci_disable_radio(struct rt2x00_dev *rt2x00dev)
|
||||
rt2x00_set_field32(®, TX_CNTL_CSR_ABORT_TX_AC2, 1);
|
||||
rt2x00_set_field32(®, TX_CNTL_CSR_ABORT_TX_AC3, 1);
|
||||
rt2x00pci_register_write(rt2x00dev, TX_CNTL_CSR, reg);
|
||||
|
||||
/*
|
||||
* Disable interrupts.
|
||||
*/
|
||||
rt61pci_toggle_irq(rt2x00dev, STATE_RADIO_IRQ_OFF);
|
||||
}
|
||||
|
||||
static int rt61pci_set_state(struct rt2x00_dev *rt2x00dev, enum dev_state state)
|
||||
@ -1443,7 +1439,6 @@ static int rt61pci_set_state(struct rt2x00_dev *rt2x00dev, enum dev_state state)
|
||||
u32 reg;
|
||||
unsigned int i;
|
||||
char put_to_sleep;
|
||||
char current_state;
|
||||
|
||||
put_to_sleep = (state != STATE_AWAKE);
|
||||
|
||||
@ -1459,16 +1454,12 @@ static int rt61pci_set_state(struct rt2x00_dev *rt2x00dev, enum dev_state state)
|
||||
*/
|
||||
for (i = 0; i < REGISTER_BUSY_COUNT; i++) {
|
||||
rt2x00pci_register_read(rt2x00dev, MAC_CSR12, ®);
|
||||
current_state =
|
||||
rt2x00_get_field32(reg, MAC_CSR12_BBP_CURRENT_STATE);
|
||||
if (current_state == !put_to_sleep)
|
||||
state = rt2x00_get_field32(reg, MAC_CSR12_BBP_CURRENT_STATE);
|
||||
if (state == !put_to_sleep)
|
||||
return 0;
|
||||
msleep(10);
|
||||
}
|
||||
|
||||
NOTICE(rt2x00dev, "Device failed to enter state %d, "
|
||||
"current device state %d.\n", !put_to_sleep, current_state);
|
||||
|
||||
return -EBUSY;
|
||||
}
|
||||
|
||||
@ -1486,11 +1477,13 @@ static int rt61pci_set_device_state(struct rt2x00_dev *rt2x00dev,
|
||||
break;
|
||||
case STATE_RADIO_RX_ON:
|
||||
case STATE_RADIO_RX_ON_LINK:
|
||||
rt61pci_toggle_rx(rt2x00dev, STATE_RADIO_RX_ON);
|
||||
break;
|
||||
case STATE_RADIO_RX_OFF:
|
||||
case STATE_RADIO_RX_OFF_LINK:
|
||||
rt61pci_toggle_rx(rt2x00dev, STATE_RADIO_RX_OFF);
|
||||
rt61pci_toggle_rx(rt2x00dev, state);
|
||||
break;
|
||||
case STATE_RADIO_IRQ_ON:
|
||||
case STATE_RADIO_IRQ_OFF:
|
||||
rt61pci_toggle_irq(rt2x00dev, state);
|
||||
break;
|
||||
case STATE_DEEP_SLEEP:
|
||||
case STATE_SLEEP:
|
||||
@ -1503,6 +1496,10 @@ static int rt61pci_set_device_state(struct rt2x00_dev *rt2x00dev,
|
||||
break;
|
||||
}
|
||||
|
||||
if (unlikely(retval))
|
||||
ERROR(rt2x00dev, "Device failed to enter state %d (%d).\n",
|
||||
state, retval);
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
@ -1084,6 +1084,22 @@ static int rt73usb_init_registers(struct rt2x00_dev *rt2x00dev)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int rt73usb_wait_bbp_ready(struct rt2x00_dev *rt2x00dev)
|
||||
{
|
||||
unsigned int i;
|
||||
u8 value;
|
||||
|
||||
for (i = 0; i < REGISTER_BUSY_COUNT; i++) {
|
||||
rt73usb_bbp_read(rt2x00dev, 0, &value);
|
||||
if ((value != 0xff) && (value != 0x00))
|
||||
return 0;
|
||||
udelay(REGISTER_BUSY_DELAY);
|
||||
}
|
||||
|
||||
ERROR(rt2x00dev, "BBP register access failed, aborting.\n");
|
||||
return -EACCES;
|
||||
}
|
||||
|
||||
static int rt73usb_init_bbp(struct rt2x00_dev *rt2x00dev)
|
||||
{
|
||||
unsigned int i;
|
||||
@ -1091,18 +1107,9 @@ static int rt73usb_init_bbp(struct rt2x00_dev *rt2x00dev)
|
||||
u8 reg_id;
|
||||
u8 value;
|
||||
|
||||
for (i = 0; i < REGISTER_BUSY_COUNT; i++) {
|
||||
rt73usb_bbp_read(rt2x00dev, 0, &value);
|
||||
if ((value != 0xff) && (value != 0x00))
|
||||
goto continue_csr_init;
|
||||
NOTICE(rt2x00dev, "Waiting for BBP register.\n");
|
||||
udelay(REGISTER_BUSY_DELAY);
|
||||
}
|
||||
if (unlikely(rt73usb_wait_bbp_ready(rt2x00dev)))
|
||||
return -EACCES;
|
||||
|
||||
ERROR(rt2x00dev, "BBP register access failed, aborting.\n");
|
||||
return -EACCES;
|
||||
|
||||
continue_csr_init:
|
||||
rt73usb_bbp_write(rt2x00dev, 3, 0x80);
|
||||
rt73usb_bbp_write(rt2x00dev, 15, 0x30);
|
||||
rt73usb_bbp_write(rt2x00dev, 21, 0xc8);
|
||||
@ -1152,7 +1159,8 @@ static void rt73usb_toggle_rx(struct rt2x00_dev *rt2x00dev,
|
||||
|
||||
rt73usb_register_read(rt2x00dev, TXRX_CSR0, ®);
|
||||
rt2x00_set_field32(®, TXRX_CSR0_DISABLE_RX,
|
||||
state == STATE_RADIO_RX_OFF);
|
||||
(state == STATE_RADIO_RX_OFF) ||
|
||||
(state == STATE_RADIO_RX_OFF_LINK));
|
||||
rt73usb_register_write(rt2x00dev, TXRX_CSR0, reg);
|
||||
}
|
||||
|
||||
@ -1161,11 +1169,9 @@ static int rt73usb_enable_radio(struct rt2x00_dev *rt2x00dev)
|
||||
/*
|
||||
* Initialize all registers.
|
||||
*/
|
||||
if (rt73usb_init_registers(rt2x00dev) ||
|
||||
rt73usb_init_bbp(rt2x00dev)) {
|
||||
ERROR(rt2x00dev, "Register initialization failed.\n");
|
||||
if (unlikely(rt73usb_init_registers(rt2x00dev) ||
|
||||
rt73usb_init_bbp(rt2x00dev)))
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -1187,7 +1193,6 @@ static int rt73usb_set_state(struct rt2x00_dev *rt2x00dev, enum dev_state state)
|
||||
u32 reg;
|
||||
unsigned int i;
|
||||
char put_to_sleep;
|
||||
char current_state;
|
||||
|
||||
put_to_sleep = (state != STATE_AWAKE);
|
||||
|
||||
@ -1203,16 +1208,12 @@ static int rt73usb_set_state(struct rt2x00_dev *rt2x00dev, enum dev_state state)
|
||||
*/
|
||||
for (i = 0; i < REGISTER_BUSY_COUNT; i++) {
|
||||
rt73usb_register_read(rt2x00dev, MAC_CSR12, ®);
|
||||
current_state =
|
||||
rt2x00_get_field32(reg, MAC_CSR12_BBP_CURRENT_STATE);
|
||||
if (current_state == !put_to_sleep)
|
||||
state = rt2x00_get_field32(reg, MAC_CSR12_BBP_CURRENT_STATE);
|
||||
if (state == !put_to_sleep)
|
||||
return 0;
|
||||
msleep(10);
|
||||
}
|
||||
|
||||
NOTICE(rt2x00dev, "Device failed to enter state %d, "
|
||||
"current device state %d.\n", !put_to_sleep, current_state);
|
||||
|
||||
return -EBUSY;
|
||||
}
|
||||
|
||||
@ -1230,11 +1231,13 @@ static int rt73usb_set_device_state(struct rt2x00_dev *rt2x00dev,
|
||||
break;
|
||||
case STATE_RADIO_RX_ON:
|
||||
case STATE_RADIO_RX_ON_LINK:
|
||||
rt73usb_toggle_rx(rt2x00dev, STATE_RADIO_RX_ON);
|
||||
break;
|
||||
case STATE_RADIO_RX_OFF:
|
||||
case STATE_RADIO_RX_OFF_LINK:
|
||||
rt73usb_toggle_rx(rt2x00dev, STATE_RADIO_RX_OFF);
|
||||
rt73usb_toggle_rx(rt2x00dev, state);
|
||||
break;
|
||||
case STATE_RADIO_IRQ_ON:
|
||||
case STATE_RADIO_IRQ_OFF:
|
||||
/* No support, but no error either */
|
||||
break;
|
||||
case STATE_DEEP_SLEEP:
|
||||
case STATE_SLEEP:
|
||||
@ -1247,6 +1250,10 @@ static int rt73usb_set_device_state(struct rt2x00_dev *rt2x00dev,
|
||||
break;
|
||||
}
|
||||
|
||||
if (unlikely(retval))
|
||||
ERROR(rt2x00dev, "Device failed to enter state %d (%d).\n",
|
||||
state, retval);
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user