All of lore.kernel.org
 help / color / mirror / Atom feed
* [U-Boot] [PATCH v2 1/2] drivers: net: driver for MDIO muxes controlled over I2C
@ 2019-07-16  8:21 Alex Marginean
  2019-07-16  8:21 ` [U-Boot] [PATCH v2 2/2] doc: bindings: Add binding for register driven MDIO muxes Alex Marginean
                   ` (3 more replies)
  0 siblings, 4 replies; 10+ messages in thread
From: Alex Marginean @ 2019-07-16  8:21 UTC (permalink / raw)
  To: u-boot

This driver is used for MDIO muxes driven over I2C.  This is currently
used on Freescale LS1028A QDS board, on which the physical MDIO MUX is
controlled by an on-board FPGA which in turn is configured through I2C.

Signed-off-by: Alex Marginean <alexm.osslist@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>
---

Changes in v2:
	- renamed APIs, config options to mdio_mux_i2creg (instead of i2c_reg)

 drivers/net/Kconfig           |   8 +++
 drivers/net/Makefile          |   1 +
 drivers/net/mdio_mux_i2creg.c | 108 ++++++++++++++++++++++++++++++++++
 3 files changed, 117 insertions(+)
 create mode 100644 drivers/net/mdio_mux_i2creg.c

diff --git a/drivers/net/Kconfig b/drivers/net/Kconfig
index 4d85fb1716..883b849b78 100644
--- a/drivers/net/Kconfig
+++ b/drivers/net/Kconfig
@@ -595,4 +595,12 @@ config FSL_ENETC
 	  This driver supports the NXP ENETC Ethernet controller found on some
 	  of the NXP SoCs.
 
+config MDIO_MUX_I2CREG
+	bool "MDIO MUX accessed as a register over I2C"
+	depends on DM_MDIO_MUX && DM_I2C
+	help
+	  This driver is used for MDIO muxes driven by writing to a register of
+	  an I2C chip.  The board it was developed for uses a mux controlled by
+	  on-board FPGA which in turn is accessed as a chip over I2C.
+
 endif # NETDEVICES
diff --git a/drivers/net/Makefile b/drivers/net/Makefile
index 97119cec7c..6122bcdb81 100644
--- a/drivers/net/Makefile
+++ b/drivers/net/Makefile
@@ -80,3 +80,4 @@ obj-$(CONFIG_HIGMACV300_ETH) += higmacv300.o
 obj-$(CONFIG_MDIO_SANDBOX) += mdio_sandbox.o
 obj-$(CONFIG_FSL_ENETC) += fsl_enetc.o fsl_enetc_mdio.o
 obj-$(CONFIG_MDIO_MUX_SANDBOX) += mdio_mux_sandbox.o
+obj-$(CONFIG_MDIO_MUX_I2CREG) += mdio_mux_i2creg.o
diff --git a/drivers/net/mdio_mux_i2creg.c b/drivers/net/mdio_mux_i2creg.c
new file mode 100644
index 0000000000..3e82898f46
--- /dev/null
+++ b/drivers/net/mdio_mux_i2creg.c
@@ -0,0 +1,108 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * (C) Copyright 2019
+ * Alex Marginean, NXP
+ */
+
+#include <dm.h>
+#include <errno.h>
+#include <miiphy.h>
+#include <i2c.h>
+
+/*
+ * This driver is used for MDIO muxes driven by writing to a register of an I2C
+ * chip.  The board it was developed for uses a mux controlled by on-board FPGA
+ * which in turn is accessed as a chip over I2C.
+ */
+
+struct mdio_mux_i2creg_priv {
+	struct udevice *chip;
+	int reg;
+	int mask;
+};
+
+static int mdio_mux_i2creg_select(struct udevice *mux, int cur, int sel)
+{
+	struct mdio_mux_i2creg_priv *priv = dev_get_priv(mux);
+	u8 val, val_old;
+
+	/* if last selection didn't change we're good to go */
+	if (cur == sel)
+		return 0;
+
+	val_old = dm_i2c_reg_read(priv->chip, priv->reg);
+	val = (val_old & ~priv->mask) | (sel & priv->mask);
+	debug("%s: chip %s, reg %x, val %x => %x\n", __func__, priv->chip->name,
+	      priv->reg, val_old, val);
+	dm_i2c_reg_write(priv->chip, priv->reg, val);
+
+	return 0;
+}
+
+static const struct mdio_mux_ops mdio_mux_i2creg_ops = {
+	.select = mdio_mux_i2creg_select,
+};
+
+static int mdio_mux_i2creg_probe(struct udevice *dev)
+{
+	struct mdio_mux_i2creg_priv *priv = dev_get_priv(dev);
+	ofnode chip_node, bus_node;
+	struct udevice *i2c_bus;
+	u32 reg_mask[2];
+	u32 chip_addr;
+	int err;
+
+	/* read the register addr/mask pair */
+	err = dev_read_u32_array(dev, "mux-reg-masks", reg_mask, 2);
+	if (err) {
+		debug("%s: error reading mux-reg-masks property\n", __func__);
+		return err;
+	}
+
+	/* parent should be an I2C chip, grandparent should be an I2C bus */
+	chip_node = ofnode_get_parent(dev->node);
+	bus_node = ofnode_get_parent(chip_node);
+
+	err = uclass_get_device_by_ofnode(UCLASS_I2C, bus_node, &i2c_bus);
+	if (err) {
+		debug("%s: can't find I2C bus for node %s\n", __func__,
+		      ofnode_get_name(bus_node));
+		return err;
+	}
+
+	err = ofnode_read_u32(chip_node, "reg", &chip_addr);
+	if (err) {
+		debug("%s: can't read chip address in %s\n", __func__,
+		      ofnode_get_name(chip_node));
+		return err;
+	}
+
+	err = i2c_get_chip(i2c_bus, (uint)chip_addr, 1, &priv->chip);
+	if (err) {
+		debug("%s: can't find i2c chip device for addr %x\n", __func__,
+		      chip_addr);
+		return err;
+	}
+
+	priv->reg = (int)reg_mask[0];
+	priv->mask = (int)reg_mask[1];
+
+	debug("%s: chip %s, reg %x, mask %x\n", __func__, priv->chip->name,
+	      priv->reg, priv->mask);
+
+	return 0;
+}
+
+static const struct udevice_id mdio_mux_i2creg_ids[] = {
+	{ .compatible = "mdio-mux-i2creg" },
+	{ }
+};
+
+U_BOOT_DRIVER(mdio_mux_i2creg) = {
+	.name		= "mdio_mux_i2creg",
+	.id		= UCLASS_MDIO_MUX,
+	.of_match	= mdio_mux_i2creg_ids,
+	.probe		= mdio_mux_i2creg_probe,
+	.ops		= &mdio_mux_i2creg_ops,
+	.priv_auto_alloc_size = sizeof(struct mdio_mux_i2creg_priv),
+};
-- 
2.17.1

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [U-Boot] [PATCH v2 2/2] doc: bindings: Add binding for register driven MDIO muxes
  2019-07-16  8:21 [U-Boot] [PATCH v2 1/2] drivers: net: driver for MDIO muxes controlled over I2C Alex Marginean
@ 2019-07-16  8:21 ` Alex Marginean
  2019-07-23  4:34   ` Joe Hershberger
                     ` (2 more replies)
  2019-07-23  6:33 ` [U-Boot] [PATCH v2 1/2] drivers: net: driver for MDIO muxes controlled over I2C Bin Meng
                   ` (2 subsequent siblings)
  3 siblings, 3 replies; 10+ messages in thread
From: Alex Marginean @ 2019-07-16  8:21 UTC (permalink / raw)
  To: u-boot

This binding documents two properties that describe the registers used to
perform MUX selection.

Signed-off-by: Alex Marginean <alexm.osslist@gmail.com>
---

Changes in v2:
	- renamed APIs, config options to mdio_mux_i2creg (instead of i2c_reg)
	- expanded example to include all QDS card slots

 doc/device-tree-bindings/net/mdio-mux-reg.txt | 82 +++++++++++++++++++
 1 file changed, 82 insertions(+)
 create mode 100644 doc/device-tree-bindings/net/mdio-mux-reg.txt

diff --git a/doc/device-tree-bindings/net/mdio-mux-reg.txt b/doc/device-tree-bindings/net/mdio-mux-reg.txt
new file mode 100644
index 0000000000..0ac34dc423
--- /dev/null
+++ b/doc/device-tree-bindings/net/mdio-mux-reg.txt
@@ -0,0 +1,82 @@
+Device tree structures used by register based MDIO muxes is described here.
+This binding is based on reg-mux.txt binding in Linux and is currently used by
+mdio-mux-i2creg driver in U-Boot.
+
+Required properties:
+#mux-control-cells = <1> indicates how many registers are used for mux
+			selection.  mux-reg-mask property described below must
+			include this number of pairs.
+mux-reg-masks = <reg mask> describes pairs of register offset and register mask.
+			Register bits enabled in mask are set to the selection
+			value defined in reg property of child MDIOs to control
+			selection.
+Properties described in mdio-mux.txt also apply.
+
+Example structure, used on Freescale LS1028A QDS board:
+
+&i2c0 {
+	status = "okay";
+	u-boot,dm-pre-reloc;
+
+	fpga at 66 {
+		#address-cells = <1>;
+		#size-cells = <0>;
+		compatible = "simple-mfd";
+		reg = <0x66>;
+
+		mux-mdio at 54 {
+			#address-cells = <1>;
+			#size-cells = <0>;
+			compatible = "mdio-mux-i2creg";
+			reg = <0x54>;
+			#mux-control-cells = <1>;
+			mux-reg-masks = <0x54 0xf0>;
+			mdio-parent-bus = <&mdio0>;
+
+			/* on-board MDIO with a single RGMII PHY */
+			mdio at 00 {
+				#address-cells = <1>;
+				#size-cells = <0>;
+				reg = <0x00>;
+
+				/* on-board 1G RGMII PHY */
+				qds_phy0: phy at 5 {
+					reg = <5>;
+				};
+			};
+			/* card slot 1 */
+			mdio at 40 {
+				#address-cells = <1>;
+				#size-cells = <0>;
+				reg = <0x40>;
+				/* VSC8234 1G SGMII card */
+				sgmii_port0: phy at 1c {
+					reg = <0x1c>;
+				};
+			};
+			/* card slot 2 */
+			mdio at 50 {
+				#address-cells = <1>;
+				#size-cells = <0>;
+				reg = <0x50>;
+			};
+			/* card slot 3 */
+			mdio at 60 {
+				#address-cells = <1>;
+				#size-cells = <0>;
+				reg = <0x60>;
+			};
+			/* card slot 4 */
+			mdio at 70 {
+				#address-cells = <1>;
+				#size-cells = <0>;
+				reg = <0x70>;
+			};
+		};
+	};
+};
+
+/* Parent MDIO, defined in SoC .dtsi file, just enabled here */
+&mdio0 {
+	status = "okay";
+};
-- 
2.17.1

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [U-Boot] [PATCH v2 2/2] doc: bindings: Add binding for register driven MDIO muxes
  2019-07-16  8:21 ` [U-Boot] [PATCH v2 2/2] doc: bindings: Add binding for register driven MDIO muxes Alex Marginean
@ 2019-07-23  4:34   ` Joe Hershberger
  2019-07-23  6:34   ` Bin Meng
  2019-07-25 18:41   ` [U-Boot] " Joe Hershberger
  2 siblings, 0 replies; 10+ messages in thread
From: Joe Hershberger @ 2019-07-23  4:34 UTC (permalink / raw)
  To: u-boot

On Tue, Jul 16, 2019 at 3:22 AM Alex Marginean
<alexandru.marginean@nxp.com> wrote:
>
> This binding documents two properties that describe the registers used to
> perform MUX selection.
>
> Signed-off-by: Alex Marginean <alexm.osslist@gmail.com>

Acked-by: Joe Hershberger <joe.hershberger@ni.com>

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [U-Boot] [PATCH v2 1/2] drivers: net: driver for MDIO muxes controlled over I2C
  2019-07-16  8:21 [U-Boot] [PATCH v2 1/2] drivers: net: driver for MDIO muxes controlled over I2C Alex Marginean
  2019-07-16  8:21 ` [U-Boot] [PATCH v2 2/2] doc: bindings: Add binding for register driven MDIO muxes Alex Marginean
@ 2019-07-23  6:33 ` Bin Meng
  2019-07-25 18:41 ` [U-Boot] " Joe Hershberger
  2019-09-04 16:40 ` Joe Hershberger
  3 siblings, 0 replies; 10+ messages in thread
From: Bin Meng @ 2019-07-23  6:33 UTC (permalink / raw)
  To: u-boot

On Tue, Jul 16, 2019 at 4:21 PM Alex Marginean
<alexandru.marginean@nxp.com> wrote:
>
> This driver is used for MDIO muxes driven over I2C.  This is currently
> used on Freescale LS1028A QDS board, on which the physical MDIO MUX is
> controlled by an on-board FPGA which in turn is configured through I2C.
>
> Signed-off-by: Alex Marginean <alexm.osslist@gmail.com>
> Acked-by: Joe Hershberger <joe.hershberger@ni.com>
> ---
>
> Changes in v2:
>         - renamed APIs, config options to mdio_mux_i2creg (instead of i2c_reg)
>
>  drivers/net/Kconfig           |   8 +++
>  drivers/net/Makefile          |   1 +
>  drivers/net/mdio_mux_i2creg.c | 108 ++++++++++++++++++++++++++++++++++
>  3 files changed, 117 insertions(+)
>  create mode 100644 drivers/net/mdio_mux_i2creg.c
>

Reviewed-by: Bin Meng <bmeng.cn@gmail.com>

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [U-Boot] [PATCH v2 2/2] doc: bindings: Add binding for register driven MDIO muxes
  2019-07-16  8:21 ` [U-Boot] [PATCH v2 2/2] doc: bindings: Add binding for register driven MDIO muxes Alex Marginean
  2019-07-23  4:34   ` Joe Hershberger
@ 2019-07-23  6:34   ` Bin Meng
  2019-07-25 18:41   ` [U-Boot] " Joe Hershberger
  2 siblings, 0 replies; 10+ messages in thread
From: Bin Meng @ 2019-07-23  6:34 UTC (permalink / raw)
  To: u-boot

On Tue, Jul 16, 2019 at 4:21 PM Alex Marginean
<alexandru.marginean@nxp.com> wrote:
>
> This binding documents two properties that describe the registers used to
> perform MUX selection.
>
> Signed-off-by: Alex Marginean <alexm.osslist@gmail.com>
> ---
>
> Changes in v2:
>         - renamed APIs, config options to mdio_mux_i2creg (instead of i2c_reg)
>         - expanded example to include all QDS card slots
>
>  doc/device-tree-bindings/net/mdio-mux-reg.txt | 82 +++++++++++++++++++
>  1 file changed, 82 insertions(+)
>  create mode 100644 doc/device-tree-bindings/net/mdio-mux-reg.txt
>

Reviewed-by: Bin Meng <bmeng.cn@gmail.com>

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [U-Boot] drivers: net: driver for MDIO muxes controlled over I2C
  2019-07-16  8:21 [U-Boot] [PATCH v2 1/2] drivers: net: driver for MDIO muxes controlled over I2C Alex Marginean
  2019-07-16  8:21 ` [U-Boot] [PATCH v2 2/2] doc: bindings: Add binding for register driven MDIO muxes Alex Marginean
  2019-07-23  6:33 ` [U-Boot] [PATCH v2 1/2] drivers: net: driver for MDIO muxes controlled over I2C Bin Meng
@ 2019-07-25 18:41 ` Joe Hershberger
  2019-08-08 20:16   ` Alex Marginean
  2019-09-04 16:40 ` Joe Hershberger
  3 siblings, 1 reply; 10+ messages in thread
From: Joe Hershberger @ 2019-07-25 18:41 UTC (permalink / raw)
  To: u-boot

Hi Alex,

https://patchwork.ozlabs.org/patch/1132514/ was applied to http://git.denx.de/?p=u-boot/u-boot-net.git

Thanks!
-Joe

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [U-Boot] doc: bindings: Add binding for register driven MDIO muxes
  2019-07-16  8:21 ` [U-Boot] [PATCH v2 2/2] doc: bindings: Add binding for register driven MDIO muxes Alex Marginean
  2019-07-23  4:34   ` Joe Hershberger
  2019-07-23  6:34   ` Bin Meng
@ 2019-07-25 18:41   ` Joe Hershberger
  2 siblings, 0 replies; 10+ messages in thread
From: Joe Hershberger @ 2019-07-25 18:41 UTC (permalink / raw)
  To: u-boot

Hi Alex,

https://patchwork.ozlabs.org/patch/1132515/ was applied to http://git.denx.de/?p=u-boot/u-boot-net.git

Thanks!
-Joe

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [U-Boot] drivers: net: driver for MDIO muxes controlled over I2C
  2019-07-25 18:41 ` [U-Boot] " Joe Hershberger
@ 2019-08-08 20:16   ` Alex Marginean
  2019-08-09 16:48     ` Joe Hershberger
  0 siblings, 1 reply; 10+ messages in thread
From: Alex Marginean @ 2019-08-08 20:16 UTC (permalink / raw)
  To: u-boot

Hi Joe,

On 7/25/2019 9:41 PM, Joe Hershberger wrote:
> Hi Alex,
> 
> https://patchwork.ozlabs.org/patch/1132514/ was applied to http://git.denx.de/?p=u-boot/u-boot-net.git

can you please check this commit (d9a9174), I think mdio_mux_i2creg.c
was lost at merge.
Do you want me to send a new patch with just the .c file?

Thank you!
Alex


> 
> Thanks!
> -Joe
> _______________________________________________
> U-Boot mailing list
> U-Boot at lists.denx.de
> https://lists.denx.de/listinfo/u-boot
> 

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [U-Boot] drivers: net: driver for MDIO muxes controlled over I2C
  2019-08-08 20:16   ` Alex Marginean
@ 2019-08-09 16:48     ` Joe Hershberger
  0 siblings, 0 replies; 10+ messages in thread
From: Joe Hershberger @ 2019-08-09 16:48 UTC (permalink / raw)
  To: u-boot

On Thu, Aug 8, 2019 at 3:16 PM Alex Marginean <alexm.osslist@gmail.com> wrote:
>
> Hi Joe,
>
> On 7/25/2019 9:41 PM, Joe Hershberger wrote:
> > Hi Alex,
> >
> > https://patchwork.ozlabs.org/patch/1132514/ was applied to http://git.denx.de/?p=u-boot/u-boot-net.git
>
> can you please check this commit (d9a9174), I think mdio_mux_i2creg.c
> was lost at merge.
> Do you want me to send a new patch with just the .c file?

Yes, it seems you're right... I'll reapply the original.

Apologies,
-Joe

>
> Thank you!
> Alex
>
>
> >
> > Thanks!
> > -Joe
> > _______________________________________________
> > U-Boot mailing list
> > U-Boot at lists.denx.de
> > https://lists.denx.de/listinfo/u-boot
> >
>
> _______________________________________________
> U-Boot mailing list
> U-Boot at lists.denx.de
> https://lists.denx.de/listinfo/u-boot

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [U-Boot] drivers: net: driver for MDIO muxes controlled over I2C
  2019-07-16  8:21 [U-Boot] [PATCH v2 1/2] drivers: net: driver for MDIO muxes controlled over I2C Alex Marginean
                   ` (2 preceding siblings ...)
  2019-07-25 18:41 ` [U-Boot] " Joe Hershberger
@ 2019-09-04 16:40 ` Joe Hershberger
  3 siblings, 0 replies; 10+ messages in thread
From: Joe Hershberger @ 2019-09-04 16:40 UTC (permalink / raw)
  To: u-boot

Hi Alex,

https://patchwork.ozlabs.org/patch/1132514/ was applied to http://git.denx.de/?p=u-boot/u-boot-net.git

Thanks!
-Joe

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2019-09-04 16:40 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-07-16  8:21 [U-Boot] [PATCH v2 1/2] drivers: net: driver for MDIO muxes controlled over I2C Alex Marginean
2019-07-16  8:21 ` [U-Boot] [PATCH v2 2/2] doc: bindings: Add binding for register driven MDIO muxes Alex Marginean
2019-07-23  4:34   ` Joe Hershberger
2019-07-23  6:34   ` Bin Meng
2019-07-25 18:41   ` [U-Boot] " Joe Hershberger
2019-07-23  6:33 ` [U-Boot] [PATCH v2 1/2] drivers: net: driver for MDIO muxes controlled over I2C Bin Meng
2019-07-25 18:41 ` [U-Boot] " Joe Hershberger
2019-08-08 20:16   ` Alex Marginean
2019-08-09 16:48     ` Joe Hershberger
2019-09-04 16:40 ` Joe Hershberger

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.