~ubuntu-branches/ubuntu/precise/linux-ti-omap4/precise

« back to all changes in this revision

Viewing changes to drivers/net/wireless/ath/ath5k/eeprom.c

  • Committer: Bazaar Package Importer
  • Author(s): Paolo Pisati
  • Date: 2011-06-29 15:23:51 UTC
  • mfrom: (26.1.1 natty-proposed)
  • Revision ID: james.westby@ubuntu.com-20110629152351-xs96tm303d95rpbk
Tags: 3.0.0-1200.2
* Rebased against 3.0.0-6.7
* BSP from TI based on 3.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
72
72
ath5k_eeprom_init_header(struct ath5k_hw *ah)
73
73
{
74
74
        struct ath5k_eeprom_info *ee = &ah->ah_capabilities.cap_eeprom;
75
 
        int ret;
76
75
        u16 val;
77
76
        u32 cksum, offset, eep_max = AR5K_EEPROM_INFO_MAX;
78
77
 
192
191
        struct ath5k_eeprom_info *ee = &ah->ah_capabilities.cap_eeprom;
193
192
        u32 o = *offset;
194
193
        u16 val;
195
 
        int ret, i = 0;
 
194
        int i = 0;
196
195
 
197
196
        AR5K_EEPROM_READ(o++, val);
198
197
        ee->ee_switch_settling[mode]    = (val >> 8) & 0x7f;
252
251
        struct ath5k_eeprom_info *ee = &ah->ah_capabilities.cap_eeprom;
253
252
        u32 o = *offset;
254
253
        u16 val;
255
 
        int ret;
256
254
 
257
255
        ee->ee_n_piers[mode] = 0;
258
256
        AR5K_EEPROM_READ(o++, val);
515
513
        int o = *offset;
516
514
        int i = 0;
517
515
        u8 freq1, freq2;
518
 
        int ret;
519
516
        u16 val;
520
517
 
521
518
        ee->ee_n_piers[mode] = 0;
551
548
{
552
549
        struct ath5k_eeprom_info *ee = &ah->ah_capabilities.cap_eeprom;
553
550
        struct ath5k_chan_pcal_info *pcal = ee->ee_pwr_cal_a;
554
 
        int i, ret;
 
551
        int i;
555
552
        u16 val;
556
553
        u8 mask;
557
554
 
663
660
                vp[i] = (ip[i] * max + (100 - ip[i]) * min) / 100;
664
661
}
665
662
 
 
663
static int
 
664
ath5k_eeprom_free_pcal_info(struct ath5k_hw *ah, int mode)
 
665
{
 
666
        struct ath5k_eeprom_info *ee = &ah->ah_capabilities.cap_eeprom;
 
667
        struct ath5k_chan_pcal_info *chinfo;
 
668
        u8 pier, pdg;
 
669
 
 
670
        switch (mode) {
 
671
        case AR5K_EEPROM_MODE_11A:
 
672
                if (!AR5K_EEPROM_HDR_11A(ee->ee_header))
 
673
                        return 0;
 
674
                chinfo = ee->ee_pwr_cal_a;
 
675
                break;
 
676
        case AR5K_EEPROM_MODE_11B:
 
677
                if (!AR5K_EEPROM_HDR_11B(ee->ee_header))
 
678
                        return 0;
 
679
                chinfo = ee->ee_pwr_cal_b;
 
680
                break;
 
681
        case AR5K_EEPROM_MODE_11G:
 
682
                if (!AR5K_EEPROM_HDR_11G(ee->ee_header))
 
683
                        return 0;
 
684
                chinfo = ee->ee_pwr_cal_g;
 
685
                break;
 
686
        default:
 
687
                return -EINVAL;
 
688
        }
 
689
 
 
690
        for (pier = 0; pier < ee->ee_n_piers[mode]; pier++) {
 
691
                if (!chinfo[pier].pd_curves)
 
692
                        continue;
 
693
 
 
694
                for (pdg = 0; pdg < AR5K_EEPROM_N_PD_CURVES; pdg++) {
 
695
                        struct ath5k_pdgain_info *pd =
 
696
                                        &chinfo[pier].pd_curves[pdg];
 
697
 
 
698
                        kfree(pd->pd_step);
 
699
                        kfree(pd->pd_pwr);
 
700
                }
 
701
 
 
702
                kfree(chinfo[pier].pd_curves);
 
703
        }
 
704
 
 
705
        return 0;
 
706
}
 
707
 
666
708
/* Convert RF5111 specific data to generic raw data
667
709
 * used by interpolation code */
668
710
static int
687
729
                                GFP_KERNEL);
688
730
 
689
731
                if (!chinfo[pier].pd_curves)
690
 
                        return -ENOMEM;
 
732
                        goto err_out;
691
733
 
692
734
                /* Only one curve for RF5111
693
735
                 * find out which one and place
711
753
                pd->pd_step = kcalloc(AR5K_EEPROM_N_PWR_POINTS_5111,
712
754
                                        sizeof(u8), GFP_KERNEL);
713
755
                if (!pd->pd_step)
714
 
                        return -ENOMEM;
 
756
                        goto err_out;
715
757
 
716
758
                pd->pd_pwr = kcalloc(AR5K_EEPROM_N_PWR_POINTS_5111,
717
759
                                        sizeof(s16), GFP_KERNEL);
718
760
                if (!pd->pd_pwr)
719
 
                        return -ENOMEM;
 
761
                        goto err_out;
720
762
 
721
763
                /* Fill raw dataset
722
764
                 * (convert power to 0.25dB units
737
779
        }
738
780
 
739
781
        return 0;
 
782
 
 
783
err_out:
 
784
        ath5k_eeprom_free_pcal_info(ah, mode);
 
785
        return -ENOMEM;
740
786
}
741
787
 
742
788
/* Parse EEPROM data */
870
916
                                        GFP_KERNEL);
871
917
 
872
918
                if (!chinfo[pier].pd_curves)
873
 
                        return -ENOMEM;
 
919
                        goto err_out;
874
920
 
875
921
                /* Fill pd_curves */
876
922
                for (pdg = 0; pdg < ee->ee_pd_gains[mode]; pdg++) {
889
935
                                                sizeof(u8), GFP_KERNEL);
890
936
 
891
937
                                if (!pd->pd_step)
892
 
                                        return -ENOMEM;
 
938
                                        goto err_out;
893
939
 
894
940
                                pd->pd_pwr = kcalloc(pd->pd_points,
895
941
                                                sizeof(s16), GFP_KERNEL);
896
942
 
897
943
                                if (!pd->pd_pwr)
898
 
                                        return -ENOMEM;
899
 
 
 
944
                                        goto err_out;
900
945
 
901
946
                                /* Fill raw dataset
902
947
                                 * (all power levels are in 0.25dB units) */
928
973
                                                sizeof(u8), GFP_KERNEL);
929
974
 
930
975
                                if (!pd->pd_step)
931
 
                                        return -ENOMEM;
 
976
                                        goto err_out;
932
977
 
933
978
                                pd->pd_pwr = kcalloc(pd->pd_points,
934
979
                                                sizeof(s16), GFP_KERNEL);
935
980
 
936
981
                                if (!pd->pd_pwr)
937
 
                                        return -ENOMEM;
 
982
                                        goto err_out;
938
983
 
939
984
                                /* Fill raw dataset
940
985
                                 * (all power levels are in 0.25dB units) */
957
1002
        }
958
1003
 
959
1004
        return 0;
 
1005
 
 
1006
err_out:
 
1007
        ath5k_eeprom_free_pcal_info(ah, mode);
 
1008
        return -ENOMEM;
960
1009
}
961
1010
 
962
1011
/* Parse EEPROM data */
970
1019
        u32 offset;
971
1020
        u8 i, c;
972
1021
        u16 val;
973
 
        int ret;
974
1022
        u8 pd_gains = 0;
975
1023
 
976
1024
        /* Count how many curves we have and
1084
1132
 *
1085
1133
 * To recreate the curves we read here the points and interpolate
1086
1134
 * later. Note that in most cases only 2 (higher and lower) curves are
1087
 
 * used (like RF5112) but vendors have the oportunity to include all
 
1135
 * used (like RF5112) but vendors have the opportunity to include all
1088
1136
 * 4 curves on eeprom. The final curve (higher power) has an extra
1089
1137
 * point for better accuracy like RF5112.
1090
1138
 */
1160
1208
                                        GFP_KERNEL);
1161
1209
 
1162
1210
                if (!chinfo[pier].pd_curves)
1163
 
                        return -ENOMEM;
 
1211
                        goto err_out;
1164
1212
 
1165
1213
                /* Fill pd_curves */
1166
1214
                for (pdg = 0; pdg < ee->ee_pd_gains[mode]; pdg++) {
1181
1229
                                        sizeof(u8), GFP_KERNEL);
1182
1230
 
1183
1231
                        if (!pd->pd_step)
1184
 
                                return -ENOMEM;
 
1232
                                goto err_out;
1185
1233
 
1186
1234
                        pd->pd_pwr = kcalloc(pd->pd_points,
1187
1235
                                        sizeof(s16), GFP_KERNEL);
1188
1236
 
1189
1237
                        if (!pd->pd_pwr)
1190
 
                                return -ENOMEM;
 
1238
                                goto err_out;
1191
1239
 
1192
1240
                        /* Fill raw dataset
1193
1241
                         * convert all pwr levels to
1217
1265
        }
1218
1266
 
1219
1267
        return 0;
 
1268
 
 
1269
err_out:
 
1270
        ath5k_eeprom_free_pcal_info(ah, mode);
 
1271
        return -ENOMEM;
1220
1272
}
1221
1273
 
1222
1274
/* Parse EEPROM data */
1228
1280
        struct ath5k_chan_pcal_info *chinfo;
1229
1281
        u8 *pdgain_idx = ee->ee_pdc_to_idx[mode];
1230
1282
        u32 offset;
1231
 
        int idx, i, ret;
 
1283
        int idx, i;
1232
1284
        u16 val;
1233
1285
        u8 pd_gains = 0;
1234
1286
 
1306
1358
                        /*
1307
1359
                         * Pd gain 0 is not the last pd gain
1308
1360
                         * so it only has 2 pd points.
1309
 
                         * Continue wih pd gain 1.
 
1361
                         * Continue with pd gain 1.
1310
1362
                         */
1311
1363
                        pcinfo->pwr_i[1] = (val >> 10) & 0x1f;
1312
1364
 
1419
1471
        u8 *rate_target_pwr_num;
1420
1472
        u32 offset;
1421
1473
        u16 val;
1422
 
        int ret, i;
 
1474
        int i;
1423
1475
 
1424
1476
        offset = AR5K_EEPROM_TARGET_PWRSTART(ee->ee_misc1);
1425
1477
        rate_target_pwr_num = &ee->ee_rate_target_pwr_num[mode];
1538
1590
        return 0;
1539
1591
}
1540
1592
 
1541
 
static int
1542
 
ath5k_eeprom_free_pcal_info(struct ath5k_hw *ah, int mode)
1543
 
{
1544
 
        struct ath5k_eeprom_info *ee = &ah->ah_capabilities.cap_eeprom;
1545
 
        struct ath5k_chan_pcal_info *chinfo;
1546
 
        u8 pier, pdg;
1547
 
 
1548
 
        switch (mode) {
1549
 
        case AR5K_EEPROM_MODE_11A:
1550
 
                if (!AR5K_EEPROM_HDR_11A(ee->ee_header))
1551
 
                        return 0;
1552
 
                chinfo = ee->ee_pwr_cal_a;
1553
 
                break;
1554
 
        case AR5K_EEPROM_MODE_11B:
1555
 
                if (!AR5K_EEPROM_HDR_11B(ee->ee_header))
1556
 
                        return 0;
1557
 
                chinfo = ee->ee_pwr_cal_b;
1558
 
                break;
1559
 
        case AR5K_EEPROM_MODE_11G:
1560
 
                if (!AR5K_EEPROM_HDR_11G(ee->ee_header))
1561
 
                        return 0;
1562
 
                chinfo = ee->ee_pwr_cal_g;
1563
 
                break;
1564
 
        default:
1565
 
                return -EINVAL;
1566
 
        }
1567
 
 
1568
 
        for (pier = 0; pier < ee->ee_n_piers[mode]; pier++) {
1569
 
                if (!chinfo[pier].pd_curves)
1570
 
                        continue;
1571
 
 
1572
 
                for (pdg = 0; pdg < ee->ee_pd_gains[mode]; pdg++) {
1573
 
                        struct ath5k_pdgain_info *pd =
1574
 
                                        &chinfo[pier].pd_curves[pdg];
1575
 
 
1576
 
                        if (pd != NULL) {
1577
 
                                kfree(pd->pd_step);
1578
 
                                kfree(pd->pd_pwr);
1579
 
                        }
1580
 
                }
1581
 
 
1582
 
                kfree(chinfo[pier].pd_curves);
1583
 
        }
1584
 
 
1585
 
        return 0;
1586
 
}
1587
 
 
1588
1593
/* Read conformance test limits used for regulatory control */
1589
1594
static int
1590
1595
ath5k_eeprom_read_ctl_info(struct ath5k_hw *ah)
1593
1598
        struct ath5k_edge_power *rep;
1594
1599
        unsigned int fmask, pmask;
1595
1600
        unsigned int ctl_mode;
1596
 
        int ret, i, j;
 
1601
        int i, j;
1597
1602
        u32 offset;
1598
1603
        u16 val;
1599
1604
 
1725
1730
        return ret;
1726
1731
}
1727
1732
 
1728
 
/*
1729
 
 * Read the MAC address from eeprom
1730
 
 */
1731
 
int ath5k_eeprom_read_mac(struct ath5k_hw *ah, u8 *mac)
1732
 
{
1733
 
        u8 mac_d[ETH_ALEN] = {};
1734
 
        u32 total, offset;
1735
 
        u16 data;
1736
 
        int octet, ret;
1737
 
 
1738
 
        ret = ath5k_hw_nvram_read(ah, 0x20, &data);
1739
 
        if (ret)
1740
 
                return ret;
1741
 
 
1742
 
        for (offset = 0x1f, octet = 0, total = 0; offset >= 0x1d; offset--) {
1743
 
                ret = ath5k_hw_nvram_read(ah, offset, &data);
1744
 
                if (ret)
1745
 
                        return ret;
1746
 
 
1747
 
                total += data;
1748
 
                mac_d[octet + 1] = data & 0xff;
1749
 
                mac_d[octet] = data >> 8;
1750
 
                octet += 2;
1751
 
        }
1752
 
 
1753
 
        if (!total || total == 3 * 0xffff)
1754
 
                return -EINVAL;
1755
 
 
1756
 
        memcpy(mac, mac_d, ETH_ALEN);
1757
 
 
1758
 
        return 0;
1759
 
}
1760
 
 
1761
1733
 
1762
1734
/***********************\
1763
1735
* Init/Detach functions *