All of lore.kernel.org
 help / color / mirror / Atom feed
From: Mario Six <mario.six@gdsys.cc>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH v2 2/2] ihs_mdio: Make DM-compatible
Date: Fri, 27 Apr 2018 14:52:10 +0200	[thread overview]
Message-ID: <20180427125210.891-2-mario.six@gdsys.cc> (raw)
In-Reply-To: <20180427125210.891-1-mario.six@gdsys.cc>

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

  reply	other threads:[~2018-04-27 12:52 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
2018-05-09  1:31   ` [U-Boot] [U-Boot,v2,2/2] ihs_mdio: Make DM-compatible Tom Rini
2018-05-09  1:30 ` [U-Boot] [U-Boot,v2,1/2] ihs_mdio: Encapsulate register access Tom Rini

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=20180427125210.891-2-mario.six@gdsys.cc \
    --to=mario.six@gdsys.cc \
    --cc=u-boot@lists.denx.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 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.