From patchwork Sat Apr 23 03:46:22 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jonathan Bakker X-Patchwork-Id: 12824408 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B8A0CC433EF for ; Sat, 23 Apr 2022 03:47:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232601AbiDWDuC (ORCPT ); Fri, 22 Apr 2022 23:50:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50836 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232574AbiDWDtr (ORCPT ); Fri, 22 Apr 2022 23:49:47 -0400 Received: from NAM04-BN8-obe.outbound.protection.outlook.com (mail-bn8nam08olkn2043.outbound.protection.outlook.com [40.92.47.43]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4381D13977A; Fri, 22 Apr 2022 20:46:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=SFmtbCaZIEnuiPmmNmwGITR1lZMLKCft3uUCaBWw2XVuXWJ0RYvWspUBRGSz2Se2DOW2sGnyYV4kHh3uXwxHIclEt9vnT9ND8hD2BVIR/aMwlObHYEAlyUdH3rmVDGBfVn/E/1DHLnTnmeu58/33D9ZVNBMkxN7AZDbhUFGPzdlGsHNTnUC314FFU/ZL9WjsXPvFQO1X4mmFrIvUW6FyFm0NorGm7dQR24EXOQnGy8Tw+izOHf6TgSOzEh3sLL2GSzfovbVziu7MG5mz6VcgD27llWcCRGSwcoVjsea3F9gen3OJQFjryb0jfczZIn+Gx3H1pTdcvH3XCWaWdAR+Tw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=gRz4KJxx36uXke3/M9dDj+fZyMzrPh775UfAXXXdqLs=; b=JEIpcY9r0MdREHPGbC45BblBA7dO4DCoBM8EZ4f7xZA5DB/98fqFSWgBR5d2JL7hxNcIdd5nM+sc8ScVFYtSsQAsSiaKBMETvUClbw7YoImx37Q3t7BeMYszHzRcL/yYdJKprv1h96af+tdyCsDFET5RwkAYGreFzBqSEHP8lWWmC+uIePojvIUNrCF0QaOrxOHYbd9GP3zGUgjyJgP3pZgFfV1mh7/dJWNZ84zn+GIz2bIf8y8RZ6R2JAj4qHc+pnA8YCYQXhhDZq6EawtyrhYRAGEQLiLjn7j91PqFhyzIxAq9Pe1+PW33qOXD0KHdS/hsrcausW58jX7gb3GDtA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none Received: from CY4PR04MB0567.namprd04.prod.outlook.com (2603:10b6:903:b1::20) by SN6PR04MB4205.namprd04.prod.outlook.com (2603:10b6:805:30::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5144.29; Sat, 23 Apr 2022 03:46:48 +0000 Received: from CY4PR04MB0567.namprd04.prod.outlook.com ([fe80::8e:6e22:f98c:29d5]) by CY4PR04MB0567.namprd04.prod.outlook.com ([fe80::8e:6e22:f98c:29d5%5]) with mapi id 15.20.5186.015; Sat, 23 Apr 2022 03:46:48 +0000 From: Jonathan Bakker To: Miquel Raynal Cc: Kyungmin Park , Richard Weinberger , Vignesh Raghavendra , linux-mtd@lists.infradead.org, linux-kernel@vger.kernel.org, linux-samsung-soc@vger.kernel.org, Tomasz Figa , =?utf-8?q?Pawe=C5=82_Chmiel?= , Jonathan Bakker Subject: [PATCH 5/5] mtd: onenand: samsung: Add device tree support Date: Fri, 22 Apr 2022 20:46:22 -0700 Message-ID: X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220423034622.366696-1-xc-racer2@live.ca> References: <20220423034524.366612-1-xc-racer2@live.ca> <20220423034622.366696-1-xc-racer2@live.ca> X-TMN: [lSK7iLLjEA4qxR34T9AkrmY8T4I/xv1/GtDCGGhtOGPCqTn2DHcGevU28dsWUlY+] X-ClientProxiedBy: MW4PR04CA0210.namprd04.prod.outlook.com (2603:10b6:303:86::35) To CY4PR04MB0567.namprd04.prod.outlook.com (2603:10b6:903:b1::20) X-Microsoft-Original-Message-ID: <20220423034622.366696-4-xc-racer2@live.ca> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 2aa12229-2cfd-4497-1fbd-08da24dbe4f9 X-MS-TrafficTypeDiagnostic: SN6PR04MB4205:EE_ X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: vSjq2cDEbz9929l0WJ5DX2V8SSHhDexGbbVKKH8u9EMklwUiL3xKzXvMeaD5OOXRsG1Ry/cCH1amM/NERgDITpBjiTEioZ9rNh+2+1kVdlyqHmxv9RAFM6Ur0nhUvOsiQ3laqzo2G2PSNrmMM3hzB3nvtMqdqXiL17zIWJPYv8MZVmQSSPLSffLAtlXdupSR2jBiYI4hH9c66wIUE7bGfxo4U0iElFvdPp9j4yCn15i7SeyaDjFcWni7cKE7X48QuzVr814gIwQgvdLvJDORRwRMeIZD1H3OFFgxM3EQ2fYhi2g1+rCEEtclyo7FhQuasg3KzYDzozSrNGiAAHDXN1az1G8zP9xfGWgOyrOvBTvY1+OC3dSG9x9fdU9gj0zZlBaueFY/14or6XztAmibdsTLIpNgxNVOMXuaN31kzXQi4taybi0cEzGHN053IZdNel2Ee+AN0K4CSa1dSxe52H7t30rfynG+t4CvVeRZ1sliemW4MKnF/0qgBHron4+oEsKqOFOL/mOl0Z56+bAYqu1p8h9b6wLsqAO4oywRMUfXrwGRC/Hc9UEJkpHu4i+EW3EzwMNZXN+gbWjma+XsJg== X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?VzKSmEYcFd2DVwYo4P0LViFOUa11?= =?utf-8?q?L6yLU6bsRtrLEiy3BBS5yJmsGoEp5XOXOMnV9eGBM0EfGVZYyIQ2YTaxag+wr022z?= =?utf-8?q?3pNXJlO8/c7SNBx6c6S/DpDFWHmHG47B584+Y1fp3pqSyNyItnPGMkJovHq9VYLOz?= =?utf-8?q?77AYkojLg1B48In1bVFYjdZBAsC+TUSDYqSjiRjB2MHIYyZB267jrs84q41U59ELX?= =?utf-8?q?n4mrPTKKrXEyZjx+2GCE0qEio1lntlIeYxfRfnBu88E619dtB+/GlCg693TzMmCkT?= =?utf-8?q?sWJChBkENoB0s9O1CXamH+FCtTxxIltMKT8IZoV6QH95VOs0ZvR8gUEmshFy5xzRp?= =?utf-8?q?ErsCv+woMJ5i1FSbfkCnrU8+3zUpJWxdhH8KafzZ0ZoU1h3h2xxLh4UG/71uyNkr5?= =?utf-8?q?m393SwY0fyN+VbIKXp4GG73h4slCfz6uXGACZ1JZwoH6ESBW331p/h769WlTghrjN?= =?utf-8?q?mlSCM5osdUq5uciumiPujtNKrhF/FxqWw1p26+22Okrl3fpyiJX+KCfFFYyrCZKh7?= =?utf-8?q?u9EViOJDubh+9KEZbZ1L4Mn9c5B+pLcqYXOLgggZSrP+jDRk/zQDZdqdWzRt3IHLa?= =?utf-8?q?73rmLOtc5lYaVNaY+SXQR8IQS8NaybNhoiUReviUSqbIPbsYv4/9Le2Oz3KkfVVfa?= =?utf-8?q?NYheVkjeUv0VnycIORZsBqLLaFffg6pQzeCQtFf89tRLmE0VbgUFsWehnmhsj9XIt?= =?utf-8?q?2nWZcANm+Le68lwLzwDwIWZhlyTuEvP8tHoHXO5NjhONp2qH0eL61J2TSosEERS8m?= =?utf-8?q?7cKs8FepGZWKzbxKF33Es/rBt+QnnC7zOhYO3SJUo84pINcukKEyft7as2zWFRxdQ?= =?utf-8?q?sl8JrNTMuODESiV/lI7oPhzUUBIGTyS1rBoG58V6Nv5aK2sJ8wOM4PxXftZeq8bmH?= =?utf-8?q?KFEYBFlS3hTRtWk7/ibS9aScpltOT2DPfYN8Q8CEsbph7e4dWXKNcacIcQXff1S40?= =?utf-8?q?VxSZqiCrirgN0SxfWNSH1ueuvvE/JAUQxUFeilsgzT3wbYNPaT15Sqq7OUIblqhvy?= =?utf-8?q?SaZdQpJZsS2hcIQMahIzsalWGZfs7dI7TqZGi5StPjxRF/nQQ1Exp8m+oX1AvMPUx?= =?utf-8?q?OMH+azN2VnPBix+7N4LiwGmhB5zHmto5oHthSXI/L4Z5ZIWCHJ/ch4DFqGXFR7pTz?= =?utf-8?q?bDpZBHZfQMwUWajgubfwshjFYpqdr/oqdusLODGKVQRivuYa/TfONKQ2Ha3uJAf2N?= =?utf-8?q?o8aM+P7fH6NSXeEpj3mxUV1bn+PdV6lWgc/DWyI394pSRITOJFp21Y/WK9WyGWC8j?= =?utf-8?q?vkI/R8T4RVpRm1rAslq0pcSlFLLJ9uGftVi484j9UiR9LwCJBEXqX4eJcz483ZZe9?= =?utf-8?q?5zY7Vj9o3jshr76CGUJ5zBcxFHX1GxBhJPAbcErmvmQs4at6OGmoErX7/rXoeadeS?= =?utf-8?q?Y5n6JenehEuFVAxvuh1tG7Fk8OHqVjnUHKka+W+7hVeFRYHbKVgDF33tU=3D?= X-OriginatorOrg: sct-15-20-4755-11-msonline-outlook-edb50.templateTenant X-MS-Exchange-CrossTenant-Network-Message-Id: 2aa12229-2cfd-4497-1fbd-08da24dbe4f9 X-MS-Exchange-CrossTenant-AuthSource: CY4PR04MB0567.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Apr 2022 03:46:48.8065 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN6PR04MB4205 Precedence: bulk List-ID: X-Mailing-List: linux-samsung-soc@vger.kernel.org From: Tomasz Figa This patch adds support for instantation using Device Tree. Signed-off-by: Tomasz Figa Signed-off-by: Paweł Chmiel Signed-off-by: Jonathan Bakker --- Changes from previous patchset - Adjust to having a nand child node as per binding feedback --- drivers/mtd/nand/onenand/onenand_samsung.c | 67 +++++++++++++++++++++- 1 file changed, 65 insertions(+), 2 deletions(-) diff --git a/drivers/mtd/nand/onenand/onenand_samsung.c b/drivers/mtd/nand/onenand/onenand_samsung.c index 62014f8d27b6..0108c8c75d5b 100644 --- a/drivers/mtd/nand/onenand/onenand_samsung.c +++ b/drivers/mtd/nand/onenand/onenand_samsung.c @@ -22,6 +22,7 @@ #include #include #include +#include #include "samsung.h" @@ -832,8 +833,36 @@ static void s3c_onenand_setup(struct mtd_info *mtd) this->write_bufferram = onenand_write_bufferram; } +#ifdef CONFIG_OF +static const struct of_device_id s3c_onenand_of_match[] = { + { .compatible = "samsung,s3c6400-onenand", + .data = (void *)TYPE_S3C6400 }, + { .compatible = "samsung,s3c6410-onenand", + .data = (void *)TYPE_S3C6410 }, + { .compatible = "samsung,s5pv210-onenand", + .data = (void *)TYPE_S5PC110 }, + {}, +}; +MODULE_DEVICE_TABLE(of, onenand_s3c_dt_match); +#endif + +static enum soc_type s3c_onenand_get_device_id(struct platform_device *pdev) +{ + struct device_node *np = pdev->dev.of_node; + + if (IS_ENABLED(CONFIG_OF) && np) { + const struct of_device_id *match; + + match = of_match_node(s3c_onenand_of_match, np); + return (enum soc_type)match->data; + } + + return platform_get_device_id(pdev)->driver_data; +} + static int s3c_onenand_probe(struct platform_device *pdev) { + struct device_node *np = pdev->dev.of_node; struct onenand_platform_data *pdata; struct onenand_chip *this; struct mtd_info *mtd; @@ -856,9 +885,10 @@ static int s3c_onenand_probe(struct platform_device *pdev) this = (struct onenand_chip *) &mtd[1]; mtd->name = dev_name(&pdev->dev); mtd->priv = this; + mtd->dev.of_node = np; mtd->dev.parent = &pdev->dev; onenand->pdev = pdev; - onenand->type = platform_get_device_id(pdev)->driver_data; + onenand->type = s3c_onenand_get_device_id(pdev); s3c_onenand_setup(mtd); @@ -867,7 +897,35 @@ static int s3c_onenand_probe(struct platform_device *pdev) if (IS_ERR(onenand->ctrl_base)) return PTR_ERR(onenand->ctrl_base); - r = platform_get_resource(pdev, IORESOURCE_MEM, 1); + if (np) { + /* Determine which CS to use - this driver only supports one */ + u32 cs = 0; + struct device_node *child_np; + struct device_node *extra_chip_np; + + child_np = of_get_next_available_child(np, NULL); + if (child_np == NULL) { + dev_err(&pdev->dev, "failed to get chip node\n"); + return -EINVAL; + } + + /* Warn if more than one chip as this unsupported */ + extra_chip_np = of_get_next_available_child(np, child_np); + if (extra_chip_np != NULL) { + dev_warn(&pdev->dev, "multiple chip nodes, using only first\n"); + of_node_put(extra_chip_np); + } + + err = of_property_read_u32(child_np, "reg", &cs); + of_node_put(child_np); + if (err < 0) + return err; + + r = platform_get_resource(pdev, IORESOURCE_MEM, cs + 1); + } else { + r = platform_get_resource(pdev, IORESOURCE_MEM, 1); + } + onenand->chip_base = devm_ioremap_resource(&pdev->dev, r); if (IS_ERR(onenand->chip_base)) return PTR_ERR(onenand->chip_base); @@ -917,6 +975,10 @@ static int s3c_onenand_probe(struct platform_device *pdev) } onenand->clk_bus = devm_clk_get(&pdev->dev, "bus"); + if (np && IS_ERR(onenand->clk_bus)) { + dev_err(&pdev->dev, "failed to get bus clock\n"); + return PTR_ERR(onenand->clk_bus); + } if (!IS_ERR(onenand->clk_bus)) clk_prepare_enable(onenand->clk_bus); @@ -998,6 +1060,7 @@ static struct platform_driver s3c_onenand_driver = { .driver = { .name = "samsung-onenand", .pm = &s3c_pm_ops, + .of_match_table = of_match_ptr(s3c_onenand_of_match), }, .id_table = s3c_onenand_driver_ids, .probe = s3c_onenand_probe,