[PATCH 2/3] Move wcn36xx initialization from init to probe

Eugene Krasnikov k.eugene.e at gmail.com
Wed Aug 7 03:57:44 EDT 2013


This is there initialization should be.

Signed-off-by: Eugene Krasnikov <k.eugene.e at gmail.com>
---
 main.c | 172 +++++++++++++++++++++++++++++++++--------------------------------
 1 file changed, 88 insertions(+), 84 deletions(-)

diff --git a/main.c b/main.c
index 7657f1d..17341c2 100644
--- a/main.c
+++ b/main.c
@@ -16,7 +16,6 @@
  */
 
 #include <linux/module.h>
-#include <linux/wcnss_wlan.h>
 #include <linux/firmware.h>
 #include <linux/platform_device.h>
 #include "wcn36xx.h"
@@ -25,13 +24,6 @@ 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), \
@@ -891,6 +883,9 @@ static int wcn36xx_init_ieee80211(struct wcn36xx *wcn)
 	wcn->hw->wiphy->wowlan = &wowlan_support;
 #endif
 
+	wcn->hw->wiphy->n_addresses = ARRAY_SIZE(wcn->addresses);
+	wcn->hw->wiphy->addresses = wcn->addresses;
+
 	wcn->hw->max_listen_interval = 200;
 
 	wcn->hw->queues = 4;
@@ -954,41 +949,49 @@ static int wcn36xx_read_mac_addresses(struct wcn36xx *wcn)
 
 	return 0;
 }
-static int __devinit wcn36xx_probe(struct platform_device *pdev)
+static int wcn36xx_platform_get_resources(struct wcn36xx *wcn,
+					  struct platform_device *pdev)
 {
-	wcn36xx_dbg(WCN36XX_DBG_MAC, "platform probe");
-	return 0;
-}
-static int __devexit wcn36xx_remove(struct platform_device *pdev)
-{
-	wcn36xx_dbg(WCN36XX_DBG_MAC, "platform remove");
+	struct resource *res;
+	/* Set TX IRQ */
+	res = platform_get_resource_byname(pdev, IORESOURCE_IRQ,
+					   "wcnss_wlantx_irq");
+	if (!res) {
+		wcn36xx_error("failed to get tx_irq");
+		return -ENOENT;
+	}
+	wcn->tx_irq = res->start;
+
+	/* Set RX IRQ */
+	res = platform_get_resource_byname(pdev, IORESOURCE_IRQ,
+					   "wcnss_wlanrx_irq");
+	if (!res) {
+		wcn36xx_error("failed to get rx_irq");
+		return -ENOENT;
+	}
+	wcn->rx_irq = res->start;
+
+	/* Map the memory */
+	res = platform_get_resource_byname(pdev, IORESOURCE_MEM,
+						 "wcnss_mmio");
+	if (!res) {
+		wcn36xx_error("failed to get mmio");
+		return -ENOENT;
+	}
+	wcn->mmio = ioremap(res->start, resource_size(res));
+	if (!wcn->mmio) {
+		wcn36xx_error("failed to map io memory");
+		return -ENOMEM;
+	}
 	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)
+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, "platform probe");
 
 	hw = wcn36xx_alloc_hw();
 	if (!hw) {
@@ -996,25 +999,13 @@ static int __init wcn36xx_init(void)
 		ret = -ENOMEM;
 		goto out_err;
 	}
-
+	platform_set_drvdata(pdev, hw);
 	wcn = hw->priv;
 	wcn->hw = hw;
+	wcn->dev = &pdev->dev;
 
-	wcn->dev = wcnss_wlan_get_device();
-	if (wcn->dev == NULL) {
-		wcn36xx_error("failed to get wcnss wlan device");
-		ret = -ENOENT;
-		goto out_err;
-	}
-
-	wcn->wq = create_workqueue("wcn36xx_wq");
-	if (!wcn->wq) {
-		wcn36xx_error("failed to allocate wq");
-		ret = -ENOMEM;
-		goto out_err;
-	}
-
-	wcn36xx_init_ieee80211(wcn);
+	mutex_init(&wcn->pm_mutex);
+	mutex_init(&wcn->smd_mutex);
 
 	/* Configuring supported rates */
 	wcn->supported_rates.op_rate_mode = STA_11n;
@@ -1034,60 +1025,41 @@ static int __init wcn36xx_init(void)
 
 	wcn->supported_rates.supported_mcs_set[0] = 0xFF;
 
-	wcn->aid = 0;
-	wcn->current_vif = NULL;
-	wcn->is_joining = 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;
+	wcn36xx_read_mac_addresses(wcn);
+	SET_IEEE80211_PERM_ADDR(wcn->hw, wcn->addresses[0].addr);
 
-	wcnss_memory = wcnss_wlan_get_memory_map(wcn->dev);
-	if (wcnss_memory == NULL) {
-		wcn36xx_error("failed to get wcnss wlan memory map");
+	wcn->wq = create_workqueue("wcn36xx_wq");
+	if (!wcn->wq) {
+		wcn36xx_error("failed to allocate wq");
 		ret = -ENOMEM;
-		goto out_wq;
+		goto out_hw;
 	}
-
-	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;
+	ret = wcn36xx_platform_get_resources(wcn, pdev);
+	if (ret)
 		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);
 
+	wcn36xx_init_ieee80211(wcn);
 	ret = ieee80211_register_hw(wcn->hw);
 	if (ret)
 		goto out_unmap;
 
-	platform_driver_register(&wcn36xx_driver);
 	return 0;
 
 out_unmap:
 	iounmap(wcn->mmio);
 out_wq:
 	destroy_workqueue(wcn->wq);
+out_hw:
+	ieee80211_free_hw(hw);
 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 ieee80211_hw *hw = platform_get_drvdata(pdev);
 	struct wcn36xx *wcn = hw->priv;
+	wcn36xx_dbg(WCN36XX_DBG_MAC, "platform remove");
 
-	platform_driver_unregister(&wcn36xx_driver);
 	mutex_destroy(&wcn->pm_mutex);
 	mutex_destroy(&wcn->smd_mutex);
 
@@ -1095,6 +1067,38 @@ static void __exit wcn36xx_exit(void)
 	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);
 
-- 
1.8.2.2




More information about the wcn36xx mailing list