From patchwork Sat Aug 31 00:29:33 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergei Shtylyov X-Patchwork-Id: 2852274 Return-Path: X-Original-To: patchwork-linux-sh@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 204019F2F4 for ; Sat, 31 Aug 2013 00:29:37 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id F39E020462 for ; Sat, 31 Aug 2013 00:29:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id DACFA20459 for ; Sat, 31 Aug 2013 00:29:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754969Ab3HaA3e (ORCPT ); Fri, 30 Aug 2013 20:29:34 -0400 Received: from mail-la0-f54.google.com ([209.85.215.54]:51012 "EHLO mail-la0-f54.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752905Ab3HaA3d (ORCPT ); Fri, 30 Aug 2013 20:29:33 -0400 Received: by mail-la0-f54.google.com with SMTP id ea20so2093872lab.27 for ; Fri, 30 Aug 2013 17:29:31 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:to:subject:cc:from:organization:date :mime-version:content-type:content-transfer-encoding:message-id; bh=J0kPGlaeQWZGHWaLS05xZVchl7GeByWDuaPuGaugfyI=; b=EOQwlPlcL3Qivwrt0TVqc6rTNAV1JDVRdyIP1hLEocQa8l/9fHCSNAWkQDTnmitPsY 0Lxs7MEwVPQNtBYxKjcgqlLYTNyoBoGx5dSrl3Tihej+LwQ0P4IbY+5kgOrnBD7N5IrJ dq9DdSs9J6UZtRcDzopKS/41kArx/SJowyGi2LmRCWbGxY+8vjvJi8tiqQnqdol4IcrL llX5TUiB6GgtTdQwlKPWXwlsnOiDoZgxRk4a1G7RyNzKP4GKS+q5HZymyBdkqiFDPI2U shbzpjE0u0Cig/P3WmWOlhu2nsfxlLmW+Yuwr3kOr7Mt2PWxMUsrdJPckVU0dUjbVejN B/+w== X-Gm-Message-State: ALoCoQmNADIfjAzYszPqawSTUSHHgrwrjVWUPVAOxAeSifOGEiSjzR+FM4Id+RVBCTY1sMqEGsiy X-Received: by 10.152.6.97 with SMTP id z1mr9998552laz.26.1377908971868; Fri, 30 Aug 2013 17:29:31 -0700 (PDT) Received: from wasted.dev.rtsoft.ru (ppp91-76-94-226.pppoe.mtu-net.ru. [91.76.94.226]) by mx.google.com with ESMTPSA id n15sm232890laa.2.1969.12.31.16.00.00 (version=TLSv1 cipher=RC4-SHA bits=128/128); Fri, 30 Aug 2013 17:29:31 -0700 (PDT) To: netdev@vger.kernel.org, rob.herring@calxeda.com, pawel.moll@arm.com, mark.rutland@arm.com, swarren@wwwdotorg.org, ian.campbell@citrix.com, grant.likely@linaro.org, devicetree@vger.kernel.org Subject: [PATCH 2/2] sh_eth: add device tree support Cc: nobuhiro.iwamatsu.yj@renesas.com, linux-sh@vger.kernel.org, rob@landley.net, linux-doc@vger.kernel.org From: Sergei Shtylyov Organization: Cogent Embedded Date: Sat, 31 Aug 2013 04:29:33 +0400 MIME-Version: 1.0 Message-Id: <201308310429.34856.sergei.shtylyov@cogentembedded.com> Sender: linux-sh-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-sh@vger.kernel.org X-Spam-Status: No, score=-9.0 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham 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 Add support of the device tree probing for the Renesas SH-Mobile SoCs. This work is loosely based on an original patch by Nobuhiro Iwamatsu . Signed-off-by: Sergei Shtylyov --- This patch is against Dave's 'net-next.git' repo. Documentation/devicetree/bindings/net/sh_eth.txt | 40 +++++++++++++ drivers/net/ethernet/renesas/sh_eth.c | 66 ++++++++++++++++++++++- 2 files changed, 105 insertions(+), 1 deletion(-) -- To unsubscribe from this list: send the line "unsubscribe linux-sh" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Index: net-next/Documentation/devicetree/bindings/net/sh_eth.txt =================================================================== --- /dev/null +++ net-next/Documentation/devicetree/bindings/net/sh_eth.txt @@ -0,0 +1,40 @@ +* Renesas Electronics SH EtherMAC + +This file provides information on what the device node for the SH EtherMAC +interface contains. + +Required properties: +- compatible: "renesas,gether-r8a7740" if the device is a part of R8A7740 SoC. + "renesas,ether-r8a7779" if the device is a part of R8A7778/9 SoCs. + "renesas,ether-r8a7790" if the device is a part of R8A7790/1 SoCs. +- reg: offset and length of the register set for the device; if the device has + TSU registers, you need to specify two register sets here. +- interrupt-parent: the phandle for the interrupt controller that services + interrupts for this device. +- interrupts: interrupt mapping for the interrupt source. +- phy-mode: string, operation mode of the PHY interface (a string that + of_get_phy_mode() can understand). +- phy-handle: phandle of the PHY device. + +Optional properties: +- local-mac-address: 6 bytes, MAC address. +- renesas,no-ether-link: specify when a board does not provide a proper LINK + signal. +- renesas,ether-link-active-low: specify when the LINK signal is active-low. + +Example (Armadillo800EVA board): + + ethernet@e9a00000 { + compatible = "renesas,gether-r8a7740"; + reg = <0xe9a00000 0x800>, <0xe9a01800 0x800>; + interrupt-parent = <&gic>; + interrupts = <0 142 0x4>; + phy-mode = "mii"; + phy-handle = <&phy0>; + #address-cells = <1>; + #size-cells = <0>; + + phy0: ethernet-phy@0 { + reg = <0>; + }; + }; Index: net-next/drivers/net/ethernet/renesas/sh_eth.c =================================================================== --- net-next.orig/drivers/net/ethernet/renesas/sh_eth.c +++ net-next/drivers/net/ethernet/renesas/sh_eth.c @@ -32,6 +32,9 @@ #include #include #include +#include +#include +#include #include #include #include @@ -2600,6 +2603,52 @@ static const struct net_device_ops sh_et .ndo_change_mtu = eth_change_mtu, }; +#ifdef CONFIG_OF +static struct sh_eth_plat_data *sh_eth_parse_dt(struct device *dev) +{ + struct device_node *np = dev->of_node; + struct sh_eth_plat_data *pdata; + struct device_node *phy; + const char *mac_addr; + + pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL); + if (!pdata) + return NULL; + + pdata->phy_interface = of_get_phy_mode(np); + + phy = of_parse_phandle(np, "phy-handle", 0); + if (!phy || of_property_read_u32(phy, "reg", &pdata->phy)) { + devm_kfree(dev, pdata); + return NULL; + } + + mac_addr = of_get_mac_address(np); + if (mac_addr) + memcpy(pdata->mac_addr, mac_addr, ETH_ALEN); + + pdata->no_ether_link = + of_property_read_bool(np, "renesas,no-ether-link"); + pdata->ether_link_active_low = + of_property_read_bool(np, "renesas,ether-link-active-low"); + + return pdata; +} + +static const struct of_device_id sh_eth_match_table[] = { + { .compatible = "renesas,gether-r8a7740", .data = &r8a7740_data }, + { .compatible = "renesas,ether-r8a7779", .data = &r8a777x_data }, + { .compatible = "renesas,ether-r8a7790", .data = &r8a7790_data }, + { } +}; +MODULE_DEVICE_TABLE(of, sh_eth_match_table); +#else +static inline struct sh_eth_plat_data *sh_eth_parse_dt(struct device *dev) +{ + return NULL; +} +#endif + static int sh_eth_drv_probe(struct platform_device *pdev) { int ret, devno = 0; @@ -2653,6 +2702,8 @@ static int sh_eth_drv_probe(struct platf pm_runtime_enable(&pdev->dev); pm_runtime_resume(&pdev->dev); + if (pdev->dev.of_node) + pd = sh_eth_parse_dt(&pdev->dev); if (!pd) { dev_err(&pdev->dev, "no platform data\n"); ret = -EINVAL; @@ -2668,7 +2719,19 @@ static int sh_eth_drv_probe(struct platf mdp->ether_link_active_low = pd->ether_link_active_low; /* set cpu data */ - mdp->cd = (struct sh_eth_cpu_data *)id->driver_data; + if (id) { + mdp->cd = (struct sh_eth_cpu_data *)id->driver_data; + } else { + const struct of_device_id *match; + + match = of_match_device(of_match_ptr(sh_eth_match_table), + &pdev->dev); + if (!match) { + ret = -EINVAL; + goto out_release; + } + mdp->cd = (struct sh_eth_cpu_data *)match->data; + } mdp->reg_offset = sh_eth_get_register_offset(mdp->cd->register_type); sh_eth_set_default_cpu_data(mdp->cd); @@ -2809,6 +2872,7 @@ static struct platform_driver sh_eth_dri .driver = { .name = CARDNAME, .pm = SH_ETH_PM_OPS, + .of_match_table = of_match_ptr(sh_eth_match_table), }, };