Skip to contentSkip to conversation

i2c: axxia: Add I2C driver for AXM55xx

PATCH Superseded Anders Berg 4 participants 11 messages Aug 25, 2014 – Sep 22, 2014

Subsystems (2)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 i2c: axxia: Add I2C driver for AXM55xx

Add I2C bus driver for the controller found in the LSI Axxia family SoCs. The driver implements 10-bit addressing and SMBus transfer modes via emulation (including SMBus block data read).

---
 .../devicetree/bindings/i2c/i2c-axxia.txt          |  30 ++
 drivers/i2c/busses/Kconfig                         |   9 +
 drivers/i2c/busses/Makefile                        |   1 +
 drivers/i2c/busses/i2c-axxia.c                     | 591 +++++++++++++++++++++
 4 files changed, 631 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/i2c/i2c-axxia.txt
 create mode 100644 drivers/i2c/busses/i2c-axxia.c
Documentation/devicetree/bindings/i2c/i2c-axxia.txt new file +30 -0
new file mode 100644
index 0000000..2296d78
@@ -0,0 +1,30 @@
+LSI Axxia I2C
+
+Required properties :
+- compatible : Must be "lsi,api2c"
+- reg : Offset and length of the register set for the device
+- interrupts : the interrupt specifier
+- #address-cells : Must be <1>;
+- #size-cells : Must be <0>;
+- clock-names : Must contain "i2c".
+- clocks: Must contain an entry for each name in clock-names. See the common
+  clock bindings.
+
+Optional properties :
+- clock-frequency : Desired I2C bus clock frequency in Hz. If not specified,
+  the default 100 kHz frequency will be used. As only Normal and Fast modes
+  are supported, possible values are 100000 and 400000.
+
+Example :
+
+i2c at 02010084000 {
+	compatible = "lsi,api2c";
+	device_type = "i2c";
+	#address-cells = <1>;
+	#size-cells = <0>;
+	reg = <0x20 0x10084000 0x00 0x1000>;
+	interrupts = <0 19 4>;
+	clocks = <&clk_per>;
+	clock-names = "i2c";
+	clock-frequency = <400000>;
+};
drivers/i2c/busses/Kconfig +9 -0
index 2ac87fa..7f7bf8f 100644
@@ -77,6 +77,15 @@ config I2C_AMD8111
 	  This driver can also be built as a module.  If so, the module
 	  will be called i2c-amd8111.
 
+config I2C_AXXIA
+	tristate "Axxia I2C controller"
+	depends on ARCH_AXXIA
+	help
+	  Say yes if you want to support the I2C bus on Axxia platforms.
+
+	  If you don't know, say Y.
+
+
 config I2C_I801
 	tristate "Intel 82801 (ICH/PCH)"
 	depends on PCI
drivers/i2c/busses/Makefile +1 -0
index 49bf07e..5899edb 100644
@@ -12,6 +12,7 @@ obj-$(CONFIG_I2C_ALI15X3)	+= i2c-ali15x3.o
 obj-$(CONFIG_I2C_AMD756)	+= i2c-amd756.o
 obj-$(CONFIG_I2C_AMD756_S4882)	+= i2c-amd756-s4882.o
 obj-$(CONFIG_I2C_AMD8111)	+= i2c-amd8111.o
+obj-$(CONFIG_I2C_AXXIA)		+= i2c-axxia.o
 obj-$(CONFIG_I2C_I801)		+= i2c-i801.o
 obj-$(CONFIG_I2C_ISCH)		+= i2c-isch.o
 obj-$(CONFIG_I2C_ISMT)		+= i2c-ismt.o
drivers/i2c/busses/i2c-axxia.c new file +591 -0

591 lines not on this page · raw message

Signature · 1 line
1.9.1
#1 lore raw

Hi,

thanks for the submission.

Quoted 5 lines · Anders Berg

Add I2C bus driver for the controller found in the LSI Axxia family SoCs. The driver implements 10-bit addressing and SMBus transfer modes via emulation (including SMBus block data read).

Looks pretty good already. Still, some comments:

drivers/i2c/busses/Kconfig config I2C_AMD8111 · line 86

Quoted 7 lines
drivers/i2c/busses/Kconfig +7 -0
+config I2C_AXXIA
+	tristate "Axxia I2C controller"
+	depends on ARCH_AXXIA
+	help
+	  Say yes if you want to support the I2C bus on Axxia platforms.
+
+	  If you don't know, say Y.

I'd say skip this sentence and consider 'default y' if it is really needed on this platform.

drivers/i2c/busses/i2c-axxia.c line 2

Quoted 8 lines
drivers/i2c/busses/i2c-axxia.c new file +2 -0
new file mode 100644
index 0000000..e6c9b88
@@ -0,0 +1,591 @@
+/*
+ * drivers/i2c/busses/i2c-axxia.c

No pathnames please, they might get stale.

Quoted 8 lines
drivers/i2c/busses/i2c-axxia.c new file +8 -0
+ *
+ * This driver implements I2C master functionality using the LSI API2C
+ * controller.
+ *
+ * This software is licensed under the terms of the GNU General Public
+ * License version 2, as published by the Free Software Foundation, and
+ * may be copied, distributed, and modified under those terms.
+ */

drivers/i2c/busses/i2c-axxia.c line 20

Quoted 10 lines
drivers/i2c/busses/i2c-axxia.c new file +10 -0
+#include <linux/clk.h>
+#include <linux/clkdev.h>
+#include <linux/err.h>
+#include <linux/i2c.h>
+#include <linux/init.h>
+#include <linux/interrupt.h>
+#include <linux/module.h>
+#include <linux/io.h>
+#include <linux/kernel.h>
+#include <linux/platform_device.h>

At least of.h, too?

Quoted 15 lines
drivers/i2c/busses/i2c-axxia.c new file +15 -0
+
+#define SCL_WAIT_TIMEOUT_NS 25000000
+#define I2C_XFER_TIMEOUT    (msecs_to_jiffies(250))
+#define I2C_STOP_TIMEOUT    (msecs_to_jiffies(100))
+#define FIFO_SIZE           8
+
+#define GLOBAL_CONTROL		0x00
+#define   GLOBAL_MST_EN         BIT(0)
+#define   GLOBAL_SLV_EN         BIT(1)
+#define   GLOBAL_IBML_EN        BIT(2)
+#define INTERRUPT_STATUS	0x04
+#define INTERRUPT_ENABLE	0x08
+#define   INT_SLV               BIT(1)
+#define   INT_MST               BIT(0)
+#define WAIT_TIMER_CONTROL	0x0c

drivers/i2c/busses/i2c-axxia.c line 45

Quoted 10 lines
drivers/i2c/busses/i2c-axxia.c new file +10 -0
+#define   WT_EN			BIT(15)
+#define   WT_VALUE(_x)		((_x) & 0x7fff)
+#define IBML_TIMEOUT		0x10
+#define IBML_LOW_MEXT		0x14
+#define IBML_LOW_SEXT		0x18
+#define TIMER_CLOCK_DIV		0x1c
+#define I2C_BUS_MONITOR		0x20
+#define SOFT_RESET		0x24
+#define MST_COMMAND		0x28
+#define   CMD_BUSY		(1<<3)

The whole driver has 'spaces around operator' issues, please fix them.

...

drivers/i2c/busses/i2c-axxia.c line 47

Quoted 2 lines
drivers/i2c/busses/i2c-axxia.c new file +2 -0
+	/* Find the prescaler value that makes tmo_clk fit in 15-bits counter.
+	 */

Minor: Make this a one line comment. Better readable.

...

drivers/i2c/busses/i2c-axxia.c line 238

Quoted 12 lines
drivers/i2c/busses/i2c-axxia.c new file +12 -0
+/**
+ * axxia_i2c_empty_rx_fifo - Fetch data from RX FIFO and update SMBus block
+ * transfer length if this is the first byte of such a transfer.
+ */
+static int
+axxia_i2c_empty_rx_fifo(struct axxia_i2c_dev *idev)
+{
+	struct i2c_msg *msg = idev->msg;
+	size_t rx_fifo_avail = readl(idev->base + MST_RX_FIFO);
+	int bytes_to_transfer = min(rx_fifo_avail, msg->len - idev->msg_xfrd);
+
+	while (0 < bytes_to_transfer--) {

Please put constants on the right side. Reading this is very twisting.

drivers/i2c/busses/i2c-axxia.c line 251

Quoted 13 lines
drivers/i2c/busses/i2c-axxia.c new file +13 -0
+		int c = readl(idev->base + MST_DATA);
+
+		if (idev->msg_xfrd == 0 && i2c_m_recv_len(msg)) {
+			/*
+			 * Check length byte for SMBus block read
+			 */
+			if (c <= 0) {
+				idev->msg_err = -EPROTO;
+				i2c_int_disable(idev, ~0);
+				complete(&idev->msg_complete);
+				break;
+			} else if (c > I2C_SMBUS_BLOCK_MAX) {
+				c = I2C_SMBUS_BLOCK_MAX;

What about returning -EPROTO here as well? I don't think that reading just a slice of all the data is helpful.

...

drivers/i2c/busses/i2c-axxia.c line 281

Quoted 2 lines
drivers/i2c/busses/i2c-axxia.c new file +2 -0
+static irqreturn_t
+axxia_i2c_isr(int irq, void *_dev)

Merge those into a single line please.

drivers/i2c/busses/i2c-axxia.c line 287

Quoted 6 lines
drivers/i2c/busses/i2c-axxia.c new file +6 -0
+{
+	struct axxia_i2c_dev *idev = _dev;
+	u32 status;
+
+	if (!idev->msg)
+		return IRQ_NONE;

This is actually not true. There might be interrupt bits set, so there is an IRQ. There shouldn't be one, right, but that's another case IMO.

...

drivers/i2c/busses/i2c-axxia.c line 350

Quoted 10 lines
drivers/i2c/busses/i2c-axxia.c new file +10 -0
+static int
+axxia_i2c_xfer_msg(struct axxia_i2c_dev *idev, struct i2c_msg *msg)
+{
+	u32 int_mask = MST_STATUS_ERR | MST_STATUS_SNS;
+	u32 rx_xfer, tx_xfer;
+	u32 addr_1, addr_2;
+	int ret;
+
+	if (msg->len == 0 || msg->len > 255)
+		return -EINVAL;

Ouch, really? Maybe we should warn the user here.

drivers/i2c/busses/i2c-axxia.c line 355

Quoted 5 lines
drivers/i2c/busses/i2c-axxia.c new file +5 -0
+
+	idev->msg = msg;
+	idev->msg_xfrd = 0;
+	idev->msg_err = 0;
+	init_completion(&idev->msg_complete);

reinit_completion?

drivers/i2c/busses/i2c-axxia.c line 407

Quoted 9 lines
drivers/i2c/busses/i2c-axxia.c new file +9 -0
+	ret = wait_for_completion_timeout(&idev->msg_complete,
+					  I2C_XFER_TIMEOUT);
+
+	i2c_int_disable(idev, int_mask);
+
+	WARN_ON(readl(idev->base + MST_COMMAND) & CMD_BUSY);
+
+	if (ret == 0) {
+		dev_warn(idev->dev, "xfer timeout (%#x)\n", msg->addr);

But no warning here. Timeouts can easily happen.

Quoted 6 lines
drivers/i2c/busses/i2c-axxia.c new file +6 -0
+		idev->msg_err = -ETIMEDOUT;
+	}
+
+	if (unlikely(idev->msg_err))
+		axxia_i2c_init(idev);
+

drivers/i2c/busses/i2c-axxia.c line 423

Quoted 10 lines
drivers/i2c/busses/i2c-axxia.c new file +10 -0
+	return idev->msg_err;
+}
+
+static int
+axxia_i2c_stop(struct axxia_i2c_dev *idev)
+{
+	u32 int_mask = MST_STATUS_ERR | MST_STATUS_SCC;
+	int ret;
+
+	init_completion(&idev->msg_complete);

reinit_completion

drivers/i2c/busses/i2c-axxia.c line 434

Quoted 11 lines
drivers/i2c/busses/i2c-axxia.c new file +11 -0
+
+	/* Issue stop */
+	writel(0xb, idev->base + MST_COMMAND);
+	i2c_int_enable(idev, int_mask);
+	ret = wait_for_completion_timeout(&idev->msg_complete,
+					  I2C_STOP_TIMEOUT);
+	i2c_int_disable(idev, int_mask);
+	if (ret == 0)
+		return -ETIMEDOUT;
+
+	WARN_ON(readl(idev->base + MST_COMMAND) & CMD_BUSY);

Message saying that bus is stuck should be enough? The call trace won't help here.

...

Quoted 4 lines
drivers/i2c/busses/i2c-axxia.c new file +4 -0
+#ifdef CONFIG_PM
+static int axxia_i2c_suspend(struct platform_device *pdev, pm_message_t state)
+{
+	return -EOPNOTSUPP;

drivers/i2c/busses/i2c-axxia.c line 566

Quoted 10 lines
drivers/i2c/busses/i2c-axxia.c new file +10 -0
+}
+
+static int axxia_i2c_resume(struct platform_device *pdev)
+{
+	return -EOPNOTSUPP;
+}
+#else
+#define axxia_i2c_suspend NULL
+#define axxia_i2c_resume NULL
+#endif

Is this really better than to keep them empty?

drivers/i2c/busses/i2c-axxia.c line 582

Quoted 8 lines
drivers/i2c/busses/i2c-axxia.c new file +8 -0
+static struct platform_driver axxia_i2c_driver = {
+	.probe   = axxia_i2c_probe,
+	.remove  = axxia_i2c_remove,
+	.suspend = axxia_i2c_suspend,
+	.resume  = axxia_i2c_resume,
+	.driver  = {
+		.name  = "axxia-i2c",
+		.owner = THIS_MODULE,

owner can be dropped.

Quoted 3 lines
drivers/i2c/busses/i2c-axxia.c new file +3 -0
+		.of_match_table = axxia_i2c_of_match,
+	},
+};
#2 lore raw
Quoted 3 lines · Wolfram Sang

Hi,

thanks for the submission.

Sure. Thanks for the comments. I'll update the patch and submit a v2.

Quoted 10 lines · Anders Berg
Quoted 5 lines

Add I2C bus driver for the controller found in the LSI Axxia family SoCs. The driver implements 10-bit addressing and SMBus transfer modes via emulation (including SMBus block data read).

Looks pretty good already. Still, some comments:

Quoted 10 lines

drivers/i2c/busses/Kconfig config I2C_AMD8111 · line 86

Quoted 7 lines
drivers/i2c/busses/Kconfig +7 -0
+config I2C_AXXIA
+     tristate "Axxia I2C controller"
+     depends on ARCH_AXXIA
+     help
+       Say yes if you want to support the I2C bus on Axxia platforms.
+
+       If you don't know, say Y.

I'd say skip this sentence and consider 'default y' if it is really needed on this platform.

Ok. Dropped the last sentence and defaulting to 'y'.

Quoted 12 lines

drivers/i2c/busses/i2c-axxia.c line 2

Quoted 9 lines
drivers/i2c/busses/i2c-axxia.c new file +2 -0
new file mode 100644
index 0000000..e6c9b88
@@ -0,0 +1,591 @@
+/*
+ * drivers/i2c/busses/i2c-axxia.c

No pathnames please, they might get stale.

Got it.

Quoted 12 lines
Quoted 12 lines
drivers/i2c/busses/i2c-axxia.c new file +12 -0
+ *
+ * This driver implements I2C master functionality using the LSI API2C
+ * controller.
+ *
+ * This software is licensed under the terms of the GNU General Public
+ * License version 2, as published by the Free Software Foundation, and
+ * may be copied, distributed, and modified under those terms.
+ */
+#include <linux/clk.h>
+#include <linux/clkdev.h>
+#include <linux/err.h>
+#include <linux/i2c.h>
Quoted 9 lines

drivers/i2c/busses/i2c-axxia.c line 20

Quoted 6 lines
drivers/i2c/busses/i2c-axxia.c new file +6 -0
+#include <linux/init.h>
+#include <linux/interrupt.h>
+#include <linux/module.h>
+#include <linux/io.h>
+#include <linux/kernel.h>
+#include <linux/platform_device.h>

At least of.h, too?

Ok, added.

Quoted 19 lines
Quoted 19 lines
drivers/i2c/busses/i2c-axxia.c new file +19 -0
+
+#define SCL_WAIT_TIMEOUT_NS 25000000
+#define I2C_XFER_TIMEOUT    (msecs_to_jiffies(250))
+#define I2C_STOP_TIMEOUT    (msecs_to_jiffies(100))
+#define FIFO_SIZE           8
+
+#define GLOBAL_CONTROL               0x00
+#define   GLOBAL_MST_EN         BIT(0)
+#define   GLOBAL_SLV_EN         BIT(1)
+#define   GLOBAL_IBML_EN        BIT(2)
+#define INTERRUPT_STATUS     0x04
+#define INTERRUPT_ENABLE     0x08
+#define   INT_SLV               BIT(1)
+#define   INT_MST               BIT(0)
+#define WAIT_TIMER_CONTROL   0x0c
+#define   WT_EN                      BIT(15)
+#define   WT_VALUE(_x)               ((_x) & 0x7fff)
+#define IBML_TIMEOUT         0x10
+#define IBML_LOW_MEXT                0x14
Quoted 9 lines

drivers/i2c/busses/i2c-axxia.c line 45

Quoted 6 lines
drivers/i2c/busses/i2c-axxia.c new file +6 -0
+#define IBML_LOW_SEXT                0x18
+#define TIMER_CLOCK_DIV              0x1c
+#define I2C_BUS_MONITOR              0x20
+#define SOFT_RESET           0x24
+#define MST_COMMAND          0x28
+#define   CMD_BUSY           (1<<3)

The whole driver has 'spaces around operator' issues, please fix them.

Ok.

Quoted 11 lines

...

drivers/i2c/busses/i2c-axxia.c

Quoted 2 lines
drivers/i2c/busses/i2c-axxia.c new file +2 -0
+     /* Find the prescaler value that makes tmo_clk fit in 15-bits counter.
+      */

Minor: Make this a one line comment. Better readable.

...

Quoted 15 lines

drivers/i2c/busses/i2c-axxia.c line 238

Quoted 12 lines
drivers/i2c/busses/i2c-axxia.c new file +12 -0
+/**
+ * axxia_i2c_empty_rx_fifo - Fetch data from RX FIFO and update SMBus block
+ * transfer length if this is the first byte of such a transfer.
+ */
+static int
+axxia_i2c_empty_rx_fifo(struct axxia_i2c_dev *idev)
+{
+     struct i2c_msg *msg = idev->msg;
+     size_t rx_fifo_avail = readl(idev->base + MST_RX_FIFO);
+     int bytes_to_transfer = min(rx_fifo_avail, msg->len - idev->msg_xfrd);
+
+     while (0 < bytes_to_transfer--) {

Please put constants on the right side. Reading this is very twisting.

Ok.

Quoted 15 lines
Quoted 4 lines
drivers/i2c/busses/i2c-axxia.c new file +3 -0
+             int c = readl(idev->base + MST_DATA);
+
+             if (idev->msg_xfrd == 0 && i2c_m_recv_len(msg)) {

drivers/i2c/busses/i2c-axxia.c line 251

Quoted 10 lines
drivers/i2c/busses/i2c-axxia.c new file +10 -0
+                     /*
+                      * Check length byte for SMBus block read
+                      */
+                     if (c <= 0) {
+                             idev->msg_err = -EPROTO;
+                             i2c_int_disable(idev, ~0);
+                             complete(&idev->msg_complete);
+                             break;
+                     } else if (c > I2C_SMBUS_BLOCK_MAX) {
+                             c = I2C_SMBUS_BLOCK_MAX;
Quoted 3 lines

What about returning -EPROTO here as well? I don't think that reading just a slice of all the data is helpful.

Right, that is probably true. This came from the device I was using to test the block-read operation. This device violated the I2C_SMBUS_BLOCK_MAX limit, so I added this truncation to at least get something out...

But I agree, for real-world use it makes no sense to truncate the message like this. I'll remove it.

Quoted 7 lines

...

drivers/i2c/busses/i2c-axxia.c line 281

Quoted 2 lines
drivers/i2c/busses/i2c-axxia.c new file +2 -0
+static irqreturn_t
+axxia_i2c_isr(int irq, void *_dev)

Merge those into a single line please.

I'll fix all occurrences of this.

Quoted 10 lines

drivers/i2c/busses/i2c-axxia.c line 287

Quoted 6 lines
drivers/i2c/busses/i2c-axxia.c new file +6 -0
+{
+     struct axxia_i2c_dev *idev = _dev;
+     u32 status;
+
+     if (!idev->msg)
+             return IRQ_NONE;

This is actually not true. There might be interrupt bits set, so there is an IRQ. There shouldn't be one, right, but that's another case IMO.

You could see it as: there is no interrupt that this handler is interested in serving. I'd like to keep this test as there is some legacy software that could be run on platforms with this driver that access the I2C controller directly. If this happens, this test assures that the user get an informative "unhandled irq" error message (instead of a null pointer dereference).

Quoted 14 lines

...

drivers/i2c/busses/i2c-axxia.c line 350

Quoted 10 lines
drivers/i2c/busses/i2c-axxia.c new file +10 -0
+static int
+axxia_i2c_xfer_msg(struct axxia_i2c_dev *idev, struct i2c_msg *msg)
+{
+     u32 int_mask = MST_STATUS_ERR | MST_STATUS_SNS;
+     u32 rx_xfer, tx_xfer;
+     u32 addr_1, addr_2;
+     int ret;
+
+     if (msg->len == 0 || msg->len > 255)
+             return -EINVAL;

Ouch, really? Maybe we should warn the user here.

Yeah, the transfer length register limits the length to 255. I'll add a warning here.

Quoted 8 lines

drivers/i2c/busses/i2c-axxia.c line 355

Quoted 6 lines
drivers/i2c/busses/i2c-axxia.c new file +5 -0
+
+     idev->msg = msg;
+     idev->msg_xfrd = 0;
+     idev->msg_err = 0;
+     init_completion(&idev->msg_complete);

reinit_completion?

Ok (learned something new there... :-)

Quoted 12 lines

drivers/i2c/busses/i2c-axxia.c line 407

Quoted 10 lines
drivers/i2c/busses/i2c-axxia.c new file +9 -0
+     ret = wait_for_completion_timeout(&idev->msg_complete,
+                                       I2C_XFER_TIMEOUT);
+
+     i2c_int_disable(idev, int_mask);
+
+     WARN_ON(readl(idev->base + MST_COMMAND) & CMD_BUSY);
+
+     if (ret == 0) {
+             dev_warn(idev->dev, "xfer timeout (%#x)\n", msg->addr);

But no warning here. Timeouts can easily happen.

Ok.

Quoted 20 lines
Quoted 7 lines
drivers/i2c/busses/i2c-axxia.c new file +6 -0
+             idev->msg_err = -ETIMEDOUT;
+     }
+
+     if (unlikely(idev->msg_err))
+             axxia_i2c_init(idev);
+

drivers/i2c/busses/i2c-axxia.c line 423

Quoted 10 lines
drivers/i2c/busses/i2c-axxia.c new file +10 -0
+     return idev->msg_err;
+}
+
+static int
+axxia_i2c_stop(struct axxia_i2c_dev *idev)
+{
+     u32 int_mask = MST_STATUS_ERR | MST_STATUS_SCC;
+     int ret;
+
+     init_completion(&idev->msg_complete);

reinit_completion

Quoted 15 lines

drivers/i2c/busses/i2c-axxia.c line 434

Quoted 11 lines
drivers/i2c/busses/i2c-axxia.c new file +11 -0
+
+     /* Issue stop */
+     writel(0xb, idev->base + MST_COMMAND);
+     i2c_int_enable(idev, int_mask);
+     ret = wait_for_completion_timeout(&idev->msg_complete,
+                                       I2C_STOP_TIMEOUT);
+     i2c_int_disable(idev, int_mask);
+     if (ret == 0)
+             return -ETIMEDOUT;
+
+     WARN_ON(readl(idev->base + MST_COMMAND) & CMD_BUSY);

Message saying that bus is stuck should be enough? The call trace won't help here.

Agreed.

Quoted 18 lines

...

Quoted 4 lines
drivers/i2c/busses/i2c-axxia.c new file +4 -0
+#ifdef CONFIG_PM
+static int axxia_i2c_suspend(struct platform_device *pdev, pm_message_t state)
+{
+     return -EOPNOTSUPP;

drivers/i2c/busses/i2c-axxia.c line 566

Quoted 10 lines
drivers/i2c/busses/i2c-axxia.c new file +10 -0
+}
+
+static int axxia_i2c_resume(struct platform_device *pdev)
+{
+     return -EOPNOTSUPP;
+}
+#else
+#define axxia_i2c_suspend NULL
+#define axxia_i2c_resume NULL
+#endif

Is this really better than to keep them empty?

Probably not. I'll remove these.

Quoted 11 lines

drivers/i2c/busses/i2c-axxia.c line 582

Quoted 9 lines
drivers/i2c/busses/i2c-axxia.c new file +8 -0
+static struct platform_driver axxia_i2c_driver = {
+     .probe   = axxia_i2c_probe,
+     .remove  = axxia_i2c_remove,
+     .suspend = axxia_i2c_suspend,
+     .resume  = axxia_i2c_resume,
+     .driver  = {
+             .name  = "axxia-i2c",
+             .owner = THIS_MODULE,

owner can be dropped.

... and this.

/Anders

#3 lore raw
Quoted 13 lines
Quoted 13 lines
Quoted 12 lines
drivers/i2c/busses/i2c-axxia.c new file +11 -0
+             if (idev->msg_xfrd == 0 && i2c_m_recv_len(msg)) {
+                     /*
+                      * Check length byte for SMBus block read
+                      */
+                     if (c <= 0) {
+                             idev->msg_err = -EPROTO;
+                             i2c_int_disable(idev, ~0);
+                             complete(&idev->msg_complete);
+                             break;
+                     } else if (c > I2C_SMBUS_BLOCK_MAX) {
+                             c = I2C_SMBUS_BLOCK_MAX;
Quoted 8 lines
Quoted 3 lines

What about returning -EPROTO here as well? I don't think that reading just a slice of all the data is helpful.

Right, that is probably true. This came from the device I was using to test the block-read operation. This device violated the I2C_SMBUS_BLOCK_MAX limit, so I added this truncation to at least get something out...

Which device was it? I know there are some doing that, yet I like to know which ones.

Quoted 11 lines
Quoted 10 lines

drivers/i2c/busses/i2c-axxia.c line 287

Quoted 6 lines
drivers/i2c/busses/i2c-axxia.c new file +6 -0
+{
+     struct axxia_i2c_dev *idev = _dev;
+     u32 status;
+
+     if (!idev->msg)
+             return IRQ_NONE;

This is actually not true. There might be interrupt bits set, so there is an IRQ. There shouldn't be one, right, but that's another case IMO.

Quoted 6 lines

You could see it as: there is no interrupt that this handler is interested in serving. I'd like to keep this test as there is some legacy software that could be run on platforms with this driver that access the I2C controller directly. If this happens, this test assures that the user get an informative "unhandled irq" error message (instead of a null pointer dereference).

IRQ_NONE is "this interrupt wasn't by me" so for shared IRQs, the next handler can check. You shouldn't remove the check per se. Still, since this interrupt was definately from the I2C core, you should return IRQ_HANDLED and print an error message to the logs.

Quoted 13 lines
Quoted 4 lines
Quoted 4 lines
drivers/i2c/busses/i2c-axxia.c new file +4 -0
+static int
+axxia_i2c_xfer_msg(struct axxia_i2c_dev *idev, struct i2c_msg *msg)
+{
+     u32 int_mask = MST_STATUS_ERR | MST_STATUS_SNS;
Quoted 8 lines

drivers/i2c/busses/i2c-axxia.c line 350

Quoted 6 lines
drivers/i2c/busses/i2c-axxia.c new file +6 -0
+     u32 rx_xfer, tx_xfer;
+     u32 addr_1, addr_2;
+     int ret;
+
+     if (msg->len == 0 || msg->len > 255)
+             return -EINVAL;

Ouch, really? Maybe we should warn the user here.

Quoted 2 lines

Yeah, the transfer length register limits the length to 255. I'll add a warning here.

Please also add this information to the Kconfig description and somewhere at the top of the source file. This is an important flaw which people should easily find out about.

#4 lore raw
Quoted 17 lines · Wolfram Sang
Quoted 17 lines
Quoted 16 lines

drivers/i2c/busses/i2c-axxia.c line 251

Quoted 12 lines
drivers/i2c/busses/i2c-axxia.c new file +11 -0
+             if (idev->msg_xfrd == 0 && i2c_m_recv_len(msg)) {
+                     /*
+                      * Check length byte for SMBus block read
+                      */
+                     if (c <= 0) {
+                             idev->msg_err = -EPROTO;
+                             i2c_int_disable(idev, ~0);
+                             complete(&idev->msg_complete);
+                             break;
+                     } else if (c > I2C_SMBUS_BLOCK_MAX) {
+                             c = I2C_SMBUS_BLOCK_MAX;

What about returning -EPROTO here as well? I don't think that reading just a slice of all the data is helpful.

Quoted 7 lines
Quoted 4 lines

Right, that is probably true. This came from the device I was using to test the block-read operation. This device violated the I2C_SMBUS_BLOCK_MAX limit, so I added this truncation to at least get something out...

Which device was it? I know there are some doing that, yet I like to know which ones.

It was a LTC2974, register MFR_FAULT_LOG (0xee).

Quoted 19 lines
Quoted 12 lines
Quoted 11 lines

drivers/i2c/busses/i2c-axxia.c line 287

Quoted 7 lines
drivers/i2c/busses/i2c-axxia.c new file +6 -0
+{
+     struct axxia_i2c_dev *idev = _dev;
+     u32 status;
+
+     if (!idev->msg)
+             return IRQ_NONE;

This is actually not true. There might be interrupt bits set, so there is an IRQ. There shouldn't be one, right, but that's another case IMO.

Quoted 6 lines

You could see it as: there is no interrupt that this handler is interested in serving. I'd like to keep this test as there is some legacy software that could be run on platforms with this driver that access the I2C controller directly. If this happens, this test assures that the user get an informative "unhandled irq" error message (instead of a null pointer dereference).

Quoted 5 lines

IRQ_NONE is "this interrupt wasn't by me" so for shared IRQs, the next handler can check. You shouldn't remove the check per se. Still, since this interrupt was definately from the I2C core, you should return IRQ_HANDLED and print an error message to the logs.

Ok, I'll do that.

Quoted 13 lines
Quoted 13 lines
Quoted 12 lines

drivers/i2c/busses/i2c-axxia.c line 350

Quoted 10 lines
drivers/i2c/busses/i2c-axxia.c new file +10 -0
+static int
+axxia_i2c_xfer_msg(struct axxia_i2c_dev *idev, struct i2c_msg *msg)
+{
+     u32 int_mask = MST_STATUS_ERR | MST_STATUS_SNS;
+     u32 rx_xfer, tx_xfer;
+     u32 addr_1, addr_2;
+     int ret;
+
+     if (msg->len == 0 || msg->len > 255)
+             return -EINVAL;

Ouch, really? Maybe we should warn the user here.

Quoted 7 lines
Quoted 2 lines

Yeah, the transfer length register limits the length to 255. I'll add a warning here.

Please also add this information to the Kconfig description and somewhere at the top of the source file. This is an important flaw which people should easily find out about.

Ok.

Thanks,
Anders

#5 lore raw
In reply to Wolfram Sang
Quoted 13 lines · Wolfram Sang
Quoted 13 lines
Quoted 12 lines

drivers/i2c/busses/i2c-axxia.c line 350

Quoted 10 lines
drivers/i2c/busses/i2c-axxia.c new file +10 -0
+static int
+axxia_i2c_xfer_msg(struct axxia_i2c_dev *idev, struct i2c_msg *msg)
+{
+     u32 int_mask = MST_STATUS_ERR | MST_STATUS_SNS;
+     u32 rx_xfer, tx_xfer;
+     u32 addr_1, addr_2;
+     int ret;
+
+     if (msg->len == 0 || msg->len > 255)
+             return -EINVAL;

Ouch, really? Maybe we should warn the user here.

Quoted 7 lines
Quoted 2 lines

Yeah, the transfer length register limits the length to 255. I'll add a warning here.

Please also add this information to the Kconfig description and somewhere at the top of the source file. This is an important flaw which people should easily find out about.

You are referring to the "len <= 255" restriction being the flaw here, right? I'll add a note to Kconfig and the driver about that.

The other part of the condition (msg->len == 0) should actually go away. The controller can do zero-length-data transfers. I'll fix that for next round.

/Anders

#6 lore raw
Quoted 9 lines
Quoted 9 lines
Quoted 8 lines
Quoted 5 lines

drivers/i2c/busses/i2c-axxia.c line 350

Quoted 3 lines
drivers/i2c/busses/i2c-axxia.c new file +2 -0
+     if (msg->len == 0 || msg->len > 255)
+             return -EINVAL;

Ouch, really? Maybe we should warn the user here.

Yeah, the transfer length register limits the length to 255. I'll add a warning here.

Quoted 7 lines
Quoted 4 lines

Please also add this information to the Kconfig description and somewhere at the top of the source file. This is an important flaw which people should easily find out about.

You are referring to the "len <= 255" restriction being the flaw here, right? I'll add a note to Kconfig and the driver about that.

Yes, I meant that. I just remembered we should do something else:

Remove I2C_FUNC_I2C (because it cannot do endless transfers) from functionality and simply use I2C_FUNC_SMBUS_I2C_BLOCK which does I2C like transfers with the SMBus Limit of 32 bytes. It seems PMBus allows for 255 byte which this HW could support, yet I don't recall we have support for that size currently.

Quoted 3 lines

The other part of the condition (msg->len == 0) should actually go away. The controller can do zero-length-data transfers. I'll fix that for next round.

Great!

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20140922/1e878942/attachment.sig>

#7 lore raw
Quoted 17 lines · Wolfram Sang
Quoted 9 lines
Quoted 9 lines
Quoted 8 lines
Quoted 5 lines

drivers/i2c/busses/i2c-axxia.c line 350

Quoted 3 lines
drivers/i2c/busses/i2c-axxia.c new file +2 -0
+     if (msg->len == 0 || msg->len > 255)
+             return -EINVAL;

Ouch, really? Maybe we should warn the user here.

Yeah, the transfer length register limits the length to 255. I'll add a warning here.

Quoted 7 lines
Quoted 4 lines

Please also add this information to the Kconfig description and somewhere at the top of the source file. This is an important flaw which people should easily find out about.

You are referring to the "len <= 255" restriction being the flaw here, right? I'll add a note to Kconfig and the driver about that.

Quoted 8 lines

Yes, I meant that. I just remembered we should do something else:

Remove I2C_FUNC_I2C (because it cannot do endless transfers) from functionality and simply use I2C_FUNC_SMBUS_I2C_BLOCK which does I2C like transfers with the SMBus Limit of 32 bytes. It seems PMBus allows for 255 byte which this HW could support, yet I don't recall we have support for that size currently.

Just tried this out... With the above change (I2C_FUNC_I2C replaced with I2C_FUNC_SMBUS_I2C_BLOCK) an EEPROM device fails (at24 driver) since it can't do a 16-bit offset when using the SMBUS_I2C_BLOCK transfer.

Would you be OK with keeping the I2C_FUNC_I2C capability and documenting the restriction (as per your initial suggestion)?

/Anders

#8 lore raw
In reply to Wolfram Sang
Quoted 2 lines · Wolfram Sang

IRQ_NONE is "this interrupt wasn't by me" so for shared IRQs, the next handler can check.

Err, no it isn't. IRQ_NONE has no such effect. All handlers on a shared interrupt are always run irrespective of the return value from any particular interrupt handler. See kernel/irq/handle.c.

Signature · 2 lines
FTTC broadband for 0.8mile line: currently at 9.5Mbps down 400kbps up
according to speedtest.net.
#10 lore raw
In reply to Wolfram Sang
Quoted 13 lines · Wolfram Sang

Hi,

thanks for the submission.

Quoted 5 lines · Anders Berg

Add I2C bus driver for the controller found in the LSI Axxia family SoCs. The driver implements 10-bit addressing and SMBus transfer modes via emulation (including SMBus block data read).

Looks pretty good already. Still, some comments:

Quoted 10 lines

drivers/i2c/busses/Kconfig config I2C_AMD8111 · line 86

Quoted 7 lines
drivers/i2c/busses/Kconfig +7 -0
+config I2C_AXXIA
+	tristate "Axxia I2C controller"
+	depends on ARCH_AXXIA
+	help
+	  Say yes if you want to support the I2C bus on Axxia platforms.
+
+	  If you don't know, say Y.

I'd say skip this sentence and consider 'default y' if it is really needed on this platform.

Still better:

	depends on ARCH_AXXIA || COMPILE_TEST
	default ARCH_AXXIA

Best regards
Uwe

Signature · 2 lines
Pengutronix e.K.                           | Uwe Kleine-K?nig            |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
#9 lore raw
In reply to Russell King - ARM Linux
Quoted 7 lines · Russell King - ARM Linux
Quoted 2 lines · Wolfram Sang

IRQ_NONE is "this interrupt wasn't by me" so for shared IRQs, the next handler can check.

Err, no it isn't. IRQ_NONE has no such effect. All handlers on a shared interrupt are always run irrespective of the return value from any particular interrupt handler. See kernel/irq/handle.c.

/me picks the brown paper bag. I was sure I did. Need to update my notes, it seems. Thanks for the heads up!