1 // SPDX-License-Identifier: GPL-2.0-or-later 2 /** 3 * emac_arc.c - ARC EMAC specific glue layer 4 * 5 * Copyright (C) 2014 Romain Perier 6 * 7 * Romain Perier <romain.perier@gmail.com> 8 */ 9 10 #include <linux/etherdevice.h> 11 #include <linux/module.h> 12 #include <linux/of_net.h> 13 #include <linux/platform_device.h> 14 15 #include "emac.h" 16 17 #define DRV_NAME "emac_arc" 18 #define DRV_VERSION "1.0" 19 20 static int emac_arc_probe(struct platform_device *pdev) 21 { 22 struct device *dev = &pdev->dev; 23 struct arc_emac_priv *priv; 24 phy_interface_t interface; 25 struct net_device *ndev; 26 int err; 27 28 if (!dev->of_node) 29 return -ENODEV; 30 31 ndev = alloc_etherdev(sizeof(struct arc_emac_priv)); 32 if (!ndev) 33 return -ENOMEM; 34 platform_set_drvdata(pdev, ndev); 35 SET_NETDEV_DEV(ndev, dev); 36 37 priv = netdev_priv(ndev); 38 priv->drv_name = DRV_NAME; 39 priv->drv_version = DRV_VERSION; 40 41 err = of_get_phy_mode(dev->of_node, &interface); 42 if (err) { 43 if (err == -ENODEV) 44 interface = PHY_INTERFACE_MODE_MII; 45 else 46 goto out_netdev; 47 } 48 49 priv->clk = devm_clk_get(dev, "hclk"); 50 if (IS_ERR(priv->clk)) { 51 dev_err(dev, "failed to retrieve host clock from device tree\n"); 52 err = -EINVAL; 53 goto out_netdev; 54 } 55 56 err = arc_emac_probe(ndev, interface); 57 out_netdev: 58 if (err) 59 free_netdev(ndev); 60 return err; 61 } 62 63 static int emac_arc_remove(struct platform_device *pdev) 64 { 65 struct net_device *ndev = platform_get_drvdata(pdev); 66 int err; 67 68 err = arc_emac_remove(ndev); 69 free_netdev(ndev); 70 return err; 71 } 72 73 static const struct of_device_id emac_arc_dt_ids[] = { 74 { .compatible = "snps,arc-emac" }, 75 { /* Sentinel */ } 76 }; 77 MODULE_DEVICE_TABLE(of, emac_arc_dt_ids); 78 79 static struct platform_driver emac_arc_driver = { 80 .probe = emac_arc_probe, 81 .remove = emac_arc_remove, 82 .driver = { 83 .name = DRV_NAME, 84 .of_match_table = emac_arc_dt_ids, 85 }, 86 }; 87 88 module_platform_driver(emac_arc_driver); 89 90 MODULE_AUTHOR("Romain Perier <romain.perier@gmail.com>"); 91 MODULE_DESCRIPTION("ARC EMAC platform driver"); 92 MODULE_LICENSE("GPL"); 93