diff options
author | Sander Vanheule <sander@svanheule.net> | 2021-05-17 21:28:03 +0200 |
---|---|---|
committer | Mark Brown <broonie@kernel.org> | 2021-05-19 14:19:10 +0100 |
commit | 1f89d2fe16072a74b34bdb895160910091427891 (patch) | |
tree | 74d11349d77590477b8b85ae3748058328900382 /drivers/base/regmap/regmap-mdio.c | |
parent | 6efb943b8616ec53a5e444193dccf1af9ad627b5 (diff) | |
download | lwn-1f89d2fe16072a74b34bdb895160910091427891.tar.gz lwn-1f89d2fe16072a74b34bdb895160910091427891.zip |
regmap: Add MDIO bus support
Basic support for MDIO bus access. Support only includes clause-22
register access, with 5-bit addresses, and 16-bit wide registers.
Signed-off-by: Sander Vanheule <sander@svanheule.net>
Link: https://lore.kernel.org/r/63b99a2fec2c4ea3c461d59d451af8d675ecf312.1621279162.git.sander@svanheule.net
Signed-off-by: Mark Brown <broonie@kernel.org>
Diffstat (limited to 'drivers/base/regmap/regmap-mdio.c')
-rw-r--r-- | drivers/base/regmap/regmap-mdio.c | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/drivers/base/regmap/regmap-mdio.c b/drivers/base/regmap/regmap-mdio.c new file mode 100644 index 000000000000..5f18fe409f56 --- /dev/null +++ b/drivers/base/regmap/regmap-mdio.c @@ -0,0 +1,57 @@ +// SPDX-License-Identifier: GPL-2.0 + +#include <linux/errno.h> +#include <linux/mdio.h> +#include <linux/module.h> +#include <linux/regmap.h> + +static int regmap_mdio_read(void *context, unsigned int reg, unsigned int *val) +{ + struct mdio_device *mdio_dev = context; + int ret; + + ret = mdiobus_read(mdio_dev->bus, mdio_dev->addr, reg); + *val = ret & 0xffff; + + return ret < 0 ? ret : 0; +} + +static int regmap_mdio_write(void *context, unsigned int reg, unsigned int val) +{ + struct mdio_device *mdio_dev = context; + + return mdiobus_write(mdio_dev->bus, mdio_dev->addr, reg, val); +} + +static const struct regmap_bus regmap_mdio_bus = { + .reg_write = regmap_mdio_write, + .reg_read = regmap_mdio_read, +}; + +struct regmap *__regmap_init_mdio(struct mdio_device *mdio_dev, + const struct regmap_config *config, struct lock_class_key *lock_key, + const char *lock_name) +{ + if (config->reg_bits != 5 || config->val_bits != 16) + return ERR_PTR(-EOPNOTSUPP); + + return __regmap_init(&mdio_dev->dev, ®map_mdio_bus, mdio_dev, config, + lock_key, lock_name); +} +EXPORT_SYMBOL_GPL(__regmap_init_mdio); + +struct regmap *__devm_regmap_init_mdio(struct mdio_device *mdio_dev, + const struct regmap_config *config, struct lock_class_key *lock_key, + const char *lock_name) +{ + if (config->reg_bits != 5 || config->val_bits != 16) + return ERR_PTR(-EOPNOTSUPP); + + return __devm_regmap_init(&mdio_dev->dev, ®map_mdio_bus, mdio_dev, + config, lock_key, lock_name); +} +EXPORT_SYMBOL_GPL(__devm_regmap_init_mdio); + +MODULE_AUTHOR("Sander Vanheule <sander@svanheule.net>"); +MODULE_DESCRIPTION("Regmap MDIO Module"); +MODULE_LICENSE("GPL v2"); |