Skip to content

Commit b356e97

Browse files
Sergei Shtylyovdavem330
authored andcommitted
sh_eth: add device tree support
Add support of the device tree probing for the Renesas SH-Mobile SoCs documenting the device tree binding as necessary. This work is loosely based on the original patch by Nobuhiro Iwamatsu <nobuhiro.iwamatsu.yj@renesas.com>. Signed-off-by: Sergei Shtylyov <sergei.shtylyov@cogentembedded.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent e8f08ee commit b356e97

File tree

2 files changed

+121
-3
lines changed

2 files changed

+121
-3
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
* Renesas Electronics SH EtherMAC
2+
3+
This file provides information on what the device node for the SH EtherMAC
4+
interface contains.
5+
6+
Required properties:
7+
- compatible: "renesas,gether-r8a7740" if the device is a part of R8A7740 SoC.
8+
"renesas,ether-r8a7778" if the device is a part of R8A7778 SoC.
9+
"renesas,ether-r8a7779" if the device is a part of R8A7779 SoC.
10+
"renesas,ether-r8a7790" if the device is a part of R8A7790 SoC.
11+
"renesas,ether-r8a7791" if the device is a part of R8A7791 SoC.
12+
"renesas,ether-r7s72100" if the device is a part of R7S72100 SoC.
13+
- reg: offset and length of (1) the E-DMAC/feLic register block (required),
14+
(2) the TSU register block (optional).
15+
- interrupts: interrupt specifier for the sole interrupt.
16+
- phy-mode: see ethernet.txt file in the same directory.
17+
- phy-handle: see ethernet.txt file in the same directory.
18+
- #address-cells: number of address cells for the MDIO bus, must be equal to 1.
19+
- #size-cells: number of size cells on the MDIO bus, must be equal to 0.
20+
- clocks: clock phandle and specifier pair.
21+
- pinctrl-0: phandle, referring to a default pin configuration node.
22+
23+
Optional properties:
24+
- interrupt-parent: the phandle for the interrupt controller that services
25+
interrupts for this device.
26+
- pinctrl-names: pin configuration state name ("default").
27+
- renesas,no-ether-link: boolean, specify when a board does not provide a proper
28+
Ether LINK signal.
29+
- renesas,ether-link-active-low: boolean, specify when the Ether LINK signal is
30+
active-low instead of normal active-high.
31+
32+
Example (Lager board):
33+
34+
ethernet@ee700000 {
35+
compatible = "renesas,ether-r8a7790";
36+
reg = <0 0xee700000 0 0x400>;
37+
interrupt-parent = <&gic>;
38+
interrupts = <0 162 IRQ_TYPE_LEVEL_HIGH>;
39+
clocks = <&mstp8_clks R8A7790_CLK_ETHER>;
40+
phy-mode = "rmii";
41+
phy-handle = <&phy1>;
42+
pinctrl-0 = <&ether_pins>;
43+
pinctrl-names = "default";
44+
renesas,ether-link-active-low;
45+
#address-cells = <1>;
46+
#size-cells = <0>;
47+
48+
phy1: ethernet-phy@1 {
49+
reg = <1>;
50+
interrupt-parent = <&irqc0>;
51+
interrupts = <0 IRQ_TYPE_LEVEL_LOW>;
52+
pinctrl-0 = <&phy1_pins>;
53+
pinctrl-names = "default";
54+
};
55+
};

drivers/net/ethernet/renesas/sh_eth.c

Lines changed: 66 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
/* SuperH Ethernet device driver
22
*
33
* Copyright (C) 2006-2012 Nobuhiro Iwamatsu
4-
* Copyright (C) 2008-2013 Renesas Solutions Corp.
5-
* Copyright (C) 2013 Cogent Embedded, Inc.
4+
* Copyright (C) 2008-2014 Renesas Solutions Corp.
5+
* Copyright (C) 2013-2014 Cogent Embedded, Inc.
66
*
77
* This program is free software; you can redistribute it and/or modify it
88
* under the terms and conditions of the GNU General Public License,
@@ -27,6 +27,10 @@
2727
#include <linux/platform_device.h>
2828
#include <linux/mdio-bitbang.h>
2929
#include <linux/netdevice.h>
30+
#include <linux/of.h>
31+
#include <linux/of_device.h>
32+
#include <linux/of_irq.h>
33+
#include <linux/of_net.h>
3034
#include <linux/phy.h>
3135
#include <linux/cache.h>
3236
#include <linux/io.h>
@@ -2710,6 +2714,54 @@ static const struct net_device_ops sh_eth_netdev_ops_tsu = {
27102714
.ndo_change_mtu = eth_change_mtu,
27112715
};
27122716

2717+
#ifdef CONFIG_OF
2718+
static struct sh_eth_plat_data *sh_eth_parse_dt(struct device *dev)
2719+
{
2720+
struct device_node *np = dev->of_node;
2721+
struct sh_eth_plat_data *pdata;
2722+
struct device_node *phy;
2723+
const char *mac_addr;
2724+
2725+
pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL);
2726+
if (!pdata)
2727+
return NULL;
2728+
2729+
pdata->phy_interface = of_get_phy_mode(np);
2730+
2731+
phy = of_parse_phandle(np, "phy-handle", 0);
2732+
if (of_property_read_u32(phy, "reg", &pdata->phy))
2733+
return NULL;
2734+
pdata->phy_irq = irq_of_parse_and_map(phy, 0);
2735+
2736+
mac_addr = of_get_mac_address(np);
2737+
if (mac_addr)
2738+
memcpy(pdata->mac_addr, mac_addr, ETH_ALEN);
2739+
2740+
pdata->no_ether_link =
2741+
of_property_read_bool(np, "renesas,no-ether-link");
2742+
pdata->ether_link_active_low =
2743+
of_property_read_bool(np, "renesas,ether-link-active-low");
2744+
2745+
return pdata;
2746+
}
2747+
2748+
static const struct of_device_id sh_eth_match_table[] = {
2749+
{ .compatible = "renesas,gether-r8a7740", .data = &r8a7740_data },
2750+
{ .compatible = "renesas,ether-r8a7778", .data = &r8a777x_data },
2751+
{ .compatible = "renesas,ether-r8a7779", .data = &r8a777x_data },
2752+
{ .compatible = "renesas,ether-r8a7790", .data = &r8a779x_data },
2753+
{ .compatible = "renesas,ether-r8a7791", .data = &r8a779x_data },
2754+
{ .compatible = "renesas,ether-r7s72100", .data = &r7s72100_data },
2755+
{ }
2756+
};
2757+
MODULE_DEVICE_TABLE(of, sh_eth_match_table);
2758+
#else
2759+
static inline struct sh_eth_plat_data *sh_eth_parse_dt(struct device *dev)
2760+
{
2761+
return NULL;
2762+
}
2763+
#endif
2764+
27132765
static int sh_eth_drv_probe(struct platform_device *pdev)
27142766
{
27152767
int ret, devno = 0;
@@ -2763,6 +2815,8 @@ static int sh_eth_drv_probe(struct platform_device *pdev)
27632815
pm_runtime_enable(&pdev->dev);
27642816
pm_runtime_resume(&pdev->dev);
27652817

2818+
if (pdev->dev.of_node)
2819+
pd = sh_eth_parse_dt(&pdev->dev);
27662820
if (!pd) {
27672821
dev_err(&pdev->dev, "no platform data\n");
27682822
ret = -EINVAL;
@@ -2778,7 +2832,15 @@ static int sh_eth_drv_probe(struct platform_device *pdev)
27782832
mdp->ether_link_active_low = pd->ether_link_active_low;
27792833

27802834
/* set cpu data */
2781-
mdp->cd = (struct sh_eth_cpu_data *)id->driver_data;
2835+
if (id) {
2836+
mdp->cd = (struct sh_eth_cpu_data *)id->driver_data;
2837+
} else {
2838+
const struct of_device_id *match;
2839+
2840+
match = of_match_device(of_match_ptr(sh_eth_match_table),
2841+
&pdev->dev);
2842+
mdp->cd = (struct sh_eth_cpu_data *)match->data;
2843+
}
27822844
mdp->reg_offset = sh_eth_get_register_offset(mdp->cd->register_type);
27832845
sh_eth_set_default_cpu_data(mdp->cd);
27842846

@@ -2920,6 +2982,7 @@ static struct platform_driver sh_eth_driver = {
29202982
.driver = {
29212983
.name = CARDNAME,
29222984
.pm = SH_ETH_PM_OPS,
2985+
.of_match_table = of_match_ptr(sh_eth_match_table),
29232986
},
29242987
};
29252988

0 commit comments

Comments
 (0)