2009-01-10 05:58:09 +07:00
|
|
|
/*
|
|
|
|
* linux/drivers/net/wireless/libertas/if_spi.c
|
|
|
|
*
|
|
|
|
* Driver for Marvell SPI WLAN cards.
|
|
|
|
*
|
|
|
|
* Copyright 2008 Analog Devices Inc.
|
|
|
|
*
|
|
|
|
* Authors:
|
|
|
|
* Andrey Yurovsky <andrey@cozybit.com>
|
|
|
|
* Colin McCabe <colin@cozybit.com>
|
|
|
|
*
|
|
|
|
* Inspired by if_sdio.c, Copyright 2007-2008 Pierre Ossman
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*/
|
|
|
|
|
2011-05-03 06:49:14 +07:00
|
|
|
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
|
|
|
|
|
2011-06-06 17:43:46 +07:00
|
|
|
#include <linux/hardirq.h>
|
|
|
|
#include <linux/interrupt.h>
|
2009-01-10 05:58:09 +07:00
|
|
|
#include <linux/moduleparam.h>
|
|
|
|
#include <linux/firmware.h>
|
|
|
|
#include <linux/jiffies.h>
|
|
|
|
#include <linux/list.h>
|
|
|
|
#include <linux/netdevice.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 15:04:11 +07:00
|
|
|
#include <linux/slab.h>
|
2009-01-10 05:58:09 +07:00
|
|
|
#include <linux/spi/libertas_spi.h>
|
|
|
|
#include <linux/spi/spi.h>
|
|
|
|
|
|
|
|
#include "host.h"
|
|
|
|
#include "decl.h"
|
|
|
|
#include "defs.h"
|
|
|
|
#include "dev.h"
|
|
|
|
#include "if_spi.h"
|
|
|
|
|
2011-01-22 03:44:48 +07:00
|
|
|
struct if_spi_packet {
|
|
|
|
struct list_head list;
|
|
|
|
u16 blen;
|
|
|
|
u8 buffer[0] __attribute__((aligned(4)));
|
|
|
|
};
|
|
|
|
|
2009-01-10 05:58:09 +07:00
|
|
|
struct if_spi_card {
|
|
|
|
struct spi_device *spi;
|
|
|
|
struct lbs_private *priv;
|
2009-02-03 14:04:20 +07:00
|
|
|
struct libertas_spi_platform_data *pdata;
|
2009-01-10 05:58:09 +07:00
|
|
|
|
|
|
|
/* The card ID and card revision, as reported by the hardware. */
|
|
|
|
u16 card_id;
|
|
|
|
u8 card_rev;
|
|
|
|
|
|
|
|
/* The last time that we initiated an SPU operation */
|
|
|
|
unsigned long prev_xfer_time;
|
|
|
|
|
|
|
|
int use_dummy_writes;
|
|
|
|
unsigned long spu_port_delay;
|
|
|
|
unsigned long spu_reg_delay;
|
|
|
|
|
|
|
|
/* Handles all SPI communication (except for FW load) */
|
2011-01-22 03:44:48 +07:00
|
|
|
struct workqueue_struct *workqueue;
|
|
|
|
struct work_struct packet_work;
|
2011-03-16 21:41:46 +07:00
|
|
|
struct work_struct resume_work;
|
2009-01-10 05:58:09 +07:00
|
|
|
|
|
|
|
u8 cmd_buffer[IF_SPI_CMD_BUF_SIZE];
|
2011-01-22 03:44:48 +07:00
|
|
|
|
|
|
|
/* A buffer of incoming packets from libertas core.
|
|
|
|
* Since we can't sleep in hw_host_to_card, we have to buffer
|
|
|
|
* them. */
|
|
|
|
struct list_head cmd_packet_list;
|
|
|
|
struct list_head data_packet_list;
|
|
|
|
|
|
|
|
/* Protects cmd_packet_list and data_packet_list */
|
|
|
|
spinlock_t buffer_lock;
|
2011-03-16 21:41:46 +07:00
|
|
|
|
|
|
|
/* True is card suspended */
|
|
|
|
u8 suspended;
|
2009-01-10 05:58:09 +07:00
|
|
|
};
|
|
|
|
|
|
|
|
static void free_if_spi_card(struct if_spi_card *card)
|
|
|
|
{
|
2011-01-22 03:44:48 +07:00
|
|
|
struct list_head *cursor, *next;
|
|
|
|
struct if_spi_packet *packet;
|
|
|
|
|
|
|
|
list_for_each_safe(cursor, next, &card->cmd_packet_list) {
|
|
|
|
packet = container_of(cursor, struct if_spi_packet, list);
|
|
|
|
list_del(&packet->list);
|
|
|
|
kfree(packet);
|
|
|
|
}
|
|
|
|
list_for_each_safe(cursor, next, &card->data_packet_list) {
|
|
|
|
packet = container_of(cursor, struct if_spi_packet, list);
|
|
|
|
list_del(&packet->list);
|
|
|
|
kfree(packet);
|
|
|
|
}
|
2009-01-10 05:58:09 +07:00
|
|
|
spi_set_drvdata(card->spi, NULL);
|
|
|
|
kfree(card);
|
|
|
|
}
|
|
|
|
|
2010-08-08 09:16:30 +07:00
|
|
|
#define MODEL_8385 0x04
|
|
|
|
#define MODEL_8686 0x0b
|
|
|
|
#define MODEL_8688 0x10
|
|
|
|
|
|
|
|
static const struct lbs_fw_table fw_table[] = {
|
|
|
|
{ MODEL_8385, "libertas/gspi8385_helper.bin", "libertas/gspi8385.bin" },
|
|
|
|
{ MODEL_8385, "libertas/gspi8385_hlp.bin", "libertas/gspi8385.bin" },
|
|
|
|
{ MODEL_8686, "libertas/gspi8686_v9_helper.bin", "libertas/gspi8686_v9.bin" },
|
|
|
|
{ MODEL_8686, "libertas/gspi8686_hlp.bin", "libertas/gspi8686.bin" },
|
|
|
|
{ MODEL_8688, "libertas/gspi8688_helper.bin", "libertas/gspi8688.bin" },
|
|
|
|
{ 0, NULL, NULL }
|
2009-01-10 05:58:09 +07:00
|
|
|
};
|
2010-08-08 09:16:30 +07:00
|
|
|
MODULE_FIRMWARE("libertas/gspi8385_helper.bin");
|
|
|
|
MODULE_FIRMWARE("libertas/gspi8385_hlp.bin");
|
|
|
|
MODULE_FIRMWARE("libertas/gspi8385.bin");
|
|
|
|
MODULE_FIRMWARE("libertas/gspi8686_v9_helper.bin");
|
|
|
|
MODULE_FIRMWARE("libertas/gspi8686_v9.bin");
|
|
|
|
MODULE_FIRMWARE("libertas/gspi8686_hlp.bin");
|
|
|
|
MODULE_FIRMWARE("libertas/gspi8686.bin");
|
|
|
|
MODULE_FIRMWARE("libertas/gspi8688_helper.bin");
|
|
|
|
MODULE_FIRMWARE("libertas/gspi8688.bin");
|
|
|
|
|
2009-01-10 05:58:09 +07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* SPI Interface Unit Routines
|
|
|
|
*
|
|
|
|
* The SPU sits between the host and the WLAN module.
|
|
|
|
* All communication with the firmware is through SPU transactions.
|
|
|
|
*
|
|
|
|
* First we have to put a SPU register name on the bus. Then we can
|
|
|
|
* either read from or write to that register.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
static void spu_transaction_init(struct if_spi_card *card)
|
|
|
|
{
|
|
|
|
if (!time_after(jiffies, card->prev_xfer_time + 1)) {
|
|
|
|
/* Unfortunately, the SPU requires a delay between successive
|
|
|
|
* transactions. If our last transaction was more than a jiffy
|
|
|
|
* ago, we have obviously already delayed enough.
|
|
|
|
* If not, we have to busy-wait to be on the safe side. */
|
|
|
|
ndelay(400);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void spu_transaction_finish(struct if_spi_card *card)
|
|
|
|
{
|
|
|
|
card->prev_xfer_time = jiffies;
|
|
|
|
}
|
|
|
|
|
2011-04-27 05:25:29 +07:00
|
|
|
/*
|
|
|
|
* Write out a byte buffer to an SPI register,
|
|
|
|
* using a series of 16-bit transfers.
|
|
|
|
*/
|
2009-01-10 05:58:09 +07:00
|
|
|
static int spu_write(struct if_spi_card *card, u16 reg, const u8 *buf, int len)
|
|
|
|
{
|
|
|
|
int err = 0;
|
2009-10-22 20:30:44 +07:00
|
|
|
__le16 reg_out = cpu_to_le16(reg | IF_SPI_WRITE_OPERATION_MASK);
|
2009-06-05 02:57:03 +07:00
|
|
|
struct spi_message m;
|
|
|
|
struct spi_transfer reg_trans;
|
|
|
|
struct spi_transfer data_trans;
|
|
|
|
|
|
|
|
spi_message_init(&m);
|
|
|
|
memset(®_trans, 0, sizeof(reg_trans));
|
|
|
|
memset(&data_trans, 0, sizeof(data_trans));
|
2009-01-10 05:58:09 +07:00
|
|
|
|
|
|
|
/* You must give an even number of bytes to the SPU, even if it
|
|
|
|
* doesn't care about the last one. */
|
|
|
|
BUG_ON(len & 0x1);
|
|
|
|
|
|
|
|
spu_transaction_init(card);
|
|
|
|
|
|
|
|
/* write SPU register index */
|
2009-06-05 02:57:03 +07:00
|
|
|
reg_trans.tx_buf = ®_out;
|
|
|
|
reg_trans.len = sizeof(reg_out);
|
2009-01-10 05:58:09 +07:00
|
|
|
|
2009-06-05 02:57:03 +07:00
|
|
|
data_trans.tx_buf = buf;
|
|
|
|
data_trans.len = len;
|
2009-01-10 05:58:09 +07:00
|
|
|
|
2009-06-05 02:57:03 +07:00
|
|
|
spi_message_add_tail(®_trans, &m);
|
|
|
|
spi_message_add_tail(&data_trans, &m);
|
|
|
|
|
|
|
|
err = spi_sync(card->spi, &m);
|
2009-01-10 05:58:09 +07:00
|
|
|
spu_transaction_finish(card);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int spu_write_u16(struct if_spi_card *card, u16 reg, u16 val)
|
|
|
|
{
|
2009-10-22 20:30:44 +07:00
|
|
|
__le16 buff;
|
2009-01-10 05:58:09 +07:00
|
|
|
|
2009-05-23 02:19:40 +07:00
|
|
|
buff = cpu_to_le16(val);
|
|
|
|
return spu_write(card, reg, (u8 *)&buff, sizeof(u16));
|
2009-01-10 05:58:09 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline int spu_reg_is_port_reg(u16 reg)
|
|
|
|
{
|
|
|
|
switch (reg) {
|
|
|
|
case IF_SPI_IO_RDWRPORT_REG:
|
|
|
|
case IF_SPI_CMD_RDWRPORT_REG:
|
|
|
|
case IF_SPI_DATA_RDWRPORT_REG:
|
|
|
|
return 1;
|
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int spu_read(struct if_spi_card *card, u16 reg, u8 *buf, int len)
|
|
|
|
{
|
2009-06-05 02:57:03 +07:00
|
|
|
unsigned int delay;
|
2009-01-10 05:58:09 +07:00
|
|
|
int err = 0;
|
2009-10-22 20:30:44 +07:00
|
|
|
__le16 reg_out = cpu_to_le16(reg | IF_SPI_READ_OPERATION_MASK);
|
2009-06-05 02:57:03 +07:00
|
|
|
struct spi_message m;
|
|
|
|
struct spi_transfer reg_trans;
|
|
|
|
struct spi_transfer dummy_trans;
|
|
|
|
struct spi_transfer data_trans;
|
2009-01-10 05:58:09 +07:00
|
|
|
|
2011-04-27 05:25:29 +07:00
|
|
|
/*
|
|
|
|
* You must take an even number of bytes from the SPU, even if you
|
|
|
|
* don't care about the last one.
|
|
|
|
*/
|
2009-01-10 05:58:09 +07:00
|
|
|
BUG_ON(len & 0x1);
|
|
|
|
|
|
|
|
spu_transaction_init(card);
|
|
|
|
|
2009-06-05 02:57:03 +07:00
|
|
|
spi_message_init(&m);
|
|
|
|
memset(®_trans, 0, sizeof(reg_trans));
|
|
|
|
memset(&dummy_trans, 0, sizeof(dummy_trans));
|
|
|
|
memset(&data_trans, 0, sizeof(data_trans));
|
|
|
|
|
2009-01-10 05:58:09 +07:00
|
|
|
/* write SPU register index */
|
2009-06-05 02:57:03 +07:00
|
|
|
reg_trans.tx_buf = ®_out;
|
|
|
|
reg_trans.len = sizeof(reg_out);
|
|
|
|
spi_message_add_tail(®_trans, &m);
|
2009-01-10 05:58:09 +07:00
|
|
|
|
|
|
|
delay = spu_reg_is_port_reg(reg) ? card->spu_port_delay :
|
|
|
|
card->spu_reg_delay;
|
|
|
|
if (card->use_dummy_writes) {
|
|
|
|
/* Clock in dummy cycles while the SPU fills the FIFO */
|
2009-06-05 02:57:03 +07:00
|
|
|
dummy_trans.len = delay / 8;
|
|
|
|
spi_message_add_tail(&dummy_trans, &m);
|
2009-01-10 05:58:09 +07:00
|
|
|
} else {
|
|
|
|
/* Busy-wait while the SPU fills the FIFO */
|
2009-06-05 02:57:03 +07:00
|
|
|
reg_trans.delay_usecs =
|
|
|
|
DIV_ROUND_UP((100 + (delay * 10)), 1000);
|
2009-01-10 05:58:09 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* read in data */
|
2009-06-05 02:57:03 +07:00
|
|
|
data_trans.rx_buf = buf;
|
|
|
|
data_trans.len = len;
|
|
|
|
spi_message_add_tail(&data_trans, &m);
|
2009-01-10 05:58:09 +07:00
|
|
|
|
2009-06-05 02:57:03 +07:00
|
|
|
err = spi_sync(card->spi, &m);
|
2009-01-10 05:58:09 +07:00
|
|
|
spu_transaction_finish(card);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Read 16 bits from an SPI register */
|
|
|
|
static inline int spu_read_u16(struct if_spi_card *card, u16 reg, u16 *val)
|
|
|
|
{
|
2009-10-22 20:30:44 +07:00
|
|
|
__le16 buf;
|
2009-05-23 02:19:40 +07:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = spu_read(card, reg, (u8 *)&buf, sizeof(buf));
|
|
|
|
if (ret == 0)
|
|
|
|
*val = le16_to_cpup(&buf);
|
|
|
|
return ret;
|
2009-01-10 05:58:09 +07:00
|
|
|
}
|
|
|
|
|
2011-04-27 05:25:29 +07:00
|
|
|
/*
|
|
|
|
* Read 32 bits from an SPI register.
|
|
|
|
* The low 16 bits are read first.
|
|
|
|
*/
|
2009-01-10 05:58:09 +07:00
|
|
|
static int spu_read_u32(struct if_spi_card *card, u16 reg, u32 *val)
|
|
|
|
{
|
2009-10-22 20:30:44 +07:00
|
|
|
__le32 buf;
|
2009-01-10 05:58:09 +07:00
|
|
|
int err;
|
2009-05-23 02:19:40 +07:00
|
|
|
|
|
|
|
err = spu_read(card, reg, (u8 *)&buf, sizeof(buf));
|
2009-01-10 05:58:09 +07:00
|
|
|
if (!err)
|
2009-05-23 02:19:40 +07:00
|
|
|
*val = le32_to_cpup(&buf);
|
2009-01-10 05:58:09 +07:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2011-04-27 05:25:29 +07:00
|
|
|
/*
|
|
|
|
* Keep reading 16 bits from an SPI register until you get the correct result.
|
2009-01-10 05:58:09 +07:00
|
|
|
*
|
|
|
|
* If mask = 0, the correct result is any non-zero number.
|
|
|
|
* If mask != 0, the correct result is any number where
|
|
|
|
* number & target_mask == target
|
|
|
|
*
|
2011-04-27 05:25:29 +07:00
|
|
|
* Returns -ETIMEDOUT if a second passes without the correct result.
|
|
|
|
*/
|
2009-01-10 05:58:09 +07:00
|
|
|
static int spu_wait_for_u16(struct if_spi_card *card, u16 reg,
|
|
|
|
u16 target_mask, u16 target)
|
|
|
|
{
|
|
|
|
int err;
|
|
|
|
unsigned long timeout = jiffies + 5*HZ;
|
|
|
|
while (1) {
|
|
|
|
u16 val;
|
|
|
|
err = spu_read_u16(card, reg, &val);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
if (target_mask) {
|
|
|
|
if ((val & target_mask) == target)
|
|
|
|
return 0;
|
|
|
|
} else {
|
|
|
|
if (val)
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
udelay(100);
|
|
|
|
if (time_after(jiffies, timeout)) {
|
2011-05-03 06:49:14 +07:00
|
|
|
pr_err("%s: timeout with val=%02x, target_mask=%02x, target=%02x\n",
|
2009-01-10 05:58:09 +07:00
|
|
|
__func__, val, target_mask, target);
|
|
|
|
return -ETIMEDOUT;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-04-27 05:25:29 +07:00
|
|
|
/*
|
|
|
|
* Read 16 bits from an SPI register until you receive a specific value.
|
|
|
|
* Returns -ETIMEDOUT if a 4 tries pass without success.
|
|
|
|
*/
|
2009-01-10 05:58:09 +07:00
|
|
|
static int spu_wait_for_u32(struct if_spi_card *card, u32 reg, u32 target)
|
|
|
|
{
|
|
|
|
int err, try;
|
|
|
|
for (try = 0; try < 4; ++try) {
|
|
|
|
u32 val = 0;
|
|
|
|
err = spu_read_u32(card, reg, &val);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
if (val == target)
|
|
|
|
return 0;
|
|
|
|
mdelay(100);
|
|
|
|
}
|
|
|
|
return -ETIMEDOUT;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int spu_set_interrupt_mode(struct if_spi_card *card,
|
|
|
|
int suppress_host_int,
|
|
|
|
int auto_int)
|
|
|
|
{
|
|
|
|
int err = 0;
|
|
|
|
|
2011-04-27 05:25:29 +07:00
|
|
|
/*
|
|
|
|
* We can suppress a host interrupt by clearing the appropriate
|
|
|
|
* bit in the "host interrupt status mask" register
|
|
|
|
*/
|
2009-01-10 05:58:09 +07:00
|
|
|
if (suppress_host_int) {
|
|
|
|
err = spu_write_u16(card, IF_SPI_HOST_INT_STATUS_MASK_REG, 0);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
} else {
|
|
|
|
err = spu_write_u16(card, IF_SPI_HOST_INT_STATUS_MASK_REG,
|
|
|
|
IF_SPI_HISM_TX_DOWNLOAD_RDY |
|
|
|
|
IF_SPI_HISM_RX_UPLOAD_RDY |
|
|
|
|
IF_SPI_HISM_CMD_DOWNLOAD_RDY |
|
|
|
|
IF_SPI_HISM_CARDEVENT |
|
|
|
|
IF_SPI_HISM_CMD_UPLOAD_RDY);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2011-04-27 05:25:29 +07:00
|
|
|
/*
|
|
|
|
* If auto-interrupts are on, the completion of certain transactions
|
2009-01-10 05:58:09 +07:00
|
|
|
* will trigger an interrupt automatically. If auto-interrupts
|
|
|
|
* are off, we need to set the "Card Interrupt Cause" register to
|
2011-04-27 05:25:29 +07:00
|
|
|
* trigger a card interrupt.
|
|
|
|
*/
|
2009-01-10 05:58:09 +07:00
|
|
|
if (auto_int) {
|
|
|
|
err = spu_write_u16(card, IF_SPI_HOST_INT_CTRL_REG,
|
|
|
|
IF_SPI_HICT_TX_DOWNLOAD_OVER_AUTO |
|
|
|
|
IF_SPI_HICT_RX_UPLOAD_OVER_AUTO |
|
|
|
|
IF_SPI_HICT_CMD_DOWNLOAD_OVER_AUTO |
|
|
|
|
IF_SPI_HICT_CMD_UPLOAD_OVER_AUTO);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
} else {
|
|
|
|
err = spu_write_u16(card, IF_SPI_HOST_INT_STATUS_MASK_REG, 0);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int spu_get_chip_revision(struct if_spi_card *card,
|
|
|
|
u16 *card_id, u8 *card_rev)
|
|
|
|
{
|
|
|
|
int err = 0;
|
|
|
|
u32 dev_ctrl;
|
|
|
|
err = spu_read_u32(card, IF_SPI_DEVICEID_CTRL_REG, &dev_ctrl);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
*card_id = IF_SPI_DEVICEID_CTRL_REG_TO_CARD_ID(dev_ctrl);
|
|
|
|
*card_rev = IF_SPI_DEVICEID_CTRL_REG_TO_CARD_REV(dev_ctrl);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int spu_set_bus_mode(struct if_spi_card *card, u16 mode)
|
|
|
|
{
|
|
|
|
int err = 0;
|
|
|
|
u16 rval;
|
|
|
|
/* set bus mode */
|
|
|
|
err = spu_write_u16(card, IF_SPI_SPU_BUS_MODE_REG, mode);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
/* Check that we were able to read back what we just wrote. */
|
|
|
|
err = spu_read_u16(card, IF_SPI_SPU_BUS_MODE_REG, &rval);
|
|
|
|
if (err)
|
|
|
|
return err;
|
2009-08-01 01:35:19 +07:00
|
|
|
if ((rval & 0xF) != mode) {
|
2011-05-03 06:49:14 +07:00
|
|
|
pr_err("Can't read bus mode register\n");
|
2009-01-10 05:58:09 +07:00
|
|
|
return -EIO;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int spu_init(struct if_spi_card *card, int use_dummy_writes)
|
|
|
|
{
|
|
|
|
int err = 0;
|
|
|
|
u32 delay;
|
|
|
|
|
2011-04-27 05:25:29 +07:00
|
|
|
/*
|
|
|
|
* We have to start up in timed delay mode so that we can safely
|
|
|
|
* read the Delay Read Register.
|
|
|
|
*/
|
2009-01-10 05:58:09 +07:00
|
|
|
card->use_dummy_writes = 0;
|
|
|
|
err = spu_set_bus_mode(card,
|
|
|
|
IF_SPI_BUS_MODE_SPI_CLOCK_PHASE_RISING |
|
|
|
|
IF_SPI_BUS_MODE_DELAY_METHOD_TIMED |
|
|
|
|
IF_SPI_BUS_MODE_16_BIT_ADDRESS_16_BIT_DATA);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
card->spu_port_delay = 1000;
|
|
|
|
card->spu_reg_delay = 1000;
|
|
|
|
err = spu_read_u32(card, IF_SPI_DELAY_READ_REG, &delay);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
card->spu_port_delay = delay & 0x0000ffff;
|
|
|
|
card->spu_reg_delay = (delay & 0xffff0000) >> 16;
|
|
|
|
|
|
|
|
/* If dummy clock delay mode has been requested, switch to it now */
|
|
|
|
if (use_dummy_writes) {
|
|
|
|
card->use_dummy_writes = 1;
|
|
|
|
err = spu_set_bus_mode(card,
|
|
|
|
IF_SPI_BUS_MODE_SPI_CLOCK_PHASE_RISING |
|
|
|
|
IF_SPI_BUS_MODE_DELAY_METHOD_DUMMY_CLOCK |
|
|
|
|
IF_SPI_BUS_MODE_16_BIT_ADDRESS_16_BIT_DATA);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
lbs_deb_spi("Initialized SPU unit. "
|
|
|
|
"spu_port_delay=0x%04lx, spu_reg_delay=0x%04lx\n",
|
|
|
|
card->spu_port_delay, card->spu_reg_delay);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Firmware Loading
|
|
|
|
*/
|
|
|
|
|
2010-08-08 09:16:30 +07:00
|
|
|
static int if_spi_prog_helper_firmware(struct if_spi_card *card,
|
|
|
|
const struct firmware *firmware)
|
2009-01-10 05:58:09 +07:00
|
|
|
{
|
|
|
|
int err = 0;
|
|
|
|
int bytes_remaining;
|
|
|
|
const u8 *fw;
|
|
|
|
u8 temp[HELPER_FW_LOAD_CHUNK_SZ];
|
|
|
|
|
|
|
|
lbs_deb_enter(LBS_DEB_SPI);
|
|
|
|
|
|
|
|
err = spu_set_interrupt_mode(card, 1, 0);
|
|
|
|
if (err)
|
|
|
|
goto out;
|
2010-08-08 09:16:30 +07:00
|
|
|
|
2009-01-10 05:58:09 +07:00
|
|
|
bytes_remaining = firmware->size;
|
|
|
|
fw = firmware->data;
|
|
|
|
|
|
|
|
/* Load helper firmware image */
|
|
|
|
while (bytes_remaining > 0) {
|
2011-04-27 05:25:29 +07:00
|
|
|
/*
|
|
|
|
* Scratch pad 1 should contain the number of bytes we
|
|
|
|
* want to download to the firmware
|
|
|
|
*/
|
2009-01-10 05:58:09 +07:00
|
|
|
err = spu_write_u16(card, IF_SPI_SCRATCH_1_REG,
|
|
|
|
HELPER_FW_LOAD_CHUNK_SZ);
|
|
|
|
if (err)
|
2010-08-08 09:16:30 +07:00
|
|
|
goto out;
|
2009-01-10 05:58:09 +07:00
|
|
|
|
|
|
|
err = spu_wait_for_u16(card, IF_SPI_HOST_INT_STATUS_REG,
|
|
|
|
IF_SPI_HIST_CMD_DOWNLOAD_RDY,
|
|
|
|
IF_SPI_HIST_CMD_DOWNLOAD_RDY);
|
|
|
|
if (err)
|
2010-08-08 09:16:30 +07:00
|
|
|
goto out;
|
2009-01-10 05:58:09 +07:00
|
|
|
|
2011-04-27 05:25:29 +07:00
|
|
|
/*
|
|
|
|
* Feed the data into the command read/write port reg
|
|
|
|
* in chunks of 64 bytes
|
|
|
|
*/
|
2009-01-10 05:58:09 +07:00
|
|
|
memset(temp, 0, sizeof(temp));
|
|
|
|
memcpy(temp, fw,
|
|
|
|
min(bytes_remaining, HELPER_FW_LOAD_CHUNK_SZ));
|
|
|
|
mdelay(10);
|
|
|
|
err = spu_write(card, IF_SPI_CMD_RDWRPORT_REG,
|
|
|
|
temp, HELPER_FW_LOAD_CHUNK_SZ);
|
|
|
|
if (err)
|
2010-08-08 09:16:30 +07:00
|
|
|
goto out;
|
2009-01-10 05:58:09 +07:00
|
|
|
|
|
|
|
/* Interrupt the boot code */
|
|
|
|
err = spu_write_u16(card, IF_SPI_HOST_INT_STATUS_REG, 0);
|
|
|
|
if (err)
|
2010-08-08 09:16:30 +07:00
|
|
|
goto out;
|
2009-01-10 05:58:09 +07:00
|
|
|
err = spu_write_u16(card, IF_SPI_CARD_INT_CAUSE_REG,
|
|
|
|
IF_SPI_CIC_CMD_DOWNLOAD_OVER);
|
|
|
|
if (err)
|
2010-08-08 09:16:30 +07:00
|
|
|
goto out;
|
2009-01-10 05:58:09 +07:00
|
|
|
bytes_remaining -= HELPER_FW_LOAD_CHUNK_SZ;
|
|
|
|
fw += HELPER_FW_LOAD_CHUNK_SZ;
|
|
|
|
}
|
|
|
|
|
2011-04-27 05:25:29 +07:00
|
|
|
/*
|
|
|
|
* Once the helper / single stage firmware download is complete,
|
2009-01-10 05:58:09 +07:00
|
|
|
* write 0 to scratch pad 1 and interrupt the
|
2011-04-27 05:25:29 +07:00
|
|
|
* bootloader. This completes the helper download.
|
|
|
|
*/
|
2009-01-10 05:58:09 +07:00
|
|
|
err = spu_write_u16(card, IF_SPI_SCRATCH_1_REG, FIRMWARE_DNLD_OK);
|
|
|
|
if (err)
|
2010-08-08 09:16:30 +07:00
|
|
|
goto out;
|
2009-01-10 05:58:09 +07:00
|
|
|
err = spu_write_u16(card, IF_SPI_HOST_INT_STATUS_REG, 0);
|
|
|
|
if (err)
|
2010-08-08 09:16:30 +07:00
|
|
|
goto out;
|
2009-01-10 05:58:09 +07:00
|
|
|
err = spu_write_u16(card, IF_SPI_CARD_INT_CAUSE_REG,
|
|
|
|
IF_SPI_CIC_CMD_DOWNLOAD_OVER);
|
|
|
|
out:
|
|
|
|
if (err)
|
2011-05-03 06:49:14 +07:00
|
|
|
pr_err("failed to load helper firmware (err=%d)\n", err);
|
2009-01-10 05:58:09 +07:00
|
|
|
lbs_deb_leave_args(LBS_DEB_SPI, "err %d", err);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2011-04-27 05:25:29 +07:00
|
|
|
/*
|
|
|
|
* Returns the length of the next packet the firmware expects us to send.
|
|
|
|
* Sets crc_err if the previous transfer had a CRC error.
|
|
|
|
*/
|
2009-01-10 05:58:09 +07:00
|
|
|
static int if_spi_prog_main_firmware_check_len(struct if_spi_card *card,
|
|
|
|
int *crc_err)
|
|
|
|
{
|
|
|
|
u16 len;
|
|
|
|
int err = 0;
|
|
|
|
|
2011-04-27 05:25:29 +07:00
|
|
|
/*
|
|
|
|
* wait until the host interrupt status register indicates
|
|
|
|
* that we are ready to download
|
|
|
|
*/
|
2009-01-10 05:58:09 +07:00
|
|
|
err = spu_wait_for_u16(card, IF_SPI_HOST_INT_STATUS_REG,
|
|
|
|
IF_SPI_HIST_CMD_DOWNLOAD_RDY,
|
|
|
|
IF_SPI_HIST_CMD_DOWNLOAD_RDY);
|
|
|
|
if (err) {
|
2011-05-03 06:49:14 +07:00
|
|
|
pr_err("timed out waiting for host_int_status\n");
|
2009-01-10 05:58:09 +07:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Ask the device how many bytes of firmware it wants. */
|
|
|
|
err = spu_read_u16(card, IF_SPI_SCRATCH_1_REG, &len);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
if (len > IF_SPI_CMD_BUF_SIZE) {
|
2011-05-03 06:49:14 +07:00
|
|
|
pr_err("firmware load device requested a larger transfer than we are prepared to handle (len = %d)\n",
|
|
|
|
len);
|
2009-01-10 05:58:09 +07:00
|
|
|
return -EIO;
|
|
|
|
}
|
|
|
|
if (len & 0x1) {
|
|
|
|
lbs_deb_spi("%s: crc error\n", __func__);
|
|
|
|
len &= ~0x1;
|
|
|
|
*crc_err = 1;
|
|
|
|
} else
|
|
|
|
*crc_err = 0;
|
|
|
|
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
2010-08-08 09:16:30 +07:00
|
|
|
static int if_spi_prog_main_firmware(struct if_spi_card *card,
|
|
|
|
const struct firmware *firmware)
|
2009-01-10 05:58:09 +07:00
|
|
|
{
|
2011-05-03 06:49:15 +07:00
|
|
|
struct lbs_private *priv = card->priv;
|
2009-01-10 05:58:09 +07:00
|
|
|
int len, prev_len;
|
|
|
|
int bytes, crc_err = 0, err = 0;
|
|
|
|
const u8 *fw;
|
|
|
|
u16 num_crc_errs;
|
|
|
|
|
|
|
|
lbs_deb_enter(LBS_DEB_SPI);
|
|
|
|
|
|
|
|
err = spu_set_interrupt_mode(card, 1, 0);
|
|
|
|
if (err)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
err = spu_wait_for_u16(card, IF_SPI_SCRATCH_1_REG, 0, 0);
|
|
|
|
if (err) {
|
2011-05-03 06:49:15 +07:00
|
|
|
netdev_err(priv->dev,
|
|
|
|
"%s: timed out waiting for initial scratch reg = 0\n",
|
|
|
|
__func__);
|
2010-08-08 09:16:30 +07:00
|
|
|
goto out;
|
2009-01-10 05:58:09 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
num_crc_errs = 0;
|
|
|
|
prev_len = 0;
|
|
|
|
bytes = firmware->size;
|
|
|
|
fw = firmware->data;
|
|
|
|
while ((len = if_spi_prog_main_firmware_check_len(card, &crc_err))) {
|
|
|
|
if (len < 0) {
|
|
|
|
err = len;
|
2010-08-08 09:16:30 +07:00
|
|
|
goto out;
|
2009-01-10 05:58:09 +07:00
|
|
|
}
|
|
|
|
if (bytes < 0) {
|
2011-04-27 05:25:29 +07:00
|
|
|
/*
|
|
|
|
* If there are no more bytes left, we would normally
|
|
|
|
* expect to have terminated with len = 0
|
|
|
|
*/
|
2011-05-03 06:49:15 +07:00
|
|
|
netdev_err(priv->dev,
|
|
|
|
"Firmware load wants more bytes than we have to offer.\n");
|
2009-01-10 05:58:09 +07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (crc_err) {
|
|
|
|
/* Previous transfer failed. */
|
|
|
|
if (++num_crc_errs > MAX_MAIN_FW_LOAD_CRC_ERR) {
|
2011-05-03 06:49:14 +07:00
|
|
|
pr_err("Too many CRC errors encountered in firmware load.\n");
|
2009-01-10 05:58:09 +07:00
|
|
|
err = -EIO;
|
2010-08-08 09:16:30 +07:00
|
|
|
goto out;
|
2009-01-10 05:58:09 +07:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* Previous transfer succeeded. Advance counters. */
|
|
|
|
bytes -= prev_len;
|
|
|
|
fw += prev_len;
|
|
|
|
}
|
|
|
|
if (bytes < len) {
|
|
|
|
memset(card->cmd_buffer, 0, len);
|
|
|
|
memcpy(card->cmd_buffer, fw, bytes);
|
|
|
|
} else
|
|
|
|
memcpy(card->cmd_buffer, fw, len);
|
|
|
|
|
|
|
|
err = spu_write_u16(card, IF_SPI_HOST_INT_STATUS_REG, 0);
|
|
|
|
if (err)
|
2010-08-08 09:16:30 +07:00
|
|
|
goto out;
|
2009-01-10 05:58:09 +07:00
|
|
|
err = spu_write(card, IF_SPI_CMD_RDWRPORT_REG,
|
|
|
|
card->cmd_buffer, len);
|
|
|
|
if (err)
|
2010-08-08 09:16:30 +07:00
|
|
|
goto out;
|
2009-01-10 05:58:09 +07:00
|
|
|
err = spu_write_u16(card, IF_SPI_CARD_INT_CAUSE_REG ,
|
|
|
|
IF_SPI_CIC_CMD_DOWNLOAD_OVER);
|
|
|
|
if (err)
|
2010-08-08 09:16:30 +07:00
|
|
|
goto out;
|
2009-01-10 05:58:09 +07:00
|
|
|
prev_len = len;
|
|
|
|
}
|
|
|
|
if (bytes > prev_len) {
|
2011-05-03 06:49:14 +07:00
|
|
|
pr_err("firmware load wants fewer bytes than we have to offer\n");
|
2009-01-10 05:58:09 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Confirm firmware download */
|
|
|
|
err = spu_wait_for_u32(card, IF_SPI_SCRATCH_4_REG,
|
|
|
|
SUCCESSFUL_FW_DOWNLOAD_MAGIC);
|
|
|
|
if (err) {
|
2011-05-03 06:49:14 +07:00
|
|
|
pr_err("failed to confirm the firmware download\n");
|
2010-08-08 09:16:30 +07:00
|
|
|
goto out;
|
2009-01-10 05:58:09 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
out:
|
|
|
|
if (err)
|
2011-05-03 06:49:14 +07:00
|
|
|
pr_err("failed to load firmware (err=%d)\n", err);
|
2009-01-10 05:58:09 +07:00
|
|
|
lbs_deb_leave_args(LBS_DEB_SPI, "err %d", err);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* SPI Transfer Thread
|
|
|
|
*
|
2011-01-22 03:44:48 +07:00
|
|
|
* The SPI worker handles all SPI transfers, so there is no need for a lock.
|
2009-01-10 05:58:09 +07:00
|
|
|
*/
|
|
|
|
|
|
|
|
/* Move a command from the card to the host */
|
|
|
|
static int if_spi_c2h_cmd(struct if_spi_card *card)
|
|
|
|
{
|
|
|
|
struct lbs_private *priv = card->priv;
|
|
|
|
unsigned long flags;
|
|
|
|
int err = 0;
|
|
|
|
u16 len;
|
|
|
|
u8 i;
|
|
|
|
|
2011-04-27 05:25:29 +07:00
|
|
|
/*
|
|
|
|
* We need a buffer big enough to handle whatever people send to
|
|
|
|
* hw_host_to_card
|
|
|
|
*/
|
2009-01-10 05:58:09 +07:00
|
|
|
BUILD_BUG_ON(IF_SPI_CMD_BUF_SIZE < LBS_CMD_BUFFER_SIZE);
|
|
|
|
BUILD_BUG_ON(IF_SPI_CMD_BUF_SIZE < LBS_UPLD_SIZE);
|
|
|
|
|
2011-04-27 05:25:29 +07:00
|
|
|
/*
|
|
|
|
* It's just annoying if the buffer size isn't a multiple of 4, because
|
|
|
|
* then we might have len < IF_SPI_CMD_BUF_SIZE but
|
|
|
|
* ALIGN(len, 4) > IF_SPI_CMD_BUF_SIZE
|
|
|
|
*/
|
2009-01-10 05:58:09 +07:00
|
|
|
BUILD_BUG_ON(IF_SPI_CMD_BUF_SIZE % 4 != 0);
|
|
|
|
|
|
|
|
lbs_deb_enter(LBS_DEB_SPI);
|
|
|
|
|
|
|
|
/* How many bytes are there to read? */
|
|
|
|
err = spu_read_u16(card, IF_SPI_SCRATCH_2_REG, &len);
|
|
|
|
if (err)
|
|
|
|
goto out;
|
|
|
|
if (!len) {
|
2011-05-03 06:49:15 +07:00
|
|
|
netdev_err(priv->dev, "%s: error: card has no data for host\n",
|
|
|
|
__func__);
|
2009-01-10 05:58:09 +07:00
|
|
|
err = -EINVAL;
|
|
|
|
goto out;
|
|
|
|
} else if (len > IF_SPI_CMD_BUF_SIZE) {
|
2011-05-03 06:49:15 +07:00
|
|
|
netdev_err(priv->dev,
|
|
|
|
"%s: error: response packet too large: %d bytes, but maximum is %d\n",
|
|
|
|
__func__, len, IF_SPI_CMD_BUF_SIZE);
|
2009-01-10 05:58:09 +07:00
|
|
|
err = -EINVAL;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Read the data from the WLAN module into our command buffer */
|
|
|
|
err = spu_read(card, IF_SPI_CMD_RDWRPORT_REG,
|
|
|
|
card->cmd_buffer, ALIGN(len, 4));
|
|
|
|
if (err)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&priv->driver_lock, flags);
|
|
|
|
i = (priv->resp_idx == 0) ? 1 : 0;
|
|
|
|
BUG_ON(priv->resp_len[i]);
|
|
|
|
priv->resp_len[i] = len;
|
|
|
|
memcpy(priv->resp_buf[i], card->cmd_buffer, len);
|
|
|
|
lbs_notify_command_response(priv, i);
|
|
|
|
spin_unlock_irqrestore(&priv->driver_lock, flags);
|
|
|
|
|
|
|
|
out:
|
|
|
|
if (err)
|
2011-05-03 06:49:15 +07:00
|
|
|
netdev_err(priv->dev, "%s: err=%d\n", __func__, err);
|
2009-01-10 05:58:09 +07:00
|
|
|
lbs_deb_leave(LBS_DEB_SPI);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Move data from the card to the host */
|
|
|
|
static int if_spi_c2h_data(struct if_spi_card *card)
|
|
|
|
{
|
2011-05-03 06:49:15 +07:00
|
|
|
struct lbs_private *priv = card->priv;
|
2009-01-10 05:58:09 +07:00
|
|
|
struct sk_buff *skb;
|
|
|
|
char *data;
|
|
|
|
u16 len;
|
|
|
|
int err = 0;
|
|
|
|
|
|
|
|
lbs_deb_enter(LBS_DEB_SPI);
|
|
|
|
|
|
|
|
/* How many bytes are there to read? */
|
|
|
|
err = spu_read_u16(card, IF_SPI_SCRATCH_1_REG, &len);
|
|
|
|
if (err)
|
|
|
|
goto out;
|
|
|
|
if (!len) {
|
2011-05-03 06:49:15 +07:00
|
|
|
netdev_err(priv->dev, "%s: error: card has no data for host\n",
|
|
|
|
__func__);
|
2009-01-10 05:58:09 +07:00
|
|
|
err = -EINVAL;
|
|
|
|
goto out;
|
|
|
|
} else if (len > MRVDRV_ETH_RX_PACKET_BUFFER_SIZE) {
|
2011-05-03 06:49:15 +07:00
|
|
|
netdev_err(priv->dev,
|
|
|
|
"%s: error: card has %d bytes of data, but our maximum skb size is %zu\n",
|
|
|
|
__func__, len, MRVDRV_ETH_RX_PACKET_BUFFER_SIZE);
|
2009-01-10 05:58:09 +07:00
|
|
|
err = -EINVAL;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* TODO: should we allocate a smaller skb if we have less data? */
|
|
|
|
skb = dev_alloc_skb(MRVDRV_ETH_RX_PACKET_BUFFER_SIZE);
|
|
|
|
if (!skb) {
|
|
|
|
err = -ENOBUFS;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
skb_reserve(skb, IPFIELD_ALIGN_OFFSET);
|
|
|
|
data = skb_put(skb, len);
|
|
|
|
|
|
|
|
/* Read the data from the WLAN module into our skb... */
|
|
|
|
err = spu_read(card, IF_SPI_DATA_RDWRPORT_REG, data, ALIGN(len, 4));
|
|
|
|
if (err)
|
|
|
|
goto free_skb;
|
|
|
|
|
|
|
|
/* pass the SKB to libertas */
|
|
|
|
err = lbs_process_rxed_packet(card->priv, skb);
|
|
|
|
if (err)
|
|
|
|
goto free_skb;
|
|
|
|
|
|
|
|
/* success */
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
free_skb:
|
|
|
|
dev_kfree_skb(skb);
|
|
|
|
out:
|
|
|
|
if (err)
|
2011-05-03 06:49:15 +07:00
|
|
|
netdev_err(priv->dev, "%s: err=%d\n", __func__, err);
|
2009-01-10 05:58:09 +07:00
|
|
|
lbs_deb_leave(LBS_DEB_SPI);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2011-01-22 03:44:48 +07:00
|
|
|
/* Move data or a command from the host to the card. */
|
|
|
|
static void if_spi_h2c(struct if_spi_card *card,
|
|
|
|
struct if_spi_packet *packet, int type)
|
|
|
|
{
|
2011-05-03 06:49:15 +07:00
|
|
|
struct lbs_private *priv = card->priv;
|
2011-01-22 03:44:48 +07:00
|
|
|
int err = 0;
|
|
|
|
u16 int_type, port_reg;
|
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
case MVMS_DAT:
|
|
|
|
int_type = IF_SPI_CIC_TX_DOWNLOAD_OVER;
|
|
|
|
port_reg = IF_SPI_DATA_RDWRPORT_REG;
|
|
|
|
break;
|
|
|
|
case MVMS_CMD:
|
|
|
|
int_type = IF_SPI_CIC_CMD_DOWNLOAD_OVER;
|
|
|
|
port_reg = IF_SPI_CMD_RDWRPORT_REG;
|
|
|
|
break;
|
|
|
|
default:
|
2011-05-03 06:49:15 +07:00
|
|
|
netdev_err(priv->dev, "can't transfer buffer of type %d\n",
|
|
|
|
type);
|
2011-01-22 03:44:48 +07:00
|
|
|
err = -EINVAL;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Write the data to the card */
|
|
|
|
err = spu_write(card, port_reg, packet->buffer, packet->blen);
|
|
|
|
if (err)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
out:
|
|
|
|
kfree(packet);
|
|
|
|
|
|
|
|
if (err)
|
2011-05-03 06:49:15 +07:00
|
|
|
netdev_err(priv->dev, "%s: error %d\n", __func__, err);
|
2011-01-22 03:44:48 +07:00
|
|
|
}
|
|
|
|
|
2009-01-10 05:58:09 +07:00
|
|
|
/* Inform the host about a card event */
|
|
|
|
static void if_spi_e2h(struct if_spi_card *card)
|
|
|
|
{
|
|
|
|
int err = 0;
|
|
|
|
u32 cause;
|
|
|
|
struct lbs_private *priv = card->priv;
|
|
|
|
|
|
|
|
err = spu_read_u32(card, IF_SPI_SCRATCH_3_REG, &cause);
|
|
|
|
if (err)
|
|
|
|
goto out;
|
|
|
|
|
2009-05-20 07:20:13 +07:00
|
|
|
/* re-enable the card event interrupt */
|
|
|
|
spu_write_u16(card, IF_SPI_HOST_INT_STATUS_REG,
|
|
|
|
~IF_SPI_HICU_CARD_EVENT);
|
|
|
|
|
|
|
|
/* generate a card interrupt */
|
|
|
|
spu_write_u16(card, IF_SPI_CARD_INT_CAUSE_REG, IF_SPI_CIC_HOST_EVENT);
|
|
|
|
|
2009-01-10 05:58:09 +07:00
|
|
|
lbs_queue_event(priv, cause & 0xff);
|
|
|
|
out:
|
|
|
|
if (err)
|
2011-05-03 06:49:15 +07:00
|
|
|
netdev_err(priv->dev, "%s: error %d\n", __func__, err);
|
2009-01-10 05:58:09 +07:00
|
|
|
}
|
|
|
|
|
2011-01-22 03:44:48 +07:00
|
|
|
static void if_spi_host_to_card_worker(struct work_struct *work)
|
2009-01-10 05:58:09 +07:00
|
|
|
{
|
|
|
|
int err;
|
2011-01-22 03:44:48 +07:00
|
|
|
struct if_spi_card *card;
|
2009-01-10 05:58:09 +07:00
|
|
|
u16 hiStatus;
|
2011-01-22 03:44:48 +07:00
|
|
|
unsigned long flags;
|
|
|
|
struct if_spi_packet *packet;
|
2011-05-03 06:49:15 +07:00
|
|
|
struct lbs_private *priv;
|
2009-01-10 05:58:09 +07:00
|
|
|
|
2011-01-22 03:44:48 +07:00
|
|
|
card = container_of(work, struct if_spi_card, packet_work);
|
2011-05-03 06:49:15 +07:00
|
|
|
priv = card->priv;
|
2009-01-10 05:58:09 +07:00
|
|
|
|
2011-01-22 03:44:48 +07:00
|
|
|
lbs_deb_enter(LBS_DEB_SPI);
|
|
|
|
|
2011-04-27 05:25:29 +07:00
|
|
|
/*
|
|
|
|
* Read the host interrupt status register to see what we
|
|
|
|
* can do.
|
|
|
|
*/
|
2011-01-22 03:44:48 +07:00
|
|
|
err = spu_read_u16(card, IF_SPI_HOST_INT_STATUS_REG,
|
|
|
|
&hiStatus);
|
|
|
|
if (err) {
|
2011-05-03 06:49:15 +07:00
|
|
|
netdev_err(priv->dev, "I/O error\n");
|
2011-01-22 03:44:48 +07:00
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (hiStatus & IF_SPI_HIST_CMD_UPLOAD_RDY) {
|
|
|
|
err = if_spi_c2h_cmd(card);
|
|
|
|
if (err)
|
2009-01-10 05:58:09 +07:00
|
|
|
goto err;
|
2011-01-22 03:44:48 +07:00
|
|
|
}
|
|
|
|
if (hiStatus & IF_SPI_HIST_RX_UPLOAD_RDY) {
|
|
|
|
err = if_spi_c2h_data(card);
|
|
|
|
if (err)
|
|
|
|
goto err;
|
|
|
|
}
|
2009-01-10 05:58:09 +07:00
|
|
|
|
2011-04-27 05:25:29 +07:00
|
|
|
/*
|
|
|
|
* workaround: in PS mode, the card does not set the Command
|
|
|
|
* Download Ready bit, but it sets TX Download Ready.
|
|
|
|
*/
|
2011-01-22 03:44:48 +07:00
|
|
|
if (hiStatus & IF_SPI_HIST_CMD_DOWNLOAD_RDY ||
|
|
|
|
(card->priv->psstate != PS_STATE_FULL_POWER &&
|
|
|
|
(hiStatus & IF_SPI_HIST_TX_DOWNLOAD_RDY))) {
|
2011-04-27 05:25:29 +07:00
|
|
|
/*
|
|
|
|
* This means two things. First of all,
|
2011-01-22 03:44:48 +07:00
|
|
|
* if there was a previous command sent, the card has
|
|
|
|
* successfully received it.
|
|
|
|
* Secondly, it is now ready to download another
|
|
|
|
* command.
|
|
|
|
*/
|
|
|
|
lbs_host_to_card_done(card->priv);
|
|
|
|
|
2011-04-27 05:25:29 +07:00
|
|
|
/* Do we have any command packets from the host to send? */
|
2011-01-22 03:44:48 +07:00
|
|
|
packet = NULL;
|
|
|
|
spin_lock_irqsave(&card->buffer_lock, flags);
|
|
|
|
if (!list_empty(&card->cmd_packet_list)) {
|
|
|
|
packet = (struct if_spi_packet *)(card->
|
|
|
|
cmd_packet_list.next);
|
|
|
|
list_del(&packet->list);
|
2010-08-06 03:23:54 +07:00
|
|
|
}
|
2011-01-22 03:44:48 +07:00
|
|
|
spin_unlock_irqrestore(&card->buffer_lock, flags);
|
2009-06-13 02:45:36 +07:00
|
|
|
|
2011-01-22 03:44:48 +07:00
|
|
|
if (packet)
|
|
|
|
if_spi_h2c(card, packet, MVMS_CMD);
|
|
|
|
}
|
|
|
|
if (hiStatus & IF_SPI_HIST_TX_DOWNLOAD_RDY) {
|
2011-04-27 05:25:29 +07:00
|
|
|
/* Do we have any data packets from the host to send? */
|
2011-01-22 03:44:48 +07:00
|
|
|
packet = NULL;
|
|
|
|
spin_lock_irqsave(&card->buffer_lock, flags);
|
|
|
|
if (!list_empty(&card->data_packet_list)) {
|
|
|
|
packet = (struct if_spi_packet *)(card->
|
|
|
|
data_packet_list.next);
|
|
|
|
list_del(&packet->list);
|
2009-01-10 05:58:09 +07:00
|
|
|
}
|
2011-01-22 03:44:48 +07:00
|
|
|
spin_unlock_irqrestore(&card->buffer_lock, flags);
|
2009-01-10 05:58:09 +07:00
|
|
|
|
2011-01-22 03:44:48 +07:00
|
|
|
if (packet)
|
|
|
|
if_spi_h2c(card, packet, MVMS_DAT);
|
|
|
|
}
|
|
|
|
if (hiStatus & IF_SPI_HIST_CARD_EVENT)
|
|
|
|
if_spi_e2h(card);
|
2009-01-10 05:58:09 +07:00
|
|
|
|
|
|
|
err:
|
2011-01-22 03:44:48 +07:00
|
|
|
if (err)
|
2011-05-03 06:49:15 +07:00
|
|
|
netdev_err(priv->dev, "%s: got error %d\n", __func__, err);
|
2009-01-10 05:58:09 +07:00
|
|
|
|
2011-01-22 03:44:48 +07:00
|
|
|
lbs_deb_leave(LBS_DEB_SPI);
|
2009-01-10 05:58:09 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Host to Card
|
|
|
|
*
|
|
|
|
* Called from Libertas to transfer some data to the WLAN device
|
2011-04-27 05:25:29 +07:00
|
|
|
* We can't sleep here.
|
|
|
|
*/
|
2009-01-10 05:58:09 +07:00
|
|
|
static int if_spi_host_to_card(struct lbs_private *priv,
|
|
|
|
u8 type, u8 *buf, u16 nb)
|
|
|
|
{
|
|
|
|
int err = 0;
|
2011-01-22 03:44:48 +07:00
|
|
|
unsigned long flags;
|
2009-01-10 05:58:09 +07:00
|
|
|
struct if_spi_card *card = priv->card;
|
2011-01-22 03:44:48 +07:00
|
|
|
struct if_spi_packet *packet;
|
|
|
|
u16 blen;
|
2009-01-10 05:58:09 +07:00
|
|
|
|
|
|
|
lbs_deb_enter_args(LBS_DEB_SPI, "type %d, bytes %d", type, nb);
|
|
|
|
|
2011-01-22 03:44:48 +07:00
|
|
|
if (nb == 0) {
|
2011-05-03 06:49:15 +07:00
|
|
|
netdev_err(priv->dev, "%s: invalid size requested: %d\n",
|
|
|
|
__func__, nb);
|
2011-01-22 03:44:48 +07:00
|
|
|
err = -EINVAL;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
blen = ALIGN(nb, 4);
|
|
|
|
packet = kzalloc(sizeof(struct if_spi_packet) + blen, GFP_ATOMIC);
|
|
|
|
if (!packet) {
|
|
|
|
err = -ENOMEM;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
packet->blen = blen;
|
|
|
|
memcpy(packet->buffer, buf, nb);
|
|
|
|
memset(packet->buffer + nb, 0, blen - nb);
|
2009-01-10 05:58:09 +07:00
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
case MVMS_CMD:
|
2011-01-22 03:44:48 +07:00
|
|
|
priv->dnld_sent = DNLD_CMD_SENT;
|
|
|
|
spin_lock_irqsave(&card->buffer_lock, flags);
|
|
|
|
list_add_tail(&packet->list, &card->cmd_packet_list);
|
|
|
|
spin_unlock_irqrestore(&card->buffer_lock, flags);
|
2009-01-10 05:58:09 +07:00
|
|
|
break;
|
|
|
|
case MVMS_DAT:
|
2011-01-22 03:44:48 +07:00
|
|
|
priv->dnld_sent = DNLD_DATA_SENT;
|
|
|
|
spin_lock_irqsave(&card->buffer_lock, flags);
|
|
|
|
list_add_tail(&packet->list, &card->data_packet_list);
|
|
|
|
spin_unlock_irqrestore(&card->buffer_lock, flags);
|
2009-01-10 05:58:09 +07:00
|
|
|
break;
|
|
|
|
default:
|
2011-11-14 04:14:32 +07:00
|
|
|
kfree(packet);
|
2011-05-03 06:49:15 +07:00
|
|
|
netdev_err(priv->dev, "can't transfer buffer of type %d\n",
|
|
|
|
type);
|
2009-01-10 05:58:09 +07:00
|
|
|
err = -EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2011-01-22 03:44:48 +07:00
|
|
|
/* Queue spi xfer work */
|
|
|
|
queue_work(card->workqueue, &card->packet_work);
|
|
|
|
out:
|
2009-01-10 05:58:09 +07:00
|
|
|
lbs_deb_leave_args(LBS_DEB_SPI, "err=%d", err);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Host Interrupts
|
|
|
|
*
|
|
|
|
* Service incoming interrupts from the WLAN device. We can't sleep here, so
|
2011-01-22 03:44:48 +07:00
|
|
|
* don't try to talk on the SPI bus, just queue the SPI xfer work.
|
2009-01-10 05:58:09 +07:00
|
|
|
*/
|
|
|
|
static irqreturn_t if_spi_host_interrupt(int irq, void *dev_id)
|
|
|
|
{
|
|
|
|
struct if_spi_card *card = dev_id;
|
|
|
|
|
2011-01-22 03:44:48 +07:00
|
|
|
queue_work(card->workqueue, &card->packet_work);
|
|
|
|
|
2009-01-10 05:58:09 +07:00
|
|
|
return IRQ_HANDLED;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* SPI callbacks
|
|
|
|
*/
|
|
|
|
|
2011-01-22 03:44:48 +07:00
|
|
|
static int if_spi_init_card(struct if_spi_card *card)
|
2009-01-10 05:58:09 +07:00
|
|
|
{
|
2011-05-03 06:49:15 +07:00
|
|
|
struct lbs_private *priv = card->priv;
|
2011-01-22 03:44:48 +07:00
|
|
|
int err, i;
|
2009-01-10 05:58:09 +07:00
|
|
|
u32 scratch;
|
2010-08-08 09:16:30 +07:00
|
|
|
const struct firmware *helper = NULL;
|
|
|
|
const struct firmware *mainfw = NULL;
|
2009-01-10 05:58:09 +07:00
|
|
|
|
|
|
|
lbs_deb_enter(LBS_DEB_SPI);
|
|
|
|
|
2011-01-22 03:44:48 +07:00
|
|
|
err = spu_init(card, card->pdata->use_dummy_writes);
|
2009-01-10 05:58:09 +07:00
|
|
|
if (err)
|
2011-01-22 03:44:48 +07:00
|
|
|
goto out;
|
2009-01-10 05:58:09 +07:00
|
|
|
err = spu_get_chip_revision(card, &card->card_id, &card->card_rev);
|
|
|
|
if (err)
|
2011-01-22 03:44:48 +07:00
|
|
|
goto out;
|
2009-01-10 05:58:09 +07:00
|
|
|
|
|
|
|
err = spu_read_u32(card, IF_SPI_SCRATCH_4_REG, &scratch);
|
|
|
|
if (err)
|
2011-01-22 03:44:48 +07:00
|
|
|
goto out;
|
2009-01-10 05:58:09 +07:00
|
|
|
if (scratch == SUCCESSFUL_FW_DOWNLOAD_MAGIC)
|
|
|
|
lbs_deb_spi("Firmware is already loaded for "
|
|
|
|
"Marvell WLAN 802.11 adapter\n");
|
|
|
|
else {
|
2010-08-08 09:16:30 +07:00
|
|
|
/* Check if we support this card */
|
|
|
|
for (i = 0; i < ARRAY_SIZE(fw_table); i++) {
|
|
|
|
if (card->card_id == fw_table[i].model)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (i == ARRAY_SIZE(fw_table)) {
|
2011-05-03 06:49:15 +07:00
|
|
|
netdev_err(priv->dev, "Unsupported chip_id: 0x%02x\n",
|
|
|
|
card->card_id);
|
2010-08-08 09:16:30 +07:00
|
|
|
err = -ENODEV;
|
2011-01-22 03:44:48 +07:00
|
|
|
goto out;
|
2010-08-08 09:16:30 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
err = lbs_get_firmware(&card->spi->dev, NULL, NULL,
|
|
|
|
card->card_id, &fw_table[0], &helper,
|
|
|
|
&mainfw);
|
|
|
|
if (err) {
|
2011-05-03 06:49:15 +07:00
|
|
|
netdev_err(priv->dev, "failed to find firmware (%d)\n",
|
|
|
|
err);
|
2011-01-22 03:44:48 +07:00
|
|
|
goto out;
|
2010-08-08 09:16:30 +07:00
|
|
|
}
|
2009-01-10 05:58:09 +07:00
|
|
|
|
|
|
|
lbs_deb_spi("Initializing FW for Marvell WLAN 802.11 adapter "
|
|
|
|
"(chip_id = 0x%04x, chip_rev = 0x%02x) "
|
|
|
|
"attached to SPI bus_num %d, chip_select %d. "
|
|
|
|
"spi->max_speed_hz=%d\n",
|
|
|
|
card->card_id, card->card_rev,
|
2011-06-14 12:53:46 +07:00
|
|
|
card->spi->master->bus_num,
|
|
|
|
card->spi->chip_select,
|
|
|
|
card->spi->max_speed_hz);
|
2010-08-08 09:16:30 +07:00
|
|
|
err = if_spi_prog_helper_firmware(card, helper);
|
2009-01-10 05:58:09 +07:00
|
|
|
if (err)
|
2011-01-22 03:44:48 +07:00
|
|
|
goto out;
|
2010-08-08 09:16:30 +07:00
|
|
|
err = if_spi_prog_main_firmware(card, mainfw);
|
2009-01-10 05:58:09 +07:00
|
|
|
if (err)
|
2011-01-22 03:44:48 +07:00
|
|
|
goto out;
|
2009-01-10 05:58:09 +07:00
|
|
|
lbs_deb_spi("loaded FW for Marvell WLAN 802.11 adapter\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
err = spu_set_interrupt_mode(card, 0, 1);
|
2011-01-22 03:44:48 +07:00
|
|
|
if (err)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
out:
|
|
|
|
if (helper)
|
|
|
|
release_firmware(helper);
|
|
|
|
if (mainfw)
|
|
|
|
release_firmware(mainfw);
|
|
|
|
|
|
|
|
lbs_deb_leave_args(LBS_DEB_SPI, "err %d\n", err);
|
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2011-03-16 21:41:46 +07:00
|
|
|
static void if_spi_resume_worker(struct work_struct *work)
|
|
|
|
{
|
|
|
|
struct if_spi_card *card;
|
|
|
|
|
|
|
|
card = container_of(work, struct if_spi_card, resume_work);
|
|
|
|
|
|
|
|
if (card->suspended) {
|
|
|
|
if (card->pdata->setup)
|
|
|
|
card->pdata->setup(card->spi);
|
|
|
|
|
|
|
|
/* Init card ... */
|
|
|
|
if_spi_init_card(card);
|
|
|
|
|
|
|
|
enable_irq(card->spi->irq);
|
|
|
|
|
|
|
|
/* And resume it ... */
|
|
|
|
lbs_resume(card->priv);
|
|
|
|
|
|
|
|
card->suspended = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-01-22 03:44:48 +07:00
|
|
|
static int __devinit if_spi_probe(struct spi_device *spi)
|
|
|
|
{
|
|
|
|
struct if_spi_card *card;
|
|
|
|
struct lbs_private *priv = NULL;
|
|
|
|
struct libertas_spi_platform_data *pdata = spi->dev.platform_data;
|
|
|
|
int err = 0;
|
|
|
|
|
|
|
|
lbs_deb_enter(LBS_DEB_SPI);
|
|
|
|
|
|
|
|
if (!pdata) {
|
|
|
|
err = -EINVAL;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pdata->setup) {
|
|
|
|
err = pdata->setup(spi);
|
|
|
|
if (err)
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Allocate card structure to represent this specific device */
|
|
|
|
card = kzalloc(sizeof(struct if_spi_card), GFP_KERNEL);
|
|
|
|
if (!card) {
|
|
|
|
err = -ENOMEM;
|
|
|
|
goto teardown;
|
|
|
|
}
|
|
|
|
spi_set_drvdata(spi, card);
|
|
|
|
card->pdata = pdata;
|
|
|
|
card->spi = spi;
|
|
|
|
card->prev_xfer_time = jiffies;
|
|
|
|
|
|
|
|
INIT_LIST_HEAD(&card->cmd_packet_list);
|
|
|
|
INIT_LIST_HEAD(&card->data_packet_list);
|
|
|
|
spin_lock_init(&card->buffer_lock);
|
|
|
|
|
|
|
|
/* Initialize the SPI Interface Unit */
|
|
|
|
|
|
|
|
/* Firmware load */
|
|
|
|
err = if_spi_init_card(card);
|
2009-01-10 05:58:09 +07:00
|
|
|
if (err)
|
2009-06-05 02:57:03 +07:00
|
|
|
goto free_card;
|
2009-01-10 05:58:09 +07:00
|
|
|
|
2011-04-27 05:25:29 +07:00
|
|
|
/*
|
|
|
|
* Register our card with libertas.
|
|
|
|
* This will call alloc_etherdev.
|
|
|
|
*/
|
2009-01-10 05:58:09 +07:00
|
|
|
priv = lbs_add_card(card, &spi->dev);
|
|
|
|
if (!priv) {
|
|
|
|
err = -ENOMEM;
|
2009-06-05 02:57:03 +07:00
|
|
|
goto free_card;
|
2009-01-10 05:58:09 +07:00
|
|
|
}
|
|
|
|
card->priv = priv;
|
2011-03-16 21:41:46 +07:00
|
|
|
priv->setup_fw_on_resume = 1;
|
2009-01-10 05:58:09 +07:00
|
|
|
priv->card = card;
|
|
|
|
priv->hw_host_to_card = if_spi_host_to_card;
|
2009-10-01 10:04:38 +07:00
|
|
|
priv->enter_deep_sleep = NULL;
|
|
|
|
priv->exit_deep_sleep = NULL;
|
|
|
|
priv->reset_deep_sleep_wakeup = NULL;
|
2009-01-10 05:58:09 +07:00
|
|
|
priv->fw_ready = 1;
|
|
|
|
|
|
|
|
/* Initialize interrupt handling stuff. */
|
2011-01-22 03:44:48 +07:00
|
|
|
card->workqueue = create_workqueue("libertas_spi");
|
|
|
|
INIT_WORK(&card->packet_work, if_spi_host_to_card_worker);
|
2011-03-16 21:41:46 +07:00
|
|
|
INIT_WORK(&card->resume_work, if_spi_resume_worker);
|
2009-04-03 04:44:09 +07:00
|
|
|
|
2009-01-10 05:58:09 +07:00
|
|
|
err = request_irq(spi->irq, if_spi_host_interrupt,
|
|
|
|
IRQF_TRIGGER_FALLING, "libertas_spi", card);
|
|
|
|
if (err) {
|
2011-05-03 06:49:14 +07:00
|
|
|
pr_err("can't get host irq line-- request_irq failed\n");
|
2011-01-22 03:44:48 +07:00
|
|
|
goto terminate_workqueue;
|
2009-01-10 05:58:09 +07:00
|
|
|
}
|
|
|
|
|
2011-04-27 05:25:29 +07:00
|
|
|
/*
|
|
|
|
* Start the card.
|
2009-01-10 05:58:09 +07:00
|
|
|
* This will call register_netdev, and we'll start
|
2011-04-27 05:25:29 +07:00
|
|
|
* getting interrupts...
|
|
|
|
*/
|
2009-01-10 05:58:09 +07:00
|
|
|
err = lbs_start_card(priv);
|
|
|
|
if (err)
|
|
|
|
goto release_irq;
|
|
|
|
|
|
|
|
lbs_deb_spi("Finished initializing WLAN module.\n");
|
|
|
|
|
|
|
|
/* successful exit */
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
release_irq:
|
|
|
|
free_irq(spi->irq, card);
|
2011-01-22 03:44:48 +07:00
|
|
|
terminate_workqueue:
|
|
|
|
flush_workqueue(card->workqueue);
|
|
|
|
destroy_workqueue(card->workqueue);
|
2009-01-10 05:58:09 +07:00
|
|
|
lbs_remove_card(priv); /* will call free_netdev */
|
|
|
|
free_card:
|
|
|
|
free_if_spi_card(card);
|
2011-01-22 03:44:48 +07:00
|
|
|
teardown:
|
|
|
|
if (pdata->teardown)
|
|
|
|
pdata->teardown(spi);
|
2009-01-10 05:58:09 +07:00
|
|
|
out:
|
|
|
|
lbs_deb_leave_args(LBS_DEB_SPI, "err %d\n", err);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int __devexit libertas_spi_remove(struct spi_device *spi)
|
|
|
|
{
|
|
|
|
struct if_spi_card *card = spi_get_drvdata(spi);
|
|
|
|
struct lbs_private *priv = card->priv;
|
|
|
|
|
|
|
|
lbs_deb_spi("libertas_spi_remove\n");
|
|
|
|
lbs_deb_enter(LBS_DEB_SPI);
|
|
|
|
|
2011-03-16 21:41:46 +07:00
|
|
|
cancel_work_sync(&card->resume_work);
|
|
|
|
|
2009-01-10 05:58:09 +07:00
|
|
|
lbs_stop_card(priv);
|
2009-06-18 23:51:57 +07:00
|
|
|
lbs_remove_card(priv); /* will call free_netdev */
|
|
|
|
|
2009-01-10 05:58:09 +07:00
|
|
|
free_irq(spi->irq, card);
|
2011-01-22 03:44:48 +07:00
|
|
|
flush_workqueue(card->workqueue);
|
|
|
|
destroy_workqueue(card->workqueue);
|
2009-02-03 14:04:20 +07:00
|
|
|
if (card->pdata->teardown)
|
|
|
|
card->pdata->teardown(spi);
|
2009-01-10 05:58:09 +07:00
|
|
|
free_if_spi_card(card);
|
|
|
|
lbs_deb_leave(LBS_DEB_SPI);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-03-16 21:41:46 +07:00
|
|
|
static int if_spi_suspend(struct device *dev)
|
|
|
|
{
|
|
|
|
struct spi_device *spi = to_spi_device(dev);
|
|
|
|
struct if_spi_card *card = spi_get_drvdata(spi);
|
|
|
|
|
|
|
|
if (!card->suspended) {
|
|
|
|
lbs_suspend(card->priv);
|
|
|
|
flush_workqueue(card->workqueue);
|
|
|
|
disable_irq(spi->irq);
|
|
|
|
|
|
|
|
if (card->pdata->teardown)
|
|
|
|
card->pdata->teardown(spi);
|
|
|
|
card->suspended = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int if_spi_resume(struct device *dev)
|
|
|
|
{
|
|
|
|
struct spi_device *spi = to_spi_device(dev);
|
|
|
|
struct if_spi_card *card = spi_get_drvdata(spi);
|
|
|
|
|
|
|
|
/* Schedule delayed work */
|
|
|
|
schedule_work(&card->resume_work);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct dev_pm_ops if_spi_pm_ops = {
|
|
|
|
.suspend = if_spi_suspend,
|
|
|
|
.resume = if_spi_resume,
|
|
|
|
};
|
|
|
|
|
2009-01-10 05:58:09 +07:00
|
|
|
static struct spi_driver libertas_spi_driver = {
|
|
|
|
.probe = if_spi_probe,
|
|
|
|
.remove = __devexit_p(libertas_spi_remove),
|
|
|
|
.driver = {
|
|
|
|
.name = "libertas_spi",
|
|
|
|
.bus = &spi_bus_type,
|
|
|
|
.owner = THIS_MODULE,
|
2011-03-16 21:41:46 +07:00
|
|
|
.pm = &if_spi_pm_ops,
|
2009-01-10 05:58:09 +07:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Module functions
|
|
|
|
*/
|
|
|
|
|
|
|
|
static int __init if_spi_init_module(void)
|
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
lbs_deb_enter(LBS_DEB_SPI);
|
|
|
|
printk(KERN_INFO "libertas_spi: Libertas SPI driver\n");
|
|
|
|
ret = spi_register_driver(&libertas_spi_driver);
|
|
|
|
lbs_deb_leave(LBS_DEB_SPI);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void __exit if_spi_exit_module(void)
|
|
|
|
{
|
|
|
|
lbs_deb_enter(LBS_DEB_SPI);
|
|
|
|
spi_unregister_driver(&libertas_spi_driver);
|
|
|
|
lbs_deb_leave(LBS_DEB_SPI);
|
|
|
|
}
|
|
|
|
|
|
|
|
module_init(if_spi_init_module);
|
|
|
|
module_exit(if_spi_exit_module);
|
|
|
|
|
|
|
|
MODULE_DESCRIPTION("Libertas SPI WLAN Driver");
|
|
|
|
MODULE_AUTHOR("Andrey Yurovsky <andrey@cozybit.com>, "
|
|
|
|
"Colin McCabe <colin@cozybit.com>");
|
|
|
|
MODULE_LICENSE("GPL");
|
2009-09-23 06:46:08 +07:00
|
|
|
MODULE_ALIAS("spi:libertas_spi");
|