Changeset 4cb0148 in mainline for uspace/drv/bus/usb/ar9271/hw.c
- Timestamp:
- 2015-03-05T10:53:02Z (10 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 9e5a51c
- Parents:
- 56c0930
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/bus/usb/ar9271/hw.c
r56c0930 r4cb0148 342 342 } 343 343 344 static uint32_t hw_reverse_bits(uint32_t value, uint32_t count)345 {346 uint32_t ret_val = 0;347 348 for(size_t i = 0; i < count; i++) {349 ret_val = (ret_val << 1) | (value & 1);350 value >>= 1;351 }352 353 return ret_val;354 }355 356 344 static int hw_set_freq(ar9271_t *ar9271, uint16_t freq) 357 345 { … … 372 360 373 361 /* Some magic here. */ 374 uint32_t channel = hw_reverse_bits( 375 (((((freq - 672) * 2 - 3040) / 10) << 2) & 0xFF), 8); 376 uint32_t to_write = (channel << 8) | 33; 377 378 wmi_reg_write(ar9271->htc_device, AR9271_PHY_BASE + (0x37 << 2), 379 to_write); 362 uint32_t synth_ctl; 363 wmi_reg_read(ar9271->htc_device, AR9271_PHY_SYNTH_CONTROL, &synth_ctl); 364 synth_ctl &= 0xC0000000; 365 uint32_t channel_select = (freq * 0x10000) / 15; 366 synth_ctl = synth_ctl | (1 << 29) | (1 << 28) | channel_select; 367 368 wmi_reg_write(ar9271->htc_device, AR9271_PHY_SYNTH_CONTROL, synth_ctl); 380 369 381 370 ar9271->ieee80211_dev->current_freq = freq; … … 397 386 398 387 filter_bits |= AR9271_RX_FILTER_UNI | AR9271_RX_FILTER_MULTI | 399 AR9271_RX_FILTER_BROAD | AR9271_RX_FILTER_BEACON | 400 AR9271_RX_FILTER_MYBEACON | AR9271_RX_FILTER_PROMISCUOUS; 388 AR9271_RX_FILTER_BROAD | AR9271_RX_FILTER_PROMISCUOUS; 401 389 402 390 rc = wmi_reg_write(ar9271->htc_device, AR9271_RX_FILTER, filter_bits); … … 423 411 return EINVAL; 424 412 } 413 414 wmi_reg_write(ar9271->htc_device, AR9271_MULTICAST_FILTER1, ~0); 415 wmi_reg_write(ar9271->htc_device, AR9271_MULTICAST_FILTER2, ~0); 425 416 426 417 return EOK; … … 447 438 pll = (0x5 << 10) & 0x00003C00; 448 439 pll |= (0x2 << 14) & 0x0000C000; /**< 0x2 ~ quarter rate (0x1 half) */ 449 pll |= 0x 58& 0x000003FF;440 pll |= 0x2C & 0x000003FF; 450 441 451 442 return wmi_reg_write(ar9271->htc_device, AR9271_RTC_PLL_CONTROL, pll); 452 443 } 453 444 454 static int hw_calibrate(ar9271_t *ar9271) 445 static int hw_set_init_values(ar9271_t *ar9271) 446 { 447 uint32_t reg_offset, reg_value; 448 449 int size = 450 sizeof(ar9271_2g_mode_array) / sizeof(ar9271_2g_mode_array[0]); 451 452 for(int i = 0; i < size; i++) { 453 reg_offset = ar9271_2g_mode_array[i][0]; 454 reg_value = ar9271_2g_mode_array[i][1]; 455 wmi_reg_write(ar9271->htc_device, reg_offset, reg_value); 456 } 457 458 size = sizeof(ar9271_init_array) / sizeof(ar9271_init_array[0]); 459 460 for(int i = 0; i < size; i++) { 461 reg_offset = ar9271_init_array[i][0]; 462 reg_value = ar9271_init_array[i][1]; 463 wmi_reg_write(ar9271->htc_device, reg_offset, reg_value); 464 } 465 466 return EOK; 467 } 468 469 static int hw_calibration(ar9271_t *ar9271) 455 470 { 456 471 wmi_reg_set_bit(ar9271->htc_device, AR9271_CARRIER_LEAK_CONTROL, … … 482 497 } 483 498 484 static int hw_set_init_values(ar9271_t *ar9271) 485 { 486 int size = sizeof(ar9271_init_array) / sizeof(ar9271_init_array[0]); 487 488 for(int i = 0; i < size; i++) { 489 uint32_t reg_offset = ar9271_init_array[i][0]; 490 uint32_t reg_value = ar9271_init_array[i][1]; 491 wmi_reg_write(ar9271->htc_device, reg_offset, reg_value); 492 } 499 static int hw_noise_floor_calibration(ar9271_t *ar9271) 500 { 501 wmi_reg_set_bit(ar9271->htc_device, AR9271_AGC_CONTROL, 502 AR9271_AGC_CONTROL_NF_CALIB_EN); 503 504 wmi_reg_clear_bit(ar9271->htc_device, AR9271_AGC_CONTROL, 505 AR9271_AGC_CONTROL_NF_NOT_UPDATE); 506 507 wmi_reg_set_bit(ar9271->htc_device, AR9271_AGC_CONTROL, 508 AR9271_AGC_CONTROL_NF_CALIB); 493 509 494 510 return EOK; … … 554 570 555 571 /* Set physical layer mode. */ 556 rc = wmi_reg_write(ar9271->htc_device, AR9271_PHY_MODE, 557 AR9271_PHY_MODE_DYNAMIC | AR9271_PHY_MODE_2G);572 rc = wmi_reg_write(ar9271->htc_device, AR9271_PHY_MODE, 573 AR9271_PHY_MODE_DYNAMIC); 558 574 if(rc != EOK) { 559 575 usb_log_error("Failed to set physical layer mode.\n"); 560 576 return rc; 561 577 } 562 563 /* TODO: Init EEPROM here. */564 578 565 579 /* Set device operating mode. */ … … 571 585 572 586 /* Set channel frequency. */ 573 rc = hw_set_freq(ar9271, IEEE80211_FIRST_FREQ);587 rc = hw_set_freq(ar9271, 2437); 574 588 if(rc != EOK) { 575 589 usb_log_error("Failed to set channel.\n"); … … 591 605 /* TODO: Maybe resetting TX queues will be necessary afterwards here. */ 592 606 593 /* TODO: Setting RX, TX timeouts and others may be necessary here. */594 595 607 /* Activate physical layer. */ 596 608 rc = hw_activate_phy(ar9271); … … 601 613 602 614 /* Calibration. */ 603 rc = hw_calibrat e(ar9271);615 rc = hw_calibration(ar9271); 604 616 if(rc != EOK) { 605 617 usb_log_error("Failed to calibrate device.\n"); 618 return rc; 619 } 620 621 rc = hw_noise_floor_calibration(ar9271); 622 if(rc != EOK) { 623 usb_log_error("Failed to calibrate noise floor.\n"); 606 624 return rc; 607 625 }
Note:
See TracChangeset
for help on using the changeset viewer.