[ARM] pxa: Gumstix Verdex PCMCIA support
[linux-2.6/verdex.git] / drivers / net / wireless / wl12xx / wl1251_event.c
blob00076c4a8a21debeb99c925dff82056990ba823d
1 /*
2 * This file is part of wl1251
4 * Copyright (c) 1998-2007 Texas Instruments Incorporated
5 * Copyright (C) 2008 Nokia Corporation
7 * Contact: Kalle Valo <kalle.valo@nokia.com>
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * version 2 as published by the Free Software Foundation.
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
21 * 02110-1301 USA
25 #include "wl1251.h"
26 #include "wl1251_reg.h"
27 #include "wl1251_io.h"
28 #include "wl1251_event.h"
29 #include "wl1251_ps.h"
31 static int wl1251_event_scan_complete(struct wl1251 *wl,
32 struct event_mailbox *mbox)
34 wl1251_debug(DEBUG_EVENT, "status: 0x%x, channels: %d",
35 mbox->scheduled_scan_status,
36 mbox->scheduled_scan_channels);
38 if (wl->scanning) {
39 mutex_unlock(&wl->mutex);
40 ieee80211_scan_completed(wl->hw, false);
41 mutex_lock(&wl->mutex);
42 wl1251_debug(DEBUG_MAC80211, "mac80211 hw scan completed");
43 wl->scanning = false;
46 return 0;
49 static void wl1251_event_mbox_dump(struct event_mailbox *mbox)
51 wl1251_debug(DEBUG_EVENT, "MBOX DUMP:");
52 wl1251_debug(DEBUG_EVENT, "\tvector: 0x%x", mbox->events_vector);
53 wl1251_debug(DEBUG_EVENT, "\tmask: 0x%x", mbox->events_mask);
56 static int wl1251_event_process(struct wl1251 *wl, struct event_mailbox *mbox)
58 int ret;
59 u32 vector;
61 wl1251_event_mbox_dump(mbox);
63 vector = mbox->events_vector & ~(mbox->events_mask);
64 wl1251_debug(DEBUG_EVENT, "vector: 0x%x", vector);
66 if (vector & SCAN_COMPLETE_EVENT_ID) {
67 ret = wl1251_event_scan_complete(wl, mbox);
68 if (ret < 0)
69 return ret;
72 if (vector & BSS_LOSE_EVENT_ID) {
73 wl1251_debug(DEBUG_EVENT, "BSS_LOSE_EVENT");
75 if (wl->psm_requested && wl->psm) {
76 ret = wl1251_ps_set_mode(wl, STATION_ACTIVE_MODE);
77 if (ret < 0)
78 return ret;
82 return 0;
85 int wl1251_event_unmask(struct wl1251 *wl)
87 int ret;
89 ret = wl1251_acx_event_mbox_mask(wl, ~(wl->event_mask));
90 if (ret < 0)
91 return ret;
93 return 0;
96 void wl1251_event_mbox_config(struct wl1251 *wl)
98 wl->mbox_ptr[0] = wl1251_reg_read32(wl, REG_EVENT_MAILBOX_PTR);
99 wl->mbox_ptr[1] = wl->mbox_ptr[0] + sizeof(struct event_mailbox);
101 wl1251_debug(DEBUG_EVENT, "MBOX ptrs: 0x%x 0x%x",
102 wl->mbox_ptr[0], wl->mbox_ptr[1]);
105 int wl1251_event_handle(struct wl1251 *wl, u8 mbox_num)
107 struct event_mailbox mbox;
108 int ret;
110 wl1251_debug(DEBUG_EVENT, "EVENT on mbox %d", mbox_num);
112 if (mbox_num > 1)
113 return -EINVAL;
115 /* first we read the mbox descriptor */
116 wl1251_mem_read(wl, wl->mbox_ptr[mbox_num], &mbox,
117 sizeof(struct event_mailbox));
119 /* process the descriptor */
120 ret = wl1251_event_process(wl, &mbox);
121 if (ret < 0)
122 return ret;
124 /* then we let the firmware know it can go on...*/
125 wl1251_reg_write32(wl, ACX_REG_INTERRUPT_TRIG, INTR_TRIG_EVENT_ACK);
127 return 0;