Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp5381321rwr; Mon, 24 Apr 2023 03:22:22 -0700 (PDT) X-Google-Smtp-Source: AKy350YCKDR0DZB7gAzealICgyRud5ljmRZfEGWQSgejEdNtZbRhRXVNS+88Q0OL7Ew7kfvrszUq X-Received: by 2002:a05:6a20:5485:b0:f3:ac88:c048 with SMTP id i5-20020a056a20548500b000f3ac88c048mr5859065pzk.7.1682331741806; Mon, 24 Apr 2023 03:22:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682331741; cv=none; d=google.com; s=arc-20160816; b=vroO3M4qHynrENp+oPlnKLQV/tjbXBfLiW79e3UMOQlZq9piPxHEtFILS2fWFbPhwc /jZdU3Wo++X9Ee+ZCDHNDryLIoHRLjZQF+swT/h0IebsqIAY0XbTMYYrz0yjXhM/NRVl y4+D+R+f6+5maTcznIwhp4c7RkmHGPviaGSRO7C1sPTDLMwIJWsvWNgVfEtHvBx9Ie+3 Q+ddpG1fSOkJIyXBnwAxH58S3fBOKkgT3CrcgtbYQ0Sg6G4wYoI4T38EA4qOdJ34mE2C jRrHmyUuBze6olL+RabMnv2qMWulscmKZhKlD8A4IVuBDAie76btoOBbCloJzVLjc4H1 CHRQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:to:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:from :dkim-signature; bh=26jP1z6kJxd8ER1tdQvbAbkoWyGDLjC4In1lvVJLLi0=; b=SAc8lrhoh5hAwxzZGiNzGMy/v0yLXFhjndolym2J5voHIf8j+Psyvn0ZnPhuv6tehB ylZTobKgkQdfYZI2ts6r7ToTNO6dVmvZTbdRTUPNanBHDsClAB/Hu8cQRrguG9QABZjF JQWLEd0mOGFdKgf4wRBWfzXCRtWjR0NJa6rkMalg+71FHnC13ji4vPGh8rwp6vCNjRUp c55IMWo2bINHPdpwb8/gLEDTG5atu1ZKNcOxt3YcJmAKGw3uTvi2cQ7C+a1soBVAWzcQ puW/phx+gYQa9LfD1ybE8MCKLyS5ZE6l2+btrFgqzmDnyv8JzbvRwPUAsfwZqxq5PWp9 NYLQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@maquefel.me header.s=mail header.b=sG8MZrtD; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l191-20020a633ec8000000b005133f7ca477si10816163pga.707.2023.04.24.03.22.10; Mon, 24 Apr 2023 03:22:21 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=fail header.i=@maquefel.me header.s=mail header.b=sG8MZrtD; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229625AbjDXKVX (ORCPT + 99 others); Mon, 24 Apr 2023 06:21:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44416 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231672AbjDXKUr (ORCPT ); Mon, 24 Apr 2023 06:20:47 -0400 Received: from forward501c.mail.yandex.net (forward501c.mail.yandex.net [178.154.239.209]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BB46E18C for ; Mon, 24 Apr 2023 03:20:45 -0700 (PDT) Received: from mail-nwsmtp-smtp-production-main-39.myt.yp-c.yandex.net (mail-nwsmtp-smtp-production-main-39.myt.yp-c.yandex.net [IPv6:2a02:6b8:c12:261e:0:640:2e3d:0]) by forward501c.mail.yandex.net (Yandex) with ESMTP id 8845C5EBF7; Mon, 24 Apr 2023 12:35:58 +0300 (MSK) Received: by mail-nwsmtp-smtp-production-main-39.myt.yp-c.yandex.net (smtp/Yandex) with ESMTPSA id JZBb1pbWwKo0-qs8Ysl2n; Mon, 24 Apr 2023 12:35:57 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=maquefel.me; s=mail; t=1682328957; bh=26jP1z6kJxd8ER1tdQvbAbkoWyGDLjC4In1lvVJLLi0=; h=Message-Id:Date:In-Reply-To:Cc:Subject:References:To:From; b=sG8MZrtDcSveu1AzqOtwAzYRoYdrobB5Ta8zWmDhb+TvBCgPhPXlAoI1ia0VWrbgP DKobaaCytaGR+RiMIBK+PWCikaBjg1Ckrh8ML7KhQbPBo6XIRK8od48iHIZlYjSjyB LEQj79fbsT2LZiyJz3r7ghpUMR22Eh97qB5XqjCQ= Authentication-Results: mail-nwsmtp-smtp-production-main-39.myt.yp-c.yandex.net; dkim=pass header.i=@maquefel.me From: Nikita Shubin Cc: Arnd Bergmann , Linus Walleij , Alexander Sverdlin , Miquel Raynal , Richard Weinberger , Vignesh Raghavendra , Arnd Bergmann , Neil Armstrong , Chuanhong Guo , Liang Yang , Jean Delvare , Florian Fainelli , linux-kernel@vger.kernel.org, linux-mtd@lists.infradead.org Subject: [PATCH 23/43] mtd: ts72xx_nand: add platform helper Date: Mon, 24 Apr 2023 15:34:39 +0300 Message-Id: <20230424123522.18302-24-nikita.shubin@maquefel.me> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230424123522.18302-1-nikita.shubin@maquefel.me> References: <20230424123522.18302-1-nikita.shubin@maquefel.me> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE, 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 To: unlisted-recipients:; (no To-header on input) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The only purpose of this code to provide platform_nand_data to gen_nand driver which requires .cmd_ctrl and .dev_ready. Signed-off-by: Nikita Shubin --- Notes: rfc->v0 Alexander Sverdlin: - platfrom -> platform Linus Walleij: - __raw_read/write[w|l] -> readb/writeb Arnd Bergmann: - name match node ts7250 instead of wildcard drivers/mtd/nand/raw/Kconfig | 8 +++ drivers/mtd/nand/raw/Makefile | 1 + drivers/mtd/nand/raw/ts72xx_nand.c | 94 ++++++++++++++++++++++++++++++ 3 files changed, 103 insertions(+) create mode 100644 drivers/mtd/nand/raw/ts72xx_nand.c diff --git a/drivers/mtd/nand/raw/Kconfig b/drivers/mtd/nand/raw/Kconfig index 170f1185ddc4..08f88c34ce53 100644 --- a/drivers/mtd/nand/raw/Kconfig +++ b/drivers/mtd/nand/raw/Kconfig @@ -456,6 +456,14 @@ config MTD_NAND_RENESAS Enables support for the NAND controller found on Renesas R-Car Gen3 and RZ/N1 SoC families. +config MTD_NAND_TS72XX + bool "ts72xx NAND controller" + depends on ARCH_EP93XX && HAS_IOMEM + select MTD_NAND_PLATFORM + help + Enables support for NAND controller on ts72xx SBCs. + These only set's platform data. The real driver is gen_nand. + comment "Misc" config MTD_SM_COMMON diff --git a/drivers/mtd/nand/raw/Makefile b/drivers/mtd/nand/raw/Makefile index 917cdfb815b9..b1d5cec84519 100644 --- a/drivers/mtd/nand/raw/Makefile +++ b/drivers/mtd/nand/raw/Makefile @@ -23,6 +23,7 @@ omap2_nand-objs := omap2.o obj-$(CONFIG_MTD_NAND_OMAP2) += omap2_nand.o obj-$(CONFIG_MTD_NAND_OMAP_BCH_BUILD) += omap_elm.o obj-$(CONFIG_MTD_NAND_MARVELL) += marvell_nand.o +obj-$(CONFIG_MTD_NAND_TS72XX) += ts72xx_nand.o obj-$(CONFIG_MTD_NAND_PLATFORM) += plat_nand.o obj-$(CONFIG_MTD_NAND_PASEMI) += pasemi_nand.o obj-$(CONFIG_MTD_NAND_ORION) += orion_nand.o diff --git a/drivers/mtd/nand/raw/ts72xx_nand.c b/drivers/mtd/nand/raw/ts72xx_nand.c new file mode 100644 index 000000000000..1c1c06c6e71a --- /dev/null +++ b/drivers/mtd/nand/raw/ts72xx_nand.c @@ -0,0 +1,94 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Technologic Systems TS72xx NAND driver platform code + * Copyright (C) 2021 Nikita Shubin + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define TS72XX_NAND_CONTROL_ADDR_LINE 22 /* 0xN0400000 */ +#define TS72XX_NAND_BUSY_ADDR_LINE 23 /* 0xN0800000 */ + +static void ts72xx_nand_hwcontrol(struct nand_chip *chip, + int cmd, unsigned int ctrl) +{ + if (ctrl & NAND_CTRL_CHANGE) { + void __iomem *addr = chip->legacy.IO_ADDR_R; + unsigned char bits; + + addr += (1 << TS72XX_NAND_CONTROL_ADDR_LINE); + + bits = readb(addr) & ~0x07; + bits |= (ctrl & NAND_NCE) << 2; /* bit 0 -> bit 2 */ + bits |= (ctrl & NAND_CLE); /* bit 1 -> bit 1 */ + bits |= (ctrl & NAND_ALE) >> 2; /* bit 2 -> bit 0 */ + + writeb(bits, addr); + } + + if (cmd != NAND_CMD_NONE) + writeb(cmd, chip->legacy.IO_ADDR_W); +} + +static int ts72xx_nand_device_ready(struct nand_chip *chip) +{ + void __iomem *addr = chip->legacy.IO_ADDR_R; + + addr += (1 << TS72XX_NAND_BUSY_ADDR_LINE); + + return !!(readb(addr) & 0x20); +} + +static struct platform_nand_data ts72xx_nand_data = { + .chip = { + .nr_chips = 1, + .chip_offset = 0, + .chip_delay = 15, + }, + .ctrl = { + .cmd_ctrl = ts72xx_nand_hwcontrol, + .dev_ready = ts72xx_nand_device_ready, + }, +}; + +static int __init ts72xx_nand_setup(void) +{ + struct device_node *np; + struct platform_device *pdev; + + /* Multiplatform guard, only proceed on ts7250 */ + if (!of_machine_is_compatible("technologic,ts7250")) + return 0; + + np = of_find_compatible_node(NULL, NULL, "technologic,ts7200-nand"); + if (!np) { + pr_err("%s : nand device tree node not found.\n", __func__); + return -EINVAL; + } + + pdev = of_find_device_by_node(np); + if (!pdev) { + pr_err("%s : nand device not found.\n", __func__); + return -EINVAL; + } + + pdev->dev.platform_data = &ts72xx_nand_data; + put_device(&pdev->dev); + of_node_put(np); + + return 0; +} + +subsys_initcall(ts72xx_nand_setup); -- 2.39.2