2013-05-25 08:04:38 +08:00
|
|
|
/*
|
|
|
|
* Mac80211 SDIO driver for ST-Ericsson CW1200 device
|
|
|
|
*
|
|
|
|
* Copyright (c) 2010, ST-Ericsson
|
|
|
|
* Author: Dmitry Tarnyagin <dmitry.tarnyagin@lockless.no>
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/gpio.h>
|
|
|
|
#include <linux/delay.h>
|
|
|
|
#include <linux/mmc/host.h>
|
|
|
|
#include <linux/mmc/sdio_func.h>
|
|
|
|
#include <linux/mmc/card.h>
|
|
|
|
#include <linux/mmc/sdio.h>
|
|
|
|
#include <net/mac80211.h>
|
|
|
|
|
|
|
|
#include "cw1200.h"
|
2013-06-01 20:08:42 +08:00
|
|
|
#include "hwbus.h"
|
2013-06-02 23:35:32 +08:00
|
|
|
#include <linux/platform_data/net-cw1200.h>
|
2013-05-25 08:04:38 +08:00
|
|
|
#include "hwio.h"
|
|
|
|
|
|
|
|
MODULE_AUTHOR("Dmitry Tarnyagin <dmitry.tarnyagin@lockless.no>");
|
|
|
|
MODULE_DESCRIPTION("mac80211 ST-Ericsson CW1200 SDIO driver");
|
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
|
|
|
|
#define SDIO_BLOCK_SIZE (512)
|
|
|
|
|
2013-06-02 23:35:31 +08:00
|
|
|
/* Default platform data for Sagrad modules */
|
|
|
|
static struct cw1200_platform_data_sdio sagrad_109x_evk_platform_data = {
|
|
|
|
.ref_clk = 38400,
|
|
|
|
.have_5ghz = false,
|
|
|
|
.sdd_file = "sdd_sagrad_1091_1098.bin",
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Allow platform data to be overridden */
|
|
|
|
static struct cw1200_platform_data_sdio *global_plat_data = &sagrad_109x_evk_platform_data;
|
|
|
|
|
|
|
|
void __init cw1200_sdio_set_platform_data(struct cw1200_platform_data_sdio *pdata)
|
|
|
|
{
|
|
|
|
global_plat_data = pdata;
|
|
|
|
}
|
|
|
|
|
2013-06-01 20:08:42 +08:00
|
|
|
struct hwbus_priv {
|
2013-05-25 08:04:38 +08:00
|
|
|
struct sdio_func *func;
|
|
|
|
struct cw1200_common *core;
|
|
|
|
const struct cw1200_platform_data_sdio *pdata;
|
|
|
|
};
|
|
|
|
|
|
|
|
#ifndef SDIO_VENDOR_ID_STE
|
|
|
|
#define SDIO_VENDOR_ID_STE 0x0020
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef SDIO_DEVICE_ID_STE_CW1200
|
|
|
|
#define SDIO_DEVICE_ID_STE_CW1200 0x2280
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static const struct sdio_device_id cw1200_sdio_ids[] = {
|
|
|
|
{ SDIO_DEVICE(SDIO_VENDOR_ID_STE, SDIO_DEVICE_ID_STE_CW1200) },
|
|
|
|
{ /* end: all zeroes */ },
|
|
|
|
};
|
|
|
|
|
2013-06-01 20:08:42 +08:00
|
|
|
/* hwbus_ops implemetation */
|
2013-05-25 08:04:38 +08:00
|
|
|
|
2013-06-01 20:08:42 +08:00
|
|
|
static int cw1200_sdio_memcpy_fromio(struct hwbus_priv *self,
|
2013-05-25 08:04:38 +08:00
|
|
|
unsigned int addr,
|
|
|
|
void *dst, int count)
|
|
|
|
{
|
|
|
|
return sdio_memcpy_fromio(self->func, dst, addr, count);
|
|
|
|
}
|
|
|
|
|
2013-06-01 20:08:42 +08:00
|
|
|
static int cw1200_sdio_memcpy_toio(struct hwbus_priv *self,
|
2013-05-25 08:04:38 +08:00
|
|
|
unsigned int addr,
|
|
|
|
const void *src, int count)
|
|
|
|
{
|
|
|
|
return sdio_memcpy_toio(self->func, addr, (void *)src, count);
|
|
|
|
}
|
|
|
|
|
2013-06-01 20:08:42 +08:00
|
|
|
static void cw1200_sdio_lock(struct hwbus_priv *self)
|
2013-05-25 08:04:38 +08:00
|
|
|
{
|
|
|
|
sdio_claim_host(self->func);
|
|
|
|
}
|
|
|
|
|
2013-06-01 20:08:42 +08:00
|
|
|
static void cw1200_sdio_unlock(struct hwbus_priv *self)
|
2013-05-25 08:04:38 +08:00
|
|
|
{
|
|
|
|
sdio_release_host(self->func);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void cw1200_sdio_irq_handler(struct sdio_func *func)
|
|
|
|
{
|
2013-06-01 20:08:42 +08:00
|
|
|
struct hwbus_priv *self = sdio_get_drvdata(func);
|
2013-05-25 08:04:38 +08:00
|
|
|
|
|
|
|
/* note: sdio_host already claimed here. */
|
|
|
|
if (self->core)
|
|
|
|
cw1200_irq_handler(self->core);
|
|
|
|
}
|
|
|
|
|
|
|
|
static irqreturn_t cw1200_gpio_hardirq(int irq, void *dev_id)
|
|
|
|
{
|
|
|
|
return IRQ_WAKE_THREAD;
|
|
|
|
}
|
|
|
|
|
|
|
|
static irqreturn_t cw1200_gpio_irq(int irq, void *dev_id)
|
|
|
|
{
|
2013-06-01 20:08:42 +08:00
|
|
|
struct hwbus_priv *self = dev_id;
|
2013-05-25 08:04:38 +08:00
|
|
|
|
|
|
|
if (self->core) {
|
2013-10-26 06:15:43 +08:00
|
|
|
cw1200_sdio_lock(self);
|
2013-05-25 08:04:38 +08:00
|
|
|
cw1200_irq_handler(self->core);
|
2013-10-26 06:15:43 +08:00
|
|
|
cw1200_sdio_unlock(self);
|
2013-05-25 08:04:38 +08:00
|
|
|
return IRQ_HANDLED;
|
|
|
|
} else {
|
|
|
|
return IRQ_NONE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-01 20:08:42 +08:00
|
|
|
static int cw1200_request_irq(struct hwbus_priv *self)
|
2013-05-25 08:04:38 +08:00
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
u8 cccr;
|
|
|
|
|
|
|
|
cccr = sdio_f0_readb(self->func, SDIO_CCCR_IENx, &ret);
|
|
|
|
if (WARN_ON(ret))
|
|
|
|
goto err;
|
|
|
|
|
|
|
|
/* Master interrupt enable ... */
|
|
|
|
cccr |= BIT(0);
|
|
|
|
|
|
|
|
/* ... for our function */
|
|
|
|
cccr |= BIT(self->func->num);
|
|
|
|
|
|
|
|
sdio_f0_writeb(self->func, cccr, SDIO_CCCR_IENx, &ret);
|
|
|
|
if (WARN_ON(ret))
|
|
|
|
goto err;
|
|
|
|
|
2013-06-02 21:53:03 +08:00
|
|
|
ret = enable_irq_wake(self->pdata->irq);
|
2013-05-25 08:04:38 +08:00
|
|
|
if (WARN_ON(ret))
|
|
|
|
goto err;
|
|
|
|
|
|
|
|
/* Request the IRQ */
|
2013-06-02 21:53:03 +08:00
|
|
|
ret = request_threaded_irq(self->pdata->irq, cw1200_gpio_hardirq,
|
2013-05-25 08:04:38 +08:00
|
|
|
cw1200_gpio_irq,
|
|
|
|
IRQF_TRIGGER_HIGH | IRQF_ONESHOT,
|
2013-06-02 21:53:03 +08:00
|
|
|
"cw1200_wlan_irq", self);
|
2013-05-25 08:04:38 +08:00
|
|
|
if (WARN_ON(ret))
|
|
|
|
goto err;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
err:
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2013-06-01 20:08:42 +08:00
|
|
|
static int cw1200_sdio_irq_subscribe(struct hwbus_priv *self)
|
2013-05-25 08:04:38 +08:00
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
pr_debug("SW IRQ subscribe\n");
|
|
|
|
sdio_claim_host(self->func);
|
|
|
|
if (self->pdata->irq)
|
|
|
|
ret = cw1200_request_irq(self);
|
|
|
|
else
|
|
|
|
ret = sdio_claim_irq(self->func, cw1200_sdio_irq_handler);
|
|
|
|
|
|
|
|
sdio_release_host(self->func);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2013-06-01 20:08:42 +08:00
|
|
|
static int cw1200_sdio_irq_unsubscribe(struct hwbus_priv *self)
|
2013-05-25 08:04:38 +08:00
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
pr_debug("SW IRQ unsubscribe\n");
|
|
|
|
|
|
|
|
if (self->pdata->irq) {
|
2013-06-02 21:53:03 +08:00
|
|
|
disable_irq_wake(self->pdata->irq);
|
|
|
|
free_irq(self->pdata->irq, self);
|
2013-05-25 08:04:38 +08:00
|
|
|
} else {
|
|
|
|
sdio_claim_host(self->func);
|
|
|
|
ret = sdio_release_irq(self->func);
|
|
|
|
sdio_release_host(self->func);
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int cw1200_sdio_off(const struct cw1200_platform_data_sdio *pdata)
|
|
|
|
{
|
2013-06-02 21:53:03 +08:00
|
|
|
if (pdata->reset) {
|
|
|
|
gpio_set_value(pdata->reset, 0);
|
2013-05-25 08:04:38 +08:00
|
|
|
msleep(30); /* Min is 2 * CLK32K cycles */
|
2013-06-02 21:53:03 +08:00
|
|
|
gpio_free(pdata->reset);
|
2013-05-25 08:04:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (pdata->power_ctrl)
|
|
|
|
pdata->power_ctrl(pdata, false);
|
|
|
|
if (pdata->clk_ctrl)
|
|
|
|
pdata->clk_ctrl(pdata, false);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int cw1200_sdio_on(const struct cw1200_platform_data_sdio *pdata)
|
|
|
|
{
|
|
|
|
/* Ensure I/Os are pulled low */
|
2013-06-02 21:53:03 +08:00
|
|
|
if (pdata->reset) {
|
|
|
|
gpio_request(pdata->reset, "cw1200_wlan_reset");
|
|
|
|
gpio_direction_output(pdata->reset, 0);
|
2013-05-25 08:04:38 +08:00
|
|
|
}
|
2013-06-02 21:53:03 +08:00
|
|
|
if (pdata->powerup) {
|
|
|
|
gpio_request(pdata->powerup, "cw1200_wlan_powerup");
|
|
|
|
gpio_direction_output(pdata->powerup, 0);
|
2013-05-25 08:04:38 +08:00
|
|
|
}
|
2013-06-02 21:53:03 +08:00
|
|
|
if (pdata->reset || pdata->powerup)
|
|
|
|
msleep(10); /* Settle time? */
|
2013-05-25 08:04:38 +08:00
|
|
|
|
|
|
|
/* Enable 3v3 and 1v8 to hardware */
|
|
|
|
if (pdata->power_ctrl) {
|
|
|
|
if (pdata->power_ctrl(pdata, true)) {
|
|
|
|
pr_err("power_ctrl() failed!\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Enable CLK32K */
|
|
|
|
if (pdata->clk_ctrl) {
|
|
|
|
if (pdata->clk_ctrl(pdata, true)) {
|
|
|
|
pr_err("clk_ctrl() failed!\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
msleep(10); /* Delay until clock is stable for 2 cycles */
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Enable POWERUP signal */
|
2013-06-02 21:53:03 +08:00
|
|
|
if (pdata->powerup) {
|
|
|
|
gpio_set_value(pdata->powerup, 1);
|
2013-05-25 08:04:38 +08:00
|
|
|
msleep(250); /* or more..? */
|
|
|
|
}
|
|
|
|
/* Enable RSTn signal */
|
2013-06-02 21:53:03 +08:00
|
|
|
if (pdata->reset) {
|
|
|
|
gpio_set_value(pdata->reset, 1);
|
2013-05-25 08:04:38 +08:00
|
|
|
msleep(50); /* Or more..? */
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-06-01 20:08:42 +08:00
|
|
|
static size_t cw1200_sdio_align_size(struct hwbus_priv *self, size_t size)
|
2013-05-25 08:04:38 +08:00
|
|
|
{
|
|
|
|
if (self->pdata->no_nptb)
|
|
|
|
size = round_up(size, SDIO_BLOCK_SIZE);
|
|
|
|
else
|
|
|
|
size = sdio_align_size(self->func, size);
|
|
|
|
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
2013-06-01 20:08:42 +08:00
|
|
|
static int cw1200_sdio_pm(struct hwbus_priv *self, bool suspend)
|
2013-05-25 08:04:38 +08:00
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
if (self->pdata->irq)
|
2013-06-02 21:53:03 +08:00
|
|
|
ret = irq_set_irq_wake(self->pdata->irq, suspend);
|
2013-05-25 08:04:38 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2013-06-01 20:08:42 +08:00
|
|
|
static struct hwbus_ops cw1200_sdio_hwbus_ops = {
|
|
|
|
.hwbus_memcpy_fromio = cw1200_sdio_memcpy_fromio,
|
|
|
|
.hwbus_memcpy_toio = cw1200_sdio_memcpy_toio,
|
2013-05-25 08:04:38 +08:00
|
|
|
.lock = cw1200_sdio_lock,
|
|
|
|
.unlock = cw1200_sdio_unlock,
|
|
|
|
.align_size = cw1200_sdio_align_size,
|
|
|
|
.power_mgmt = cw1200_sdio_pm,
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Probe Function to be called by SDIO stack when device is discovered */
|
|
|
|
static int cw1200_sdio_probe(struct sdio_func *func,
|
2013-06-02 23:35:31 +08:00
|
|
|
const struct sdio_device_id *id)
|
2013-05-25 08:04:38 +08:00
|
|
|
{
|
2013-06-01 20:08:42 +08:00
|
|
|
struct hwbus_priv *self;
|
2013-05-25 08:04:38 +08:00
|
|
|
int status;
|
|
|
|
|
|
|
|
pr_info("cw1200_wlan_sdio: Probe called\n");
|
|
|
|
|
2013-06-02 21:53:03 +08:00
|
|
|
/* We are only able to handle the wlan function */
|
2013-05-25 08:04:38 +08:00
|
|
|
if (func->num != 0x01)
|
|
|
|
return -ENODEV;
|
|
|
|
|
|
|
|
self = kzalloc(sizeof(*self), GFP_KERNEL);
|
|
|
|
if (!self) {
|
2013-06-01 20:08:42 +08:00
|
|
|
pr_err("Can't allocate SDIO hwbus_priv.\n");
|
2013-05-25 08:04:38 +08:00
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
func->card->quirks |= MMC_QUIRK_LENIENT_FN0;
|
|
|
|
|
2013-06-02 23:35:31 +08:00
|
|
|
self->pdata = global_plat_data; /* FIXME */
|
2013-05-25 08:04:38 +08:00
|
|
|
self->func = func;
|
|
|
|
sdio_set_drvdata(func, self);
|
|
|
|
sdio_claim_host(func);
|
|
|
|
sdio_enable_func(func);
|
|
|
|
sdio_release_host(func);
|
|
|
|
|
|
|
|
status = cw1200_sdio_irq_subscribe(self);
|
|
|
|
|
2013-06-01 20:08:42 +08:00
|
|
|
status = cw1200_core_probe(&cw1200_sdio_hwbus_ops,
|
2013-05-25 08:04:38 +08:00
|
|
|
self, &func->dev, &self->core,
|
|
|
|
self->pdata->ref_clk,
|
|
|
|
self->pdata->macaddr,
|
|
|
|
self->pdata->sdd_file,
|
|
|
|
self->pdata->have_5ghz);
|
|
|
|
if (status) {
|
|
|
|
cw1200_sdio_irq_unsubscribe(self);
|
|
|
|
sdio_claim_host(func);
|
|
|
|
sdio_disable_func(func);
|
|
|
|
sdio_release_host(func);
|
|
|
|
sdio_set_drvdata(func, NULL);
|
|
|
|
kfree(self);
|
|
|
|
}
|
|
|
|
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Disconnect Function to be called by SDIO stack when
|
2013-06-11 21:49:40 +08:00
|
|
|
* device is disconnected
|
|
|
|
*/
|
2013-05-25 08:04:38 +08:00
|
|
|
static void cw1200_sdio_disconnect(struct sdio_func *func)
|
|
|
|
{
|
2013-06-01 20:08:42 +08:00
|
|
|
struct hwbus_priv *self = sdio_get_drvdata(func);
|
2013-05-25 08:04:38 +08:00
|
|
|
|
|
|
|
if (self) {
|
|
|
|
cw1200_sdio_irq_unsubscribe(self);
|
|
|
|
if (self->core) {
|
|
|
|
cw1200_core_release(self->core);
|
|
|
|
self->core = NULL;
|
|
|
|
}
|
|
|
|
sdio_claim_host(func);
|
|
|
|
sdio_disable_func(func);
|
|
|
|
sdio_release_host(func);
|
|
|
|
sdio_set_drvdata(func, NULL);
|
|
|
|
kfree(self);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-30 10:22:05 +08:00
|
|
|
#ifdef CONFIG_PM
|
2013-05-25 08:04:38 +08:00
|
|
|
static int cw1200_sdio_suspend(struct device *dev)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
struct sdio_func *func = dev_to_sdio_func(dev);
|
2013-06-01 20:08:42 +08:00
|
|
|
struct hwbus_priv *self = sdio_get_drvdata(func);
|
2013-05-25 08:04:38 +08:00
|
|
|
|
|
|
|
if (!cw1200_can_suspend(self->core))
|
|
|
|
return -EAGAIN;
|
|
|
|
|
|
|
|
/* Notify SDIO that CW1200 will remain powered during suspend */
|
|
|
|
ret = sdio_set_host_pm_flags(func, MMC_PM_KEEP_POWER);
|
|
|
|
if (ret)
|
|
|
|
pr_err("Error setting SDIO pm flags: %i\n", ret);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int cw1200_sdio_resume(struct device *dev)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct dev_pm_ops cw1200_pm_ops = {
|
|
|
|
.suspend = cw1200_sdio_suspend,
|
|
|
|
.resume = cw1200_sdio_resume,
|
|
|
|
};
|
2013-05-30 10:22:05 +08:00
|
|
|
#endif
|
2013-05-25 08:04:38 +08:00
|
|
|
|
|
|
|
static struct sdio_driver sdio_driver = {
|
|
|
|
.name = "cw1200_wlan_sdio",
|
|
|
|
.id_table = cw1200_sdio_ids,
|
|
|
|
.probe = cw1200_sdio_probe,
|
|
|
|
.remove = cw1200_sdio_disconnect,
|
2013-05-30 10:22:05 +08:00
|
|
|
#ifdef CONFIG_PM
|
2013-05-25 08:04:38 +08:00
|
|
|
.drv = {
|
|
|
|
.pm = &cw1200_pm_ops,
|
|
|
|
}
|
2013-05-30 10:22:05 +08:00
|
|
|
#endif
|
2013-05-25 08:04:38 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Init Module function -> Called by insmod */
|
|
|
|
static int __init cw1200_sdio_init(void)
|
|
|
|
{
|
|
|
|
const struct cw1200_platform_data_sdio *pdata;
|
|
|
|
int ret;
|
|
|
|
|
2013-06-02 23:35:31 +08:00
|
|
|
/* FIXME -- this won't support multiple devices */
|
|
|
|
pdata = global_plat_data;
|
2013-05-25 08:04:38 +08:00
|
|
|
|
|
|
|
if (cw1200_sdio_on(pdata)) {
|
|
|
|
ret = -1;
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = sdio_register_driver(&sdio_driver);
|
|
|
|
if (ret)
|
|
|
|
goto err;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
err:
|
|
|
|
cw1200_sdio_off(pdata);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Called at Driver Unloading */
|
|
|
|
static void __exit cw1200_sdio_exit(void)
|
|
|
|
{
|
|
|
|
const struct cw1200_platform_data_sdio *pdata;
|
2013-06-02 23:35:31 +08:00
|
|
|
|
|
|
|
/* FIXME -- this won't support multiple devices */
|
|
|
|
pdata = global_plat_data;
|
2013-05-25 08:04:38 +08:00
|
|
|
sdio_unregister_driver(&sdio_driver);
|
|
|
|
cw1200_sdio_off(pdata);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
module_init(cw1200_sdio_init);
|
|
|
|
module_exit(cw1200_sdio_exit);
|