From: Vincent Whitchurch <vincent.whitchurch@axis.com> To: <vigneshr@ti.com>, <richard@nod.at>, <miquel.raynal@bootlin.com>, <joern@lazybastard.org> Cc: <kernel@axis.com>, Vincent Whitchurch <vincent.whitchurch@axis.com>, <linux-mtd@lists.infradead.org>, <devicetree@vger.kernel.org>, <robh+dt@kernel.org>, <krzk+dt@kernel.org>, <frowand.list@gmail.com>, <linux-kernel@vger.kernel.org> Subject: [PATCH v3 3/4] mtd: phram: Allow probing via reserved-memory Date: Tue, 12 Apr 2022 15:53:01 +0200 [thread overview] Message-ID: <20220412135302.1682890-4-vincent.whitchurch@axis.com> (raw) In-Reply-To: <20220412135302.1682890-1-vincent.whitchurch@axis.com> Allow phram to be probed from the devicetree. It expects to be in a reserved-memory node as documented by the bindings. This allows things like partitioning to be specified via the devicetree. Signed-off-by: Vincent Whitchurch <vincent.whitchurch@axis.com> --- Notes: v3: - Add missing semicolon after MODULE_DEVICE_TABLE causing build errors on some configs. drivers/mtd/devices/phram.c | 67 ++++++++++++++++++++++++++++++++++--- drivers/of/platform.c | 1 + 2 files changed, 64 insertions(+), 4 deletions(-) diff --git a/drivers/mtd/devices/phram.c b/drivers/mtd/devices/phram.c index d503821a3e60..506e9edf5c85 100644 --- a/drivers/mtd/devices/phram.c +++ b/drivers/mtd/devices/phram.c @@ -27,6 +27,9 @@ #include <linux/slab.h> #include <linux/mtd/mtd.h> #include <asm/div64.h> +#include <linux/platform_device.h> +#include <linux/of_address.h> +#include <linux/of.h> struct phram_mtd_list { struct mtd_info mtd; @@ -89,8 +92,10 @@ static void unregister_devices(void) } } -static int register_device(char *name, phys_addr_t start, size_t len, uint32_t erasesize) +static int register_device(struct platform_device *pdev, const char *name, + phys_addr_t start, size_t len, uint32_t erasesize) { + struct device_node *np = pdev ? pdev->dev.of_node : NULL; struct phram_mtd_list *new; int ret = -ENOMEM; @@ -119,13 +124,19 @@ static int register_device(char *name, phys_addr_t start, size_t len, uint32_t e new->mtd.erasesize = erasesize; new->mtd.writesize = 1; + mtd_set_of_node(&new->mtd, np); + ret = -EAGAIN; if (mtd_device_register(&new->mtd, NULL, 0)) { pr_err("Failed to register new device\n"); goto out2; } - list_add_tail(&new->list, &phram_list); + if (pdev) + platform_set_drvdata(pdev, new); + else + list_add_tail(&new->list, &phram_list); + return 0; out2: @@ -278,7 +289,7 @@ static int phram_setup(const char *val) goto error; } - ret = register_device(name, start, len, (uint32_t)erasesize); + ret = register_device(NULL, name, start, len, (uint32_t)erasesize); if (ret) goto error; @@ -325,10 +336,54 @@ static int phram_param_call(const char *val, const struct kernel_param *kp) module_param_call(phram, phram_param_call, NULL, NULL, 0200); MODULE_PARM_DESC(phram, "Memory region to map. \"phram=<name>,<start>,<length>[,<erasesize>]\""); +#ifdef CONFIG_OF +static const struct of_device_id phram_of_match[] = { + { .compatible = "phram" }, + {} +}; +MODULE_DEVICE_TABLE(of, phram_of_match); +#endif + +static int phram_probe(struct platform_device *pdev) +{ + struct resource *res; + + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); + if (!res) + return -ENOMEM; + + /* mtd_set_of_node() reads name from "label" */ + return register_device(pdev, NULL, res->start, resource_size(res), + PAGE_SIZE); +} + +static int phram_remove(struct platform_device *pdev) +{ + struct phram_mtd_list *phram = platform_get_drvdata(pdev); + + mtd_device_unregister(&phram->mtd); + iounmap(phram->mtd.priv); + kfree(phram); + + return 0; +} + +static struct platform_driver phram_driver = { + .probe = phram_probe, + .remove = phram_remove, + .driver = { + .name = "phram", + .of_match_table = of_match_ptr(phram_of_match), + }, +}; static int __init init_phram(void) { - int ret = 0; + int ret; + + ret = platform_driver_register(&phram_driver); + if (ret) + return ret; #ifndef MODULE if (phram_paramline[0]) @@ -336,12 +391,16 @@ static int __init init_phram(void) phram_init_called = 1; #endif + if (ret) + platform_driver_unregister(&phram_driver); + return ret; } static void __exit cleanup_phram(void) { unregister_devices(); + platform_driver_unregister(&phram_driver); } module_init(init_phram); diff --git a/drivers/of/platform.c b/drivers/of/platform.c index a16b74f32aa9..55d62b82c650 100644 --- a/drivers/of/platform.c +++ b/drivers/of/platform.c @@ -509,6 +509,7 @@ EXPORT_SYMBOL_GPL(of_platform_default_populate); #ifndef CONFIG_PPC static const struct of_device_id reserved_mem_matches[] = { + { .compatible = "phram" }, { .compatible = "qcom,rmtfs-mem" }, { .compatible = "qcom,cmd-db" }, { .compatible = "qcom,smem" }, -- 2.34.1
WARNING: multiple messages have this Message-ID (diff)
From: Vincent Whitchurch <vincent.whitchurch@axis.com> To: <vigneshr@ti.com>, <richard@nod.at>, <miquel.raynal@bootlin.com>, <joern@lazybastard.org> Cc: <kernel@axis.com>, Vincent Whitchurch <vincent.whitchurch@axis.com>, <linux-mtd@lists.infradead.org>, <devicetree@vger.kernel.org>, <robh+dt@kernel.org>, <krzk+dt@kernel.org>, <frowand.list@gmail.com>, <linux-kernel@vger.kernel.org> Subject: [PATCH v3 3/4] mtd: phram: Allow probing via reserved-memory Date: Tue, 12 Apr 2022 15:53:01 +0200 [thread overview] Message-ID: <20220412135302.1682890-4-vincent.whitchurch@axis.com> (raw) In-Reply-To: <20220412135302.1682890-1-vincent.whitchurch@axis.com> Allow phram to be probed from the devicetree. It expects to be in a reserved-memory node as documented by the bindings. This allows things like partitioning to be specified via the devicetree. Signed-off-by: Vincent Whitchurch <vincent.whitchurch@axis.com> --- Notes: v3: - Add missing semicolon after MODULE_DEVICE_TABLE causing build errors on some configs. drivers/mtd/devices/phram.c | 67 ++++++++++++++++++++++++++++++++++--- drivers/of/platform.c | 1 + 2 files changed, 64 insertions(+), 4 deletions(-) diff --git a/drivers/mtd/devices/phram.c b/drivers/mtd/devices/phram.c index d503821a3e60..506e9edf5c85 100644 --- a/drivers/mtd/devices/phram.c +++ b/drivers/mtd/devices/phram.c @@ -27,6 +27,9 @@ #include <linux/slab.h> #include <linux/mtd/mtd.h> #include <asm/div64.h> +#include <linux/platform_device.h> +#include <linux/of_address.h> +#include <linux/of.h> struct phram_mtd_list { struct mtd_info mtd; @@ -89,8 +92,10 @@ static void unregister_devices(void) } } -static int register_device(char *name, phys_addr_t start, size_t len, uint32_t erasesize) +static int register_device(struct platform_device *pdev, const char *name, + phys_addr_t start, size_t len, uint32_t erasesize) { + struct device_node *np = pdev ? pdev->dev.of_node : NULL; struct phram_mtd_list *new; int ret = -ENOMEM; @@ -119,13 +124,19 @@ static int register_device(char *name, phys_addr_t start, size_t len, uint32_t e new->mtd.erasesize = erasesize; new->mtd.writesize = 1; + mtd_set_of_node(&new->mtd, np); + ret = -EAGAIN; if (mtd_device_register(&new->mtd, NULL, 0)) { pr_err("Failed to register new device\n"); goto out2; } - list_add_tail(&new->list, &phram_list); + if (pdev) + platform_set_drvdata(pdev, new); + else + list_add_tail(&new->list, &phram_list); + return 0; out2: @@ -278,7 +289,7 @@ static int phram_setup(const char *val) goto error; } - ret = register_device(name, start, len, (uint32_t)erasesize); + ret = register_device(NULL, name, start, len, (uint32_t)erasesize); if (ret) goto error; @@ -325,10 +336,54 @@ static int phram_param_call(const char *val, const struct kernel_param *kp) module_param_call(phram, phram_param_call, NULL, NULL, 0200); MODULE_PARM_DESC(phram, "Memory region to map. \"phram=<name>,<start>,<length>[,<erasesize>]\""); +#ifdef CONFIG_OF +static const struct of_device_id phram_of_match[] = { + { .compatible = "phram" }, + {} +}; +MODULE_DEVICE_TABLE(of, phram_of_match); +#endif + +static int phram_probe(struct platform_device *pdev) +{ + struct resource *res; + + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); + if (!res) + return -ENOMEM; + + /* mtd_set_of_node() reads name from "label" */ + return register_device(pdev, NULL, res->start, resource_size(res), + PAGE_SIZE); +} + +static int phram_remove(struct platform_device *pdev) +{ + struct phram_mtd_list *phram = platform_get_drvdata(pdev); + + mtd_device_unregister(&phram->mtd); + iounmap(phram->mtd.priv); + kfree(phram); + + return 0; +} + +static struct platform_driver phram_driver = { + .probe = phram_probe, + .remove = phram_remove, + .driver = { + .name = "phram", + .of_match_table = of_match_ptr(phram_of_match), + }, +}; static int __init init_phram(void) { - int ret = 0; + int ret; + + ret = platform_driver_register(&phram_driver); + if (ret) + return ret; #ifndef MODULE if (phram_paramline[0]) @@ -336,12 +391,16 @@ static int __init init_phram(void) phram_init_called = 1; #endif + if (ret) + platform_driver_unregister(&phram_driver); + return ret; } static void __exit cleanup_phram(void) { unregister_devices(); + platform_driver_unregister(&phram_driver); } module_init(init_phram); diff --git a/drivers/of/platform.c b/drivers/of/platform.c index a16b74f32aa9..55d62b82c650 100644 --- a/drivers/of/platform.c +++ b/drivers/of/platform.c @@ -509,6 +509,7 @@ EXPORT_SYMBOL_GPL(of_platform_default_populate); #ifndef CONFIG_PPC static const struct of_device_id reserved_mem_matches[] = { + { .compatible = "phram" }, { .compatible = "qcom,rmtfs-mem" }, { .compatible = "qcom,cmd-db" }, { .compatible = "qcom,smem" }, -- 2.34.1 ______________________________________________________ Linux MTD discussion mailing list http://lists.infradead.org/mailman/listinfo/linux-mtd/
next prev parent reply other threads:[~2022-04-12 13:53 UTC|newest] Thread overview: 36+ messages / expand[flat|nested] mbox.gz Atom feed top 2022-04-12 13:52 [PATCH v3 0/4] mtd: phram improvements Vincent Whitchurch 2022-04-12 13:52 ` Vincent Whitchurch 2022-04-12 13:52 ` [PATCH v3 1/4] mtd: core: Check devicetree alias for index Vincent Whitchurch 2022-04-12 13:52 ` Vincent Whitchurch 2022-04-21 7:36 ` Miquel Raynal 2022-04-21 7:36 ` Miquel Raynal 2022-04-12 13:53 ` [PATCH v3 2/4] dt-bindings: reserved-memory: Support MTD/block device Vincent Whitchurch 2022-04-12 13:53 ` Vincent Whitchurch 2022-04-14 16:00 ` Rob Herring 2022-04-14 16:00 ` Rob Herring 2022-04-21 7:36 ` Miquel Raynal 2022-04-21 7:36 ` Miquel Raynal 2022-04-12 13:53 ` Vincent Whitchurch [this message] 2022-04-12 13:53 ` [PATCH v3 3/4] mtd: phram: Allow probing via reserved-memory Vincent Whitchurch 2022-04-14 16:02 ` Rob Herring 2022-04-14 16:02 ` Rob Herring 2022-04-21 7:36 ` Miquel Raynal 2022-04-21 7:36 ` Miquel Raynal 2022-04-12 13:53 ` [PATCH v3 4/4] mtd: phram: Allow cached mappings Vincent Whitchurch 2022-04-12 13:53 ` Vincent Whitchurch 2022-04-13 6:45 ` kernel test robot 2022-04-13 6:45 ` kernel test robot 2022-04-14 9:04 ` Vincent Whitchurch 2022-04-14 9:04 ` Vincent Whitchurch 2022-04-14 9:04 ` Vincent Whitchurch 2022-04-25 8:28 ` Miquel Raynal 2022-04-25 8:28 ` Miquel Raynal 2022-04-25 8:28 ` Miquel Raynal 2022-04-25 8:30 ` Miquel Raynal 2022-04-25 8:30 ` Miquel Raynal 2022-04-25 8:30 ` Miquel Raynal 2022-05-10 15:26 ` Vincent Whitchurch 2022-05-10 15:26 ` Vincent Whitchurch 2022-05-10 15:26 ` Vincent Whitchurch 2022-04-21 7:35 ` Miquel Raynal 2022-04-21 7:35 ` Miquel Raynal
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20220412135302.1682890-4-vincent.whitchurch@axis.com \ --to=vincent.whitchurch@axis.com \ --cc=devicetree@vger.kernel.org \ --cc=frowand.list@gmail.com \ --cc=joern@lazybastard.org \ --cc=kernel@axis.com \ --cc=krzk+dt@kernel.org \ --cc=linux-kernel@vger.kernel.org \ --cc=linux-mtd@lists.infradead.org \ --cc=miquel.raynal@bootlin.com \ --cc=richard@nod.at \ --cc=robh+dt@kernel.org \ --cc=vigneshr@ti.com \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.