From patchwork Tue Apr 12 13:53:00 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vincent Whitchurch X-Patchwork-Id: 1616295 Return-Path: X-Original-To: incoming-dt@patchwork.ozlabs.org Delivered-To: patchwork-incoming-dt@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=axis.com header.i=@axis.com header.a=rsa-sha256 header.s=axis-central1 header.b=AsPkKyqR; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2620:137:e000::1:20; helo=out1.vger.email; envelope-from=devicetree-owner@vger.kernel.org; receiver=) Received: from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by bilbo.ozlabs.org (Postfix) with ESMTP id 4Kd6cq0VTGz9sCD for ; Tue, 12 Apr 2022 23:53:15 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1356373AbiDLNz3 (ORCPT ); Tue, 12 Apr 2022 09:55:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51300 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1356352AbiDLNzZ (ORCPT ); Tue, 12 Apr 2022 09:55:25 -0400 Received: from smtp2.axis.com (smtp2.axis.com [195.60.68.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7955757488; Tue, 12 Apr 2022 06:53:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=axis.com; q=dns/txt; s=axis-central1; t=1649771588; x=1681307588; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=jupemliQ8dJWnscgwhDk1djkO0V1yNDM+5JWRzk83NE=; b=AsPkKyqRtkZeyL7JAWRqNjITpIQwd2aRv3sIsgEO3000zpSp1w7RwlHG 9iaNT6vCNeCQdXD+dAmx3OKQbEGaag9JLgIMG3QITu4CDDSo8t+4MiUrt sv1UOvMIO7W+b+/BaG9G9Ji/uyncRR7ExGGmXLYCZkem/zHYpWLqyYdqF cMLDu36juukh721NzCbP/+J7U0AFr1oLzI8UUjoNqQ9ZVAJ/9Qe93ovld VVDqHlyZKvS/E7+NvXwJHB7NnUO9UGCn4WNiCect5HZmBrb4orkf3sWRq v/Wi1Ik27HultEwH27w2Sq7i68Jq11RFgt1Z0XWO8QGn8bM5Ea63DG5r7 A==; From: Vincent Whitchurch To: , , , CC: , Vincent Whitchurch , , , , , , Subject: [PATCH v3 2/4] dt-bindings: reserved-memory: Support MTD/block device Date: Tue, 12 Apr 2022 15:53:00 +0200 Message-ID: <20220412135302.1682890-3-vincent.whitchurch@axis.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220412135302.1682890-1-vincent.whitchurch@axis.com> References: <20220412135302.1682890-1-vincent.whitchurch@axis.com> MIME-Version: 1.0 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_PASS, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org Add bindings to allow MTD/block devices to be used in reserved-memory regions using the "phram" (MTD in PHysical RAM) driver. This allows things like partitioning to be specified via the existing devicetree bindings. Signed-off-by: Vincent Whitchurch Reviewed-by: Rob Herring --- Notes: v3: - Reword description. v2: - Add note on what "phram" means. - Use /schemas/mtd/mtd.yaml instead of relative pathUse /schemas/mtd/mtd.yaml instead of relative path. .../bindings/reserved-memory/phram.yaml | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 Documentation/devicetree/bindings/reserved-memory/phram.yaml diff --git a/Documentation/devicetree/bindings/reserved-memory/phram.yaml b/Documentation/devicetree/bindings/reserved-memory/phram.yaml new file mode 100644 index 000000000000..6c4db28015f1 --- /dev/null +++ b/Documentation/devicetree/bindings/reserved-memory/phram.yaml @@ -0,0 +1,47 @@ +# SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/reserved-memory/phram.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: MTD/block device in RAM + +description: | + Specifies that the reserved memory region can be used as an MTD or block + device. + + The "phram" node is named after the "MTD in PHysical RAM" driver which + provides an implementation of this functionality in Linux. + +maintainers: + - Vincent Whitchurch + +allOf: + - $ref: "reserved-memory.yaml" + - $ref: "/schemas/mtd/mtd.yaml" + +properties: + compatible: + const: phram + + reg: + description: region of memory that can be used as an MTD/block device + +required: + - compatible + - reg + +unevaluatedProperties: false + +examples: + - | + reserved-memory { + #address-cells = <1>; + #size-cells = <1>; + + phram: flash@12340000 { + compatible = "phram"; + label = "rootfs"; + reg = <0x12340000 0x00800000>; + }; + }; From patchwork Tue Apr 12 13:53:01 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vincent Whitchurch X-Patchwork-Id: 1616297 Return-Path: X-Original-To: incoming-dt@patchwork.ozlabs.org Delivered-To: patchwork-incoming-dt@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=axis.com header.i=@axis.com header.a=rsa-sha256 header.s=axis-central1 header.b=Jtmyrn3W; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2620:137:e000::1:20; helo=out1.vger.email; envelope-from=devicetree-owner@vger.kernel.org; receiver=) Received: from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by bilbo.ozlabs.org (Postfix) with ESMTP id 4Kd6cv2yn9z9sCD for ; Tue, 12 Apr 2022 23:53:19 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1351029AbiDLNzd (ORCPT ); Tue, 12 Apr 2022 09:55:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51378 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1356379AbiDLNz3 (ORCPT ); Tue, 12 Apr 2022 09:55:29 -0400 Received: from smtp2.axis.com (smtp2.axis.com [195.60.68.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AE210583AD; Tue, 12 Apr 2022 06:53:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=axis.com; q=dns/txt; s=axis-central1; t=1649771591; x=1681307591; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=1WivjijgLp2UzgX8W5CgQakX5pH8VwBd0BfhWfMFW+Q=; b=Jtmyrn3WpYYHaCmHkiJKBw95g3pm7SMH9cnuTCdT7W+z6FKJx1gvYQK/ 7KGe3IAR6sXrKWPQgt9GRfiJeU3DyMQiG2UZz8J8Gp50F3s8Pu88/I94G vU3z8b+4I8/1BAX+iWln6mVrvVm1880jV8FO3uE/R5AOMmUUz/GC776xc i3+cRQtpjFN9iGIKgXZmByiG4ylMUXwjfffXmFpkRJrnfqF8yvU1UHNH3 N6VNLoBYXqYYq67hyqB0DK2P3CLubWlEtvTE8UHcczQKZdAOgLQM+Ya3W Ht8ySXY4xB/MwYzgU98/bXdkxQ9eJ1M5upaeSn4EPVHS8V5o7KDrHZq56 A==; From: Vincent Whitchurch To: , , , CC: , Vincent Whitchurch , , , , , , Subject: [PATCH v3 3/4] mtd: phram: Allow probing via reserved-memory Date: Tue, 12 Apr 2022 15:53:01 +0200 Message-ID: <20220412135302.1682890-4-vincent.whitchurch@axis.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220412135302.1682890-1-vincent.whitchurch@axis.com> References: <20220412135302.1682890-1-vincent.whitchurch@axis.com> MIME-Version: 1.0 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_PASS, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org 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 Acked-by: Rob Herring --- 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 #include #include +#include +#include +#include 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=,,[,]\""); +#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" },