Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp3560633pxp; Tue, 8 Mar 2022 17:28:51 -0800 (PST) X-Google-Smtp-Source: ABdhPJzezU5OSvpU+7R6SSIQgW1PC9sTQ8nJmiv0mF27pogdsiMehOvRjj1FlJKHSzC3S48SHUpl X-Received: by 2002:a65:49cc:0:b0:372:a079:cb3a with SMTP id t12-20020a6549cc000000b00372a079cb3amr16127174pgs.222.1646789331550; Tue, 08 Mar 2022 17:28:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646789331; cv=none; d=google.com; s=arc-20160816; b=LsU4TWMkNg2n0RE5m07sj3BZWZN4f9hPqDSPQ6L+Q0dtDdjwDuRHdtgo/CShjgiBnw u21o3J4WBRBN5PDtSIooADUT2nGPL29VGgJ+y4qovYpgfSK0e7R//4576xDEh8Jj4fze kKT0/oy11Dc+spExZqxHlIkpjMSQ+IdKngTo1nNZlLzHFfGaDnXgzMYCpStPvVsFTQdZ sCBRVXFi6qyCht0eSGZ9jcGT3tppwRhjsUohKZg68H8weXCRIRbJQQo99Vr1Su6fUnxe hBDyj9qm/x+/Kt4JpVzR40VT/WTmVL7JT+yqWH9DQSXDNANfKgDxEcGzGsWgaoY/+kHW IvyQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=SRDguBSs1Y1J0kKrsj8H5WlSWoje+dTygZTrpaj2/6I=; b=ye2hj4V6yp5ankPhmBvvlD6A8stsSQIcliuJ+/7hmtg/DU+kwny92flRGwX9zmE7xu 9w4lHKNY0kmeYtRLM2wnu+pvdmR2TxscKgnX1VpUZLTBSMHbwzdbrGm+lM9YMVc7FDuz WLaFErVyfiZanUXzHrGkoToyD8QSA93EbSUWxEqM/Zm+quJ0kBTlCZZq3uwPDOKYCH/L 9DNxkDdF3fneoQlJAjy07bKCBDIBy24oK40805WdrPxJulzVHj0LGI7JP2WlIkk44H+Y vgc2K+ECreftkLTdCR95SC+9qboURNwT7l1GKIIt3Y9+JlXFGEly7RDvHaPcZTUB8eyQ glzA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass (test mode) header.i=@axis.com header.s=axis-central1 header.b=i32gAMvT; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=axis.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id k8-20020a654348000000b00374a1995f0csi454936pgq.259.2022.03.08.17.28.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Mar 2022 17:28:51 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass (test mode) header.i=@axis.com header.s=axis-central1 header.b=i32gAMvT; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=axis.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 76AB11A7DB1; Tue, 8 Mar 2022 16:17:59 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243083AbiCGORR (ORCPT + 99 others); Mon, 7 Mar 2022 09:17:17 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39826 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243079AbiCGORL (ORCPT ); Mon, 7 Mar 2022 09:17:11 -0500 Received: from smtp1.axis.com (smtp1.axis.com [195.60.68.17]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A59248EB49; Mon, 7 Mar 2022 06:16:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=axis.com; q=dns/txt; s=axis-central1; t=1646662575; x=1678198575; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=SRDguBSs1Y1J0kKrsj8H5WlSWoje+dTygZTrpaj2/6I=; b=i32gAMvTl9+mAXdmrBFhKxJm1ko6Jg7ib2miDSbELkXCDYjw1N0mwhfA uG6Ju8tP7/toOzQFb90rfTe7Azp+V0AB4+oZ71PWrYFZ7fqNuSu8dtw2w SIE7CbgEJFZrXZcEsZbdRHovfkqPUhglOaGY1z3NBh2x1mck8r/lIuXmZ imQX9Joy3bKKjlLAjXg+oZiRMzHUOeThFpHpaspqLKk1MztlGJ/MyO8wN KHZ1kbMWlS2ZGgeK6pbQEm2Smo6Fp/DGZblvPpazN72vxDLQY3LukYveU w3uqYQeOr7Rn+4ubw+FAEzbaMqBvDWoOW2a1I/+7i9MHBJnfh4Nd6UPKS g==; From: Vincent Whitchurch To: , , , CC: , , , , , , , Vincent Whitchurch Subject: [PATCH 3/4] mtd: phram: Allow probing via reserved-memory Date: Mon, 7 Mar 2022 15:15:48 +0100 Message-ID: <20220307141549.2732179-4-vincent.whitchurch@axis.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220307141549.2732179-1-vincent.whitchurch@axis.com> References: <20220307141549.2732179-1-vincent.whitchurch@axis.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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: linux-kernel@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 --- 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..6dfe9401a3c5 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" }, -- 2.34.1