Received: by 2002:a05:6520:4211:b029:f4:110d:56bc with SMTP id o17csp723740lkv; Tue, 18 May 2021 18:21:59 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzZbuNwwQyr8X7W5d55iie/4Z4Mk81dmEZuOXAW09vtvog51y5Mqw5A3htYj2EOzL9i4gwb X-Received: by 2002:a05:6e02:1e05:: with SMTP id g5mr7590525ila.134.1621387318802; Tue, 18 May 2021 18:21:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621387318; cv=none; d=google.com; s=arc-20160816; b=vkpX5rR9SVDr5TL0kfio3NtuvwP5Nt5R/YO+bS2d5StxeJJQRRg7zZTvWB+CGvwdsS NeHVFk6ZUFFdKqv2gctNiLnEdGQtkJxxHD3FcaJBFZV5ulgyiPcrosbeOJe/nyd9liuu 9S7ZHOj+Gpee2JXAooyVdXXF9TdKMlNXbSjS5MZGHdf38BqJ/A29kA6bWd0QbbSzBhrr zFl9ctEfS+S+QQIcK1yR05C7fz8ZnnJz+8lL+z+vFs2zrgUplR74WjmDqhJ3jhWBXa3u ctgRzzyeI7WNTDH27Sact77rSV9fxMqlrUCptJPVOLRPUn0uOmGrkDP1dSq4EJSq2dYG J+OQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=sCTcUHfrMYU4IbYJ3Pim5sRRRlNd4hzoqkJqPSWFtA0=; b=C5t8UfGIZ9iZSarav32xwCvbr0EyJfT7Eo0MDVRLbrcTEBHrb7HXVsvMXSrWbyr8KU qJLGIqjT6Z/hI6L2Zw5Ent/qa6vt2VRm/UkLvvjg+5+kkN7qSot0y+46ws7W9qzCteHd MTe85USTSZxzThuBPTLK2GyGqva+eVRLEP6RqVbFawXIrPRakw+pgUtRgKz+aTvyBPII 05Q4hT9EADgTFsXKHozRWqiK60y188Se1PBbs0LJ4/MHEWyk+rKzhpvF9jKyvahBj4D2 uozkNBOv+nUyHNcjmtMIWvX2Yn+UMkFvtTyrIMNyKp4BJQ8rVJchioNzfPotUMS0YbYk wvHw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@svanheule.net header.s=mail1707 header.b="4x8+Ta/x"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=svanheule.net Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b12si23860342jai.103.2021.05.18.18.21.46; Tue, 18 May 2021 18:21:58 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@svanheule.net header.s=mail1707 header.b="4x8+Ta/x"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=svanheule.net Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233712AbhEQT36 (ORCPT + 99 others); Mon, 17 May 2021 15:29:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51728 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233581AbhEQT3y (ORCPT ); Mon, 17 May 2021 15:29:54 -0400 X-Greylist: delayed 38256 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Mon, 17 May 2021 12:28:37 PDT Received: from polaris.svanheule.net (polaris.svanheule.net [IPv6:2a00:c98:2060:a004:1::200]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 904D4C061573 for ; Mon, 17 May 2021 12:28:37 -0700 (PDT) Received: from terra.local.svanheule.net (unknown [IPv6:2a02:a03f:eafb:ee01:404a:340a:91cb:c07b]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: sander@svanheule.net) by polaris.svanheule.net (Postfix) with ESMTPSA id EB4441FFBF7; Mon, 17 May 2021 21:28:35 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=svanheule.net; s=mail1707; t=1621279716; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=sCTcUHfrMYU4IbYJ3Pim5sRRRlNd4hzoqkJqPSWFtA0=; b=4x8+Ta/x511RUhSXyHEnwL0IZUKRrFnlurF0qanRl1NHj82/q4FJEajvxGhF9LgkwyHVnM WXwcpC8ofjZJ710mRYrdd40nkq7niDdYLo2Lhxo/mz0AIuFnC2FgpwtQnMxwKNtB8Ee3zd gWKXKmWGyHg/5BZJauFJiEqCoFDfjsHq0uWOUpgVhsehhVd68sg3CVUZeswt1iSgKaa+yw Su8MYRzTRyWYGquz8ghBvslWwBJIB5fnJbSD6fI7VCVgnETEB+trRfH0pzD3zAZ2d9Y8k+ cNh9NghjwAYWPxsnjtVFdq2blhCSQgfVk+U3N5ZqvNavBj87F1J6yRE6dEtsSg== From: Sander Vanheule To: Pavel Machek , Rob Herring , Lee Jones , Mark Brown , Greg Kroah-Hartman , "Rafael J . Wysocki" , Michael Walle , Linus Walleij , Bartosz Golaszewski , linux-leds@vger.kernel.org, devicetree@vger.kernel.org, linux-gpio@vger.kernel.org Cc: Andrew Lunn , Andy Shevchenko , linux-kernel@vger.kernel.org, Sander Vanheule Subject: [PATCH v2 1/7] regmap: Add MDIO bus support Date: Mon, 17 May 2021 21:28:03 +0200 Message-Id: <63b99a2fec2c4ea3c461d59d451af8d675ecf312.1621279162.git.sander@svanheule.net> X-Mailer: git-send-email 2.31.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- drivers/base/regmap/Kconfig | 6 +++- drivers/base/regmap/Makefile | 1 + drivers/base/regmap/regmap-mdio.c | 57 +++++++++++++++++++++++++++++++ include/linux/regmap.h | 36 +++++++++++++++++++ 4 files changed, 99 insertions(+), 1 deletion(-) create mode 100644 drivers/base/regmap/regmap-mdio.c diff --git a/drivers/base/regmap/Kconfig b/drivers/base/regmap/Kconfig index 50b1e2d06a25..159bac6c5046 100644 --- a/drivers/base/regmap/Kconfig +++ b/drivers/base/regmap/Kconfig @@ -4,8 +4,9 @@ # subsystems should select the appropriate symbols. config REGMAP - default y if (REGMAP_I2C || REGMAP_SPI || REGMAP_SPMI || REGMAP_W1 || REGMAP_AC97 || REGMAP_MMIO || REGMAP_IRQ || REGMAP_SOUNDWIRE || REGMAP_SOUNDWIRE_MBQ || REGMAP_SCCB || REGMAP_I3C || REGMAP_SPI_AVMM) + default y if (REGMAP_I2C || REGMAP_SPI || REGMAP_SPMI || REGMAP_W1 || REGMAP_AC97 || REGMAP_MMIO || REGMAP_IRQ || REGMAP_SOUNDWIRE || REGMAP_SOUNDWIRE_MBQ || REGMAP_SCCB || REGMAP_I3C || REGMAP_SPI_AVMM || REGMAP_MDIO) select IRQ_DOMAIN if REGMAP_IRQ + select MDIO_BUS if REGMAP_MDIO bool config REGCACHE_COMPRESSED @@ -36,6 +37,9 @@ config REGMAP_W1 tristate depends on W1 +config REGMAP_MDIO + tristate + config REGMAP_MMIO tristate diff --git a/drivers/base/regmap/Makefile b/drivers/base/regmap/Makefile index 33f63adb5b3d..11facb32a027 100644 --- a/drivers/base/regmap/Makefile +++ b/drivers/base/regmap/Makefile @@ -19,3 +19,4 @@ obj-$(CONFIG_REGMAP_SOUNDWIRE_MBQ) += regmap-sdw-mbq.o obj-$(CONFIG_REGMAP_SCCB) += regmap-sccb.o obj-$(CONFIG_REGMAP_I3C) += regmap-i3c.o obj-$(CONFIG_REGMAP_SPI_AVMM) += regmap-spi-avmm.o +obj-$(CONFIG_REGMAP_MDIO) += regmap-mdio.o 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 +#include +#include +#include + +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 "); +MODULE_DESCRIPTION("Regmap MDIO Module"); +MODULE_LICENSE("GPL v2"); diff --git a/include/linux/regmap.h b/include/linux/regmap.h index f87a11a5cc4a..e97dd05f7cdb 100644 --- a/include/linux/regmap.h +++ b/include/linux/regmap.h @@ -27,6 +27,7 @@ struct device_node; struct i2c_client; struct i3c_device; struct irq_domain; +struct mdio_device; struct slim_device; struct spi_device; struct spmi_device; @@ -538,6 +539,10 @@ struct regmap *__regmap_init_i2c(struct i2c_client *i2c, const struct regmap_config *config, struct lock_class_key *lock_key, const char *lock_name); +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); struct regmap *__regmap_init_sccb(struct i2c_client *i2c, const struct regmap_config *config, struct lock_class_key *lock_key, @@ -594,6 +599,10 @@ struct regmap *__devm_regmap_init_i2c(struct i2c_client *i2c, const struct regmap_config *config, struct lock_class_key *lock_key, const char *lock_name); +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); struct regmap *__devm_regmap_init_sccb(struct i2c_client *i2c, const struct regmap_config *config, struct lock_class_key *lock_key, @@ -697,6 +706,19 @@ int regmap_attach_dev(struct device *dev, struct regmap *map, __regmap_lockdep_wrapper(__regmap_init_i2c, #config, \ i2c, config) +/** + * regmap_init_mdio() - Initialise register map + * + * @mdio_dev: Device that will be interacted with + * @config: Configuration for register map + * + * The return value will be an ERR_PTR() on error or a valid pointer to + * a struct regmap. + */ +#define regmap_init_mdio(mdio_dev, config) \ + __regmap_lockdep_wrapper(__regmap_init_mdio, #config, \ + mdio_dev, config) + /** * regmap_init_sccb() - Initialise register map * @@ -888,6 +910,20 @@ bool regmap_ac97_default_volatile(struct device *dev, unsigned int reg); __regmap_lockdep_wrapper(__devm_regmap_init_i2c, #config, \ i2c, config) +/** + * devm_regmap_init_mdio() - Initialise managed register map + * + * @mdio_dev: Device that will be interacted with + * @config: Configuration for register map + * + * The return value will be an ERR_PTR() on error or a valid pointer + * to a struct regmap. The regmap will be automatically freed by the + * device management code. + */ +#define devm_regmap_init_mdio(mdio_dev, config) \ + __regmap_lockdep_wrapper(__devm_regmap_init_mdio, #config, \ + mdio_dev, config) + /** * devm_regmap_init_sccb() - Initialise managed register map * -- 2.31.1