From patchwork Sun May 3 22:14:11 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joachim Eastwood X-Patchwork-Id: 6322331 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id CEC939F32B for ; Sun, 3 May 2015 22:17:14 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id CDE6520384 for ; Sun, 3 May 2015 22:17:13 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id C752920382 for ; Sun, 3 May 2015 22:17:12 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1Yp2AA-0002Ai-32; Sun, 03 May 2015 22:15:02 +0000 Received: from mail-la0-x22e.google.com ([2a00:1450:4010:c03::22e]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1Yp2A7-00029G-7Z for linux-arm-kernel@lists.infradead.org; Sun, 03 May 2015 22:15:00 +0000 Received: by lagv1 with SMTP id v1so93300244lag.3 for ; Sun, 03 May 2015 15:14:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=1bNmVI42bkrpajptlJYgs43trDZ5HyT8rHL4fNSu6oM=; b=ivrUUrWncQarU2hWl0Wh6QS0HOq1+EwD9EJ+KJ4lGnE74XB/QjvfTl8RORmFa7k1EC LROvk4jhNBhqPB08hWTBX+WSrJw+ckKuM4lDnUg+x6cUXh45FPjKsCMTw/9MYC+45X3e GQfXC/ezR8OI1kgcW/fSwFS3cJUcsPV9IroAQu2OF5Pn6AtZIYoN9VzJcseOlwzM36k/ lDnf46davowbWUa22ErVT0keKZyHiMzNzSD7AHYkgVfpGRS3H2radERDFYguh7zv8ZXW haIGM2T2rKCKR5jTQ3EeM4xYqhjgonSi4XH9Mom0vNa4YVvnmglTpKhFD24u5NXY/49K l0jA== X-Received: by 10.112.129.132 with SMTP id nw4mr17495000lbb.122.1430691276661; Sun, 03 May 2015 15:14:36 -0700 (PDT) Received: from localhost.localdomain ([90.149.48.183]) by mx.google.com with ESMTPSA id df8sm2952091lac.3.2015.05.03.15.14.35 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sun, 03 May 2015 15:14:36 -0700 (PDT) From: Joachim Eastwood To: arnd@arndb.de Subject: Re: [PATCH 1/2] stmac: add dwmac glue for NXP 18xx/43xx family Date: Mon, 4 May 2015 00:14:11 +0200 Message-Id: <1430691251-28119-1-git-send-email-manabian@gmail.com> X-Mailer: git-send-email 1.8.0 In-Reply-To: <3200125.o3jqXuyPfG@wuerfel> References: <3200125.o3jqXuyPfG@wuerfel> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20150503_151459_463592_F40BA47D X-CRM114-Status: GOOD ( 20.64 ) X-Spam-Score: -0.8 (/) Cc: peppe.cavallaro@st.com, manabian@gmail.com, davem@davemloft.net, linux-arm-kernel@lists.infradead.org, netdev@vger.kernel.org X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.1 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_MED, T_DKIM_INVALID, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP >On Saturday 02 May 2015 18:40:41 Joachim Eastwood wrote: >> --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c >> +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c >> @@ -36,6 +36,7 @@ static const struct of_device_id stmmac_dt_ids[] = { >> { .compatible = "rockchip,rk3288-gmac", .data = &rk3288_gmac_data}, >> { .compatible = "amlogic,meson6-dwmac", .data = &meson6_dwmac_data}, >> { .compatible = "allwinner,sun7i-a20-gmac", .data = &sun7i_gmac_data}, >> + { .compatible = "nxp,lpc1850-dwmac", .data = &lpc18xx_dwmac_data}, >> { .compatible = "st,stih415-dwmac", .data = &stih4xx_dwmac_data}, >> { .compatible = "st,stih416-dwmac", .data = &stih4xx_dwmac_data}, >> { .compatible = "st,stid127-dwmac", .data = &stid127_dwmac_data}, >> diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.h b/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.h >> > >Any chance you could turn this around and do the probing in the normal >order, with a platform driver that registers to your compatible string >and calls into a common base module? > >Unfortunately, something went wrong when we first started adding platform >specific hacks to the driver. I tried to fix it up back then, and IIRC >it was agreed that it should be changed but my patches for some reason >missed out on getting merged and the mistake propagated afterwards. > >It should be fairly straightforward to split the probe function >into two and export a function that takes a device and a stmmac_of_data >pointer as arguments, and declare a module_platform_driver in your >code. How about something like the patch below. All it does is to play a little trick with the of_match_device in the dt config function and export the probe/remove/pm stuff for the driver. The dwmac-lpc18xx would then become something like this: static const struct stmmac_of_data lpc18xx_dwmac_data = { .has_gmac = 1, .setup = lpc18xx_dwmac_setup, .init = lpc18xx_dwmac_init, }; static const struct of_device_id lpc18xx_dwmac_match[] = { { .compatible = "nxp,lpc1850-dwmac", .data = &lpc18xx_dwmac_data }, { } }; MODULE_DEVICE_TABLE(of, lpc18xx_dwmac_match); static struct platform_driver lpc18xx_dwmac_driver = { .probe = stmmac_pltfr_probe, .remove = stmmac_pltfr_remove, .driver = { .name = "lpc18xx-dwmac", .pm = &stmmac_pltfr_pm_ops, .of_match_table = lpc18xx_dwmac_match, }, }; module_platform_driver(lpc18xx_dwmac_driver); All though this seem to work, stmmac_platform.c could benefit from some refactoring. But this patch and then fixing the other DT users could be a first step. regards, Joachim Eastwood --- drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c | 14 +++++++++----- drivers/net/ethernet/stmicro/stmmac/stmmac_platform.h | 4 ++++ 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c index ccfa4fa02f6a..a7d8ae081b24 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c @@ -129,11 +129,12 @@ static int stmmac_probe_config_dt(struct platform_device *pdev, struct device_node *np = pdev->dev.of_node; struct stmmac_dma_cfg *dma_cfg; const struct of_device_id *device; + struct device *dev = &pdev->dev; if (!np) return -ENODEV; - device = of_match_device(stmmac_dt_ids, &pdev->dev); + device = of_match_device(dev->driver->of_match_table, dev); if (!device) return -ENODEV; @@ -264,7 +265,7 @@ static int stmmac_probe_config_dt(struct platform_device *pdev, * the necessary platform resources, invoke custom helper (if required) and * invoke the main probe function. */ -static int stmmac_pltfr_probe(struct platform_device *pdev) +int stmmac_pltfr_probe(struct platform_device *pdev) { int ret = 0; struct resource *res; @@ -370,6 +371,7 @@ static int stmmac_pltfr_probe(struct platform_device *pdev) return 0; } +EXPORT_SYMBOL_GPL(stmmac_pltfr_probe); /** * stmmac_pltfr_remove @@ -377,7 +379,7 @@ static int stmmac_pltfr_probe(struct platform_device *pdev) * Description: this function calls the main to free the net resources * and calls the platforms hook and release the resources (e.g. mem). */ -static int stmmac_pltfr_remove(struct platform_device *pdev) +int stmmac_pltfr_remove(struct platform_device *pdev) { struct net_device *ndev = platform_get_drvdata(pdev); struct stmmac_priv *priv = netdev_priv(ndev); @@ -391,6 +393,7 @@ static int stmmac_pltfr_remove(struct platform_device *pdev) return ret; } +EXPORT_SYMBOL_GPL(stmmac_pltfr_remove); #ifdef CONFIG_PM_SLEEP /** @@ -434,8 +437,9 @@ static int stmmac_pltfr_resume(struct device *dev) } #endif /* CONFIG_PM_SLEEP */ -static SIMPLE_DEV_PM_OPS(stmmac_pltfr_pm_ops, - stmmac_pltfr_suspend, stmmac_pltfr_resume); +SIMPLE_DEV_PM_OPS(stmmac_pltfr_pm_ops, stmmac_pltfr_suspend, + stmmac_pltfr_resume); +EXPORT_SYMBOL_GPL(stmmac_pltfr_pm_ops); static struct platform_driver stmmac_pltfr_driver = { .probe = stmmac_pltfr_probe, diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.h b/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.h index 59fe8fb46a48..5be0b101bffd 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.h +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.h @@ -19,6 +19,10 @@ #ifndef __STMMAC_PLATFORM_H__ #define __STMMAC_PLATFORM_H__ +int stmmac_pltfr_probe(struct platform_device *pdev); +int stmmac_pltfr_remove(struct platform_device *pdev); +extern const struct dev_pm_ops stmmac_pltfr_pm_ops; + extern const struct stmmac_of_data lpc18xx_dwmac_data; extern const struct stmmac_of_data meson6_dwmac_data; extern const struct stmmac_of_data sun7i_gmac_data;