From mboxrd@z Thu Jan 1 00:00:00 1970 Delivery-date: Wed, 11 Jan 2023 14:32:01 +0100 Received: from metis.ext.pengutronix.de ([2001:67c:670:201:290:27ff:fe1d:cc33]) by lore.white.stw.pengutronix.de with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1pFbD0-008r5h-HZ for lore@lore.pengutronix.de; Wed, 11 Jan 2023 14:32:01 +0100 Received: from bombadil.infradead.org ([2607:7c80:54:3::133]) by metis.ext.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pFbCy-0002U5-2U for lore@pengutronix.de; Wed, 11 Jan 2023 14:32:01 +0100 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=E4TBYly6sH5AlVRzcxaTBIy0LbYBHf88mnxrI3v4t3k=; b=Mh9ydQ5la6Rf2faGJAdmojV2gR UtcFX6pWM/13sE8Ggc8lgX5tka4/iBE5+NbLHhDfmBHVfTvGZmaXYt8FrGZ98qNxdrE6CIXWC6QTZ xSQt1+aH0NEg1eL5Yhwh/UdpxN3nvBD0xKmdEibqe5U6b3gO6iVpR2ctIMzlUEjuTYvsHTqOA393j ++4b3gyFWP7lORLSzOpksGbgGFy5C4fnsqSgSvDsY3zWJbBXHQiQE6E6fk2fTd/eGNu3qeXPacbRE uU4kfc5QvEyu8xFfE4g9boJDv1yKdNuO+xO/0RcIyj34EhrWb5RnbEi9oHdW92DEgcL7mrs30BBsQ tKlApwDA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pFbBQ-00BZkE-79; Wed, 11 Jan 2023 13:30:24 +0000 Received: from metis.ext.pengutronix.de ([2001:67c:670:201:290:27ff:fe1d:cc33]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pFbB7-00BZaN-Gf for barebox@lists.infradead.org; Wed, 11 Jan 2023 13:30:09 +0000 Received: from drehscheibe.grey.stw.pengutronix.de ([2a0a:edc0:0:c01:1d::a2]) by metis.ext.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pFbB3-0001g1-S2; Wed, 11 Jan 2023 14:30:01 +0100 Received: from [2a0a:edc0:0:1101:1d::ac] (helo=dude04.red.stw.pengutronix.de) by drehscheibe.grey.stw.pengutronix.de with esmtp (Exim 4.94.2) (envelope-from ) id 1pFbB3-005JQG-5F; Wed, 11 Jan 2023 14:30:01 +0100 Received: from afa by dude04.red.stw.pengutronix.de with local (Exim 4.94.2) (envelope-from ) id 1pFbB1-004rr7-Mf; Wed, 11 Jan 2023 14:29:59 +0100 From: Ahmad Fatoum To: barebox@lists.infradead.org Cc: Ahmad Fatoum Date: Wed, 11 Jan 2023 14:29:56 +0100 Message-Id: <20230111132956.1153359-12-a.fatoum@pengutronix.de> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230111132956.1153359-1-a.fatoum@pengutronix.de> References: <20230111132956.1153359-1-a.fatoum@pengutronix.de> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230111_053005_689514_19727095 X-CRM114-Status: GOOD ( 17.79 ) X-BeenThere: barebox@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "barebox" X-SA-Exim-Connect-IP: 2607:7c80:54:3::133 X-SA-Exim-Mail-From: barebox-bounces+lore=pengutronix.de@lists.infradead.org X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on metis.ext.pengutronix.de X-Spam-Level: X-Spam-Status: No, score=-4.7 required=4.0 tests=AWL,BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_NONE autolearn=unavailable autolearn_force=no version=3.4.2 Subject: [PATCH v2 11/11] net: ksz9477: add I2C support X-SA-Exim-Version: 4.2.1 (built Wed, 08 May 2019 21:11:16 +0000) X-SA-Exim-Scanned: Yes (on metis.ext.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 --- 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 #include #include +#include #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