blob: 1a0a0bc1a31ff0908372965b045bd1cd007ed307 [file] [log] [blame]
Kalle Valo2f01a1f2009-04-29 23:33:31 +03001/*
Kalle Valo80301cd2009-06-12 14:17:39 +03002 * This file is part of wl1251
Kalle Valo2f01a1f2009-04-29 23:33:31 +03003 *
4 * Copyright (c) 1998-2007 Texas Instruments Incorporated
5 * Copyright (C) 2008 Nokia Corporation
6 *
7 * Contact: Kalle Valo <kalle.valo@nokia.com>
8 *
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.
12 *
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.
17 *
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
22 *
23 */
24
Kalle Valo13674112009-06-12 14:17:25 +030025#include "wl1251.h"
Kalle Valo2f01a1f2009-04-29 23:33:31 +030026#include "reg.h"
Kalle Valoef2f8d42009-06-12 14:17:19 +030027#include "wl1251_spi.h"
28#include "wl1251_event.h"
29#include "wl1251_ps.h"
Kalle Valo2f01a1f2009-04-29 23:33:31 +030030
Kalle Valo80301cd2009-06-12 14:17:39 +030031static int wl1251_event_scan_complete(struct wl1251 *wl,
Kalle Valo2f01a1f2009-04-29 23:33:31 +030032 struct event_mailbox *mbox)
33{
Kalle Valo80301cd2009-06-12 14:17:39 +030034 wl1251_debug(DEBUG_EVENT, "status: 0x%x, channels: %d",
Kalle Valo2f01a1f2009-04-29 23:33:31 +030035 mbox->scheduled_scan_status,
36 mbox->scheduled_scan_channels);
37
38 if (wl->scanning) {
39 mutex_unlock(&wl->mutex);
40 ieee80211_scan_completed(wl->hw, false);
41 mutex_lock(&wl->mutex);
42 wl->scanning = false;
43 }
44
45 return 0;
46}
47
Kalle Valo80301cd2009-06-12 14:17:39 +030048static void wl1251_event_mbox_dump(struct event_mailbox *mbox)
Kalle Valo2f01a1f2009-04-29 23:33:31 +030049{
Kalle Valo80301cd2009-06-12 14:17:39 +030050 wl1251_debug(DEBUG_EVENT, "MBOX DUMP:");
51 wl1251_debug(DEBUG_EVENT, "\tvector: 0x%x", mbox->events_vector);
52 wl1251_debug(DEBUG_EVENT, "\tmask: 0x%x", mbox->events_mask);
Kalle Valo2f01a1f2009-04-29 23:33:31 +030053}
54
Kalle Valo80301cd2009-06-12 14:17:39 +030055static int wl1251_event_process(struct wl1251 *wl, struct event_mailbox *mbox)
Kalle Valo2f01a1f2009-04-29 23:33:31 +030056{
57 int ret;
58 u32 vector;
59
Kalle Valo80301cd2009-06-12 14:17:39 +030060 wl1251_event_mbox_dump(mbox);
Kalle Valo2f01a1f2009-04-29 23:33:31 +030061
62 vector = mbox->events_vector & ~(mbox->events_mask);
Kalle Valo80301cd2009-06-12 14:17:39 +030063 wl1251_debug(DEBUG_EVENT, "vector: 0x%x", vector);
Kalle Valo2f01a1f2009-04-29 23:33:31 +030064
65 if (vector & SCAN_COMPLETE_EVENT_ID) {
Kalle Valo80301cd2009-06-12 14:17:39 +030066 ret = wl1251_event_scan_complete(wl, mbox);
Kalle Valo2f01a1f2009-04-29 23:33:31 +030067 if (ret < 0)
68 return ret;
69 }
70
71 if (vector & BSS_LOSE_EVENT_ID) {
Kalle Valo80301cd2009-06-12 14:17:39 +030072 wl1251_debug(DEBUG_EVENT, "BSS_LOSE_EVENT");
Kalle Valo2f01a1f2009-04-29 23:33:31 +030073
74 if (wl->psm_requested && wl->psm) {
Kalle Valo80301cd2009-06-12 14:17:39 +030075 ret = wl1251_ps_set_mode(wl, STATION_ACTIVE_MODE);
Kalle Valo2f01a1f2009-04-29 23:33:31 +030076 if (ret < 0)
77 return ret;
78 }
79 }
80
81 return 0;
82}
83
Kalle Valo80301cd2009-06-12 14:17:39 +030084int wl1251_event_unmask(struct wl1251 *wl)
Kalle Valo2f01a1f2009-04-29 23:33:31 +030085{
86 int ret;
87
Kalle Valo80301cd2009-06-12 14:17:39 +030088 ret = wl1251_acx_event_mbox_mask(wl, ~(wl->event_mask));
Kalle Valo2f01a1f2009-04-29 23:33:31 +030089 if (ret < 0)
90 return ret;
91
92 return 0;
93}
94
Kalle Valo80301cd2009-06-12 14:17:39 +030095void wl1251_event_mbox_config(struct wl1251 *wl)
Kalle Valo2f01a1f2009-04-29 23:33:31 +030096{
Kalle Valo80301cd2009-06-12 14:17:39 +030097 wl->mbox_ptr[0] = wl1251_reg_read32(wl, REG_EVENT_MAILBOX_PTR);
Kalle Valo2f01a1f2009-04-29 23:33:31 +030098 wl->mbox_ptr[1] = wl->mbox_ptr[0] + sizeof(struct event_mailbox);
99
Kalle Valo80301cd2009-06-12 14:17:39 +0300100 wl1251_debug(DEBUG_EVENT, "MBOX ptrs: 0x%x 0x%x",
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300101 wl->mbox_ptr[0], wl->mbox_ptr[1]);
102}
103
Kalle Valo80301cd2009-06-12 14:17:39 +0300104int wl1251_event_handle(struct wl1251 *wl, u8 mbox_num)
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300105{
106 struct event_mailbox mbox;
107 int ret;
108
Kalle Valo80301cd2009-06-12 14:17:39 +0300109 wl1251_debug(DEBUG_EVENT, "EVENT on mbox %d", mbox_num);
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300110
111 if (mbox_num > 1)
112 return -EINVAL;
113
114 /* first we read the mbox descriptor */
Kalle Valo80301cd2009-06-12 14:17:39 +0300115 wl1251_spi_mem_read(wl, wl->mbox_ptr[mbox_num], &mbox,
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300116 sizeof(struct event_mailbox));
117
118 /* process the descriptor */
Kalle Valo80301cd2009-06-12 14:17:39 +0300119 ret = wl1251_event_process(wl, &mbox);
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300120 if (ret < 0)
121 return ret;
122
123 /* then we let the firmware know it can go on...*/
Kalle Valo80301cd2009-06-12 14:17:39 +0300124 wl1251_reg_write32(wl, ACX_REG_INTERRUPT_TRIG, INTR_TRIG_EVENT_ACK);
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300125
126 return 0;
127}