From patchwork Thu Dec 3 10:21:12 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Eggers X-Patchwork-Id: 11948337 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1D8EAC64E7B for ; Thu, 3 Dec 2020 10:26:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B20B022244 for ; Thu, 3 Dec 2020 10:26:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730265AbgLCKZz (ORCPT ); Thu, 3 Dec 2020 05:25:55 -0500 Received: from mailout01.rmx.de ([94.199.90.91]:34572 "EHLO mailout01.rmx.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730192AbgLCKZy (ORCPT ); Thu, 3 Dec 2020 05:25:54 -0500 Received: from kdin02.retarus.com (kdin02.dmz1.retloc [172.19.17.49]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mailout01.rmx.de (Postfix) with ESMTPS id 4CmsR81v57z2SX3Q; Thu, 3 Dec 2020 11:25:08 +0100 (CET) Received: from mta.arri.de (unknown [217.111.95.66]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by kdin02.retarus.com (Postfix) with ESMTPS id 4CmsQJ1jTZz2TTL5; Thu, 3 Dec 2020 11:24:24 +0100 (CET) Received: from N95HX1G2.wgnetz.xx (192.168.54.174) by mta.arri.de (192.168.100.104) with Microsoft SMTP Server (TLS) id 14.3.487.0; Thu, 3 Dec 2020 11:23:44 +0100 From: Christian Eggers To: Vladimir Oltean , Jakub Kicinski , Andrew Lunn , Richard Cochran , "Rob Herring" CC: Vivien Didelot , "David S . Miller" , Kurt Kanzenbach , George McCollister , Marek Vasut , Helmut Grohne , Paul Barker , Codrin Ciubotariu , Tristram Ha , Woojung Huh , Microchip Linux Driver Support , Christian Eggers , , , Subject: [PATCH net-next v5 4/9] net: dsa: microchip: ksz9477: basic interrupt support Date: Thu, 3 Dec 2020 11:21:12 +0100 Message-ID: <20201203102117.8995-5-ceggers@arri.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20201203102117.8995-1-ceggers@arri.de> References: <20201203102117.8995-1-ceggers@arri.de> MIME-Version: 1.0 X-Originating-IP: [192.168.54.174] X-RMX-ID: 20201203-112424-NLSCxzcZDpWs-0@out02.hq X-RMX-SOURCE: 217.111.95.66 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org Interrupts are required for TX time stamping. Probably they could also be used for PHY connection status. This patch only adds the basic infrastructure for interrupts, no interrupts are finally enabled nor handled. Signed-off-by: Christian Eggers Reviewed-by: Vladimir Oltean --- Changes in v4: -------------- - s/low active/active low/ - Reviewed-by: Vladimir Oltean drivers/net/dsa/microchip/ksz9477_i2c.c | 2 + drivers/net/dsa/microchip/ksz9477_main.c | 68 ++++++++++++++++++++++++ drivers/net/dsa/microchip/ksz9477_spi.c | 2 + drivers/net/dsa/microchip/ksz_common.h | 1 + 4 files changed, 73 insertions(+) diff --git a/drivers/net/dsa/microchip/ksz9477_i2c.c b/drivers/net/dsa/microchip/ksz9477_i2c.c index 4e053a25d077..4ed1f503044a 100644 --- a/drivers/net/dsa/microchip/ksz9477_i2c.c +++ b/drivers/net/dsa/microchip/ksz9477_i2c.c @@ -41,6 +41,8 @@ static int ksz9477_i2c_probe(struct i2c_client *i2c, if (i2c->dev.platform_data) dev->pdata = i2c->dev.platform_data; + dev->irq = i2c->irq; + ret = ksz9477_switch_register(dev); /* Main DSA driver may not be started yet. */ diff --git a/drivers/net/dsa/microchip/ksz9477_main.c b/drivers/net/dsa/microchip/ksz9477_main.c index 681e752919ac..f869041e3be0 100644 --- a/drivers/net/dsa/microchip/ksz9477_main.c +++ b/drivers/net/dsa/microchip/ksz9477_main.c @@ -5,9 +5,12 @@ * Copyright (C) 2017-2019 Microchip Technology Inc. */ +#include #include #include +#include #include +#include #include #include #include @@ -1524,6 +1527,54 @@ static const struct ksz_chip_data ksz9477_switch_chips[] = { }, }; +static irqreturn_t ksz9477_switch_irq_thread(int irq, void *dev_id) +{ + struct ksz_device *dev = dev_id; + u32 data; + int port; + int ret; + + /* Read global port interrupt status register */ + ret = ksz_read32(dev, REG_SW_PORT_INT_STATUS__4, &data); + if (ret) + return IRQ_NONE; + + for (port = 0; port < dev->port_cnt; port++) { + u8 data8; + + if (!(data & BIT(port))) + continue; + + /* Read port interrupt status register */ + ret = ksz_read8(dev, PORT_CTRL_ADDR(port, REG_PORT_INT_STATUS), + &data8); + if (ret) + return IRQ_NONE; + + /* ToDo: Add specific handling of port interrupts */ + } + + return IRQ_NONE; +} + +static int ksz9477_enable_port_interrupts(struct ksz_device *dev, bool enable) +{ + u32 data, mask = GENMASK(dev->port_cnt - 1, 0); + int ret; + + ret = ksz_read32(dev, REG_SW_PORT_INT_MASK__4, &data); + if (ret) + return ret; + + /* bits in REG_SW_PORT_INT_MASK__4 are active low */ + if (enable) + data &= ~mask; + else + data |= mask; + + return ksz_write32(dev, REG_SW_PORT_INT_MASK__4, data); +} + static int ksz9477_switch_init(struct ksz_device *dev) { int i, ret; @@ -1579,12 +1630,29 @@ static int ksz9477_switch_init(struct ksz_device *dev) /* set the real number of ports */ dev->ds->num_ports = dev->port_cnt; + if (dev->irq > 0) { + ret = devm_request_threaded_irq(dev->dev, dev->irq, NULL, + ksz9477_switch_irq_thread, + IRQF_ONESHOT | IRQF_SHARED, + dev_name(dev->dev), + dev); + if (ret) { + dev_err(dev->dev, "failed to request IRQ.\n"); + return ret; + } + + ret = ksz9477_enable_port_interrupts(dev, true); + if (ret) + return ret; + } return 0; } static void ksz9477_switch_exit(struct ksz_device *dev) { + if (dev->irq > 0) + ksz9477_enable_port_interrupts(dev, false); ksz9477_reset_switch(dev); } diff --git a/drivers/net/dsa/microchip/ksz9477_spi.c b/drivers/net/dsa/microchip/ksz9477_spi.c index 15bc11b3cda4..fc0ac9e2c56d 100644 --- a/drivers/net/dsa/microchip/ksz9477_spi.c +++ b/drivers/net/dsa/microchip/ksz9477_spi.c @@ -48,6 +48,8 @@ static int ksz9477_spi_probe(struct spi_device *spi) if (spi->dev.platform_data) dev->pdata = spi->dev.platform_data; + dev->irq = spi->irq; + /* setup spi */ spi->mode = SPI_MODE_3; ret = spi_setup(spi); diff --git a/drivers/net/dsa/microchip/ksz_common.h b/drivers/net/dsa/microchip/ksz_common.h index 720f22275c84..ac6914d361c8 100644 --- a/drivers/net/dsa/microchip/ksz_common.h +++ b/drivers/net/dsa/microchip/ksz_common.h @@ -55,6 +55,7 @@ struct ksz_device { struct device *dev; struct regmap *regmap[3]; + int irq; void *priv;