2007-10-04 00:25:41 +00:00
|
|
|
/*
|
|
|
|
|
|
|
|
Driver for the Marvell 8385 based compact flash WLAN cards.
|
|
|
|
|
|
|
|
(C) 2007 by Holger Schurig <hs4233@mail.mn-solutions.de>
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; see the file COPYING. If not, write to
|
|
|
|
the Free Software Foundation, Inc., 51 Franklin Steet, Fifth Floor,
|
|
|
|
Boston, MA 02110-1301, USA.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/module.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 08:04:11 +00:00
|
|
|
#include <linux/slab.h>
|
2007-10-04 00:25:41 +00:00
|
|
|
#include <linux/delay.h>
|
|
|
|
#include <linux/moduleparam.h>
|
|
|
|
#include <linux/firmware.h>
|
|
|
|
#include <linux/netdevice.h>
|
|
|
|
|
|
|
|
#include <pcmcia/cistpl.h>
|
|
|
|
#include <pcmcia/ds.h>
|
|
|
|
|
|
|
|
#include <linux/io.h>
|
|
|
|
|
|
|
|
#define DRV_NAME "libertas_cs"
|
|
|
|
|
|
|
|
#include "decl.h"
|
|
|
|
#include "defs.h"
|
|
|
|
#include "dev.h"
|
|
|
|
|
|
|
|
|
|
|
|
/********************************************************************/
|
|
|
|
/* Module stuff */
|
|
|
|
/********************************************************************/
|
|
|
|
|
|
|
|
MODULE_AUTHOR("Holger Schurig <hs4233@mail.mn-solutions.de>");
|
|
|
|
MODULE_DESCRIPTION("Driver for Marvell 83xx compact flash WLAN cards");
|
|
|
|
MODULE_LICENSE("GPL");
|
2009-11-07 22:00:03 +00:00
|
|
|
MODULE_FIRMWARE("libertas_cs_helper.fw");
|
2007-10-04 00:25:41 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/********************************************************************/
|
|
|
|
/* Data structures */
|
|
|
|
/********************************************************************/
|
|
|
|
|
|
|
|
struct if_cs_card {
|
|
|
|
struct pcmcia_device *p_dev;
|
2007-11-23 14:43:44 +00:00
|
|
|
struct lbs_private *priv;
|
2007-10-04 00:25:41 +00:00
|
|
|
void __iomem *iobase;
|
2009-08-21 02:08:16 +00:00
|
|
|
bool align_regs;
|
2007-10-04 00:25:41 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/********************************************************************/
|
|
|
|
/* Hardware access */
|
|
|
|
/********************************************************************/
|
|
|
|
|
|
|
|
/* This define enables wrapper functions which allow you
|
|
|
|
to dump all register accesses. You normally won't this,
|
|
|
|
except for development */
|
|
|
|
/* #define DEBUG_IO */
|
|
|
|
|
|
|
|
#ifdef DEBUG_IO
|
|
|
|
static int debug_output = 0;
|
|
|
|
#else
|
|
|
|
/* This way the compiler optimizes the printk's away */
|
|
|
|
#define debug_output 0
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static inline unsigned int if_cs_read8(struct if_cs_card *card, uint reg)
|
|
|
|
{
|
|
|
|
unsigned int val = ioread8(card->iobase + reg);
|
|
|
|
if (debug_output)
|
2008-04-01 12:50:43 +00:00
|
|
|
printk(KERN_INFO "inb %08x<%02x\n", reg, val);
|
2007-10-04 00:25:41 +00:00
|
|
|
return val;
|
|
|
|
}
|
|
|
|
static inline unsigned int if_cs_read16(struct if_cs_card *card, uint reg)
|
|
|
|
{
|
|
|
|
unsigned int val = ioread16(card->iobase + reg);
|
|
|
|
if (debug_output)
|
2008-04-01 12:50:43 +00:00
|
|
|
printk(KERN_INFO "inw %08x<%04x\n", reg, val);
|
2007-10-04 00:25:41 +00:00
|
|
|
return val;
|
|
|
|
}
|
|
|
|
static inline void if_cs_read16_rep(
|
|
|
|
struct if_cs_card *card,
|
|
|
|
uint reg,
|
|
|
|
void *buf,
|
|
|
|
unsigned long count)
|
|
|
|
{
|
|
|
|
if (debug_output)
|
2008-04-01 12:50:43 +00:00
|
|
|
printk(KERN_INFO "insw %08x<(0x%lx words)\n",
|
2007-10-04 00:25:41 +00:00
|
|
|
reg, count);
|
|
|
|
ioread16_rep(card->iobase + reg, buf, count);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void if_cs_write8(struct if_cs_card *card, uint reg, u8 val)
|
|
|
|
{
|
|
|
|
if (debug_output)
|
2008-04-01 12:50:43 +00:00
|
|
|
printk(KERN_INFO "outb %08x>%02x\n", reg, val);
|
2007-10-04 00:25:41 +00:00
|
|
|
iowrite8(val, card->iobase + reg);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void if_cs_write16(struct if_cs_card *card, uint reg, u16 val)
|
|
|
|
{
|
|
|
|
if (debug_output)
|
2008-04-01 12:50:43 +00:00
|
|
|
printk(KERN_INFO "outw %08x>%04x\n", reg, val);
|
2007-10-04 00:25:41 +00:00
|
|
|
iowrite16(val, card->iobase + reg);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void if_cs_write16_rep(
|
|
|
|
struct if_cs_card *card,
|
|
|
|
uint reg,
|
2008-05-23 17:37:51 +00:00
|
|
|
const void *buf,
|
2007-10-04 00:25:41 +00:00
|
|
|
unsigned long count)
|
|
|
|
{
|
|
|
|
if (debug_output)
|
2008-04-01 12:50:43 +00:00
|
|
|
printk(KERN_INFO "outsw %08x>(0x%lx words)\n",
|
2007-10-04 00:25:41 +00:00
|
|
|
reg, count);
|
|
|
|
iowrite16_rep(card->iobase + reg, buf, count);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* I know that polling/delaying is frowned upon. However, this procedure
|
|
|
|
* with polling is needed while downloading the firmware. At this stage,
|
|
|
|
* the hardware does unfortunately not create any interrupts.
|
|
|
|
*
|
|
|
|
* Fortunately, this function is never used once the firmware is in
|
|
|
|
* the card. :-)
|
|
|
|
*
|
|
|
|
* As a reference, see the "Firmware Specification v5.1", page 18
|
|
|
|
* and 19. I did not follow their suggested timing to the word,
|
|
|
|
* but this works nice & fast anyway.
|
|
|
|
*/
|
|
|
|
static int if_cs_poll_while_fw_download(struct if_cs_card *card, uint addr, u8 reg)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2008-05-23 08:18:26 +00:00
|
|
|
for (i = 0; i < 100000; i++) {
|
2007-10-04 00:25:41 +00:00
|
|
|
u8 val = if_cs_read8(card, addr);
|
|
|
|
if (val == reg)
|
2009-01-23 16:55:33 +00:00
|
|
|
return 0;
|
2008-05-23 08:18:26 +00:00
|
|
|
udelay(5);
|
2007-10-04 00:25:41 +00:00
|
|
|
}
|
|
|
|
return -ETIME;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2008-06-05 11:07:04 +00:00
|
|
|
/*
|
|
|
|
* First the bitmasks for the host/card interrupt/status registers:
|
|
|
|
*/
|
2008-06-02 07:25:05 +00:00
|
|
|
#define IF_CS_BIT_TX 0x0001
|
|
|
|
#define IF_CS_BIT_RX 0x0002
|
|
|
|
#define IF_CS_BIT_COMMAND 0x0004
|
|
|
|
#define IF_CS_BIT_RESP 0x0008
|
|
|
|
#define IF_CS_BIT_EVENT 0x0010
|
|
|
|
#define IF_CS_BIT_MASK 0x001f
|
2007-10-04 00:25:41 +00:00
|
|
|
|
2008-06-05 11:07:04 +00:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* It's not really clear to me what the host status register is for. It
|
|
|
|
* needs to be set almost in union with "host int cause". The following
|
|
|
|
* bits from above are used:
|
|
|
|
*
|
|
|
|
* IF_CS_BIT_TX driver downloaded a data packet
|
|
|
|
* IF_CS_BIT_RX driver got a data packet
|
|
|
|
* IF_CS_BIT_COMMAND driver downloaded a command
|
|
|
|
* IF_CS_BIT_RESP not used (has some meaning with powerdown)
|
|
|
|
* IF_CS_BIT_EVENT driver read a host event
|
|
|
|
*/
|
2008-06-02 07:25:05 +00:00
|
|
|
#define IF_CS_HOST_STATUS 0x00000000
|
2007-10-04 00:25:41 +00:00
|
|
|
|
2008-06-05 11:07:04 +00:00
|
|
|
/*
|
|
|
|
* With the host int cause register can the host (that is, Linux) cause
|
|
|
|
* an interrupt in the firmware, to tell the firmware about those events:
|
|
|
|
*
|
|
|
|
* IF_CS_BIT_TX a data packet has been downloaded
|
|
|
|
* IF_CS_BIT_RX a received data packet has retrieved
|
|
|
|
* IF_CS_BIT_COMMAND a firmware block or a command has been downloaded
|
|
|
|
* IF_CS_BIT_RESP not used (has some meaning with powerdown)
|
|
|
|
* IF_CS_BIT_EVENT a host event (link lost etc) has been retrieved
|
|
|
|
*/
|
2008-06-02 07:25:05 +00:00
|
|
|
#define IF_CS_HOST_INT_CAUSE 0x00000002
|
2007-10-04 00:25:41 +00:00
|
|
|
|
2008-06-05 11:07:04 +00:00
|
|
|
/*
|
|
|
|
* The host int mask register is used to enable/disable interrupt. However,
|
|
|
|
* I have the suspicion that disabled interrupts are lost.
|
|
|
|
*/
|
2008-06-02 07:25:05 +00:00
|
|
|
#define IF_CS_HOST_INT_MASK 0x00000004
|
2007-10-04 00:25:41 +00:00
|
|
|
|
2008-06-05 11:07:04 +00:00
|
|
|
/*
|
|
|
|
* Used to send or receive data packets:
|
|
|
|
*/
|
2008-06-05 11:09:50 +00:00
|
|
|
#define IF_CS_WRITE 0x00000016
|
|
|
|
#define IF_CS_WRITE_LEN 0x00000014
|
2008-06-02 07:25:05 +00:00
|
|
|
#define IF_CS_READ 0x00000010
|
|
|
|
#define IF_CS_READ_LEN 0x00000024
|
2007-10-04 00:25:41 +00:00
|
|
|
|
2008-06-05 11:07:04 +00:00
|
|
|
/*
|
|
|
|
* Used to send commands (and to send firmware block) and to
|
|
|
|
* receive command responses:
|
|
|
|
*/
|
2008-06-05 11:09:50 +00:00
|
|
|
#define IF_CS_CMD 0x0000001A
|
|
|
|
#define IF_CS_CMD_LEN 0x00000018
|
|
|
|
#define IF_CS_RESP 0x00000012
|
|
|
|
#define IF_CS_RESP_LEN 0x00000030
|
2007-10-04 00:25:41 +00:00
|
|
|
|
2008-06-05 11:07:04 +00:00
|
|
|
/*
|
|
|
|
* The card status registers shows what the card/firmware actually
|
|
|
|
* accepts:
|
|
|
|
*
|
|
|
|
* IF_CS_BIT_TX you may send a data packet
|
|
|
|
* IF_CS_BIT_RX you may retrieve a data packet
|
|
|
|
* IF_CS_BIT_COMMAND you may send a command
|
|
|
|
* IF_CS_BIT_RESP you may retrieve a command response
|
|
|
|
* IF_CS_BIT_EVENT the card has a event for use (link lost, snr low etc)
|
|
|
|
*
|
|
|
|
* When reading this register several times, you will get back the same
|
|
|
|
* results --- with one exception: the IF_CS_BIT_EVENT clear itself
|
|
|
|
* automatically.
|
|
|
|
*
|
|
|
|
* Not that we don't rely on BIT_RX,_BIT_RESP or BIT_EVENT because
|
|
|
|
* we handle this via the card int cause register.
|
|
|
|
*/
|
2008-06-02 07:25:05 +00:00
|
|
|
#define IF_CS_CARD_STATUS 0x00000020
|
|
|
|
#define IF_CS_CARD_STATUS_MASK 0x7f00
|
2007-10-04 00:25:41 +00:00
|
|
|
|
2008-06-05 11:07:04 +00:00
|
|
|
/*
|
|
|
|
* The card int cause register is used by the card/firmware to notify us
|
|
|
|
* about the following events:
|
|
|
|
*
|
|
|
|
* IF_CS_BIT_TX a data packet has successfully been sentx
|
|
|
|
* IF_CS_BIT_RX a data packet has been received and can be retrieved
|
|
|
|
* IF_CS_BIT_COMMAND not used
|
|
|
|
* IF_CS_BIT_RESP the firmware has a command response for us
|
|
|
|
* IF_CS_BIT_EVENT the card has a event for use (link lost, snr low etc)
|
|
|
|
*/
|
2008-06-02 07:25:05 +00:00
|
|
|
#define IF_CS_CARD_INT_CAUSE 0x00000022
|
2007-10-04 00:25:41 +00:00
|
|
|
|
2008-06-05 11:07:04 +00:00
|
|
|
/*
|
|
|
|
* This is used to for handshaking with the card's bootloader/helper image
|
|
|
|
* to synchronize downloading of firmware blocks.
|
|
|
|
*/
|
2008-06-05 11:09:50 +00:00
|
|
|
#define IF_CS_SQ_READ_LOW 0x00000028
|
|
|
|
#define IF_CS_SQ_HELPER_OK 0x10
|
2007-10-04 00:25:41 +00:00
|
|
|
|
2008-06-05 11:07:04 +00:00
|
|
|
/*
|
|
|
|
* The scratch register tells us ...
|
|
|
|
*
|
|
|
|
* IF_CS_SCRATCH_BOOT_OK the bootloader runs
|
|
|
|
* IF_CS_SCRATCH_HELPER_OK the helper firmware already runs
|
|
|
|
*/
|
2007-10-04 00:25:41 +00:00
|
|
|
#define IF_CS_SCRATCH 0x0000003F
|
2008-06-05 11:07:04 +00:00
|
|
|
#define IF_CS_SCRATCH_BOOT_OK 0x00
|
|
|
|
#define IF_CS_SCRATCH_HELPER_OK 0x5a
|
2007-10-04 00:25:41 +00:00
|
|
|
|
2008-06-05 11:08:35 +00:00
|
|
|
/*
|
|
|
|
* Used to detect ancient chips:
|
|
|
|
*/
|
|
|
|
#define IF_CS_PRODUCT_ID 0x0000001C
|
|
|
|
#define IF_CS_CF8385_B1_REV 0x12
|
2009-03-24 20:33:43 +00:00
|
|
|
#define IF_CS_CF8381_B3_REV 0x04
|
2009-08-21 02:08:16 +00:00
|
|
|
#define IF_CS_CF8305_B1_REV 0x03
|
2008-06-05 11:08:35 +00:00
|
|
|
|
2009-03-24 20:33:43 +00:00
|
|
|
/*
|
|
|
|
* Used to detect other cards than CF8385 since their revisions of silicon
|
|
|
|
* doesn't match those from CF8385, eg. CF8381 B3 works with this driver.
|
|
|
|
*/
|
2009-08-21 02:08:16 +00:00
|
|
|
#define CF8305_MANFID 0x02db
|
|
|
|
#define CF8305_CARDID 0x8103
|
2009-03-24 20:33:43 +00:00
|
|
|
#define CF8381_MANFID 0x02db
|
|
|
|
#define CF8381_CARDID 0x6064
|
|
|
|
#define CF8385_MANFID 0x02df
|
|
|
|
#define CF8385_CARDID 0x8103
|
|
|
|
|
2009-08-21 02:08:16 +00:00
|
|
|
static inline int if_cs_hw_is_cf8305(struct pcmcia_device *p_dev)
|
|
|
|
{
|
|
|
|
return (p_dev->manf_id == CF8305_MANFID &&
|
|
|
|
p_dev->card_id == CF8305_CARDID);
|
|
|
|
}
|
|
|
|
|
2009-03-24 20:33:43 +00:00
|
|
|
static inline int if_cs_hw_is_cf8381(struct pcmcia_device *p_dev)
|
|
|
|
{
|
|
|
|
return (p_dev->manf_id == CF8381_MANFID &&
|
|
|
|
p_dev->card_id == CF8381_CARDID);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int if_cs_hw_is_cf8385(struct pcmcia_device *p_dev)
|
|
|
|
{
|
|
|
|
return (p_dev->manf_id == CF8385_MANFID &&
|
|
|
|
p_dev->card_id == CF8385_CARDID);
|
|
|
|
}
|
2007-10-04 00:25:41 +00:00
|
|
|
|
|
|
|
/********************************************************************/
|
2008-05-26 10:50:23 +00:00
|
|
|
/* I/O and interrupt handling */
|
2007-10-04 00:25:41 +00:00
|
|
|
/********************************************************************/
|
|
|
|
|
2008-05-26 10:50:23 +00:00
|
|
|
static inline void if_cs_enable_ints(struct if_cs_card *card)
|
|
|
|
{
|
|
|
|
lbs_deb_enter(LBS_DEB_CS);
|
2008-06-02 07:25:05 +00:00
|
|
|
if_cs_write16(card, IF_CS_HOST_INT_MASK, 0);
|
2008-05-26 10:50:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void if_cs_disable_ints(struct if_cs_card *card)
|
|
|
|
{
|
|
|
|
lbs_deb_enter(LBS_DEB_CS);
|
2008-06-02 07:25:05 +00:00
|
|
|
if_cs_write16(card, IF_CS_HOST_INT_MASK, IF_CS_BIT_MASK);
|
2008-05-26 10:50:23 +00:00
|
|
|
}
|
|
|
|
|
2007-10-04 00:25:41 +00:00
|
|
|
/*
|
|
|
|
* Called from if_cs_host_to_card to send a command to the hardware
|
|
|
|
*/
|
2007-11-23 14:43:44 +00:00
|
|
|
static int if_cs_send_cmd(struct lbs_private *priv, u8 *buf, u16 nb)
|
2007-10-04 00:25:41 +00:00
|
|
|
{
|
|
|
|
struct if_cs_card *card = (struct if_cs_card *)priv->card;
|
|
|
|
int ret = -1;
|
|
|
|
int loops = 0;
|
|
|
|
|
|
|
|
lbs_deb_enter(LBS_DEB_CS);
|
2008-05-26 10:50:23 +00:00
|
|
|
if_cs_disable_ints(card);
|
2007-10-04 00:25:41 +00:00
|
|
|
|
|
|
|
/* Is hardware ready? */
|
|
|
|
while (1) {
|
2008-06-05 11:09:50 +00:00
|
|
|
u16 status = if_cs_read16(card, IF_CS_CARD_STATUS);
|
|
|
|
if (status & IF_CS_BIT_COMMAND)
|
2007-10-04 00:25:41 +00:00
|
|
|
break;
|
|
|
|
if (++loops > 100) {
|
|
|
|
lbs_pr_err("card not ready for commands\n");
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
mdelay(1);
|
|
|
|
}
|
|
|
|
|
2008-06-05 11:09:50 +00:00
|
|
|
if_cs_write16(card, IF_CS_CMD_LEN, nb);
|
2007-10-04 00:25:41 +00:00
|
|
|
|
2008-06-05 11:09:50 +00:00
|
|
|
if_cs_write16_rep(card, IF_CS_CMD, buf, nb / 2);
|
2007-10-04 00:25:41 +00:00
|
|
|
/* Are we supposed to transfer an odd amount of bytes? */
|
|
|
|
if (nb & 1)
|
2008-06-05 11:09:50 +00:00
|
|
|
if_cs_write8(card, IF_CS_CMD, buf[nb-1]);
|
2007-10-04 00:25:41 +00:00
|
|
|
|
|
|
|
/* "Assert the download over interrupt command in the Host
|
|
|
|
* status register" */
|
2008-06-02 07:25:05 +00:00
|
|
|
if_cs_write16(card, IF_CS_HOST_STATUS, IF_CS_BIT_COMMAND);
|
2007-10-04 00:25:41 +00:00
|
|
|
|
|
|
|
/* "Assert the download over interrupt command in the Card
|
|
|
|
* interrupt case register" */
|
2008-06-02 07:25:05 +00:00
|
|
|
if_cs_write16(card, IF_CS_HOST_INT_CAUSE, IF_CS_BIT_COMMAND);
|
2007-10-04 00:25:41 +00:00
|
|
|
ret = 0;
|
|
|
|
|
|
|
|
done:
|
2008-05-26 10:50:23 +00:00
|
|
|
if_cs_enable_ints(card);
|
2007-10-04 00:25:41 +00:00
|
|
|
lbs_deb_leave_args(LBS_DEB_CS, "ret %d", ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Called from if_cs_host_to_card to send a data to the hardware
|
|
|
|
*/
|
2007-11-23 14:43:44 +00:00
|
|
|
static void if_cs_send_data(struct lbs_private *priv, u8 *buf, u16 nb)
|
2007-10-04 00:25:41 +00:00
|
|
|
{
|
|
|
|
struct if_cs_card *card = (struct if_cs_card *)priv->card;
|
2008-05-26 10:50:23 +00:00
|
|
|
u16 status;
|
2007-10-04 00:25:41 +00:00
|
|
|
|
|
|
|
lbs_deb_enter(LBS_DEB_CS);
|
2008-05-26 10:50:23 +00:00
|
|
|
if_cs_disable_ints(card);
|
|
|
|
|
2008-06-02 07:25:05 +00:00
|
|
|
status = if_cs_read16(card, IF_CS_CARD_STATUS);
|
|
|
|
BUG_ON((status & IF_CS_BIT_TX) == 0);
|
2007-10-04 00:25:41 +00:00
|
|
|
|
2008-06-05 11:09:50 +00:00
|
|
|
if_cs_write16(card, IF_CS_WRITE_LEN, nb);
|
2007-10-04 00:25:41 +00:00
|
|
|
|
|
|
|
/* write even number of bytes, then odd byte if necessary */
|
2008-06-05 11:09:50 +00:00
|
|
|
if_cs_write16_rep(card, IF_CS_WRITE, buf, nb / 2);
|
2007-10-04 00:25:41 +00:00
|
|
|
if (nb & 1)
|
2008-06-05 11:09:50 +00:00
|
|
|
if_cs_write8(card, IF_CS_WRITE, buf[nb-1]);
|
2007-10-04 00:25:41 +00:00
|
|
|
|
2008-06-02 07:25:05 +00:00
|
|
|
if_cs_write16(card, IF_CS_HOST_STATUS, IF_CS_BIT_TX);
|
|
|
|
if_cs_write16(card, IF_CS_HOST_INT_CAUSE, IF_CS_BIT_TX);
|
2008-05-26 10:50:23 +00:00
|
|
|
if_cs_enable_ints(card);
|
2007-10-04 00:25:41 +00:00
|
|
|
|
|
|
|
lbs_deb_leave(LBS_DEB_CS);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Get the command result out of the card.
|
|
|
|
*/
|
2007-11-23 14:43:44 +00:00
|
|
|
static int if_cs_receive_cmdres(struct lbs_private *priv, u8 *data, u32 *len)
|
2007-10-04 00:25:41 +00:00
|
|
|
{
|
2008-04-01 12:50:43 +00:00
|
|
|
unsigned long flags;
|
2007-10-04 00:25:41 +00:00
|
|
|
int ret = -1;
|
2008-06-02 07:25:05 +00:00
|
|
|
u16 status;
|
2007-10-04 00:25:41 +00:00
|
|
|
|
|
|
|
lbs_deb_enter(LBS_DEB_CS);
|
|
|
|
|
|
|
|
/* is hardware ready? */
|
2008-06-02 07:25:05 +00:00
|
|
|
status = if_cs_read16(priv->card, IF_CS_CARD_STATUS);
|
|
|
|
if ((status & IF_CS_BIT_RESP) == 0) {
|
|
|
|
lbs_pr_err("no cmd response in card\n");
|
|
|
|
*len = 0;
|
2007-10-04 00:25:41 +00:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2008-06-05 11:09:50 +00:00
|
|
|
*len = if_cs_read16(priv->card, IF_CS_RESP_LEN);
|
2007-12-11 18:49:39 +00:00
|
|
|
if ((*len == 0) || (*len > LBS_CMD_BUFFER_SIZE)) {
|
2007-10-04 00:25:41 +00:00
|
|
|
lbs_pr_err("card cmd buffer has invalid # of bytes (%d)\n", *len);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* read even number of bytes, then odd byte if necessary */
|
2008-06-05 11:09:50 +00:00
|
|
|
if_cs_read16_rep(priv->card, IF_CS_RESP, data, *len/sizeof(u16));
|
2007-10-04 00:25:41 +00:00
|
|
|
if (*len & 1)
|
2008-06-05 11:09:50 +00:00
|
|
|
data[*len-1] = if_cs_read8(priv->card, IF_CS_RESP);
|
2007-10-04 00:25:41 +00:00
|
|
|
|
2007-12-06 12:50:30 +00:00
|
|
|
/* This is a workaround for a firmware that reports too much
|
|
|
|
* bytes */
|
|
|
|
*len -= 8;
|
2007-10-04 00:25:41 +00:00
|
|
|
ret = 0;
|
2008-04-01 12:50:43 +00:00
|
|
|
|
|
|
|
/* Clear this flag again */
|
|
|
|
spin_lock_irqsave(&priv->driver_lock, flags);
|
|
|
|
priv->dnld_sent = DNLD_RES_RECEIVED;
|
|
|
|
spin_unlock_irqrestore(&priv->driver_lock, flags);
|
|
|
|
|
2007-10-04 00:25:41 +00:00
|
|
|
out:
|
|
|
|
lbs_deb_leave_args(LBS_DEB_CS, "ret %d, len %d", ret, *len);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2007-11-23 14:43:44 +00:00
|
|
|
static struct sk_buff *if_cs_receive_data(struct lbs_private *priv)
|
2007-10-04 00:25:41 +00:00
|
|
|
{
|
|
|
|
struct sk_buff *skb = NULL;
|
|
|
|
u16 len;
|
|
|
|
u8 *data;
|
|
|
|
|
|
|
|
lbs_deb_enter(LBS_DEB_CS);
|
|
|
|
|
2008-06-02 07:25:05 +00:00
|
|
|
len = if_cs_read16(priv->card, IF_CS_READ_LEN);
|
2007-10-04 00:25:41 +00:00
|
|
|
if (len == 0 || len > MRVDRV_ETH_RX_PACKET_BUFFER_SIZE) {
|
|
|
|
lbs_pr_err("card data buffer has invalid # of bytes (%d)\n", len);
|
2009-03-20 19:36:36 +00:00
|
|
|
priv->dev->stats.rx_dropped++;
|
2007-10-04 00:25:41 +00:00
|
|
|
goto dat_err;
|
|
|
|
}
|
|
|
|
|
2007-09-07 01:41:02 +00:00
|
|
|
skb = dev_alloc_skb(MRVDRV_ETH_RX_PACKET_BUFFER_SIZE + 2);
|
2007-10-04 00:25:41 +00:00
|
|
|
if (!skb)
|
|
|
|
goto out;
|
2007-09-07 01:41:02 +00:00
|
|
|
skb_put(skb, len);
|
|
|
|
skb_reserve(skb, 2);/* 16 byte align */
|
|
|
|
data = skb->data;
|
2007-10-04 00:25:41 +00:00
|
|
|
|
|
|
|
/* read even number of bytes, then odd byte if necessary */
|
2008-06-02 07:25:05 +00:00
|
|
|
if_cs_read16_rep(priv->card, IF_CS_READ, data, len/sizeof(u16));
|
2007-10-04 00:25:41 +00:00
|
|
|
if (len & 1)
|
2008-06-02 07:25:05 +00:00
|
|
|
data[len-1] = if_cs_read8(priv->card, IF_CS_READ);
|
2007-10-04 00:25:41 +00:00
|
|
|
|
|
|
|
dat_err:
|
2008-06-02 07:25:05 +00:00
|
|
|
if_cs_write16(priv->card, IF_CS_HOST_STATUS, IF_CS_BIT_RX);
|
|
|
|
if_cs_write16(priv->card, IF_CS_HOST_INT_CAUSE, IF_CS_BIT_RX);
|
2007-10-04 00:25:41 +00:00
|
|
|
|
|
|
|
out:
|
|
|
|
lbs_deb_leave_args(LBS_DEB_CS, "ret %p", skb);
|
|
|
|
return skb;
|
|
|
|
}
|
|
|
|
|
2008-04-01 12:50:43 +00:00
|
|
|
static irqreturn_t if_cs_interrupt(int irq, void *data)
|
|
|
|
{
|
|
|
|
struct if_cs_card *card = data;
|
|
|
|
struct lbs_private *priv = card->priv;
|
|
|
|
u16 cause;
|
|
|
|
|
|
|
|
lbs_deb_enter(LBS_DEB_CS);
|
|
|
|
|
2008-05-26 10:50:23 +00:00
|
|
|
/* Ask card interrupt cause register if there is something for us */
|
2008-06-02 07:25:05 +00:00
|
|
|
cause = if_cs_read16(card, IF_CS_CARD_INT_CAUSE);
|
2008-06-05 11:06:15 +00:00
|
|
|
lbs_deb_cs("cause 0x%04x\n", cause);
|
|
|
|
|
2008-04-01 12:50:43 +00:00
|
|
|
if (cause == 0) {
|
|
|
|
/* Not for us */
|
|
|
|
return IRQ_NONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cause == 0xffff) {
|
|
|
|
/* Read in junk, the card has probably been removed */
|
|
|
|
card->priv->surpriseremoved = 1;
|
|
|
|
return IRQ_HANDLED;
|
|
|
|
}
|
|
|
|
|
2008-06-02 07:25:05 +00:00
|
|
|
if (cause & IF_CS_BIT_RX) {
|
2008-04-01 12:50:43 +00:00
|
|
|
struct sk_buff *skb;
|
|
|
|
lbs_deb_cs("rx packet\n");
|
|
|
|
skb = if_cs_receive_data(priv);
|
|
|
|
if (skb)
|
|
|
|
lbs_process_rxed_packet(priv, skb);
|
|
|
|
}
|
|
|
|
|
2008-06-02 07:25:05 +00:00
|
|
|
if (cause & IF_CS_BIT_TX) {
|
2008-05-26 10:50:23 +00:00
|
|
|
lbs_deb_cs("tx done\n");
|
2008-04-01 12:50:43 +00:00
|
|
|
lbs_host_to_card_done(priv);
|
|
|
|
}
|
|
|
|
|
2008-06-02 07:25:05 +00:00
|
|
|
if (cause & IF_CS_BIT_RESP) {
|
2008-04-01 12:50:43 +00:00
|
|
|
unsigned long flags;
|
|
|
|
u8 i;
|
|
|
|
|
2008-05-26 10:50:23 +00:00
|
|
|
lbs_deb_cs("cmd resp\n");
|
2008-04-01 12:50:43 +00:00
|
|
|
spin_lock_irqsave(&priv->driver_lock, flags);
|
|
|
|
i = (priv->resp_idx == 0) ? 1 : 0;
|
|
|
|
spin_unlock_irqrestore(&priv->driver_lock, flags);
|
|
|
|
|
|
|
|
BUG_ON(priv->resp_len[i]);
|
|
|
|
if_cs_receive_cmdres(priv, priv->resp_buf[i],
|
|
|
|
&priv->resp_len[i]);
|
|
|
|
|
|
|
|
spin_lock_irqsave(&priv->driver_lock, flags);
|
|
|
|
lbs_notify_command_response(priv, i);
|
|
|
|
spin_unlock_irqrestore(&priv->driver_lock, flags);
|
|
|
|
}
|
|
|
|
|
2008-06-02 07:25:05 +00:00
|
|
|
if (cause & IF_CS_BIT_EVENT) {
|
2008-06-05 11:09:50 +00:00
|
|
|
u16 status = if_cs_read16(priv->card, IF_CS_CARD_STATUS);
|
2008-06-02 07:25:05 +00:00
|
|
|
if_cs_write16(priv->card, IF_CS_HOST_INT_CAUSE,
|
|
|
|
IF_CS_BIT_EVENT);
|
2008-06-05 11:09:50 +00:00
|
|
|
lbs_queue_event(priv, (status & IF_CS_CARD_STATUS_MASK) >> 8);
|
2008-04-01 12:50:43 +00:00
|
|
|
}
|
|
|
|
|
2008-06-05 11:06:15 +00:00
|
|
|
/* Clear interrupt cause */
|
|
|
|
if_cs_write16(card, IF_CS_CARD_INT_CAUSE, cause & IF_CS_BIT_MASK);
|
|
|
|
|
2008-05-26 10:50:23 +00:00
|
|
|
lbs_deb_leave(LBS_DEB_CS);
|
2008-04-01 12:50:43 +00:00
|
|
|
return IRQ_HANDLED;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2007-10-04 00:25:41 +00:00
|
|
|
/********************************************************************/
|
|
|
|
/* Firmware */
|
|
|
|
/********************************************************************/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Tries to program the helper firmware.
|
|
|
|
*
|
|
|
|
* Return 0 on success
|
|
|
|
*/
|
|
|
|
static int if_cs_prog_helper(struct if_cs_card *card)
|
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
int sent = 0;
|
|
|
|
u8 scratch;
|
|
|
|
const struct firmware *fw;
|
|
|
|
|
|
|
|
lbs_deb_enter(LBS_DEB_CS);
|
|
|
|
|
2009-08-21 02:08:16 +00:00
|
|
|
/*
|
|
|
|
* This is the only place where an unaligned register access happens on
|
|
|
|
* the CF8305 card, therefore for the sake of speed of the driver, we do
|
|
|
|
* the alignment correction here.
|
|
|
|
*/
|
|
|
|
if (card->align_regs)
|
|
|
|
scratch = if_cs_read16(card, IF_CS_SCRATCH) >> 8;
|
|
|
|
else
|
|
|
|
scratch = if_cs_read8(card, IF_CS_SCRATCH);
|
2007-10-04 00:25:41 +00:00
|
|
|
|
|
|
|
/* "If the value is 0x5a, the firmware is already
|
|
|
|
* downloaded successfully"
|
|
|
|
*/
|
2008-06-05 11:07:04 +00:00
|
|
|
if (scratch == IF_CS_SCRATCH_HELPER_OK)
|
2007-10-04 00:25:41 +00:00
|
|
|
goto done;
|
|
|
|
|
|
|
|
/* "If the value is != 00, it is invalid value of register */
|
2008-06-05 11:07:04 +00:00
|
|
|
if (scratch != IF_CS_SCRATCH_BOOT_OK) {
|
2007-10-04 00:25:41 +00:00
|
|
|
ret = -ENODEV;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* TODO: make firmware file configurable */
|
|
|
|
ret = request_firmware(&fw, "libertas_cs_helper.fw",
|
2009-11-03 09:27:34 +00:00
|
|
|
&card->p_dev->dev);
|
2007-10-04 00:25:41 +00:00
|
|
|
if (ret) {
|
|
|
|
lbs_pr_err("can't load helper firmware\n");
|
|
|
|
ret = -ENODEV;
|
|
|
|
goto done;
|
|
|
|
}
|
2007-08-21 09:15:45 +00:00
|
|
|
lbs_deb_cs("helper size %td\n", fw->size);
|
2007-10-04 00:25:41 +00:00
|
|
|
|
|
|
|
/* "Set the 5 bytes of the helper image to 0" */
|
|
|
|
/* Not needed, this contains an ARM branch instruction */
|
|
|
|
|
|
|
|
for (;;) {
|
|
|
|
/* "the number of bytes to send is 256" */
|
|
|
|
int count = 256;
|
|
|
|
int remain = fw->size - sent;
|
|
|
|
|
|
|
|
if (remain < count)
|
|
|
|
count = remain;
|
|
|
|
|
|
|
|
/* "write the number of bytes to be sent to the I/O Command
|
|
|
|
* write length register" */
|
2008-06-05 11:09:50 +00:00
|
|
|
if_cs_write16(card, IF_CS_CMD_LEN, count);
|
2007-10-04 00:25:41 +00:00
|
|
|
|
|
|
|
/* "write this to I/O Command port register as 16 bit writes */
|
|
|
|
if (count)
|
2008-06-05 11:09:50 +00:00
|
|
|
if_cs_write16_rep(card, IF_CS_CMD,
|
2007-10-04 00:25:41 +00:00
|
|
|
&fw->data[sent],
|
|
|
|
count >> 1);
|
|
|
|
|
|
|
|
/* "Assert the download over interrupt command in the Host
|
|
|
|
* status register" */
|
2008-06-02 07:25:05 +00:00
|
|
|
if_cs_write8(card, IF_CS_HOST_STATUS, IF_CS_BIT_COMMAND);
|
2007-10-04 00:25:41 +00:00
|
|
|
|
|
|
|
/* "Assert the download over interrupt command in the Card
|
|
|
|
* interrupt case register" */
|
2008-06-02 07:25:05 +00:00
|
|
|
if_cs_write16(card, IF_CS_HOST_INT_CAUSE, IF_CS_BIT_COMMAND);
|
2007-10-04 00:25:41 +00:00
|
|
|
|
|
|
|
/* "The host polls the Card Status register ... for 50 ms before
|
|
|
|
declaring a failure */
|
2008-06-02 07:25:05 +00:00
|
|
|
ret = if_cs_poll_while_fw_download(card, IF_CS_CARD_STATUS,
|
|
|
|
IF_CS_BIT_COMMAND);
|
2007-10-04 00:25:41 +00:00
|
|
|
if (ret < 0) {
|
|
|
|
lbs_pr_err("can't download helper at 0x%x, ret %d\n",
|
|
|
|
sent, ret);
|
2008-08-27 22:05:08 +00:00
|
|
|
goto err_release;
|
2007-10-04 00:25:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (count == 0)
|
|
|
|
break;
|
|
|
|
|
|
|
|
sent += count;
|
|
|
|
}
|
|
|
|
|
2008-08-27 22:05:08 +00:00
|
|
|
err_release:
|
2007-10-04 00:25:41 +00:00
|
|
|
release_firmware(fw);
|
|
|
|
done:
|
|
|
|
lbs_deb_leave_args(LBS_DEB_CS, "ret %d", ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int if_cs_prog_real(struct if_cs_card *card)
|
|
|
|
{
|
|
|
|
const struct firmware *fw;
|
|
|
|
int ret = 0;
|
|
|
|
int retry = 0;
|
|
|
|
int len = 0;
|
|
|
|
int sent;
|
|
|
|
|
|
|
|
lbs_deb_enter(LBS_DEB_CS);
|
|
|
|
|
|
|
|
/* TODO: make firmware file configurable */
|
|
|
|
ret = request_firmware(&fw, "libertas_cs.fw",
|
2009-11-03 09:27:34 +00:00
|
|
|
&card->p_dev->dev);
|
2007-10-04 00:25:41 +00:00
|
|
|
if (ret) {
|
|
|
|
lbs_pr_err("can't load firmware\n");
|
|
|
|
ret = -ENODEV;
|
|
|
|
goto done;
|
|
|
|
}
|
2007-08-21 09:15:45 +00:00
|
|
|
lbs_deb_cs("fw size %td\n", fw->size);
|
2007-10-04 00:25:41 +00:00
|
|
|
|
2008-06-05 11:09:50 +00:00
|
|
|
ret = if_cs_poll_while_fw_download(card, IF_CS_SQ_READ_LOW,
|
|
|
|
IF_CS_SQ_HELPER_OK);
|
2007-10-04 00:25:41 +00:00
|
|
|
if (ret < 0) {
|
|
|
|
lbs_pr_err("helper firmware doesn't answer\n");
|
|
|
|
goto err_release;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (sent = 0; sent < fw->size; sent += len) {
|
2008-06-05 11:09:50 +00:00
|
|
|
len = if_cs_read16(card, IF_CS_SQ_READ_LOW);
|
2007-10-04 00:25:41 +00:00
|
|
|
if (len & 1) {
|
|
|
|
retry++;
|
|
|
|
lbs_pr_info("odd, need to retry this firmware block\n");
|
|
|
|
} else {
|
|
|
|
retry = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (retry > 20) {
|
|
|
|
lbs_pr_err("could not download firmware\n");
|
|
|
|
ret = -ENODEV;
|
|
|
|
goto err_release;
|
|
|
|
}
|
|
|
|
if (retry) {
|
|
|
|
sent -= len;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-06-05 11:09:50 +00:00
|
|
|
if_cs_write16(card, IF_CS_CMD_LEN, len);
|
2007-10-04 00:25:41 +00:00
|
|
|
|
2008-06-05 11:09:50 +00:00
|
|
|
if_cs_write16_rep(card, IF_CS_CMD,
|
2007-10-04 00:25:41 +00:00
|
|
|
&fw->data[sent],
|
|
|
|
(len+1) >> 1);
|
2008-06-02 07:25:05 +00:00
|
|
|
if_cs_write8(card, IF_CS_HOST_STATUS, IF_CS_BIT_COMMAND);
|
|
|
|
if_cs_write16(card, IF_CS_HOST_INT_CAUSE, IF_CS_BIT_COMMAND);
|
2007-10-04 00:25:41 +00:00
|
|
|
|
2008-06-02 07:25:05 +00:00
|
|
|
ret = if_cs_poll_while_fw_download(card, IF_CS_CARD_STATUS,
|
|
|
|
IF_CS_BIT_COMMAND);
|
2007-10-04 00:25:41 +00:00
|
|
|
if (ret < 0) {
|
|
|
|
lbs_pr_err("can't download firmware at 0x%x\n", sent);
|
|
|
|
goto err_release;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = if_cs_poll_while_fw_download(card, IF_CS_SCRATCH, 0x5a);
|
2008-08-27 22:05:08 +00:00
|
|
|
if (ret < 0)
|
2007-10-04 00:25:41 +00:00
|
|
|
lbs_pr_err("firmware download failed\n");
|
|
|
|
|
|
|
|
err_release:
|
|
|
|
release_firmware(fw);
|
|
|
|
|
|
|
|
done:
|
|
|
|
lbs_deb_leave_args(LBS_DEB_CS, "ret %d", ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/********************************************************************/
|
|
|
|
/* Callback functions for libertas.ko */
|
|
|
|
/********************************************************************/
|
|
|
|
|
|
|
|
/* Send commands or data packets to the card */
|
2007-11-23 14:43:44 +00:00
|
|
|
static int if_cs_host_to_card(struct lbs_private *priv,
|
|
|
|
u8 type,
|
|
|
|
u8 *buf,
|
|
|
|
u16 nb)
|
2007-10-04 00:25:41 +00:00
|
|
|
{
|
|
|
|
int ret = -1;
|
|
|
|
|
|
|
|
lbs_deb_enter_args(LBS_DEB_CS, "type %d, bytes %d", type, nb);
|
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
case MVMS_DAT:
|
2007-09-07 01:30:32 +00:00
|
|
|
priv->dnld_sent = DNLD_DATA_SENT;
|
2007-10-04 00:25:41 +00:00
|
|
|
if_cs_send_data(priv, buf, nb);
|
|
|
|
ret = 0;
|
|
|
|
break;
|
|
|
|
case MVMS_CMD:
|
2007-09-07 01:30:32 +00:00
|
|
|
priv->dnld_sent = DNLD_CMD_SENT;
|
2007-10-04 00:25:41 +00:00
|
|
|
ret = if_cs_send_cmd(priv, buf, nb);
|
|
|
|
break;
|
|
|
|
default:
|
2008-07-29 06:01:34 +00:00
|
|
|
lbs_pr_err("%s: unsupported type %d\n", __func__, type);
|
2007-10-04 00:25:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
lbs_deb_leave_args(LBS_DEB_CS, "ret %d", ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/********************************************************************/
|
|
|
|
/* Card Services */
|
|
|
|
/********************************************************************/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* After a card is removed, if_cs_release() will unregister the
|
|
|
|
* device, and release the PCMCIA configuration. If the device is
|
|
|
|
* still open, this will be postponed until it is closed.
|
|
|
|
*/
|
|
|
|
static void if_cs_release(struct pcmcia_device *p_dev)
|
|
|
|
{
|
|
|
|
struct if_cs_card *card = p_dev->priv;
|
|
|
|
|
|
|
|
lbs_deb_enter(LBS_DEB_CS);
|
|
|
|
|
2010-03-07 11:21:16 +00:00
|
|
|
free_irq(p_dev->irq, card);
|
2008-01-25 13:15:48 +00:00
|
|
|
pcmcia_disable_device(p_dev);
|
2007-10-04 00:25:41 +00:00
|
|
|
if (card->iobase)
|
|
|
|
ioport_unmap(card->iobase);
|
|
|
|
|
|
|
|
lbs_deb_leave(LBS_DEB_CS);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This creates an "instance" of the driver, allocating local data
|
|
|
|
* structures for one device. The device is registered with Card
|
|
|
|
* Services.
|
|
|
|
*
|
|
|
|
* The dev_link structure is initialized, but we don't actually
|
|
|
|
* configure the card at this point -- we wait until we receive a card
|
|
|
|
* insertion event.
|
|
|
|
*/
|
2009-10-18 16:28:39 +00:00
|
|
|
|
|
|
|
static int if_cs_ioprobe(struct pcmcia_device *p_dev,
|
|
|
|
cistpl_cftable_entry_t *cfg,
|
|
|
|
cistpl_cftable_entry_t *dflt,
|
|
|
|
void *priv_data)
|
|
|
|
{
|
2010-07-24 15:23:51 +00:00
|
|
|
p_dev->resource[0]->flags |= IO_DATA_PATH_WIDTH_AUTO;
|
|
|
|
p_dev->resource[0]->start = cfg->io.win[0].base;
|
|
|
|
p_dev->resource[0]->end = cfg->io.win[0].len;
|
2009-10-18 16:28:39 +00:00
|
|
|
|
|
|
|
/* Do we need to allocate an interrupt? */
|
2010-07-29 17:27:09 +00:00
|
|
|
p_dev->config_flags |= CONF_ENABLE_IRQ;
|
2009-10-18 16:28:39 +00:00
|
|
|
|
|
|
|
/* IO window settings */
|
|
|
|
if (cfg->io.nwin != 1) {
|
|
|
|
lbs_pr_err("wrong CIS (check number of IO windows)\n");
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* This reserves IO space but doesn't actually enable it */
|
2010-07-24 15:23:51 +00:00
|
|
|
return pcmcia_request_io(p_dev);
|
2009-10-18 16:28:39 +00:00
|
|
|
}
|
|
|
|
|
2007-10-04 00:25:41 +00:00
|
|
|
static int if_cs_probe(struct pcmcia_device *p_dev)
|
|
|
|
{
|
|
|
|
int ret = -ENOMEM;
|
2009-03-24 20:33:43 +00:00
|
|
|
unsigned int prod_id;
|
2007-11-23 14:43:44 +00:00
|
|
|
struct lbs_private *priv;
|
2007-10-04 00:25:41 +00:00
|
|
|
struct if_cs_card *card;
|
|
|
|
|
|
|
|
lbs_deb_enter(LBS_DEB_CS);
|
|
|
|
|
|
|
|
card = kzalloc(sizeof(struct if_cs_card), GFP_KERNEL);
|
|
|
|
if (!card) {
|
|
|
|
lbs_pr_err("error in kzalloc\n");
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
card->p_dev = p_dev;
|
|
|
|
p_dev->priv = card;
|
|
|
|
|
2009-10-18 16:28:39 +00:00
|
|
|
if (pcmcia_loop_config(p_dev, if_cs_ioprobe, NULL)) {
|
|
|
|
lbs_pr_err("error in pcmcia_loop_config\n");
|
2007-10-04 00:25:41 +00:00
|
|
|
goto out1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Allocate an interrupt line. Note that this does not assign
|
|
|
|
* a handler to the interrupt, unless the 'Handler' member of
|
|
|
|
* the irq structure is initialized.
|
|
|
|
*/
|
2010-03-07 11:21:16 +00:00
|
|
|
if (!p_dev->irq)
|
|
|
|
goto out1;
|
2007-10-04 00:25:41 +00:00
|
|
|
|
|
|
|
/* Initialize io access */
|
2010-07-24 13:58:54 +00:00
|
|
|
card->iobase = ioport_map(p_dev->resource[0]->start,
|
|
|
|
resource_size(p_dev->resource[0]));
|
2007-10-04 00:25:41 +00:00
|
|
|
if (!card->iobase) {
|
|
|
|
lbs_pr_err("error in ioport_map\n");
|
|
|
|
ret = -EIO;
|
|
|
|
goto out1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This actually configures the PCMCIA socket -- setting up
|
|
|
|
* the I/O windows and the interrupt mapping, and putting the
|
|
|
|
* card and host interface into "Memory and IO" mode.
|
|
|
|
*/
|
2010-07-29 17:27:09 +00:00
|
|
|
ret = pcmcia_enable_device(p_dev);
|
2007-10-04 00:25:41 +00:00
|
|
|
if (ret) {
|
2010-07-29 17:27:09 +00:00
|
|
|
lbs_pr_err("error in pcmcia_enable_device\n");
|
2007-10-04 00:25:41 +00:00
|
|
|
goto out2;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Finally, report what we've done */
|
2010-07-24 13:58:54 +00:00
|
|
|
lbs_deb_cs("irq %d, io %pR", p_dev->irq, p_dev->resource[0]);
|
2007-10-04 00:25:41 +00:00
|
|
|
|
2009-08-21 02:08:16 +00:00
|
|
|
/*
|
|
|
|
* Most of the libertas cards can do unaligned register access, but some
|
|
|
|
* weird ones can not. That's especially true for the CF8305 card.
|
|
|
|
*/
|
|
|
|
card->align_regs = 0;
|
|
|
|
|
2008-06-05 11:08:35 +00:00
|
|
|
/* Check if we have a current silicon */
|
2009-03-24 20:33:43 +00:00
|
|
|
prod_id = if_cs_read8(card, IF_CS_PRODUCT_ID);
|
2009-08-21 02:08:16 +00:00
|
|
|
if (if_cs_hw_is_cf8305(p_dev)) {
|
|
|
|
card->align_regs = 1;
|
|
|
|
if (prod_id < IF_CS_CF8305_B1_REV) {
|
|
|
|
lbs_pr_err("old chips like 8305 rev B3 "
|
|
|
|
"aren't supported\n");
|
|
|
|
ret = -ENODEV;
|
|
|
|
goto out2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-03-24 20:33:43 +00:00
|
|
|
if (if_cs_hw_is_cf8381(p_dev) && prod_id < IF_CS_CF8381_B3_REV) {
|
|
|
|
lbs_pr_err("old chips like 8381 rev B3 aren't supported\n");
|
|
|
|
ret = -ENODEV;
|
|
|
|
goto out2;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (if_cs_hw_is_cf8385(p_dev) && prod_id < IF_CS_CF8385_B1_REV) {
|
2008-06-05 11:08:35 +00:00
|
|
|
lbs_pr_err("old chips like 8385 rev B1 aren't supported\n");
|
|
|
|
ret = -ENODEV;
|
|
|
|
goto out2;
|
|
|
|
}
|
2007-10-04 00:25:41 +00:00
|
|
|
|
|
|
|
/* Load the firmware early, before calling into libertas.ko */
|
|
|
|
ret = if_cs_prog_helper(card);
|
2009-08-21 02:08:16 +00:00
|
|
|
if (ret == 0 && !if_cs_hw_is_cf8305(p_dev))
|
2007-10-04 00:25:41 +00:00
|
|
|
ret = if_cs_prog_real(card);
|
|
|
|
if (ret)
|
|
|
|
goto out2;
|
|
|
|
|
|
|
|
/* Make this card known to the libertas driver */
|
2007-11-15 23:05:47 +00:00
|
|
|
priv = lbs_add_card(card, &p_dev->dev);
|
2007-10-04 00:25:41 +00:00
|
|
|
if (!priv) {
|
|
|
|
ret = -ENOMEM;
|
|
|
|
goto out2;
|
|
|
|
}
|
|
|
|
|
2008-04-01 12:50:43 +00:00
|
|
|
/* Finish setting up fields in lbs_private */
|
2007-08-20 15:43:25 +00:00
|
|
|
card->priv = priv;
|
2007-10-04 00:25:41 +00:00
|
|
|
priv->card = card;
|
2008-04-01 12:50:43 +00:00
|
|
|
priv->hw_host_to_card = if_cs_host_to_card;
|
2009-10-01 03:04:38 +00:00
|
|
|
priv->enter_deep_sleep = NULL;
|
|
|
|
priv->exit_deep_sleep = NULL;
|
|
|
|
priv->reset_deep_sleep_wakeup = NULL;
|
2007-12-08 20:04:36 +00:00
|
|
|
priv->fw_ready = 1;
|
2007-08-20 15:43:25 +00:00
|
|
|
|
2007-10-04 00:25:41 +00:00
|
|
|
/* Now actually get the IRQ */
|
2010-03-07 11:21:16 +00:00
|
|
|
ret = request_irq(p_dev->irq, if_cs_interrupt,
|
2007-10-04 00:25:41 +00:00
|
|
|
IRQF_SHARED, DRV_NAME, card);
|
|
|
|
if (ret) {
|
|
|
|
lbs_pr_err("error in request_irq\n");
|
|
|
|
goto out3;
|
|
|
|
}
|
|
|
|
|
2007-10-09 08:41:57 +00:00
|
|
|
/* Clear any interrupt cause that happend while sending
|
|
|
|
* firmware/initializing card */
|
2008-06-02 07:25:05 +00:00
|
|
|
if_cs_write16(card, IF_CS_CARD_INT_CAUSE, IF_CS_BIT_MASK);
|
2007-09-07 01:32:42 +00:00
|
|
|
if_cs_enable_ints(card);
|
|
|
|
|
2007-10-04 00:25:41 +00:00
|
|
|
/* And finally bring the card up */
|
2007-11-15 23:05:47 +00:00
|
|
|
if (lbs_start_card(priv) != 0) {
|
2007-10-04 00:25:41 +00:00
|
|
|
lbs_pr_err("could not activate card\n");
|
|
|
|
goto out3;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
out3:
|
2007-11-15 23:05:47 +00:00
|
|
|
lbs_remove_card(priv);
|
2007-10-04 00:25:41 +00:00
|
|
|
out2:
|
|
|
|
ioport_unmap(card->iobase);
|
|
|
|
out1:
|
|
|
|
pcmcia_disable_device(p_dev);
|
|
|
|
out:
|
|
|
|
lbs_deb_leave_args(LBS_DEB_CS, "ret %d", ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This deletes a driver "instance". The device is de-registered with
|
|
|
|
* Card Services. If it has been released, all local data structures
|
|
|
|
* are freed. Otherwise, the structures will be freed when the device
|
|
|
|
* is released.
|
|
|
|
*/
|
|
|
|
static void if_cs_detach(struct pcmcia_device *p_dev)
|
|
|
|
{
|
|
|
|
struct if_cs_card *card = p_dev->priv;
|
|
|
|
|
|
|
|
lbs_deb_enter(LBS_DEB_CS);
|
|
|
|
|
2007-11-15 23:05:47 +00:00
|
|
|
lbs_stop_card(card->priv);
|
|
|
|
lbs_remove_card(card->priv);
|
2007-09-07 01:32:42 +00:00
|
|
|
if_cs_disable_ints(card);
|
2007-10-04 00:25:41 +00:00
|
|
|
if_cs_release(p_dev);
|
|
|
|
kfree(card);
|
|
|
|
|
|
|
|
lbs_deb_leave(LBS_DEB_CS);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/********************************************************************/
|
|
|
|
/* Module initialization */
|
|
|
|
/********************************************************************/
|
|
|
|
|
|
|
|
static struct pcmcia_device_id if_cs_ids[] = {
|
2009-08-21 02:08:16 +00:00
|
|
|
PCMCIA_DEVICE_MANF_CARD(CF8305_MANFID, CF8305_CARDID),
|
2009-03-24 20:33:43 +00:00
|
|
|
PCMCIA_DEVICE_MANF_CARD(CF8381_MANFID, CF8381_CARDID),
|
|
|
|
PCMCIA_DEVICE_MANF_CARD(CF8385_MANFID, CF8385_CARDID),
|
2007-10-04 00:25:41 +00:00
|
|
|
PCMCIA_DEVICE_NULL,
|
|
|
|
};
|
|
|
|
MODULE_DEVICE_TABLE(pcmcia, if_cs_ids);
|
|
|
|
|
|
|
|
|
2007-11-15 23:05:47 +00:00
|
|
|
static struct pcmcia_driver lbs_driver = {
|
2007-10-04 00:25:41 +00:00
|
|
|
.owner = THIS_MODULE,
|
|
|
|
.drv = {
|
|
|
|
.name = DRV_NAME,
|
|
|
|
},
|
|
|
|
.probe = if_cs_probe,
|
|
|
|
.remove = if_cs_detach,
|
|
|
|
.id_table = if_cs_ids,
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
static int __init if_cs_init(void)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
lbs_deb_enter(LBS_DEB_CS);
|
2007-11-15 23:05:47 +00:00
|
|
|
ret = pcmcia_register_driver(&lbs_driver);
|
2007-10-04 00:25:41 +00:00
|
|
|
lbs_deb_leave(LBS_DEB_CS);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void __exit if_cs_exit(void)
|
|
|
|
{
|
|
|
|
lbs_deb_enter(LBS_DEB_CS);
|
2007-11-15 23:05:47 +00:00
|
|
|
pcmcia_unregister_driver(&lbs_driver);
|
2007-10-04 00:25:41 +00:00
|
|
|
lbs_deb_leave(LBS_DEB_CS);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
module_init(if_cs_init);
|
|
|
|
module_exit(if_cs_exit);
|