Staging: w35und: reformat wbhal.c
[linux-2.6] / drivers / staging / winbond / wbhal.c
1 #include "sysdef.h"
2 #include "wbhal_f.h"
3 #include "wblinux_f.h"
4
5 void hal_set_ethernet_address(struct hw_data *pHwData, u8 * current_address)
6 {
7         u32 ltmp[2];
8
9         if (pHwData->SurpriseRemove)
10                 return;
11
12         memcpy(pHwData->CurrentMacAddress, current_address, ETH_ALEN);
13
14         ltmp[0] = cpu_to_le32(*(u32 *) pHwData->CurrentMacAddress);
15         ltmp[1] =
16             cpu_to_le32(*(u32 *) (pHwData->CurrentMacAddress + 4)) & 0xffff;
17
18         Wb35Reg_BurstWrite(pHwData, 0x03e8, ltmp, 2, AUTO_INCREMENT);
19 }
20
21 void hal_get_permanent_address(struct hw_data *pHwData, u8 * pethernet_address)
22 {
23         if (pHwData->SurpriseRemove)
24                 return;
25
26         memcpy(pethernet_address, pHwData->PermanentMacAddress, 6);
27 }
28
29 //---------------------------------------------------------------------------------------------------
30 void hal_set_beacon_period(struct hw_data *pHwData, u16 beacon_period)
31 {
32         u32 tmp;
33
34         if (pHwData->SurpriseRemove)
35                 return;
36
37         pHwData->BeaconPeriod = beacon_period;
38         tmp = pHwData->BeaconPeriod << 16;
39         tmp |= pHwData->ProbeDelay;
40         Wb35Reg_Write(pHwData, 0x0848, tmp);
41 }
42
43 static void hal_set_current_channel_ex(struct hw_data *pHwData,
44                                        ChanInfo channel)
45 {
46         struct wb35_reg *reg = &pHwData->reg;
47
48         if (pHwData->SurpriseRemove)
49                 return;
50
51         printk("Going to channel: %d/%d\n", channel.band, channel.ChanNo);
52
53         RFSynthesizer_SwitchingChannel(pHwData, channel);       // Switch channel
54         pHwData->Channel = channel.ChanNo;
55         pHwData->band = channel.band;
56 #ifdef _PE_STATE_DUMP_
57         printk("Set channel is %d, band =%d\n", pHwData->Channel,
58                pHwData->band);
59 #endif
60         reg->M28_MacControl &= ~0xff;   // Clean channel information field
61         reg->M28_MacControl |= channel.ChanNo;
62         Wb35Reg_WriteWithCallbackValue(pHwData, 0x0828, reg->M28_MacControl,
63                                        (s8 *) & channel, sizeof(ChanInfo));
64 }
65
66 //---------------------------------------------------------------------------------------------------
67 void hal_set_current_channel(struct hw_data *pHwData, ChanInfo channel)
68 {
69         hal_set_current_channel_ex(pHwData, channel);
70 }
71
72 //---------------------------------------------------------------------------------------------------
73 void hal_set_accept_broadcast(struct hw_data *pHwData, u8 enable)
74 {
75         struct wb35_reg *reg = &pHwData->reg;
76
77         if (pHwData->SurpriseRemove)
78                 return;
79
80         reg->M00_MacControl &= ~0x02000000;     //The HW value
81
82         if (enable)
83                 reg->M00_MacControl |= 0x02000000;      //The HW value
84
85         Wb35Reg_Write(pHwData, 0x0800, reg->M00_MacControl);
86 }
87
88 //for wep key error detection, we need to accept broadcast packets to be received temporary.
89 void hal_set_accept_promiscuous(struct hw_data *pHwData, u8 enable)
90 {
91         struct wb35_reg *reg = &pHwData->reg;
92
93         if (pHwData->SurpriseRemove)
94                 return;
95         if (enable) {
96                 reg->M00_MacControl |= 0x00400000;
97                 Wb35Reg_Write(pHwData, 0x0800, reg->M00_MacControl);
98         } else {
99                 reg->M00_MacControl &= ~0x00400000;
100                 Wb35Reg_Write(pHwData, 0x0800, reg->M00_MacControl);
101         }
102 }
103
104 void hal_set_accept_multicast(struct hw_data *pHwData, u8 enable)
105 {
106         struct wb35_reg *reg = &pHwData->reg;
107
108         if (pHwData->SurpriseRemove)
109                 return;
110
111         reg->M00_MacControl &= ~0x01000000;     //The HW value
112         if (enable)
113                 reg->M00_MacControl |= 0x01000000;      //The HW value
114         Wb35Reg_Write(pHwData, 0x0800, reg->M00_MacControl);
115 }
116
117 void hal_set_accept_beacon(struct hw_data *pHwData, u8 enable)
118 {
119         struct wb35_reg *reg = &pHwData->reg;
120
121         if (pHwData->SurpriseRemove)
122                 return;
123
124         // 20040108 debug
125         if (!enable)            //Due to SME and MLME are not suitable for 35
126                 return;
127
128         reg->M00_MacControl &= ~0x04000000;     //The HW value
129         if (enable)
130                 reg->M00_MacControl |= 0x04000000;      //The HW value
131
132         Wb35Reg_Write(pHwData, 0x0800, reg->M00_MacControl);
133 }
134
135 //---------------------------------------------------------------------------------------------------
136
137 void hal_stop(struct hw_data *pHwData)
138 {
139         struct wb35_reg *reg = &pHwData->reg;
140
141         pHwData->Wb35Rx.rx_halt = 1;
142         Wb35Rx_stop(pHwData);
143
144         pHwData->Wb35Tx.tx_halt = 1;
145         Wb35Tx_stop(pHwData);
146
147         reg->D00_DmaControl &= ~0xc0000000;     //Tx Off, Rx Off
148         Wb35Reg_Write(pHwData, 0x0400, reg->D00_DmaControl);
149 }
150
151 unsigned char hal_idle(struct hw_data *pHwData)
152 {
153         struct wb35_reg *reg = &pHwData->reg;
154         struct wb_usb *pWbUsb = &pHwData->WbUsb;
155
156         if (!pHwData->SurpriseRemove
157             && (pWbUsb->DetectCount || reg->EP0vm_state != VM_STOP))
158                 return false;
159
160         return true;
161 }
162
163 void hal_set_radio_mode(struct hw_data *pHwData, unsigned char radio_off)
164 {
165         struct wb35_reg *reg = &pHwData->reg;
166
167         if (pHwData->SurpriseRemove)
168                 return;
169
170         if (radio_off)          //disable Baseband receive off
171         {
172                 pHwData->CurrentRadioSw = 1;    // off
173                 reg->M24_MacControl &= 0xffffffbf;
174         } else {
175                 pHwData->CurrentRadioSw = 0;    // on
176                 reg->M24_MacControl |= 0x00000040;
177         }
178         Wb35Reg_Write(pHwData, 0x0824, reg->M24_MacControl);
179 }
180
181 u8 hal_get_antenna_number(struct hw_data *pHwData)
182 {
183         struct wb35_reg *reg = &pHwData->reg;
184
185         if ((reg->BB2C & BIT(11)) == 0)
186                 return 0;
187         else
188                 return 1;
189 }
190
191 //----------------------------------------------------------------------------------------------------
192 //0 : radio on; 1: radio off
193 u8 hal_get_hw_radio_off(struct hw_data * pHwData)
194 {
195         struct wb35_reg *reg = &pHwData->reg;
196
197         if (pHwData->SurpriseRemove)
198                 return 1;
199
200         //read the bit16 of register U1B0
201         Wb35Reg_Read(pHwData, 0x3b0, &reg->U1B0);
202         if ((reg->U1B0 & 0x00010000)) {
203                 pHwData->CurrentRadioHw = 1;
204                 return 1;
205         } else {
206                 pHwData->CurrentRadioHw = 0;
207                 return 0;
208         }
209 }
210
211 unsigned char hal_get_dxx_reg(struct hw_data *pHwData, u16 number, u32 * pValue)
212 {
213         if (number < 0x1000)
214                 number += 0x1000;
215         return Wb35Reg_ReadSync(pHwData, number, pValue);
216 }
217
218 unsigned char hal_set_dxx_reg(struct hw_data *pHwData, u16 number, u32 value)
219 {
220         unsigned char ret;
221
222         if (number < 0x1000)
223                 number += 0x1000;
224         ret = Wb35Reg_WriteSync(pHwData, number, value);
225         return ret;
226 }
227
228 void hal_set_rf_power(struct hw_data *pHwData, u8 PowerIndex)
229 {
230         RFSynthesizer_SetPowerIndex(pHwData, PowerIndex);
231 }