Merge Official Source

Signed-off-by: Tianling Shen <cnsztl@immortalwrt.org>
This commit is contained in:
Tianling Shen 2025-02-03 20:41:15 +08:00
commit ef51053445
No known key found for this signature in database
GPG Key ID: 6850B6345C862176
10 changed files with 404 additions and 22 deletions

View File

@ -4367,6 +4367,7 @@ CONFIG_NLS_DEFAULT="iso8859-1"
# CONFIG_NVMEM_LAYOUT_ONIE_TLV is not set
# CONFIG_NVMEM_LAYOUT_SL28_VPD is not set
# CONFIG_NVMEM_LAYOUT_U_BOOT_ENV is not set
# CONFIG_NVMEM_LAYOUT_ASCII_ENV is not set
# CONFIG_NVMEM_REBOOT_MODE is not set
# CONFIG_NVMEM_RMEM is not set
# CONFIG_NVMEM_SYSFS is not set

View File

@ -0,0 +1,98 @@
From 995a6e0d3fdd1e4fb38465f224db8a4c7b1e279d Mon Sep 17 00:00:00 2001
From: Christian Marangi <ansuelsmth@gmail.com>
Date: Mon, 3 Feb 2025 00:10:18 +0100
Subject: [PATCH 1/2] nvmem: core: generalize "mac-base" cells handling
Generalize support of "mac-base" nvmem cells and provide a GPL symbol to
permit also other NVMEM layout driver to parse mac-base cells.
It's VERY COMMON for some specially formatted NVMEM to expose a mac
address in ASCII format or HEX format hence prevent code duplication by
exposing a common helper.
Such helper will change the nvmem_info_cell and apply the correct post
process function to correctly parse the mac address.
Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
---
drivers/nvmem/core.c | 41 +++++++++++++++++++---------------
include/linux/nvmem-provider.h | 4 ++++
2 files changed, 27 insertions(+), 18 deletions(-)
--- a/drivers/nvmem/core.c
+++ b/drivers/nvmem/core.c
@@ -855,6 +855,27 @@ static int nvmem_mac_base_hex_read(void
return 0;
}
+void nvmem_layout_parse_mac_base(struct nvmem_cell_info *info)
+{
+ if (!of_device_is_compatible(info->np, "mac-base"))
+ return;
+
+ if (info->bytes == ETH_ALEN) {
+ info->raw_len = info->bytes;
+ info->bytes = ETH_ALEN;
+ info->read_post_process = nvmem_mac_base_raw_read;
+ } else if (info->bytes == 2 * ETH_ALEN) {
+ info->raw_len = info->bytes;
+ info->bytes = ETH_ALEN;
+ info->read_post_process = nvmem_mac_base_hex_read;
+ } else if (info->bytes == 3 * ETH_ALEN - 1) {
+ info->raw_len = info->bytes;
+ info->bytes = ETH_ALEN;
+ info->read_post_process = nvmem_mac_base_ascii_read;
+ }
+}
+EXPORT_SYMBOL_GPL(nvmem_layout_parse_mac_base);
+
static int nvmem_add_cells_from_dt(struct nvmem_device *nvmem, struct device_node *np)
{
struct device *dev = &nvmem->dev;
@@ -894,24 +915,8 @@ static int nvmem_add_cells_from_dt(struc
if (nvmem->fixup_dt_cell_info)
nvmem->fixup_dt_cell_info(nvmem, &info);
- if (of_device_is_compatible(np, "fixed-layout")) {
- if (of_device_is_compatible(child, "mac-base")) {
- if (info.bytes == ETH_ALEN) {
- info.raw_len = info.bytes;
- info.bytes = ETH_ALEN;
- info.read_post_process = nvmem_mac_base_raw_read;
- } else if (info.bytes == 2 * ETH_ALEN) {
- info.raw_len = info.bytes;
- info.bytes = ETH_ALEN;
- info.read_post_process = nvmem_mac_base_hex_read;
- } else if (info.bytes == 3 * ETH_ALEN - 1) {
- info.raw_len = info.bytes;
- info.bytes = ETH_ALEN;
- info.read_post_process = nvmem_mac_base_ascii_read;
- }
-
- }
- }
+ if (of_device_is_compatible(np, "fixed-layout"))
+ nvmem_layout_parse_mac_base(&info);
ret = nvmem_add_one_cell(nvmem, &info);
kfree(info.name);
--- a/include/linux/nvmem-provider.h
+++ b/include/linux/nvmem-provider.h
@@ -242,6 +242,8 @@ static inline void nvmem_layout_unregist
#if IS_ENABLED(CONFIG_NVMEM) && IS_ENABLED(CONFIG_OF)
+void nvmem_layout_parse_mac_base(struct nvmem_cell_info *info);
+
/**
* of_nvmem_layout_get_container() - Get OF node of layout container
*
@@ -254,6 +256,8 @@ struct device_node *of_nvmem_layout_get_
#else /* CONFIG_NVMEM && CONFIG_OF */
+static inline void nvmem_layout_parse_mac_base(void) {}
+
static inline struct device_node *of_nvmem_layout_get_container(struct nvmem_device *nvmem)
{
return NULL;

View File

@ -0,0 +1,187 @@
From 38287e8ec5c0281377fc70f11f20bcd9986a05f5 Mon Sep 17 00:00:00 2001
From: Christian Marangi <ansuelsmth@gmail.com>
Date: Mon, 3 Feb 2025 00:36:12 +0100
Subject: [PATCH 2/2] nvmem: layouts: add support for ascii-env driver
Add support for simple ASCII envirorment driver for NVMEM layouts.
It's very common for devices to store simple text file format in
partition for environment varibles. The most common pattern is variable
name, a delimiter and variable value all separated by a new line
character (\n).
This driver adds support for exporting such data and expose NVMEM cells
so they can be referenced by other drivers. This driver also supports
parsing mac-base NVMEM cells to parse ASCII or HEX mac address.
Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
---
drivers/nvmem/layouts/Kconfig | 13 +++
drivers/nvmem/layouts/Makefile | 1 +
drivers/nvmem/layouts/ascii-env.c | 131 ++++++++++++++++++++++++++++++
3 files changed, 145 insertions(+)
create mode 100644 drivers/nvmem/layouts/ascii-env.c
--- a/drivers/nvmem/layouts/Kconfig
+++ b/drivers/nvmem/layouts/Kconfig
@@ -37,6 +37,19 @@ config NVMEM_LAYOUT_U_BOOT_ENV
If unsure, say N.
+config NVMEM_LAYOUT_ASCII_ENV
+ tristate "ASCII environment variables layout"
+ help
+ It's very common for devices to store simple text file format in
+ partition for environment varibles. The most common pattern is variable
+ name, a delimiter and variable value all separated by a new line
+ character (\n).
+ This driver adds support for exporting such data and expose NVMEM cells
+ so they can be referenced by other drivers. This driver also supports
+ parsing mac-base NVMEM cells to parse ASCII or HEX mac address.
+
+ If unsure, say N.
+
endmenu
endif
--- a/drivers/nvmem/layouts/Makefile
+++ b/drivers/nvmem/layouts/Makefile
@@ -6,3 +6,4 @@
obj-$(CONFIG_NVMEM_LAYOUT_SL28_VPD) += sl28vpd.o
obj-$(CONFIG_NVMEM_LAYOUT_ONIE_TLV) += onie-tlv.o
obj-$(CONFIG_NVMEM_LAYOUT_U_BOOT_ENV) += u-boot-env.o
+obj-$(CONFIG_NVMEM_LAYOUT_ASCII_ENV) += ascii-env.o
--- /dev/null
+++ b/drivers/nvmem/layouts/ascii-env.c
@@ -0,0 +1,131 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Copyright (C) 2024 Christian Marangi <ansuelsmth@gmail.com>
+ *
+ * This borrow some parse logic from u-boot-env.
+ */
+#include <linux/nvmem-consumer.h>
+#include <linux/nvmem-provider.h>
+#include <linux/of.h>
+#include <linux/slab.h>
+
+/*
+ * Parse a buffer as an ASCII text with name delimiter value and each pattern separated
+ * with a new line char '\n'
+ * Example: (delimiter '=')
+ * name=value\nname2=value2\n
+ * 2 Cell:
+ * - name: value
+ * - name2: value2
+ */
+static int ascii_env_parse_cells(struct device *dev, struct nvmem_device *nvmem, uint8_t *buf,
+ size_t data_len, const char delim)
+{
+ char *var, *value, *eq, *lf;
+ char *data = buf;
+
+ /*
+ * Warning the inner loop take care of replacing '\n'
+ * with '\0', hence we can use strlen on value.
+ */
+ for (var = data; var < data + data_len && *var;
+ var = value + strlen(value) + 1) {
+ struct nvmem_cell_info info = {};
+
+ eq = strchr(var, delim);
+ if (!eq)
+ break;
+ *eq = '\0';
+ value = eq + 1;
+
+ /* Replace '\n' with '\0' to use strlen for value */
+ lf = strchr(value, '\n');
+ if (!lf)
+ break;
+ *lf = '\0';
+
+ info.name = devm_kstrdup(dev, var, GFP_KERNEL);
+ if (!info.name)
+ return -ENOMEM;
+ info.offset = value - data;
+ info.bytes = strlen(value);
+ info.np = of_get_child_by_name(dev->of_node, info.name);
+
+ nvmem_layout_parse_mac_base(&info);
+
+ nvmem_add_one_cell(nvmem, &info);
+ }
+
+ return 0;
+}
+
+static int ascii_env_add_cells(struct nvmem_layout *layout)
+{
+ struct nvmem_device *nvmem = layout->nvmem;
+ struct device *dev = &layout->dev;
+ size_t dev_size;
+ uint8_t *buf;
+ char delim;
+ int bytes;
+ int ret;
+
+ /* Get the delimiter for name value pattern */
+ delim = device_get_match_data(dev);
+
+ dev_size = nvmem_dev_size(nvmem);
+
+ buf = kzalloc(dev_size, GFP_KERNEL);
+ if (!buf) {
+ ret = -ENOMEM;
+ goto err_out;
+ }
+
+ bytes = nvmem_device_read(nvmem, 0, dev_size, buf);
+ if (bytes < 0) {
+ ret = bytes;
+ goto err_kfree;
+ } else if (bytes != dev_size) {
+ ret = -EIO;
+ goto err_kfree;
+ }
+
+ buf[dev_size - 1] = '\0';
+ ret = ascii_env_parse_cells(dev, nvmem, buf, dev_size, delim);
+
+err_kfree:
+ kfree(buf);
+err_out:
+ return ret;
+}
+
+static int ascii_env_probe(struct nvmem_layout *layout)
+{
+ layout->add_cells = ascii_env_add_cells;
+
+ return nvmem_layout_register(layout);
+}
+
+static void ascii_env_remove(struct nvmem_layout *layout)
+{
+ nvmem_layout_unregister(layout);
+}
+
+static const struct of_device_id ascii_env_of_match_table[] = {
+ { .compatible = "ascii-eq-delim-env", .data = (void *)'=', },
+ {},
+};
+
+static struct nvmem_layout_driver ascii_env_layout = {
+ .driver = {
+ .name = "ascii-env-layout",
+ .of_match_table = ascii_env_of_match_table,
+ },
+ .probe = ascii_env_probe,
+ .remove = ascii_env_remove,
+};
+module_nvmem_layout_driver(ascii_env_layout);
+
+MODULE_AUTHOR("Christian Marangi <ansuelsmth@gmail.com>");
+MODULE_LICENSE("GPL");
+MODULE_DEVICE_TABLE(of, ascii_env_of_match_table);
+MODULE_DESCRIPTION("NVMEM layout driver for ASCII environment variables");

View File

@ -86,16 +86,6 @@ ipq806x_setup_macs()
local board="$1"
case "$board" in
linksys,ea7500-v1)
hw_mac_addr=$(mtd_get_mac_ascii devinfo hw_mac_addr)
ucidef_set_interface_macaddr "lan" "$hw_mac_addr"
ucidef_set_interface_macaddr "wan" "$hw_mac_addr"
;;
linksys,ea8500)
hw_mac_addr=$(mtd_get_mac_ascii devinfo hw_mac_addr)
ucidef_set_interface_macaddr "lan" "$hw_mac_addr"
ucidef_set_interface_macaddr "wan" "$hw_mac_addr"
;;
linksys,e8350-v1 |\
zyxel,nbg6817)
hw_mac_addr=$(mtd_get_mac_ascii 0:appsblenv ethaddr)
@ -111,7 +101,7 @@ ipq806x_setup_macs()
hw_mac_addr=$(mtd_get_mac_ascii hwconfig HW.LAN.MAC.Address)
ucidef_set_interface_macaddr "lan" "$hw_mac_addr"
hw_mac_addr=$(mtd_get_mac_ascii hwconfig HW.WAN.MAC.Address)
ucidef_set_interface_macaddr "wan" "$hw_mac_addr"
ucidef_set_interface_macaddr "wan" "$(macaddr_add $hw_mac_addr 1)"
;;
esac
}

View File

@ -314,6 +314,7 @@ CONFIG_NO_HZ_IDLE=y
CONFIG_NR_CPUS=2
CONFIG_NVMEM=y
CONFIG_NVMEM_LAYOUTS=y
CONFIG_NVMEM_LAYOUT_ASCII_ENV=y
CONFIG_NVMEM_QCOM_QFPROM=y
# CONFIG_NVMEM_QCOM_SEC_QFPROM is not set
# CONFIG_NVMEM_SPMI_SDAM is not set

View File

@ -150,6 +150,18 @@
partition@f40000 {
label = "devinfo";
reg = <0x0f40000 0x0040000>;
nvmem-layout {
compatible = "ascii-eq-delim-env";
#address-cells = <1>;
#size-cells = <1>;
hw_mac_addr: hw_mac_addr {
compatible = "mac-base";
#nvmem-cell-cells = <1>;
};
};
};
partition@f80000 {
@ -294,6 +306,9 @@
pinctrl-0 = <&rgmii2_pins>;
pinctrl-names = "default";
nvmem-cells = <&hw_mac_addr 0>;
nvmem-cell-names = "mac-address";
fixed-link {
speed = <1000>;
full-duplex;
@ -306,6 +321,9 @@
phy-mode = "sgmii";
qcom,id = <2>;
nvmem-cells = <&hw_mac_addr 1>;
nvmem-cell-names = "mac-address";
fixed-link {
speed = <1000>;
full-duplex;

View File

@ -46,11 +46,12 @@ Signed-off-by: Daniel Golle <daniel@makrotopia.org>
select CRC8
--- a/drivers/nvmem/layouts/Makefile
+++ b/drivers/nvmem/layouts/Makefile
@@ -6,3 +6,4 @@
@@ -6,4 +6,5 @@
obj-$(CONFIG_NVMEM_LAYOUT_SL28_VPD) += sl28vpd.o
obj-$(CONFIG_NVMEM_LAYOUT_ONIE_TLV) += onie-tlv.o
obj-$(CONFIG_NVMEM_LAYOUT_U_BOOT_ENV) += u-boot-env.o
+obj-$(CONFIG_NVMEM_LAYOUT_ADTRAN) += adtran.o
obj-$(CONFIG_NVMEM_LAYOUT_ASCII_ENV) += ascii-env.o
--- /dev/null
+++ b/drivers/nvmem/layouts/adtran.c
@@ -0,0 +1,135 @@

View File

@ -51,7 +51,7 @@
compatible = "ralink,rt2880-timer";
reg = <0x100 0x20>;
clocks = <&sysc 5>;
clocks = <&sysc 4>;
interrupt-parent = <&intc>;
interrupts = <1>;
@ -61,7 +61,7 @@
compatible = "ralink,rt2880-wdt";
reg = <0x120 0x10>;
clocks = <&sysc 6>;
clocks = <&sysc 5>;
resets = <&sysc 8>;
reset-names = "wdt";
@ -93,7 +93,7 @@
compatible = "ralink,rt3883-uart", "ralink,rt2880-uart", "ns16550a";
reg = <0x500 0x100>;
clocks = <&sysc 7>;
clocks = <&sysc 6>;
resets = <&sysc 12>;
@ -187,7 +187,7 @@
compatible = "ralink,rt2880-i2c";
reg = <0x900 0x100>;
clocks = <&sysc 8>;
clocks = <&sysc 7>;
resets = <&sysc 16>;
reset-names = "i2c";
@ -205,7 +205,7 @@
compatible = "ralink,rt3883-i2s";
reg = <0xa00 0x100>;
clocks = <&sysc 9>;
clocks = <&sysc 8>;
resets = <&sysc 17>;
reset-names = "i2s";
@ -229,7 +229,7 @@
#address-cells = <1>;
#size-cells = <0>;
clocks = <&sysc 10>;
clocks = <&sysc 9>;
resets = <&sysc 18>;
reset-names = "spi";
@ -246,7 +246,7 @@
#address-cells = <1>;
#size-cells = <0>;
clocks = <&sysc 11>;
clocks = <&sysc 10>;
resets = <&sysc 18>;
reset-names = "spi";
@ -261,7 +261,7 @@
compatible = "ralink,rt3883-uart", "ralink,rt2880-uart", "ns16550a";
reg = <0xc00 0x100>;
clocks = <&sysc 12>;
clocks = <&sysc 11>;
resets = <&sysc 19>;
@ -343,7 +343,7 @@
#size-cells = <0>;
reg = <0x10100000 0x10000>;
clocks = <&sysc 13>;
clocks = <&sysc 12>;
resets = <&sysc 21>;
reset-names = "fe";
@ -463,7 +463,7 @@
compatible = "ralink,rt3883-wmac", "ralink,rt2880-wmac";
reg = <0x10180000 0x40000>;
clocks = <&sysc 14>;
clocks = <&sysc 13>;
interrupt-parent = <&cpuintc>;
interrupts = <6>;

View File

@ -0,0 +1,28 @@
From 830d8062d25581cf0beaa334486eea06834044da Mon Sep 17 00:00:00 2001
From: Sergio Paracuellos <sergio.paracuellos@gmail.com>
Date: Wed, 8 Jan 2025 10:36:36 +0100
Subject: [PATCH] clk: ralink: mtmips: remove duplicated 'xtal' clock for
Ralink SoC RT3883
Ralink SoC RT3883 has already 'xtal' defined as a base clock so there is no
need to redefine it again in fixed clocks section. Hence, remove the duplicate
one from there.
Fixes: d34db686a3d7 ("clk: ralink: mtmips: fix clocks probe order in oldest ralink SoCs")
Signed-off-by: Sergio Paracuellos <sergio.paracuellos@gmail.com>
Link: https://lore.kernel.org/r/20250108093636.265033-1-sergio.paracuellos@gmail.com
Signed-off-by: Stephen Boyd <sboyd@kernel.org>
---
drivers/clk/ralink/clk-mtmips.c | 1 -
1 file changed, 1 deletion(-)
--- a/drivers/clk/ralink/clk-mtmips.c
+++ b/drivers/clk/ralink/clk-mtmips.c
@@ -266,7 +266,6 @@ err_clk_unreg:
}
static struct mtmips_clk_fixed rt3883_fixed_clocks[] = {
- CLK_FIXED("xtal", NULL, 40000000),
CLK_FIXED("periph", "xtal", 40000000)
};

View File

@ -0,0 +1,58 @@
From ef57412d070fe663a66a5473ffc708bd89671259 Mon Sep 17 00:00:00 2001
From: Signed-off-by: Shiji Yang <yangshiji66@outlook.com>
Date: Sun, 2 Feb 2025 17:10:14 +0800
Subject: [PATCH] mips: ralink: update CPU clock index
Some clock indexes have been reorganized in commit d34db686a3d7
("clk: ralink: mtmips: fix clocks probe order in oldest ralink SoCs").
Update CPU clock index to match the clock driver changes.
Signed-off-by: Shiji Yang <yangshiji66@outlook.com>
Co-authored-by: Mieczyslaw Nalewaj <namiltd@yahoo.com>
---
arch/mips/ralink/clk.c | 11 ++---------
1 file changed, 2 insertions(+), 9 deletions(-)
--- a/arch/mips/ralink/clk.c
+++ b/arch/mips/ralink/clk.c
@@ -19,27 +19,22 @@
static const char *clk_cpu(int *idx)
{
+ *idx = 1;
+
switch (ralink_soc) {
case RT2880_SOC:
- *idx = 0;
return "ralink,rt2880-sysc";
case RT3883_SOC:
- *idx = 0;
return "ralink,rt3883-sysc";
case RT305X_SOC_RT3050:
- *idx = 0;
return "ralink,rt3050-sysc";
case RT305X_SOC_RT3052:
- *idx = 0;
return "ralink,rt3052-sysc";
case RT305X_SOC_RT3350:
- *idx = 1;
return "ralink,rt3350-sysc";
case RT305X_SOC_RT3352:
- *idx = 1;
return "ralink,rt3352-sysc";
case RT305X_SOC_RT5350:
- *idx = 1;
return "ralink,rt5350-sysc";
case MT762X_SOC_MT7620A:
*idx = 2;
@@ -48,10 +43,8 @@ static const char *clk_cpu(int *idx)
*idx = 2;
return "ralink,mt7620-sysc";
case MT762X_SOC_MT7628AN:
- *idx = 1;
return "ralink,mt7628-sysc";
case MT762X_SOC_MT7688:
- *idx = 1;
return "ralink,mt7688-sysc";
default:
*idx = -1;