huge madwifi update (work in progress, disabled by default, compiles but breaks at...
[openwrt.git] / package / madwifi / patches-r3776 / 318-ifxmips_eeprom.patch
1 Index: madwifi-trunk-r3776/ath_hal/ah_os.c
2 ===================================================================
3 --- madwifi-trunk-r3776.orig/ath_hal/ah_os.c    2008-07-17 00:21:30.000000000 +0200
4 +++ madwifi-trunk-r3776/ath_hal/ah_os.c 2008-07-17 04:00:18.000000000 +0200
5 @@ -917,9 +917,56 @@
6   * NB: see the comments in ah_osdep.h about byte-swapping register
7   *     reads and writes to understand what's going on below.
8   */
9 +
10 +#ifdef CONFIG_IFXMIPS
11 +extern int ifxmips_has_brn_block(void);
12 +static int ifxmips_emulate = 0;
13 +#define EEPROM_EMULATION 1
14 +#endif
15 +
16 +#ifdef EEPROM_EMULATION
17 +static int ath_hal_eeprom(struct ath_hal *ah, unsigned long addr, int val, int write)
18 +{
19 +       static int addrsel = 0;
20 +       static int rc = 0;
21 +
22 +       if (write) {
23 +               if(addr == 0x6000) {
24 +                       addrsel = val * 2;
25 +                       rc = 0;
26 +               }
27 +       } else {
28 +               switch(addr)
29 +               {
30 +               case 0x600c:
31 +                       if(rc++ < 2)
32 +                               val = 0x00000000;
33 +                       else
34 +                               val = 0x00000002;
35 +                       break;
36 +               case 0x6004:
37 +                       val = cpu_to_le16(__raw_readw((u16 *) KSEG1ADDR(0xb07f0400 + addrsel)));
38 +                       /* this forces the regdomain to 0x00 (worldwide), as the original setting
39 +                        * causes issues with the HAL */
40 +                       if (addrsel == 0x17e)
41 +                               val = 0;
42 +                       break;
43 +               }
44 +       }
45 +       return val;
46 +}
47 +#endif
48 +
49  void __ahdecl
50  ath_hal_reg_write(struct ath_hal *ah, u_int address, u_int32_t value)
51  {
52 +#ifdef EEPROM_EMULATION
53 +       if((address >= 0x6000) && (address <= 0x6010) && ifxmips_emulate) {
54 +               ath_hal_eeprom(ah, address, value, 1);
55 +               return;
56 +       }
57 +#endif
58 +
59         _trace_regop(ah, REGOP_WRITE, address, value);
60         _OS_REG_WRITE(ah, address, value);
61  }
62 @@ -929,7 +976,14 @@
63  u_int32_t __ahdecl
64  ath_hal_reg_read(struct ath_hal *ah, u_int address)
65  {
66 -       u_int32_t val = _OS_REG_READ(ah, address);
67 +       u_int32_t val;
68 +
69 +#ifdef EEPROM_EMULATION
70 +       if((address >= 0x6000) && (address <= 0x6010) && ifxmips_emulate)
71 +               val = ath_hal_eeprom(ah, address, 0, 0);
72 +       else
73 +#endif
74 +               val = _OS_REG_READ(ah, address);
75         _trace_regop(ah, REGOP_READ, address, val);
76         return val;
77  }
78 @@ -1123,6 +1177,9 @@
79  #ifdef MMIOTRACE
80         kmmio_logmsg = _kmmio_logmsg;
81  #endif
82 +#ifdef CONFIG_IFXMIPS
83 +       ifxmips_emulate = ifxmips_has_brn_block();
84 +#endif
85  
86         sep = "";
87         for (i = 0; ath_hal_buildopts[i] != NULL; i++) {