Linux Audio

Check our new training course

Loading...
v6.8
 1// SPDX-License-Identifier: GPL-2.0-or-later
 2/**
 3 * DOC: 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
19static int emac_arc_probe(struct platform_device *pdev)
20{
21	struct device *dev = &pdev->dev;
22	struct arc_emac_priv *priv;
23	phy_interface_t interface;
24	struct net_device *ndev;
25	int err;
 
26
27	if (!dev->of_node)
28		return -ENODEV;
29
30	ndev = alloc_etherdev(sizeof(struct arc_emac_priv));
31	if (!ndev)
32		return -ENOMEM;
33	platform_set_drvdata(pdev, ndev);
34	SET_NETDEV_DEV(ndev, dev);
35
36	priv = netdev_priv(ndev);
37	priv->drv_name = DRV_NAME;
 
38
39	err = of_get_phy_mode(dev->of_node, &interface);
40	if (err) {
41		if (err == -ENODEV)
42			interface = PHY_INTERFACE_MODE_MII;
43		else
44			goto out_netdev;
45	}
46
47	priv->clk = devm_clk_get(dev, "hclk");
48	if (IS_ERR(priv->clk)) {
49		dev_err(dev, "failed to retrieve host clock from device tree\n");
50		err = -EINVAL;
51		goto out_netdev;
52	}
53
54	err = arc_emac_probe(ndev, interface);
55out_netdev:
56	if (err)
57		free_netdev(ndev);
58	return err;
59}
60
61static void emac_arc_remove(struct platform_device *pdev)
62{
63	struct net_device *ndev = platform_get_drvdata(pdev);
 
64
65	arc_emac_remove(ndev);
66	free_netdev(ndev);
 
67}
68
69static const struct of_device_id emac_arc_dt_ids[] = {
70	{ .compatible = "snps,arc-emac" },
71	{ /* Sentinel */ }
72};
73MODULE_DEVICE_TABLE(of, emac_arc_dt_ids);
74
75static struct platform_driver emac_arc_driver = {
76	.probe = emac_arc_probe,
77	.remove_new = emac_arc_remove,
78	.driver = {
79		.name = DRV_NAME,
80		.of_match_table  = emac_arc_dt_ids,
81	},
82};
83
84module_platform_driver(emac_arc_driver);
85
86MODULE_AUTHOR("Romain Perier <romain.perier@gmail.com>");
87MODULE_DESCRIPTION("ARC EMAC platform driver");
88MODULE_LICENSE("GPL");
v4.17
 
 1/**
 2 * emac_arc.c - ARC EMAC specific glue layer
 3 *
 4 * Copyright (C) 2014 Romain Perier
 5 *
 6 * Romain Perier  <romain.perier@gmail.com>
 7 *
 8 * This program is free software; you can redistribute it and/or modify
 9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 * GNU General Public License for more details.
17 */
18
19#include <linux/etherdevice.h>
20#include <linux/module.h>
21#include <linux/of_net.h>
22#include <linux/platform_device.h>
23
24#include "emac.h"
25
26#define DRV_NAME    "emac_arc"
27#define DRV_VERSION "1.0"
28
29static int emac_arc_probe(struct platform_device *pdev)
30{
31	struct device *dev = &pdev->dev;
 
 
32	struct net_device *ndev;
33	struct arc_emac_priv *priv;
34	int interface, err;
35
36	if (!dev->of_node)
37		return -ENODEV;
38
39	ndev = alloc_etherdev(sizeof(struct arc_emac_priv));
40	if (!ndev)
41		return -ENOMEM;
42	platform_set_drvdata(pdev, ndev);
43	SET_NETDEV_DEV(ndev, dev);
44
45	priv = netdev_priv(ndev);
46	priv->drv_name = DRV_NAME;
47	priv->drv_version = DRV_VERSION;
48
49	interface = of_get_phy_mode(dev->of_node);
50	if (interface < 0)
51		interface = PHY_INTERFACE_MODE_MII;
 
 
 
 
52
53	priv->clk = devm_clk_get(dev, "hclk");
54	if (IS_ERR(priv->clk)) {
55		dev_err(dev, "failed to retrieve host clock from device tree\n");
56		err = -EINVAL;
57		goto out_netdev;
58	}
59
60	err = arc_emac_probe(ndev, interface);
61out_netdev:
62	if (err)
63		free_netdev(ndev);
64	return err;
65}
66
67static int emac_arc_remove(struct platform_device *pdev)
68{
69	struct net_device *ndev = platform_get_drvdata(pdev);
70	int err;
71
72	err = arc_emac_remove(ndev);
73	free_netdev(ndev);
74	return err;
75}
76
77static const struct of_device_id emac_arc_dt_ids[] = {
78	{ .compatible = "snps,arc-emac" },
79	{ /* Sentinel */ }
80};
81MODULE_DEVICE_TABLE(of, emac_arc_dt_ids);
82
83static struct platform_driver emac_arc_driver = {
84	.probe = emac_arc_probe,
85	.remove = emac_arc_remove,
86	.driver = {
87		.name = DRV_NAME,
88		.of_match_table  = emac_arc_dt_ids,
89	},
90};
91
92module_platform_driver(emac_arc_driver);
93
94MODULE_AUTHOR("Romain Perier <romain.perier@gmail.com>");
95MODULE_DESCRIPTION("ARC EMAC platform driver");
96MODULE_LICENSE("GPL");