From patchwork Sun Dec 16 13:54:26 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bastian Hecht X-Patchwork-Id: 1884791 Return-Path: X-Original-To: patchwork-linux-sh@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork1.kernel.org (Postfix) with ESMTP id 6ADFC40D7F for ; Sun, 16 Dec 2012 13:54:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753076Ab2LPNy1 (ORCPT ); Sun, 16 Dec 2012 08:54:27 -0500 Received: from mail-ee0-f46.google.com ([74.125.83.46]:47199 "EHLO mail-ee0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753029Ab2LPNyZ (ORCPT ); Sun, 16 Dec 2012 08:54:25 -0500 Received: by mail-ee0-f46.google.com with SMTP id e53so2750286eek.19 for ; Sun, 16 Dec 2012 05:54:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; bh=5vQ9qC8xlNFNLV9RSoIjMUOb4w0pUvclV6Src+o1nJM=; b=mw4S/SMNx3E/OfIwyojt3v0+RJlSpNQgqMtJDyM196GgNNqtD1llZ7k1W2VPbSK84M 4FENJJYFAv+cQRwMErd32zFQfe6yOYaDkAUZX1+MtxMG3jPWymHGun1d6fCkytWVi+DF CmHsrlZLJAutRjOmz5weg40XvIPx1GWCp3kXO0WusYpwzIbvISnobZdPie8RH1wWDLXQ TR4cIdyEXitL90YN+shgsehX6u3+Qz2xCPqpPRaBBwmoPwFwc59HwUzkmR4mVsteJMIx cS+ZY85Z1AY428sbLUSmc/XV1uafS9pTkZl0on4IaWQ1kJQP1gAA5S9kiSnDFWDCV28i vOiA== Received: by 10.14.213.134 with SMTP id a6mr32435248eep.45.1355666064473; Sun, 16 Dec 2012 05:54:24 -0800 (PST) Received: from localhost.localdomain (p4FD25859.dip.t-dialin.net. [79.210.88.89]) by mx.google.com with ESMTPS id r1sm22637215eeo.2.2012.12.16.05.54.23 (version=TLSv1/SSLv3 cipher=OTHER); Sun, 16 Dec 2012 05:54:23 -0800 (PST) From: Bastian Hecht To: linux-sh@vger.kernel.org Cc: Simon Horman , Magnus Damm , Bastian Hecht Subject: [PATCH 2/2] net: sh_eth: Add Device Tree support Date: Sun, 16 Dec 2012 14:54:26 +0100 Message-Id: <1355666066-25649-3-git-send-email-hechtb+renesas@gmail.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1355666066-25649-1-git-send-email-hechtb+renesas@gmail.com> References: <1355666066-25649-1-git-send-email-hechtb+renesas@gmail.com> Sender: linux-sh-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-sh@vger.kernel.org We add support for Device Tree probing in order to support the Armadillo DT testcase. Until we figure out what portions of the platform config are board dependent and should be used as OF properties and what portions are only SoC related and can be stored in the driver itself, I have attached all platform configurations to the OF match in the driver. Not-yet-signed-off-by: Bastian Hecht --- drivers/net/ethernet/renesas/sh_eth.c | 72 ++++++++++++++++++++++++++++++++- 1 file changed, 71 insertions(+), 1 deletion(-) diff --git a/drivers/net/ethernet/renesas/sh_eth.c b/drivers/net/ethernet/renesas/sh_eth.c index c8bfea0..1fbbf69 100644 --- a/drivers/net/ethernet/renesas/sh_eth.c +++ b/drivers/net/ethernet/renesas/sh_eth.c @@ -31,6 +31,8 @@ #include #include #include +#include +#include #include #include #include @@ -2347,6 +2349,63 @@ static const struct net_device_ops sh_eth_netdev_ops = { .ndo_change_mtu = eth_change_mtu, }; +#ifdef CONFIG_OF +struct sh_eth_soc_config { + int phy; + phy_interface_t phy_interface; + unsigned edmac_endian:1; + unsigned register_type:2; +}; + +static struct sh_eth_soc_config sh_eth_r8a7740_config = { + .phy = 0x00, + .phy_interface = PHY_INTERFACE_MODE_MII, + .edmac_endian = EDMAC_LITTLE_ENDIAN, + .register_type = SH_ETH_REG_GIGABIT, +}; + +static const struct of_device_id sh_eth_match[] = { + { .compatible = "renesas,sh-eth-r8a7740", + .data = &sh_eth_r8a7740_config }, + {}, +}; +MODULE_DEVICE_TABLE(of, sh_eth_match); + +static struct sh_eth_plat_data *sh_eth_parse_dt(struct device *dev) +{ + const struct of_device_id *match; + struct sh_eth_plat_data *pd; + struct sh_eth_soc_config *config; + + match = of_match_device(sh_eth_match, dev); + if (match) + config = (struct sh_eth_soc_config *)match->data; + else { + dev_err(dev, "%s: no OF configuration attached\n", __func__); + return NULL; + } + + pd = devm_kzalloc(dev, sizeof(struct sh_eth_plat_data), GFP_KERNEL); + if (!pd) { + dev_err(dev, "failed to allocate setup data\n"); + return NULL; + } + + pd->phy = config->phy; + pd->phy_interface = config->phy_interface; + pd->edmac_endian = config->edmac_endian; + pd->register_type = config->register_type; + + return pd; +} +#else +static struct sh_eth_plat_data *sh_eth_parse_dt(struct device *dev) +{ + return NULL; +} +#define sh_eth_match NULL +#endif + static int sh_eth_drv_probe(struct platform_device *pdev) { int ret, devno = 0; @@ -2403,7 +2462,17 @@ static int sh_eth_drv_probe(struct platform_device *pdev) pm_runtime_enable(&pdev->dev); pm_runtime_resume(&pdev->dev); - pd = (struct sh_eth_plat_data *)(pdev->dev.platform_data); + if (pdev->dev.of_node) + pd = sh_eth_parse_dt(&pdev->dev); + else + pd = pdev->dev.platform_data; + + if (!pd) { + dev_err(&pdev->dev, "failed to obtain device info\n"); + ret = -ENXIO; + goto out_release; + } + /* get PHY ID */ mdp->phy_id = pd->phy; mdp->phy_interface = pd->phy_interface; @@ -2533,6 +2602,7 @@ static struct platform_driver sh_eth_driver = { .driver = { .name = CARDNAME, .pm = &sh_eth_dev_pm_ops, + .of_match_table = sh_eth_match, }, };