blob: 99cefe6f5edb9d9e717f93f6e5c00dc0081b688b [file] [log] [blame]
Thomas Gleixner55716d22019-06-01 10:08:42 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Grant Likely8bc487d2009-04-25 12:52:56 +00002/*
3 * OF helpers for the MDIO (Ethernet PHY) API
4 *
5 * Copyright (c) 2009 Secret Lab Technologies, Ltd.
Grant Likely8bc487d2009-04-25 12:52:56 +00006 */
7
8#ifndef __LINUX_OF_MDIO_H
9#define __LINUX_OF_MDIO_H
10
11#include <linux/phy.h>
12#include <linux/of.h>
13
Florian Fainellie6e14f62017-03-23 10:01:17 -070014#if IS_ENABLED(CONFIG_OF_MDIO)
Grant Likely8bc487d2009-04-25 12:52:56 +000015extern int of_mdiobus_register(struct mii_bus *mdio, struct device_node *np);
16extern struct phy_device *of_phy_find_device(struct device_node *phy_np);
17extern struct phy_device *of_phy_connect(struct net_device *dev,
18 struct device_node *phy_np,
19 void (*hndlr)(struct net_device *),
20 u32 flags, phy_interface_t iface);
Dongpo Lib7862412016-07-15 16:26:34 +080021extern struct phy_device *
22of_phy_get_and_connect(struct net_device *dev, struct device_node *np,
23 void (*hndlr)(struct net_device *));
Andy Fleming7614aba2014-01-10 14:28:11 +080024struct phy_device *of_phy_attach(struct net_device *dev,
25 struct device_node *phy_np, u32 flags,
26 phy_interface_t iface);
Grant Likely8bc487d2009-04-25 12:52:56 +000027
David Daney25106022012-05-02 15:16:37 +000028extern struct mii_bus *of_mdio_find_bus(struct device_node *mdio_np);
Arnd Bergmanna5e4bd92016-06-24 11:24:08 +020029extern int of_phy_register_fixed_link(struct device_node *np);
Johan Hovold3f650472016-11-28 19:24:55 +010030extern void of_phy_deregister_fixed_link(struct device_node *np);
Arnd Bergmanna5e4bd92016-06-24 11:24:08 +020031extern bool of_phy_is_fixed_link(struct device_node *np);
David Daney25106022012-05-02 15:16:37 +000032
Jon Mason4798a712017-06-13 10:56:08 -040033
34static inline int of_mdio_parse_addr(struct device *dev,
35 const struct device_node *np)
36{
37 u32 addr;
38 int ret;
39
40 ret = of_property_read_u32(np, "reg", &addr);
41 if (ret < 0) {
42 dev_err(dev, "%s has invalid PHY address\n", np->full_name);
43 return ret;
44 }
45
46 /* A PHY must have a reg property in the range [0-31] */
47 if (addr >= PHY_MAX_ADDR) {
48 dev_err(dev, "%s PHY address %i is too large\n",
49 np->full_name, addr);
50 return -EINVAL;
51 }
52
53 return addr;
54}
55
Florian Fainellie6e14f62017-03-23 10:01:17 -070056#else /* CONFIG_OF_MDIO */
Mark Brown2a5cf802012-10-09 18:33:38 +000057static inline int of_mdiobus_register(struct mii_bus *mdio, struct device_node *np)
Srinivas Kandagatlaf9dc9ac2012-08-24 01:58:59 +000058{
Daniel Mack23a456f2014-05-06 18:52:16 +020059 /*
60 * Fall back to the non-DT function to register a bus.
61 * This way, we don't have to keep compat bits around in drivers.
62 */
63
64 return mdiobus_register(mdio);
Srinivas Kandagatlaf9dc9ac2012-08-24 01:58:59 +000065}
66
Mark Brown2a5cf802012-10-09 18:33:38 +000067static inline struct phy_device *of_phy_find_device(struct device_node *phy_np)
Srinivas Kandagatlaf9dc9ac2012-08-24 01:58:59 +000068{
69 return NULL;
70}
71
Mark Brown2a5cf802012-10-09 18:33:38 +000072static inline struct phy_device *of_phy_connect(struct net_device *dev,
73 struct device_node *phy_np,
74 void (*hndlr)(struct net_device *),
75 u32 flags, phy_interface_t iface)
Srinivas Kandagatlaf9dc9ac2012-08-24 01:58:59 +000076{
77 return NULL;
78}
79
Dongpo Lib7862412016-07-15 16:26:34 +080080static inline struct phy_device *
81of_phy_get_and_connect(struct net_device *dev, struct device_node *np,
82 void (*hndlr)(struct net_device *))
83{
84 return NULL;
85}
86
Andy Fleming7614aba2014-01-10 14:28:11 +080087static inline struct phy_device *of_phy_attach(struct net_device *dev,
88 struct device_node *phy_np,
89 u32 flags, phy_interface_t iface)
90{
91 return NULL;
92}
93
Mark Brown2a5cf802012-10-09 18:33:38 +000094static inline struct mii_bus *of_mdio_find_bus(struct device_node *mdio_np)
Srinivas Kandagatlaf9dc9ac2012-08-24 01:58:59 +000095{
96 return NULL;
97}
Florian Fainelli33d67372015-03-10 16:57:11 -070098
99static inline int of_mdio_parse_addr(struct device *dev,
100 const struct device_node *np)
101{
102 return -ENOSYS;
103}
Thomas Petazzoni3be2a492014-05-16 16:14:05 +0200104static inline int of_phy_register_fixed_link(struct device_node *np)
105{
106 return -ENOSYS;
107}
Johan Hovold3f650472016-11-28 19:24:55 +0100108static inline void of_phy_deregister_fixed_link(struct device_node *np)
109{
110}
Thomas Petazzoni3be2a492014-05-16 16:14:05 +0200111static inline bool of_phy_is_fixed_link(struct device_node *np)
112{
113 return false;
114}
115#endif
116
117
Grant Likely8bc487d2009-04-25 12:52:56 +0000118#endif /* __LINUX_OF_MDIO_H */