All of lore.kernel.org
 help / color / mirror / Atom feed
* [U-Boot] [PATCH v2 1/2] ihs_mdio: Encapsulate register access
@ 2018-04-27 12:52 Mario Six
  2018-04-27 12:52 ` [U-Boot] [PATCH v2 2/2] ihs_mdio: Make DM-compatible Mario Six
  2018-05-09  1:30 ` [U-Boot] [U-Boot,v2,1/2] ihs_mdio: Encapsulate register access Tom Rini
  0 siblings, 2 replies; 4+ messages in thread
From: Mario Six @ 2018-04-27 12:52 UTC (permalink / raw)
  To: u-boot

To prepare for DM conversion, encapsulate all register accesses in
function calls.

Signed-off-by: Mario Six <mario.six@gdsys.cc>
---

v1 -> v2:
No changes

---
 board/gdsys/common/ihs_mdio.c | 41 ++++++++++++++++++++++++++++++++++-------
 1 file changed, 34 insertions(+), 7 deletions(-)

diff --git a/board/gdsys/common/ihs_mdio.c b/board/gdsys/common/ihs_mdio.c
index 822517d4b2..b5fe3dbbdc 100644
--- a/board/gdsys/common/ihs_mdio.c
+++ b/board/gdsys/common/ihs_mdio.c
@@ -12,6 +12,34 @@
 
 #include "ihs_mdio.h"
 
+static inline u16 read_control(struct ihs_mdio_info *info)
+{
+	u16 val;
+
+	FPGA_GET_REG(info->fpga, mdio.control, &val);
+
+	return val;
+}
+
+static inline void write_control(struct ihs_mdio_info *info, u16 val)
+{
+	FPGA_SET_REG(info->fpga, mdio.control, val);
+}
+
+static inline void write_addr_data(struct ihs_mdio_info *info, u16 val)
+{
+	FPGA_SET_REG(info->fpga, mdio.address_data, val);
+}
+
+static inline u16 read_rx_data(struct ihs_mdio_info *info)
+{
+	u16 val;
+
+	FPGA_GET_REG(info->fpga, mdio.rx_data, &val);
+
+	return val;
+}
+
 static int ihs_mdio_idle(struct mii_dev *bus)
 {
 	struct ihs_mdio_info *info = bus->priv;
@@ -19,7 +47,7 @@ static int ihs_mdio_idle(struct mii_dev *bus)
 	unsigned int ctr = 0;
 
 	do {
-		FPGA_GET_REG(info->fpga, mdio.control, &val);
+		val = read_control(info);
 		udelay(100);
 		if (ctr++ > 10)
 			return -1;
@@ -43,13 +71,13 @@ static int ihs_mdio_read(struct mii_dev *bus, int addr, int dev_addr,
 
 	ihs_mdio_idle(bus);
 
-	FPGA_SET_REG(info->fpga, mdio.control,
-		     ((addr & 0x1f) << 5) | (regnum & 0x1f) | (2 << 10));
+	write_control(info,
+		      ((addr & 0x1f) << 5) | (regnum & 0x1f) | (2 << 10));
 
 	/* wait for rx data available */
 	udelay(100);
 
-	FPGA_GET_REG(info->fpga, mdio.rx_data, &val);
+	val = read_rx_data(info);
 
 	return val;
 }
@@ -61,9 +89,8 @@ static int ihs_mdio_write(struct mii_dev *bus, int addr, int dev_addr,
 
 	ihs_mdio_idle(bus);
 
-	FPGA_SET_REG(info->fpga, mdio.address_data, value);
-	FPGA_SET_REG(info->fpga, mdio.control,
-		     ((addr & 0x1f) << 5) | (regnum & 0x1f) | (1 << 10));
+	write_addr_data(info, value);
+	write_control(info, ((addr & 0x1f) << 5) | (regnum & 0x1f) | (1 << 10));
 
 	return 0;
 }
-- 
2.16.1

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

* [U-Boot] [PATCH v2 2/2] ihs_mdio: Make DM-compatible
  2018-04-27 12:52 [U-Boot] [PATCH v2 1/2] ihs_mdio: Encapsulate register access Mario Six
@ 2018-04-27 12:52 ` Mario Six
  2018-05-09  1:31   ` [U-Boot] [U-Boot,v2,2/2] " Tom Rini
  2018-05-09  1:30 ` [U-Boot] [U-Boot,v2,1/2] ihs_mdio: Encapsulate register access Tom Rini
  1 sibling, 1 reply; 4+ messages in thread
From: Mario Six @ 2018-04-27 12:52 UTC (permalink / raw)
  To: u-boot

Make the ihs_mdio driver DM-compatible, while retaining the old
functionality for not-yet-converted boards.

Signed-off-by: Mario Six <mario.six@gdsys.cc>
---

v1 -> v2:
* Switched to regmap usage (instead of fpgamap)

---
 board/gdsys/common/ihs_mdio.c | 58 +++++++++++++++++++++++++++++++++++++++----
 board/gdsys/common/ihs_mdio.h |  5 ++++
 2 files changed, 58 insertions(+), 5 deletions(-)

diff --git a/board/gdsys/common/ihs_mdio.c b/board/gdsys/common/ihs_mdio.c
index b5fe3dbbdc..6b06b1d692 100644
--- a/board/gdsys/common/ihs_mdio.c
+++ b/board/gdsys/common/ihs_mdio.c
@@ -7,36 +7,84 @@
 
 #include <common.h>
 
-#include <gdsys_fpga.h>
 #include <miiphy.h>
+#ifdef CONFIG_GDSYS_LEGACY_DRIVERS
+#include <gdsys_fpga.h>
+#else
+#include <fdtdec.h>
+#include <regmap.h>
+#endif
 
 #include "ihs_mdio.h"
 
+#ifndef CONFIG_GDSYS_LEGACY_DRIVERS
+enum {
+	REG_MDIO_CONTROL = 0x0,
+	REG_MDIO_ADDR_DATA = 0x2,
+	REG_MDIO_RX_DATA = 0x4,
+};
+
+static inline u16 read_reg(struct udevice *fpga, uint base, uint addr)
+{
+	struct regmap *map;
+	u8 *ptr;
+
+	regmap_init_mem(fpga, &map);
+	ptr = regmap_get_range(map, 0);
+
+	return in_le16((u16 *)(ptr + base + addr));
+}
+
+static inline void write_reg(struct udevice *fpga, uint base, uint addr,
+			     u16 val)
+{
+	struct regmap *map;
+	u8 *ptr;
+
+	regmap_init_mem(fpga, &map);
+	ptr = regmap_get_range(map, 0);
+
+	out_le16((u16 *)(ptr + base + addr), val);
+}
+#endif
+
 static inline u16 read_control(struct ihs_mdio_info *info)
 {
 	u16 val;
-
+#ifdef CONFIG_GDSYS_LEGACY_DRIVERS
 	FPGA_GET_REG(info->fpga, mdio.control, &val);
-
+#else
+	val = read_reg(info->fpga, info->base, REG_MDIO_CONTROL);
+#endif
 	return val;
 }
 
 static inline void write_control(struct ihs_mdio_info *info, u16 val)
 {
+#ifdef CONFIG_GDSYS_LEGACY_DRIVERS
 	FPGA_SET_REG(info->fpga, mdio.control, val);
+#else
+	write_reg(info->fpga, info->base, REG_MDIO_CONTROL, val);
+#endif
 }
 
 static inline void write_addr_data(struct ihs_mdio_info *info, u16 val)
 {
+#ifdef CONFIG_GDSYS_LEGACY_DRIVERS
 	FPGA_SET_REG(info->fpga, mdio.address_data, val);
+#else
+	write_reg(info->fpga, info->base, REG_MDIO_ADDR_DATA, val);
+#endif
 }
 
 static inline u16 read_rx_data(struct ihs_mdio_info *info)
 {
 	u16 val;
-
+#ifdef CONFIG_GDSYS_LEGACY_DRIVERS
 	FPGA_GET_REG(info->fpga, mdio.rx_data, &val);
-
+#else
+	val = read_reg(info->fpga, info->base, REG_MDIO_RX_DATA);
+#endif
 	return val;
 }
 
diff --git a/board/gdsys/common/ihs_mdio.h b/board/gdsys/common/ihs_mdio.h
index 64b4049378..3e3ba25bc6 100644
--- a/board/gdsys/common/ihs_mdio.h
+++ b/board/gdsys/common/ihs_mdio.h
@@ -9,7 +9,12 @@
 #define _IHS_MDIO_H_
 
 struct ihs_mdio_info {
+#ifdef CONFIG_GDSYS_LEGACY_DRIVERS
 	u32 fpga;
+#else
+	struct udevice *fpga;
+	int base;
+#endif
 	char *name;
 };
 
-- 
2.16.1

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

* [U-Boot] [U-Boot,v2,1/2] ihs_mdio: Encapsulate register access
  2018-04-27 12:52 [U-Boot] [PATCH v2 1/2] ihs_mdio: Encapsulate register access Mario Six
  2018-04-27 12:52 ` [U-Boot] [PATCH v2 2/2] ihs_mdio: Make DM-compatible Mario Six
@ 2018-05-09  1:30 ` Tom Rini
  1 sibling, 0 replies; 4+ messages in thread
From: Tom Rini @ 2018-05-09  1:30 UTC (permalink / raw)
  To: u-boot

On Fri, Apr 27, 2018 at 02:52:09PM +0200, Mario Six wrote:

> To prepare for DM conversion, encapsulate all register accesses in
> function calls.
> 
> Signed-off-by: Mario Six <mario.six@gdsys.cc>

Applied to u-boot/master, thanks!

-- 
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20180508/76534917/attachment.sig>

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

* [U-Boot] [U-Boot,v2,2/2] ihs_mdio: Make DM-compatible
  2018-04-27 12:52 ` [U-Boot] [PATCH v2 2/2] ihs_mdio: Make DM-compatible Mario Six
@ 2018-05-09  1:31   ` Tom Rini
  0 siblings, 0 replies; 4+ messages in thread
From: Tom Rini @ 2018-05-09  1:31 UTC (permalink / raw)
  To: u-boot

On Fri, Apr 27, 2018 at 02:52:10PM +0200, Mario Six wrote:

> Make the ihs_mdio driver DM-compatible, while retaining the old
> functionality for not-yet-converted boards.
> 
> Signed-off-by: Mario Six <mario.six@gdsys.cc>

Applied to u-boot/master, thanks!

-- 
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20180508/c6dc018a/attachment.sig>

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

end of thread, other threads:[~2018-05-09  1:31 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-04-27 12:52 [U-Boot] [PATCH v2 1/2] ihs_mdio: Encapsulate register access Mario Six
2018-04-27 12:52 ` [U-Boot] [PATCH v2 2/2] ihs_mdio: Make DM-compatible Mario Six
2018-05-09  1:31   ` [U-Boot] [U-Boot,v2,2/2] " Tom Rini
2018-05-09  1:30 ` [U-Boot] [U-Boot,v2,1/2] ihs_mdio: Encapsulate register access Tom Rini

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.