2009-01-11 08:18:38 +08:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2008 Christian Lamparter <chunkeey@web.de>
|
|
|
|
* Copyright 2008 Johannes Berg <johannes@sipsolutions.net>
|
|
|
|
*
|
|
|
|
* This driver is a port from stlc45xx:
|
|
|
|
* Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies).
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* version 2 as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* 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; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
|
|
|
|
* 02110-1301 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/platform_device.h>
|
|
|
|
#include <linux/interrupt.h>
|
|
|
|
#include <linux/firmware.h>
|
|
|
|
#include <linux/delay.h>
|
|
|
|
#include <linux/irq.h>
|
|
|
|
#include <linux/spi/spi.h>
|
|
|
|
#include <linux/etherdevice.h>
|
|
|
|
#include <linux/gpio.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 16:04:11 +08:00
|
|
|
#include <linux/slab.h>
|
2009-01-11 08:18:38 +08:00
|
|
|
|
|
|
|
#include "p54spi.h"
|
|
|
|
#include "p54.h"
|
|
|
|
|
2009-06-23 23:39:45 +08:00
|
|
|
#include "lmac.h"
|
2009-01-11 08:18:38 +08:00
|
|
|
|
2010-08-22 06:00:14 +08:00
|
|
|
#ifdef CONFIG_P54_SPI_DEFAULT_EEPROM
|
|
|
|
#include "p54spi_eeprom.h"
|
|
|
|
#endif /* CONFIG_P54_SPI_DEFAULT_EEPROM */
|
|
|
|
|
2009-01-11 08:18:38 +08:00
|
|
|
MODULE_FIRMWARE("3826.arm");
|
|
|
|
|
2009-01-17 05:34:15 +08:00
|
|
|
/*
|
|
|
|
* gpios should be handled in board files and provided via platform data,
|
|
|
|
* but because it's currently impossible for p54spi to have a header file
|
|
|
|
* in include/linux, let's use module paramaters for now
|
|
|
|
*/
|
|
|
|
|
|
|
|
static int p54spi_gpio_power = 97;
|
|
|
|
module_param(p54spi_gpio_power, int, 0444);
|
|
|
|
MODULE_PARM_DESC(p54spi_gpio_power, "gpio number for power line");
|
|
|
|
|
|
|
|
static int p54spi_gpio_irq = 87;
|
|
|
|
module_param(p54spi_gpio_irq, int, 0444);
|
|
|
|
MODULE_PARM_DESC(p54spi_gpio_irq, "gpio number for irq line");
|
|
|
|
|
2009-01-11 08:18:38 +08:00
|
|
|
static void p54spi_spi_read(struct p54s_priv *priv, u8 address,
|
|
|
|
void *buf, size_t len)
|
|
|
|
{
|
|
|
|
struct spi_transfer t[2];
|
|
|
|
struct spi_message m;
|
|
|
|
__le16 addr;
|
|
|
|
|
|
|
|
/* We first push the address */
|
|
|
|
addr = cpu_to_le16(address << 8 | SPI_ADRS_READ_BIT_15);
|
|
|
|
|
|
|
|
spi_message_init(&m);
|
|
|
|
memset(t, 0, sizeof(t));
|
|
|
|
|
|
|
|
t[0].tx_buf = &addr;
|
|
|
|
t[0].len = sizeof(addr);
|
|
|
|
spi_message_add_tail(&t[0], &m);
|
|
|
|
|
|
|
|
t[1].rx_buf = buf;
|
|
|
|
t[1].len = len;
|
|
|
|
spi_message_add_tail(&t[1], &m);
|
|
|
|
|
|
|
|
spi_sync(priv->spi, &m);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void p54spi_spi_write(struct p54s_priv *priv, u8 address,
|
|
|
|
const void *buf, size_t len)
|
|
|
|
{
|
|
|
|
struct spi_transfer t[3];
|
|
|
|
struct spi_message m;
|
|
|
|
__le16 addr;
|
|
|
|
|
|
|
|
/* We first push the address */
|
|
|
|
addr = cpu_to_le16(address << 8);
|
|
|
|
|
|
|
|
spi_message_init(&m);
|
|
|
|
memset(t, 0, sizeof(t));
|
|
|
|
|
|
|
|
t[0].tx_buf = &addr;
|
|
|
|
t[0].len = sizeof(addr);
|
|
|
|
spi_message_add_tail(&t[0], &m);
|
|
|
|
|
|
|
|
t[1].tx_buf = buf;
|
2009-05-18 07:02:32 +08:00
|
|
|
t[1].len = len & ~1;
|
2009-01-11 08:18:38 +08:00
|
|
|
spi_message_add_tail(&t[1], &m);
|
|
|
|
|
|
|
|
if (len % 2) {
|
|
|
|
__le16 last_word;
|
|
|
|
last_word = cpu_to_le16(((u8 *)buf)[len - 1]);
|
|
|
|
|
|
|
|
t[2].tx_buf = &last_word;
|
|
|
|
t[2].len = sizeof(last_word);
|
|
|
|
spi_message_add_tail(&t[2], &m);
|
|
|
|
}
|
|
|
|
|
|
|
|
spi_sync(priv->spi, &m);
|
|
|
|
}
|
|
|
|
|
|
|
|
static u32 p54spi_read32(struct p54s_priv *priv, u8 addr)
|
|
|
|
{
|
|
|
|
__le32 val;
|
|
|
|
|
|
|
|
p54spi_spi_read(priv, addr, &val, sizeof(val));
|
|
|
|
|
|
|
|
return le32_to_cpu(val);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void p54spi_write16(struct p54s_priv *priv, u8 addr, __le16 val)
|
|
|
|
{
|
|
|
|
p54spi_spi_write(priv, addr, &val, sizeof(val));
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void p54spi_write32(struct p54s_priv *priv, u8 addr, __le32 val)
|
|
|
|
{
|
|
|
|
p54spi_spi_write(priv, addr, &val, sizeof(val));
|
|
|
|
}
|
|
|
|
|
2009-07-04 03:01:15 +08:00
|
|
|
static int p54spi_wait_bit(struct p54s_priv *priv, u16 reg, u32 bits)
|
2009-01-11 08:18:38 +08:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < 2000; i++) {
|
2009-07-04 03:01:15 +08:00
|
|
|
u32 buffer = p54spi_read32(priv, reg);
|
2009-03-25 13:30:15 +08:00
|
|
|
if ((buffer & bits) == bits)
|
2009-01-11 08:18:38 +08:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-03-26 11:38:25 +08:00
|
|
|
static int p54spi_spi_write_dma(struct p54s_priv *priv, __le32 base,
|
|
|
|
const void *buf, size_t len)
|
|
|
|
{
|
2009-07-04 03:01:15 +08:00
|
|
|
if (!p54spi_wait_bit(priv, SPI_ADRS_DMA_WRITE_CTRL, HOST_ALLOWED)) {
|
2009-03-26 11:38:25 +08:00
|
|
|
dev_err(&priv->spi->dev, "spi_write_dma not allowed "
|
2009-04-06 05:03:09 +08:00
|
|
|
"to DMA write.\n");
|
2009-03-26 11:38:25 +08:00
|
|
|
return -EAGAIN;
|
|
|
|
}
|
|
|
|
|
2009-05-18 07:02:31 +08:00
|
|
|
p54spi_write16(priv, SPI_ADRS_DMA_WRITE_CTRL,
|
|
|
|
cpu_to_le16(SPI_DMA_WRITE_CTRL_ENABLE));
|
|
|
|
|
2009-03-26 11:38:25 +08:00
|
|
|
p54spi_write16(priv, SPI_ADRS_DMA_WRITE_LEN, cpu_to_le16(len));
|
|
|
|
p54spi_write32(priv, SPI_ADRS_DMA_WRITE_BASE, base);
|
|
|
|
p54spi_spi_write(priv, SPI_ADRS_DMA_DATA, buf, len);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-01-11 08:18:38 +08:00
|
|
|
static int p54spi_request_firmware(struct ieee80211_hw *dev)
|
|
|
|
{
|
|
|
|
struct p54s_priv *priv = dev->priv;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
/* FIXME: should driver use it's own struct device? */
|
|
|
|
ret = request_firmware(&priv->firmware, "3826.arm", &priv->spi->dev);
|
|
|
|
|
|
|
|
if (ret < 0) {
|
|
|
|
dev_err(&priv->spi->dev, "request_firmware() failed: %d", ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = p54_parse_firmware(dev, priv->firmware);
|
|
|
|
if (ret) {
|
|
|
|
release_firmware(priv->firmware);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int p54spi_request_eeprom(struct ieee80211_hw *dev)
|
|
|
|
{
|
|
|
|
struct p54s_priv *priv = dev->priv;
|
|
|
|
const struct firmware *eeprom;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* allow users to customize their eeprom.
|
|
|
|
*/
|
|
|
|
|
|
|
|
ret = request_firmware(&eeprom, "3826.eeprom", &priv->spi->dev);
|
|
|
|
if (ret < 0) {
|
2010-08-22 06:00:14 +08:00
|
|
|
#ifdef CONFIG_P54_SPI_DEFAULT_EEPROM
|
2009-01-11 08:18:38 +08:00
|
|
|
dev_info(&priv->spi->dev, "loading default eeprom...\n");
|
|
|
|
ret = p54_parse_eeprom(dev, (void *) p54spi_eeprom,
|
|
|
|
sizeof(p54spi_eeprom));
|
2010-09-05 06:55:38 +08:00
|
|
|
#else
|
|
|
|
dev_err(&priv->spi->dev, "Failed to request user eeprom\n");
|
2010-08-22 06:00:14 +08:00
|
|
|
#endif /* CONFIG_P54_SPI_DEFAULT_EEPROM */
|
2009-01-11 08:18:38 +08:00
|
|
|
} else {
|
|
|
|
dev_info(&priv->spi->dev, "loading user eeprom...\n");
|
|
|
|
ret = p54_parse_eeprom(dev, (void *) eeprom->data,
|
|
|
|
(int)eeprom->size);
|
|
|
|
release_firmware(eeprom);
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int p54spi_upload_firmware(struct ieee80211_hw *dev)
|
|
|
|
{
|
|
|
|
struct p54s_priv *priv = dev->priv;
|
2009-03-25 20:45:01 +08:00
|
|
|
unsigned long fw_len, _fw_len;
|
|
|
|
unsigned int offset = 0;
|
|
|
|
int err = 0;
|
|
|
|
u8 *fw;
|
|
|
|
|
|
|
|
fw_len = priv->firmware->size;
|
|
|
|
fw = kmemdup(priv->firmware->data, fw_len, GFP_KERNEL);
|
|
|
|
if (!fw)
|
|
|
|
return -ENOMEM;
|
2009-01-11 08:18:38 +08:00
|
|
|
|
|
|
|
/* stop the device */
|
|
|
|
p54spi_write16(priv, SPI_ADRS_DEV_CTRL_STAT, cpu_to_le16(
|
|
|
|
SPI_CTRL_STAT_HOST_OVERRIDE | SPI_CTRL_STAT_HOST_RESET |
|
|
|
|
SPI_CTRL_STAT_START_HALTED));
|
|
|
|
|
|
|
|
msleep(TARGET_BOOT_SLEEP);
|
|
|
|
|
|
|
|
p54spi_write16(priv, SPI_ADRS_DEV_CTRL_STAT, cpu_to_le16(
|
|
|
|
SPI_CTRL_STAT_HOST_OVERRIDE |
|
|
|
|
SPI_CTRL_STAT_START_HALTED));
|
|
|
|
|
|
|
|
msleep(TARGET_BOOT_SLEEP);
|
|
|
|
|
|
|
|
while (fw_len > 0) {
|
|
|
|
_fw_len = min_t(long, fw_len, SPI_MAX_PACKET_SIZE);
|
|
|
|
|
2009-03-26 11:38:25 +08:00
|
|
|
err = p54spi_spi_write_dma(priv, cpu_to_le32(
|
|
|
|
ISL38XX_DEV_FIRMWARE_ADDR + offset),
|
|
|
|
(fw + offset), _fw_len);
|
|
|
|
if (err < 0)
|
2009-03-25 20:45:01 +08:00
|
|
|
goto out;
|
2009-01-11 08:18:38 +08:00
|
|
|
|
|
|
|
fw_len -= _fw_len;
|
2009-03-25 20:45:01 +08:00
|
|
|
offset += _fw_len;
|
2009-01-11 08:18:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
BUG_ON(fw_len != 0);
|
|
|
|
|
|
|
|
/* enable host interrupts */
|
|
|
|
p54spi_write32(priv, SPI_ADRS_HOST_INT_EN,
|
|
|
|
cpu_to_le32(SPI_HOST_INTS_DEFAULT));
|
|
|
|
|
|
|
|
/* boot the device */
|
|
|
|
p54spi_write16(priv, SPI_ADRS_DEV_CTRL_STAT, cpu_to_le16(
|
|
|
|
SPI_CTRL_STAT_HOST_OVERRIDE | SPI_CTRL_STAT_HOST_RESET |
|
|
|
|
SPI_CTRL_STAT_RAM_BOOT));
|
|
|
|
|
|
|
|
msleep(TARGET_BOOT_SLEEP);
|
|
|
|
|
|
|
|
p54spi_write16(priv, SPI_ADRS_DEV_CTRL_STAT, cpu_to_le16(
|
|
|
|
SPI_CTRL_STAT_HOST_OVERRIDE | SPI_CTRL_STAT_RAM_BOOT));
|
|
|
|
msleep(TARGET_BOOT_SLEEP);
|
2009-03-25 20:45:01 +08:00
|
|
|
|
|
|
|
out:
|
|
|
|
kfree(fw);
|
|
|
|
return err;
|
2009-01-11 08:18:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void p54spi_power_off(struct p54s_priv *priv)
|
|
|
|
{
|
2009-01-17 05:34:15 +08:00
|
|
|
disable_irq(gpio_to_irq(p54spi_gpio_irq));
|
|
|
|
gpio_set_value(p54spi_gpio_power, 0);
|
2009-01-11 08:18:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void p54spi_power_on(struct p54s_priv *priv)
|
|
|
|
{
|
2009-01-17 05:34:15 +08:00
|
|
|
gpio_set_value(p54spi_gpio_power, 1);
|
|
|
|
enable_irq(gpio_to_irq(p54spi_gpio_irq));
|
2009-01-11 08:18:38 +08:00
|
|
|
|
|
|
|
/*
|
2011-03-31 09:57:33 +08:00
|
|
|
* need to wait a while before device can be accessed, the length
|
2009-01-11 08:18:38 +08:00
|
|
|
* is just a guess
|
|
|
|
*/
|
|
|
|
msleep(10);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void p54spi_int_ack(struct p54s_priv *priv, u32 val)
|
|
|
|
{
|
|
|
|
p54spi_write32(priv, SPI_ADRS_HOST_INT_ACK, cpu_to_le32(val));
|
|
|
|
}
|
|
|
|
|
2009-05-18 07:02:33 +08:00
|
|
|
static int p54spi_wakeup(struct p54s_priv *priv)
|
2009-01-11 08:18:38 +08:00
|
|
|
{
|
|
|
|
/* wake the chip */
|
|
|
|
p54spi_write32(priv, SPI_ADRS_ARM_INTERRUPTS,
|
|
|
|
cpu_to_le32(SPI_TARGET_INT_WAKEUP));
|
|
|
|
|
|
|
|
/* And wait for the READY interrupt */
|
2009-04-06 05:03:09 +08:00
|
|
|
if (!p54spi_wait_bit(priv, SPI_ADRS_HOST_INTERRUPTS,
|
2009-07-04 03:01:15 +08:00
|
|
|
SPI_HOST_INT_READY)) {
|
2009-04-06 05:03:09 +08:00
|
|
|
dev_err(&priv->spi->dev, "INT_READY timeout\n");
|
2009-05-18 07:02:33 +08:00
|
|
|
return -EBUSY;
|
2009-01-11 08:18:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
p54spi_int_ack(priv, SPI_HOST_INT_READY);
|
2009-05-18 07:02:33 +08:00
|
|
|
return 0;
|
2009-01-11 08:18:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void p54spi_sleep(struct p54s_priv *priv)
|
|
|
|
{
|
|
|
|
p54spi_write32(priv, SPI_ADRS_ARM_INTERRUPTS,
|
|
|
|
cpu_to_le32(SPI_TARGET_INT_SLEEP));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void p54spi_int_ready(struct p54s_priv *priv)
|
|
|
|
{
|
|
|
|
p54spi_write32(priv, SPI_ADRS_HOST_INT_EN, cpu_to_le32(
|
|
|
|
SPI_HOST_INT_UPDATE | SPI_HOST_INT_SW_UPDATE));
|
|
|
|
|
|
|
|
switch (priv->fw_state) {
|
|
|
|
case FW_STATE_BOOTING:
|
|
|
|
priv->fw_state = FW_STATE_READY;
|
|
|
|
complete(&priv->fw_comp);
|
|
|
|
break;
|
|
|
|
case FW_STATE_RESETTING:
|
|
|
|
priv->fw_state = FW_STATE_READY;
|
|
|
|
/* TODO: reinitialize state */
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int p54spi_rx(struct p54s_priv *priv)
|
|
|
|
{
|
|
|
|
struct sk_buff *skb;
|
|
|
|
u16 len;
|
2009-05-18 07:02:35 +08:00
|
|
|
u16 rx_head[2];
|
|
|
|
#define READAHEAD_SZ (sizeof(rx_head)-sizeof(u16))
|
2009-01-11 08:18:38 +08:00
|
|
|
|
2009-05-18 07:02:33 +08:00
|
|
|
if (p54spi_wakeup(priv) < 0)
|
|
|
|
return -EBUSY;
|
2009-01-11 08:18:38 +08:00
|
|
|
|
2009-05-18 07:02:35 +08:00
|
|
|
/* Read data size and first data word in one SPI transaction
|
|
|
|
* This is workaround for firmware/DMA bug,
|
|
|
|
* when first data word gets lost under high load.
|
|
|
|
*/
|
|
|
|
p54spi_spi_read(priv, SPI_ADRS_DMA_DATA, rx_head, sizeof(rx_head));
|
|
|
|
len = rx_head[0];
|
2009-01-11 08:18:38 +08:00
|
|
|
|
|
|
|
if (len == 0) {
|
2009-05-18 07:02:35 +08:00
|
|
|
p54spi_sleep(priv);
|
|
|
|
dev_err(&priv->spi->dev, "rx request of zero bytes\n");
|
2009-01-11 08:18:38 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-03-27 12:50:53 +08:00
|
|
|
/* Firmware may insert up to 4 padding bytes after the lmac header,
|
|
|
|
* but it does not amend the size of SPI data transfer.
|
|
|
|
* Such packets has correct data size in header, thus referencing
|
|
|
|
* past the end of allocated skb. Reserve extra 4 bytes for this case */
|
|
|
|
skb = dev_alloc_skb(len + 4);
|
2009-01-11 08:18:38 +08:00
|
|
|
if (!skb) {
|
2009-05-18 07:02:35 +08:00
|
|
|
p54spi_sleep(priv);
|
2009-01-11 08:18:38 +08:00
|
|
|
dev_err(&priv->spi->dev, "could not alloc skb");
|
2009-05-18 07:02:35 +08:00
|
|
|
return -ENOMEM;
|
2009-01-11 08:18:38 +08:00
|
|
|
}
|
|
|
|
|
2009-05-18 07:02:35 +08:00
|
|
|
if (len <= READAHEAD_SZ) {
|
|
|
|
memcpy(skb_put(skb, len), rx_head + 1, len);
|
|
|
|
} else {
|
|
|
|
memcpy(skb_put(skb, READAHEAD_SZ), rx_head + 1, READAHEAD_SZ);
|
|
|
|
p54spi_spi_read(priv, SPI_ADRS_DMA_DATA,
|
|
|
|
skb_put(skb, len - READAHEAD_SZ),
|
|
|
|
len - READAHEAD_SZ);
|
|
|
|
}
|
2009-01-11 08:18:38 +08:00
|
|
|
p54spi_sleep(priv);
|
2009-03-27 12:50:53 +08:00
|
|
|
/* Put additional bytes to compensate for the possible
|
|
|
|
* alignment-caused truncation */
|
|
|
|
skb_put(skb, 4);
|
2009-01-11 08:18:38 +08:00
|
|
|
|
|
|
|
if (p54_rx(priv->hw, skb) == 0)
|
|
|
|
dev_kfree_skb(skb);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static irqreturn_t p54spi_interrupt(int irq, void *config)
|
|
|
|
{
|
|
|
|
struct spi_device *spi = config;
|
|
|
|
struct p54s_priv *priv = dev_get_drvdata(&spi->dev);
|
|
|
|
|
2009-07-30 08:08:07 +08:00
|
|
|
ieee80211_queue_work(priv->hw, &priv->work);
|
2009-01-11 08:18:38 +08:00
|
|
|
|
|
|
|
return IRQ_HANDLED;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int p54spi_tx_frame(struct p54s_priv *priv, struct sk_buff *skb)
|
|
|
|
{
|
|
|
|
struct p54_hdr *hdr = (struct p54_hdr *) skb->data;
|
|
|
|
int ret = 0;
|
|
|
|
|
2009-05-18 07:02:33 +08:00
|
|
|
if (p54spi_wakeup(priv) < 0)
|
|
|
|
return -EBUSY;
|
2009-01-11 08:18:38 +08:00
|
|
|
|
2009-03-26 11:38:25 +08:00
|
|
|
ret = p54spi_spi_write_dma(priv, hdr->req_id, skb->data, skb->len);
|
|
|
|
if (ret < 0)
|
|
|
|
goto out;
|
2009-01-11 08:18:38 +08:00
|
|
|
|
2009-04-06 05:03:09 +08:00
|
|
|
if (!p54spi_wait_bit(priv, SPI_ADRS_HOST_INTERRUPTS,
|
2009-07-04 03:01:15 +08:00
|
|
|
SPI_HOST_INT_WR_READY)) {
|
2009-04-06 05:03:09 +08:00
|
|
|
dev_err(&priv->spi->dev, "WR_READY timeout\n");
|
2009-05-18 07:02:34 +08:00
|
|
|
ret = -EAGAIN;
|
2009-04-06 05:03:09 +08:00
|
|
|
goto out;
|
2009-01-11 08:18:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
p54spi_int_ack(priv, SPI_HOST_INT_WR_READY);
|
|
|
|
|
|
|
|
if (FREE_AFTER_TX(skb))
|
|
|
|
p54_free_skb(priv->hw, skb);
|
2009-03-26 11:38:25 +08:00
|
|
|
out:
|
2009-05-18 07:02:34 +08:00
|
|
|
p54spi_sleep(priv);
|
2009-01-11 08:18:38 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int p54spi_wq_tx(struct p54s_priv *priv)
|
|
|
|
{
|
|
|
|
struct p54s_tx_info *entry;
|
|
|
|
struct sk_buff *skb;
|
|
|
|
struct ieee80211_tx_info *info;
|
|
|
|
struct p54_tx_info *minfo;
|
|
|
|
struct p54s_tx_info *dinfo;
|
2009-03-30 21:55:24 +08:00
|
|
|
unsigned long flags;
|
2009-01-11 08:18:38 +08:00
|
|
|
int ret = 0;
|
|
|
|
|
2009-03-30 21:55:24 +08:00
|
|
|
spin_lock_irqsave(&priv->tx_lock, flags);
|
2009-01-11 08:18:38 +08:00
|
|
|
|
|
|
|
while (!list_empty(&priv->tx_pending)) {
|
|
|
|
entry = list_entry(priv->tx_pending.next,
|
|
|
|
struct p54s_tx_info, tx_list);
|
|
|
|
|
|
|
|
list_del_init(&entry->tx_list);
|
|
|
|
|
2009-03-30 21:55:24 +08:00
|
|
|
spin_unlock_irqrestore(&priv->tx_lock, flags);
|
2009-01-11 08:18:38 +08:00
|
|
|
|
|
|
|
dinfo = container_of((void *) entry, struct p54s_tx_info,
|
|
|
|
tx_list);
|
|
|
|
minfo = container_of((void *) dinfo, struct p54_tx_info,
|
|
|
|
data);
|
|
|
|
info = container_of((void *) minfo, struct ieee80211_tx_info,
|
|
|
|
rate_driver_data);
|
|
|
|
skb = container_of((void *) info, struct sk_buff, cb);
|
|
|
|
|
|
|
|
ret = p54spi_tx_frame(priv, skb);
|
|
|
|
|
|
|
|
if (ret < 0) {
|
|
|
|
p54_free_skb(priv->hw, skb);
|
2009-03-30 21:55:24 +08:00
|
|
|
return ret;
|
2009-01-11 08:18:38 +08:00
|
|
|
}
|
|
|
|
|
2009-03-30 21:55:24 +08:00
|
|
|
spin_lock_irqsave(&priv->tx_lock, flags);
|
|
|
|
}
|
|
|
|
spin_unlock_irqrestore(&priv->tx_lock, flags);
|
2009-01-11 08:18:38 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void p54spi_op_tx(struct ieee80211_hw *dev, struct sk_buff *skb)
|
|
|
|
{
|
|
|
|
struct p54s_priv *priv = dev->priv;
|
|
|
|
struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
|
|
|
|
struct p54_tx_info *mi = (struct p54_tx_info *) info->rate_driver_data;
|
|
|
|
struct p54s_tx_info *di = (struct p54s_tx_info *) mi->data;
|
2009-03-30 21:55:24 +08:00
|
|
|
unsigned long flags;
|
2009-01-11 08:18:38 +08:00
|
|
|
|
|
|
|
BUILD_BUG_ON(sizeof(*di) > sizeof((mi->data)));
|
|
|
|
|
2009-03-30 21:55:24 +08:00
|
|
|
spin_lock_irqsave(&priv->tx_lock, flags);
|
2009-01-11 08:18:38 +08:00
|
|
|
list_add_tail(&di->tx_list, &priv->tx_pending);
|
2009-03-30 21:55:24 +08:00
|
|
|
spin_unlock_irqrestore(&priv->tx_lock, flags);
|
2009-01-11 08:18:38 +08:00
|
|
|
|
2009-07-30 08:08:07 +08:00
|
|
|
ieee80211_queue_work(priv->hw, &priv->work);
|
2009-01-11 08:18:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void p54spi_work(struct work_struct *work)
|
|
|
|
{
|
|
|
|
struct p54s_priv *priv = container_of(work, struct p54s_priv, work);
|
|
|
|
u32 ints;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
mutex_lock(&priv->mutex);
|
|
|
|
|
2009-05-19 01:28:55 +08:00
|
|
|
if (priv->fw_state == FW_STATE_OFF)
|
2009-01-11 08:18:38 +08:00
|
|
|
goto out;
|
|
|
|
|
|
|
|
ints = p54spi_read32(priv, SPI_ADRS_HOST_INTERRUPTS);
|
|
|
|
|
|
|
|
if (ints & SPI_HOST_INT_READY) {
|
|
|
|
p54spi_int_ready(priv);
|
|
|
|
p54spi_int_ack(priv, SPI_HOST_INT_READY);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (priv->fw_state != FW_STATE_READY)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
if (ints & SPI_HOST_INT_UPDATE) {
|
|
|
|
p54spi_int_ack(priv, SPI_HOST_INT_UPDATE);
|
|
|
|
ret = p54spi_rx(priv);
|
|
|
|
if (ret < 0)
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
if (ints & SPI_HOST_INT_SW_UPDATE) {
|
|
|
|
p54spi_int_ack(priv, SPI_HOST_INT_SW_UPDATE);
|
|
|
|
ret = p54spi_rx(priv);
|
|
|
|
if (ret < 0)
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = p54spi_wq_tx(priv);
|
|
|
|
out:
|
|
|
|
mutex_unlock(&priv->mutex);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int p54spi_op_start(struct ieee80211_hw *dev)
|
|
|
|
{
|
|
|
|
struct p54s_priv *priv = dev->priv;
|
|
|
|
unsigned long timeout;
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
if (mutex_lock_interruptible(&priv->mutex)) {
|
|
|
|
ret = -EINTR;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
priv->fw_state = FW_STATE_BOOTING;
|
|
|
|
|
|
|
|
p54spi_power_on(priv);
|
|
|
|
|
|
|
|
ret = p54spi_upload_firmware(dev);
|
|
|
|
if (ret < 0) {
|
|
|
|
p54spi_power_off(priv);
|
|
|
|
goto out_unlock;
|
|
|
|
}
|
|
|
|
|
|
|
|
mutex_unlock(&priv->mutex);
|
|
|
|
|
|
|
|
timeout = msecs_to_jiffies(2000);
|
|
|
|
timeout = wait_for_completion_interruptible_timeout(&priv->fw_comp,
|
|
|
|
timeout);
|
|
|
|
if (!timeout) {
|
|
|
|
dev_err(&priv->spi->dev, "firmware boot failed");
|
|
|
|
p54spi_power_off(priv);
|
|
|
|
ret = -1;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mutex_lock_interruptible(&priv->mutex)) {
|
|
|
|
ret = -EINTR;
|
|
|
|
p54spi_power_off(priv);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
WARN_ON(priv->fw_state != FW_STATE_READY);
|
|
|
|
|
|
|
|
out_unlock:
|
|
|
|
mutex_unlock(&priv->mutex);
|
|
|
|
|
|
|
|
out:
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void p54spi_op_stop(struct ieee80211_hw *dev)
|
|
|
|
{
|
|
|
|
struct p54s_priv *priv = dev->priv;
|
2009-03-30 21:55:24 +08:00
|
|
|
unsigned long flags;
|
2009-01-11 08:18:38 +08:00
|
|
|
|
2011-11-17 06:51:20 +08:00
|
|
|
mutex_lock(&priv->mutex);
|
2009-01-11 08:18:38 +08:00
|
|
|
WARN_ON(priv->fw_state != FW_STATE_READY);
|
|
|
|
|
|
|
|
p54spi_power_off(priv);
|
2009-03-30 21:55:24 +08:00
|
|
|
spin_lock_irqsave(&priv->tx_lock, flags);
|
2009-01-11 08:18:38 +08:00
|
|
|
INIT_LIST_HEAD(&priv->tx_pending);
|
2009-03-30 21:55:24 +08:00
|
|
|
spin_unlock_irqrestore(&priv->tx_lock, flags);
|
2009-01-11 08:18:38 +08:00
|
|
|
|
|
|
|
priv->fw_state = FW_STATE_OFF;
|
|
|
|
mutex_unlock(&priv->mutex);
|
2011-11-17 06:55:46 +08:00
|
|
|
|
|
|
|
cancel_work_sync(&priv->work);
|
2009-01-11 08:18:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int __devinit p54spi_probe(struct spi_device *spi)
|
|
|
|
{
|
|
|
|
struct p54s_priv *priv = NULL;
|
|
|
|
struct ieee80211_hw *hw;
|
|
|
|
int ret = -EINVAL;
|
|
|
|
|
|
|
|
hw = p54_init_common(sizeof(*priv));
|
|
|
|
if (!hw) {
|
2009-07-20 03:26:13 +08:00
|
|
|
dev_err(&spi->dev, "could not alloc ieee80211_hw");
|
2009-01-11 08:18:38 +08:00
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
priv = hw->priv;
|
|
|
|
priv->hw = hw;
|
|
|
|
dev_set_drvdata(&spi->dev, priv);
|
|
|
|
priv->spi = spi;
|
|
|
|
|
|
|
|
spi->bits_per_word = 16;
|
|
|
|
spi->max_speed_hz = 24000000;
|
|
|
|
|
|
|
|
ret = spi_setup(spi);
|
|
|
|
if (ret < 0) {
|
|
|
|
dev_err(&priv->spi->dev, "spi_setup failed");
|
2012-03-01 04:40:08 +08:00
|
|
|
goto err_free;
|
2009-01-11 08:18:38 +08:00
|
|
|
}
|
|
|
|
|
2009-01-17 05:34:15 +08:00
|
|
|
ret = gpio_request(p54spi_gpio_power, "p54spi power");
|
2009-01-11 08:18:38 +08:00
|
|
|
if (ret < 0) {
|
|
|
|
dev_err(&priv->spi->dev, "power GPIO request failed: %d", ret);
|
2012-03-01 04:40:08 +08:00
|
|
|
goto err_free;
|
2009-01-11 08:18:38 +08:00
|
|
|
}
|
|
|
|
|
2009-01-17 05:34:15 +08:00
|
|
|
ret = gpio_request(p54spi_gpio_irq, "p54spi irq");
|
2009-01-11 08:18:38 +08:00
|
|
|
if (ret < 0) {
|
|
|
|
dev_err(&priv->spi->dev, "irq GPIO request failed: %d", ret);
|
2012-03-01 04:40:08 +08:00
|
|
|
goto err_free_gpio_power;
|
2009-01-11 08:18:38 +08:00
|
|
|
}
|
|
|
|
|
2009-01-17 05:34:15 +08:00
|
|
|
gpio_direction_output(p54spi_gpio_power, 0);
|
|
|
|
gpio_direction_input(p54spi_gpio_irq);
|
2009-01-11 08:18:38 +08:00
|
|
|
|
2009-01-17 05:34:15 +08:00
|
|
|
ret = request_irq(gpio_to_irq(p54spi_gpio_irq),
|
2009-01-11 08:18:38 +08:00
|
|
|
p54spi_interrupt, IRQF_DISABLED, "p54spi",
|
|
|
|
priv->spi);
|
|
|
|
if (ret < 0) {
|
|
|
|
dev_err(&priv->spi->dev, "request_irq() failed");
|
2012-03-01 04:40:08 +08:00
|
|
|
goto err_free_gpio_irq;
|
2009-01-11 08:18:38 +08:00
|
|
|
}
|
|
|
|
|
2011-03-28 23:49:12 +08:00
|
|
|
irq_set_irq_type(gpio_to_irq(p54spi_gpio_irq), IRQ_TYPE_EDGE_RISING);
|
2009-01-11 08:18:38 +08:00
|
|
|
|
2009-01-17 05:34:15 +08:00
|
|
|
disable_irq(gpio_to_irq(p54spi_gpio_irq));
|
2009-01-11 08:18:38 +08:00
|
|
|
|
|
|
|
INIT_WORK(&priv->work, p54spi_work);
|
|
|
|
init_completion(&priv->fw_comp);
|
|
|
|
INIT_LIST_HEAD(&priv->tx_pending);
|
|
|
|
mutex_init(&priv->mutex);
|
2011-11-17 06:48:31 +08:00
|
|
|
spin_lock_init(&priv->tx_lock);
|
2009-01-11 08:18:38 +08:00
|
|
|
SET_IEEE80211_DEV(hw, &spi->dev);
|
|
|
|
priv->common.open = p54spi_op_start;
|
|
|
|
priv->common.stop = p54spi_op_stop;
|
|
|
|
priv->common.tx = p54spi_op_tx;
|
|
|
|
|
|
|
|
ret = p54spi_request_firmware(hw);
|
|
|
|
if (ret < 0)
|
|
|
|
goto err_free_common;
|
|
|
|
|
|
|
|
ret = p54spi_request_eeprom(hw);
|
|
|
|
if (ret)
|
|
|
|
goto err_free_common;
|
|
|
|
|
2009-03-06 04:30:10 +08:00
|
|
|
ret = p54_register_common(hw, &priv->spi->dev);
|
|
|
|
if (ret)
|
2009-01-11 08:18:38 +08:00
|
|
|
goto err_free_common;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
err_free_common:
|
2012-03-01 04:40:08 +08:00
|
|
|
free_irq(gpio_to_irq(p54spi_gpio_irq), spi);
|
|
|
|
err_free_gpio_irq:
|
|
|
|
gpio_free(p54spi_gpio_irq);
|
|
|
|
err_free_gpio_power:
|
|
|
|
gpio_free(p54spi_gpio_power);
|
|
|
|
err_free:
|
2009-01-11 08:18:38 +08:00
|
|
|
p54_free_common(priv->hw);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int __devexit p54spi_remove(struct spi_device *spi)
|
|
|
|
{
|
|
|
|
struct p54s_priv *priv = dev_get_drvdata(&spi->dev);
|
|
|
|
|
2009-06-23 23:39:45 +08:00
|
|
|
p54_unregister_common(priv->hw);
|
2009-01-11 08:18:38 +08:00
|
|
|
|
2009-01-17 05:34:15 +08:00
|
|
|
free_irq(gpio_to_irq(p54spi_gpio_irq), spi);
|
2009-01-11 08:18:38 +08:00
|
|
|
|
2009-01-17 05:34:15 +08:00
|
|
|
gpio_free(p54spi_gpio_power);
|
|
|
|
gpio_free(p54spi_gpio_irq);
|
2009-01-11 08:18:38 +08:00
|
|
|
release_firmware(priv->firmware);
|
|
|
|
|
|
|
|
mutex_destroy(&priv->mutex);
|
|
|
|
|
|
|
|
p54_free_common(priv->hw);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static struct spi_driver p54spi_driver = {
|
|
|
|
.driver = {
|
2010-06-02 10:16:53 +08:00
|
|
|
.name = "p54spi",
|
2009-01-11 08:18:38 +08:00
|
|
|
.owner = THIS_MODULE,
|
|
|
|
},
|
|
|
|
|
|
|
|
.probe = p54spi_probe,
|
|
|
|
.remove = __devexit_p(p54spi_remove),
|
|
|
|
};
|
|
|
|
|
|
|
|
static int __init p54spi_init(void)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = spi_register_driver(&p54spi_driver);
|
|
|
|
if (ret < 0) {
|
|
|
|
printk(KERN_ERR "failed to register SPI driver: %d", ret);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
out:
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void __exit p54spi_exit(void)
|
|
|
|
{
|
|
|
|
spi_unregister_driver(&p54spi_driver);
|
|
|
|
}
|
|
|
|
|
|
|
|
module_init(p54spi_init);
|
|
|
|
module_exit(p54spi_exit);
|
|
|
|
|
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
MODULE_AUTHOR("Christian Lamparter <chunkeey@web.de>");
|
2009-09-23 07:46:08 +08:00
|
|
|
MODULE_ALIAS("spi:cx3110x");
|
2010-06-02 10:16:53 +08:00
|
|
|
MODULE_ALIAS("spi:p54spi");
|
2011-08-26 14:34:59 +08:00
|
|
|
MODULE_ALIAS("spi:stlc45xx");
|