From: Rafał Miłecki Date: Wed, 17 Aug 2022 09:04:29 +0000 (+0200) Subject: kernel: rename 5.20 patches to 6.0 X-Git-Url: http://git.lede-project.org./?a=commitdiff_plain;h=372ee1919d281dd3e86121996805291a6948c982;p=openwrt%2Fstaging%2Fansuel.git kernel: rename 5.20 patches to 6.0 Signed-off-by: Rafał Miłecki --- diff --git a/target/linux/generic/backport-5.10/411-v5.20-mtd-parsers-add-support-for-Sercomm-partitions.patch b/target/linux/generic/backport-5.10/411-v5.20-mtd-parsers-add-support-for-Sercomm-partitions.patch deleted file mode 100644 index 5ed6fd1b3b..0000000000 --- a/target/linux/generic/backport-5.10/411-v5.20-mtd-parsers-add-support-for-Sercomm-partitions.patch +++ /dev/null @@ -1,301 +0,0 @@ -From 9b78ef0c7997052e9eaa0f7a4513d546fa17358c Mon Sep 17 00:00:00 2001 -From: Mikhail Zhilkin -Date: Sun, 29 May 2022 11:07:14 +0000 -Subject: [PATCH] mtd: parsers: add support for Sercomm partitions - -This adds an MTD partition parser for the Sercomm partition table that -is used in some Beeline, Netgear and Sercomm routers. - -The Sercomm partition map table contains real partition offsets, which -may differ from device to device depending on the number and location of -bad blocks on NAND. - -Original patch (proposed by NOGUCHI Hiroshi): -Link: https://github.com/openwrt/openwrt/pull/1318#issuecomment-420607394 - -Signed-off-by: NOGUCHI Hiroshi -Signed-off-by: Mikhail Zhilkin -Signed-off-by: Miquel Raynal -Link: https://lore.kernel.org/linux-mtd/20220529110714.189732-1-csharper2005@gmail.com ---- - drivers/mtd/parsers/Kconfig | 9 ++ - drivers/mtd/parsers/Makefile | 1 + - drivers/mtd/parsers/scpart.c | 248 +++++++++++++++++++++++++++++++++++ - 3 files changed, 258 insertions(+) - create mode 100644 drivers/mtd/parsers/scpart.c - ---- a/drivers/mtd/parsers/Kconfig -+++ b/drivers/mtd/parsers/Kconfig -@@ -179,3 +179,12 @@ config MTD_REDBOOT_PARTS_READONLY - 'FIS directory' images, enable this option. - - endif # MTD_REDBOOT_PARTS -+ -+config MTD_SERCOMM_PARTS -+ tristate "Sercomm partition table parser" -+ depends on MTD && RALINK -+ help -+ This provides partitions table parser for devices with Sercomm -+ partition map. This partition table contains real partition -+ offsets, which may differ from device to device depending on the -+ number and location of bad blocks on NAND. ---- a/drivers/mtd/parsers/Makefile -+++ b/drivers/mtd/parsers/Makefile -@@ -10,5 +10,6 @@ ofpart-$(CONFIG_MTD_OF_PARTS_LINKSYS_NS) - obj-$(CONFIG_MTD_PARSER_IMAGETAG) += parser_imagetag.o - obj-$(CONFIG_MTD_AFS_PARTS) += afs.o - obj-$(CONFIG_MTD_PARSER_TRX) += parser_trx.o -+obj-$(CONFIG_MTD_SERCOMM_PARTS) += scpart.o - obj-$(CONFIG_MTD_SHARPSL_PARTS) += sharpslpart.o - obj-$(CONFIG_MTD_REDBOOT_PARTS) += redboot.o ---- /dev/null -+++ b/drivers/mtd/parsers/scpart.c -@@ -0,0 +1,248 @@ -+// SPDX-License-Identifier: GPL-2.0-or-later -+/* -+ * drivers/mtd/scpart.c: Sercomm Partition Parser -+ * -+ * Copyright (C) 2018 NOGUCHI Hiroshi -+ * Copyright (C) 2022 Mikhail Zhilkin -+ */ -+ -+#include -+#include -+#include -+#include -+#include -+ -+#define MOD_NAME "scpart" -+ -+#ifdef pr_fmt -+#undef pr_fmt -+#endif -+ -+#define pr_fmt(fmt) MOD_NAME ": " fmt -+ -+#define ID_ALREADY_FOUND 0xffffffffUL -+ -+#define MAP_OFFS_IN_BLK 0x800 -+#define MAP_MIRROR_NUM 2 -+ -+static const char sc_part_magic[] = { -+ 'S', 'C', 'F', 'L', 'M', 'A', 'P', 'O', 'K', '\0', -+}; -+#define PART_MAGIC_LEN sizeof(sc_part_magic) -+ -+/* assumes that all fields are set by CPU native endian */ -+struct sc_part_desc { -+ uint32_t part_id; -+ uint32_t part_offs; -+ uint32_t part_bytes; -+}; -+ -+static uint32_t scpart_desc_is_valid(struct sc_part_desc *pdesc) -+{ -+ return ((pdesc->part_id != 0xffffffffUL) && -+ (pdesc->part_offs != 0xffffffffUL) && -+ (pdesc->part_bytes != 0xffffffffUL)); -+} -+ -+static int scpart_scan_partmap(struct mtd_info *master, loff_t partmap_offs, -+ struct sc_part_desc **ppdesc) -+{ -+ int cnt = 0; -+ int res = 0; -+ int res2; -+ loff_t offs; -+ size_t retlen; -+ struct sc_part_desc *pdesc = NULL; -+ struct sc_part_desc *tmpdesc; -+ uint8_t *buf; -+ -+ buf = kzalloc(master->erasesize, GFP_KERNEL); -+ if (!buf) { -+ res = -ENOMEM; -+ goto out; -+ } -+ -+ res2 = mtd_read(master, partmap_offs, master->erasesize, &retlen, buf); -+ if (res2 || retlen != master->erasesize) { -+ res = -EIO; -+ goto free; -+ } -+ -+ for (offs = MAP_OFFS_IN_BLK; -+ offs < master->erasesize - sizeof(*tmpdesc); -+ offs += sizeof(*tmpdesc)) { -+ tmpdesc = (struct sc_part_desc *)&buf[offs]; -+ if (!scpart_desc_is_valid(tmpdesc)) -+ break; -+ cnt++; -+ } -+ -+ if (cnt > 0) { -+ int bytes = cnt * sizeof(*pdesc); -+ -+ pdesc = kcalloc(cnt, sizeof(*pdesc), GFP_KERNEL); -+ if (!pdesc) { -+ res = -ENOMEM; -+ goto free; -+ } -+ memcpy(pdesc, &(buf[MAP_OFFS_IN_BLK]), bytes); -+ -+ *ppdesc = pdesc; -+ res = cnt; -+ } -+ -+free: -+ kfree(buf); -+ -+out: -+ return res; -+} -+ -+static int scpart_find_partmap(struct mtd_info *master, -+ struct sc_part_desc **ppdesc) -+{ -+ int magic_found = 0; -+ int res = 0; -+ int res2; -+ loff_t offs = 0; -+ size_t retlen; -+ uint8_t rdbuf[PART_MAGIC_LEN]; -+ -+ while ((magic_found < MAP_MIRROR_NUM) && -+ (offs < master->size) && -+ !mtd_block_isbad(master, offs)) { -+ res2 = mtd_read(master, offs, PART_MAGIC_LEN, &retlen, rdbuf); -+ if (res2 || retlen != PART_MAGIC_LEN) { -+ res = -EIO; -+ goto out; -+ } -+ if (!memcmp(rdbuf, sc_part_magic, PART_MAGIC_LEN)) { -+ pr_debug("Signature found at 0x%llx\n", offs); -+ magic_found++; -+ res = scpart_scan_partmap(master, offs, ppdesc); -+ if (res > 0) -+ goto out; -+ } -+ offs += master->erasesize; -+ } -+ -+out: -+ if (res > 0) -+ pr_info("Valid 'SC PART MAP' (%d partitions) found at 0x%llx\n", res, offs); -+ else -+ pr_info("No valid 'SC PART MAP' was found\n"); -+ -+ return res; -+} -+ -+static int scpart_parse(struct mtd_info *master, -+ const struct mtd_partition **pparts, -+ struct mtd_part_parser_data *data) -+{ -+ const char *partname; -+ int n; -+ int nr_scparts; -+ int nr_parts = 0; -+ int res = 0; -+ struct sc_part_desc *scpart_map = NULL; -+ struct mtd_partition *parts = NULL; -+ struct device_node *mtd_node; -+ struct device_node *ofpart_node; -+ struct device_node *pp; -+ -+ mtd_node = mtd_get_of_node(master); -+ if (!mtd_node) { -+ res = -ENOENT; -+ goto out; -+ } -+ -+ ofpart_node = of_get_child_by_name(mtd_node, "partitions"); -+ if (!ofpart_node) { -+ pr_info("%s: 'partitions' subnode not found on %pOF.\n", -+ master->name, mtd_node); -+ res = -ENOENT; -+ goto out; -+ } -+ -+ nr_scparts = scpart_find_partmap(master, &scpart_map); -+ if (nr_scparts <= 0) { -+ pr_info("No any partitions was found in 'SC PART MAP'.\n"); -+ res = -ENOENT; -+ goto free; -+ } -+ -+ parts = kcalloc(of_get_child_count(ofpart_node), sizeof(*parts), -+ GFP_KERNEL); -+ if (!parts) { -+ res = -ENOMEM; -+ goto free; -+ } -+ -+ for_each_child_of_node(ofpart_node, pp) { -+ u32 scpart_id; -+ -+ if (of_property_read_u32(pp, "sercomm,scpart-id", &scpart_id)) -+ continue; -+ -+ for (n = 0 ; n < nr_scparts ; n++) -+ if ((scpart_map[n].part_id != ID_ALREADY_FOUND) && -+ (scpart_id == scpart_map[n].part_id)) -+ break; -+ if (n >= nr_scparts) -+ /* not match */ -+ continue; -+ -+ /* add the partition found in OF into MTD partition array */ -+ parts[nr_parts].offset = scpart_map[n].part_offs; -+ parts[nr_parts].size = scpart_map[n].part_bytes; -+ parts[nr_parts].of_node = pp; -+ -+ if (!of_property_read_string(pp, "label", &partname)) -+ parts[nr_parts].name = partname; -+ if (of_property_read_bool(pp, "read-only")) -+ parts[nr_parts].mask_flags |= MTD_WRITEABLE; -+ if (of_property_read_bool(pp, "lock")) -+ parts[nr_parts].mask_flags |= MTD_POWERUP_LOCK; -+ -+ /* mark as 'done' */ -+ scpart_map[n].part_id = ID_ALREADY_FOUND; -+ -+ nr_parts++; -+ } -+ -+ if (nr_parts > 0) { -+ *pparts = parts; -+ res = nr_parts; -+ } else -+ pr_info("No partition in OF matches partition ID with 'SC PART MAP'.\n"); -+ -+ of_node_put(pp); -+ -+free: -+ kfree(scpart_map); -+ if (res <= 0) -+ kfree(parts); -+ -+out: -+ return res; -+} -+ -+static const struct of_device_id scpart_parser_of_match_table[] = { -+ { .compatible = "sercomm,sc-partitions" }, -+ {}, -+}; -+MODULE_DEVICE_TABLE(of, scpart_parser_of_match_table); -+ -+static struct mtd_part_parser scpart_parser = { -+ .parse_fn = scpart_parse, -+ .name = "scpart", -+ .of_match_table = scpart_parser_of_match_table, -+}; -+module_mtd_part_parser(scpart_parser); -+ -+/* mtd parsers will request the module by parser name */ -+MODULE_ALIAS("scpart"); -+MODULE_LICENSE("GPL"); -+MODULE_AUTHOR("NOGUCHI Hiroshi "); -+MODULE_AUTHOR("Mikhail Zhilkin "); -+MODULE_DESCRIPTION("Sercomm partition parser"); diff --git a/target/linux/generic/backport-5.10/411-v6.0-mtd-parsers-add-support-for-Sercomm-partitions.patch b/target/linux/generic/backport-5.10/411-v6.0-mtd-parsers-add-support-for-Sercomm-partitions.patch new file mode 100644 index 0000000000..5ed6fd1b3b --- /dev/null +++ b/target/linux/generic/backport-5.10/411-v6.0-mtd-parsers-add-support-for-Sercomm-partitions.patch @@ -0,0 +1,301 @@ +From 9b78ef0c7997052e9eaa0f7a4513d546fa17358c Mon Sep 17 00:00:00 2001 +From: Mikhail Zhilkin +Date: Sun, 29 May 2022 11:07:14 +0000 +Subject: [PATCH] mtd: parsers: add support for Sercomm partitions + +This adds an MTD partition parser for the Sercomm partition table that +is used in some Beeline, Netgear and Sercomm routers. + +The Sercomm partition map table contains real partition offsets, which +may differ from device to device depending on the number and location of +bad blocks on NAND. + +Original patch (proposed by NOGUCHI Hiroshi): +Link: https://github.com/openwrt/openwrt/pull/1318#issuecomment-420607394 + +Signed-off-by: NOGUCHI Hiroshi +Signed-off-by: Mikhail Zhilkin +Signed-off-by: Miquel Raynal +Link: https://lore.kernel.org/linux-mtd/20220529110714.189732-1-csharper2005@gmail.com +--- + drivers/mtd/parsers/Kconfig | 9 ++ + drivers/mtd/parsers/Makefile | 1 + + drivers/mtd/parsers/scpart.c | 248 +++++++++++++++++++++++++++++++++++ + 3 files changed, 258 insertions(+) + create mode 100644 drivers/mtd/parsers/scpart.c + +--- a/drivers/mtd/parsers/Kconfig ++++ b/drivers/mtd/parsers/Kconfig +@@ -179,3 +179,12 @@ config MTD_REDBOOT_PARTS_READONLY + 'FIS directory' images, enable this option. + + endif # MTD_REDBOOT_PARTS ++ ++config MTD_SERCOMM_PARTS ++ tristate "Sercomm partition table parser" ++ depends on MTD && RALINK ++ help ++ This provides partitions table parser for devices with Sercomm ++ partition map. This partition table contains real partition ++ offsets, which may differ from device to device depending on the ++ number and location of bad blocks on NAND. +--- a/drivers/mtd/parsers/Makefile ++++ b/drivers/mtd/parsers/Makefile +@@ -10,5 +10,6 @@ ofpart-$(CONFIG_MTD_OF_PARTS_LINKSYS_NS) + obj-$(CONFIG_MTD_PARSER_IMAGETAG) += parser_imagetag.o + obj-$(CONFIG_MTD_AFS_PARTS) += afs.o + obj-$(CONFIG_MTD_PARSER_TRX) += parser_trx.o ++obj-$(CONFIG_MTD_SERCOMM_PARTS) += scpart.o + obj-$(CONFIG_MTD_SHARPSL_PARTS) += sharpslpart.o + obj-$(CONFIG_MTD_REDBOOT_PARTS) += redboot.o +--- /dev/null ++++ b/drivers/mtd/parsers/scpart.c +@@ -0,0 +1,248 @@ ++// SPDX-License-Identifier: GPL-2.0-or-later ++/* ++ * drivers/mtd/scpart.c: Sercomm Partition Parser ++ * ++ * Copyright (C) 2018 NOGUCHI Hiroshi ++ * Copyright (C) 2022 Mikhail Zhilkin ++ */ ++ ++#include ++#include ++#include ++#include ++#include ++ ++#define MOD_NAME "scpart" ++ ++#ifdef pr_fmt ++#undef pr_fmt ++#endif ++ ++#define pr_fmt(fmt) MOD_NAME ": " fmt ++ ++#define ID_ALREADY_FOUND 0xffffffffUL ++ ++#define MAP_OFFS_IN_BLK 0x800 ++#define MAP_MIRROR_NUM 2 ++ ++static const char sc_part_magic[] = { ++ 'S', 'C', 'F', 'L', 'M', 'A', 'P', 'O', 'K', '\0', ++}; ++#define PART_MAGIC_LEN sizeof(sc_part_magic) ++ ++/* assumes that all fields are set by CPU native endian */ ++struct sc_part_desc { ++ uint32_t part_id; ++ uint32_t part_offs; ++ uint32_t part_bytes; ++}; ++ ++static uint32_t scpart_desc_is_valid(struct sc_part_desc *pdesc) ++{ ++ return ((pdesc->part_id != 0xffffffffUL) && ++ (pdesc->part_offs != 0xffffffffUL) && ++ (pdesc->part_bytes != 0xffffffffUL)); ++} ++ ++static int scpart_scan_partmap(struct mtd_info *master, loff_t partmap_offs, ++ struct sc_part_desc **ppdesc) ++{ ++ int cnt = 0; ++ int res = 0; ++ int res2; ++ loff_t offs; ++ size_t retlen; ++ struct sc_part_desc *pdesc = NULL; ++ struct sc_part_desc *tmpdesc; ++ uint8_t *buf; ++ ++ buf = kzalloc(master->erasesize, GFP_KERNEL); ++ if (!buf) { ++ res = -ENOMEM; ++ goto out; ++ } ++ ++ res2 = mtd_read(master, partmap_offs, master->erasesize, &retlen, buf); ++ if (res2 || retlen != master->erasesize) { ++ res = -EIO; ++ goto free; ++ } ++ ++ for (offs = MAP_OFFS_IN_BLK; ++ offs < master->erasesize - sizeof(*tmpdesc); ++ offs += sizeof(*tmpdesc)) { ++ tmpdesc = (struct sc_part_desc *)&buf[offs]; ++ if (!scpart_desc_is_valid(tmpdesc)) ++ break; ++ cnt++; ++ } ++ ++ if (cnt > 0) { ++ int bytes = cnt * sizeof(*pdesc); ++ ++ pdesc = kcalloc(cnt, sizeof(*pdesc), GFP_KERNEL); ++ if (!pdesc) { ++ res = -ENOMEM; ++ goto free; ++ } ++ memcpy(pdesc, &(buf[MAP_OFFS_IN_BLK]), bytes); ++ ++ *ppdesc = pdesc; ++ res = cnt; ++ } ++ ++free: ++ kfree(buf); ++ ++out: ++ return res; ++} ++ ++static int scpart_find_partmap(struct mtd_info *master, ++ struct sc_part_desc **ppdesc) ++{ ++ int magic_found = 0; ++ int res = 0; ++ int res2; ++ loff_t offs = 0; ++ size_t retlen; ++ uint8_t rdbuf[PART_MAGIC_LEN]; ++ ++ while ((magic_found < MAP_MIRROR_NUM) && ++ (offs < master->size) && ++ !mtd_block_isbad(master, offs)) { ++ res2 = mtd_read(master, offs, PART_MAGIC_LEN, &retlen, rdbuf); ++ if (res2 || retlen != PART_MAGIC_LEN) { ++ res = -EIO; ++ goto out; ++ } ++ if (!memcmp(rdbuf, sc_part_magic, PART_MAGIC_LEN)) { ++ pr_debug("Signature found at 0x%llx\n", offs); ++ magic_found++; ++ res = scpart_scan_partmap(master, offs, ppdesc); ++ if (res > 0) ++ goto out; ++ } ++ offs += master->erasesize; ++ } ++ ++out: ++ if (res > 0) ++ pr_info("Valid 'SC PART MAP' (%d partitions) found at 0x%llx\n", res, offs); ++ else ++ pr_info("No valid 'SC PART MAP' was found\n"); ++ ++ return res; ++} ++ ++static int scpart_parse(struct mtd_info *master, ++ const struct mtd_partition **pparts, ++ struct mtd_part_parser_data *data) ++{ ++ const char *partname; ++ int n; ++ int nr_scparts; ++ int nr_parts = 0; ++ int res = 0; ++ struct sc_part_desc *scpart_map = NULL; ++ struct mtd_partition *parts = NULL; ++ struct device_node *mtd_node; ++ struct device_node *ofpart_node; ++ struct device_node *pp; ++ ++ mtd_node = mtd_get_of_node(master); ++ if (!mtd_node) { ++ res = -ENOENT; ++ goto out; ++ } ++ ++ ofpart_node = of_get_child_by_name(mtd_node, "partitions"); ++ if (!ofpart_node) { ++ pr_info("%s: 'partitions' subnode not found on %pOF.\n", ++ master->name, mtd_node); ++ res = -ENOENT; ++ goto out; ++ } ++ ++ nr_scparts = scpart_find_partmap(master, &scpart_map); ++ if (nr_scparts <= 0) { ++ pr_info("No any partitions was found in 'SC PART MAP'.\n"); ++ res = -ENOENT; ++ goto free; ++ } ++ ++ parts = kcalloc(of_get_child_count(ofpart_node), sizeof(*parts), ++ GFP_KERNEL); ++ if (!parts) { ++ res = -ENOMEM; ++ goto free; ++ } ++ ++ for_each_child_of_node(ofpart_node, pp) { ++ u32 scpart_id; ++ ++ if (of_property_read_u32(pp, "sercomm,scpart-id", &scpart_id)) ++ continue; ++ ++ for (n = 0 ; n < nr_scparts ; n++) ++ if ((scpart_map[n].part_id != ID_ALREADY_FOUND) && ++ (scpart_id == scpart_map[n].part_id)) ++ break; ++ if (n >= nr_scparts) ++ /* not match */ ++ continue; ++ ++ /* add the partition found in OF into MTD partition array */ ++ parts[nr_parts].offset = scpart_map[n].part_offs; ++ parts[nr_parts].size = scpart_map[n].part_bytes; ++ parts[nr_parts].of_node = pp; ++ ++ if (!of_property_read_string(pp, "label", &partname)) ++ parts[nr_parts].name = partname; ++ if (of_property_read_bool(pp, "read-only")) ++ parts[nr_parts].mask_flags |= MTD_WRITEABLE; ++ if (of_property_read_bool(pp, "lock")) ++ parts[nr_parts].mask_flags |= MTD_POWERUP_LOCK; ++ ++ /* mark as 'done' */ ++ scpart_map[n].part_id = ID_ALREADY_FOUND; ++ ++ nr_parts++; ++ } ++ ++ if (nr_parts > 0) { ++ *pparts = parts; ++ res = nr_parts; ++ } else ++ pr_info("No partition in OF matches partition ID with 'SC PART MAP'.\n"); ++ ++ of_node_put(pp); ++ ++free: ++ kfree(scpart_map); ++ if (res <= 0) ++ kfree(parts); ++ ++out: ++ return res; ++} ++ ++static const struct of_device_id scpart_parser_of_match_table[] = { ++ { .compatible = "sercomm,sc-partitions" }, ++ {}, ++}; ++MODULE_DEVICE_TABLE(of, scpart_parser_of_match_table); ++ ++static struct mtd_part_parser scpart_parser = { ++ .parse_fn = scpart_parse, ++ .name = "scpart", ++ .of_match_table = scpart_parser_of_match_table, ++}; ++module_mtd_part_parser(scpart_parser); ++ ++/* mtd parsers will request the module by parser name */ ++MODULE_ALIAS("scpart"); ++MODULE_LICENSE("GPL"); ++MODULE_AUTHOR("NOGUCHI Hiroshi "); ++MODULE_AUTHOR("Mikhail Zhilkin "); ++MODULE_DESCRIPTION("Sercomm partition parser"); diff --git a/target/linux/generic/backport-5.10/413-v5.20-mtd-next-mtd-core-introduce-of-support-for-dynamic-partitions.patch b/target/linux/generic/backport-5.10/413-v5.20-mtd-next-mtd-core-introduce-of-support-for-dynamic-partitions.patch deleted file mode 100644 index 801d9a13cb..0000000000 --- a/target/linux/generic/backport-5.10/413-v5.20-mtd-next-mtd-core-introduce-of-support-for-dynamic-partitions.patch +++ /dev/null @@ -1,106 +0,0 @@ -From ad9b10d1eaada169bd764abcab58f08538877e26 Mon Sep 17 00:00:00 2001 -From: Christian Marangi -Date: Wed, 22 Jun 2022 03:06:28 +0200 -Subject: mtd: core: introduce of support for dynamic partitions - -We have many parser that register mtd partitions at runtime. One example -is the cmdlinepart or the smem-part parser where the compatible is defined -in the dts and the partitions gets detected and registered by the -parser. This is problematic for the NVMEM subsystem that requires an OF -node to detect NVMEM cells. - -To fix this problem, introduce an additional logic that will try to -assign an OF node to the MTD if declared. - -On MTD addition, it will be checked if the MTD has an OF node and if -not declared will check if a partition with the same label / node name is -declared in DTS. If an exact match is found, the partition dynamically -allocated by the parser will have a connected OF node. - -The NVMEM subsystem will detect the OF node and register any NVMEM cells -declared statically in the DTS. - -Signed-off-by: Christian Marangi -Signed-off-by: Miquel Raynal -Link: https://lore.kernel.org/linux-mtd/20220622010628.30414-4-ansuelsmth@gmail.com ---- - drivers/mtd/mtdcore.c | 61 +++++++++++++++++++++++++++++++++++++++++++ - 1 file changed, 61 insertions(+) - ---- a/drivers/mtd/mtdcore.c -+++ b/drivers/mtd/mtdcore.c -@@ -561,6 +561,66 @@ static int mtd_nvmem_add(struct mtd_info - return 0; - } - -+static void mtd_check_of_node(struct mtd_info *mtd) -+{ -+ struct device_node *partitions, *parent_dn, *mtd_dn = NULL; -+ const char *pname, *prefix = "partition-"; -+ int plen, mtd_name_len, offset, prefix_len; -+ struct mtd_info *parent; -+ bool found = false; -+ -+ /* Check if MTD already has a device node */ -+ if (dev_of_node(&mtd->dev)) -+ return; -+ -+ /* Check if a partitions node exist */ -+ parent = mtd->parent; -+ parent_dn = dev_of_node(&parent->dev); -+ if (!parent_dn) -+ return; -+ -+ partitions = of_get_child_by_name(parent_dn, "partitions"); -+ if (!partitions) -+ goto exit_parent; -+ -+ prefix_len = strlen(prefix); -+ mtd_name_len = strlen(mtd->name); -+ -+ /* Search if a partition is defined with the same name */ -+ for_each_child_of_node(partitions, mtd_dn) { -+ offset = 0; -+ -+ /* Skip partition with no/wrong prefix */ -+ if (!of_node_name_prefix(mtd_dn, "partition-")) -+ continue; -+ -+ /* Label have priority. Check that first */ -+ if (of_property_read_string(mtd_dn, "label", &pname)) { -+ of_property_read_string(mtd_dn, "name", &pname); -+ offset = prefix_len; -+ } -+ -+ plen = strlen(pname) - offset; -+ if (plen == mtd_name_len && -+ !strncmp(mtd->name, pname + offset, plen)) { -+ found = true; -+ break; -+ } -+ } -+ -+ if (!found) -+ goto exit_partitions; -+ -+ /* Set of_node only for nvmem */ -+ if (of_device_is_compatible(mtd_dn, "nvmem-cells")) -+ mtd_set_of_node(mtd, mtd_dn); -+ -+exit_partitions: -+ of_node_put(partitions); -+exit_parent: -+ of_node_put(parent_dn); -+} -+ - /** - * add_mtd_device - register an MTD device - * @mtd: pointer to new MTD device info structure -@@ -666,6 +726,7 @@ int add_mtd_device(struct mtd_info *mtd) - mtd->dev.devt = MTD_DEVT(i); - dev_set_name(&mtd->dev, "mtd%d", i); - dev_set_drvdata(&mtd->dev, mtd); -+ mtd_check_of_node(mtd); - of_node_get(mtd_get_of_node(mtd)); - error = device_register(&mtd->dev); - if (error) diff --git a/target/linux/generic/backport-5.10/413-v6.0-mtd-next-mtd-core-introduce-of-support-for-dynamic-partitions.patch b/target/linux/generic/backport-5.10/413-v6.0-mtd-next-mtd-core-introduce-of-support-for-dynamic-partitions.patch new file mode 100644 index 0000000000..801d9a13cb --- /dev/null +++ b/target/linux/generic/backport-5.10/413-v6.0-mtd-next-mtd-core-introduce-of-support-for-dynamic-partitions.patch @@ -0,0 +1,106 @@ +From ad9b10d1eaada169bd764abcab58f08538877e26 Mon Sep 17 00:00:00 2001 +From: Christian Marangi +Date: Wed, 22 Jun 2022 03:06:28 +0200 +Subject: mtd: core: introduce of support for dynamic partitions + +We have many parser that register mtd partitions at runtime. One example +is the cmdlinepart or the smem-part parser where the compatible is defined +in the dts and the partitions gets detected and registered by the +parser. This is problematic for the NVMEM subsystem that requires an OF +node to detect NVMEM cells. + +To fix this problem, introduce an additional logic that will try to +assign an OF node to the MTD if declared. + +On MTD addition, it will be checked if the MTD has an OF node and if +not declared will check if a partition with the same label / node name is +declared in DTS. If an exact match is found, the partition dynamically +allocated by the parser will have a connected OF node. + +The NVMEM subsystem will detect the OF node and register any NVMEM cells +declared statically in the DTS. + +Signed-off-by: Christian Marangi +Signed-off-by: Miquel Raynal +Link: https://lore.kernel.org/linux-mtd/20220622010628.30414-4-ansuelsmth@gmail.com +--- + drivers/mtd/mtdcore.c | 61 +++++++++++++++++++++++++++++++++++++++++++ + 1 file changed, 61 insertions(+) + +--- a/drivers/mtd/mtdcore.c ++++ b/drivers/mtd/mtdcore.c +@@ -561,6 +561,66 @@ static int mtd_nvmem_add(struct mtd_info + return 0; + } + ++static void mtd_check_of_node(struct mtd_info *mtd) ++{ ++ struct device_node *partitions, *parent_dn, *mtd_dn = NULL; ++ const char *pname, *prefix = "partition-"; ++ int plen, mtd_name_len, offset, prefix_len; ++ struct mtd_info *parent; ++ bool found = false; ++ ++ /* Check if MTD already has a device node */ ++ if (dev_of_node(&mtd->dev)) ++ return; ++ ++ /* Check if a partitions node exist */ ++ parent = mtd->parent; ++ parent_dn = dev_of_node(&parent->dev); ++ if (!parent_dn) ++ return; ++ ++ partitions = of_get_child_by_name(parent_dn, "partitions"); ++ if (!partitions) ++ goto exit_parent; ++ ++ prefix_len = strlen(prefix); ++ mtd_name_len = strlen(mtd->name); ++ ++ /* Search if a partition is defined with the same name */ ++ for_each_child_of_node(partitions, mtd_dn) { ++ offset = 0; ++ ++ /* Skip partition with no/wrong prefix */ ++ if (!of_node_name_prefix(mtd_dn, "partition-")) ++ continue; ++ ++ /* Label have priority. Check that first */ ++ if (of_property_read_string(mtd_dn, "label", &pname)) { ++ of_property_read_string(mtd_dn, "name", &pname); ++ offset = prefix_len; ++ } ++ ++ plen = strlen(pname) - offset; ++ if (plen == mtd_name_len && ++ !strncmp(mtd->name, pname + offset, plen)) { ++ found = true; ++ break; ++ } ++ } ++ ++ if (!found) ++ goto exit_partitions; ++ ++ /* Set of_node only for nvmem */ ++ if (of_device_is_compatible(mtd_dn, "nvmem-cells")) ++ mtd_set_of_node(mtd, mtd_dn); ++ ++exit_partitions: ++ of_node_put(partitions); ++exit_parent: ++ of_node_put(parent_dn); ++} ++ + /** + * add_mtd_device - register an MTD device + * @mtd: pointer to new MTD device info structure +@@ -666,6 +726,7 @@ int add_mtd_device(struct mtd_info *mtd) + mtd->dev.devt = MTD_DEVT(i); + dev_set_name(&mtd->dev, "mtd%d", i); + dev_set_drvdata(&mtd->dev, mtd); ++ mtd_check_of_node(mtd); + of_node_get(mtd_get_of_node(mtd)); + error = device_register(&mtd->dev); + if (error) diff --git a/target/linux/generic/backport-5.10/845-v5.20-0001-dt-bindings-leds-add-Broadcom-s-BCM63138-controller.patch b/target/linux/generic/backport-5.10/845-v5.20-0001-dt-bindings-leds-add-Broadcom-s-BCM63138-controller.patch deleted file mode 100644 index b1072ce640..0000000000 --- a/target/linux/generic/backport-5.10/845-v5.20-0001-dt-bindings-leds-add-Broadcom-s-BCM63138-controller.patch +++ /dev/null @@ -1,125 +0,0 @@ -From 13344f8ce8a0d98aa7f5d69ce3b47393c73a343b Mon Sep 17 00:00:00 2001 -From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= -Date: Mon, 27 Dec 2021 15:59:04 +0100 -Subject: [PATCH] dt-bindings: leds: add Broadcom's BCM63138 controller -MIME-Version: 1.0 -Content-Type: text/plain; charset=UTF-8 -Content-Transfer-Encoding: 8bit - -Broadcom used 2 LEDs hardware blocks for their BCM63xx SoCs: -1. Older one (BCM6318, BCM6328, BCM6362, BCM63268, BCM6838) -2. Newer one (BCM6848, BCM6858, BCM63138, BCM63148, BCM63381, BCM68360) - -The newer one was also later also used on BCM4908 SoC. - -Old block is already documented in the leds-bcm6328.yaml. This binding -documents the new one which uses different registers & programming. It's -first used in BCM63138 thus the binding name. - -Signed-off-by: Rafał Miłecki -Reviewed-by: Rob Herring -Reviewed-by: Florian Fainelli -Signed-off-by: Pavel Machek ---- - .../bindings/leds/leds-bcm63138.yaml | 95 +++++++++++++++++++ - 1 file changed, 95 insertions(+) - create mode 100644 Documentation/devicetree/bindings/leds/leds-bcm63138.yaml - ---- /dev/null -+++ b/Documentation/devicetree/bindings/leds/leds-bcm63138.yaml -@@ -0,0 +1,95 @@ -+# SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause -+%YAML 1.2 -+--- -+$id: http://devicetree.org/schemas/leds/leds-bcm63138.yaml# -+$schema: http://devicetree.org/meta-schemas/core.yaml# -+ -+title: Broadcom's BCM63138 LEDs controller -+ -+maintainers: -+ - Rafał Miłecki -+ -+description: | -+ This LEDs controller was first used on BCM63138 and later reused on BCM4908, -+ BCM6848, BCM6858, BCM63138, BCM63148, BCM63381 and BCM68360 SoCs. -+ -+ It supports up to 32 LEDs that can be connected parallelly or serially. It -+ also includes limited support for hardware blinking. -+ -+ Binding serially connected LEDs isn't documented yet. -+ -+properties: -+ compatible: -+ oneOf: -+ - items: -+ - enum: -+ - brcm,bcm4908-leds -+ - brcm,bcm6848-leds -+ - brcm,bcm6858-leds -+ - brcm,bcm63148-leds -+ - brcm,bcm63381-leds -+ - brcm,bcm68360-leds -+ - const: brcm,bcm63138-leds -+ - const: brcm,bcm63138-leds -+ -+ reg: -+ maxItems: 1 -+ -+ "#address-cells": -+ const: 1 -+ -+ "#size-cells": -+ const: 0 -+ -+patternProperties: -+ "^led@[a-f0-9]+$": -+ type: object -+ -+ $ref: common.yaml# -+ -+ properties: -+ reg: -+ maxItems: 1 -+ description: LED pin number -+ -+ active-low: -+ type: boolean -+ description: Makes LED active low. -+ -+ required: -+ - reg -+ -+ unevaluatedProperties: false -+ -+required: -+ - reg -+ - "#address-cells" -+ - "#size-cells" -+ -+additionalProperties: false -+ -+examples: -+ - | -+ #include -+ -+ leds@ff800800 { -+ compatible = "brcm,bcm4908-leds", "brcm,bcm63138-leds"; -+ reg = <0xff800800 0xdc>; -+ -+ #address-cells = <1>; -+ #size-cells = <0>; -+ -+ led@0 { -+ reg = <0x0>; -+ function = LED_FUNCTION_POWER; -+ color = ; -+ default-state = "on"; -+ }; -+ -+ led@3 { -+ reg = <0x3>; -+ function = LED_FUNCTION_STATUS; -+ color = ; -+ active-low; -+ }; -+ }; diff --git a/target/linux/generic/backport-5.10/845-v5.20-0002-leds-bcm63138-add-support-for-BCM63138-controller.patch b/target/linux/generic/backport-5.10/845-v5.20-0002-leds-bcm63138-add-support-for-BCM63138-controller.patch deleted file mode 100644 index 8ebe8f180b..0000000000 --- a/target/linux/generic/backport-5.10/845-v5.20-0002-leds-bcm63138-add-support-for-BCM63138-controller.patch +++ /dev/null @@ -1,371 +0,0 @@ -From a0ba692072d89075d0a75c7ad9df31f2c1ee9a1c Mon Sep 17 00:00:00 2001 -From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= -Date: Mon, 27 Dec 2021 15:59:05 +0100 -Subject: [PATCH] leds: bcm63138: add support for BCM63138 controller -MIME-Version: 1.0 -Content-Type: text/plain; charset=UTF-8 -Content-Transfer-Encoding: 8bit - -It's a new controller first introduced in BCM63138 SoC. Later it was -also used in BCM4908, some BCM68xx and some BCM63xxx SoCs. - -Signed-off-by: Rafał Miłecki -Reviewed-by: Florian Fainelli -Signed-off-by: Pavel Machek ---- - drivers/leds/blink/Kconfig | 12 ++ - drivers/leds/blink/Makefile | 1 + - drivers/leds/blink/leds-bcm63138.c | 308 +++++++++++++++++++++++++++++ - 3 files changed, 321 insertions(+) - create mode 100644 drivers/leds/blink/leds-bcm63138.c - ---- /dev/null -+++ b/drivers/leds/blink/Kconfig -@@ -0,0 +1,11 @@ -+config LEDS_BCM63138 -+ tristate "LED Support for Broadcom BCM63138 SoC" -+ depends on LEDS_CLASS -+ depends on ARCH_BCM4908 || ARCH_BCM_5301X || BCM63XX || COMPILE_TEST -+ depends on HAS_IOMEM -+ depends on OF -+ default ARCH_BCM4908 -+ help -+ This option enables support for LED controller that is part of -+ BCM63138 SoC. The same hardware block is known to be also used -+ in BCM4908, BCM6848, BCM6858, BCM63148, BCM63381 and BCM68360. ---- /dev/null -+++ b/drivers/leds/blink/Makefile -@@ -0,0 +1,2 @@ -+# SPDX-License-Identifier: GPL-2.0 -+obj-$(CONFIG_LEDS_BCM63138) += leds-bcm63138.o ---- /dev/null -+++ b/drivers/leds/blink/leds-bcm63138.c -@@ -0,0 +1,308 @@ -+// SPDX-License-Identifier: GPL-2.0-only -+/* -+ * Copyright (C) 2021 Rafał Miłecki -+ */ -+#include -+#include -+#include -+#include -+#include -+#include -+#include -+#include -+ -+#define BCM63138_MAX_LEDS 32 -+#define BCM63138_MAX_BRIGHTNESS 9 -+ -+#define BCM63138_LED_BITS 4 /* how many bits control a single LED */ -+#define BCM63138_LED_MASK ((1 << BCM63138_LED_BITS) - 1) /* 0xf */ -+#define BCM63138_LEDS_PER_REG (32 / BCM63138_LED_BITS) /* 8 */ -+ -+#define BCM63138_GLB_CTRL 0x00 -+#define BCM63138_GLB_CTRL_SERIAL_LED_DATA_PPOL 0x00000002 -+#define BCM63138_GLB_CTRL_SERIAL_LED_EN_POL 0x00000008 -+#define BCM63138_MASK 0x04 -+#define BCM63138_HW_LED_EN 0x08 -+#define BCM63138_SERIAL_LED_SHIFT_SEL 0x0c -+#define BCM63138_FLASH_RATE_CTRL1 0x10 -+#define BCM63138_FLASH_RATE_CTRL2 0x14 -+#define BCM63138_FLASH_RATE_CTRL3 0x18 -+#define BCM63138_FLASH_RATE_CTRL4 0x1c -+#define BCM63138_BRIGHT_CTRL1 0x20 -+#define BCM63138_BRIGHT_CTRL2 0x24 -+#define BCM63138_BRIGHT_CTRL3 0x28 -+#define BCM63138_BRIGHT_CTRL4 0x2c -+#define BCM63138_POWER_LED_CFG 0x30 -+#define BCM63138_HW_POLARITY 0xb4 -+#define BCM63138_SW_DATA 0xb8 -+#define BCM63138_SW_POLARITY 0xbc -+#define BCM63138_PARALLEL_LED_POLARITY 0xc0 -+#define BCM63138_SERIAL_LED_POLARITY 0xc4 -+#define BCM63138_HW_LED_STATUS 0xc8 -+#define BCM63138_FLASH_CTRL_STATUS 0xcc -+#define BCM63138_FLASH_BRT_CTRL 0xd0 -+#define BCM63138_FLASH_P_LED_OUT_STATUS 0xd4 -+#define BCM63138_FLASH_S_LED_OUT_STATUS 0xd8 -+ -+struct bcm63138_leds { -+ struct device *dev; -+ void __iomem *base; -+ spinlock_t lock; -+}; -+ -+struct bcm63138_led { -+ struct bcm63138_leds *leds; -+ struct led_classdev cdev; -+ u32 pin; -+ bool active_low; -+}; -+ -+/* -+ * I/O access -+ */ -+ -+static void bcm63138_leds_write(struct bcm63138_leds *leds, unsigned int reg, -+ u32 data) -+{ -+ writel(data, leds->base + reg); -+} -+ -+static unsigned long bcm63138_leds_read(struct bcm63138_leds *leds, -+ unsigned int reg) -+{ -+ return readl(leds->base + reg); -+} -+ -+static void bcm63138_leds_update_bits(struct bcm63138_leds *leds, -+ unsigned int reg, u32 mask, u32 val) -+{ -+ WARN_ON(val & ~mask); -+ -+ bcm63138_leds_write(leds, reg, (bcm63138_leds_read(leds, reg) & ~mask) | (val & mask)); -+} -+ -+/* -+ * Helpers -+ */ -+ -+static void bcm63138_leds_set_flash_rate(struct bcm63138_leds *leds, -+ struct bcm63138_led *led, -+ u8 value) -+{ -+ int reg_offset = (led->pin >> fls((BCM63138_LEDS_PER_REG - 1))) * 4; -+ int shift = (led->pin & (BCM63138_LEDS_PER_REG - 1)) * BCM63138_LED_BITS; -+ -+ bcm63138_leds_update_bits(leds, BCM63138_FLASH_RATE_CTRL1 + reg_offset, -+ BCM63138_LED_MASK << shift, value << shift); -+} -+ -+static void bcm63138_leds_set_bright(struct bcm63138_leds *leds, -+ struct bcm63138_led *led, -+ u8 value) -+{ -+ int reg_offset = (led->pin >> fls((BCM63138_LEDS_PER_REG - 1))) * 4; -+ int shift = (led->pin & (BCM63138_LEDS_PER_REG - 1)) * BCM63138_LED_BITS; -+ -+ bcm63138_leds_update_bits(leds, BCM63138_BRIGHT_CTRL1 + reg_offset, -+ BCM63138_LED_MASK << shift, value << shift); -+} -+ -+static void bcm63138_leds_enable_led(struct bcm63138_leds *leds, -+ struct bcm63138_led *led, -+ enum led_brightness value) -+{ -+ u32 bit = BIT(led->pin); -+ -+ bcm63138_leds_update_bits(leds, BCM63138_SW_DATA, bit, -+ value == LED_OFF ? 0 : bit); -+} -+ -+/* -+ * API callbacks -+ */ -+ -+static void bcm63138_leds_brightness_set(struct led_classdev *led_cdev, -+ enum led_brightness value) -+{ -+ struct bcm63138_led *led = container_of(led_cdev, struct bcm63138_led, cdev); -+ struct bcm63138_leds *leds = led->leds; -+ unsigned long flags; -+ -+ spin_lock_irqsave(&leds->lock, flags); -+ -+ bcm63138_leds_enable_led(leds, led, value); -+ if (!value) -+ bcm63138_leds_set_flash_rate(leds, led, 0); -+ else -+ bcm63138_leds_set_bright(leds, led, value); -+ -+ spin_unlock_irqrestore(&leds->lock, flags); -+} -+ -+static int bcm63138_leds_blink_set(struct led_classdev *led_cdev, -+ unsigned long *delay_on, -+ unsigned long *delay_off) -+{ -+ struct bcm63138_led *led = container_of(led_cdev, struct bcm63138_led, cdev); -+ struct bcm63138_leds *leds = led->leds; -+ unsigned long flags; -+ u8 value; -+ -+ if (!*delay_on && !*delay_off) { -+ *delay_on = 640; -+ *delay_off = 640; -+ } -+ -+ if (*delay_on != *delay_off) { -+ dev_dbg(led_cdev->dev, "Blinking at unequal delays is not supported\n"); -+ return -EINVAL; -+ } -+ -+ switch (*delay_on) { -+ case 1152 ... 1408: /* 1280 ms ± 10% */ -+ value = 0x7; -+ break; -+ case 576 ... 704: /* 640 ms ± 10% */ -+ value = 0x6; -+ break; -+ case 288 ... 352: /* 320 ms ± 10% */ -+ value = 0x5; -+ break; -+ case 126 ... 154: /* 140 ms ± 10% */ -+ value = 0x4; -+ break; -+ case 59 ... 72: /* 65 ms ± 10% */ -+ value = 0x3; -+ break; -+ default: -+ dev_dbg(led_cdev->dev, "Blinking delay value %lu is unsupported\n", -+ *delay_on); -+ return -EINVAL; -+ } -+ -+ spin_lock_irqsave(&leds->lock, flags); -+ -+ bcm63138_leds_enable_led(leds, led, BCM63138_MAX_BRIGHTNESS); -+ bcm63138_leds_set_flash_rate(leds, led, value); -+ -+ spin_unlock_irqrestore(&leds->lock, flags); -+ -+ return 0; -+} -+ -+/* -+ * LED driver -+ */ -+ -+static void bcm63138_leds_create_led(struct bcm63138_leds *leds, -+ struct device_node *np) -+{ -+ struct led_init_data init_data = { -+ .fwnode = of_fwnode_handle(np), -+ }; -+ struct device *dev = leds->dev; -+ struct bcm63138_led *led; -+ struct pinctrl *pinctrl; -+ u32 bit; -+ int err; -+ -+ led = devm_kzalloc(dev, sizeof(*led), GFP_KERNEL); -+ if (!led) { -+ dev_err(dev, "Failed to alloc LED\n"); -+ return; -+ } -+ -+ led->leds = leds; -+ -+ if (of_property_read_u32(np, "reg", &led->pin)) { -+ dev_err(dev, "Missing \"reg\" property in %pOF\n", np); -+ goto err_free; -+ } -+ -+ if (led->pin >= BCM63138_MAX_LEDS) { -+ dev_err(dev, "Invalid \"reg\" value %d\n", led->pin); -+ goto err_free; -+ } -+ -+ led->active_low = of_property_read_bool(np, "active-low"); -+ -+ led->cdev.max_brightness = BCM63138_MAX_BRIGHTNESS; -+ led->cdev.brightness_set = bcm63138_leds_brightness_set; -+ led->cdev.blink_set = bcm63138_leds_blink_set; -+ -+ err = devm_led_classdev_register_ext(dev, &led->cdev, &init_data); -+ if (err) { -+ dev_err(dev, "Failed to register LED %pOF: %d\n", np, err); -+ goto err_free; -+ } -+ -+ pinctrl = devm_pinctrl_get_select_default(led->cdev.dev); -+ if (IS_ERR(pinctrl) && PTR_ERR(pinctrl) != -ENODEV) { -+ dev_warn(led->cdev.dev, "Failed to select %pOF pinctrl: %ld\n", -+ np, PTR_ERR(pinctrl)); -+ } -+ -+ bit = BIT(led->pin); -+ bcm63138_leds_update_bits(leds, BCM63138_PARALLEL_LED_POLARITY, bit, -+ led->active_low ? 0 : bit); -+ bcm63138_leds_update_bits(leds, BCM63138_HW_LED_EN, bit, 0); -+ bcm63138_leds_set_flash_rate(leds, led, 0); -+ bcm63138_leds_enable_led(leds, led, led->cdev.brightness); -+ -+ return; -+ -+err_free: -+ devm_kfree(dev, led); -+} -+ -+static int bcm63138_leds_probe(struct platform_device *pdev) -+{ -+ struct device_node *np = dev_of_node(&pdev->dev); -+ struct device *dev = &pdev->dev; -+ struct bcm63138_leds *leds; -+ struct device_node *child; -+ -+ leds = devm_kzalloc(dev, sizeof(*leds), GFP_KERNEL); -+ if (!leds) -+ return -ENOMEM; -+ -+ leds->dev = dev; -+ -+ leds->base = devm_platform_ioremap_resource(pdev, 0); -+ if (IS_ERR(leds->base)) -+ return PTR_ERR(leds->base); -+ -+ spin_lock_init(&leds->lock); -+ -+ bcm63138_leds_write(leds, BCM63138_GLB_CTRL, -+ BCM63138_GLB_CTRL_SERIAL_LED_DATA_PPOL | -+ BCM63138_GLB_CTRL_SERIAL_LED_EN_POL); -+ bcm63138_leds_write(leds, BCM63138_HW_LED_EN, 0); -+ bcm63138_leds_write(leds, BCM63138_SERIAL_LED_POLARITY, 0); -+ bcm63138_leds_write(leds, BCM63138_PARALLEL_LED_POLARITY, 0); -+ -+ for_each_available_child_of_node(np, child) { -+ bcm63138_leds_create_led(leds, child); -+ } -+ -+ return 0; -+} -+ -+static const struct of_device_id bcm63138_leds_of_match_table[] = { -+ { .compatible = "brcm,bcm63138-leds", }, -+ { }, -+}; -+ -+static struct platform_driver bcm63138_leds_driver = { -+ .probe = bcm63138_leds_probe, -+ .driver = { -+ .name = "leds-bcm63xxx", -+ .of_match_table = bcm63138_leds_of_match_table, -+ }, -+}; -+ -+module_platform_driver(bcm63138_leds_driver); -+ -+MODULE_AUTHOR("Rafał Miłecki"); -+MODULE_LICENSE("GPL"); -+MODULE_DEVICE_TABLE(of, bcm63138_leds_of_match_table); ---- a/drivers/leds/Kconfig -+++ b/drivers/leds/Kconfig -@@ -929,6 +929,8 @@ config LEDS_ACER_A500 - This option enables support for the Power Button LED of - Acer Iconia Tab A500. - -+source "drivers/leds/blink/Kconfig" -+ - comment "LED Triggers" - source "drivers/leds/trigger/Kconfig" - ---- a/drivers/leds/Makefile -+++ b/drivers/leds/Makefile -@@ -105,3 +105,6 @@ obj-$(CONFIG_LEDS_USER) += uleds.o - - # LED Triggers - obj-$(CONFIG_LEDS_TRIGGERS) += trigger/ -+ -+# LED Blink -+obj-y += blink/ diff --git a/target/linux/generic/backport-5.10/845-v6.0-0001-dt-bindings-leds-add-Broadcom-s-BCM63138-controller.patch b/target/linux/generic/backport-5.10/845-v6.0-0001-dt-bindings-leds-add-Broadcom-s-BCM63138-controller.patch new file mode 100644 index 0000000000..b1072ce640 --- /dev/null +++ b/target/linux/generic/backport-5.10/845-v6.0-0001-dt-bindings-leds-add-Broadcom-s-BCM63138-controller.patch @@ -0,0 +1,125 @@ +From 13344f8ce8a0d98aa7f5d69ce3b47393c73a343b Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= +Date: Mon, 27 Dec 2021 15:59:04 +0100 +Subject: [PATCH] dt-bindings: leds: add Broadcom's BCM63138 controller +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +Broadcom used 2 LEDs hardware blocks for their BCM63xx SoCs: +1. Older one (BCM6318, BCM6328, BCM6362, BCM63268, BCM6838) +2. Newer one (BCM6848, BCM6858, BCM63138, BCM63148, BCM63381, BCM68360) + +The newer one was also later also used on BCM4908 SoC. + +Old block is already documented in the leds-bcm6328.yaml. This binding +documents the new one which uses different registers & programming. It's +first used in BCM63138 thus the binding name. + +Signed-off-by: Rafał Miłecki +Reviewed-by: Rob Herring +Reviewed-by: Florian Fainelli +Signed-off-by: Pavel Machek +--- + .../bindings/leds/leds-bcm63138.yaml | 95 +++++++++++++++++++ + 1 file changed, 95 insertions(+) + create mode 100644 Documentation/devicetree/bindings/leds/leds-bcm63138.yaml + +--- /dev/null ++++ b/Documentation/devicetree/bindings/leds/leds-bcm63138.yaml +@@ -0,0 +1,95 @@ ++# SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause ++%YAML 1.2 ++--- ++$id: http://devicetree.org/schemas/leds/leds-bcm63138.yaml# ++$schema: http://devicetree.org/meta-schemas/core.yaml# ++ ++title: Broadcom's BCM63138 LEDs controller ++ ++maintainers: ++ - Rafał Miłecki ++ ++description: | ++ This LEDs controller was first used on BCM63138 and later reused on BCM4908, ++ BCM6848, BCM6858, BCM63138, BCM63148, BCM63381 and BCM68360 SoCs. ++ ++ It supports up to 32 LEDs that can be connected parallelly or serially. It ++ also includes limited support for hardware blinking. ++ ++ Binding serially connected LEDs isn't documented yet. ++ ++properties: ++ compatible: ++ oneOf: ++ - items: ++ - enum: ++ - brcm,bcm4908-leds ++ - brcm,bcm6848-leds ++ - brcm,bcm6858-leds ++ - brcm,bcm63148-leds ++ - brcm,bcm63381-leds ++ - brcm,bcm68360-leds ++ - const: brcm,bcm63138-leds ++ - const: brcm,bcm63138-leds ++ ++ reg: ++ maxItems: 1 ++ ++ "#address-cells": ++ const: 1 ++ ++ "#size-cells": ++ const: 0 ++ ++patternProperties: ++ "^led@[a-f0-9]+$": ++ type: object ++ ++ $ref: common.yaml# ++ ++ properties: ++ reg: ++ maxItems: 1 ++ description: LED pin number ++ ++ active-low: ++ type: boolean ++ description: Makes LED active low. ++ ++ required: ++ - reg ++ ++ unevaluatedProperties: false ++ ++required: ++ - reg ++ - "#address-cells" ++ - "#size-cells" ++ ++additionalProperties: false ++ ++examples: ++ - | ++ #include ++ ++ leds@ff800800 { ++ compatible = "brcm,bcm4908-leds", "brcm,bcm63138-leds"; ++ reg = <0xff800800 0xdc>; ++ ++ #address-cells = <1>; ++ #size-cells = <0>; ++ ++ led@0 { ++ reg = <0x0>; ++ function = LED_FUNCTION_POWER; ++ color = ; ++ default-state = "on"; ++ }; ++ ++ led@3 { ++ reg = <0x3>; ++ function = LED_FUNCTION_STATUS; ++ color = ; ++ active-low; ++ }; ++ }; diff --git a/target/linux/generic/backport-5.10/845-v6.0-0002-leds-bcm63138-add-support-for-BCM63138-controller.patch b/target/linux/generic/backport-5.10/845-v6.0-0002-leds-bcm63138-add-support-for-BCM63138-controller.patch new file mode 100644 index 0000000000..8ebe8f180b --- /dev/null +++ b/target/linux/generic/backport-5.10/845-v6.0-0002-leds-bcm63138-add-support-for-BCM63138-controller.patch @@ -0,0 +1,371 @@ +From a0ba692072d89075d0a75c7ad9df31f2c1ee9a1c Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= +Date: Mon, 27 Dec 2021 15:59:05 +0100 +Subject: [PATCH] leds: bcm63138: add support for BCM63138 controller +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +It's a new controller first introduced in BCM63138 SoC. Later it was +also used in BCM4908, some BCM68xx and some BCM63xxx SoCs. + +Signed-off-by: Rafał Miłecki +Reviewed-by: Florian Fainelli +Signed-off-by: Pavel Machek +--- + drivers/leds/blink/Kconfig | 12 ++ + drivers/leds/blink/Makefile | 1 + + drivers/leds/blink/leds-bcm63138.c | 308 +++++++++++++++++++++++++++++ + 3 files changed, 321 insertions(+) + create mode 100644 drivers/leds/blink/leds-bcm63138.c + +--- /dev/null ++++ b/drivers/leds/blink/Kconfig +@@ -0,0 +1,11 @@ ++config LEDS_BCM63138 ++ tristate "LED Support for Broadcom BCM63138 SoC" ++ depends on LEDS_CLASS ++ depends on ARCH_BCM4908 || ARCH_BCM_5301X || BCM63XX || COMPILE_TEST ++ depends on HAS_IOMEM ++ depends on OF ++ default ARCH_BCM4908 ++ help ++ This option enables support for LED controller that is part of ++ BCM63138 SoC. The same hardware block is known to be also used ++ in BCM4908, BCM6848, BCM6858, BCM63148, BCM63381 and BCM68360. +--- /dev/null ++++ b/drivers/leds/blink/Makefile +@@ -0,0 +1,2 @@ ++# SPDX-License-Identifier: GPL-2.0 ++obj-$(CONFIG_LEDS_BCM63138) += leds-bcm63138.o +--- /dev/null ++++ b/drivers/leds/blink/leds-bcm63138.c +@@ -0,0 +1,308 @@ ++// SPDX-License-Identifier: GPL-2.0-only ++/* ++ * Copyright (C) 2021 Rafał Miłecki ++ */ ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++ ++#define BCM63138_MAX_LEDS 32 ++#define BCM63138_MAX_BRIGHTNESS 9 ++ ++#define BCM63138_LED_BITS 4 /* how many bits control a single LED */ ++#define BCM63138_LED_MASK ((1 << BCM63138_LED_BITS) - 1) /* 0xf */ ++#define BCM63138_LEDS_PER_REG (32 / BCM63138_LED_BITS) /* 8 */ ++ ++#define BCM63138_GLB_CTRL 0x00 ++#define BCM63138_GLB_CTRL_SERIAL_LED_DATA_PPOL 0x00000002 ++#define BCM63138_GLB_CTRL_SERIAL_LED_EN_POL 0x00000008 ++#define BCM63138_MASK 0x04 ++#define BCM63138_HW_LED_EN 0x08 ++#define BCM63138_SERIAL_LED_SHIFT_SEL 0x0c ++#define BCM63138_FLASH_RATE_CTRL1 0x10 ++#define BCM63138_FLASH_RATE_CTRL2 0x14 ++#define BCM63138_FLASH_RATE_CTRL3 0x18 ++#define BCM63138_FLASH_RATE_CTRL4 0x1c ++#define BCM63138_BRIGHT_CTRL1 0x20 ++#define BCM63138_BRIGHT_CTRL2 0x24 ++#define BCM63138_BRIGHT_CTRL3 0x28 ++#define BCM63138_BRIGHT_CTRL4 0x2c ++#define BCM63138_POWER_LED_CFG 0x30 ++#define BCM63138_HW_POLARITY 0xb4 ++#define BCM63138_SW_DATA 0xb8 ++#define BCM63138_SW_POLARITY 0xbc ++#define BCM63138_PARALLEL_LED_POLARITY 0xc0 ++#define BCM63138_SERIAL_LED_POLARITY 0xc4 ++#define BCM63138_HW_LED_STATUS 0xc8 ++#define BCM63138_FLASH_CTRL_STATUS 0xcc ++#define BCM63138_FLASH_BRT_CTRL 0xd0 ++#define BCM63138_FLASH_P_LED_OUT_STATUS 0xd4 ++#define BCM63138_FLASH_S_LED_OUT_STATUS 0xd8 ++ ++struct bcm63138_leds { ++ struct device *dev; ++ void __iomem *base; ++ spinlock_t lock; ++}; ++ ++struct bcm63138_led { ++ struct bcm63138_leds *leds; ++ struct led_classdev cdev; ++ u32 pin; ++ bool active_low; ++}; ++ ++/* ++ * I/O access ++ */ ++ ++static void bcm63138_leds_write(struct bcm63138_leds *leds, unsigned int reg, ++ u32 data) ++{ ++ writel(data, leds->base + reg); ++} ++ ++static unsigned long bcm63138_leds_read(struct bcm63138_leds *leds, ++ unsigned int reg) ++{ ++ return readl(leds->base + reg); ++} ++ ++static void bcm63138_leds_update_bits(struct bcm63138_leds *leds, ++ unsigned int reg, u32 mask, u32 val) ++{ ++ WARN_ON(val & ~mask); ++ ++ bcm63138_leds_write(leds, reg, (bcm63138_leds_read(leds, reg) & ~mask) | (val & mask)); ++} ++ ++/* ++ * Helpers ++ */ ++ ++static void bcm63138_leds_set_flash_rate(struct bcm63138_leds *leds, ++ struct bcm63138_led *led, ++ u8 value) ++{ ++ int reg_offset = (led->pin >> fls((BCM63138_LEDS_PER_REG - 1))) * 4; ++ int shift = (led->pin & (BCM63138_LEDS_PER_REG - 1)) * BCM63138_LED_BITS; ++ ++ bcm63138_leds_update_bits(leds, BCM63138_FLASH_RATE_CTRL1 + reg_offset, ++ BCM63138_LED_MASK << shift, value << shift); ++} ++ ++static void bcm63138_leds_set_bright(struct bcm63138_leds *leds, ++ struct bcm63138_led *led, ++ u8 value) ++{ ++ int reg_offset = (led->pin >> fls((BCM63138_LEDS_PER_REG - 1))) * 4; ++ int shift = (led->pin & (BCM63138_LEDS_PER_REG - 1)) * BCM63138_LED_BITS; ++ ++ bcm63138_leds_update_bits(leds, BCM63138_BRIGHT_CTRL1 + reg_offset, ++ BCM63138_LED_MASK << shift, value << shift); ++} ++ ++static void bcm63138_leds_enable_led(struct bcm63138_leds *leds, ++ struct bcm63138_led *led, ++ enum led_brightness value) ++{ ++ u32 bit = BIT(led->pin); ++ ++ bcm63138_leds_update_bits(leds, BCM63138_SW_DATA, bit, ++ value == LED_OFF ? 0 : bit); ++} ++ ++/* ++ * API callbacks ++ */ ++ ++static void bcm63138_leds_brightness_set(struct led_classdev *led_cdev, ++ enum led_brightness value) ++{ ++ struct bcm63138_led *led = container_of(led_cdev, struct bcm63138_led, cdev); ++ struct bcm63138_leds *leds = led->leds; ++ unsigned long flags; ++ ++ spin_lock_irqsave(&leds->lock, flags); ++ ++ bcm63138_leds_enable_led(leds, led, value); ++ if (!value) ++ bcm63138_leds_set_flash_rate(leds, led, 0); ++ else ++ bcm63138_leds_set_bright(leds, led, value); ++ ++ spin_unlock_irqrestore(&leds->lock, flags); ++} ++ ++static int bcm63138_leds_blink_set(struct led_classdev *led_cdev, ++ unsigned long *delay_on, ++ unsigned long *delay_off) ++{ ++ struct bcm63138_led *led = container_of(led_cdev, struct bcm63138_led, cdev); ++ struct bcm63138_leds *leds = led->leds; ++ unsigned long flags; ++ u8 value; ++ ++ if (!*delay_on && !*delay_off) { ++ *delay_on = 640; ++ *delay_off = 640; ++ } ++ ++ if (*delay_on != *delay_off) { ++ dev_dbg(led_cdev->dev, "Blinking at unequal delays is not supported\n"); ++ return -EINVAL; ++ } ++ ++ switch (*delay_on) { ++ case 1152 ... 1408: /* 1280 ms ± 10% */ ++ value = 0x7; ++ break; ++ case 576 ... 704: /* 640 ms ± 10% */ ++ value = 0x6; ++ break; ++ case 288 ... 352: /* 320 ms ± 10% */ ++ value = 0x5; ++ break; ++ case 126 ... 154: /* 140 ms ± 10% */ ++ value = 0x4; ++ break; ++ case 59 ... 72: /* 65 ms ± 10% */ ++ value = 0x3; ++ break; ++ default: ++ dev_dbg(led_cdev->dev, "Blinking delay value %lu is unsupported\n", ++ *delay_on); ++ return -EINVAL; ++ } ++ ++ spin_lock_irqsave(&leds->lock, flags); ++ ++ bcm63138_leds_enable_led(leds, led, BCM63138_MAX_BRIGHTNESS); ++ bcm63138_leds_set_flash_rate(leds, led, value); ++ ++ spin_unlock_irqrestore(&leds->lock, flags); ++ ++ return 0; ++} ++ ++/* ++ * LED driver ++ */ ++ ++static void bcm63138_leds_create_led(struct bcm63138_leds *leds, ++ struct device_node *np) ++{ ++ struct led_init_data init_data = { ++ .fwnode = of_fwnode_handle(np), ++ }; ++ struct device *dev = leds->dev; ++ struct bcm63138_led *led; ++ struct pinctrl *pinctrl; ++ u32 bit; ++ int err; ++ ++ led = devm_kzalloc(dev, sizeof(*led), GFP_KERNEL); ++ if (!led) { ++ dev_err(dev, "Failed to alloc LED\n"); ++ return; ++ } ++ ++ led->leds = leds; ++ ++ if (of_property_read_u32(np, "reg", &led->pin)) { ++ dev_err(dev, "Missing \"reg\" property in %pOF\n", np); ++ goto err_free; ++ } ++ ++ if (led->pin >= BCM63138_MAX_LEDS) { ++ dev_err(dev, "Invalid \"reg\" value %d\n", led->pin); ++ goto err_free; ++ } ++ ++ led->active_low = of_property_read_bool(np, "active-low"); ++ ++ led->cdev.max_brightness = BCM63138_MAX_BRIGHTNESS; ++ led->cdev.brightness_set = bcm63138_leds_brightness_set; ++ led->cdev.blink_set = bcm63138_leds_blink_set; ++ ++ err = devm_led_classdev_register_ext(dev, &led->cdev, &init_data); ++ if (err) { ++ dev_err(dev, "Failed to register LED %pOF: %d\n", np, err); ++ goto err_free; ++ } ++ ++ pinctrl = devm_pinctrl_get_select_default(led->cdev.dev); ++ if (IS_ERR(pinctrl) && PTR_ERR(pinctrl) != -ENODEV) { ++ dev_warn(led->cdev.dev, "Failed to select %pOF pinctrl: %ld\n", ++ np, PTR_ERR(pinctrl)); ++ } ++ ++ bit = BIT(led->pin); ++ bcm63138_leds_update_bits(leds, BCM63138_PARALLEL_LED_POLARITY, bit, ++ led->active_low ? 0 : bit); ++ bcm63138_leds_update_bits(leds, BCM63138_HW_LED_EN, bit, 0); ++ bcm63138_leds_set_flash_rate(leds, led, 0); ++ bcm63138_leds_enable_led(leds, led, led->cdev.brightness); ++ ++ return; ++ ++err_free: ++ devm_kfree(dev, led); ++} ++ ++static int bcm63138_leds_probe(struct platform_device *pdev) ++{ ++ struct device_node *np = dev_of_node(&pdev->dev); ++ struct device *dev = &pdev->dev; ++ struct bcm63138_leds *leds; ++ struct device_node *child; ++ ++ leds = devm_kzalloc(dev, sizeof(*leds), GFP_KERNEL); ++ if (!leds) ++ return -ENOMEM; ++ ++ leds->dev = dev; ++ ++ leds->base = devm_platform_ioremap_resource(pdev, 0); ++ if (IS_ERR(leds->base)) ++ return PTR_ERR(leds->base); ++ ++ spin_lock_init(&leds->lock); ++ ++ bcm63138_leds_write(leds, BCM63138_GLB_CTRL, ++ BCM63138_GLB_CTRL_SERIAL_LED_DATA_PPOL | ++ BCM63138_GLB_CTRL_SERIAL_LED_EN_POL); ++ bcm63138_leds_write(leds, BCM63138_HW_LED_EN, 0); ++ bcm63138_leds_write(leds, BCM63138_SERIAL_LED_POLARITY, 0); ++ bcm63138_leds_write(leds, BCM63138_PARALLEL_LED_POLARITY, 0); ++ ++ for_each_available_child_of_node(np, child) { ++ bcm63138_leds_create_led(leds, child); ++ } ++ ++ return 0; ++} ++ ++static const struct of_device_id bcm63138_leds_of_match_table[] = { ++ { .compatible = "brcm,bcm63138-leds", }, ++ { }, ++}; ++ ++static struct platform_driver bcm63138_leds_driver = { ++ .probe = bcm63138_leds_probe, ++ .driver = { ++ .name = "leds-bcm63xxx", ++ .of_match_table = bcm63138_leds_of_match_table, ++ }, ++}; ++ ++module_platform_driver(bcm63138_leds_driver); ++ ++MODULE_AUTHOR("Rafał Miłecki"); ++MODULE_LICENSE("GPL"); ++MODULE_DEVICE_TABLE(of, bcm63138_leds_of_match_table); +--- a/drivers/leds/Kconfig ++++ b/drivers/leds/Kconfig +@@ -929,6 +929,8 @@ config LEDS_ACER_A500 + This option enables support for the Power Button LED of + Acer Iconia Tab A500. + ++source "drivers/leds/blink/Kconfig" ++ + comment "LED Triggers" + source "drivers/leds/trigger/Kconfig" + +--- a/drivers/leds/Makefile ++++ b/drivers/leds/Makefile +@@ -105,3 +105,6 @@ obj-$(CONFIG_LEDS_USER) += uleds.o + + # LED Triggers + obj-$(CONFIG_LEDS_TRIGGERS) += trigger/ ++ ++# LED Blink ++obj-y += blink/ diff --git a/target/linux/generic/backport-5.10/846-v5.20-0001-dt-bindings-leds-leds-bcm63138-unify-full-stops-in-d.patch b/target/linux/generic/backport-5.10/846-v5.20-0001-dt-bindings-leds-leds-bcm63138-unify-full-stops-in-d.patch deleted file mode 100644 index 483826abed..0000000000 --- a/target/linux/generic/backport-5.10/846-v5.20-0001-dt-bindings-leds-leds-bcm63138-unify-full-stops-in-d.patch +++ /dev/null @@ -1,30 +0,0 @@ -From 13b64a0c19059b38150c79d65d350ae44034c5df Mon Sep 17 00:00:00 2001 -From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= -Date: Sun, 17 Jul 2022 14:42:46 +0200 -Subject: [PATCH] dt-bindings: leds: leds-bcm63138: unify full stops in - descriptions -MIME-Version: 1.0 -Content-Type: text/plain; charset=UTF-8 -Content-Transfer-Encoding: 8bit - -Description of "reg" doesn't have full stop at the end. It makes sense -as it's a one-sentence only. Use the same style for "active-low". - -Reported-by: Pavel Machek -Signed-off-by: Rafał Miłecki -Signed-off-by: Pavel Machek ---- - Documentation/devicetree/bindings/leds/leds-bcm63138.yaml | 2 +- - 1 file changed, 1 insertion(+), 1 deletion(-) - ---- a/Documentation/devicetree/bindings/leds/leds-bcm63138.yaml -+++ b/Documentation/devicetree/bindings/leds/leds-bcm63138.yaml -@@ -54,7 +54,7 @@ patternProperties: - - active-low: - type: boolean -- description: Makes LED active low. -+ description: Makes LED active low - - required: - - reg diff --git a/target/linux/generic/backport-5.10/846-v5.20-0002-leds-add-help-info-about-BCM63138-module-name.patch b/target/linux/generic/backport-5.10/846-v5.20-0002-leds-add-help-info-about-BCM63138-module-name.patch deleted file mode 100644 index 44e8be86fd..0000000000 --- a/target/linux/generic/backport-5.10/846-v5.20-0002-leds-add-help-info-about-BCM63138-module-name.patch +++ /dev/null @@ -1,25 +0,0 @@ -From bcc607cdbb1f931111196699426f0cb83bfb296a Mon Sep 17 00:00:00 2001 -From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= -Date: Sun, 17 Jul 2022 14:42:47 +0200 -Subject: [PATCH] leds: add help info about BCM63138 module name -MIME-Version: 1.0 -Content-Type: text/plain; charset=UTF-8 -Content-Transfer-Encoding: 8bit - -It's what we do for all other LEDs drivers. - -Reported-by: Pavel Machek -Signed-off-by: Rafał Miłecki -Signed-off-by: Pavel Machek ---- - drivers/leds/blink/Kconfig | 2 ++ - 1 file changed, 2 insertions(+) - ---- a/drivers/leds/blink/Kconfig -+++ b/drivers/leds/blink/Kconfig -@@ -9,3 +9,5 @@ config LEDS_BCM63138 - This option enables support for LED controller that is part of - BCM63138 SoC. The same hardware block is known to be also used - in BCM4908, BCM6848, BCM6858, BCM63148, BCM63381 and BCM68360. -+ -+ If compiled as module it will be called leds-bcm63138. diff --git a/target/linux/generic/backport-5.10/846-v5.20-0003-leds-leds-bcm63138-get-rid-of-LED_OFF.patch b/target/linux/generic/backport-5.10/846-v5.20-0003-leds-leds-bcm63138-get-rid-of-LED_OFF.patch deleted file mode 100644 index e125a54613..0000000000 --- a/target/linux/generic/backport-5.10/846-v5.20-0003-leds-leds-bcm63138-get-rid-of-LED_OFF.patch +++ /dev/null @@ -1,30 +0,0 @@ -From 92cfc71ee2ddfb499ed53e21b28bdf8739bc70bc Mon Sep 17 00:00:00 2001 -From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= -Date: Sun, 17 Jul 2022 14:42:48 +0200 -Subject: [PATCH] leds: leds-bcm63138: get rid of LED_OFF -MIME-Version: 1.0 -Content-Type: text/plain; charset=UTF-8 -Content-Transfer-Encoding: 8bit - -The whole "enum led_brightness" is marked as obsolete. Replace it with a -(non-)zero check. - -Reported-by: Pavel Machek -Signed-off-by: Rafał Miłecki -Signed-off-by: Pavel Machek ---- - drivers/leds/blink/leds-bcm63138.c | 3 +-- - 1 file changed, 1 insertion(+), 2 deletions(-) - ---- a/drivers/leds/blink/leds-bcm63138.c -+++ b/drivers/leds/blink/leds-bcm63138.c -@@ -113,8 +113,7 @@ static void bcm63138_leds_enable_led(str - { - u32 bit = BIT(led->pin); - -- bcm63138_leds_update_bits(leds, BCM63138_SW_DATA, bit, -- value == LED_OFF ? 0 : bit); -+ bcm63138_leds_update_bits(leds, BCM63138_SW_DATA, bit, value ? bit : 0); - } - - /* diff --git a/target/linux/generic/backport-5.10/846-v6.0-0001-dt-bindings-leds-leds-bcm63138-unify-full-stops-in-d.patch b/target/linux/generic/backport-5.10/846-v6.0-0001-dt-bindings-leds-leds-bcm63138-unify-full-stops-in-d.patch new file mode 100644 index 0000000000..483826abed --- /dev/null +++ b/target/linux/generic/backport-5.10/846-v6.0-0001-dt-bindings-leds-leds-bcm63138-unify-full-stops-in-d.patch @@ -0,0 +1,30 @@ +From 13b64a0c19059b38150c79d65d350ae44034c5df Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= +Date: Sun, 17 Jul 2022 14:42:46 +0200 +Subject: [PATCH] dt-bindings: leds: leds-bcm63138: unify full stops in + descriptions +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +Description of "reg" doesn't have full stop at the end. It makes sense +as it's a one-sentence only. Use the same style for "active-low". + +Reported-by: Pavel Machek +Signed-off-by: Rafał Miłecki +Signed-off-by: Pavel Machek +--- + Documentation/devicetree/bindings/leds/leds-bcm63138.yaml | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +--- a/Documentation/devicetree/bindings/leds/leds-bcm63138.yaml ++++ b/Documentation/devicetree/bindings/leds/leds-bcm63138.yaml +@@ -54,7 +54,7 @@ patternProperties: + + active-low: + type: boolean +- description: Makes LED active low. ++ description: Makes LED active low + + required: + - reg diff --git a/target/linux/generic/backport-5.10/846-v6.0-0002-leds-add-help-info-about-BCM63138-module-name.patch b/target/linux/generic/backport-5.10/846-v6.0-0002-leds-add-help-info-about-BCM63138-module-name.patch new file mode 100644 index 0000000000..44e8be86fd --- /dev/null +++ b/target/linux/generic/backport-5.10/846-v6.0-0002-leds-add-help-info-about-BCM63138-module-name.patch @@ -0,0 +1,25 @@ +From bcc607cdbb1f931111196699426f0cb83bfb296a Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= +Date: Sun, 17 Jul 2022 14:42:47 +0200 +Subject: [PATCH] leds: add help info about BCM63138 module name +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +It's what we do for all other LEDs drivers. + +Reported-by: Pavel Machek +Signed-off-by: Rafał Miłecki +Signed-off-by: Pavel Machek +--- + drivers/leds/blink/Kconfig | 2 ++ + 1 file changed, 2 insertions(+) + +--- a/drivers/leds/blink/Kconfig ++++ b/drivers/leds/blink/Kconfig +@@ -9,3 +9,5 @@ config LEDS_BCM63138 + This option enables support for LED controller that is part of + BCM63138 SoC. The same hardware block is known to be also used + in BCM4908, BCM6848, BCM6858, BCM63148, BCM63381 and BCM68360. ++ ++ If compiled as module it will be called leds-bcm63138. diff --git a/target/linux/generic/backport-5.10/846-v6.0-0003-leds-leds-bcm63138-get-rid-of-LED_OFF.patch b/target/linux/generic/backport-5.10/846-v6.0-0003-leds-leds-bcm63138-get-rid-of-LED_OFF.patch new file mode 100644 index 0000000000..e125a54613 --- /dev/null +++ b/target/linux/generic/backport-5.10/846-v6.0-0003-leds-leds-bcm63138-get-rid-of-LED_OFF.patch @@ -0,0 +1,30 @@ +From 92cfc71ee2ddfb499ed53e21b28bdf8739bc70bc Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= +Date: Sun, 17 Jul 2022 14:42:48 +0200 +Subject: [PATCH] leds: leds-bcm63138: get rid of LED_OFF +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +The whole "enum led_brightness" is marked as obsolete. Replace it with a +(non-)zero check. + +Reported-by: Pavel Machek +Signed-off-by: Rafał Miłecki +Signed-off-by: Pavel Machek +--- + drivers/leds/blink/leds-bcm63138.c | 3 +-- + 1 file changed, 1 insertion(+), 2 deletions(-) + +--- a/drivers/leds/blink/leds-bcm63138.c ++++ b/drivers/leds/blink/leds-bcm63138.c +@@ -113,8 +113,7 @@ static void bcm63138_leds_enable_led(str + { + u32 bit = BIT(led->pin); + +- bcm63138_leds_update_bits(leds, BCM63138_SW_DATA, bit, +- value == LED_OFF ? 0 : bit); ++ bcm63138_leds_update_bits(leds, BCM63138_SW_DATA, bit, value ? bit : 0); + } + + /* diff --git a/target/linux/generic/backport-5.15/401-v5.20-mtd-parsers-add-support-for-Sercomm-partitions.patch b/target/linux/generic/backport-5.15/401-v5.20-mtd-parsers-add-support-for-Sercomm-partitions.patch deleted file mode 100644 index 113a96ad42..0000000000 --- a/target/linux/generic/backport-5.15/401-v5.20-mtd-parsers-add-support-for-Sercomm-partitions.patch +++ /dev/null @@ -1,302 +0,0 @@ -From 9b78ef0c7997052e9eaa0f7a4513d546fa17358c Mon Sep 17 00:00:00 2001 -From: Mikhail Zhilkin -Date: Sun, 29 May 2022 11:07:14 +0000 -Subject: [PATCH] mtd: parsers: add support for Sercomm partitions - -This adds an MTD partition parser for the Sercomm partition table that -is used in some Beeline, Netgear and Sercomm routers. - -The Sercomm partition map table contains real partition offsets, which -may differ from device to device depending on the number and location of -bad blocks on NAND. - -Original patch (proposed by NOGUCHI Hiroshi): -Link: https://github.com/openwrt/openwrt/pull/1318#issuecomment-420607394 - -Signed-off-by: NOGUCHI Hiroshi -Signed-off-by: Mikhail Zhilkin -Signed-off-by: Miquel Raynal -Link: https://lore.kernel.org/linux-mtd/20220529110714.189732-1-csharper2005@gmail.com ---- - drivers/mtd/parsers/Kconfig | 9 ++ - drivers/mtd/parsers/Makefile | 1 + - drivers/mtd/parsers/scpart.c | 248 +++++++++++++++++++++++++++++++++++ - 3 files changed, 258 insertions(+) - create mode 100644 drivers/mtd/parsers/scpart.c - ---- a/drivers/mtd/parsers/Kconfig -+++ b/drivers/mtd/parsers/Kconfig -@@ -186,3 +186,12 @@ config MTD_QCOMSMEM_PARTS - help - This provides support for parsing partitions from Shared Memory (SMEM) - for NAND and SPI flash on Qualcomm platforms. -+ -+config MTD_SERCOMM_PARTS -+ tristate "Sercomm partition table parser" -+ depends on MTD && RALINK -+ help -+ This provides partitions table parser for devices with Sercomm -+ partition map. This partition table contains real partition -+ offsets, which may differ from device to device depending on the -+ number and location of bad blocks on NAND. ---- a/drivers/mtd/parsers/Makefile -+++ b/drivers/mtd/parsers/Makefile -@@ -10,6 +10,7 @@ ofpart-$(CONFIG_MTD_OF_PARTS_LINKSYS_NS) - obj-$(CONFIG_MTD_PARSER_IMAGETAG) += parser_imagetag.o - obj-$(CONFIG_MTD_AFS_PARTS) += afs.o - obj-$(CONFIG_MTD_PARSER_TRX) += parser_trx.o -+obj-$(CONFIG_MTD_SERCOMM_PARTS) += scpart.o - obj-$(CONFIG_MTD_SHARPSL_PARTS) += sharpslpart.o - obj-$(CONFIG_MTD_REDBOOT_PARTS) += redboot.o - obj-$(CONFIG_MTD_QCOMSMEM_PARTS) += qcomsmempart.o ---- /dev/null -+++ b/drivers/mtd/parsers/scpart.c -@@ -0,0 +1,248 @@ -+// SPDX-License-Identifier: GPL-2.0-or-later -+/* -+ * drivers/mtd/scpart.c: Sercomm Partition Parser -+ * -+ * Copyright (C) 2018 NOGUCHI Hiroshi -+ * Copyright (C) 2022 Mikhail Zhilkin -+ */ -+ -+#include -+#include -+#include -+#include -+#include -+ -+#define MOD_NAME "scpart" -+ -+#ifdef pr_fmt -+#undef pr_fmt -+#endif -+ -+#define pr_fmt(fmt) MOD_NAME ": " fmt -+ -+#define ID_ALREADY_FOUND 0xffffffffUL -+ -+#define MAP_OFFS_IN_BLK 0x800 -+#define MAP_MIRROR_NUM 2 -+ -+static const char sc_part_magic[] = { -+ 'S', 'C', 'F', 'L', 'M', 'A', 'P', 'O', 'K', '\0', -+}; -+#define PART_MAGIC_LEN sizeof(sc_part_magic) -+ -+/* assumes that all fields are set by CPU native endian */ -+struct sc_part_desc { -+ uint32_t part_id; -+ uint32_t part_offs; -+ uint32_t part_bytes; -+}; -+ -+static uint32_t scpart_desc_is_valid(struct sc_part_desc *pdesc) -+{ -+ return ((pdesc->part_id != 0xffffffffUL) && -+ (pdesc->part_offs != 0xffffffffUL) && -+ (pdesc->part_bytes != 0xffffffffUL)); -+} -+ -+static int scpart_scan_partmap(struct mtd_info *master, loff_t partmap_offs, -+ struct sc_part_desc **ppdesc) -+{ -+ int cnt = 0; -+ int res = 0; -+ int res2; -+ loff_t offs; -+ size_t retlen; -+ struct sc_part_desc *pdesc = NULL; -+ struct sc_part_desc *tmpdesc; -+ uint8_t *buf; -+ -+ buf = kzalloc(master->erasesize, GFP_KERNEL); -+ if (!buf) { -+ res = -ENOMEM; -+ goto out; -+ } -+ -+ res2 = mtd_read(master, partmap_offs, master->erasesize, &retlen, buf); -+ if (res2 || retlen != master->erasesize) { -+ res = -EIO; -+ goto free; -+ } -+ -+ for (offs = MAP_OFFS_IN_BLK; -+ offs < master->erasesize - sizeof(*tmpdesc); -+ offs += sizeof(*tmpdesc)) { -+ tmpdesc = (struct sc_part_desc *)&buf[offs]; -+ if (!scpart_desc_is_valid(tmpdesc)) -+ break; -+ cnt++; -+ } -+ -+ if (cnt > 0) { -+ int bytes = cnt * sizeof(*pdesc); -+ -+ pdesc = kcalloc(cnt, sizeof(*pdesc), GFP_KERNEL); -+ if (!pdesc) { -+ res = -ENOMEM; -+ goto free; -+ } -+ memcpy(pdesc, &(buf[MAP_OFFS_IN_BLK]), bytes); -+ -+ *ppdesc = pdesc; -+ res = cnt; -+ } -+ -+free: -+ kfree(buf); -+ -+out: -+ return res; -+} -+ -+static int scpart_find_partmap(struct mtd_info *master, -+ struct sc_part_desc **ppdesc) -+{ -+ int magic_found = 0; -+ int res = 0; -+ int res2; -+ loff_t offs = 0; -+ size_t retlen; -+ uint8_t rdbuf[PART_MAGIC_LEN]; -+ -+ while ((magic_found < MAP_MIRROR_NUM) && -+ (offs < master->size) && -+ !mtd_block_isbad(master, offs)) { -+ res2 = mtd_read(master, offs, PART_MAGIC_LEN, &retlen, rdbuf); -+ if (res2 || retlen != PART_MAGIC_LEN) { -+ res = -EIO; -+ goto out; -+ } -+ if (!memcmp(rdbuf, sc_part_magic, PART_MAGIC_LEN)) { -+ pr_debug("Signature found at 0x%llx\n", offs); -+ magic_found++; -+ res = scpart_scan_partmap(master, offs, ppdesc); -+ if (res > 0) -+ goto out; -+ } -+ offs += master->erasesize; -+ } -+ -+out: -+ if (res > 0) -+ pr_info("Valid 'SC PART MAP' (%d partitions) found at 0x%llx\n", res, offs); -+ else -+ pr_info("No valid 'SC PART MAP' was found\n"); -+ -+ return res; -+} -+ -+static int scpart_parse(struct mtd_info *master, -+ const struct mtd_partition **pparts, -+ struct mtd_part_parser_data *data) -+{ -+ const char *partname; -+ int n; -+ int nr_scparts; -+ int nr_parts = 0; -+ int res = 0; -+ struct sc_part_desc *scpart_map = NULL; -+ struct mtd_partition *parts = NULL; -+ struct device_node *mtd_node; -+ struct device_node *ofpart_node; -+ struct device_node *pp; -+ -+ mtd_node = mtd_get_of_node(master); -+ if (!mtd_node) { -+ res = -ENOENT; -+ goto out; -+ } -+ -+ ofpart_node = of_get_child_by_name(mtd_node, "partitions"); -+ if (!ofpart_node) { -+ pr_info("%s: 'partitions' subnode not found on %pOF.\n", -+ master->name, mtd_node); -+ res = -ENOENT; -+ goto out; -+ } -+ -+ nr_scparts = scpart_find_partmap(master, &scpart_map); -+ if (nr_scparts <= 0) { -+ pr_info("No any partitions was found in 'SC PART MAP'.\n"); -+ res = -ENOENT; -+ goto free; -+ } -+ -+ parts = kcalloc(of_get_child_count(ofpart_node), sizeof(*parts), -+ GFP_KERNEL); -+ if (!parts) { -+ res = -ENOMEM; -+ goto free; -+ } -+ -+ for_each_child_of_node(ofpart_node, pp) { -+ u32 scpart_id; -+ -+ if (of_property_read_u32(pp, "sercomm,scpart-id", &scpart_id)) -+ continue; -+ -+ for (n = 0 ; n < nr_scparts ; n++) -+ if ((scpart_map[n].part_id != ID_ALREADY_FOUND) && -+ (scpart_id == scpart_map[n].part_id)) -+ break; -+ if (n >= nr_scparts) -+ /* not match */ -+ continue; -+ -+ /* add the partition found in OF into MTD partition array */ -+ parts[nr_parts].offset = scpart_map[n].part_offs; -+ parts[nr_parts].size = scpart_map[n].part_bytes; -+ parts[nr_parts].of_node = pp; -+ -+ if (!of_property_read_string(pp, "label", &partname)) -+ parts[nr_parts].name = partname; -+ if (of_property_read_bool(pp, "read-only")) -+ parts[nr_parts].mask_flags |= MTD_WRITEABLE; -+ if (of_property_read_bool(pp, "lock")) -+ parts[nr_parts].mask_flags |= MTD_POWERUP_LOCK; -+ -+ /* mark as 'done' */ -+ scpart_map[n].part_id = ID_ALREADY_FOUND; -+ -+ nr_parts++; -+ } -+ -+ if (nr_parts > 0) { -+ *pparts = parts; -+ res = nr_parts; -+ } else -+ pr_info("No partition in OF matches partition ID with 'SC PART MAP'.\n"); -+ -+ of_node_put(pp); -+ -+free: -+ kfree(scpart_map); -+ if (res <= 0) -+ kfree(parts); -+ -+out: -+ return res; -+} -+ -+static const struct of_device_id scpart_parser_of_match_table[] = { -+ { .compatible = "sercomm,sc-partitions" }, -+ {}, -+}; -+MODULE_DEVICE_TABLE(of, scpart_parser_of_match_table); -+ -+static struct mtd_part_parser scpart_parser = { -+ .parse_fn = scpart_parse, -+ .name = "scpart", -+ .of_match_table = scpart_parser_of_match_table, -+}; -+module_mtd_part_parser(scpart_parser); -+ -+/* mtd parsers will request the module by parser name */ -+MODULE_ALIAS("scpart"); -+MODULE_LICENSE("GPL"); -+MODULE_AUTHOR("NOGUCHI Hiroshi "); -+MODULE_AUTHOR("Mikhail Zhilkin "); -+MODULE_DESCRIPTION("Sercomm partition parser"); diff --git a/target/linux/generic/backport-5.15/401-v6.0-mtd-parsers-add-support-for-Sercomm-partitions.patch b/target/linux/generic/backport-5.15/401-v6.0-mtd-parsers-add-support-for-Sercomm-partitions.patch new file mode 100644 index 0000000000..113a96ad42 --- /dev/null +++ b/target/linux/generic/backport-5.15/401-v6.0-mtd-parsers-add-support-for-Sercomm-partitions.patch @@ -0,0 +1,302 @@ +From 9b78ef0c7997052e9eaa0f7a4513d546fa17358c Mon Sep 17 00:00:00 2001 +From: Mikhail Zhilkin +Date: Sun, 29 May 2022 11:07:14 +0000 +Subject: [PATCH] mtd: parsers: add support for Sercomm partitions + +This adds an MTD partition parser for the Sercomm partition table that +is used in some Beeline, Netgear and Sercomm routers. + +The Sercomm partition map table contains real partition offsets, which +may differ from device to device depending on the number and location of +bad blocks on NAND. + +Original patch (proposed by NOGUCHI Hiroshi): +Link: https://github.com/openwrt/openwrt/pull/1318#issuecomment-420607394 + +Signed-off-by: NOGUCHI Hiroshi +Signed-off-by: Mikhail Zhilkin +Signed-off-by: Miquel Raynal +Link: https://lore.kernel.org/linux-mtd/20220529110714.189732-1-csharper2005@gmail.com +--- + drivers/mtd/parsers/Kconfig | 9 ++ + drivers/mtd/parsers/Makefile | 1 + + drivers/mtd/parsers/scpart.c | 248 +++++++++++++++++++++++++++++++++++ + 3 files changed, 258 insertions(+) + create mode 100644 drivers/mtd/parsers/scpart.c + +--- a/drivers/mtd/parsers/Kconfig ++++ b/drivers/mtd/parsers/Kconfig +@@ -186,3 +186,12 @@ config MTD_QCOMSMEM_PARTS + help + This provides support for parsing partitions from Shared Memory (SMEM) + for NAND and SPI flash on Qualcomm platforms. ++ ++config MTD_SERCOMM_PARTS ++ tristate "Sercomm partition table parser" ++ depends on MTD && RALINK ++ help ++ This provides partitions table parser for devices with Sercomm ++ partition map. This partition table contains real partition ++ offsets, which may differ from device to device depending on the ++ number and location of bad blocks on NAND. +--- a/drivers/mtd/parsers/Makefile ++++ b/drivers/mtd/parsers/Makefile +@@ -10,6 +10,7 @@ ofpart-$(CONFIG_MTD_OF_PARTS_LINKSYS_NS) + obj-$(CONFIG_MTD_PARSER_IMAGETAG) += parser_imagetag.o + obj-$(CONFIG_MTD_AFS_PARTS) += afs.o + obj-$(CONFIG_MTD_PARSER_TRX) += parser_trx.o ++obj-$(CONFIG_MTD_SERCOMM_PARTS) += scpart.o + obj-$(CONFIG_MTD_SHARPSL_PARTS) += sharpslpart.o + obj-$(CONFIG_MTD_REDBOOT_PARTS) += redboot.o + obj-$(CONFIG_MTD_QCOMSMEM_PARTS) += qcomsmempart.o +--- /dev/null ++++ b/drivers/mtd/parsers/scpart.c +@@ -0,0 +1,248 @@ ++// SPDX-License-Identifier: GPL-2.0-or-later ++/* ++ * drivers/mtd/scpart.c: Sercomm Partition Parser ++ * ++ * Copyright (C) 2018 NOGUCHI Hiroshi ++ * Copyright (C) 2022 Mikhail Zhilkin ++ */ ++ ++#include ++#include ++#include ++#include ++#include ++ ++#define MOD_NAME "scpart" ++ ++#ifdef pr_fmt ++#undef pr_fmt ++#endif ++ ++#define pr_fmt(fmt) MOD_NAME ": " fmt ++ ++#define ID_ALREADY_FOUND 0xffffffffUL ++ ++#define MAP_OFFS_IN_BLK 0x800 ++#define MAP_MIRROR_NUM 2 ++ ++static const char sc_part_magic[] = { ++ 'S', 'C', 'F', 'L', 'M', 'A', 'P', 'O', 'K', '\0', ++}; ++#define PART_MAGIC_LEN sizeof(sc_part_magic) ++ ++/* assumes that all fields are set by CPU native endian */ ++struct sc_part_desc { ++ uint32_t part_id; ++ uint32_t part_offs; ++ uint32_t part_bytes; ++}; ++ ++static uint32_t scpart_desc_is_valid(struct sc_part_desc *pdesc) ++{ ++ return ((pdesc->part_id != 0xffffffffUL) && ++ (pdesc->part_offs != 0xffffffffUL) && ++ (pdesc->part_bytes != 0xffffffffUL)); ++} ++ ++static int scpart_scan_partmap(struct mtd_info *master, loff_t partmap_offs, ++ struct sc_part_desc **ppdesc) ++{ ++ int cnt = 0; ++ int res = 0; ++ int res2; ++ loff_t offs; ++ size_t retlen; ++ struct sc_part_desc *pdesc = NULL; ++ struct sc_part_desc *tmpdesc; ++ uint8_t *buf; ++ ++ buf = kzalloc(master->erasesize, GFP_KERNEL); ++ if (!buf) { ++ res = -ENOMEM; ++ goto out; ++ } ++ ++ res2 = mtd_read(master, partmap_offs, master->erasesize, &retlen, buf); ++ if (res2 || retlen != master->erasesize) { ++ res = -EIO; ++ goto free; ++ } ++ ++ for (offs = MAP_OFFS_IN_BLK; ++ offs < master->erasesize - sizeof(*tmpdesc); ++ offs += sizeof(*tmpdesc)) { ++ tmpdesc = (struct sc_part_desc *)&buf[offs]; ++ if (!scpart_desc_is_valid(tmpdesc)) ++ break; ++ cnt++; ++ } ++ ++ if (cnt > 0) { ++ int bytes = cnt * sizeof(*pdesc); ++ ++ pdesc = kcalloc(cnt, sizeof(*pdesc), GFP_KERNEL); ++ if (!pdesc) { ++ res = -ENOMEM; ++ goto free; ++ } ++ memcpy(pdesc, &(buf[MAP_OFFS_IN_BLK]), bytes); ++ ++ *ppdesc = pdesc; ++ res = cnt; ++ } ++ ++free: ++ kfree(buf); ++ ++out: ++ return res; ++} ++ ++static int scpart_find_partmap(struct mtd_info *master, ++ struct sc_part_desc **ppdesc) ++{ ++ int magic_found = 0; ++ int res = 0; ++ int res2; ++ loff_t offs = 0; ++ size_t retlen; ++ uint8_t rdbuf[PART_MAGIC_LEN]; ++ ++ while ((magic_found < MAP_MIRROR_NUM) && ++ (offs < master->size) && ++ !mtd_block_isbad(master, offs)) { ++ res2 = mtd_read(master, offs, PART_MAGIC_LEN, &retlen, rdbuf); ++ if (res2 || retlen != PART_MAGIC_LEN) { ++ res = -EIO; ++ goto out; ++ } ++ if (!memcmp(rdbuf, sc_part_magic, PART_MAGIC_LEN)) { ++ pr_debug("Signature found at 0x%llx\n", offs); ++ magic_found++; ++ res = scpart_scan_partmap(master, offs, ppdesc); ++ if (res > 0) ++ goto out; ++ } ++ offs += master->erasesize; ++ } ++ ++out: ++ if (res > 0) ++ pr_info("Valid 'SC PART MAP' (%d partitions) found at 0x%llx\n", res, offs); ++ else ++ pr_info("No valid 'SC PART MAP' was found\n"); ++ ++ return res; ++} ++ ++static int scpart_parse(struct mtd_info *master, ++ const struct mtd_partition **pparts, ++ struct mtd_part_parser_data *data) ++{ ++ const char *partname; ++ int n; ++ int nr_scparts; ++ int nr_parts = 0; ++ int res = 0; ++ struct sc_part_desc *scpart_map = NULL; ++ struct mtd_partition *parts = NULL; ++ struct device_node *mtd_node; ++ struct device_node *ofpart_node; ++ struct device_node *pp; ++ ++ mtd_node = mtd_get_of_node(master); ++ if (!mtd_node) { ++ res = -ENOENT; ++ goto out; ++ } ++ ++ ofpart_node = of_get_child_by_name(mtd_node, "partitions"); ++ if (!ofpart_node) { ++ pr_info("%s: 'partitions' subnode not found on %pOF.\n", ++ master->name, mtd_node); ++ res = -ENOENT; ++ goto out; ++ } ++ ++ nr_scparts = scpart_find_partmap(master, &scpart_map); ++ if (nr_scparts <= 0) { ++ pr_info("No any partitions was found in 'SC PART MAP'.\n"); ++ res = -ENOENT; ++ goto free; ++ } ++ ++ parts = kcalloc(of_get_child_count(ofpart_node), sizeof(*parts), ++ GFP_KERNEL); ++ if (!parts) { ++ res = -ENOMEM; ++ goto free; ++ } ++ ++ for_each_child_of_node(ofpart_node, pp) { ++ u32 scpart_id; ++ ++ if (of_property_read_u32(pp, "sercomm,scpart-id", &scpart_id)) ++ continue; ++ ++ for (n = 0 ; n < nr_scparts ; n++) ++ if ((scpart_map[n].part_id != ID_ALREADY_FOUND) && ++ (scpart_id == scpart_map[n].part_id)) ++ break; ++ if (n >= nr_scparts) ++ /* not match */ ++ continue; ++ ++ /* add the partition found in OF into MTD partition array */ ++ parts[nr_parts].offset = scpart_map[n].part_offs; ++ parts[nr_parts].size = scpart_map[n].part_bytes; ++ parts[nr_parts].of_node = pp; ++ ++ if (!of_property_read_string(pp, "label", &partname)) ++ parts[nr_parts].name = partname; ++ if (of_property_read_bool(pp, "read-only")) ++ parts[nr_parts].mask_flags |= MTD_WRITEABLE; ++ if (of_property_read_bool(pp, "lock")) ++ parts[nr_parts].mask_flags |= MTD_POWERUP_LOCK; ++ ++ /* mark as 'done' */ ++ scpart_map[n].part_id = ID_ALREADY_FOUND; ++ ++ nr_parts++; ++ } ++ ++ if (nr_parts > 0) { ++ *pparts = parts; ++ res = nr_parts; ++ } else ++ pr_info("No partition in OF matches partition ID with 'SC PART MAP'.\n"); ++ ++ of_node_put(pp); ++ ++free: ++ kfree(scpart_map); ++ if (res <= 0) ++ kfree(parts); ++ ++out: ++ return res; ++} ++ ++static const struct of_device_id scpart_parser_of_match_table[] = { ++ { .compatible = "sercomm,sc-partitions" }, ++ {}, ++}; ++MODULE_DEVICE_TABLE(of, scpart_parser_of_match_table); ++ ++static struct mtd_part_parser scpart_parser = { ++ .parse_fn = scpart_parse, ++ .name = "scpart", ++ .of_match_table = scpart_parser_of_match_table, ++}; ++module_mtd_part_parser(scpart_parser); ++ ++/* mtd parsers will request the module by parser name */ ++MODULE_ALIAS("scpart"); ++MODULE_LICENSE("GPL"); ++MODULE_AUTHOR("NOGUCHI Hiroshi "); ++MODULE_AUTHOR("Mikhail Zhilkin "); ++MODULE_DESCRIPTION("Sercomm partition parser"); diff --git a/target/linux/generic/backport-5.15/402-v5.20-mtd-next-mtd-core-introduce-of-support-for-dynamic-partitions.patch b/target/linux/generic/backport-5.15/402-v5.20-mtd-next-mtd-core-introduce-of-support-for-dynamic-partitions.patch deleted file mode 100644 index 8b8e478b00..0000000000 --- a/target/linux/generic/backport-5.15/402-v5.20-mtd-next-mtd-core-introduce-of-support-for-dynamic-partitions.patch +++ /dev/null @@ -1,106 +0,0 @@ -From ad9b10d1eaada169bd764abcab58f08538877e26 Mon Sep 17 00:00:00 2001 -From: Christian Marangi -Date: Wed, 22 Jun 2022 03:06:28 +0200 -Subject: mtd: core: introduce of support for dynamic partitions - -We have many parser that register mtd partitions at runtime. One example -is the cmdlinepart or the smem-part parser where the compatible is defined -in the dts and the partitions gets detected and registered by the -parser. This is problematic for the NVMEM subsystem that requires an OF -node to detect NVMEM cells. - -To fix this problem, introduce an additional logic that will try to -assign an OF node to the MTD if declared. - -On MTD addition, it will be checked if the MTD has an OF node and if -not declared will check if a partition with the same label / node name is -declared in DTS. If an exact match is found, the partition dynamically -allocated by the parser will have a connected OF node. - -The NVMEM subsystem will detect the OF node and register any NVMEM cells -declared statically in the DTS. - -Signed-off-by: Christian Marangi -Signed-off-by: Miquel Raynal -Link: https://lore.kernel.org/linux-mtd/20220622010628.30414-4-ansuelsmth@gmail.com ---- - drivers/mtd/mtdcore.c | 61 +++++++++++++++++++++++++++++++++++++++++++ - 1 file changed, 61 insertions(+) - ---- a/drivers/mtd/mtdcore.c -+++ b/drivers/mtd/mtdcore.c -@@ -564,6 +564,66 @@ static int mtd_nvmem_add(struct mtd_info - return 0; - } - -+static void mtd_check_of_node(struct mtd_info *mtd) -+{ -+ struct device_node *partitions, *parent_dn, *mtd_dn = NULL; -+ const char *pname, *prefix = "partition-"; -+ int plen, mtd_name_len, offset, prefix_len; -+ struct mtd_info *parent; -+ bool found = false; -+ -+ /* Check if MTD already has a device node */ -+ if (dev_of_node(&mtd->dev)) -+ return; -+ -+ /* Check if a partitions node exist */ -+ parent = mtd->parent; -+ parent_dn = dev_of_node(&parent->dev); -+ if (!parent_dn) -+ return; -+ -+ partitions = of_get_child_by_name(parent_dn, "partitions"); -+ if (!partitions) -+ goto exit_parent; -+ -+ prefix_len = strlen(prefix); -+ mtd_name_len = strlen(mtd->name); -+ -+ /* Search if a partition is defined with the same name */ -+ for_each_child_of_node(partitions, mtd_dn) { -+ offset = 0; -+ -+ /* Skip partition with no/wrong prefix */ -+ if (!of_node_name_prefix(mtd_dn, "partition-")) -+ continue; -+ -+ /* Label have priority. Check that first */ -+ if (of_property_read_string(mtd_dn, "label", &pname)) { -+ of_property_read_string(mtd_dn, "name", &pname); -+ offset = prefix_len; -+ } -+ -+ plen = strlen(pname) - offset; -+ if (plen == mtd_name_len && -+ !strncmp(mtd->name, pname + offset, plen)) { -+ found = true; -+ break; -+ } -+ } -+ -+ if (!found) -+ goto exit_partitions; -+ -+ /* Set of_node only for nvmem */ -+ if (of_device_is_compatible(mtd_dn, "nvmem-cells")) -+ mtd_set_of_node(mtd, mtd_dn); -+ -+exit_partitions: -+ of_node_put(partitions); -+exit_parent: -+ of_node_put(parent_dn); -+} -+ - /** - * add_mtd_device - register an MTD device - * @mtd: pointer to new MTD device info structure -@@ -669,6 +729,7 @@ int add_mtd_device(struct mtd_info *mtd) - mtd->dev.devt = MTD_DEVT(i); - dev_set_name(&mtd->dev, "mtd%d", i); - dev_set_drvdata(&mtd->dev, mtd); -+ mtd_check_of_node(mtd); - of_node_get(mtd_get_of_node(mtd)); - error = device_register(&mtd->dev); - if (error) diff --git a/target/linux/generic/backport-5.15/402-v6.0-mtd-next-mtd-core-introduce-of-support-for-dynamic-partitions.patch b/target/linux/generic/backport-5.15/402-v6.0-mtd-next-mtd-core-introduce-of-support-for-dynamic-partitions.patch new file mode 100644 index 0000000000..8b8e478b00 --- /dev/null +++ b/target/linux/generic/backport-5.15/402-v6.0-mtd-next-mtd-core-introduce-of-support-for-dynamic-partitions.patch @@ -0,0 +1,106 @@ +From ad9b10d1eaada169bd764abcab58f08538877e26 Mon Sep 17 00:00:00 2001 +From: Christian Marangi +Date: Wed, 22 Jun 2022 03:06:28 +0200 +Subject: mtd: core: introduce of support for dynamic partitions + +We have many parser that register mtd partitions at runtime. One example +is the cmdlinepart or the smem-part parser where the compatible is defined +in the dts and the partitions gets detected and registered by the +parser. This is problematic for the NVMEM subsystem that requires an OF +node to detect NVMEM cells. + +To fix this problem, introduce an additional logic that will try to +assign an OF node to the MTD if declared. + +On MTD addition, it will be checked if the MTD has an OF node and if +not declared will check if a partition with the same label / node name is +declared in DTS. If an exact match is found, the partition dynamically +allocated by the parser will have a connected OF node. + +The NVMEM subsystem will detect the OF node and register any NVMEM cells +declared statically in the DTS. + +Signed-off-by: Christian Marangi +Signed-off-by: Miquel Raynal +Link: https://lore.kernel.org/linux-mtd/20220622010628.30414-4-ansuelsmth@gmail.com +--- + drivers/mtd/mtdcore.c | 61 +++++++++++++++++++++++++++++++++++++++++++ + 1 file changed, 61 insertions(+) + +--- a/drivers/mtd/mtdcore.c ++++ b/drivers/mtd/mtdcore.c +@@ -564,6 +564,66 @@ static int mtd_nvmem_add(struct mtd_info + return 0; + } + ++static void mtd_check_of_node(struct mtd_info *mtd) ++{ ++ struct device_node *partitions, *parent_dn, *mtd_dn = NULL; ++ const char *pname, *prefix = "partition-"; ++ int plen, mtd_name_len, offset, prefix_len; ++ struct mtd_info *parent; ++ bool found = false; ++ ++ /* Check if MTD already has a device node */ ++ if (dev_of_node(&mtd->dev)) ++ return; ++ ++ /* Check if a partitions node exist */ ++ parent = mtd->parent; ++ parent_dn = dev_of_node(&parent->dev); ++ if (!parent_dn) ++ return; ++ ++ partitions = of_get_child_by_name(parent_dn, "partitions"); ++ if (!partitions) ++ goto exit_parent; ++ ++ prefix_len = strlen(prefix); ++ mtd_name_len = strlen(mtd->name); ++ ++ /* Search if a partition is defined with the same name */ ++ for_each_child_of_node(partitions, mtd_dn) { ++ offset = 0; ++ ++ /* Skip partition with no/wrong prefix */ ++ if (!of_node_name_prefix(mtd_dn, "partition-")) ++ continue; ++ ++ /* Label have priority. Check that first */ ++ if (of_property_read_string(mtd_dn, "label", &pname)) { ++ of_property_read_string(mtd_dn, "name", &pname); ++ offset = prefix_len; ++ } ++ ++ plen = strlen(pname) - offset; ++ if (plen == mtd_name_len && ++ !strncmp(mtd->name, pname + offset, plen)) { ++ found = true; ++ break; ++ } ++ } ++ ++ if (!found) ++ goto exit_partitions; ++ ++ /* Set of_node only for nvmem */ ++ if (of_device_is_compatible(mtd_dn, "nvmem-cells")) ++ mtd_set_of_node(mtd, mtd_dn); ++ ++exit_partitions: ++ of_node_put(partitions); ++exit_parent: ++ of_node_put(parent_dn); ++} ++ + /** + * add_mtd_device - register an MTD device + * @mtd: pointer to new MTD device info structure +@@ -669,6 +729,7 @@ int add_mtd_device(struct mtd_info *mtd) + mtd->dev.devt = MTD_DEVT(i); + dev_set_name(&mtd->dev, "mtd%d", i); + dev_set_drvdata(&mtd->dev, mtd); ++ mtd_check_of_node(mtd); + of_node_get(mtd_get_of_node(mtd)); + error = device_register(&mtd->dev); + if (error) diff --git a/target/linux/generic/backport-5.15/800-v5.20-0001-dt-bindings-leds-add-Broadcom-s-BCM63138-controller.patch b/target/linux/generic/backport-5.15/800-v5.20-0001-dt-bindings-leds-add-Broadcom-s-BCM63138-controller.patch deleted file mode 100644 index b1072ce640..0000000000 --- a/target/linux/generic/backport-5.15/800-v5.20-0001-dt-bindings-leds-add-Broadcom-s-BCM63138-controller.patch +++ /dev/null @@ -1,125 +0,0 @@ -From 13344f8ce8a0d98aa7f5d69ce3b47393c73a343b Mon Sep 17 00:00:00 2001 -From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= -Date: Mon, 27 Dec 2021 15:59:04 +0100 -Subject: [PATCH] dt-bindings: leds: add Broadcom's BCM63138 controller -MIME-Version: 1.0 -Content-Type: text/plain; charset=UTF-8 -Content-Transfer-Encoding: 8bit - -Broadcom used 2 LEDs hardware blocks for their BCM63xx SoCs: -1. Older one (BCM6318, BCM6328, BCM6362, BCM63268, BCM6838) -2. Newer one (BCM6848, BCM6858, BCM63138, BCM63148, BCM63381, BCM68360) - -The newer one was also later also used on BCM4908 SoC. - -Old block is already documented in the leds-bcm6328.yaml. This binding -documents the new one which uses different registers & programming. It's -first used in BCM63138 thus the binding name. - -Signed-off-by: Rafał Miłecki -Reviewed-by: Rob Herring -Reviewed-by: Florian Fainelli -Signed-off-by: Pavel Machek ---- - .../bindings/leds/leds-bcm63138.yaml | 95 +++++++++++++++++++ - 1 file changed, 95 insertions(+) - create mode 100644 Documentation/devicetree/bindings/leds/leds-bcm63138.yaml - ---- /dev/null -+++ b/Documentation/devicetree/bindings/leds/leds-bcm63138.yaml -@@ -0,0 +1,95 @@ -+# SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause -+%YAML 1.2 -+--- -+$id: http://devicetree.org/schemas/leds/leds-bcm63138.yaml# -+$schema: http://devicetree.org/meta-schemas/core.yaml# -+ -+title: Broadcom's BCM63138 LEDs controller -+ -+maintainers: -+ - Rafał Miłecki -+ -+description: | -+ This LEDs controller was first used on BCM63138 and later reused on BCM4908, -+ BCM6848, BCM6858, BCM63138, BCM63148, BCM63381 and BCM68360 SoCs. -+ -+ It supports up to 32 LEDs that can be connected parallelly or serially. It -+ also includes limited support for hardware blinking. -+ -+ Binding serially connected LEDs isn't documented yet. -+ -+properties: -+ compatible: -+ oneOf: -+ - items: -+ - enum: -+ - brcm,bcm4908-leds -+ - brcm,bcm6848-leds -+ - brcm,bcm6858-leds -+ - brcm,bcm63148-leds -+ - brcm,bcm63381-leds -+ - brcm,bcm68360-leds -+ - const: brcm,bcm63138-leds -+ - const: brcm,bcm63138-leds -+ -+ reg: -+ maxItems: 1 -+ -+ "#address-cells": -+ const: 1 -+ -+ "#size-cells": -+ const: 0 -+ -+patternProperties: -+ "^led@[a-f0-9]+$": -+ type: object -+ -+ $ref: common.yaml# -+ -+ properties: -+ reg: -+ maxItems: 1 -+ description: LED pin number -+ -+ active-low: -+ type: boolean -+ description: Makes LED active low. -+ -+ required: -+ - reg -+ -+ unevaluatedProperties: false -+ -+required: -+ - reg -+ - "#address-cells" -+ - "#size-cells" -+ -+additionalProperties: false -+ -+examples: -+ - | -+ #include -+ -+ leds@ff800800 { -+ compatible = "brcm,bcm4908-leds", "brcm,bcm63138-leds"; -+ reg = <0xff800800 0xdc>; -+ -+ #address-cells = <1>; -+ #size-cells = <0>; -+ -+ led@0 { -+ reg = <0x0>; -+ function = LED_FUNCTION_POWER; -+ color = ; -+ default-state = "on"; -+ }; -+ -+ led@3 { -+ reg = <0x3>; -+ function = LED_FUNCTION_STATUS; -+ color = ; -+ active-low; -+ }; -+ }; diff --git a/target/linux/generic/backport-5.15/800-v5.20-0002-leds-bcm63138-add-support-for-BCM63138-controller.patch b/target/linux/generic/backport-5.15/800-v5.20-0002-leds-bcm63138-add-support-for-BCM63138-controller.patch deleted file mode 100644 index 376584574f..0000000000 --- a/target/linux/generic/backport-5.15/800-v5.20-0002-leds-bcm63138-add-support-for-BCM63138-controller.patch +++ /dev/null @@ -1,356 +0,0 @@ -From a0ba692072d89075d0a75c7ad9df31f2c1ee9a1c Mon Sep 17 00:00:00 2001 -From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= -Date: Mon, 27 Dec 2021 15:59:05 +0100 -Subject: [PATCH] leds: bcm63138: add support for BCM63138 controller -MIME-Version: 1.0 -Content-Type: text/plain; charset=UTF-8 -Content-Transfer-Encoding: 8bit - -It's a new controller first introduced in BCM63138 SoC. Later it was -also used in BCM4908, some BCM68xx and some BCM63xxx SoCs. - -Signed-off-by: Rafał Miłecki -Reviewed-by: Florian Fainelli -Signed-off-by: Pavel Machek ---- - drivers/leds/blink/Kconfig | 12 ++ - drivers/leds/blink/Makefile | 1 + - drivers/leds/blink/leds-bcm63138.c | 308 +++++++++++++++++++++++++++++ - 3 files changed, 321 insertions(+) - create mode 100644 drivers/leds/blink/leds-bcm63138.c - ---- a/drivers/leds/blink/Kconfig -+++ b/drivers/leds/blink/Kconfig -@@ -1,3 +1,15 @@ -+config LEDS_BCM63138 -+ tristate "LED Support for Broadcom BCM63138 SoC" -+ depends on LEDS_CLASS -+ depends on ARCH_BCM4908 || ARCH_BCM_5301X || BCM63XX || COMPILE_TEST -+ depends on HAS_IOMEM -+ depends on OF -+ default ARCH_BCM4908 -+ help -+ This option enables support for LED controller that is part of -+ BCM63138 SoC. The same hardware block is known to be also used -+ in BCM4908, BCM6848, BCM6858, BCM63148, BCM63381 and BCM68360. -+ - config LEDS_LGM - tristate "LED support for LGM SoC series" - depends on X86 || COMPILE_TEST ---- a/drivers/leds/blink/Makefile -+++ b/drivers/leds/blink/Makefile -@@ -1,2 +1,3 @@ - # SPDX-License-Identifier: GPL-2.0 -+obj-$(CONFIG_LEDS_BCM63138) += leds-bcm63138.o - obj-$(CONFIG_LEDS_LGM) += leds-lgm-sso.o ---- /dev/null -+++ b/drivers/leds/blink/leds-bcm63138.c -@@ -0,0 +1,308 @@ -+// SPDX-License-Identifier: GPL-2.0-only -+/* -+ * Copyright (C) 2021 Rafał Miłecki -+ */ -+#include -+#include -+#include -+#include -+#include -+#include -+#include -+#include -+ -+#define BCM63138_MAX_LEDS 32 -+#define BCM63138_MAX_BRIGHTNESS 9 -+ -+#define BCM63138_LED_BITS 4 /* how many bits control a single LED */ -+#define BCM63138_LED_MASK ((1 << BCM63138_LED_BITS) - 1) /* 0xf */ -+#define BCM63138_LEDS_PER_REG (32 / BCM63138_LED_BITS) /* 8 */ -+ -+#define BCM63138_GLB_CTRL 0x00 -+#define BCM63138_GLB_CTRL_SERIAL_LED_DATA_PPOL 0x00000002 -+#define BCM63138_GLB_CTRL_SERIAL_LED_EN_POL 0x00000008 -+#define BCM63138_MASK 0x04 -+#define BCM63138_HW_LED_EN 0x08 -+#define BCM63138_SERIAL_LED_SHIFT_SEL 0x0c -+#define BCM63138_FLASH_RATE_CTRL1 0x10 -+#define BCM63138_FLASH_RATE_CTRL2 0x14 -+#define BCM63138_FLASH_RATE_CTRL3 0x18 -+#define BCM63138_FLASH_RATE_CTRL4 0x1c -+#define BCM63138_BRIGHT_CTRL1 0x20 -+#define BCM63138_BRIGHT_CTRL2 0x24 -+#define BCM63138_BRIGHT_CTRL3 0x28 -+#define BCM63138_BRIGHT_CTRL4 0x2c -+#define BCM63138_POWER_LED_CFG 0x30 -+#define BCM63138_HW_POLARITY 0xb4 -+#define BCM63138_SW_DATA 0xb8 -+#define BCM63138_SW_POLARITY 0xbc -+#define BCM63138_PARALLEL_LED_POLARITY 0xc0 -+#define BCM63138_SERIAL_LED_POLARITY 0xc4 -+#define BCM63138_HW_LED_STATUS 0xc8 -+#define BCM63138_FLASH_CTRL_STATUS 0xcc -+#define BCM63138_FLASH_BRT_CTRL 0xd0 -+#define BCM63138_FLASH_P_LED_OUT_STATUS 0xd4 -+#define BCM63138_FLASH_S_LED_OUT_STATUS 0xd8 -+ -+struct bcm63138_leds { -+ struct device *dev; -+ void __iomem *base; -+ spinlock_t lock; -+}; -+ -+struct bcm63138_led { -+ struct bcm63138_leds *leds; -+ struct led_classdev cdev; -+ u32 pin; -+ bool active_low; -+}; -+ -+/* -+ * I/O access -+ */ -+ -+static void bcm63138_leds_write(struct bcm63138_leds *leds, unsigned int reg, -+ u32 data) -+{ -+ writel(data, leds->base + reg); -+} -+ -+static unsigned long bcm63138_leds_read(struct bcm63138_leds *leds, -+ unsigned int reg) -+{ -+ return readl(leds->base + reg); -+} -+ -+static void bcm63138_leds_update_bits(struct bcm63138_leds *leds, -+ unsigned int reg, u32 mask, u32 val) -+{ -+ WARN_ON(val & ~mask); -+ -+ bcm63138_leds_write(leds, reg, (bcm63138_leds_read(leds, reg) & ~mask) | (val & mask)); -+} -+ -+/* -+ * Helpers -+ */ -+ -+static void bcm63138_leds_set_flash_rate(struct bcm63138_leds *leds, -+ struct bcm63138_led *led, -+ u8 value) -+{ -+ int reg_offset = (led->pin >> fls((BCM63138_LEDS_PER_REG - 1))) * 4; -+ int shift = (led->pin & (BCM63138_LEDS_PER_REG - 1)) * BCM63138_LED_BITS; -+ -+ bcm63138_leds_update_bits(leds, BCM63138_FLASH_RATE_CTRL1 + reg_offset, -+ BCM63138_LED_MASK << shift, value << shift); -+} -+ -+static void bcm63138_leds_set_bright(struct bcm63138_leds *leds, -+ struct bcm63138_led *led, -+ u8 value) -+{ -+ int reg_offset = (led->pin >> fls((BCM63138_LEDS_PER_REG - 1))) * 4; -+ int shift = (led->pin & (BCM63138_LEDS_PER_REG - 1)) * BCM63138_LED_BITS; -+ -+ bcm63138_leds_update_bits(leds, BCM63138_BRIGHT_CTRL1 + reg_offset, -+ BCM63138_LED_MASK << shift, value << shift); -+} -+ -+static void bcm63138_leds_enable_led(struct bcm63138_leds *leds, -+ struct bcm63138_led *led, -+ enum led_brightness value) -+{ -+ u32 bit = BIT(led->pin); -+ -+ bcm63138_leds_update_bits(leds, BCM63138_SW_DATA, bit, -+ value == LED_OFF ? 0 : bit); -+} -+ -+/* -+ * API callbacks -+ */ -+ -+static void bcm63138_leds_brightness_set(struct led_classdev *led_cdev, -+ enum led_brightness value) -+{ -+ struct bcm63138_led *led = container_of(led_cdev, struct bcm63138_led, cdev); -+ struct bcm63138_leds *leds = led->leds; -+ unsigned long flags; -+ -+ spin_lock_irqsave(&leds->lock, flags); -+ -+ bcm63138_leds_enable_led(leds, led, value); -+ if (!value) -+ bcm63138_leds_set_flash_rate(leds, led, 0); -+ else -+ bcm63138_leds_set_bright(leds, led, value); -+ -+ spin_unlock_irqrestore(&leds->lock, flags); -+} -+ -+static int bcm63138_leds_blink_set(struct led_classdev *led_cdev, -+ unsigned long *delay_on, -+ unsigned long *delay_off) -+{ -+ struct bcm63138_led *led = container_of(led_cdev, struct bcm63138_led, cdev); -+ struct bcm63138_leds *leds = led->leds; -+ unsigned long flags; -+ u8 value; -+ -+ if (!*delay_on && !*delay_off) { -+ *delay_on = 640; -+ *delay_off = 640; -+ } -+ -+ if (*delay_on != *delay_off) { -+ dev_dbg(led_cdev->dev, "Blinking at unequal delays is not supported\n"); -+ return -EINVAL; -+ } -+ -+ switch (*delay_on) { -+ case 1152 ... 1408: /* 1280 ms ± 10% */ -+ value = 0x7; -+ break; -+ case 576 ... 704: /* 640 ms ± 10% */ -+ value = 0x6; -+ break; -+ case 288 ... 352: /* 320 ms ± 10% */ -+ value = 0x5; -+ break; -+ case 126 ... 154: /* 140 ms ± 10% */ -+ value = 0x4; -+ break; -+ case 59 ... 72: /* 65 ms ± 10% */ -+ value = 0x3; -+ break; -+ default: -+ dev_dbg(led_cdev->dev, "Blinking delay value %lu is unsupported\n", -+ *delay_on); -+ return -EINVAL; -+ } -+ -+ spin_lock_irqsave(&leds->lock, flags); -+ -+ bcm63138_leds_enable_led(leds, led, BCM63138_MAX_BRIGHTNESS); -+ bcm63138_leds_set_flash_rate(leds, led, value); -+ -+ spin_unlock_irqrestore(&leds->lock, flags); -+ -+ return 0; -+} -+ -+/* -+ * LED driver -+ */ -+ -+static void bcm63138_leds_create_led(struct bcm63138_leds *leds, -+ struct device_node *np) -+{ -+ struct led_init_data init_data = { -+ .fwnode = of_fwnode_handle(np), -+ }; -+ struct device *dev = leds->dev; -+ struct bcm63138_led *led; -+ struct pinctrl *pinctrl; -+ u32 bit; -+ int err; -+ -+ led = devm_kzalloc(dev, sizeof(*led), GFP_KERNEL); -+ if (!led) { -+ dev_err(dev, "Failed to alloc LED\n"); -+ return; -+ } -+ -+ led->leds = leds; -+ -+ if (of_property_read_u32(np, "reg", &led->pin)) { -+ dev_err(dev, "Missing \"reg\" property in %pOF\n", np); -+ goto err_free; -+ } -+ -+ if (led->pin >= BCM63138_MAX_LEDS) { -+ dev_err(dev, "Invalid \"reg\" value %d\n", led->pin); -+ goto err_free; -+ } -+ -+ led->active_low = of_property_read_bool(np, "active-low"); -+ -+ led->cdev.max_brightness = BCM63138_MAX_BRIGHTNESS; -+ led->cdev.brightness_set = bcm63138_leds_brightness_set; -+ led->cdev.blink_set = bcm63138_leds_blink_set; -+ -+ err = devm_led_classdev_register_ext(dev, &led->cdev, &init_data); -+ if (err) { -+ dev_err(dev, "Failed to register LED %pOF: %d\n", np, err); -+ goto err_free; -+ } -+ -+ pinctrl = devm_pinctrl_get_select_default(led->cdev.dev); -+ if (IS_ERR(pinctrl) && PTR_ERR(pinctrl) != -ENODEV) { -+ dev_warn(led->cdev.dev, "Failed to select %pOF pinctrl: %ld\n", -+ np, PTR_ERR(pinctrl)); -+ } -+ -+ bit = BIT(led->pin); -+ bcm63138_leds_update_bits(leds, BCM63138_PARALLEL_LED_POLARITY, bit, -+ led->active_low ? 0 : bit); -+ bcm63138_leds_update_bits(leds, BCM63138_HW_LED_EN, bit, 0); -+ bcm63138_leds_set_flash_rate(leds, led, 0); -+ bcm63138_leds_enable_led(leds, led, led->cdev.brightness); -+ -+ return; -+ -+err_free: -+ devm_kfree(dev, led); -+} -+ -+static int bcm63138_leds_probe(struct platform_device *pdev) -+{ -+ struct device_node *np = dev_of_node(&pdev->dev); -+ struct device *dev = &pdev->dev; -+ struct bcm63138_leds *leds; -+ struct device_node *child; -+ -+ leds = devm_kzalloc(dev, sizeof(*leds), GFP_KERNEL); -+ if (!leds) -+ return -ENOMEM; -+ -+ leds->dev = dev; -+ -+ leds->base = devm_platform_ioremap_resource(pdev, 0); -+ if (IS_ERR(leds->base)) -+ return PTR_ERR(leds->base); -+ -+ spin_lock_init(&leds->lock); -+ -+ bcm63138_leds_write(leds, BCM63138_GLB_CTRL, -+ BCM63138_GLB_CTRL_SERIAL_LED_DATA_PPOL | -+ BCM63138_GLB_CTRL_SERIAL_LED_EN_POL); -+ bcm63138_leds_write(leds, BCM63138_HW_LED_EN, 0); -+ bcm63138_leds_write(leds, BCM63138_SERIAL_LED_POLARITY, 0); -+ bcm63138_leds_write(leds, BCM63138_PARALLEL_LED_POLARITY, 0); -+ -+ for_each_available_child_of_node(np, child) { -+ bcm63138_leds_create_led(leds, child); -+ } -+ -+ return 0; -+} -+ -+static const struct of_device_id bcm63138_leds_of_match_table[] = { -+ { .compatible = "brcm,bcm63138-leds", }, -+ { }, -+}; -+ -+static struct platform_driver bcm63138_leds_driver = { -+ .probe = bcm63138_leds_probe, -+ .driver = { -+ .name = "leds-bcm63xxx", -+ .of_match_table = bcm63138_leds_of_match_table, -+ }, -+}; -+ -+module_platform_driver(bcm63138_leds_driver); -+ -+MODULE_AUTHOR("Rafał Miłecki"); -+MODULE_LICENSE("GPL"); -+MODULE_DEVICE_TABLE(of, bcm63138_leds_of_match_table); diff --git a/target/linux/generic/backport-5.15/800-v6.0-0001-dt-bindings-leds-add-Broadcom-s-BCM63138-controller.patch b/target/linux/generic/backport-5.15/800-v6.0-0001-dt-bindings-leds-add-Broadcom-s-BCM63138-controller.patch new file mode 100644 index 0000000000..b1072ce640 --- /dev/null +++ b/target/linux/generic/backport-5.15/800-v6.0-0001-dt-bindings-leds-add-Broadcom-s-BCM63138-controller.patch @@ -0,0 +1,125 @@ +From 13344f8ce8a0d98aa7f5d69ce3b47393c73a343b Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= +Date: Mon, 27 Dec 2021 15:59:04 +0100 +Subject: [PATCH] dt-bindings: leds: add Broadcom's BCM63138 controller +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +Broadcom used 2 LEDs hardware blocks for their BCM63xx SoCs: +1. Older one (BCM6318, BCM6328, BCM6362, BCM63268, BCM6838) +2. Newer one (BCM6848, BCM6858, BCM63138, BCM63148, BCM63381, BCM68360) + +The newer one was also later also used on BCM4908 SoC. + +Old block is already documented in the leds-bcm6328.yaml. This binding +documents the new one which uses different registers & programming. It's +first used in BCM63138 thus the binding name. + +Signed-off-by: Rafał Miłecki +Reviewed-by: Rob Herring +Reviewed-by: Florian Fainelli +Signed-off-by: Pavel Machek +--- + .../bindings/leds/leds-bcm63138.yaml | 95 +++++++++++++++++++ + 1 file changed, 95 insertions(+) + create mode 100644 Documentation/devicetree/bindings/leds/leds-bcm63138.yaml + +--- /dev/null ++++ b/Documentation/devicetree/bindings/leds/leds-bcm63138.yaml +@@ -0,0 +1,95 @@ ++# SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause ++%YAML 1.2 ++--- ++$id: http://devicetree.org/schemas/leds/leds-bcm63138.yaml# ++$schema: http://devicetree.org/meta-schemas/core.yaml# ++ ++title: Broadcom's BCM63138 LEDs controller ++ ++maintainers: ++ - Rafał Miłecki ++ ++description: | ++ This LEDs controller was first used on BCM63138 and later reused on BCM4908, ++ BCM6848, BCM6858, BCM63138, BCM63148, BCM63381 and BCM68360 SoCs. ++ ++ It supports up to 32 LEDs that can be connected parallelly or serially. It ++ also includes limited support for hardware blinking. ++ ++ Binding serially connected LEDs isn't documented yet. ++ ++properties: ++ compatible: ++ oneOf: ++ - items: ++ - enum: ++ - brcm,bcm4908-leds ++ - brcm,bcm6848-leds ++ - brcm,bcm6858-leds ++ - brcm,bcm63148-leds ++ - brcm,bcm63381-leds ++ - brcm,bcm68360-leds ++ - const: brcm,bcm63138-leds ++ - const: brcm,bcm63138-leds ++ ++ reg: ++ maxItems: 1 ++ ++ "#address-cells": ++ const: 1 ++ ++ "#size-cells": ++ const: 0 ++ ++patternProperties: ++ "^led@[a-f0-9]+$": ++ type: object ++ ++ $ref: common.yaml# ++ ++ properties: ++ reg: ++ maxItems: 1 ++ description: LED pin number ++ ++ active-low: ++ type: boolean ++ description: Makes LED active low. ++ ++ required: ++ - reg ++ ++ unevaluatedProperties: false ++ ++required: ++ - reg ++ - "#address-cells" ++ - "#size-cells" ++ ++additionalProperties: false ++ ++examples: ++ - | ++ #include ++ ++ leds@ff800800 { ++ compatible = "brcm,bcm4908-leds", "brcm,bcm63138-leds"; ++ reg = <0xff800800 0xdc>; ++ ++ #address-cells = <1>; ++ #size-cells = <0>; ++ ++ led@0 { ++ reg = <0x0>; ++ function = LED_FUNCTION_POWER; ++ color = ; ++ default-state = "on"; ++ }; ++ ++ led@3 { ++ reg = <0x3>; ++ function = LED_FUNCTION_STATUS; ++ color = ; ++ active-low; ++ }; ++ }; diff --git a/target/linux/generic/backport-5.15/800-v6.0-0002-leds-bcm63138-add-support-for-BCM63138-controller.patch b/target/linux/generic/backport-5.15/800-v6.0-0002-leds-bcm63138-add-support-for-BCM63138-controller.patch new file mode 100644 index 0000000000..376584574f --- /dev/null +++ b/target/linux/generic/backport-5.15/800-v6.0-0002-leds-bcm63138-add-support-for-BCM63138-controller.patch @@ -0,0 +1,356 @@ +From a0ba692072d89075d0a75c7ad9df31f2c1ee9a1c Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= +Date: Mon, 27 Dec 2021 15:59:05 +0100 +Subject: [PATCH] leds: bcm63138: add support for BCM63138 controller +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +It's a new controller first introduced in BCM63138 SoC. Later it was +also used in BCM4908, some BCM68xx and some BCM63xxx SoCs. + +Signed-off-by: Rafał Miłecki +Reviewed-by: Florian Fainelli +Signed-off-by: Pavel Machek +--- + drivers/leds/blink/Kconfig | 12 ++ + drivers/leds/blink/Makefile | 1 + + drivers/leds/blink/leds-bcm63138.c | 308 +++++++++++++++++++++++++++++ + 3 files changed, 321 insertions(+) + create mode 100644 drivers/leds/blink/leds-bcm63138.c + +--- a/drivers/leds/blink/Kconfig ++++ b/drivers/leds/blink/Kconfig +@@ -1,3 +1,15 @@ ++config LEDS_BCM63138 ++ tristate "LED Support for Broadcom BCM63138 SoC" ++ depends on LEDS_CLASS ++ depends on ARCH_BCM4908 || ARCH_BCM_5301X || BCM63XX || COMPILE_TEST ++ depends on HAS_IOMEM ++ depends on OF ++ default ARCH_BCM4908 ++ help ++ This option enables support for LED controller that is part of ++ BCM63138 SoC. The same hardware block is known to be also used ++ in BCM4908, BCM6848, BCM6858, BCM63148, BCM63381 and BCM68360. ++ + config LEDS_LGM + tristate "LED support for LGM SoC series" + depends on X86 || COMPILE_TEST +--- a/drivers/leds/blink/Makefile ++++ b/drivers/leds/blink/Makefile +@@ -1,2 +1,3 @@ + # SPDX-License-Identifier: GPL-2.0 ++obj-$(CONFIG_LEDS_BCM63138) += leds-bcm63138.o + obj-$(CONFIG_LEDS_LGM) += leds-lgm-sso.o +--- /dev/null ++++ b/drivers/leds/blink/leds-bcm63138.c +@@ -0,0 +1,308 @@ ++// SPDX-License-Identifier: GPL-2.0-only ++/* ++ * Copyright (C) 2021 Rafał Miłecki ++ */ ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++ ++#define BCM63138_MAX_LEDS 32 ++#define BCM63138_MAX_BRIGHTNESS 9 ++ ++#define BCM63138_LED_BITS 4 /* how many bits control a single LED */ ++#define BCM63138_LED_MASK ((1 << BCM63138_LED_BITS) - 1) /* 0xf */ ++#define BCM63138_LEDS_PER_REG (32 / BCM63138_LED_BITS) /* 8 */ ++ ++#define BCM63138_GLB_CTRL 0x00 ++#define BCM63138_GLB_CTRL_SERIAL_LED_DATA_PPOL 0x00000002 ++#define BCM63138_GLB_CTRL_SERIAL_LED_EN_POL 0x00000008 ++#define BCM63138_MASK 0x04 ++#define BCM63138_HW_LED_EN 0x08 ++#define BCM63138_SERIAL_LED_SHIFT_SEL 0x0c ++#define BCM63138_FLASH_RATE_CTRL1 0x10 ++#define BCM63138_FLASH_RATE_CTRL2 0x14 ++#define BCM63138_FLASH_RATE_CTRL3 0x18 ++#define BCM63138_FLASH_RATE_CTRL4 0x1c ++#define BCM63138_BRIGHT_CTRL1 0x20 ++#define BCM63138_BRIGHT_CTRL2 0x24 ++#define BCM63138_BRIGHT_CTRL3 0x28 ++#define BCM63138_BRIGHT_CTRL4 0x2c ++#define BCM63138_POWER_LED_CFG 0x30 ++#define BCM63138_HW_POLARITY 0xb4 ++#define BCM63138_SW_DATA 0xb8 ++#define BCM63138_SW_POLARITY 0xbc ++#define BCM63138_PARALLEL_LED_POLARITY 0xc0 ++#define BCM63138_SERIAL_LED_POLARITY 0xc4 ++#define BCM63138_HW_LED_STATUS 0xc8 ++#define BCM63138_FLASH_CTRL_STATUS 0xcc ++#define BCM63138_FLASH_BRT_CTRL 0xd0 ++#define BCM63138_FLASH_P_LED_OUT_STATUS 0xd4 ++#define BCM63138_FLASH_S_LED_OUT_STATUS 0xd8 ++ ++struct bcm63138_leds { ++ struct device *dev; ++ void __iomem *base; ++ spinlock_t lock; ++}; ++ ++struct bcm63138_led { ++ struct bcm63138_leds *leds; ++ struct led_classdev cdev; ++ u32 pin; ++ bool active_low; ++}; ++ ++/* ++ * I/O access ++ */ ++ ++static void bcm63138_leds_write(struct bcm63138_leds *leds, unsigned int reg, ++ u32 data) ++{ ++ writel(data, leds->base + reg); ++} ++ ++static unsigned long bcm63138_leds_read(struct bcm63138_leds *leds, ++ unsigned int reg) ++{ ++ return readl(leds->base + reg); ++} ++ ++static void bcm63138_leds_update_bits(struct bcm63138_leds *leds, ++ unsigned int reg, u32 mask, u32 val) ++{ ++ WARN_ON(val & ~mask); ++ ++ bcm63138_leds_write(leds, reg, (bcm63138_leds_read(leds, reg) & ~mask) | (val & mask)); ++} ++ ++/* ++ * Helpers ++ */ ++ ++static void bcm63138_leds_set_flash_rate(struct bcm63138_leds *leds, ++ struct bcm63138_led *led, ++ u8 value) ++{ ++ int reg_offset = (led->pin >> fls((BCM63138_LEDS_PER_REG - 1))) * 4; ++ int shift = (led->pin & (BCM63138_LEDS_PER_REG - 1)) * BCM63138_LED_BITS; ++ ++ bcm63138_leds_update_bits(leds, BCM63138_FLASH_RATE_CTRL1 + reg_offset, ++ BCM63138_LED_MASK << shift, value << shift); ++} ++ ++static void bcm63138_leds_set_bright(struct bcm63138_leds *leds, ++ struct bcm63138_led *led, ++ u8 value) ++{ ++ int reg_offset = (led->pin >> fls((BCM63138_LEDS_PER_REG - 1))) * 4; ++ int shift = (led->pin & (BCM63138_LEDS_PER_REG - 1)) * BCM63138_LED_BITS; ++ ++ bcm63138_leds_update_bits(leds, BCM63138_BRIGHT_CTRL1 + reg_offset, ++ BCM63138_LED_MASK << shift, value << shift); ++} ++ ++static void bcm63138_leds_enable_led(struct bcm63138_leds *leds, ++ struct bcm63138_led *led, ++ enum led_brightness value) ++{ ++ u32 bit = BIT(led->pin); ++ ++ bcm63138_leds_update_bits(leds, BCM63138_SW_DATA, bit, ++ value == LED_OFF ? 0 : bit); ++} ++ ++/* ++ * API callbacks ++ */ ++ ++static void bcm63138_leds_brightness_set(struct led_classdev *led_cdev, ++ enum led_brightness value) ++{ ++ struct bcm63138_led *led = container_of(led_cdev, struct bcm63138_led, cdev); ++ struct bcm63138_leds *leds = led->leds; ++ unsigned long flags; ++ ++ spin_lock_irqsave(&leds->lock, flags); ++ ++ bcm63138_leds_enable_led(leds, led, value); ++ if (!value) ++ bcm63138_leds_set_flash_rate(leds, led, 0); ++ else ++ bcm63138_leds_set_bright(leds, led, value); ++ ++ spin_unlock_irqrestore(&leds->lock, flags); ++} ++ ++static int bcm63138_leds_blink_set(struct led_classdev *led_cdev, ++ unsigned long *delay_on, ++ unsigned long *delay_off) ++{ ++ struct bcm63138_led *led = container_of(led_cdev, struct bcm63138_led, cdev); ++ struct bcm63138_leds *leds = led->leds; ++ unsigned long flags; ++ u8 value; ++ ++ if (!*delay_on && !*delay_off) { ++ *delay_on = 640; ++ *delay_off = 640; ++ } ++ ++ if (*delay_on != *delay_off) { ++ dev_dbg(led_cdev->dev, "Blinking at unequal delays is not supported\n"); ++ return -EINVAL; ++ } ++ ++ switch (*delay_on) { ++ case 1152 ... 1408: /* 1280 ms ± 10% */ ++ value = 0x7; ++ break; ++ case 576 ... 704: /* 640 ms ± 10% */ ++ value = 0x6; ++ break; ++ case 288 ... 352: /* 320 ms ± 10% */ ++ value = 0x5; ++ break; ++ case 126 ... 154: /* 140 ms ± 10% */ ++ value = 0x4; ++ break; ++ case 59 ... 72: /* 65 ms ± 10% */ ++ value = 0x3; ++ break; ++ default: ++ dev_dbg(led_cdev->dev, "Blinking delay value %lu is unsupported\n", ++ *delay_on); ++ return -EINVAL; ++ } ++ ++ spin_lock_irqsave(&leds->lock, flags); ++ ++ bcm63138_leds_enable_led(leds, led, BCM63138_MAX_BRIGHTNESS); ++ bcm63138_leds_set_flash_rate(leds, led, value); ++ ++ spin_unlock_irqrestore(&leds->lock, flags); ++ ++ return 0; ++} ++ ++/* ++ * LED driver ++ */ ++ ++static void bcm63138_leds_create_led(struct bcm63138_leds *leds, ++ struct device_node *np) ++{ ++ struct led_init_data init_data = { ++ .fwnode = of_fwnode_handle(np), ++ }; ++ struct device *dev = leds->dev; ++ struct bcm63138_led *led; ++ struct pinctrl *pinctrl; ++ u32 bit; ++ int err; ++ ++ led = devm_kzalloc(dev, sizeof(*led), GFP_KERNEL); ++ if (!led) { ++ dev_err(dev, "Failed to alloc LED\n"); ++ return; ++ } ++ ++ led->leds = leds; ++ ++ if (of_property_read_u32(np, "reg", &led->pin)) { ++ dev_err(dev, "Missing \"reg\" property in %pOF\n", np); ++ goto err_free; ++ } ++ ++ if (led->pin >= BCM63138_MAX_LEDS) { ++ dev_err(dev, "Invalid \"reg\" value %d\n", led->pin); ++ goto err_free; ++ } ++ ++ led->active_low = of_property_read_bool(np, "active-low"); ++ ++ led->cdev.max_brightness = BCM63138_MAX_BRIGHTNESS; ++ led->cdev.brightness_set = bcm63138_leds_brightness_set; ++ led->cdev.blink_set = bcm63138_leds_blink_set; ++ ++ err = devm_led_classdev_register_ext(dev, &led->cdev, &init_data); ++ if (err) { ++ dev_err(dev, "Failed to register LED %pOF: %d\n", np, err); ++ goto err_free; ++ } ++ ++ pinctrl = devm_pinctrl_get_select_default(led->cdev.dev); ++ if (IS_ERR(pinctrl) && PTR_ERR(pinctrl) != -ENODEV) { ++ dev_warn(led->cdev.dev, "Failed to select %pOF pinctrl: %ld\n", ++ np, PTR_ERR(pinctrl)); ++ } ++ ++ bit = BIT(led->pin); ++ bcm63138_leds_update_bits(leds, BCM63138_PARALLEL_LED_POLARITY, bit, ++ led->active_low ? 0 : bit); ++ bcm63138_leds_update_bits(leds, BCM63138_HW_LED_EN, bit, 0); ++ bcm63138_leds_set_flash_rate(leds, led, 0); ++ bcm63138_leds_enable_led(leds, led, led->cdev.brightness); ++ ++ return; ++ ++err_free: ++ devm_kfree(dev, led); ++} ++ ++static int bcm63138_leds_probe(struct platform_device *pdev) ++{ ++ struct device_node *np = dev_of_node(&pdev->dev); ++ struct device *dev = &pdev->dev; ++ struct bcm63138_leds *leds; ++ struct device_node *child; ++ ++ leds = devm_kzalloc(dev, sizeof(*leds), GFP_KERNEL); ++ if (!leds) ++ return -ENOMEM; ++ ++ leds->dev = dev; ++ ++ leds->base = devm_platform_ioremap_resource(pdev, 0); ++ if (IS_ERR(leds->base)) ++ return PTR_ERR(leds->base); ++ ++ spin_lock_init(&leds->lock); ++ ++ bcm63138_leds_write(leds, BCM63138_GLB_CTRL, ++ BCM63138_GLB_CTRL_SERIAL_LED_DATA_PPOL | ++ BCM63138_GLB_CTRL_SERIAL_LED_EN_POL); ++ bcm63138_leds_write(leds, BCM63138_HW_LED_EN, 0); ++ bcm63138_leds_write(leds, BCM63138_SERIAL_LED_POLARITY, 0); ++ bcm63138_leds_write(leds, BCM63138_PARALLEL_LED_POLARITY, 0); ++ ++ for_each_available_child_of_node(np, child) { ++ bcm63138_leds_create_led(leds, child); ++ } ++ ++ return 0; ++} ++ ++static const struct of_device_id bcm63138_leds_of_match_table[] = { ++ { .compatible = "brcm,bcm63138-leds", }, ++ { }, ++}; ++ ++static struct platform_driver bcm63138_leds_driver = { ++ .probe = bcm63138_leds_probe, ++ .driver = { ++ .name = "leds-bcm63xxx", ++ .of_match_table = bcm63138_leds_of_match_table, ++ }, ++}; ++ ++module_platform_driver(bcm63138_leds_driver); ++ ++MODULE_AUTHOR("Rafał Miłecki"); ++MODULE_LICENSE("GPL"); ++MODULE_DEVICE_TABLE(of, bcm63138_leds_of_match_table); diff --git a/target/linux/generic/backport-5.15/801-v5.20-0001-dt-bindings-leds-leds-bcm63138-unify-full-stops-in-d.patch b/target/linux/generic/backport-5.15/801-v5.20-0001-dt-bindings-leds-leds-bcm63138-unify-full-stops-in-d.patch deleted file mode 100644 index 483826abed..0000000000 --- a/target/linux/generic/backport-5.15/801-v5.20-0001-dt-bindings-leds-leds-bcm63138-unify-full-stops-in-d.patch +++ /dev/null @@ -1,30 +0,0 @@ -From 13b64a0c19059b38150c79d65d350ae44034c5df Mon Sep 17 00:00:00 2001 -From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= -Date: Sun, 17 Jul 2022 14:42:46 +0200 -Subject: [PATCH] dt-bindings: leds: leds-bcm63138: unify full stops in - descriptions -MIME-Version: 1.0 -Content-Type: text/plain; charset=UTF-8 -Content-Transfer-Encoding: 8bit - -Description of "reg" doesn't have full stop at the end. It makes sense -as it's a one-sentence only. Use the same style for "active-low". - -Reported-by: Pavel Machek -Signed-off-by: Rafał Miłecki -Signed-off-by: Pavel Machek ---- - Documentation/devicetree/bindings/leds/leds-bcm63138.yaml | 2 +- - 1 file changed, 1 insertion(+), 1 deletion(-) - ---- a/Documentation/devicetree/bindings/leds/leds-bcm63138.yaml -+++ b/Documentation/devicetree/bindings/leds/leds-bcm63138.yaml -@@ -54,7 +54,7 @@ patternProperties: - - active-low: - type: boolean -- description: Makes LED active low. -+ description: Makes LED active low - - required: - - reg diff --git a/target/linux/generic/backport-5.15/801-v5.20-0002-leds-add-help-info-about-BCM63138-module-name.patch b/target/linux/generic/backport-5.15/801-v5.20-0002-leds-add-help-info-about-BCM63138-module-name.patch deleted file mode 100644 index 5430b1f084..0000000000 --- a/target/linux/generic/backport-5.15/801-v5.20-0002-leds-add-help-info-about-BCM63138-module-name.patch +++ /dev/null @@ -1,28 +0,0 @@ -From bcc607cdbb1f931111196699426f0cb83bfb296a Mon Sep 17 00:00:00 2001 -From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= -Date: Sun, 17 Jul 2022 14:42:47 +0200 -Subject: [PATCH] leds: add help info about BCM63138 module name -MIME-Version: 1.0 -Content-Type: text/plain; charset=UTF-8 -Content-Transfer-Encoding: 8bit - -It's what we do for all other LEDs drivers. - -Reported-by: Pavel Machek -Signed-off-by: Rafał Miłecki -Signed-off-by: Pavel Machek ---- - drivers/leds/blink/Kconfig | 2 ++ - 1 file changed, 2 insertions(+) - ---- a/drivers/leds/blink/Kconfig -+++ b/drivers/leds/blink/Kconfig -@@ -10,6 +10,8 @@ config LEDS_BCM63138 - BCM63138 SoC. The same hardware block is known to be also used - in BCM4908, BCM6848, BCM6858, BCM63148, BCM63381 and BCM68360. - -+ If compiled as module it will be called leds-bcm63138. -+ - config LEDS_LGM - tristate "LED support for LGM SoC series" - depends on X86 || COMPILE_TEST diff --git a/target/linux/generic/backport-5.15/801-v5.20-0003-leds-leds-bcm63138-get-rid-of-LED_OFF.patch b/target/linux/generic/backport-5.15/801-v5.20-0003-leds-leds-bcm63138-get-rid-of-LED_OFF.patch deleted file mode 100644 index e125a54613..0000000000 --- a/target/linux/generic/backport-5.15/801-v5.20-0003-leds-leds-bcm63138-get-rid-of-LED_OFF.patch +++ /dev/null @@ -1,30 +0,0 @@ -From 92cfc71ee2ddfb499ed53e21b28bdf8739bc70bc Mon Sep 17 00:00:00 2001 -From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= -Date: Sun, 17 Jul 2022 14:42:48 +0200 -Subject: [PATCH] leds: leds-bcm63138: get rid of LED_OFF -MIME-Version: 1.0 -Content-Type: text/plain; charset=UTF-8 -Content-Transfer-Encoding: 8bit - -The whole "enum led_brightness" is marked as obsolete. Replace it with a -(non-)zero check. - -Reported-by: Pavel Machek -Signed-off-by: Rafał Miłecki -Signed-off-by: Pavel Machek ---- - drivers/leds/blink/leds-bcm63138.c | 3 +-- - 1 file changed, 1 insertion(+), 2 deletions(-) - ---- a/drivers/leds/blink/leds-bcm63138.c -+++ b/drivers/leds/blink/leds-bcm63138.c -@@ -113,8 +113,7 @@ static void bcm63138_leds_enable_led(str - { - u32 bit = BIT(led->pin); - -- bcm63138_leds_update_bits(leds, BCM63138_SW_DATA, bit, -- value == LED_OFF ? 0 : bit); -+ bcm63138_leds_update_bits(leds, BCM63138_SW_DATA, bit, value ? bit : 0); - } - - /* diff --git a/target/linux/generic/backport-5.15/801-v6.0-0001-dt-bindings-leds-leds-bcm63138-unify-full-stops-in-d.patch b/target/linux/generic/backport-5.15/801-v6.0-0001-dt-bindings-leds-leds-bcm63138-unify-full-stops-in-d.patch new file mode 100644 index 0000000000..483826abed --- /dev/null +++ b/target/linux/generic/backport-5.15/801-v6.0-0001-dt-bindings-leds-leds-bcm63138-unify-full-stops-in-d.patch @@ -0,0 +1,30 @@ +From 13b64a0c19059b38150c79d65d350ae44034c5df Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= +Date: Sun, 17 Jul 2022 14:42:46 +0200 +Subject: [PATCH] dt-bindings: leds: leds-bcm63138: unify full stops in + descriptions +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +Description of "reg" doesn't have full stop at the end. It makes sense +as it's a one-sentence only. Use the same style for "active-low". + +Reported-by: Pavel Machek +Signed-off-by: Rafał Miłecki +Signed-off-by: Pavel Machek +--- + Documentation/devicetree/bindings/leds/leds-bcm63138.yaml | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +--- a/Documentation/devicetree/bindings/leds/leds-bcm63138.yaml ++++ b/Documentation/devicetree/bindings/leds/leds-bcm63138.yaml +@@ -54,7 +54,7 @@ patternProperties: + + active-low: + type: boolean +- description: Makes LED active low. ++ description: Makes LED active low + + required: + - reg diff --git a/target/linux/generic/backport-5.15/801-v6.0-0002-leds-add-help-info-about-BCM63138-module-name.patch b/target/linux/generic/backport-5.15/801-v6.0-0002-leds-add-help-info-about-BCM63138-module-name.patch new file mode 100644 index 0000000000..5430b1f084 --- /dev/null +++ b/target/linux/generic/backport-5.15/801-v6.0-0002-leds-add-help-info-about-BCM63138-module-name.patch @@ -0,0 +1,28 @@ +From bcc607cdbb1f931111196699426f0cb83bfb296a Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= +Date: Sun, 17 Jul 2022 14:42:47 +0200 +Subject: [PATCH] leds: add help info about BCM63138 module name +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +It's what we do for all other LEDs drivers. + +Reported-by: Pavel Machek +Signed-off-by: Rafał Miłecki +Signed-off-by: Pavel Machek +--- + drivers/leds/blink/Kconfig | 2 ++ + 1 file changed, 2 insertions(+) + +--- a/drivers/leds/blink/Kconfig ++++ b/drivers/leds/blink/Kconfig +@@ -10,6 +10,8 @@ config LEDS_BCM63138 + BCM63138 SoC. The same hardware block is known to be also used + in BCM4908, BCM6848, BCM6858, BCM63148, BCM63381 and BCM68360. + ++ If compiled as module it will be called leds-bcm63138. ++ + config LEDS_LGM + tristate "LED support for LGM SoC series" + depends on X86 || COMPILE_TEST diff --git a/target/linux/generic/backport-5.15/801-v6.0-0003-leds-leds-bcm63138-get-rid-of-LED_OFF.patch b/target/linux/generic/backport-5.15/801-v6.0-0003-leds-leds-bcm63138-get-rid-of-LED_OFF.patch new file mode 100644 index 0000000000..e125a54613 --- /dev/null +++ b/target/linux/generic/backport-5.15/801-v6.0-0003-leds-leds-bcm63138-get-rid-of-LED_OFF.patch @@ -0,0 +1,30 @@ +From 92cfc71ee2ddfb499ed53e21b28bdf8739bc70bc Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= +Date: Sun, 17 Jul 2022 14:42:48 +0200 +Subject: [PATCH] leds: leds-bcm63138: get rid of LED_OFF +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +The whole "enum led_brightness" is marked as obsolete. Replace it with a +(non-)zero check. + +Reported-by: Pavel Machek +Signed-off-by: Rafał Miłecki +Signed-off-by: Pavel Machek +--- + drivers/leds/blink/leds-bcm63138.c | 3 +-- + 1 file changed, 1 insertion(+), 2 deletions(-) + +--- a/drivers/leds/blink/leds-bcm63138.c ++++ b/drivers/leds/blink/leds-bcm63138.c +@@ -113,8 +113,7 @@ static void bcm63138_leds_enable_led(str + { + u32 bit = BIT(led->pin); + +- bcm63138_leds_update_bits(leds, BCM63138_SW_DATA, bit, +- value == LED_OFF ? 0 : bit); ++ bcm63138_leds_update_bits(leds, BCM63138_SW_DATA, bit, value ? bit : 0); + } + + /*