Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756291AbcCaK3f (ORCPT ); Thu, 31 Mar 2016 06:29:35 -0400 Received: from mail-wm0-f65.google.com ([74.125.82.65]:36828 "EHLO mail-wm0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756064AbcCaK25 (ORCPT ); Thu, 31 Mar 2016 06:28:57 -0400 From: Jan Glauber To: Wolfram Sang Cc: linux-kernel@vger.kernel.org, linux-i2c@vger.kernel.org, David Daney , Jan Glauber Subject: [PATCH v5 14/14] i2c: thunderx: Add smbus alert support Date: Thu, 31 Mar 2016 12:28:27 +0200 Message-Id: <18ef3c1552056e51b8cfcc084be249a5372100be.1459352583.git.jglauber@cavium.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: References: In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2899 Lines: 104 Add smbus alert interrupt support. Signed-off-by: Jan Glauber --- drivers/i2c/busses/i2c-cavium.h | 6 ++++++ drivers/i2c/busses/i2c-thunderx-core.c | 35 ++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/drivers/i2c/busses/i2c-cavium.h b/drivers/i2c/busses/i2c-cavium.h index 31608c4..f934624 100644 --- a/drivers/i2c/busses/i2c-cavium.h +++ b/drivers/i2c/busses/i2c-cavium.h @@ -3,6 +3,7 @@ #include #include #include +#include #include #include #include @@ -118,6 +119,11 @@ struct octeon_i2c { #if IS_ENABLED(CONFIG_I2C_THUNDERX) struct msix_entry i2c_msix; #endif + +#if IS_ENABLED(CONFIG_I2C_SMBUS) + struct i2c_smbus_alert_setup alert_data; + struct i2c_client *ara; +#endif }; static inline void writeqflush(u64 val, void __iomem *addr) diff --git a/drivers/i2c/busses/i2c-thunderx-core.c b/drivers/i2c/busses/i2c-thunderx-core.c index 2ce985b..339378a 100644 --- a/drivers/i2c/busses/i2c-thunderx-core.c +++ b/drivers/i2c/busses/i2c-thunderx-core.c @@ -9,9 +9,11 @@ #include #include #include +#include #include #include #include +#include #include #include "i2c-cavium.h" @@ -108,6 +110,35 @@ static void thunder_i2c_clock_disable(struct device *dev, struct clk *clk) devm_clk_put(dev, clk); } +static int thunder_i2c_smbus_setup(struct octeon_i2c *i2c, + struct device_node *node) +{ +#if IS_ENABLED(CONFIG_I2C_SMBUS) + u32 type; + + i2c->alert_data.irq = irq_of_parse_and_map(node, 0); + if (!i2c->alert_data.irq) + return -EINVAL; + + type = irqd_get_trigger_type(irq_get_irq_data(i2c->alert_data.irq)); + i2c->alert_data.alert_edge_triggered = + (type & IRQ_TYPE_LEVEL_MASK) ? 1 : 0; + + i2c->ara = i2c_setup_smbus_alert(&i2c->adap, &i2c->alert_data); + if (!i2c->ara) + return -ENODEV; +#endif + return 0; +} + +static void thunder_i2c_smbus_remove(struct octeon_i2c *i2c) +{ +#if IS_ENABLED(CONFIG_I2C_SMBUS) + if (i2c->ara) + i2c_unregister_device(i2c->ara); +#endif +} + static void thunder_i2c_set_name(struct pci_dev *pdev, struct octeon_i2c *i2c, char *name) { @@ -207,6 +238,9 @@ static int thunder_i2c_probe_pci(struct pci_dev *pdev, goto out_irq; } + ret = thunder_i2c_smbus_setup(i2c, node); + if (ret < 0) + dev_err(dev, "Failed to setup smbus alert\n"); dev_info(i2c->dev, "probed\n"); return 0; @@ -237,6 +271,7 @@ static void thunder_i2c_remove_pci(struct pci_dev *pdev) dev = i2c->dev; thunder_i2c_clock_disable(dev, i2c->clk); + thunder_i2c_smbus_remove(i2c); i2c_del_adapter(&i2c->adap); devm_free_irq(dev, i2c->i2c_msix.vector, i2c); pci_disable_msix(pdev); -- 1.9.1