linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jan Glauber <jglauber@cavium.com>
To: Wolfram Sang <wsa@the-dreams.de>
Cc: linux-kernel@vger.kernel.org, linux-i2c@vger.kernel.org,
	David Daney <ddaney@caviumnetworks.com>,
	Jan Glauber <jglauber@cavium.com>
Subject: [PATCH v3 14/14] i2c-thunderx: Add smbus support
Date: Mon,  7 Mar 2016 16:10:57 +0100	[thread overview]
Message-ID: <d4614b98f53d082605a9e35d25084d4a97438b34.1457362545.git.jglauber@cavium.com> (raw)
In-Reply-To: <cover.1457362545.git.jglauber@cavium.com>
In-Reply-To: <cover.1457362545.git.jglauber@cavium.com>

Add smbus alert interrupt support.

Signed-off-by: Jan Glauber <jglauber@cavium.com>
---
 drivers/i2c/busses/i2c-cavium.h        |  5 +++++
 drivers/i2c/busses/i2c-thunderx-core.c | 35 ++++++++++++++++++++++++++++++++++
 2 files changed, 40 insertions(+)

diff --git a/drivers/i2c/busses/i2c-cavium.h b/drivers/i2c/busses/i2c-cavium.h
index 739a4d3..5b66cd5 100644
--- a/drivers/i2c/busses/i2c-cavium.h
+++ b/drivers/i2c/busses/i2c-cavium.h
@@ -3,6 +3,7 @@
 #include <linux/delay.h>
 #include <linux/device.h>
 #include <linux/i2c.h>
+#include <linux/i2c-smbus.h>
 #include <linux/io.h>
 #include <linux/kernel.h>
 #include <linux/pci.h>
@@ -110,6 +111,10 @@ 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 8748d93..d50b5ec 100644
--- a/drivers/i2c/busses/i2c-thunderx-core.c
+++ b/drivers/i2c/busses/i2c-thunderx-core.c
@@ -9,10 +9,12 @@
 #include <linux/clk.h>
 #include <linux/delay.h>
 #include <linux/i2c.h>
+#include <linux/i2c-smbus.h>
 #include <linux/interrupt.h>
 #include <linux/kernel.h>
 #include <linux/module.h>
 #include <linux/pci.h>
+#include <linux/of_irq.h>
 
 #include "i2c-cavium.h"
 
@@ -107,6 +109,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)
 {
@@ -205,6 +236,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;
 
@@ -235,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);
-- 
1.9.1

      parent reply	other threads:[~2016-03-07 15:12 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-03-07 15:10 [PATCH v3 00/14] i2c-octeon and i2c-thunderx drivers Jan Glauber
2016-03-07 15:10 ` [PATCH v3 01/14] i2c-octeon: Cleanup kerneldoc comments Jan Glauber
2016-03-12 15:35   ` Wolfram Sang
2016-03-07 15:10 ` [PATCH v3 02/14] i2c-octeon: Cleanup i2c-octeon driver Jan Glauber
2016-03-12 15:35   ` Wolfram Sang
2016-03-14  8:52     ` Jan Glauber
2016-03-07 15:10 ` [PATCH v3 03/14] i2c-octeon: Cleanup resource allocation code Jan Glauber
2016-03-12 15:37   ` Wolfram Sang
2016-03-14  9:21     ` Jan Glauber
2016-03-07 15:10 ` [PATCH v3 04/14] i2c-octeon: Support I2C_M_RECV_LEN Jan Glauber
2016-03-12 15:44   ` Wolfram Sang
2016-03-07 15:10 ` [PATCH v3 05/14] i2c-octeon: Make adapter timeout tunable Jan Glauber
2016-03-12 15:46   ` Wolfram Sang
2016-03-14 12:45     ` Jan Glauber
2016-03-14 17:21       ` Swain, Peter
2016-03-07 15:10 ` [PATCH v3 06/14] i2c-octeon: Enable high-level controller and improve on bus contention Jan Glauber
2016-03-07 15:10 ` [PATCH v3 07/14] dt-bindings: i2c: Add Octeon cn78xx TWSI Jan Glauber
2016-03-07 15:10 ` [PATCH v3 08/14] i2c-octeon: Add support for cn78XX chips Jan Glauber
2016-03-07 15:10 ` [PATCH v3 09/14] i2c-octeon: Flush TWSI writes with readback Jan Glauber
2016-03-07 15:10 ` [PATCH v3 10/14] i2c-octeon: Faster operation when IFLG signals late Jan Glauber
2016-03-07 15:10 ` [PATCH v3 11/14] i2c-octeon: Add workaround for broken irqs on CN3860 Jan Glauber
2016-03-07 15:10 ` [PATCH v3 12/14] i2c-octeon: Split the driver into two parts Jan Glauber
2016-03-07 15:10 ` [PATCH v3 13/14] i2c-thunderx: Add i2c driver for ThunderX SOC Jan Glauber
2016-03-07 15:10 ` Jan Glauber [this message]

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=d4614b98f53d082605a9e35d25084d4a97438b34.1457362545.git.jglauber@cavium.com \
    --to=jglauber@cavium.com \
    --cc=ddaney@caviumnetworks.com \
    --cc=linux-i2c@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=wsa@the-dreams.de \
    /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;
as well as URLs for NNTP newsgroup(s).