mirror of
https://github.com/torvalds/linux.git
synced 2026-10-12 21:31:03 +02:00
Merge branch 'net-phy-further-decouple-provider-from-consumer-part'
Heiner Kallweit says: ==================== net: phy: further decouple provider from consumer part This series aims at further decoupling the provider and consumer part in phylib. ==================== Link: https://patch.msgid.link/9d5724bc-e525-4f8f-b3f8-b16dd5a1164e@gmail.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
This commit is contained in:
commit
9d9d7b4b15
|
|
@ -392,7 +392,7 @@ config IPQ_NSSCC_9574
|
|||
|
||||
config IPQ_NSSCC_QCA8K
|
||||
tristate "QCA8K(QCA8386 or QCA8084) NSS Clock Controller"
|
||||
depends on MDIO_BUS
|
||||
depends on PHYLIB
|
||||
help
|
||||
Support for NSS(Network SubSystem) clock controller on
|
||||
qca8386/qca8084 chip.
|
||||
|
|
|
|||
|
|
@ -3,8 +3,8 @@
|
|||
|
||||
libphy-y := phy.o phy-c45.o phy-core.o phy_device.o \
|
||||
linkmode.o phy_link_topology.o \
|
||||
phy_caps.o mdio_bus_provider.o phy_port.o
|
||||
mdio-bus-y += mdio_bus.o mdio_device.o
|
||||
phy_caps.o mdio_bus_provider.o phy_port.o \
|
||||
mdio_device.o
|
||||
|
||||
ifdef CONFIG_PHYLIB
|
||||
# built-in whenever PHYLIB is built-in or module
|
||||
|
|
@ -15,7 +15,7 @@ libphy-$(CONFIG_SWPHY) += swphy.o
|
|||
libphy-$(CONFIG_LED_TRIGGER_PHY) += phy_led_triggers.o
|
||||
libphy-$(CONFIG_OPEN_ALLIANCE_HELPERS) += open_alliance_helpers.o
|
||||
|
||||
obj-$(CONFIG_MDIO_BUS) += mdio-bus.o
|
||||
obj-$(CONFIG_MDIO_BUS) += mdio_bus.o
|
||||
obj-$(CONFIG_PHYLINK) += phylink.o
|
||||
obj-$(CONFIG_PHYLIB) += libphy.o
|
||||
obj-$(CONFIG_PHYLIB) += mdio_devres.o
|
||||
|
|
|
|||
|
|
@ -1,11 +0,0 @@
|
|||
/* SPDX-License-Identifier: GPL-2.0-or-later */
|
||||
#ifndef __MDIO_PRIVATE_H
|
||||
#define __MDIO_PRIVATE_H
|
||||
|
||||
/* MDIO internal helpers
|
||||
*/
|
||||
|
||||
int mdio_device_register_reset(struct mdio_device *mdiodev);
|
||||
void mdio_device_unregister_reset(struct mdio_device *mdiodev);
|
||||
|
||||
#endif /* __MDIO_PRIVATE_H */
|
||||
|
|
@ -10,65 +10,23 @@
|
|||
|
||||
#include <linux/device.h>
|
||||
#include <linux/errno.h>
|
||||
#include <linux/etherdevice.h>
|
||||
#include <linux/ethtool.h>
|
||||
#include <linux/gpio/consumer.h>
|
||||
#include <linux/init.h>
|
||||
#include <linux/io.h>
|
||||
#include <linux/kernel.h>
|
||||
#include <linux/mii.h>
|
||||
#include <linux/mm.h>
|
||||
#include <linux/module.h>
|
||||
#include <linux/netdevice.h>
|
||||
#include <linux/of_device.h>
|
||||
#include <linux/of_mdio.h>
|
||||
#include <linux/phy.h>
|
||||
#include <linux/reset.h>
|
||||
#include <linux/slab.h>
|
||||
#include <linux/spinlock.h>
|
||||
#include <linux/string.h>
|
||||
#include <linux/uaccess.h>
|
||||
#include <linux/unistd.h>
|
||||
#include "mdio-private.h"
|
||||
|
||||
#define CREATE_TRACE_POINTS
|
||||
#include <trace/events/mdio.h>
|
||||
|
||||
int mdiobus_register_device(struct mdio_device *mdiodev)
|
||||
{
|
||||
int err;
|
||||
|
||||
if (mdiodev->bus->mdio_map[mdiodev->addr])
|
||||
return -EBUSY;
|
||||
|
||||
if (mdiodev->flags & MDIO_DEVICE_FLAG_PHY) {
|
||||
err = mdio_device_register_reset(mdiodev);
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
/* Assert the reset signal */
|
||||
mdio_device_reset(mdiodev, 1);
|
||||
}
|
||||
|
||||
mdiodev->bus->mdio_map[mdiodev->addr] = mdiodev;
|
||||
|
||||
return 0;
|
||||
}
|
||||
EXPORT_SYMBOL(mdiobus_register_device);
|
||||
|
||||
int mdiobus_unregister_device(struct mdio_device *mdiodev)
|
||||
{
|
||||
if (mdiodev->bus->mdio_map[mdiodev->addr] != mdiodev)
|
||||
return -EINVAL;
|
||||
|
||||
mdio_device_unregister_reset(mdiodev);
|
||||
|
||||
mdiodev->bus->mdio_map[mdiodev->addr] = NULL;
|
||||
|
||||
return 0;
|
||||
}
|
||||
EXPORT_SYMBOL(mdiobus_unregister_device);
|
||||
|
||||
static struct mdio_device *mdiobus_find_device(struct mii_bus *bus, int addr)
|
||||
{
|
||||
bool addr_valid = addr >= 0 && addr < ARRAY_SIZE(bus->mdio_map);
|
||||
|
|
@ -100,262 +58,6 @@ bool mdiobus_is_registered_device(struct mii_bus *bus, int addr)
|
|||
}
|
||||
EXPORT_SYMBOL(mdiobus_is_registered_device);
|
||||
|
||||
/**
|
||||
* mdiobus_release - mii_bus device release callback
|
||||
* @d: the target struct device that contains the mii_bus
|
||||
*
|
||||
* Description: called when the last reference to an mii_bus is
|
||||
* dropped, to free the underlying memory.
|
||||
*/
|
||||
static void mdiobus_release(struct device *d)
|
||||
{
|
||||
struct mii_bus *bus = to_mii_bus(d);
|
||||
|
||||
WARN(bus->state != MDIOBUS_RELEASED &&
|
||||
/* for compatibility with error handling in drivers */
|
||||
bus->state != MDIOBUS_ALLOCATED,
|
||||
"%s: not in RELEASED or ALLOCATED state\n",
|
||||
bus->id);
|
||||
|
||||
if (bus->state == MDIOBUS_RELEASED)
|
||||
fwnode_handle_put(dev_fwnode(d));
|
||||
|
||||
kfree(bus);
|
||||
}
|
||||
|
||||
struct mdio_bus_stat_attr {
|
||||
struct device_attribute attr;
|
||||
int address;
|
||||
unsigned int field_offset;
|
||||
};
|
||||
|
||||
static struct mdio_bus_stat_attr *to_sattr(struct device_attribute *attr)
|
||||
{
|
||||
return container_of(attr, struct mdio_bus_stat_attr, attr);
|
||||
}
|
||||
|
||||
static u64 mdio_bus_get_stat(struct mdio_bus_stats *s, unsigned int offset)
|
||||
{
|
||||
const u64_stats_t *stats = (const void *)s + offset;
|
||||
unsigned int start;
|
||||
u64 val = 0;
|
||||
|
||||
do {
|
||||
start = u64_stats_fetch_begin(&s->syncp);
|
||||
val = u64_stats_read(stats);
|
||||
} while (u64_stats_fetch_retry(&s->syncp, start));
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
static ssize_t mdio_bus_stat_field_show(struct device *dev,
|
||||
struct device_attribute *attr,
|
||||
char *buf)
|
||||
{
|
||||
struct mdio_bus_stat_attr *sattr = to_sattr(attr);
|
||||
struct mii_bus *bus = to_mii_bus(dev);
|
||||
u64 val = 0;
|
||||
|
||||
if (sattr->address < 0) {
|
||||
/* get global stats */
|
||||
for (int i = 0; i < PHY_MAX_ADDR; i++)
|
||||
val += mdio_bus_get_stat(&bus->stats[i],
|
||||
sattr->field_offset);
|
||||
} else {
|
||||
val = mdio_bus_get_stat(&bus->stats[sattr->address],
|
||||
sattr->field_offset);
|
||||
}
|
||||
|
||||
return sysfs_emit(buf, "%llu\n", val);
|
||||
}
|
||||
|
||||
static ssize_t mdio_bus_device_stat_field_show(struct device *dev,
|
||||
struct device_attribute *attr,
|
||||
char *buf)
|
||||
{
|
||||
struct mdio_bus_stat_attr *sattr = to_sattr(attr);
|
||||
struct mdio_device *mdiodev = to_mdio_device(dev);
|
||||
struct mii_bus *bus = mdiodev->bus;
|
||||
int addr = mdiodev->addr;
|
||||
u64 val;
|
||||
|
||||
val = mdio_bus_get_stat(&bus->stats[addr], sattr->field_offset);
|
||||
|
||||
return sysfs_emit(buf, "%llu\n", val);
|
||||
}
|
||||
|
||||
#define MDIO_BUS_STATS_ATTR(field) \
|
||||
static const struct mdio_bus_stat_attr dev_attr_mdio_bus_##field = { \
|
||||
.attr = __ATTR(field, 0444, mdio_bus_stat_field_show, NULL), \
|
||||
.address = -1, \
|
||||
.field_offset = offsetof(struct mdio_bus_stats, field), \
|
||||
}; \
|
||||
static const struct mdio_bus_stat_attr dev_attr_mdio_bus_device_##field = { \
|
||||
.attr = __ATTR(field, 0444, mdio_bus_device_stat_field_show, NULL), \
|
||||
.field_offset = offsetof(struct mdio_bus_stats, field), \
|
||||
}
|
||||
|
||||
MDIO_BUS_STATS_ATTR(transfers);
|
||||
MDIO_BUS_STATS_ATTR(errors);
|
||||
MDIO_BUS_STATS_ATTR(writes);
|
||||
MDIO_BUS_STATS_ATTR(reads);
|
||||
|
||||
#define MDIO_BUS_STATS_ADDR_ATTR_DECL(field, addr, file) \
|
||||
static const struct mdio_bus_stat_attr \
|
||||
dev_attr_mdio_bus_addr_##field##_##addr = { \
|
||||
.attr = { .attr = { .name = file, .mode = 0444 }, \
|
||||
.show = mdio_bus_stat_field_show, \
|
||||
}, \
|
||||
.address = addr, \
|
||||
.field_offset = offsetof(struct mdio_bus_stats, field), \
|
||||
}
|
||||
|
||||
#define MDIO_BUS_STATS_ADDR_ATTR(field, addr) \
|
||||
MDIO_BUS_STATS_ADDR_ATTR_DECL(field, addr, \
|
||||
__stringify(field) "_" __stringify(addr))
|
||||
|
||||
#define MDIO_BUS_STATS_ADDR_ATTR_GROUP_DECL(addr) \
|
||||
MDIO_BUS_STATS_ADDR_ATTR(transfers, addr); \
|
||||
MDIO_BUS_STATS_ADDR_ATTR(errors, addr); \
|
||||
MDIO_BUS_STATS_ADDR_ATTR(writes, addr); \
|
||||
MDIO_BUS_STATS_ADDR_ATTR(reads, addr) \
|
||||
|
||||
MDIO_BUS_STATS_ADDR_ATTR_GROUP_DECL(0);
|
||||
MDIO_BUS_STATS_ADDR_ATTR_GROUP_DECL(1);
|
||||
MDIO_BUS_STATS_ADDR_ATTR_GROUP_DECL(2);
|
||||
MDIO_BUS_STATS_ADDR_ATTR_GROUP_DECL(3);
|
||||
MDIO_BUS_STATS_ADDR_ATTR_GROUP_DECL(4);
|
||||
MDIO_BUS_STATS_ADDR_ATTR_GROUP_DECL(5);
|
||||
MDIO_BUS_STATS_ADDR_ATTR_GROUP_DECL(6);
|
||||
MDIO_BUS_STATS_ADDR_ATTR_GROUP_DECL(7);
|
||||
MDIO_BUS_STATS_ADDR_ATTR_GROUP_DECL(8);
|
||||
MDIO_BUS_STATS_ADDR_ATTR_GROUP_DECL(9);
|
||||
MDIO_BUS_STATS_ADDR_ATTR_GROUP_DECL(10);
|
||||
MDIO_BUS_STATS_ADDR_ATTR_GROUP_DECL(11);
|
||||
MDIO_BUS_STATS_ADDR_ATTR_GROUP_DECL(12);
|
||||
MDIO_BUS_STATS_ADDR_ATTR_GROUP_DECL(13);
|
||||
MDIO_BUS_STATS_ADDR_ATTR_GROUP_DECL(14);
|
||||
MDIO_BUS_STATS_ADDR_ATTR_GROUP_DECL(15);
|
||||
MDIO_BUS_STATS_ADDR_ATTR_GROUP_DECL(16);
|
||||
MDIO_BUS_STATS_ADDR_ATTR_GROUP_DECL(17);
|
||||
MDIO_BUS_STATS_ADDR_ATTR_GROUP_DECL(18);
|
||||
MDIO_BUS_STATS_ADDR_ATTR_GROUP_DECL(19);
|
||||
MDIO_BUS_STATS_ADDR_ATTR_GROUP_DECL(20);
|
||||
MDIO_BUS_STATS_ADDR_ATTR_GROUP_DECL(21);
|
||||
MDIO_BUS_STATS_ADDR_ATTR_GROUP_DECL(22);
|
||||
MDIO_BUS_STATS_ADDR_ATTR_GROUP_DECL(23);
|
||||
MDIO_BUS_STATS_ADDR_ATTR_GROUP_DECL(24);
|
||||
MDIO_BUS_STATS_ADDR_ATTR_GROUP_DECL(25);
|
||||
MDIO_BUS_STATS_ADDR_ATTR_GROUP_DECL(26);
|
||||
MDIO_BUS_STATS_ADDR_ATTR_GROUP_DECL(27);
|
||||
MDIO_BUS_STATS_ADDR_ATTR_GROUP_DECL(28);
|
||||
MDIO_BUS_STATS_ADDR_ATTR_GROUP_DECL(29);
|
||||
MDIO_BUS_STATS_ADDR_ATTR_GROUP_DECL(30);
|
||||
MDIO_BUS_STATS_ADDR_ATTR_GROUP_DECL(31);
|
||||
|
||||
#define MDIO_BUS_STATS_ADDR_ATTR_GROUP(addr) \
|
||||
&dev_attr_mdio_bus_addr_transfers_##addr.attr.attr, \
|
||||
&dev_attr_mdio_bus_addr_errors_##addr.attr.attr, \
|
||||
&dev_attr_mdio_bus_addr_writes_##addr.attr.attr, \
|
||||
&dev_attr_mdio_bus_addr_reads_##addr.attr.attr \
|
||||
|
||||
static const struct attribute *const mdio_bus_statistics_attrs[] = {
|
||||
&dev_attr_mdio_bus_transfers.attr.attr,
|
||||
&dev_attr_mdio_bus_errors.attr.attr,
|
||||
&dev_attr_mdio_bus_writes.attr.attr,
|
||||
&dev_attr_mdio_bus_reads.attr.attr,
|
||||
MDIO_BUS_STATS_ADDR_ATTR_GROUP(0),
|
||||
MDIO_BUS_STATS_ADDR_ATTR_GROUP(1),
|
||||
MDIO_BUS_STATS_ADDR_ATTR_GROUP(2),
|
||||
MDIO_BUS_STATS_ADDR_ATTR_GROUP(3),
|
||||
MDIO_BUS_STATS_ADDR_ATTR_GROUP(4),
|
||||
MDIO_BUS_STATS_ADDR_ATTR_GROUP(5),
|
||||
MDIO_BUS_STATS_ADDR_ATTR_GROUP(6),
|
||||
MDIO_BUS_STATS_ADDR_ATTR_GROUP(7),
|
||||
MDIO_BUS_STATS_ADDR_ATTR_GROUP(8),
|
||||
MDIO_BUS_STATS_ADDR_ATTR_GROUP(9),
|
||||
MDIO_BUS_STATS_ADDR_ATTR_GROUP(10),
|
||||
MDIO_BUS_STATS_ADDR_ATTR_GROUP(11),
|
||||
MDIO_BUS_STATS_ADDR_ATTR_GROUP(12),
|
||||
MDIO_BUS_STATS_ADDR_ATTR_GROUP(13),
|
||||
MDIO_BUS_STATS_ADDR_ATTR_GROUP(14),
|
||||
MDIO_BUS_STATS_ADDR_ATTR_GROUP(15),
|
||||
MDIO_BUS_STATS_ADDR_ATTR_GROUP(16),
|
||||
MDIO_BUS_STATS_ADDR_ATTR_GROUP(17),
|
||||
MDIO_BUS_STATS_ADDR_ATTR_GROUP(18),
|
||||
MDIO_BUS_STATS_ADDR_ATTR_GROUP(19),
|
||||
MDIO_BUS_STATS_ADDR_ATTR_GROUP(20),
|
||||
MDIO_BUS_STATS_ADDR_ATTR_GROUP(21),
|
||||
MDIO_BUS_STATS_ADDR_ATTR_GROUP(22),
|
||||
MDIO_BUS_STATS_ADDR_ATTR_GROUP(23),
|
||||
MDIO_BUS_STATS_ADDR_ATTR_GROUP(24),
|
||||
MDIO_BUS_STATS_ADDR_ATTR_GROUP(25),
|
||||
MDIO_BUS_STATS_ADDR_ATTR_GROUP(26),
|
||||
MDIO_BUS_STATS_ADDR_ATTR_GROUP(27),
|
||||
MDIO_BUS_STATS_ADDR_ATTR_GROUP(28),
|
||||
MDIO_BUS_STATS_ADDR_ATTR_GROUP(29),
|
||||
MDIO_BUS_STATS_ADDR_ATTR_GROUP(30),
|
||||
MDIO_BUS_STATS_ADDR_ATTR_GROUP(31),
|
||||
NULL,
|
||||
};
|
||||
|
||||
static const struct attribute_group mdio_bus_statistics_group = {
|
||||
.name = "statistics",
|
||||
.attrs_const = mdio_bus_statistics_attrs,
|
||||
};
|
||||
__ATTRIBUTE_GROUPS(mdio_bus_statistics);
|
||||
|
||||
const struct class mdio_bus_class = {
|
||||
.name = "mdio_bus",
|
||||
.dev_release = mdiobus_release,
|
||||
.dev_groups = mdio_bus_statistics_groups,
|
||||
};
|
||||
EXPORT_SYMBOL_GPL(mdio_bus_class);
|
||||
|
||||
/**
|
||||
* mdio_find_bus - Given the name of a mdiobus, find the mii_bus.
|
||||
* @mdio_name: The name of a mdiobus.
|
||||
*
|
||||
* Return: a reference to the mii_bus, or NULL if none found. The
|
||||
* embedded struct device will have its reference count incremented,
|
||||
* and this must be put_deviced'ed once the bus is finished with.
|
||||
*/
|
||||
struct mii_bus *mdio_find_bus(const char *mdio_name)
|
||||
{
|
||||
struct device *d;
|
||||
|
||||
d = class_find_device_by_name(&mdio_bus_class, mdio_name);
|
||||
return d ? to_mii_bus(d) : NULL;
|
||||
}
|
||||
EXPORT_SYMBOL(mdio_find_bus);
|
||||
|
||||
#if IS_ENABLED(CONFIG_OF_MDIO)
|
||||
/**
|
||||
* of_mdio_find_bus - Given an mii_bus node, find the mii_bus.
|
||||
* @mdio_bus_np: Pointer to the mii_bus.
|
||||
*
|
||||
* Return: a reference to the mii_bus, or NULL if none found. The
|
||||
* embedded struct device will have its reference count incremented,
|
||||
* and this must be put once the bus is finished with.
|
||||
*
|
||||
* Because the association of a device_node and mii_bus is made via
|
||||
* of_mdiobus_register(), the mii_bus cannot be found before it is
|
||||
* registered with of_mdiobus_register().
|
||||
*
|
||||
*/
|
||||
struct mii_bus *of_mdio_find_bus(struct device_node *mdio_bus_np)
|
||||
{
|
||||
struct device *d;
|
||||
|
||||
if (!mdio_bus_np)
|
||||
return NULL;
|
||||
|
||||
d = class_find_device_by_of_node(&mdio_bus_class, mdio_bus_np);
|
||||
return d ? to_mii_bus(d) : NULL;
|
||||
}
|
||||
EXPORT_SYMBOL(of_mdio_find_bus);
|
||||
#endif
|
||||
|
||||
static void mdiobus_stats_acct(struct mdio_bus_stats *stats, bool op, int ret)
|
||||
{
|
||||
preempt_disable();
|
||||
|
|
@ -921,92 +623,5 @@ int mdiobus_c45_modify_changed(struct mii_bus *bus, int addr, int devad,
|
|||
}
|
||||
EXPORT_SYMBOL_GPL(mdiobus_c45_modify_changed);
|
||||
|
||||
/**
|
||||
* mdio_bus_match - determine if given MDIO driver supports the given
|
||||
* MDIO device
|
||||
* @dev: target MDIO device
|
||||
* @drv: given MDIO driver
|
||||
*
|
||||
* Return: 1 if the driver supports the device, 0 otherwise
|
||||
*
|
||||
* Description: This may require calling the devices own match function,
|
||||
* since different classes of MDIO devices have different match criteria.
|
||||
*/
|
||||
static int mdio_bus_match(struct device *dev, const struct device_driver *drv)
|
||||
{
|
||||
const struct mdio_driver *mdiodrv = to_mdio_driver(drv);
|
||||
struct mdio_device *mdio = to_mdio_device(dev);
|
||||
|
||||
/* Both the driver and device must type-match */
|
||||
if (!(mdiodrv->mdiodrv.flags & MDIO_DEVICE_IS_PHY) !=
|
||||
!(mdio->flags & MDIO_DEVICE_FLAG_PHY))
|
||||
return 0;
|
||||
|
||||
if (of_driver_match_device(dev, drv))
|
||||
return 1;
|
||||
|
||||
if (mdio->bus_match)
|
||||
return mdio->bus_match(dev, drv);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int mdio_uevent(const struct device *dev, struct kobj_uevent_env *env)
|
||||
{
|
||||
int rc;
|
||||
|
||||
/* Some devices have extra OF data and an OF-style MODALIAS */
|
||||
rc = of_device_uevent_modalias(dev, env);
|
||||
if (rc != -ENODEV)
|
||||
return rc;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const struct attribute *const mdio_bus_device_statistics_attrs[] = {
|
||||
&dev_attr_mdio_bus_device_transfers.attr.attr,
|
||||
&dev_attr_mdio_bus_device_errors.attr.attr,
|
||||
&dev_attr_mdio_bus_device_writes.attr.attr,
|
||||
&dev_attr_mdio_bus_device_reads.attr.attr,
|
||||
NULL,
|
||||
};
|
||||
|
||||
static const struct attribute_group mdio_bus_device_statistics_group = {
|
||||
.name = "statistics",
|
||||
.attrs_const = mdio_bus_device_statistics_attrs,
|
||||
};
|
||||
__ATTRIBUTE_GROUPS(mdio_bus_device_statistics);
|
||||
|
||||
const struct bus_type mdio_bus_type = {
|
||||
.name = "mdio_bus",
|
||||
.dev_groups = mdio_bus_device_statistics_groups,
|
||||
.match = mdio_bus_match,
|
||||
.uevent = mdio_uevent,
|
||||
};
|
||||
EXPORT_SYMBOL(mdio_bus_type);
|
||||
|
||||
static int __init mdio_bus_init(void)
|
||||
{
|
||||
int ret;
|
||||
|
||||
ret = class_register(&mdio_bus_class);
|
||||
if (!ret) {
|
||||
ret = bus_register(&mdio_bus_type);
|
||||
if (ret)
|
||||
class_unregister(&mdio_bus_class);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void __exit mdio_bus_exit(void)
|
||||
{
|
||||
class_unregister(&mdio_bus_class);
|
||||
bus_unregister(&mdio_bus_type);
|
||||
}
|
||||
|
||||
subsys_initcall(mdio_bus_init);
|
||||
module_exit(mdio_bus_exit);
|
||||
|
||||
MODULE_LICENSE("GPL");
|
||||
MODULE_DESCRIPTION("MDIO bus/device layer");
|
||||
|
|
|
|||
|
|
@ -28,6 +28,281 @@
|
|||
#include <linux/string.h>
|
||||
#include <linux/uaccess.h>
|
||||
#include <linux/unistd.h>
|
||||
#include "phylib-internal.h"
|
||||
|
||||
/**
|
||||
* mdiobus_release - mii_bus device release callback
|
||||
* @d: the target struct device that contains the mii_bus
|
||||
*
|
||||
* Description: called when the last reference to an mii_bus is
|
||||
* dropped, to free the underlying memory.
|
||||
*/
|
||||
static void mdiobus_release(struct device *d)
|
||||
{
|
||||
struct mii_bus *bus = to_mii_bus(d);
|
||||
|
||||
WARN(bus->state != MDIOBUS_RELEASED &&
|
||||
/* for compatibility with error handling in drivers */
|
||||
bus->state != MDIOBUS_ALLOCATED,
|
||||
"%s: not in RELEASED or ALLOCATED state\n",
|
||||
bus->id);
|
||||
|
||||
if (bus->state == MDIOBUS_RELEASED)
|
||||
fwnode_handle_put(dev_fwnode(d));
|
||||
|
||||
kfree(bus);
|
||||
}
|
||||
|
||||
struct mdio_bus_stat_attr {
|
||||
struct device_attribute attr;
|
||||
int address;
|
||||
unsigned int field_offset;
|
||||
};
|
||||
|
||||
static struct mdio_bus_stat_attr *to_sattr(struct device_attribute *attr)
|
||||
{
|
||||
return container_of(attr, struct mdio_bus_stat_attr, attr);
|
||||
}
|
||||
|
||||
static u64 mdio_bus_get_stat(struct mdio_bus_stats *s, unsigned int offset)
|
||||
{
|
||||
const u64_stats_t *stats = (const void *)s + offset;
|
||||
unsigned int start;
|
||||
u64 val = 0;
|
||||
|
||||
do {
|
||||
start = u64_stats_fetch_begin(&s->syncp);
|
||||
val = u64_stats_read(stats);
|
||||
} while (u64_stats_fetch_retry(&s->syncp, start));
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
static ssize_t mdio_bus_stat_field_show(struct device *dev,
|
||||
struct device_attribute *attr,
|
||||
char *buf)
|
||||
{
|
||||
struct mdio_bus_stat_attr *sattr = to_sattr(attr);
|
||||
struct mii_bus *bus = to_mii_bus(dev);
|
||||
u64 val = 0;
|
||||
|
||||
if (sattr->address < 0) {
|
||||
/* get global stats */
|
||||
for (int i = 0; i < PHY_MAX_ADDR; i++)
|
||||
val += mdio_bus_get_stat(&bus->stats[i],
|
||||
sattr->field_offset);
|
||||
} else {
|
||||
val = mdio_bus_get_stat(&bus->stats[sattr->address],
|
||||
sattr->field_offset);
|
||||
}
|
||||
|
||||
return sysfs_emit(buf, "%llu\n", val);
|
||||
}
|
||||
|
||||
static ssize_t mdio_bus_device_stat_field_show(struct device *dev,
|
||||
struct device_attribute *attr,
|
||||
char *buf)
|
||||
{
|
||||
struct mdio_bus_stat_attr *sattr = to_sattr(attr);
|
||||
struct mdio_device *mdiodev = to_mdio_device(dev);
|
||||
struct mii_bus *bus = mdiodev->bus;
|
||||
int addr = mdiodev->addr;
|
||||
u64 val;
|
||||
|
||||
val = mdio_bus_get_stat(&bus->stats[addr], sattr->field_offset);
|
||||
|
||||
return sysfs_emit(buf, "%llu\n", val);
|
||||
}
|
||||
|
||||
#define MDIO_BUS_STATS_ATTR(field) \
|
||||
static const struct mdio_bus_stat_attr dev_attr_mdio_bus_##field = { \
|
||||
.attr = __ATTR(field, 0444, mdio_bus_stat_field_show, NULL), \
|
||||
.address = -1, \
|
||||
.field_offset = offsetof(struct mdio_bus_stats, field), \
|
||||
}; \
|
||||
static const struct mdio_bus_stat_attr dev_attr_mdio_bus_device_##field = { \
|
||||
.attr = __ATTR(field, 0444, mdio_bus_device_stat_field_show, NULL), \
|
||||
.field_offset = offsetof(struct mdio_bus_stats, field), \
|
||||
}
|
||||
|
||||
MDIO_BUS_STATS_ATTR(transfers);
|
||||
MDIO_BUS_STATS_ATTR(errors);
|
||||
MDIO_BUS_STATS_ATTR(writes);
|
||||
MDIO_BUS_STATS_ATTR(reads);
|
||||
|
||||
#define MDIO_BUS_STATS_ADDR_ATTR_DECL(field, addr, file) \
|
||||
static const struct mdio_bus_stat_attr \
|
||||
dev_attr_mdio_bus_addr_##field##_##addr = { \
|
||||
.attr = { .attr = { .name = file, .mode = 0444 }, \
|
||||
.show = mdio_bus_stat_field_show, \
|
||||
}, \
|
||||
.address = addr, \
|
||||
.field_offset = offsetof(struct mdio_bus_stats, field), \
|
||||
}
|
||||
|
||||
#define MDIO_BUS_STATS_ADDR_ATTR(field, addr) \
|
||||
MDIO_BUS_STATS_ADDR_ATTR_DECL(field, addr, \
|
||||
__stringify(field) "_" __stringify(addr))
|
||||
|
||||
#define MDIO_BUS_STATS_ADDR_ATTR_GROUP_DECL(addr) \
|
||||
MDIO_BUS_STATS_ADDR_ATTR(transfers, addr); \
|
||||
MDIO_BUS_STATS_ADDR_ATTR(errors, addr); \
|
||||
MDIO_BUS_STATS_ADDR_ATTR(writes, addr); \
|
||||
MDIO_BUS_STATS_ADDR_ATTR(reads, addr) \
|
||||
|
||||
MDIO_BUS_STATS_ADDR_ATTR_GROUP_DECL(0);
|
||||
MDIO_BUS_STATS_ADDR_ATTR_GROUP_DECL(1);
|
||||
MDIO_BUS_STATS_ADDR_ATTR_GROUP_DECL(2);
|
||||
MDIO_BUS_STATS_ADDR_ATTR_GROUP_DECL(3);
|
||||
MDIO_BUS_STATS_ADDR_ATTR_GROUP_DECL(4);
|
||||
MDIO_BUS_STATS_ADDR_ATTR_GROUP_DECL(5);
|
||||
MDIO_BUS_STATS_ADDR_ATTR_GROUP_DECL(6);
|
||||
MDIO_BUS_STATS_ADDR_ATTR_GROUP_DECL(7);
|
||||
MDIO_BUS_STATS_ADDR_ATTR_GROUP_DECL(8);
|
||||
MDIO_BUS_STATS_ADDR_ATTR_GROUP_DECL(9);
|
||||
MDIO_BUS_STATS_ADDR_ATTR_GROUP_DECL(10);
|
||||
MDIO_BUS_STATS_ADDR_ATTR_GROUP_DECL(11);
|
||||
MDIO_BUS_STATS_ADDR_ATTR_GROUP_DECL(12);
|
||||
MDIO_BUS_STATS_ADDR_ATTR_GROUP_DECL(13);
|
||||
MDIO_BUS_STATS_ADDR_ATTR_GROUP_DECL(14);
|
||||
MDIO_BUS_STATS_ADDR_ATTR_GROUP_DECL(15);
|
||||
MDIO_BUS_STATS_ADDR_ATTR_GROUP_DECL(16);
|
||||
MDIO_BUS_STATS_ADDR_ATTR_GROUP_DECL(17);
|
||||
MDIO_BUS_STATS_ADDR_ATTR_GROUP_DECL(18);
|
||||
MDIO_BUS_STATS_ADDR_ATTR_GROUP_DECL(19);
|
||||
MDIO_BUS_STATS_ADDR_ATTR_GROUP_DECL(20);
|
||||
MDIO_BUS_STATS_ADDR_ATTR_GROUP_DECL(21);
|
||||
MDIO_BUS_STATS_ADDR_ATTR_GROUP_DECL(22);
|
||||
MDIO_BUS_STATS_ADDR_ATTR_GROUP_DECL(23);
|
||||
MDIO_BUS_STATS_ADDR_ATTR_GROUP_DECL(24);
|
||||
MDIO_BUS_STATS_ADDR_ATTR_GROUP_DECL(25);
|
||||
MDIO_BUS_STATS_ADDR_ATTR_GROUP_DECL(26);
|
||||
MDIO_BUS_STATS_ADDR_ATTR_GROUP_DECL(27);
|
||||
MDIO_BUS_STATS_ADDR_ATTR_GROUP_DECL(28);
|
||||
MDIO_BUS_STATS_ADDR_ATTR_GROUP_DECL(29);
|
||||
MDIO_BUS_STATS_ADDR_ATTR_GROUP_DECL(30);
|
||||
MDIO_BUS_STATS_ADDR_ATTR_GROUP_DECL(31);
|
||||
|
||||
#define MDIO_BUS_STATS_ADDR_ATTR_GROUP(addr) \
|
||||
&(dev_attr_mdio_bus_addr_transfers_##addr).attr.attr, \
|
||||
&(dev_attr_mdio_bus_addr_errors_##addr).attr.attr, \
|
||||
&(dev_attr_mdio_bus_addr_writes_##addr).attr.attr, \
|
||||
&(dev_attr_mdio_bus_addr_reads_##addr).attr.attr \
|
||||
|
||||
static const struct attribute *const mdio_bus_statistics_attrs[] = {
|
||||
&dev_attr_mdio_bus_transfers.attr.attr,
|
||||
&dev_attr_mdio_bus_errors.attr.attr,
|
||||
&dev_attr_mdio_bus_writes.attr.attr,
|
||||
&dev_attr_mdio_bus_reads.attr.attr,
|
||||
MDIO_BUS_STATS_ADDR_ATTR_GROUP(0),
|
||||
MDIO_BUS_STATS_ADDR_ATTR_GROUP(1),
|
||||
MDIO_BUS_STATS_ADDR_ATTR_GROUP(2),
|
||||
MDIO_BUS_STATS_ADDR_ATTR_GROUP(3),
|
||||
MDIO_BUS_STATS_ADDR_ATTR_GROUP(4),
|
||||
MDIO_BUS_STATS_ADDR_ATTR_GROUP(5),
|
||||
MDIO_BUS_STATS_ADDR_ATTR_GROUP(6),
|
||||
MDIO_BUS_STATS_ADDR_ATTR_GROUP(7),
|
||||
MDIO_BUS_STATS_ADDR_ATTR_GROUP(8),
|
||||
MDIO_BUS_STATS_ADDR_ATTR_GROUP(9),
|
||||
MDIO_BUS_STATS_ADDR_ATTR_GROUP(10),
|
||||
MDIO_BUS_STATS_ADDR_ATTR_GROUP(11),
|
||||
MDIO_BUS_STATS_ADDR_ATTR_GROUP(12),
|
||||
MDIO_BUS_STATS_ADDR_ATTR_GROUP(13),
|
||||
MDIO_BUS_STATS_ADDR_ATTR_GROUP(14),
|
||||
MDIO_BUS_STATS_ADDR_ATTR_GROUP(15),
|
||||
MDIO_BUS_STATS_ADDR_ATTR_GROUP(16),
|
||||
MDIO_BUS_STATS_ADDR_ATTR_GROUP(17),
|
||||
MDIO_BUS_STATS_ADDR_ATTR_GROUP(18),
|
||||
MDIO_BUS_STATS_ADDR_ATTR_GROUP(19),
|
||||
MDIO_BUS_STATS_ADDR_ATTR_GROUP(20),
|
||||
MDIO_BUS_STATS_ADDR_ATTR_GROUP(21),
|
||||
MDIO_BUS_STATS_ADDR_ATTR_GROUP(22),
|
||||
MDIO_BUS_STATS_ADDR_ATTR_GROUP(23),
|
||||
MDIO_BUS_STATS_ADDR_ATTR_GROUP(24),
|
||||
MDIO_BUS_STATS_ADDR_ATTR_GROUP(25),
|
||||
MDIO_BUS_STATS_ADDR_ATTR_GROUP(26),
|
||||
MDIO_BUS_STATS_ADDR_ATTR_GROUP(27),
|
||||
MDIO_BUS_STATS_ADDR_ATTR_GROUP(28),
|
||||
MDIO_BUS_STATS_ADDR_ATTR_GROUP(29),
|
||||
MDIO_BUS_STATS_ADDR_ATTR_GROUP(30),
|
||||
MDIO_BUS_STATS_ADDR_ATTR_GROUP(31),
|
||||
NULL,
|
||||
};
|
||||
|
||||
static const struct attribute_group mdio_bus_statistics_group = {
|
||||
.name = "statistics",
|
||||
.attrs_const = mdio_bus_statistics_attrs,
|
||||
};
|
||||
__ATTRIBUTE_GROUPS(mdio_bus_statistics);
|
||||
|
||||
const struct class mdio_bus_class = {
|
||||
.name = "mdio_bus",
|
||||
.dev_release = mdiobus_release,
|
||||
.dev_groups = mdio_bus_statistics_groups,
|
||||
};
|
||||
|
||||
/**
|
||||
* mdio_bus_match - determine if given MDIO driver supports the given
|
||||
* MDIO device
|
||||
* @dev: target MDIO device
|
||||
* @drv: given MDIO driver
|
||||
*
|
||||
* Return: 1 if the driver supports the device, 0 otherwise
|
||||
*
|
||||
* Description: This may require calling the devices own match function,
|
||||
* since different classes of MDIO devices have different match criteria.
|
||||
*/
|
||||
static int mdio_bus_match(struct device *dev, const struct device_driver *drv)
|
||||
{
|
||||
const struct mdio_driver *mdiodrv = to_mdio_driver(drv);
|
||||
struct mdio_device *mdio = to_mdio_device(dev);
|
||||
|
||||
/* Both the driver and device must type-match */
|
||||
if (!(mdiodrv->mdiodrv.flags & MDIO_DEVICE_IS_PHY) !=
|
||||
!(mdio->flags & MDIO_DEVICE_FLAG_PHY))
|
||||
return 0;
|
||||
|
||||
if (of_driver_match_device(dev, drv))
|
||||
return 1;
|
||||
|
||||
if (mdio->bus_match)
|
||||
return mdio->bus_match(dev, drv);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int mdio_uevent(const struct device *dev, struct kobj_uevent_env *env)
|
||||
{
|
||||
int rc;
|
||||
|
||||
/* Some devices have extra OF data and an OF-style MODALIAS */
|
||||
rc = of_device_uevent_modalias(dev, env);
|
||||
if (rc != -ENODEV)
|
||||
return rc;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const struct attribute *const mdio_bus_device_statistics_attrs[] = {
|
||||
&dev_attr_mdio_bus_device_transfers.attr.attr,
|
||||
&dev_attr_mdio_bus_device_errors.attr.attr,
|
||||
&dev_attr_mdio_bus_device_writes.attr.attr,
|
||||
&dev_attr_mdio_bus_device_reads.attr.attr,
|
||||
NULL,
|
||||
};
|
||||
|
||||
static const struct attribute_group mdio_bus_device_statistics_group = {
|
||||
.name = "statistics",
|
||||
.attrs_const = mdio_bus_device_statistics_attrs,
|
||||
};
|
||||
__ATTRIBUTE_GROUPS(mdio_bus_device_statistics);
|
||||
|
||||
const struct bus_type mdio_bus_type = {
|
||||
.name = "mdio_bus",
|
||||
.dev_groups = mdio_bus_device_statistics_groups,
|
||||
.match = mdio_bus_match,
|
||||
.uevent = mdio_uevent,
|
||||
};
|
||||
|
||||
/**
|
||||
* mdiobus_alloc_size - allocate a mii_bus structure
|
||||
|
|
@ -440,3 +715,47 @@ void mdiobus_free(struct mii_bus *bus)
|
|||
put_device(&bus->dev);
|
||||
}
|
||||
EXPORT_SYMBOL(mdiobus_free);
|
||||
|
||||
/**
|
||||
* mdio_find_bus - Given the name of a mdiobus, find the mii_bus.
|
||||
* @mdio_name: The name of a mdiobus.
|
||||
*
|
||||
* Return: a reference to the mii_bus, or NULL if none found. The
|
||||
* embedded struct device will have its reference count incremented,
|
||||
* and this must be put_deviced'ed once the bus is finished with.
|
||||
*/
|
||||
struct mii_bus *mdio_find_bus(const char *mdio_name)
|
||||
{
|
||||
struct device *d;
|
||||
|
||||
d = class_find_device_by_name(&mdio_bus_class, mdio_name);
|
||||
return d ? to_mii_bus(d) : NULL;
|
||||
}
|
||||
EXPORT_SYMBOL(mdio_find_bus);
|
||||
|
||||
#if IS_ENABLED(CONFIG_OF_MDIO)
|
||||
/**
|
||||
* of_mdio_find_bus - Given an mii_bus node, find the mii_bus.
|
||||
* @mdio_bus_np: Pointer to the mii_bus.
|
||||
*
|
||||
* Return: a reference to the mii_bus, or NULL if none found. The
|
||||
* embedded struct device will have its reference count incremented,
|
||||
* and this must be put once the bus is finished with.
|
||||
*
|
||||
* Because the association of a device_node and mii_bus is made via
|
||||
* of_mdiobus_register(), the mii_bus cannot be found before it is
|
||||
* registered with of_mdiobus_register().
|
||||
*
|
||||
*/
|
||||
struct mii_bus *of_mdio_find_bus(struct device_node *mdio_bus_np)
|
||||
{
|
||||
struct device *d;
|
||||
|
||||
if (!mdio_bus_np)
|
||||
return NULL;
|
||||
|
||||
d = class_find_device_by_of_node(&mdio_bus_class, mdio_bus_np);
|
||||
return d ? to_mii_bus(d) : NULL;
|
||||
}
|
||||
EXPORT_SYMBOL(of_mdio_find_bus);
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -22,7 +22,88 @@
|
|||
#include <linux/string.h>
|
||||
#include <linux/unistd.h>
|
||||
#include <linux/property.h>
|
||||
#include "mdio-private.h"
|
||||
#include "phylib-internal.h"
|
||||
|
||||
/**
|
||||
* mdio_device_register_reset - Read and initialize the reset properties of
|
||||
* an mdio device
|
||||
* @mdiodev: mdio_device structure
|
||||
*
|
||||
* Return: Zero if successful, negative error code on failure
|
||||
*/
|
||||
static int mdio_device_register_reset(struct mdio_device *mdiodev)
|
||||
{
|
||||
struct reset_control *reset;
|
||||
|
||||
/* Deassert the optional reset signal */
|
||||
mdiodev->reset_gpio = gpiod_get_optional(&mdiodev->dev,
|
||||
"reset", GPIOD_OUT_LOW);
|
||||
if (IS_ERR(mdiodev->reset_gpio))
|
||||
return PTR_ERR(mdiodev->reset_gpio);
|
||||
|
||||
if (mdiodev->reset_gpio)
|
||||
gpiod_set_consumer_name(mdiodev->reset_gpio, "PHY reset");
|
||||
|
||||
reset = reset_control_get_optional_exclusive(&mdiodev->dev, "phy");
|
||||
if (IS_ERR(reset)) {
|
||||
gpiod_put(mdiodev->reset_gpio);
|
||||
mdiodev->reset_gpio = NULL;
|
||||
return PTR_ERR(reset);
|
||||
}
|
||||
|
||||
mdiodev->reset_ctrl = reset;
|
||||
|
||||
/* Read optional firmware properties */
|
||||
device_property_read_u32(&mdiodev->dev, "reset-assert-us",
|
||||
&mdiodev->reset_assert_delay);
|
||||
device_property_read_u32(&mdiodev->dev, "reset-deassert-us",
|
||||
&mdiodev->reset_deassert_delay);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* mdio_device_unregister_reset - uninitialize the reset properties of
|
||||
* an mdio device
|
||||
* @mdiodev: mdio_device structure
|
||||
*/
|
||||
static void mdio_device_unregister_reset(struct mdio_device *mdiodev)
|
||||
{
|
||||
gpiod_put(mdiodev->reset_gpio);
|
||||
mdiodev->reset_gpio = NULL;
|
||||
reset_control_put(mdiodev->reset_ctrl);
|
||||
mdiodev->reset_ctrl = NULL;
|
||||
mdiodev->reset_assert_delay = 0;
|
||||
mdiodev->reset_deassert_delay = 0;
|
||||
}
|
||||
|
||||
void mdio_device_reset(struct mdio_device *mdiodev, int value)
|
||||
{
|
||||
unsigned int d;
|
||||
|
||||
if (!mdiodev->reset_gpio && !mdiodev->reset_ctrl)
|
||||
return;
|
||||
|
||||
if (mdiodev->reset_state == value)
|
||||
return;
|
||||
|
||||
if (mdiodev->reset_gpio)
|
||||
gpiod_set_value_cansleep(mdiodev->reset_gpio, value);
|
||||
|
||||
if (mdiodev->reset_ctrl) {
|
||||
if (value)
|
||||
reset_control_assert(mdiodev->reset_ctrl);
|
||||
else
|
||||
reset_control_deassert(mdiodev->reset_ctrl);
|
||||
}
|
||||
|
||||
d = value ? mdiodev->reset_assert_delay : mdiodev->reset_deassert_delay;
|
||||
if (d)
|
||||
fsleep(d);
|
||||
|
||||
mdiodev->reset_state = value;
|
||||
}
|
||||
EXPORT_SYMBOL(mdio_device_reset);
|
||||
|
||||
void mdio_device_free(struct mdio_device *mdiodev)
|
||||
{
|
||||
|
|
@ -108,87 +189,39 @@ void mdio_device_remove(struct mdio_device *mdiodev)
|
|||
}
|
||||
EXPORT_SYMBOL(mdio_device_remove);
|
||||
|
||||
/**
|
||||
* mdio_device_register_reset - Read and initialize the reset properties of
|
||||
* an mdio device
|
||||
* @mdiodev: mdio_device structure
|
||||
*
|
||||
* Return: Zero if successful, negative error code on failure
|
||||
*/
|
||||
int mdio_device_register_reset(struct mdio_device *mdiodev)
|
||||
int mdiobus_register_device(struct mdio_device *mdiodev)
|
||||
{
|
||||
struct reset_control *reset;
|
||||
int err;
|
||||
|
||||
/* Deassert the optional reset signal */
|
||||
mdiodev->reset_gpio = gpiod_get_optional(&mdiodev->dev,
|
||||
"reset", GPIOD_OUT_LOW);
|
||||
if (IS_ERR(mdiodev->reset_gpio))
|
||||
return PTR_ERR(mdiodev->reset_gpio);
|
||||
if (mdiodev->bus->mdio_map[mdiodev->addr])
|
||||
return -EBUSY;
|
||||
|
||||
if (mdiodev->reset_gpio)
|
||||
gpiod_set_consumer_name(mdiodev->reset_gpio, "PHY reset");
|
||||
if (mdiodev->flags & MDIO_DEVICE_FLAG_PHY) {
|
||||
err = mdio_device_register_reset(mdiodev);
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
reset = reset_control_get_optional_exclusive(&mdiodev->dev, "phy");
|
||||
if (IS_ERR(reset)) {
|
||||
gpiod_put(mdiodev->reset_gpio);
|
||||
mdiodev->reset_gpio = NULL;
|
||||
return PTR_ERR(reset);
|
||||
/* Assert the reset signal */
|
||||
mdio_device_reset(mdiodev, 1);
|
||||
}
|
||||
|
||||
mdiodev->reset_ctrl = reset;
|
||||
|
||||
/* Read optional firmware properties */
|
||||
device_property_read_u32(&mdiodev->dev, "reset-assert-us",
|
||||
&mdiodev->reset_assert_delay);
|
||||
device_property_read_u32(&mdiodev->dev, "reset-deassert-us",
|
||||
&mdiodev->reset_deassert_delay);
|
||||
mdiodev->bus->mdio_map[mdiodev->addr] = mdiodev;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* mdio_device_unregister_reset - uninitialize the reset properties of
|
||||
* an mdio device
|
||||
* @mdiodev: mdio_device structure
|
||||
*/
|
||||
void mdio_device_unregister_reset(struct mdio_device *mdiodev)
|
||||
int mdiobus_unregister_device(struct mdio_device *mdiodev)
|
||||
{
|
||||
gpiod_put(mdiodev->reset_gpio);
|
||||
mdiodev->reset_gpio = NULL;
|
||||
reset_control_put(mdiodev->reset_ctrl);
|
||||
mdiodev->reset_ctrl = NULL;
|
||||
mdiodev->reset_assert_delay = 0;
|
||||
mdiodev->reset_deassert_delay = 0;
|
||||
if (mdiodev->bus->mdio_map[mdiodev->addr] != mdiodev)
|
||||
return -EINVAL;
|
||||
|
||||
mdio_device_unregister_reset(mdiodev);
|
||||
|
||||
mdiodev->bus->mdio_map[mdiodev->addr] = NULL;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void mdio_device_reset(struct mdio_device *mdiodev, int value)
|
||||
{
|
||||
unsigned int d;
|
||||
|
||||
if (!mdiodev->reset_gpio && !mdiodev->reset_ctrl)
|
||||
return;
|
||||
|
||||
if (mdiodev->reset_state == value)
|
||||
return;
|
||||
|
||||
if (mdiodev->reset_gpio)
|
||||
gpiod_set_value_cansleep(mdiodev->reset_gpio, value);
|
||||
|
||||
if (mdiodev->reset_ctrl) {
|
||||
if (value)
|
||||
reset_control_assert(mdiodev->reset_ctrl);
|
||||
else
|
||||
reset_control_deassert(mdiodev->reset_ctrl);
|
||||
}
|
||||
|
||||
d = value ? mdiodev->reset_assert_delay : mdiodev->reset_deassert_delay;
|
||||
if (d)
|
||||
fsleep(d);
|
||||
|
||||
mdiodev->reset_state = value;
|
||||
}
|
||||
EXPORT_SYMBOL(mdio_device_reset);
|
||||
|
||||
/**
|
||||
* mdio_probe - probe an MDIO device
|
||||
* @dev: device to probe
|
||||
|
|
|
|||
|
|
@ -3913,6 +3913,14 @@ static int __init phy_init(void)
|
|||
{
|
||||
int rc;
|
||||
|
||||
rc = class_register(&mdio_bus_class);
|
||||
if (rc)
|
||||
return rc;
|
||||
|
||||
rc = bus_register(&mdio_bus_type);
|
||||
if (rc)
|
||||
goto err_class;
|
||||
|
||||
rtnl_lock();
|
||||
ethtool_set_ethtool_phy_ops(&phy_ethtool_phy_ops);
|
||||
phylib_register_stubs();
|
||||
|
|
@ -3941,6 +3949,9 @@ static int __init phy_init(void)
|
|||
phylib_unregister_stubs();
|
||||
ethtool_set_ethtool_phy_ops(NULL);
|
||||
rtnl_unlock();
|
||||
bus_unregister(&mdio_bus_type);
|
||||
err_class:
|
||||
class_unregister(&mdio_bus_class);
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
|
@ -3953,6 +3964,8 @@ static void __exit phy_exit(void)
|
|||
phylib_unregister_stubs();
|
||||
ethtool_set_ethtool_phy_ops(NULL);
|
||||
rtnl_unlock();
|
||||
bus_unregister(&mdio_bus_type);
|
||||
class_unregister(&mdio_bus_class);
|
||||
}
|
||||
|
||||
subsys_initcall(phy_init);
|
||||
|
|
|
|||
|
|
@ -6,8 +6,12 @@
|
|||
#ifndef __PHYLIB_INTERNAL_H
|
||||
#define __PHYLIB_INTERNAL_H
|
||||
|
||||
struct mdio_device;
|
||||
struct phy_device;
|
||||
|
||||
extern const struct bus_type mdio_bus_type;
|
||||
extern const struct class mdio_bus_class;
|
||||
|
||||
/*
|
||||
* phy_supported_speeds - return all speeds currently supported by a PHY device
|
||||
*/
|
||||
|
|
@ -20,6 +24,9 @@ void of_set_phy_timing_role(struct phy_device *phydev);
|
|||
int phy_speed_down_core(struct phy_device *phydev);
|
||||
void phy_check_downshift(struct phy_device *phydev);
|
||||
|
||||
int mdiobus_register_device(struct mdio_device *mdiodev);
|
||||
int mdiobus_unregister_device(struct mdio_device *mdiodev);
|
||||
|
||||
int genphy_c45_read_eee_adv(struct phy_device *phydev, unsigned long *adv);
|
||||
|
||||
#endif /* __PHYLIB_INTERNAL_H */
|
||||
|
|
|
|||
|
|
@ -52,7 +52,7 @@ config PHY_BCM_NS_USB3
|
|||
tristate "Broadcom Northstar USB 3.0 PHY Driver"
|
||||
depends on ARCH_BCM_IPROC || COMPILE_TEST
|
||||
depends on HAS_IOMEM && OF
|
||||
depends on MDIO_BUS
|
||||
depends on PHYLIB
|
||||
select GENERIC_PHY
|
||||
help
|
||||
Enable this to support Broadcom USB 3.0 PHY connected to the USB
|
||||
|
|
@ -60,7 +60,7 @@ config PHY_BCM_NS_USB3
|
|||
|
||||
config PHY_NS2_PCIE
|
||||
tristate "Broadcom Northstar2 PCIe PHY driver"
|
||||
depends on (OF && MDIO_BUS_MUX_BCM_IPROC) || (COMPILE_TEST && MDIO_BUS)
|
||||
depends on (OF && MDIO_BUS_MUX_BCM_IPROC) || (COMPILE_TEST && PHYLIB)
|
||||
select GENERIC_PHY
|
||||
default ARCH_BCM_IPROC
|
||||
help
|
||||
|
|
|
|||
|
|
@ -688,8 +688,6 @@ static inline int mdiodev_c45_write(struct mdio_device *mdiodev, u32 devad,
|
|||
val);
|
||||
}
|
||||
|
||||
int mdiobus_register_device(struct mdio_device *mdiodev);
|
||||
int mdiobus_unregister_device(struct mdio_device *mdiodev);
|
||||
bool mdiobus_is_registered_device(struct mii_bus *bus, int addr);
|
||||
struct phy_device *mdiobus_get_phy(struct mii_bus *bus, int addr);
|
||||
|
||||
|
|
|
|||
|
|
@ -2446,9 +2446,6 @@ int __phy_hwtstamp_set(struct phy_device *phydev,
|
|||
|
||||
struct phy_port *phy_get_sfp_port(struct phy_device *phydev);
|
||||
|
||||
extern const struct bus_type mdio_bus_type;
|
||||
extern const struct class mdio_bus_class;
|
||||
|
||||
/**
|
||||
* phy_module_driver() - Helper macro for registering PHY drivers
|
||||
* @__phy_drivers: array of PHY drivers to register
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user