From: Andrey Smirnov <andrew.smirnov@gmail.com>
To: barebox@lists.infradead.org
Cc: Andrey Smirnov <andrew.smirnov@gmail.com>
Subject: [PATCH v3 03/20] i.MX: ocotp: Add provisions for storing multiple MAC addresses
Date: Tue, 10 Jan 2017 07:08:56 -0800 [thread overview]
Message-ID: <20170110150913.31416-4-andrew.smirnov@gmail.com> (raw)
In-Reply-To: <20170110150913.31416-1-andrew.smirnov@gmail.com>
i.MX SoC variants like Vybrid have more than one built-in Ethernet
interface and as a consequence support storing more than one MAC address
in OCOTP module. Add code to create multiple 'mac_addr<n>' parameters as
well as 'mac_addr' as an "alias" to 'mac_addr0' for backwards
compatibility.
Acked-by: Stefan Lengfeld <s.lengfeld@phytec.de>
Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
---
arch/arm/mach-imx/ocotp.c | 70 ++++++++++++++++++++++++++++++++++-------------
1 file changed, 51 insertions(+), 19 deletions(-)
diff --git a/arch/arm/mach-imx/ocotp.c b/arch/arm/mach-imx/ocotp.c
index 7f625d8..bd5448d 100644
--- a/arch/arm/mach-imx/ocotp.c
+++ b/arch/arm/mach-imx/ocotp.c
@@ -69,12 +69,22 @@
/* Other definitions */
#define IMX6_OTP_DATA_ERROR_VAL 0xBADABADA
#define DEF_RELAX 20
-#define MAC_OFFSET (0x22 * 4)
+#define MAC_OFFSET_0 (0x22 * 4)
+#define MAC_OFFSET_1 (0x24 * 4)
+#define MAX_MAC_OFFSETS 2
#define MAC_BYTES 8
struct imx_ocotp_data {
int num_regs;
u32 (*addr_to_offset)(u32 addr);
+ u8 mac_offsets[MAX_MAC_OFFSETS];
+ u8 mac_offsets_num;
+};
+
+struct ocotp_priv_ethaddr {
+ char value[MAC_BYTES];
+ struct regmap *map;
+ u8 offset;
};
struct ocotp_priv {
@@ -84,9 +94,10 @@ struct ocotp_priv {
struct device_d dev;
int permanent_write_enable;
int sense_enable;
- char ethaddr[6];
+ struct ocotp_priv_ethaddr ethaddr[MAX_MAC_OFFSETS];
struct regmap_config map_config;
const struct imx_ocotp_data *data;
+ int mac_offset_idx;
};
static struct ocotp_priv *imx_ocotp;
@@ -408,32 +419,28 @@ static void memreverse(void *dest, const void *src, size_t n)
static int imx_ocotp_get_mac(struct param_d *param, void *priv)
{
- struct ocotp_priv *ocotp_priv = priv;
- char buf[8];
+ char buf[MAC_BYTES];
int ret;
+ struct ocotp_priv_ethaddr *ethaddr = priv;
- ret = regmap_bulk_read(ocotp_priv->map, MAC_OFFSET, buf, MAC_BYTES);
+ ret = regmap_bulk_read(ethaddr->map, ethaddr->offset,
+ buf, MAC_BYTES);
if (ret < 0)
return ret;
- memreverse(ocotp_priv->ethaddr, buf, 6);
+ memreverse(ethaddr->value, buf, 6);
return 0;
}
static int imx_ocotp_set_mac(struct param_d *param, void *priv)
{
- struct ocotp_priv *ocotp_priv = priv;
- char buf[8];
- int ret;
+ char buf[MAC_BYTES];
+ struct ocotp_priv_ethaddr *ethaddr = priv;
- memreverse(buf, ocotp_priv->ethaddr, 6);
- buf[6] = 0; buf[7] = 0;
-
- ret = regmap_bulk_write(ocotp_priv->map, MAC_OFFSET, buf, MAC_BYTES);
- if (ret < 0)
- return ret;
+ memreverse(buf, ethaddr->value, 6);
- return 0;
+ return regmap_bulk_write(ethaddr->map, ethaddr->offset,
+ buf, MAC_BYTES);
}
static struct regmap_bus imx_ocotp_regmap_bus = {
@@ -492,9 +499,28 @@ static int imx_ocotp_probe(struct device_d *dev)
NULL, NULL, &priv->permanent_write_enable, NULL);
}
- if (IS_ENABLED(CONFIG_NET))
- dev_add_param_mac(&(priv->dev), "mac_addr", imx_ocotp_set_mac,
- imx_ocotp_get_mac, priv->ethaddr, priv);
+ if (IS_ENABLED(CONFIG_NET)) {
+ int i;
+ struct ocotp_priv_ethaddr *ethaddr;
+
+ for (i = 0; i < priv->data->mac_offsets_num; i++) {
+ ethaddr = &priv->ethaddr[i];
+ ethaddr->map = priv->map;
+ ethaddr->offset = priv->data->mac_offsets[i];
+
+ dev_add_param_mac(&priv->dev, xasprintf("mac_addr%d", i),
+ imx_ocotp_set_mac, imx_ocotp_get_mac,
+ ethaddr->value, ethaddr);
+ }
+
+ /*
+ * Alias to mac_addr0 for backwards compatibility
+ */
+ ethaddr = &priv->ethaddr[0];
+ dev_add_param_mac(&priv->dev, "mac_addr",
+ imx_ocotp_set_mac, imx_ocotp_get_mac,
+ ethaddr->value, ethaddr);
+ }
dev_add_param_bool(&(priv->dev), "sense_enable", NULL, NULL, &priv->sense_enable, priv);
@@ -533,16 +559,22 @@ static u32 vf610_addr_to_offset(u32 addr)
static struct imx_ocotp_data imx6q_ocotp_data = {
.num_regs = 512,
.addr_to_offset = imx6q_addr_to_offset,
+ .mac_offsets_num = 1,
+ .mac_offsets = { MAC_OFFSET_0 },
};
static struct imx_ocotp_data imx6sl_ocotp_data = {
.num_regs = 256,
.addr_to_offset = imx6sl_addr_to_offset,
+ .mac_offsets_num = 1,
+ .mac_offsets = { MAC_OFFSET_0 },
};
static struct imx_ocotp_data vf610_ocotp_data = {
.num_regs = 512,
.addr_to_offset = vf610_addr_to_offset,
+ .mac_offsets_num = 2,
+ .mac_offsets = { MAC_OFFSET_0, MAC_OFFSET_1 },
};
static __maybe_unused struct of_device_id imx_ocotp_dt_ids[] = {
--
2.9.3
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
next prev parent reply other threads:[~2017-01-10 15:10 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-01-10 15:08 [PATCH v3 00/20] Vybrid related patches Andrey Smirnov
2017-01-10 15:08 ` [PATCH v3 01/20] i.MX: esdhc: Enable host->clk during initialization Andrey Smirnov
2017-01-10 15:08 ` [PATCH v3 02/20] i.MX: ocotp: Move memory reversing into a subroutine Andrey Smirnov
2017-01-10 15:08 ` Andrey Smirnov [this message]
2017-01-10 15:08 ` [PATCH v3 04/20] i.MX: ocotp: Initialize OCOTP as early as possible Andrey Smirnov
2017-01-10 15:08 ` [PATCH v3 05/20] i.MX: clk: Add IMX_PLLV3_SYS_VF610 subtype Andrey Smirnov
2017-01-10 15:08 ` [PATCH v3 06/20] i.MX: ocotp: Add imx_ocotp_sense_enable() Andrey Smirnov
2017-01-10 15:09 ` [PATCH v3 07/20] i.MX: imx6-fusemap: Fix SJC_RESP_LOCK width Andrey Smirnov
2017-01-10 15:09 ` [PATCH v3 08/20] i.MX: Add fusemap for VF610 Andrey Smirnov
2017-01-10 15:09 ` [PATCH v3 09/20] i.MX: vf610: Ramp CPU clock to maximum frequency Andrey Smirnov
2017-01-10 15:09 ` [PATCH v3 10/20] i.MX: iomuxv3: Add low-level pad code to headers Andrey Smirnov
2017-01-10 15:09 ` [PATCH v3 11/20] i.MX: iomuxv3: Add helper macros to deconstruct iomux_v3_cfg_t values Andrey Smirnov
2017-01-10 15:09 ` [PATCH v3 12/20] i.MX: iomuxv3: Add low-level pad configuration routine Andrey Smirnov
2017-01-10 15:09 ` [PATCH v3 13/20] i.MX6: sabresd: Remove magic numbers in setup_uart Andrey Smirnov
2017-01-10 15:09 ` [PATCH v3 14/20] i.MX: iomuxv3: Use helper functions in iomux-v3.h Andrey Smirnov
2017-01-10 15:09 ` [PATCH v3 15/20] i.MX: vf610: Add low-level pin configuration helper Andrey Smirnov
2017-01-10 15:09 ` [PATCH v3 16/20] i.MX: iomux-vf610: Add missing pad definitions Andrey Smirnov
2017-01-10 15:09 ` [PATCH v3 17/20] i.MX: imx-usb-phy: Add VF610 OF compatiblity string Andrey Smirnov
2017-01-10 15:09 ` [PATCH v3 18/20] i.MX: Default CONFIG_USB_IMX_PHY to 'y' on Vybrid Andrey Smirnov
2017-01-10 15:09 ` [PATCH v3 19/20] i.MX: imx-usb-misc: Add Vybrid support Andrey Smirnov
2017-01-10 15:09 ` [PATCH v3 20/20] i.MX: vf610-twr: Remove MSCM setup code Andrey Smirnov
2017-01-12 6:41 ` [PATCH v3 00/20] Vybrid related patches Sascha Hauer
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=20170110150913.31416-4-andrew.smirnov@gmail.com \
--to=andrew.smirnov@gmail.com \
--cc=barebox@lists.infradead.org \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox