mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH v2 11/11] net: ksz9477: add I2C support
Date: Wed, 11 Jan 2023 14:29:56 +0100	[thread overview]
Message-ID: <20230111132956.1153359-12-a.fatoum@pengutronix.de> (raw)
In-Reply-To: <20230111132956.1153359-1-a.fatoum@pengutronix.de>

With regmap formatting support now in place, adding I2C support is quite
trivial, so let's do it.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 drivers/net/Kconfig      |  3 ++-
 drivers/net/ksz9477.c    | 18 ++++++++++++++++--
 drivers/net/ksz_common.h |  1 +
 3 files changed, 19 insertions(+), 3 deletions(-)

diff --git a/drivers/net/Kconfig b/drivers/net/Kconfig
index a6c820690f00..2622f64651d2 100644
--- a/drivers/net/Kconfig
+++ b/drivers/net/Kconfig
@@ -308,8 +308,9 @@ config DRIVER_NET_KSZ8873
 
 config DRIVER_NET_KSZ9477
 	bool "KSZ9477 switch driver"
-	depends on SPI
+	depends on SPI || I2C
 	select REGMAP_SPI if SPI
+	select REGMAP_I2C if I2C
 	help
 	  This option enables support for the Microchip KSZ9477
 	  switch chip.
diff --git a/drivers/net/ksz9477.c b/drivers/net/ksz9477.c
index acf1e949fbe1..af394554056c 100644
--- a/drivers/net/ksz9477.c
+++ b/drivers/net/ksz9477.c
@@ -7,6 +7,7 @@
 #include <net.h>
 #include <platform_data/ksz9477_reg.h>
 #include <spi/spi.h>
+#include <i2c/i2c.h>
 #include "ksz_common.h"
 
 /* SPI frame opcodes */
@@ -22,6 +23,7 @@
 
 KSZ_REGMAP_TABLE(ksz9477_spi, 32, SPI_ADDR_SHIFT,
 		 SPI_TURNAROUND_SHIFT, SPI_ADDR_ALIGN);
+KSZ_REGMAP_TABLE(ksz9477_i2c, not_used, 16, 0, 0);
 
 static int ksz9477_phy_read16(struct dsa_switch *ds, int addr, int reg)
 {
@@ -388,10 +390,13 @@ static int microchip_switch_regmap_init(struct ksz_switch *priv)
 	const struct regmap_config *cfg;
 	int i;
 
-	cfg = ksz9477_spi_regmap_config;
+	cfg = priv->spi ? ksz9477_spi_regmap_config : ksz9477_i2c_regmap_config;
 
 	for (i = 0; i < KSZ_REGMAP_ENTRY_COUNT; i++) {
-		priv->regmap[i] = regmap_init_spi(priv->spi, &cfg[i]);
+		if (priv->spi)
+			priv->regmap[i] = regmap_init_spi(priv->spi, &cfg[i]);
+		else
+			priv->regmap[i] = regmap_init_i2c(priv->i2c, &cfg[i]);
 		if (IS_ERR(priv->regmap[i]))
 			return dev_err_probe(priv->dev, PTR_ERR(priv->regmap[i]),
 					     "Failed to initialize regmap%i\n",
@@ -418,6 +423,9 @@ static int microchip_switch_probe(struct device *dev)
 		priv->spi->mode = SPI_MODE_0;
 		priv->spi->bits_per_word = 8;
 		hw_dev = &priv->spi->dev;
+	} else if (dev_bus_is_i2c(dev)) {
+		priv->i2c = dev->type_data;
+		hw_dev = &priv->i2c->dev;
 	}
 
 	ret = microchip_switch_regmap_init(priv);
@@ -475,3 +483,9 @@ static struct driver microchip_switch_spi_driver = {
 };
 device_spi_driver(microchip_switch_spi_driver);
 
+static struct driver microchip_switch_i2c_driver = {
+	.name		= "ksz9477-i2c",
+	.probe		= microchip_switch_probe,
+	.of_compatible	= DRV_OF_COMPAT(microchip_switch_dt_ids),
+};
+device_i2c_driver(microchip_switch_i2c_driver);
diff --git a/drivers/net/ksz_common.h b/drivers/net/ksz_common.h
index 01447b61419e..995054d6e8c6 100644
--- a/drivers/net/ksz_common.h
+++ b/drivers/net/ksz_common.h
@@ -9,6 +9,7 @@
 
 struct ksz_switch {
 	struct spi_device *spi;
+	struct i2c_client *i2c;
 	struct dsa_switch ds;
 	struct device *dev;
 	int phy_port_cnt;
-- 
2.30.2




  parent reply	other threads:[~2023-01-11 13:32 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-11 13:29 [PATCH v2 00/11] net: dsa: ksz9477: use regmap to add I2C support next to SPI Ahmad Fatoum
2023-01-11 13:29 ` [PATCH v2 01/11] regmap: consolidate reg/val format into regmap_format Ahmad Fatoum
2023-01-11 13:29 ` [PATCH v2 02/11] regmap: support formatted read and write Ahmad Fatoum
2023-01-11 13:29 ` [PATCH v2 03/11] regmap: port regmap_init_spi Ahmad Fatoum
2023-01-11 13:29 ` [PATCH v2 04/11] regmap: factor out regmap cdev size calculation Ahmad Fatoum
2023-01-11 13:29 ` [PATCH v2 05/11] net: dsa: ksz9477: switch to regmap_init_spi Ahmad Fatoum
2023-01-11 13:29 ` [PATCH v2 06/11] net: dsa: ksz9477: create regmap cdev for switch registers Ahmad Fatoum
2023-01-11 13:29 ` [PATCH v2 07/11] drivers: base: regmap: introduce REGMAP_I2C Ahmad Fatoum
2023-01-11 13:29 ` [PATCH v2 08/11] dev: add dev_bus_is_spi/i2c helpers Ahmad Fatoum
2023-01-11 13:29 ` [PATCH v2 09/11] net: dsa: ksz9477: refactor to prepare i2c support Ahmad Fatoum
2023-01-11 13:29 ` [PATCH v2 10/11] regmap: i2c: use formatted I/O Ahmad Fatoum
2023-01-11 13:29 ` Ahmad Fatoum [this message]
2023-01-12 14:58 ` [PATCH v2 00/11] net: dsa: ksz9477: use regmap to add I2C support next to SPI Sascha Hauer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230111132956.1153359-12-a.fatoum@pengutronix.de \
    --to=a.fatoum@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox