1
1
/* SuperH Ethernet device driver
2
2
*
3
3
* 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.
6
6
*
7
7
* This program is free software; you can redistribute it and/or modify it
8
8
* under the terms and conditions of the GNU General Public License,
27
27
#include <linux/platform_device.h>
28
28
#include <linux/mdio-bitbang.h>
29
29
#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>
30
34
#include <linux/phy.h>
31
35
#include <linux/cache.h>
32
36
#include <linux/io.h>
@@ -2710,6 +2714,54 @@ static const struct net_device_ops sh_eth_netdev_ops_tsu = {
2710
2714
.ndo_change_mtu = eth_change_mtu ,
2711
2715
};
2712
2716
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
+
2713
2765
static int sh_eth_drv_probe (struct platform_device * pdev )
2714
2766
{
2715
2767
int ret , devno = 0 ;
@@ -2763,6 +2815,8 @@ static int sh_eth_drv_probe(struct platform_device *pdev)
2763
2815
pm_runtime_enable (& pdev -> dev );
2764
2816
pm_runtime_resume (& pdev -> dev );
2765
2817
2818
+ if (pdev -> dev .of_node )
2819
+ pd = sh_eth_parse_dt (& pdev -> dev );
2766
2820
if (!pd ) {
2767
2821
dev_err (& pdev -> dev , "no platform data\n" );
2768
2822
ret = - EINVAL ;
@@ -2778,7 +2832,15 @@ static int sh_eth_drv_probe(struct platform_device *pdev)
2778
2832
mdp -> ether_link_active_low = pd -> ether_link_active_low ;
2779
2833
2780
2834
/* 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
+ }
2782
2844
mdp -> reg_offset = sh_eth_get_register_offset (mdp -> cd -> register_type );
2783
2845
sh_eth_set_default_cpu_data (mdp -> cd );
2784
2846
@@ -2920,6 +2982,7 @@ static struct platform_driver sh_eth_driver = {
2920
2982
.driver = {
2921
2983
.name = CARDNAME ,
2922
2984
.pm = SH_ETH_PM_OPS ,
2985
+ .of_match_table = of_match_ptr (sh_eth_match_table ),
2923
2986
},
2924
2987
};
2925
2988
0 commit comments