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()
58 struct phy_package_shared *shared = phydev->shared; in phy_package_address()
59 u8 base_addr = shared->base_addr; in phy_package_address()
61 if (addr_offset >= PHY_MAX_ADDR - base_addr) in phy_package_address()
62 return -EIO; in phy_package_address()
78 return __mdiobus_read(phydev->mdio.bus, addr, regnum); in __phy_package_read()
90 return __mdiobus_write(phydev->mdio.bus, addr, regnum, val); in __phy_package_write()
95 * __phy_package_read_mmd - read MMD reg relative to PHY package base addr
97 * @addr_offset: The offset to be added to PHY package base_addr
101 * Convenience helper for reading a register of an MMD on a given PHY
102 * using the PHY package base address. The base address is added to
107 * NOTE: It's assumed that the entire PHY package is either C22 or C45.
119 return -EINVAL; in __phy_package_read_mmd()
121 return mmd_phy_read(phydev->mdio.bus, addr, phydev->is_c45, devad, in __phy_package_read_mmd()
127 * __phy_package_write_mmd - write MMD reg relative to PHY package base addr
129 * @addr_offset: The offset to be added to PHY package base_addr
134 * Convenience helper for writing a register of an MMD on a given PHY
135 * using the PHY package base address. The base address is added to
140 * NOTE: It's assumed that the entire PHY package is either C22 or C45.
152 return -EINVAL; in __phy_package_write_mmd()
154 return mmd_phy_write(phydev->mdio.bus, addr, phydev->is_c45, devad, in __phy_package_write_mmd()
161 struct phy_package_shared *shared = phydev->shared; in __phy_package_set_once()
166 return !test_and_set_bit(b, &shared->flags); in __phy_package_set_once()
182 * phy_package_join - join a common PHY group
184 * @base_addr: cookie and base PHY address of PHY package for offset
186 * @priv_size: if non-zero allocate this amount of bytes for private data
188 * This joins a PHY group and provides a shared storage for all phydevs in
190 * more than one PHY, for example a quad PHY transceiver.
193 * for all members of one group and as the base PHY address of the PHY package
194 * for offset calculation to access generic registers of a PHY package.
195 * Usually, one of the PHY addresses of the different PHYs in the package
203 * allocated. If priv_size is non-zero, the given amount of bytes are
211 struct mii_bus *bus = phydev->mdio.bus; in phy_package_join()
216 return -EINVAL; in phy_package_join()
218 mutex_lock(&bus->shared_lock); in phy_package_join()
219 shared = bus->shared[base_addr]; in phy_package_join()
221 ret = -ENOMEM; in phy_package_join()
226 shared->priv = kzalloc(priv_size, GFP_KERNEL); in phy_package_join()
227 if (!shared->priv) in phy_package_join()
229 shared->priv_size = priv_size; in phy_package_join()
231 shared->base_addr = base_addr; in phy_package_join()
232 shared->np = NULL; in phy_package_join()
233 refcount_set(&shared->refcnt, 1); in phy_package_join()
234 bus->shared[base_addr] = shared; in phy_package_join()
236 ret = -EINVAL; in phy_package_join()
237 if (priv_size && priv_size != shared->priv_size) in phy_package_join()
239 refcount_inc(&shared->refcnt); in phy_package_join()
241 mutex_unlock(&bus->shared_lock); in phy_package_join()
243 phydev->shared = shared; in phy_package_join()
250 mutex_unlock(&bus->shared_lock); in phy_package_join()
256 * of_phy_package_join - join a common PHY group in PHY package
258 * @priv_size: if non-zero allocate this amount of bytes for private data
260 * This is a variant of phy_package_join for PHY package defined in DT.
262 * The parent node of the @phydev is checked as a valid PHY package node
263 * structure (by matching the node name "ethernet-phy-package") and the
264 * base_addr for the PHY package is passed to phy_package_join.
267 * filled to use additional DT defined properties in PHY specific
268 * probe_once and config_init_once PHY package OPs.
273 * name for PHY package.
277 struct device_node *node = phydev->mdio.dev.of_node; in of_phy_package_join()
283 return -EINVAL; in of_phy_package_join()
287 return -EINVAL; in of_phy_package_join()
289 if (!of_node_name_eq(package_node, "ethernet-phy-package")) { in of_phy_package_join()
290 ret = -EINVAL; in of_phy_package_join()
295 ret = -EINVAL; in of_phy_package_join()
303 phydev->shared->np = package_node; in of_phy_package_join()
313 * phy_package_leave - leave a common PHY group
316 * This leaves a PHY group created by phy_package_join(). If this phydev
318 * freed. Resets the phydev->shared pointer to NULL.
322 struct phy_package_shared *shared = phydev->shared; in phy_package_leave()
323 struct mii_bus *bus = phydev->mdio.bus; in phy_package_leave()
329 if (shared->np) in phy_package_leave()
330 of_node_put(shared->np); in phy_package_leave()
332 if (refcount_dec_and_mutex_lock(&shared->refcnt, &bus->shared_lock)) { in phy_package_leave()
333 bus->shared[shared->base_addr] = NULL; in phy_package_leave()
334 mutex_unlock(&bus->shared_lock); in phy_package_leave()
335 kfree(shared->priv); in phy_package_leave()
339 phydev->shared = NULL; in phy_package_leave()
349 * devm_phy_package_join - resource managed phy_package_join()
350 * @dev: device that is registering this PHY package
352 * @base_addr: cookie and base PHY address of PHY package for offset
354 * @priv_size: if non-zero allocate this amount of bytes for private data
369 return -ENOMEM; in devm_phy_package_join()
385 * devm_of_phy_package_join - resource managed of_phy_package_join()
386 * @dev: device that is registering this PHY package
388 * @priv_size: if non-zero allocate this amount of bytes for private data
403 return -ENOMEM; in devm_of_phy_package_join()
418 MODULE_DESCRIPTION("PHY package support");