From mboxrd@z Thu Jan 1 00:00:00 1970 From: Bastian Hecht Date: Sun, 16 Dec 2012 13:54:26 +0000 Subject: [PATCH 2/2] net: sh_eth: Add Device Tree support Message-Id: <1355666066-25649-3-git-send-email-hechtb+renesas@gmail.com> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: 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, }, }; -- 1.7.9.5