Changeset 4cb0148 in mainline for uspace/drv/bus/usb/ar9271/hw.c


Ignore:
Timestamp:
2015-03-05T10:53:02Z (9 years ago)
Author:
Jan Kolarik <kolarik@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
9e5a51c
Parents:
56c0930
Message:

Fixed some device settings that were previously taken from different ATH device, because of nonlinear numbering of ATH devices versions.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/bus/usb/ar9271/hw.c

    r56c0930 r4cb0148  
    342342}
    343343
    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 
    356344static int hw_set_freq(ar9271_t *ar9271, uint16_t freq)
    357345{
     
    372360       
    373361        /* 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);
    380369       
    381370        ar9271->ieee80211_dev->current_freq = freq;
     
    397386       
    398387        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;
    401389       
    402390        rc = wmi_reg_write(ar9271->htc_device, AR9271_RX_FILTER, filter_bits);
     
    423411                return EINVAL;
    424412        }
     413       
     414        wmi_reg_write(ar9271->htc_device, AR9271_MULTICAST_FILTER1, ~0);
     415        wmi_reg_write(ar9271->htc_device, AR9271_MULTICAST_FILTER2, ~0);
    425416       
    426417        return EOK;
     
    447438        pll = (0x5 << 10) & 0x00003C00;
    448439        pll |= (0x2 << 14) & 0x0000C000; /**< 0x2 ~ quarter rate (0x1 half) */
    449         pll |= 0x58 & 0x000003FF;
     440        pll |= 0x2C & 0x000003FF;
    450441       
    451442        return wmi_reg_write(ar9271->htc_device, AR9271_RTC_PLL_CONTROL, pll);
    452443}
    453444
    454 static int hw_calibrate(ar9271_t *ar9271)
     445static 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
     469static int hw_calibration(ar9271_t *ar9271)
    455470{
    456471        wmi_reg_set_bit(ar9271->htc_device, AR9271_CARRIER_LEAK_CONTROL,
     
    482497}
    483498
    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         }
     499static 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);
    493509       
    494510        return EOK;
     
    554570       
    555571        /* 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);
    558574        if(rc != EOK) {
    559575                usb_log_error("Failed to set physical layer mode.\n");
    560576                return rc;
    561577        }
    562        
    563         /* TODO: Init EEPROM here. */
    564578       
    565579        /* Set device operating mode. */
     
    571585       
    572586        /* Set channel frequency. */
    573         rc = hw_set_freq(ar9271, IEEE80211_FIRST_FREQ);
     587        rc = hw_set_freq(ar9271, 2437);
    574588        if(rc != EOK) {
    575589                usb_log_error("Failed to set channel.\n");
     
    591605        /* TODO: Maybe resetting TX queues will be necessary afterwards here. */
    592606       
    593         /* TODO: Setting RX, TX timeouts and others may be necessary here. */
    594        
    595607        /* Activate physical layer. */
    596608        rc = hw_activate_phy(ar9271);
     
    601613       
    602614        /* Calibration. */
    603         rc = hw_calibrate(ar9271);
     615        rc = hw_calibration(ar9271);
    604616        if(rc != EOK) {
    605617                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");
    606624                return rc;
    607625        }
Note: See TracChangeset for help on using the changeset viewer.