Changeset 4cb0148 in mainline


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.

Location:
uspace/drv/bus/usb/ar9271
Files:
3 edited

Legend:

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

    r56c0930 r4cb0148  
    165165                htc_read_data_message(ar9271->htc_device, buffer, buffer_size,
    166166                        NULL);
    167                 usb_log_info("RC is %d.\n", rc);
     167                usb_log_info("XXXXXXXXXXXXXXXXXXXXXXXXXXXX RC is %d.\n", rc);
    168168               
    169169                /* TODO: Process RX message */
     
    179179        while(true) {
    180180                uint32_t result;
     181                wmi_reg_read(ar9271->htc_device, 0x7828, &result);
     182                usb_log_info("0x7828: %x\n", result);
     183                wmi_reg_read(ar9271->htc_device, 0x782C, &result);
     184                usb_log_info("0x782C: %x\n", result);
     185                wmi_reg_read(ar9271->htc_device, 0x8048, &result);
     186                usb_log_info("Diag reg.: %x\n", result);
     187                wmi_reg_read(ar9271->htc_device, 0x8088, &result);
     188                usb_log_info("Successful RTS count: %x\n", result);
     189                wmi_reg_read(ar9271->htc_device, 0x808C, &result);
     190                usb_log_info("Failed RTS count: %x\n", result);
     191                wmi_reg_read(ar9271->htc_device, 0x8090, &result);
     192                usb_log_info("Failed ACK count: %x\n", result);
     193                wmi_reg_read(ar9271->htc_device, 0x8094, &result);
     194                usb_log_info("Failed FCS count: %x\n", result);
    181195                wmi_reg_read(ar9271->htc_device, 0x80F0, &result);
    182196                usb_log_info("RX count: %x\n", result);
    183197                wmi_reg_read(ar9271->htc_device, 0x8098, &result);
    184198                usb_log_info("Beacon count: %x\n", result);
     199                wmi_reg_read(ar9271->htc_device, 0x812C, &result);
     200                usb_log_info("PHY errors: %x\n", result);
    185201                sleep(1);
    186202        }
  • uspace/drv/bus/usb/ar9271/ar9271.h

    r56c0930 r4cb0148  
    109109        AR9271_RX_FILTER_PROBEREQ = 0x00000080,
    110110        AR9271_RX_FILTER_MYBEACON = 0x00000200,
     111        AR9271_MULTICAST_FILTER1 = 0x8040,
     112        AR9271_MULTICAST_FILTER2 = 0x8044,     
    111113               
    112114        /* Physical layer registers */
    113         AR9271_PHY_BASE = 0x9800,
    114115        AR9271_PHY_ACTIVE = 0x981C,
    115116        AR9271_ADC_CONTROL = 0x982C,
    116117        AR9271_AGC_CONTROL = 0x9860,
     118        AR9271_PHY_SYNTH_CONTROL = 0x9874,
    117119        AR9271_PHY_MODE = 0xA200,
    118120        AR9271_PHY_CCK_TX_CTRL = 0xA204,
     
    121123        AR9271_ADC_CONTROL_OFF_PWDADC = 0x00008000,
    122124        AR9271_AGC_CONTROL_CALIB = 0x00000001,
     125        AR9271_AGC_CONTROL_NF_CALIB = 0x00000002,
     126        AR9271_AGC_CONTROL_NF_CALIB_EN = 0x00008000,
    123127        AR9271_AGC_CONTROL_TX_CALIB = 0x00010000,
     128        AR9271_AGC_CONTROL_NF_NOT_UPDATE = 0x00020000,
    124129        AR9271_PHY_MODE_2G = 0x02,
    125130        AR9271_PHY_MODE_DYNAMIC = 0x04,
     
    166171        htc_device_t *htc_device;
    167172} ar9271_t;
     173
     174/**
     175 * AR9271 init values for 2GHz mode operation.
     176 *
     177 * Including settings of noise floor limits.
     178 *
     179 * Taken from Linux sources.
     180 */
     181static const uint32_t ar9271_2g_mode_array[][2] = {
     182        {0x00001030, 0x00000160},
     183        {0x00001070, 0x0000018c},
     184        {0x000010b0, 0x00003e38},
     185        {0x000010f0, 0x00000000},
     186        {0x00008014, 0x08400b00},
     187        {0x0000801c, 0x12e0002b},
     188        {0x00008318, 0x00003440},
     189        {0x00009804, 0x00000300},
     190        {0x00009820, 0x02020200},
     191        {0x00009824, 0x01000e0e},
     192        {0x00009828, 0x3a020001},
     193        {0x00009834, 0x00000e0e},
     194        {0x00009838, 0x00000007},
     195        {0x00009840, 0x206a012e},
     196        {0x00009844, 0x03721620},
     197        {0x00009848, 0x00001053},
     198        {0x0000a848, 0x00001053},
     199        {0x00009850, 0x6d4000e2},
     200        {0x00009858, 0x7ec84d2e},
     201        {0x0000985c, 0x3137605e},
     202        {0x00009860, 0x00058d18},
     203        {0x00009864, 0x0001ce00},
     204        {0x00009868, 0x5ac640d0},
     205        {0x0000986c, 0x06903881},
     206        {0x00009910, 0x30002310},
     207        {0x00009914, 0x00000898},
     208        {0x00009918, 0x0000000b},
     209        {0x00009924, 0xd00a800d},
     210        {0x00009944, 0xffbc1020},
     211        {0x00009960, 0x00000000},
     212        {0x00009964, 0x00000000},
     213        {0x000099b8, 0x0000421c},
     214        {0x000099bc, 0x00000c00},
     215        {0x000099c0, 0x05eea6d4},
     216        {0x000099c4, 0x06336f77},
     217        {0x000099c8, 0x6af6532f},
     218        {0x000099cc, 0x08f186c8},
     219        {0x000099d0, 0x00046384},
     220        {0x000099d4, 0x00000000},
     221        {0x000099d8, 0x00000000},
     222        {0x00009a00, 0x00058084},
     223        {0x00009a04, 0x00058088},
     224        {0x00009a08, 0x0005808c},
     225        {0x00009a0c, 0x00058100},
     226        {0x00009a10, 0x00058104},
     227        {0x00009a14, 0x00058108},
     228        {0x00009a18, 0x0005810c},
     229        {0x00009a1c, 0x00058110},
     230        {0x00009a20, 0x00058114},
     231        {0x00009a24, 0x00058180},
     232        {0x00009a28, 0x00058184},
     233        {0x00009a2c, 0x00058188},
     234        {0x00009a30, 0x0005818c},
     235        {0x00009a34, 0x00058190},
     236        {0x00009a38, 0x00058194},
     237        {0x00009a3c, 0x000581a0},
     238        {0x00009a40, 0x0005820c},
     239        {0x00009a44, 0x000581a8},
     240        {0x00009a48, 0x00058284},
     241        {0x00009a4c, 0x00058288},
     242        {0x00009a50, 0x00058224},
     243        {0x00009a54, 0x00058290},
     244        {0x00009a58, 0x00058300},
     245        {0x00009a5c, 0x00058304},
     246        {0x00009a60, 0x00058308},
     247        {0x00009a64, 0x0005830c},
     248        {0x00009a68, 0x00058380},
     249        {0x00009a6c, 0x00058384},
     250        {0x00009a70, 0x00068700},
     251        {0x00009a74, 0x00068704},
     252        {0x00009a78, 0x00068708},
     253        {0x00009a7c, 0x0006870c},
     254        {0x00009a80, 0x00068780},
     255        {0x00009a84, 0x00068784},
     256        {0x00009a88, 0x00078b00},
     257        {0x00009a8c, 0x00078b04},
     258        {0x00009a90, 0x00078b08},
     259        {0x00009a94, 0x00078b0c},
     260        {0x00009a98, 0x00078b80},
     261        {0x00009a9c, 0x00078b84},
     262        {0x00009aa0, 0x00078b88},
     263        {0x00009aa4, 0x00078b8c},
     264        {0x00009aa8, 0x00078b90},
     265        {0x00009aac, 0x000caf80},
     266        {0x00009ab0, 0x000caf84},
     267        {0x00009ab4, 0x000caf88},
     268        {0x00009ab8, 0x000caf8c},
     269        {0x00009abc, 0x000caf90},
     270        {0x00009ac0, 0x000db30c},
     271        {0x00009ac4, 0x000db310},
     272        {0x00009ac8, 0x000db384},
     273        {0x00009acc, 0x000db388},
     274        {0x00009ad0, 0x000db324},
     275        {0x00009ad4, 0x000eb704},
     276        {0x00009ad8, 0x000eb6a4},
     277        {0x00009adc, 0x000eb6a8},
     278        {0x00009ae0, 0x000eb710},
     279        {0x00009ae4, 0x000eb714},
     280        {0x00009ae8, 0x000eb720},
     281        {0x00009aec, 0x000eb724},
     282        {0x00009af0, 0x000eb728},
     283        {0x00009af4, 0x000eb72c},
     284        {0x00009af8, 0x000eb7a0},
     285        {0x00009afc, 0x000eb7a4},
     286        {0x00009b00, 0x000eb7a8},
     287        {0x00009b04, 0x000eb7b0},
     288        {0x00009b08, 0x000eb7b4},
     289        {0x00009b0c, 0x000eb7b8},
     290        {0x00009b10, 0x000eb7a5},
     291        {0x00009b14, 0x000eb7a9},
     292        {0x00009b18, 0x000eb7ad},
     293        {0x00009b1c, 0x000eb7b1},
     294        {0x00009b20, 0x000eb7b5},
     295        {0x00009b24, 0x000eb7b9},
     296        {0x00009b28, 0x000eb7c5},
     297        {0x00009b2c, 0x000eb7c9},
     298        {0x00009b30, 0x000eb7d1},
     299        {0x00009b34, 0x000eb7d5},
     300        {0x00009b38, 0x000eb7d9},
     301        {0x00009b3c, 0x000eb7c6},
     302        {0x00009b40, 0x000eb7ca},
     303        {0x00009b44, 0x000eb7ce},
     304        {0x00009b48, 0x000eb7d2},
     305        {0x00009b4c, 0x000eb7d6},
     306        {0x00009b50, 0x000eb7c3},
     307        {0x00009b54, 0x000eb7c7},
     308        {0x00009b58, 0x000eb7cb},
     309        {0x00009b5c, 0x000eb7cf},
     310        {0x00009b60, 0x000eb7d7},
     311        {0x00009b64, 0x000eb7db},
     312        {0x00009b68, 0x000eb7db},
     313        {0x00009b6c, 0x000eb7db},
     314        {0x00009b70, 0x000eb7db},
     315        {0x00009b74, 0x000eb7db},
     316        {0x00009b78, 0x000eb7db},
     317        {0x00009b7c, 0x000eb7db},
     318        {0x00009b80, 0x000eb7db},
     319        {0x00009b84, 0x000eb7db},
     320        {0x00009b88, 0x000eb7db},
     321        {0x00009b8c, 0x000eb7db},
     322        {0x00009b90, 0x000eb7db},
     323        {0x00009b94, 0x000eb7db},
     324        {0x00009b98, 0x000eb7db},
     325        {0x00009b9c, 0x000eb7db},
     326        {0x00009ba0, 0x000eb7db},
     327        {0x00009ba4, 0x000eb7db},
     328        {0x00009ba8, 0x000eb7db},
     329        {0x00009bac, 0x000eb7db},
     330        {0x00009bb0, 0x000eb7db},
     331        {0x00009bb4, 0x000eb7db},
     332        {0x00009bb8, 0x000eb7db},
     333        {0x00009bbc, 0x000eb7db},
     334        {0x00009bc0, 0x000eb7db},
     335        {0x00009bc4, 0x000eb7db},
     336        {0x00009bc8, 0x000eb7db},
     337        {0x00009bcc, 0x000eb7db},
     338        {0x00009bd0, 0x000eb7db},
     339        {0x00009bd4, 0x000eb7db},
     340        {0x00009bd8, 0x000eb7db},
     341        {0x00009bdc, 0x000eb7db},
     342        {0x00009be0, 0x000eb7db},
     343        {0x00009be4, 0x000eb7db},
     344        {0x00009be8, 0x000eb7db},
     345        {0x00009bec, 0x000eb7db},
     346        {0x00009bf0, 0x000eb7db},
     347        {0x00009bf4, 0x000eb7db},
     348        {0x00009bf8, 0x000eb7db},
     349        {0x00009bfc, 0x000eb7db},
     350        {0x0000aa00, 0x00058084},
     351        {0x0000aa04, 0x00058088},
     352        {0x0000aa08, 0x0005808c},
     353        {0x0000aa0c, 0x00058100},
     354        {0x0000aa10, 0x00058104},
     355        {0x0000aa14, 0x00058108},
     356        {0x0000aa18, 0x0005810c},
     357        {0x0000aa1c, 0x00058110},
     358        {0x0000aa20, 0x00058114},
     359        {0x0000aa24, 0x00058180},
     360        {0x0000aa28, 0x00058184},
     361        {0x0000aa2c, 0x00058188},
     362        {0x0000aa30, 0x0005818c},
     363        {0x0000aa34, 0x00058190},
     364        {0x0000aa38, 0x00058194},
     365        {0x0000aa3c, 0x000581a0},
     366        {0x0000aa40, 0x0005820c},
     367        {0x0000aa44, 0x000581a8},
     368        {0x0000aa48, 0x00058284},
     369        {0x0000aa4c, 0x00058288},
     370        {0x0000aa50, 0x00058224},
     371        {0x0000aa54, 0x00058290},
     372        {0x0000aa58, 0x00058300},
     373        {0x0000aa5c, 0x00058304},
     374        {0x0000aa60, 0x00058308},
     375        {0x0000aa64, 0x0005830c},
     376        {0x0000aa68, 0x00058380},
     377        {0x0000aa6c, 0x00058384},
     378        {0x0000aa70, 0x00068700},
     379        {0x0000aa74, 0x00068704},
     380        {0x0000aa78, 0x00068708},
     381        {0x0000aa7c, 0x0006870c},
     382        {0x0000aa80, 0x00068780},
     383        {0x0000aa84, 0x00068784},
     384        {0x0000aa88, 0x00078b00},
     385        {0x0000aa8c, 0x00078b04},
     386        {0x0000aa90, 0x00078b08},
     387        {0x0000aa94, 0x00078b0c},
     388        {0x0000aa98, 0x00078b80},
     389        {0x0000aa9c, 0x00078b84},
     390        {0x0000aaa0, 0x00078b88},
     391        {0x0000aaa4, 0x00078b8c},
     392        {0x0000aaa8, 0x00078b90},
     393        {0x0000aaac, 0x000caf80},
     394        {0x0000aab0, 0x000caf84},
     395        {0x0000aab4, 0x000caf88},
     396        {0x0000aab8, 0x000caf8c},
     397        {0x0000aabc, 0x000caf90},
     398        {0x0000aac0, 0x000db30c},
     399        {0x0000aac4, 0x000db310},
     400        {0x0000aac8, 0x000db384},
     401        {0x0000aacc, 0x000db388},
     402        {0x0000aad0, 0x000db324},
     403        {0x0000aad4, 0x000eb704},
     404        {0x0000aad8, 0x000eb6a4},
     405        {0x0000aadc, 0x000eb6a8},
     406        {0x0000aae0, 0x000eb710},
     407        {0x0000aae4, 0x000eb714},
     408        {0x0000aae8, 0x000eb720},
     409        {0x0000aaec, 0x000eb724},
     410        {0x0000aaf0, 0x000eb728},
     411        {0x0000aaf4, 0x000eb72c},
     412        {0x0000aaf8, 0x000eb7a0},
     413        {0x0000aafc, 0x000eb7a4},
     414        {0x0000ab00, 0x000eb7a8},
     415        {0x0000ab04, 0x000eb7b0},
     416        {0x0000ab08, 0x000eb7b4},
     417        {0x0000ab0c, 0x000eb7b8},
     418        {0x0000ab10, 0x000eb7a5},
     419        {0x0000ab14, 0x000eb7a9},
     420        {0x0000ab18, 0x000eb7ad},
     421        {0x0000ab1c, 0x000eb7b1},
     422        {0x0000ab20, 0x000eb7b5},
     423        {0x0000ab24, 0x000eb7b9},
     424        {0x0000ab28, 0x000eb7c5},
     425        {0x0000ab2c, 0x000eb7c9},
     426        {0x0000ab30, 0x000eb7d1},
     427        {0x0000ab34, 0x000eb7d5},
     428        {0x0000ab38, 0x000eb7d9},
     429        {0x0000ab3c, 0x000eb7c6},
     430        {0x0000ab40, 0x000eb7ca},
     431        {0x0000ab44, 0x000eb7ce},
     432        {0x0000ab48, 0x000eb7d2},
     433        {0x0000ab4c, 0x000eb7d6},
     434        {0x0000ab50, 0x000eb7c3},
     435        {0x0000ab54, 0x000eb7c7},
     436        {0x0000ab58, 0x000eb7cb},
     437        {0x0000ab5c, 0x000eb7cf},
     438        {0x0000ab60, 0x000eb7d7},
     439        {0x0000ab64, 0x000eb7db},
     440        {0x0000ab68, 0x000eb7db},
     441        {0x0000ab6c, 0x000eb7db},
     442        {0x0000ab70, 0x000eb7db},
     443        {0x0000ab74, 0x000eb7db},
     444        {0x0000ab78, 0x000eb7db},
     445        {0x0000ab7c, 0x000eb7db},
     446        {0x0000ab80, 0x000eb7db},
     447        {0x0000ab84, 0x000eb7db},
     448        {0x0000ab88, 0x000eb7db},
     449        {0x0000ab8c, 0x000eb7db},
     450        {0x0000ab90, 0x000eb7db},
     451        {0x0000ab94, 0x000eb7db},
     452        {0x0000ab98, 0x000eb7db},
     453        {0x0000ab9c, 0x000eb7db},
     454        {0x0000aba0, 0x000eb7db},
     455        {0x0000aba4, 0x000eb7db},
     456        {0x0000aba8, 0x000eb7db},
     457        {0x0000abac, 0x000eb7db},
     458        {0x0000abb0, 0x000eb7db},
     459        {0x0000abb4, 0x000eb7db},
     460        {0x0000abb8, 0x000eb7db},
     461        {0x0000abbc, 0x000eb7db},
     462        {0x0000abc0, 0x000eb7db},
     463        {0x0000abc4, 0x000eb7db},
     464        {0x0000abc8, 0x000eb7db},
     465        {0x0000abcc, 0x000eb7db},
     466        {0x0000abd0, 0x000eb7db},
     467        {0x0000abd4, 0x000eb7db},
     468        {0x0000abd8, 0x000eb7db},
     469        {0x0000abdc, 0x000eb7db},
     470        {0x0000abe0, 0x000eb7db},
     471        {0x0000abe4, 0x000eb7db},
     472        {0x0000abe8, 0x000eb7db},
     473        {0x0000abec, 0x000eb7db},
     474        {0x0000abf0, 0x000eb7db},
     475        {0x0000abf4, 0x000eb7db},
     476        {0x0000abf8, 0x000eb7db},
     477        {0x0000abfc, 0x000eb7db},
     478        {0x0000a204, 0x00000004},
     479        {0x0000a20c, 0x0001f000},
     480        {0x0000b20c, 0x0001f000},
     481        {0x0000a21c, 0x1883800a},
     482        {0x0000a230, 0x00000108},
     483        {0x0000a250, 0x0004a000},
     484        {0x0000a358, 0x7999aa0e}
     485};
    168486
    169487/**
     
    362680        {0x0000833c, 0x00000000},
    363681        {0x00008340, 0x00010380},
    364         {0x00008344, 0x00581043},
     682        {0x00008344, 0x00581003},/*< note: disabled ADHOC_MCAST_KEYID feature */
    365683        {0x00007010, 0x00000030},
     684        {0x00007034, 0x00000002},
     685        {0x00007038, 0x000004c2},
     686        {0x00007800, 0x00140000},
     687        {0x00007804, 0x0e4548d8},
     688        {0x00007808, 0x54214514},
     689        {0x0000780c, 0x02025820},
     690        {0x00007810, 0x71c0d388},
     691        {0x00007814, 0x924934a8},
     692        {0x0000781c, 0x00000000},
     693        {0x00007828, 0x66964300},
     694        {0x0000782c, 0x8db6d961},
     695        {0x00007830, 0x8db6d96c},
     696        {0x00007834, 0x6140008b},
     697        {0x0000783c, 0x72ee0a72},
     698        {0x00007840, 0xbbfffffc},
     699        {0x00007844, 0x000c0db6},
     700        {0x00007848, 0x6db6246f},
     701        {0x0000784c, 0x6d9b66db},
     702        {0x00007850, 0x6d8c6dba},
     703        {0x00007854, 0x00040000},
     704        {0x00007858, 0xdb003012},
     705        {0x0000785c, 0x04924914},
     706        {0x00007860, 0x21084210},
     707        {0x00007864, 0xf7d7ffde},
     708        {0x00007868, 0xc2034080},
     709        {0x00007870, 0x10142c00},
    366710        {0x00009808, 0x00000000},
    367711        {0x0000980c, 0xafe68e30},
  • 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.