Skip to contentSkip to conversation

i2c: Support for Netlogic XLP9XX/5XX I2C controller

PATCH Superseded Jayachandran C 3 participants 7 messages Mar 13, 2015 – Mar 17, 2015 6 messages not in the archive

Subsystems (3)

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

v3 cover i2c: Support for Netlogic XLP9XX/5XX I2C controller

Here is v3 of the driver for XLP9xx I2C controller. We have udpated the driver with changes for the review from Uwe.

Please let me know if there are any comments or suggestions.

Thanks,
JC.

Changes v2->v3:
* Implement changes from Uwe Kleine-König's review:
- add documentation link
- remove unnecessary #includes
- remove DATARDY interrupt
- clean up alignment and whitespace
- set CMD_STOP flag only for the last transfer
- correct freq assignment in xlp9xx_i2c_get_frequency
- remove printing out adap.nr in case of failure
- update writing to control register to make the logic clear
- clean up the #define ordering and naming a bit more
* use correct type in handling return of wait_for_completion_timeout

Changes v1->v2:
* Implement changes from Ray Jui's review
- Support for 0 length transfers
- remove .owner assignment in platform_driver and .data assignment in of_device_id table
- add synchronize_irq and disable interrupt in .remove
- Move most prints to dev_dbg
- add COMPILE_TEST
- align wrapped line in function definitions
- IRQ_NONE return if interrupt is not ours.
- error check frequency setting in DTB
- fix check of return of devm_ioremap_resource() and remove unnecessary prints
- fix incorrect irq check
- include file ordering fixed
- few unneeded variables taken out
- use u32 consistently for unsigned 32 bit int
- add comment for prescale value calculation

* Change clock-frequency parameter to take the bus frequency as expected in i2c subsystem

* Rearrage register definitions to group them better

* Add I2C_FUNC_10BIT_ADDR to xlp9xx_i2c_functionality()

* use reinit_completion before each transfer

* use i2c_add_adapter instead of doing i2c_add_numbered_adapter

Subhendu Sekhar Behera (2):
of: Add vendor prefix 'netlogic'
i2c: Support for Netlogic XLP9XX/5XX I2C controller.

 .../devicetree/bindings/i2c/i2c-xlp9xx.txt         |  22 +
 .../devicetree/bindings/vendor-prefixes.txt        |   1 +
 drivers/i2c/busses/Kconfig                         |  10 +
 drivers/i2c/busses/Makefile                        |   1 +
 drivers/i2c/busses/i2c-xlp9xx.c                    | 446 +++++++++++++++++++++
 5 files changed, 480 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/i2c/i2c-xlp9xx.txt
 create mode 100644 drivers/i2c/busses/i2c-xlp9xx.c
Signature · 1 line
1.9.1
#2 lore raw

PATCH v3 1/2 of: Add vendor prefix 'netlogic'

In reply to a message not in the archive

From: Subhendu Sekhar Behera <sbehera-dY08KVG/lbpWk0Htik3J/[email protected]>

Add vendor name "netlogic" in vendor-prefixes.txt, which will be used for the Netlogic XLP and XLPII MIPS SoCs. These processors were from NetLogic Microsystems which is now part of Broadcom Corporation.

---
 Documentation/devicetree/bindings/vendor-prefixes.txt | 1 +
 1 file changed, 1 insertion(+)
Documentation/devicetree/bindings/vendor-prefixes.txt +1 -0
index 389ca13..a718eb1 100644
@@ -123,6 +123,7 @@ mxicy	Macronix International Co., Ltd.
 national	National Semiconductor
 neonode		Neonode Inc.
 netgear	NETGEAR
+netlogic	Broadcom Corporation (formerly NetLogic Microsystems)
 newhaven	Newhaven Display International
 nintendo	Nintendo
 nokia	Nokia
Signature · 6 lines
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#3 lore raw

PATCH v3 2/2 i2c: Support for Netlogic XLP9XX/5XX I2C controller.

In reply to a message not in the archive

From: Subhendu Sekhar Behera <sbehera-dY08KVG/lbpWk0Htik3J/[email protected]>

Add an I2C bus driver i2c-xlp9xx.c to support the I2C block in the XLP9xx/XLP5xx MIPS SoC. Update Kconfig and Makefile to add the CONFIG_I2C_XLP9XX option.

Also add document Documentation/devicetree/bindings/i2c/i2c-xlp9xx.txt for DT compatible string "netlogic,xlp9xx-i2c".

---
 .../devicetree/bindings/i2c/i2c-xlp9xx.txt         |  22 +
 drivers/i2c/busses/Kconfig                         |  10 +
 drivers/i2c/busses/Makefile                        |   1 +
 drivers/i2c/busses/i2c-xlp9xx.c                    | 446 +++++++++++++++++++++
 4 files changed, 479 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/i2c/i2c-xlp9xx.txt
 create mode 100644 drivers/i2c/busses/i2c-xlp9xx.c
Documentation/devicetree/bindings/i2c/i2c-xlp9xx.txt new file +22 -0
new file mode 100644
index 00000000..f23ae87
@@ -0,0 +1,22 @@
+Device tree configuration for the I2C controller on the XLP9xx/5xx SoC
+
+Required properties:
+- compatible      : should be "netlogic,xlp9xx-i2c"
+- reg             : bus address start and address range size of device
+- interrupts      : interrupt number
+
+Optional properties:
+- clock-frequency : frequency of bus clock in Hz
+                    Defaults to 100 KHz when the property is not specified
+
+Example:
+
+i2c0: i2c@113100 {
+	compatible = "netlogic,xlp9xx-i2c";
+	#address-cells = <1>;
+	#size-cells = <0>;
+	reg = <0 0x113100 0x100>;
+	clock-frequency = <400000>;
+	interrupts = <30>;
+	interrupt-parent = <&pic>;
+};
drivers/i2c/busses/Kconfig +10 -0
index 22da9c2..dde4648 100644
@@ -898,6 +898,16 @@ config I2C_XLR
 	  This driver can also be built as a module.  If so, the module
 	  will be called i2c-xlr.
 
+config I2C_XLP9XX
+	tristate "XLP9XX I2C support"
+	depends on CPU_XLP || COMPILE_TEST
+	help
+	  This driver enables support for the on-chip I2C interface of
+	  the Broadcom XLP9xx/XLP5xx MIPS processors.
+
+	  This driver can also be built as a module.  If so, the module will
+	  be called i2c-xlp9xx.
+
 config I2C_RCAR
 	tristate "Renesas R-Car I2C Controller"
 	depends on ARCH_SHMOBILE || COMPILE_TEST
drivers/i2c/busses/Makefile +1 -0
index 3638feb..f8e0f0e 100644
@@ -87,6 +87,7 @@ obj-$(CONFIG_I2C_WMT)		+= i2c-wmt.o
 obj-$(CONFIG_I2C_OCTEON)	+= i2c-octeon.o
 obj-$(CONFIG_I2C_XILINX)	+= i2c-xiic.o
 obj-$(CONFIG_I2C_XLR)		+= i2c-xlr.o
+obj-$(CONFIG_I2C_XLP9XX)	+= i2c-xlp9xx.o
 obj-$(CONFIG_I2C_RCAR)		+= i2c-rcar.o
 
 # External I2C/SMBus adapter drivers
drivers/i2c/busses/i2c-xlp9xx.c new file +446 -0

446 lines not on this page · raw message

Signature · 1 line
1.9.1
#5 lore raw

Re: [PATCH v3 2/2] i2c: Support for Netlogic XLP9XX/5XX I2C controller.

In reply to a message not in the archive

hello,

Quoted 8 lines · Jayachandran C
drivers/i2c/busses/i2c-xlp9xx.c new file +2 -0
new file mode 100644
index 00000000..2f303ad
@@ -0,0 +1,446 @@
+/*
+ * Copyright (c) 2003-2015 Broadcom Corporation

drivers/i2c/busses/i2c-xlp9xx.c line 12

Quoted 10 lines
drivers/i2c/busses/i2c-xlp9xx.c new file +10 -0
+ *
+ * This file is licensed under the terms of the GNU General Public
+ * License version 2. This program is licensed "as is" without any
+ * warranty of any kind, whether express or implied.
+ */
+
+/*
+ * see Documentation/devicetree/bindings/i2c/i2c-xlp9xx.txt for device
+ * tree bindings documentation
+ */

When I asked for documentation here, I didn't meant the device tree binding, but the hardware reference manual.

drivers/i2c/busses/i2c-xlp9xx.c line 111

Quoted 5 lines

[...]

drivers/i2c/busses/i2c-xlp9xx.c new file +4 -0
+static void xlp9xx_i2c_mask_irq(struct xlp9xx_i2c_dev *priv, u32 mask)
+{
+	mask = xlp9xx_read_i2c_reg(priv, XLP9XX_I2C_INTEN) & ~mask;
+	xlp9xx_write_i2c_reg(priv, XLP9XX_I2C_INTEN, mask);

You didn't comment on my suggestion to add a variable here for improved readability:

	u32 inten = xlp9xx_read_i2c_reg(...);
	inten &= ~mask;
	xlp9xx_write_i2c_reg(...);

drivers/i2c/busses/i2c-xlp9xx.c line 124

Quoted 13 lines
drivers/i2c/busses/i2c-xlp9xx.c new file +13 -0
+}
+
+static void xlp9xx_i2c_unmask_irq(struct xlp9xx_i2c_dev *priv, u32 mask)
+{
+	mask = xlp9xx_read_i2c_reg(priv, XLP9XX_I2C_INTEN) | mask;
+	xlp9xx_write_i2c_reg(priv, XLP9XX_I2C_INTEN, mask);
+}
+
+static void xlp9xx_i2c_set_rx_fifo_thres(struct xlp9xx_i2c_dev *priv,
+					 u32 th)
+{
+	xlp9xx_write_i2c_reg(priv, XLP9XX_I2C_MFIFOCTRL,
+			     (th << XLP9XX_I2C_MFIFOCTRL_HITH_SHIFT));

parenthesis are not needed here.

I suggested to move the min calculation that you have to do before each call to this function into it. You replied:

The xlp9xx_i2c_... functions were written to do the hardware/register operations, so it is better to have this logic here.

...

drivers/i2c/busses/i2c-xlp9xx.c line 132

Quoted 8 lines
drivers/i2c/busses/i2c-xlp9xx.c new file +8 -0
+}
+
+static void xlp9xx_i2c_fill_tx_fifo(struct xlp9xx_i2c_dev *priv)
+{
+	u32 len, i;
+	u8 *buf = priv->msg_buf;
+
+	len = min(priv->msg_buf_remaining, XLP9XX_I2C_FIFO_SIZE);

... this didn't stop you here though :-) So I'm still convinced that having the min function in xlp9xx_i2c_set_rx_fifo_thres is a good idea.

Quoted 5 lines
drivers/i2c/busses/i2c-xlp9xx.c new file +5 -0
+	for (i = 0; i < len; i++)
+		xlp9xx_write_i2c_reg(priv, XLP9XX_I2C_MTXFIFO, buf[i]);
+	priv->msg_buf_remaining -= len;
+	priv->msg_buf += len;
+}

drivers/i2c/busses/i2c-xlp9xx.c line 215

Quoted 10 lines
drivers/i2c/busses/i2c-xlp9xx.c new file +9 -0
[...]
+static int xlp9xx_i2c_init(struct xlp9xx_i2c_dev *priv)
+{
+	u32 prescale;
+
+	/*
+	 * The controller uses 5 * SCL clock internally.
+	 * So prescale value should be divided by 5.
+	 */
+	prescale = (((XLP9XX_I2C_IP_CLK_FREQ / priv->clk_hz) - 8) / 5) - 1;

I still wonder if you should round differently here.

drivers/i2c/busses/i2c-xlp9xx.c line 223

Quoted 8 lines
drivers/i2c/busses/i2c-xlp9xx.c new file +8 -0
+	xlp9xx_write_i2c_reg(priv, XLP9XX_I2C_CTRL, XLP9XX_I2C_CTRL_RST);
+	xlp9xx_write_i2c_reg(priv, XLP9XX_I2C_CTRL, XLP9XX_I2C_CTRL_EN |
+			     XLP9XX_I2C_CTRL_MASTER);
+	xlp9xx_write_i2c_reg(priv, XLP9XX_I2C_DIV, prescale);
+	xlp9xx_write_i2c_reg(priv, XLP9XX_I2C_INTEN, 0);
+
+	return 0;
+}

Best regards
Uwe

Signature · 2 lines
Pengutronix e.K.                           | Uwe Kleine-König            |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
#12 lore raw

Re: [PATCH v3 2/2] i2c: Support for Netlogic XLP9XX/5XX I2C controller.

In reply to a message not in the archive
Quoted 2 lines · On Friday 13 March 2015 11:59:58 Jayachandran C wrote:

+- compatible : should be "netlogic,xlp9xx-i2c"

Use a real model number here, not a wildcard.

Also, please send the binding as a separate patch from the driver.

Arnd

#8 lore raw

Re: [PATCH v3 2/2] i2c: Support for Netlogic XLP9XX/5XX I2C controller.

In reply to a message not in the archive

Hello,

Quoted 17 lines · Jayachandran C.
Quoted 15 lines · Uwe Kleine-König

drivers/i2c/busses/i2c-xlp9xx.c line 12

Quoted 12 lines · Jayachandran C
drivers/i2c/busses/i2c-xlp9xx.c new file +5 -0
new file mode 100644
index 00000000..2f303ad
@@ -0,0 +1,446 @@
[...]
+
+/*
+ * see Documentation/devicetree/bindings/i2c/i2c-xlp9xx.txt for device
+ * tree bindings documentation
+ */

When I asked for documentation here, I didn't meant the device tree binding, but the hardware reference manual.

Quoted 3 lines

Unfortunately there is no standalone documentation for the I2C controller, this block is used in XLP9xx and XLP5xx SoCs and you can get the documentation for the whole SoC from support.broadcom.com if you have an account there.

I don't. According to the instructions to get such an account I have to contact my "Sales/Engineering contacts at Broadcom or its Distributors/Manufacturer's representatives directly". Who would that be for me? You?

Quoted 8 lines
Quoted 8 lines

drivers/i2c/busses/i2c-xlp9xx.c line 111

Quoted 5 lines

[...]

drivers/i2c/busses/i2c-xlp9xx.c new file +4 -0
+static void xlp9xx_i2c_mask_irq(struct xlp9xx_i2c_dev *priv, u32 mask)
+{
+	mask = xlp9xx_read_i2c_reg(priv, XLP9XX_I2C_INTEN) & ~mask;
+	xlp9xx_write_i2c_reg(priv, XLP9XX_I2C_INTEN, mask);

You didn't comment on my suggestion to add a variable here for improved readability:

Quoted 7 lines
Quoted 4 lines
	u32 inten = xlp9xx_read_i2c_reg(...);
	inten &= ~mask;
	xlp9xx_write_i2c_reg(...);

Thought it was not really needed, but it is a little better than the current code, will update.

Yeah, for the generated code it probably doesn't make much difference---if at all. Readability and so maintainability is a good reason to update code if there is no overhead in the compiled result. (And sometimes even although there is overhead.)

Quoted 12 lines
Quoted 11 lines

drivers/i2c/busses/i2c-xlp9xx.c line 215

Quoted 10 lines

[...]

drivers/i2c/busses/i2c-xlp9xx.c new file +9 -0
+static int xlp9xx_i2c_init(struct xlp9xx_i2c_dev *priv)
+{
+	u32 prescale;
+
+	/*
+	 * The controller uses 5 * SCL clock internally.
+	 * So prescale value should be divided by 5.
+	 */
+	prescale = (((XLP9XX_I2C_IP_CLK_FREQ / priv->clk_hz) - 8) / 5) - 1;

I still wonder if you should round differently here.

Quoted 2 lines

Are you thinking of making sure that we don't exceed the given clock freq because of rounding? I don't think this is an issue.

Right, that and also in the other direction not to give up speed because the calculation is not optimal.

Quoted 11 lines
Quoted 8 lines

drivers/i2c/busses/i2c-xlp9xx.c line 223

Quoted 8 lines
drivers/i2c/busses/i2c-xlp9xx.c new file +8 -0
+	xlp9xx_write_i2c_reg(priv, XLP9XX_I2C_CTRL, XLP9XX_I2C_CTRL_RST);
+	xlp9xx_write_i2c_reg(priv, XLP9XX_I2C_CTRL, XLP9XX_I2C_CTRL_EN |
+			     XLP9XX_I2C_CTRL_MASTER);
+	xlp9xx_write_i2c_reg(priv, XLP9XX_I2C_DIV, prescale);
+	xlp9xx_write_i2c_reg(priv, XLP9XX_I2C_INTEN, 0);
+
+	return 0;
+}

I will post a v4 (which takes care of another comment I have seen in this thread as well).

BTW, I fully agree to Arnd's request to use the full SoC's name in the compatible string. Pick the first SoC to fix the name, and for the later SoCs use both strings. This method proved to be flexible enough to work even if Broadcom might release a SoC next year with a name that matches 9xx but an incompatible i2c device.
For Freescale devices it works exactly like this. There are (to the best of our knowledge) 3 similar implementations. On i.MX51 the device is used that first appeared in the i.MX21 and imx51.dtsi has:

	compatible = "fsl,imx51-i2c", "fsl,imx21-i2c";

.

Best regards
Uwe

Signature · 2 lines
Pengutronix e.K.                           | Uwe Kleine-König            |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
#11 lore raw

Re: [PATCH v3 2/2] i2c: Support for Netlogic XLP9XX/5XX I2C controller.

In reply to a message not in the archive

Hello,

Quoted 22 lines · Jayachandran C.
Quoted 21 lines · Uwe Kleine-König
Quoted 20 lines · Jayachandran C.
Quoted 15 lines · Uwe Kleine-König

drivers/i2c/busses/i2c-xlp9xx.c

Quoted 12 lines · Jayachandran C
drivers/i2c/busses/i2c-xlp9xx.c new file +5 -0
new file mode 100644
index 00000000..2f303ad
@@ -0,0 +1,446 @@
[...]
+
+/*
+ * see Documentation/devicetree/bindings/i2c/i2c-xlp9xx.txt for device
+ * tree bindings documentation
+ */

When I asked for documentation here, I didn't meant the device tree binding, but the hardware reference manual.

Unfortunately there is no standalone documentation for the I2C controller, this block is used in XLP9xx and XLP5xx SoCs and you can get the documentation for the whole SoC from support.broadcom.com if you have an account there.

Quoted 8 lines
Quoted 4 lines

I don't. According to the instructions to get such an account I have to contact my "Sales/Engineering contacts at Broadcom or its Distributors/Manufacturer's representatives directly". Who would that be for me? You?

Not really. If you want to develop drivers for a XLP9xx board you have, then you should have an account at support site and the instructions apply.

I don't want to develop drivers for such a board, among other reasons because I don't own one. But I want to make a review of such a driver. And therefor a datasheet would be helpful.

Quoted 4 lines

The rationale given in device tree guidelines is that the silicon vendor may release future chips which break the wildcard. In this specific case that issue will not happen, because the driver is from the silicon vendor. Anyway, for consistency, we will take out the wildcard in v4.

I honestly hope the high trust in your employer is justified. It didn't work for me (for a different employer of course).

Best regards
Uwe

Signature · 2 lines
Pengutronix e.K.                           | Uwe Kleine-König            |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |