From: Rosen Penev <rosenp@gmail.com>
To: linux-wireless@vger.kernel.org
Cc: Johannes Berg <johannes@sipsolutions.net>,
yangshiji66@qq.com, ansuelsmth@gmail.com,
Rob Herring <robh@kernel.org>,
Krzysztof Kozlowski <krzk+dt@kernel.org>,
Conor Dooley <conor+dt@kernel.org>,
Thomas Bogendoerfer <tsbogend@alpha.franken.de>,
Matthias Brugger <matthias.bgg@gmail.com>,
AngeloGioacchino Del Regno
<angelogioacchino.delregno@collabora.com>,
Stanislaw Gruszka <stf_xl@wp.pl>,
devicetree@vger.kernel.org (open list:OPEN FIRMWARE AND
FLATTENED DEVICE TREE BINDINGS),
linux-kernel@vger.kernel.org (open list),
linux-mips@vger.kernel.org (open list:MIPS),
linux-arm-kernel@lists.infradead.org (moderated
list:ARM/Mediatek SoC support),
linux-mediatek@lists.infradead.org (moderated list:ARM/Mediatek
SoC support)
Subject: [PATCH 4/6] wifi: rt2x00: soc: move and modernize probe
Date: Sun, 6 Jul 2025 14:41:09 -0700 [thread overview]
Message-ID: <20250706214111.45687-5-rosenp@gmail.com> (raw)
In-Reply-To: <20250706214111.45687-1-rosenp@gmail.com>
By moving functions from rt2x00soc to rt2800soc, the driver benefits
with potentially smaller compiled size. It also becomes much easier to
remove a bunch of manual memory management and use devm.
Signed-off-by: Rosen Penev <rosenp@gmail.com>
---
.../net/wireless/ralink/rt2x00/rt2800soc.c | 67 +++++++++++-
.../net/wireless/ralink/rt2x00/rt2x00soc.c | 102 ------------------
2 files changed, 65 insertions(+), 104 deletions(-)
diff --git a/drivers/net/wireless/ralink/rt2x00/rt2800soc.c b/drivers/net/wireless/ralink/rt2x00/rt2800soc.c
index db8d01f0cdc3..e2c05ead9b25 100644
--- a/drivers/net/wireless/ralink/rt2x00/rt2800soc.c
+++ b/drivers/net/wireless/ralink/rt2x00/rt2800soc.c
@@ -18,6 +18,7 @@
#include <linux/init.h>
#include <linux/kernel.h>
#include <linux/module.h>
+#include <linux/of.h>
#include <linux/platform_device.h>
#include "rt2x00.h"
@@ -240,7 +241,69 @@ static const struct rt2x00_ops rt2800soc_ops = {
static int rt2800soc_probe(struct platform_device *pdev)
{
- return rt2x00soc_probe(pdev, &rt2800soc_ops);
+ const struct rt2x00_ops *ops = of_device_get_match_data(&pdev->dev);
+ struct rt2x00_dev *rt2x00dev;
+ struct ieee80211_hw *hw;
+ int retval;
+
+ hw = ieee80211_alloc_hw(sizeof(struct rt2x00_dev), ops->hw);
+ if (!hw) {
+ rt2x00_probe_err("Failed to allocate hardware\n");
+ return -ENOMEM;
+ }
+
+ platform_set_drvdata(pdev, hw);
+
+ rt2x00dev = hw->priv;
+ rt2x00dev->dev = &pdev->dev;
+ rt2x00dev->ops = ops;
+ rt2x00dev->hw = hw;
+ rt2x00dev->irq = platform_get_irq(pdev, 0);
+ rt2x00dev->name = pdev->dev.driver->name;
+ rt2x00dev->clk = devm_clk_get_optional(&pdev->dev, NULL);
+
+ rt2x00_set_chip_intf(rt2x00dev, RT2X00_CHIP_INTF_SOC);
+
+ rt2x00dev->csr.base = devm_platform_ioremap_resource(pdev, 0);
+ if (IS_ERR(rt2x00dev->csr.base)) {
+ retval = PTR_ERR(rt2x00dev->csr.base);
+ goto exit_free_device;
+ }
+
+ rt2x00dev->eeprom = devm_kzalloc(&pdev->dev, rt2x00dev->ops->eeprom_size, GFP_KERNEL);
+ if (!rt2x00dev->eeprom) {
+ retval = -ENOMEM;
+ goto exit_free_device;
+ }
+
+ rt2x00dev->rf = devm_kzalloc(&pdev->dev, rt2x00dev->ops->rf_size, GFP_KERNEL);
+ if (!rt2x00dev->rf) {
+ retval = -ENOMEM;
+ goto exit_free_device;
+ }
+
+ retval = rt2x00lib_probe_dev(rt2x00dev);
+ if (retval)
+ goto exit_free_device;
+
+ return 0;
+
+exit_free_device:
+ ieee80211_free_hw(hw);
+
+ return retval;
+}
+
+static void rt2800soc_remove(struct platform_device *pdev)
+{
+ struct ieee80211_hw *hw = platform_get_drvdata(pdev);
+ struct rt2x00_dev *rt2x00dev = hw->priv;
+
+ /*
+ * Free all allocated data.
+ */
+ rt2x00lib_remove_dev(rt2x00dev);
+ ieee80211_free_hw(hw);
}
static const struct of_device_id rt2880_wmac_match[] = {
@@ -255,7 +318,7 @@ static struct platform_driver rt2800soc_driver = {
.of_match_table = rt2880_wmac_match,
},
.probe = rt2800soc_probe,
- .remove = rt2x00soc_remove,
+ .remove = rt2800soc_remove,
.suspend = rt2x00soc_suspend,
.resume = rt2x00soc_resume,
};
diff --git a/drivers/net/wireless/ralink/rt2x00/rt2x00soc.c b/drivers/net/wireless/ralink/rt2x00/rt2x00soc.c
index f7f3a2340c39..9fd763f2fcde 100644
--- a/drivers/net/wireless/ralink/rt2x00/rt2x00soc.c
+++ b/drivers/net/wireless/ralink/rt2x00/rt2x00soc.c
@@ -20,108 +20,6 @@
#include "rt2x00.h"
#include "rt2x00soc.h"
-static void rt2x00soc_free_reg(struct rt2x00_dev *rt2x00dev)
-{
- kfree(rt2x00dev->rf);
- rt2x00dev->rf = NULL;
-
- kfree(rt2x00dev->eeprom);
- rt2x00dev->eeprom = NULL;
-
- iounmap(rt2x00dev->csr.base);
-}
-
-static int rt2x00soc_alloc_reg(struct rt2x00_dev *rt2x00dev)
-{
- struct platform_device *pdev = to_platform_device(rt2x00dev->dev);
- struct resource *res;
-
- res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
- if (!res)
- return -ENODEV;
-
- rt2x00dev->csr.base = ioremap(res->start, resource_size(res));
- if (!rt2x00dev->csr.base)
- return -ENOMEM;
-
- rt2x00dev->eeprom = kzalloc(rt2x00dev->ops->eeprom_size, GFP_KERNEL);
- if (!rt2x00dev->eeprom)
- goto exit;
-
- rt2x00dev->rf = kzalloc(rt2x00dev->ops->rf_size, GFP_KERNEL);
- if (!rt2x00dev->rf)
- goto exit;
-
- return 0;
-
-exit:
- rt2x00_probe_err("Failed to allocate registers\n");
- rt2x00soc_free_reg(rt2x00dev);
-
- return -ENOMEM;
-}
-
-int rt2x00soc_probe(struct platform_device *pdev, const struct rt2x00_ops *ops)
-{
- struct ieee80211_hw *hw;
- struct rt2x00_dev *rt2x00dev;
- int retval;
-
- hw = ieee80211_alloc_hw(sizeof(struct rt2x00_dev), ops->hw);
- if (!hw) {
- rt2x00_probe_err("Failed to allocate hardware\n");
- return -ENOMEM;
- }
-
- platform_set_drvdata(pdev, hw);
-
- rt2x00dev = hw->priv;
- rt2x00dev->dev = &pdev->dev;
- rt2x00dev->ops = ops;
- rt2x00dev->hw = hw;
- rt2x00dev->irq = platform_get_irq(pdev, 0);
- rt2x00dev->name = pdev->dev.driver->name;
-
- rt2x00dev->clk = clk_get(&pdev->dev, NULL);
- if (IS_ERR(rt2x00dev->clk))
- rt2x00dev->clk = NULL;
-
- rt2x00_set_chip_intf(rt2x00dev, RT2X00_CHIP_INTF_SOC);
-
- retval = rt2x00soc_alloc_reg(rt2x00dev);
- if (retval)
- goto exit_free_device;
-
- retval = rt2x00lib_probe_dev(rt2x00dev);
- if (retval)
- goto exit_free_reg;
-
- return 0;
-
-exit_free_reg:
- rt2x00soc_free_reg(rt2x00dev);
-
-exit_free_device:
- ieee80211_free_hw(hw);
-
- return retval;
-}
-EXPORT_SYMBOL_GPL(rt2x00soc_probe);
-
-void rt2x00soc_remove(struct platform_device *pdev)
-{
- struct ieee80211_hw *hw = platform_get_drvdata(pdev);
- struct rt2x00_dev *rt2x00dev = hw->priv;
-
- /*
- * Free all allocated data.
- */
- rt2x00lib_remove_dev(rt2x00dev);
- rt2x00soc_free_reg(rt2x00dev);
- ieee80211_free_hw(hw);
-}
-EXPORT_SYMBOL_GPL(rt2x00soc_remove);
-
#ifdef CONFIG_PM
int rt2x00soc_suspend(struct platform_device *pdev, pm_message_t state)
{
--
2.50.0
next prev parent reply other threads:[~2025-07-06 21:41 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-06 21:41 [PATCH 0/6] wifi: rt2x00: add OF bindings + cleanup Rosen Penev
2025-07-06 21:41 ` [PATCH 1/6] wifi: rt2x00: fix compilation Rosen Penev
2025-07-08 10:00 ` Sergio Paracuellos
2025-07-06 21:41 ` [PATCH 2/6] wifi: rt2x00: remove mod_name from platform_driver Rosen Penev
2025-07-08 10:01 ` Sergio Paracuellos
2025-07-06 21:41 ` [PATCH 3/6] wifi: rt2800soc: allow loading from OF Rosen Penev
2025-07-08 10:03 ` Sergio Paracuellos
2025-07-06 21:41 ` Rosen Penev [this message]
2025-07-08 10:07 ` [PATCH 4/6] wifi: rt2x00: soc: move and modernize probe Sergio Paracuellos
2025-07-06 21:41 ` [PATCH 5/6] dt-bindings: net: wireless: rt2800: add Rosen Penev
2025-07-06 22:29 ` Rob Herring (Arm)
2025-07-06 23:51 ` Rosen Penev
2025-07-06 21:41 ` [PATCH 6/6] MIPS: dts: ralink: mt7628a: add wifi binding Rosen Penev
2025-07-08 1:19 ` Daniel Golle
2025-07-08 1:36 ` Rosen Penev
2025-07-07 9:01 ` [PATCH 0/6] wifi: rt2x00: add OF bindings + cleanup Johannes Berg
2025-07-07 17:41 ` Rosen Penev
2025-07-07 18:36 ` Johannes Berg
2025-07-07 22:55 ` Rosen Penev
2025-07-08 6:51 ` Johannes Berg
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250706214111.45687-5-rosenp@gmail.com \
--to=rosenp@gmail.com \
--cc=angelogioacchino.delregno@collabora.com \
--cc=ansuelsmth@gmail.com \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=johannes@sipsolutions.net \
--cc=krzk+dt@kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mediatek@lists.infradead.org \
--cc=linux-mips@vger.kernel.org \
--cc=linux-wireless@vger.kernel.org \
--cc=matthias.bgg@gmail.com \
--cc=robh@kernel.org \
--cc=stf_xl@wp.pl \
--cc=tsbogend@alpha.franken.de \
--cc=yangshiji66@qq.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).