From patchwork Wed Jun 15 13:51:30 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Glauber X-Patchwork-Id: 635880 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3rV7Ht53tYz9t19 for ; Wed, 15 Jun 2016 23:52:42 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932130AbcFONwk (ORCPT ); Wed, 15 Jun 2016 09:52:40 -0400 Received: from mail-qg0-f68.google.com ([209.85.192.68]:32855 "EHLO mail-qg0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933045AbcFONwF (ORCPT ); Wed, 15 Jun 2016 09:52:05 -0400 Received: by mail-qg0-f68.google.com with SMTP id 34so1701524qgf.0; Wed, 15 Jun 2016 06:51:59 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=9ywUIAC+t4G8GOGB/iqEAyqdZWbRQkk4GVeu8UejxKM=; b=SUJfMxvOOlMO4IX1ajSyQWI5zZxkdxCUD0ito95+wAzzZM2dVdI7xTRqFTk29+fRXy 2tK3OEhBqBqxyuLB/wz7X996DrIPnsulAt+auYPIwRt5aH3thpLKn0fu+kqM2sHxOLqy k6sqF1kxNwa10gkCPzdx1myuhA8G/AY/c7gYsGUnwoauufYQol9t04u6nXhrE7/cO5Ri T8mS/RrEZbups5A23EUHlF83TdUeUgoYl2bi90gBvj9lQI/qcWOM+xroMv8EXQpJoRFN 80co/VmIlLmCqH75z4sWDOSq98mqRRlyE903eFmjACep3Wxr12nQ6bvcxXFQYE6BLUlg MGww== X-Gm-Message-State: ALyK8tJcQtQt8X8Ob9mW2KpXOi3p1QXjv6gP3qRkbfAr4stQSgZF4i6ZlGyzUdULIE83Qw== X-Received: by 10.28.214.73 with SMTP id n70mr11629862wmg.13.1465998718748; Wed, 15 Jun 2016 06:51:58 -0700 (PDT) Received: from wintermute.fritz.box (HSI-KBW-109-193-044-240.hsi7.kabel-badenwuerttemberg.de. [109.193.44.240]) by smtp.gmail.com with ESMTPSA id el4sm5875393wjd.23.2016.06.15.06.51.58 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 15 Jun 2016 06:51:58 -0700 (PDT) From: Jan Glauber To: Wolfram Sang Cc: linux-kernel@vger.kernel.org, linux-i2c@vger.kernel.org, David Daney , Steven.Hill@caviumnetworks.com, Jan Glauber Subject: [PATCH v10 4/8] i2c: thunderx: Add SMBUS alert support Date: Wed, 15 Jun 2016 15:51:30 +0200 Message-Id: <4ba9512e145ee8d303393874a0033ed83ae33a8f.1465997604.git.jglauber@cavium.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: References: In-Reply-To: References: Sender: linux-i2c-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org Add SMBUS alert interrupt support. For now only device tree is supported for specifying the alert. In case of ACPI an error is returned. Signed-off-by: Jan Glauber --- drivers/i2c/busses/i2c-cavium.h | 6 ++++ drivers/i2c/busses/i2c-thunderx-core.c | 51 ++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+) diff --git a/drivers/i2c/busses/i2c-cavium.h b/drivers/i2c/busses/i2c-cavium.h index 33c7e1f..9c128c1 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 @@ -119,6 +120,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 octeon_i2c_writeq_flush(u64 val, void __iomem *addr) diff --git a/drivers/i2c/busses/i2c-thunderx-core.c b/drivers/i2c/busses/i2c-thunderx-core.c index 6b830b5..d68ce08 100644 --- a/drivers/i2c/busses/i2c-thunderx-core.c +++ b/drivers/i2c/busses/i2c-thunderx-core.c @@ -10,9 +10,11 @@ #include #include #include +#include #include #include #include +#include #include #include "i2c-cavium.h" @@ -106,6 +108,51 @@ static void thunder_i2c_clock_disable(struct device *dev, struct clk *clk) devm_clk_put(dev, clk); } +#if IS_ENABLED(CONFIG_I2C_SMBUS) +static int thunder_i2c_smbus_setup_of(struct octeon_i2c *i2c, + struct device_node *node) +{ + u32 type; + + if (!node) + return -EINVAL; + + 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; + return 0; +} +#endif + +static int thunder_i2c_smbus_setup(struct octeon_i2c *i2c, + struct device_node *node) +{ +#if IS_ENABLED(CONFIG_I2C_SMBUS) + /* TODO: ACPI support */ + if (!acpi_disabled) + return -EOPNOTSUPP; + + return thunder_i2c_smbus_setup_of(i2c, node); +#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 int thunder_i2c_probe_pci(struct pci_dev *pdev, const struct pci_device_id *ent) { @@ -189,6 +236,9 @@ static int thunder_i2c_probe_pci(struct pci_dev *pdev, goto out_irq; } + ret = thunder_i2c_smbus_setup(i2c, pdev->dev.of_node); + if (ret < 0) + dev_info(dev, "SMBUS alert not active on this bus\n"); dev_info(i2c->dev, "probed\n"); return 0; @@ -219,6 +269,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);