wlcore: Refactor probe

Move most of the device-specific probe functionality into setup(), a new
op. By doing this, wlcore_probe will be the first to request a firmware
from userspace, making it easier to load the NVS file asynchronously.

Signed-off-by: Ido Yariv <ido@wizery.com>
Signed-off-by: Luciano Coelho <luca@coelho.fi>
This commit is contained in:
Ido Yariv 2012-09-02 12:29:27 +03:00 committed by Luciano Coelho
parent d556023895
commit 3992eb2bf2
4 changed files with 83 additions and 48 deletions

View File

@ -1589,7 +1589,10 @@ static int wl12xx_set_key(struct wl1271 *wl, enum set_key_cmd cmd,
return wlcore_set_key(wl, cmd, vif, sta, key_conf); return wlcore_set_key(wl, cmd, vif, sta, key_conf);
} }
static int wl12xx_setup(struct wl1271 *wl);
static struct wlcore_ops wl12xx_ops = { static struct wlcore_ops wl12xx_ops = {
.setup = wl12xx_setup,
.identify_chip = wl12xx_identify_chip, .identify_chip = wl12xx_identify_chip,
.identify_fw = wl12xx_identify_fw, .identify_fw = wl12xx_identify_fw,
.boot = wl12xx_boot, .boot = wl12xx_boot,
@ -1630,23 +1633,11 @@ static struct ieee80211_sta_ht_cap wl12xx_ht_cap = {
}, },
}; };
static int __devinit wl12xx_probe(struct platform_device *pdev) static int wl12xx_setup(struct wl1271 *wl)
{ {
struct wl12xx_platform_data *pdata = pdev->dev.platform_data; struct wl12xx_priv *priv = wl->priv;
struct wl1271 *wl; struct wl12xx_platform_data *pdata = wl->pdev->dev.platform_data;
struct ieee80211_hw *hw;
struct wl12xx_priv *priv;
hw = wlcore_alloc_hw(sizeof(*priv), WL12XX_AGGR_BUFFER_SIZE);
if (IS_ERR(hw)) {
wl1271_error("can't allocate hw");
return PTR_ERR(hw);
}
wl = hw->priv;
priv = wl->priv;
wl->ops = &wl12xx_ops;
wl->ptable = wl12xx_ptable;
wl->rtable = wl12xx_rtable; wl->rtable = wl12xx_rtable;
wl->num_tx_desc = WL12XX_NUM_TX_DESCRIPTORS; wl->num_tx_desc = WL12XX_NUM_TX_DESCRIPTORS;
wl->num_rx_desc = WL12XX_NUM_RX_DESCRIPTORS; wl->num_rx_desc = WL12XX_NUM_RX_DESCRIPTORS;
@ -1702,7 +1693,36 @@ static int __devinit wl12xx_probe(struct platform_device *pdev)
wl1271_error("Invalid tcxo parameter %s", tcxo_param); wl1271_error("Invalid tcxo parameter %s", tcxo_param);
} }
return wlcore_probe(wl, pdev); return 0;
}
static int __devinit wl12xx_probe(struct platform_device *pdev)
{
struct wl1271 *wl;
struct ieee80211_hw *hw;
int ret;
hw = wlcore_alloc_hw(sizeof(struct wl12xx_priv),
WL12XX_AGGR_BUFFER_SIZE);
if (IS_ERR(hw)) {
wl1271_error("can't allocate hw");
ret = PTR_ERR(hw);
goto out;
}
wl = hw->priv;
wl->ops = &wl12xx_ops;
wl->ptable = wl12xx_ptable;
ret = wlcore_probe(wl, pdev);
if (ret)
goto out_free;
return ret;
out_free:
wlcore_free_hw(wl);
out:
return ret;
} }
static const struct platform_device_id wl12xx_id_table[] __devinitconst = { static const struct platform_device_id wl12xx_id_table[] __devinitconst = {

View File

@ -1304,7 +1304,10 @@ static u32 wl18xx_pre_pkt_send(struct wl1271 *wl,
return buf_offset; return buf_offset;
} }
static int wl18xx_setup(struct wl1271 *wl);
static struct wlcore_ops wl18xx_ops = { static struct wlcore_ops wl18xx_ops = {
.setup = wl18xx_setup,
.identify_chip = wl18xx_identify_chip, .identify_chip = wl18xx_identify_chip,
.boot = wl18xx_boot, .boot = wl18xx_boot,
.plt_init = wl18xx_plt_init, .plt_init = wl18xx_plt_init,
@ -1385,24 +1388,11 @@ static struct ieee80211_sta_ht_cap wl18xx_mimo_ht_cap_2ghz = {
}, },
}; };
static int __devinit wl18xx_probe(struct platform_device *pdev) static int wl18xx_setup(struct wl1271 *wl)
{ {
struct wl1271 *wl; struct wl18xx_priv *priv = wl->priv;
struct ieee80211_hw *hw;
struct wl18xx_priv *priv;
int ret; int ret;
hw = wlcore_alloc_hw(sizeof(*priv), WL18XX_AGGR_BUFFER_SIZE);
if (IS_ERR(hw)) {
wl1271_error("can't allocate hw");
ret = PTR_ERR(hw);
goto out;
}
wl = hw->priv;
priv = wl->priv;
wl->ops = &wl18xx_ops;
wl->ptable = wl18xx_ptable;
wl->rtable = wl18xx_rtable; wl->rtable = wl18xx_rtable;
wl->num_tx_desc = WL18XX_NUM_TX_DESCRIPTORS; wl->num_tx_desc = WL18XX_NUM_TX_DESCRIPTORS;
wl->num_rx_desc = WL18XX_NUM_TX_DESCRIPTORS; wl->num_rx_desc = WL18XX_NUM_TX_DESCRIPTORS;
@ -1417,9 +1407,9 @@ static int __devinit wl18xx_probe(struct platform_device *pdev)
if (num_rx_desc_param != -1) if (num_rx_desc_param != -1)
wl->num_rx_desc = num_rx_desc_param; wl->num_rx_desc = num_rx_desc_param;
ret = wl18xx_conf_init(wl, &pdev->dev); ret = wl18xx_conf_init(wl, wl->dev);
if (ret < 0) if (ret < 0)
goto out_free; return ret;
/* If the module param is set, update it in conf */ /* If the module param is set, update it in conf */
if (board_type_param) { if (board_type_param) {
@ -1436,16 +1426,14 @@ static int __devinit wl18xx_probe(struct platform_device *pdev)
} else { } else {
wl1271_error("invalid board type '%s'", wl1271_error("invalid board type '%s'",
board_type_param); board_type_param);
ret = -EINVAL; return -EINVAL;
goto out_free;
} }
} }
if (priv->conf.phy.board_type >= NUM_BOARD_TYPES) { if (priv->conf.phy.board_type >= NUM_BOARD_TYPES) {
wl1271_error("invalid board type '%d'", wl1271_error("invalid board type '%d'",
priv->conf.phy.board_type); priv->conf.phy.board_type);
ret = -EINVAL; return -EINVAL;
goto out_free;
} }
if (low_band_component_param != -1) if (low_band_component_param != -1)
@ -1477,8 +1465,7 @@ static int __devinit wl18xx_probe(struct platform_device *pdev)
priv->conf.ht.mode = HT_MODE_SISO20; priv->conf.ht.mode = HT_MODE_SISO20;
else { else {
wl1271_error("invalid ht_mode '%s'", ht_mode_param); wl1271_error("invalid ht_mode '%s'", ht_mode_param);
ret = -EINVAL; return -EINVAL;
goto out_free;
} }
} }
@ -1517,7 +1504,31 @@ static int __devinit wl18xx_probe(struct platform_device *pdev)
/* Enable 11a Band only if we have 5G antennas */ /* Enable 11a Band only if we have 5G antennas */
wl->enable_11a = (priv->conf.phy.number_of_assembled_ant5 != 0); wl->enable_11a = (priv->conf.phy.number_of_assembled_ant5 != 0);
return wlcore_probe(wl, pdev); return 0;
}
static int __devinit wl18xx_probe(struct platform_device *pdev)
{
struct wl1271 *wl;
struct ieee80211_hw *hw;
int ret;
hw = wlcore_alloc_hw(sizeof(struct wl18xx_priv),
WL18XX_AGGR_BUFFER_SIZE);
if (IS_ERR(hw)) {
wl1271_error("can't allocate hw");
ret = PTR_ERR(hw);
goto out;
}
wl = hw->priv;
wl->ops = &wl18xx_ops;
wl->ptable = wl18xx_ptable;
ret = wlcore_probe(wl, pdev);
if (ret)
goto out_free;
return ret;
out_free: out_free:
wlcore_free_hw(wl); wlcore_free_hw(wl);

View File

@ -5547,9 +5547,17 @@ int __devinit wlcore_probe(struct wl1271 *wl, struct platform_device *pdev)
if (!wl->ops || !wl->ptable) { if (!wl->ops || !wl->ptable) {
ret = -EINVAL; ret = -EINVAL;
goto out_free_hw; goto out;
} }
wl->dev = &pdev->dev;
wl->pdev = pdev;
platform_set_drvdata(pdev, wl);
ret = wl->ops->setup(wl);
if (ret < 0)
goto out;
BUG_ON(wl->num_tx_desc > WLCORE_MAX_TX_DESCRIPTORS); BUG_ON(wl->num_tx_desc > WLCORE_MAX_TX_DESCRIPTORS);
/* adjust some runtime configuration parameters */ /* adjust some runtime configuration parameters */
@ -5558,11 +5566,8 @@ int __devinit wlcore_probe(struct wl1271 *wl, struct platform_device *pdev)
wl->irq = platform_get_irq(pdev, 0); wl->irq = platform_get_irq(pdev, 0);
wl->platform_quirks = pdata->platform_quirks; wl->platform_quirks = pdata->platform_quirks;
wl->set_power = pdata->set_power; wl->set_power = pdata->set_power;
wl->dev = &pdev->dev;
wl->if_ops = pdata->ops; wl->if_ops = pdata->ops;
platform_set_drvdata(pdev, wl);
if (wl->platform_quirks & WL12XX_PLATFORM_QUIRK_EDGE_IRQ) if (wl->platform_quirks & WL12XX_PLATFORM_QUIRK_EDGE_IRQ)
irqflags = IRQF_TRIGGER_RISING; irqflags = IRQF_TRIGGER_RISING;
else else
@ -5573,7 +5578,7 @@ int __devinit wlcore_probe(struct wl1271 *wl, struct platform_device *pdev)
pdev->name, wl); pdev->name, wl);
if (ret < 0) { if (ret < 0) {
wl1271_error("request_irq() failed: %d", ret); wl1271_error("request_irq() failed: %d", ret);
goto out_free_hw; goto out;
} }
#ifdef CONFIG_PM #ifdef CONFIG_PM
@ -5646,9 +5651,6 @@ int __devinit wlcore_probe(struct wl1271 *wl, struct platform_device *pdev)
out_irq: out_irq:
free_irq(wl->irq, wl); free_irq(wl->irq, wl);
out_free_hw:
wlcore_free_hw(wl);
out: out:
return ret; return ret;
} }

View File

@ -43,6 +43,7 @@ enum wl_rx_buf_align;
struct wl1271_rx_descriptor; struct wl1271_rx_descriptor;
struct wlcore_ops { struct wlcore_ops {
int (*setup)(struct wl1271 *wl);
int (*identify_chip)(struct wl1271 *wl); int (*identify_chip)(struct wl1271 *wl);
int (*identify_fw)(struct wl1271 *wl); int (*identify_fw)(struct wl1271 *wl);
int (*boot)(struct wl1271 *wl); int (*boot)(struct wl1271 *wl);
@ -149,6 +150,7 @@ struct wl1271 {
bool mac80211_registered; bool mac80211_registered;
struct device *dev; struct device *dev;
struct platform_device *pdev;
void *if_priv; void *if_priv;