/*
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 <linux/slab.h>
#include <linux/delay.h>
#include <linux/moduleparam.h>
#include <linux/firmware.h>
#include <linux/netdevice.h>
#include <pcmcia/cs_types.h>
#include <pcmcia/cs.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");
MODULE_FIRMWARE("libertas_cs_helper.fw");
/********************************************************************/
/* Data structures */
/********************************************************************/
struct if_cs_card {
struct pcmcia_device *p_dev;
struct lbs_private *priv;
void __iomem *iobase;
bool align_regs;
};
/********************************************************************/
/* 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)
printk(KERN_INFO "inb %08x<%02x\n", reg, val);
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)
printk(KERN_INFO "inw %08x<%04x\n", reg, val);
return val;
}
static inline void if_cs_read16_rep(
struct if_cs_card *card,
uint reg,
void *buf,
unsigned long count)
{
if (debug_output)
printk(KERN_INFO "insw %08x<(0x%lx words)\n",
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)
printk(KERN_INFO "outb %08x>%02x\n", reg, val);
iowrite8(val, card->iobase + reg);
}
static inline void if_cs_write16(struct if_cs_card *card, uint reg, u16 val)
{
if (debug_output)
printk(KERN_INFO "outw %08x>%04x\n", reg, val);
iowrite16(val, card->iobase + reg);
}
static inline void if_cs_write16_rep(
struct if_cs_card *card,
uint reg,
const void *buf,
unsigned long count)
{
if (debug_output)
printk(KERN_INFO "outsw %08x>(0x%lx words)\n",
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;
for (i = 0; i < 100000; i++) {
u8 val = if_cs_read8(card, addr);
if (val == reg)
return 0;
udelay(5);
}
return -ETIME;
}
/*
* First the bitmasks for the host/card interrupt/status registers:
*/
#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
/*
* 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
*/
#define IF_CS_HOST_STATUS 0x00000000
/*
* With the host int cause register can the host (that is, Linux) cause<