Skip to content

Commit

Permalink
Implement platform abstraction layer
Browse files Browse the repository at this point in the history
wcn36xx_platform_data - is the interface.

Signed-off-by: Eugene Krasnikov <k.eugene.e@gmail.com>
  • Loading branch information
Eugene Krasnikov committed Aug 6, 2013
1 parent b2cc4ce commit becf7a7
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 65 deletions.
20 changes: 10 additions & 10 deletions dxe.c
Expand Up @@ -41,12 +41,12 @@ static void wcn36xx_dxe_write_register(struct wcn36xx *wcn, int addr, int data)
addr, data);

wmb();
writel_relaxed(data, wcn->mmio + addr);
writel_relaxed(data, wcn->pdata->mmio + addr);
}

static void wcn36xx_dxe_read_register(struct wcn36xx *wcn, int addr, int *data)
{
*data = readl_relaxed(wcn->mmio + addr);
*data = readl_relaxed(wcn->pdata->mmio + addr);
rmb();

wcn36xx_dbg(WCN36XX_DBG_DXE,
Expand Down Expand Up @@ -419,7 +419,7 @@ static irqreturn_t wcn36xx_irq_rx_ready(int irq, void *dev)
{
struct wcn36xx *wcn = (struct wcn36xx *)dev;

disable_irq_nosync(wcn->rx_irq);
disable_irq_nosync(wcn->pdata->rx_irq);
queue_work(wcn->wq, &wcn->rx_ready_work);

return IRQ_HANDLED;
Expand All @@ -429,26 +429,26 @@ static int wcn36xx_dxe_request_irqs(struct wcn36xx *wcn)
{
int ret;

ret = request_irq(wcn->tx_irq, wcn36xx_irq_tx_complete,
ret = request_irq(wcn->pdata->tx_irq, wcn36xx_irq_tx_complete,
IRQF_TRIGGER_HIGH, "wcn36xx_tx", wcn);
if (ret) {
wcn36xx_error("failed to alloc tx irq");
goto out_err;
}

ret = request_irq(wcn->rx_irq, wcn36xx_irq_rx_ready, IRQF_TRIGGER_HIGH,
ret = request_irq(wcn->pdata->rx_irq, wcn36xx_irq_rx_ready, IRQF_TRIGGER_HIGH,
"wcn36xx_rx", wcn);
if (ret) {
wcn36xx_error("failed to alloc rx irq");
goto out_txirq;
}

enable_irq_wake(wcn->rx_irq);
enable_irq_wake(wcn->pdata->rx_irq);

return 0;

out_txirq:
free_irq(wcn->tx_irq, wcn);
free_irq(wcn->pdata->tx_irq, wcn);
out_err:
return ret;

Expand Down Expand Up @@ -520,7 +520,7 @@ void wcn36xx_rx_ready_work(struct work_struct *work)
if (!int_src)
wcn36xx_warn("No DXE interrupt pending");

enable_irq(wcn->rx_irq);
enable_irq(wcn->pdata->rx_irq);
}

int wcn36xx_dxe_allocate_mem_pools(struct wcn36xx *wcn)
Expand Down Expand Up @@ -798,8 +798,8 @@ int wcn36xx_dxe_init(struct wcn36xx *wcn)

void wcn36xx_dxe_deinit(struct wcn36xx *wcn)
{
free_irq(wcn->tx_irq, wcn);
free_irq(wcn->rx_irq, wcn);
free_irq(wcn->pdata->tx_irq, wcn);
free_irq(wcn->pdata->rx_irq, wcn);

/* Flush any pending rx work */
flush_workqueue(wcn->wq);
Expand Down
94 changes: 45 additions & 49 deletions main.c
Expand Up @@ -18,19 +18,13 @@
#include <linux/module.h>
#include <linux/wcnss_wlan.h>
#include <linux/firmware.h>
#include <linux/platform_device.h>
#include "wcn36xx.h"

unsigned int debug_mask;
module_param(debug_mask, uint, 0644);
MODULE_PARM_DESC(debug_mask, "Debugging mask");

/*
* provide hw to module exit function
*
* FIXME: implement this properly, maybe with platform device?
*/
static struct ieee80211_hw *private_hw;

#define CHAN2G(_freq, _idx) { \
.band = IEEE80211_BAND_2GHZ, \
.center_freq = (_freq), \
Expand Down Expand Up @@ -897,7 +891,7 @@ static int wcn36xx_init_ieee80211(struct wcn36xx *wcn)

wcn->hw->queues = 4;

SET_IEEE80211_DEV(wcn->hw, wcn->dev);
SET_IEEE80211_DEV(wcn->hw, wcn->pdata->dev);

wcn->hw->sta_data_size = sizeof(struct wcn36xx_sta);
wcn->hw->vif_data_size = sizeof(struct wcn36xx_vif);
Expand All @@ -919,7 +913,7 @@ static int wcn36xx_read_mac_addresses(struct wcn36xx *wcn)
status = -1;
else
status = request_firmware(&addr_file, files[i],
wcn->dev);
wcn->pdata->dev);

if (status) {
if (i == 0) {
Expand Down Expand Up @@ -956,13 +950,12 @@ static int wcn36xx_read_mac_addresses(struct wcn36xx *wcn)

return 0;
}

static int __init wcn36xx_init(void)
static int __devinit wcn36xx_probe(struct platform_device *pdev)
{
struct ieee80211_hw *hw;
struct wcn36xx *wcn;
struct resource *wcnss_memory;
int ret;
wcn36xx_dbg(WCN36XX_DBG_MAC, "wcn36xx_probe");

hw = wcn36xx_alloc_hw();
if (!hw) {
Expand All @@ -973,14 +966,8 @@ static int __init wcn36xx_init(void)

wcn = hw->priv;
wcn->hw = hw;

wcn->dev = wcnss_wlan_get_device();
if (wcn->dev == NULL) {
wcn36xx_error("failed to get wcnss wlan device");
ret = -ENOENT;
goto out_err;
}

wcn->pdata = pdev->dev.platform_data;
platform_set_drvdata(pdev, wcn);
wcn->wq = create_workqueue("wcn36xx_wq");
if (!wcn->wq) {
wcn36xx_error("failed to allocate wq");
Expand Down Expand Up @@ -1011,62 +998,71 @@ static int __init wcn36xx_init(void)
wcn->aid = 0;
wcn->current_vif = NULL;
wcn->is_joining = false;
wcn->beacon_enable = false;

mutex_init(&wcn->pm_mutex);
mutex_init(&wcn->smd_mutex);
wcn->hw->wiphy->n_addresses = ARRAY_SIZE(wcn->addresses);
wcn->hw->wiphy->addresses = wcn->addresses;

wcnss_memory = wcnss_wlan_get_memory_map(wcn->dev);
if (wcnss_memory == NULL) {
wcn36xx_error("failed to get wcnss wlan memory map");
ret = -ENOMEM;
goto out_wq;
}

wcn->tx_irq = wcnss_wlan_get_dxe_tx_irq(wcn->dev);
wcn->rx_irq = wcnss_wlan_get_dxe_rx_irq(wcn->dev);

wcn->mmio = ioremap(wcnss_memory->start, resource_size(wcnss_memory));
if (NULL == wcn->mmio) {
wcn36xx_error("failed to map io memory");
ret = -ENOMEM;
goto out_wq;
}

private_hw = hw;
wcn->beacon_enable = false;

wcn36xx_read_mac_addresses(wcn);
SET_IEEE80211_PERM_ADDR(wcn->hw, wcn->addresses[0].addr);

ret = ieee80211_register_hw(wcn->hw);
if (ret)
goto out_unmap;
goto out_wq;

return 0;

out_unmap:
iounmap(wcn->mmio);
out_wq:
destroy_workqueue(wcn->wq);
out_err:
return ret;
}
module_init(wcn36xx_init);

static void __exit wcn36xx_exit(void)
static int __devexit wcn36xx_remove(struct platform_device *pdev)
{
struct ieee80211_hw *hw = private_hw;
struct wcn36xx *wcn = hw->priv;
struct wcn36xx *wcn = platform_get_drvdata(pdev);
struct ieee80211_hw *hw = wcn->hw;

wcn36xx_dbg(WCN36XX_DBG_MAC, "wcn36xx_remove");

mutex_destroy(&wcn->pm_mutex);
mutex_destroy(&wcn->smd_mutex);

ieee80211_unregister_hw(hw);
destroy_workqueue(wcn->wq);
iounmap(wcn->mmio);
ieee80211_free_hw(hw);
return 0;
}
static const struct platform_device_id wcn36xx_platform_id_table[] = {
{
.name = "wcn36xx",
.driver_data = 0
},
{}
};
MODULE_DEVICE_TABLE(platform, wcn36xx_platform_id_table);

static struct platform_driver wcn36xx_driver = {
.probe = wcn36xx_probe,
.remove = wcn36xx_remove,
.driver = {
.name = "wcn36xx",
.owner = THIS_MODULE,
},
.id_table = wcn36xx_platform_id_table,
};

static int __init wcn36xx_init(void)
{
platform_driver_register(&wcn36xx_driver);
return 0;
}
module_init(wcn36xx_init);

static void __exit wcn36xx_exit(void)
{
platform_driver_unregister(&wcn36xx_driver);
}
module_exit(wcn36xx_exit);

Expand Down
2 changes: 1 addition & 1 deletion smd.c
Expand Up @@ -219,7 +219,7 @@ int wcn36xx_smd_load_nv(struct wcn36xx *wcn)
int ret;
u16 fm_offset = 0;

ret = request_firmware(&nv, WLAN_NV_FILE, wcn->dev);
ret = request_firmware(&nv, WLAN_NV_FILE, wcn->pdata->dev);
if (ret) {
wcn36xx_error("Failed to load nv file %s: %d",
WLAN_NV_FILE, ret);
Expand Down
14 changes: 9 additions & 5 deletions wcn36xx.h
Expand Up @@ -99,6 +99,14 @@ struct nv_data {
int is_valid;
void *table;
};

struct wcn36xx_platform_data {
struct device *dev;
/* IRQs */
int tx_irq;
int rx_irq;
void __iomem *mmio;
};
/**
* struct wcn36xx_vif - holds VIF related fields
*
Expand Down Expand Up @@ -148,7 +156,6 @@ struct wcn36xx_dxe_ch;
struct wcn36xx {
struct ieee80211_hw *hw;
struct workqueue_struct *wq;
struct device *dev;
struct mac_address addresses[2];
struct wcn36xx_hal_mac_ssid ssid;
u16 aid;
Expand All @@ -172,14 +179,11 @@ struct wcn36xx {
u8 wlan_version[WCN36XX_HAL_VERSION_LENGTH + 1];

bool beacon_enable;
/* IRQs */
int tx_irq;
int rx_irq;
void __iomem *mmio;

/* Rates */
struct wcn36xx_hal_supported_rates supported_rates;

struct wcn36xx_platform_data *pdata;
/* SMD related */
smd_channel_t *smd_ch;
/*
Expand Down

0 comments on commit becf7a7

Please sign in to comment.