]> git.kernelconcepts.de Git - karo-tx-linux.git/blob - drivers/staging/vt6656/wcmd.c
mtd: nand: atmel: Add ->setup_data_interface() hooks
[karo-tx-linux.git] / drivers / staging / vt6656 / wcmd.c
1 /*
2  * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3  * All rights reserved.
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  *
16  * File: wcmd.c
17  *
18  * Purpose: Handles the management command interface functions
19  *
20  * Author: Lyndon Chen
21  *
22  * Date: May 8, 2003
23  *
24  * Functions:
25  *      vnt_cmd_complete - Command Complete function
26  *      vnt_schedule_command - Push Command and wait Command Scheduler to do
27  *      vnt_cmd_timer_wait- Call back timer
28  *
29  * Revision History:
30  *
31  */
32
33 #include "device.h"
34 #include "mac.h"
35 #include "wcmd.h"
36 #include "power.h"
37 #include "usbpipe.h"
38 #include "rxtx.h"
39 #include "rf.h"
40
41 static void vnt_cmd_timer_wait(struct vnt_private *priv, unsigned long msecs)
42 {
43         schedule_delayed_work(&priv->run_command_work, msecs_to_jiffies(msecs));
44 }
45
46 static int vnt_cmd_complete(struct vnt_private *priv)
47 {
48         priv->command_state = WLAN_CMD_IDLE;
49         if (priv->free_cmd_queue == CMD_Q_SIZE) {
50                 /* Command Queue Empty */
51                 priv->cmd_running = false;
52                 return true;
53         }
54
55         priv->command = priv->cmd_queue[priv->cmd_dequeue_idx];
56
57         ADD_ONE_WITH_WRAP_AROUND(priv->cmd_dequeue_idx, CMD_Q_SIZE);
58         priv->free_cmd_queue++;
59         priv->cmd_running = true;
60
61         switch (priv->command) {
62         case WLAN_CMD_INIT_MAC80211:
63                 priv->command_state = WLAN_CMD_INIT_MAC80211_START;
64                 break;
65
66         case WLAN_CMD_TBTT_WAKEUP:
67                 priv->command_state = WLAN_CMD_TBTT_WAKEUP_START;
68                 break;
69
70         case WLAN_CMD_BECON_SEND:
71                 priv->command_state = WLAN_CMD_BECON_SEND_START;
72                 break;
73
74         case WLAN_CMD_SETPOWER:
75                 priv->command_state = WLAN_CMD_SETPOWER_START;
76                 break;
77
78         case WLAN_CMD_CHANGE_ANTENNA:
79                 priv->command_state = WLAN_CMD_CHANGE_ANTENNA_START;
80                 break;
81
82         default:
83                 break;
84         }
85
86         vnt_cmd_timer_wait(priv, 0);
87
88         return true;
89 }
90
91 void vnt_run_command(struct work_struct *work)
92 {
93         struct vnt_private *priv =
94                 container_of(work, struct vnt_private, run_command_work.work);
95
96         if (test_bit(DEVICE_FLAGS_DISCONNECTED, &priv->flags))
97                 return;
98
99         if (!priv->cmd_running)
100                 return;
101
102         switch (priv->command_state) {
103         case WLAN_CMD_INIT_MAC80211_START:
104                 if (priv->mac_hw)
105                         break;
106
107                 dev_info(&priv->usb->dev, "Starting mac80211\n");
108
109                 if (vnt_init(priv)) {
110                         /* If fail all ends TODO retry */
111                         dev_err(&priv->usb->dev, "failed to start\n");
112                         ieee80211_free_hw(priv->hw);
113                         return;
114                 }
115
116                 break;
117
118         case WLAN_CMD_TBTT_WAKEUP_START:
119                 vnt_next_tbtt_wakeup(priv);
120                 break;
121
122         case WLAN_CMD_BECON_SEND_START:
123                 if (!priv->vif)
124                         break;
125
126                 vnt_beacon_make(priv, priv->vif);
127
128                 vnt_mac_reg_bits_on(priv, MAC_REG_TCR, TCR_AUTOBCNTX);
129
130                 break;
131
132         case WLAN_CMD_SETPOWER_START:
133
134                 vnt_rf_setpower(priv, priv->current_rate,
135                                 priv->hw->conf.chandef.chan->hw_value);
136
137                 break;
138
139         case WLAN_CMD_CHANGE_ANTENNA_START:
140                 dev_dbg(&priv->usb->dev, "Change from Antenna%d to",
141                         priv->rx_antenna_sel);
142
143                 if (priv->rx_antenna_sel == 0) {
144                         priv->rx_antenna_sel = 1;
145                         if (priv->tx_rx_ant_inv)
146                                 vnt_set_antenna_mode(priv, ANT_RXA);
147                         else
148                                 vnt_set_antenna_mode(priv, ANT_RXB);
149                 } else {
150                         priv->rx_antenna_sel = 0;
151                         if (priv->tx_rx_ant_inv)
152                                 vnt_set_antenna_mode(priv, ANT_RXB);
153                         else
154                                 vnt_set_antenna_mode(priv, ANT_RXA);
155                 }
156                 break;
157
158         default:
159                 break;
160         }
161
162         vnt_cmd_complete(priv);
163 }
164
165 int vnt_schedule_command(struct vnt_private *priv, enum vnt_cmd command)
166 {
167         if (priv->free_cmd_queue == 0)
168                 return false;
169
170         priv->cmd_queue[priv->cmd_enqueue_idx] = command;
171
172         ADD_ONE_WITH_WRAP_AROUND(priv->cmd_enqueue_idx, CMD_Q_SIZE);
173         priv->free_cmd_queue--;
174
175         if (!priv->cmd_running)
176                 vnt_cmd_complete(priv);
177
178         return true;
179 }
180
181 void vnt_reset_command_timer(struct vnt_private *priv)
182 {
183         priv->free_cmd_queue = CMD_Q_SIZE;
184         priv->cmd_dequeue_idx = 0;
185         priv->cmd_enqueue_idx = 0;
186         priv->command_state = WLAN_CMD_IDLE;
187         priv->cmd_running = false;
188 }