Lines Matching +full:ethernet +full:- +full:phy +full:- +full:package
1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * PHY package support
7 #include <linux/phy.h>
10 #include "phylib-internal.h"
13 * struct phy_package_shared - Shared information in PHY packages
14 * @base_addr: Base PHY address of PHY package used to combine PHYs
15 * in one package and for offset calculation of phy_package_read/write
16 * @np: Pointer to the Device Node if PHY package defined in DT
18 * @flags: Initialization of PHY package
20 * @priv: Driver private data shared across a PHY package
23 * package, for example a quad PHY. See phy_package_join() and
28 /* With PHY package defined in DT this points to the PHY package node */
45 return phydev->shared->np; in phy_package_get_node()
51 return phydev->shared->priv; in phy_package_get_priv()
57 struct phy_package_shared *shared = phydev->shared; in phy_package_address()
58 u8 base_addr = shared->base_addr; in phy_package_address()
60 if (addr_offset >= PHY_MAX_ADDR - base_addr) in phy_package_address()
61 return -EIO; in phy_package_address()
77 return __mdiobus_read(phydev->mdio.bus, addr, regnum); in __phy_package_read()
89 return __mdiobus_write(phydev->mdio.bus, addr, regnum, val); in __phy_package_write()
95 struct phy_package_shared *shared = phydev->shared; in __phy_package_set_once()
100 return !test_and_set_bit(b, &shared->flags); in __phy_package_set_once()
116 * phy_package_join - join a common PHY group
118 * @base_addr: cookie and base PHY address of PHY package for offset
120 * @priv_size: if non-zero allocate this amount of bytes for private data
122 * This joins a PHY group and provides a shared storage for all phydevs in
124 * more than one PHY, for example a quad PHY transceiver.
127 * for all members of one group and as the base PHY address of the PHY package
128 * for offset calculation to access generic registers of a PHY package.
129 * Usually, one of the PHY addresses of the different PHYs in the package
137 * allocated. If priv_size is non-zero, the given amount of bytes are
145 struct mii_bus *bus = phydev->mdio.bus; in phy_package_join()
150 return -EINVAL; in phy_package_join()
152 mutex_lock(&bus->shared_lock); in phy_package_join()
153 shared = bus->shared[base_addr]; in phy_package_join()
155 ret = -ENOMEM; in phy_package_join()
160 shared->priv = kzalloc(priv_size, GFP_KERNEL); in phy_package_join()
161 if (!shared->priv) in phy_package_join()
163 shared->priv_size = priv_size; in phy_package_join()
165 shared->base_addr = base_addr; in phy_package_join()
166 shared->np = NULL; in phy_package_join()
167 refcount_set(&shared->refcnt, 1); in phy_package_join()
168 bus->shared[base_addr] = shared; in phy_package_join()
170 ret = -EINVAL; in phy_package_join()
171 if (priv_size && priv_size != shared->priv_size) in phy_package_join()
173 refcount_inc(&shared->refcnt); in phy_package_join()
175 mutex_unlock(&bus->shared_lock); in phy_package_join()
177 phydev->shared = shared; in phy_package_join()
184 mutex_unlock(&bus->shared_lock); in phy_package_join()
190 * of_phy_package_join - join a common PHY group in PHY package
192 * @priv_size: if non-zero allocate this amount of bytes for private data
194 * This is a variant of phy_package_join for PHY package defined in DT.
196 * The parent node of the @phydev is checked as a valid PHY package node
197 * structure (by matching the node name "ethernet-phy-package") and the
198 * base_addr for the PHY package is passed to phy_package_join.
201 * filled to use additional DT defined properties in PHY specific
202 * probe_once and config_init_once PHY package OPs.
207 * name for PHY package.
211 struct device_node *node = phydev->mdio.dev.of_node; in of_phy_package_join()
217 return -EINVAL; in of_phy_package_join()
221 return -EINVAL; in of_phy_package_join()
223 if (!of_node_name_eq(package_node, "ethernet-phy-package")) { in of_phy_package_join()
224 ret = -EINVAL; in of_phy_package_join()
229 ret = -EINVAL; in of_phy_package_join()
237 phydev->shared->np = package_node; in of_phy_package_join()
247 * phy_package_leave - leave a common PHY group
250 * This leaves a PHY group created by phy_package_join(). If this phydev
252 * freed. Resets the phydev->shared pointer to NULL.
256 struct phy_package_shared *shared = phydev->shared; in phy_package_leave()
257 struct mii_bus *bus = phydev->mdio.bus; in phy_package_leave()
263 if (shared->np) in phy_package_leave()
264 of_node_put(shared->np); in phy_package_leave()
266 if (refcount_dec_and_mutex_lock(&shared->refcnt, &bus->shared_lock)) { in phy_package_leave()
267 bus->shared[shared->base_addr] = NULL; in phy_package_leave()
268 mutex_unlock(&bus->shared_lock); in phy_package_leave()
269 kfree(shared->priv); in phy_package_leave()
273 phydev->shared = NULL; in phy_package_leave()
283 * devm_phy_package_join - resource managed phy_package_join()
284 * @dev: device that is registering this PHY package
286 * @base_addr: cookie and base PHY address of PHY package for offset
288 * @priv_size: if non-zero allocate this amount of bytes for private data
303 return -ENOMEM; in devm_phy_package_join()
319 * devm_of_phy_package_join - resource managed of_phy_package_join()
320 * @dev: device that is registering this PHY package
322 * @priv_size: if non-zero allocate this amount of bytes for private data
337 return -ENOMEM; in devm_of_phy_package_join()