Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp365461rwd; Thu, 1 Jun 2023 01:02:58 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5lwGhx7W38q38bvScOl2JhupMhqLQXB1T583Om536Cu/zBJgEn3leuGzAhr6x0KiE99gXF X-Received: by 2002:a05:6358:89c:b0:122:2c33:9f40 with SMTP id m28-20020a056358089c00b001222c339f40mr5938486rwj.13.1685606578508; Thu, 01 Jun 2023 01:02:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685606578; cv=none; d=google.com; s=arc-20160816; b=dP6sCRN671McALlMFeBdLfUTqeBOqImRlNrtt89+JqFWGXl/aozZze/y4mMvX3mxEO Xi57DDpaSLjfEMXD/wZZqImc6Ogi/cu2kd1SERVWf7kY4ORkFK2N1cpPtwLANXjto/0E iUzSjVneqdmLdo/6Rdi45qxVxsvz6+FSy3Z6HwgUj8JAYst2ryiL1LpNeylFs6WdOUgT oc4U9HSjBZrL/YghM6gStsaSwKsYaZ0ganinu0sByFols0R8OLXaHz/eqW5i5Dl//jdP dwuNJtu5SeqV3lnwM4dke2qEH0uzdodMsIO5n6bIBQOLkNkj540ntlxgfPUlL6YywmX0 jgIg== 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 :organization:references:in-reply-to:message-id:subject:cc:to:from :date:dkim-signature; bh=p8zgnzutmlxoB/RLgH8MCBdqpFZrjqcSK1xpIkDue6o=; b=VI1j8+nDGwD6I6LJzgE342ePbFOaTQVq5ikeJDDmDxG08AYXWI//yI7zisYKH4v1ye wOtuMd9hjCXumbSklUXUy8iQ2esDnw5QgjEY65TAEIe8P+rHTW+qX9BVEBmiFOsgqQU4 AczT4kjzLVxtKjb0cg1rn5hFxfgyjQ5y/fZZ/rJnXaTkrmWRL/jClgLEdQ0FUphJOk87 Kya6ykmmr6QQ5Febx/59gIEPKTPfPM8jIVX6XZFLFO/m7lEX385vbW4zSdNi9g+KKCWl K2N2hPL3ltP8GZxQXDfHNqsstkSYAyYJ+xNtQQBirE6WCQRUCzvFjaoHDeJDC3K2MU9N 8bdA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=KbeWYcIk; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id p22-20020a17090b011600b002563e365aeasi750004pjz.53.2023.06.01.01.02.42; Thu, 01 Jun 2023 01:02:58 -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=pass header.i=@bootlin.com header.s=gm1 header.b=KbeWYcIk; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231721AbjFAH5D (ORCPT + 99 others); Thu, 1 Jun 2023 03:57:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52804 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232049AbjFAHzA (ORCPT ); Thu, 1 Jun 2023 03:55:00 -0400 Received: from relay2-d.mail.gandi.net (relay2-d.mail.gandi.net [IPv6:2001:4b98:dc4:8::222]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8A95B1A1 for ; Thu, 1 Jun 2023 00:49:15 -0700 (PDT) X-GND-Sasl: miquel.raynal@bootlin.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1685605753; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=p8zgnzutmlxoB/RLgH8MCBdqpFZrjqcSK1xpIkDue6o=; b=KbeWYcIkRJ1sK7c0UlhKZhnmQ8JZHE5MzAxAfkwMiJ6rsCuqfR7J2qpxuwAwjR4KNy1cKZ P4ThP/k9rpHM/5CbGzqogIzEexqvotx5PqMxuOCTOwwS2Y+C557Jba38pbWPXrfpFJ3D8j G2yY5ib1G9o12uuxy65gvPoQj6UoYnfmGQ+sIEAEfEpmMwbf4nQ1B8zDAop80MAndIhX3I dJQCmb3du9+OmxJPYPcBjWq7UnH2tlTtz++DKJm6pDwu2WBs0TFFixhen7v79PL2IOrMI3 bz8YCrdizsPVkEja2BkNpTUlNT7unWKk3fYPEAuDTjErhGjeREpdk4v9jU/FSA== X-GND-Sasl: miquel.raynal@bootlin.com X-GND-Sasl: miquel.raynal@bootlin.com X-GND-Sasl: miquel.raynal@bootlin.com X-GND-Sasl: miquel.raynal@bootlin.com X-GND-Sasl: miquel.raynal@bootlin.com X-GND-Sasl: miquel.raynal@bootlin.com X-GND-Sasl: miquel.raynal@bootlin.com X-GND-Sasl: miquel.raynal@bootlin.com X-GND-Sasl: miquel.raynal@bootlin.com X-GND-Sasl: miquel.raynal@bootlin.com X-GND-Sasl: miquel.raynal@bootlin.com X-GND-Sasl: miquel.raynal@bootlin.com X-GND-Sasl: miquel.raynal@bootlin.com X-GND-Sasl: miquel.raynal@bootlin.com X-GND-Sasl: miquel.raynal@bootlin.com Received: by mail.gandi.net (Postfix) with ESMTPSA id 1DBD640014; Thu, 1 Jun 2023 07:49:09 +0000 (UTC) Date: Thu, 1 Jun 2023 09:49:08 +0200 From: Miquel Raynal To: Nikita Shubin Cc: Alexander Sverdlin , Arnd Bergmann , Linus Walleij , Richard Weinberger , Vignesh Raghavendra , Jonathan Cameron , Stephen Boyd , Christophe Kerello , Jean Delvare , Liang Yang , Florian Fainelli , Michael Peters , Kris Bahnsen , linux-kernel@vger.kernel.org, linux-mtd@lists.infradead.org Subject: Re: [PATCH v1 24/43] mtd: nand: add support for ts72xx Message-ID: <20230601094908.7838ec17@xps-13> In-Reply-To: <20230601054549.10843-6-nikita.shubin@maquefel.me> References: <20230424123522.18302-1-nikita.shubin@maquefel.me> <20230601054549.10843-6-nikita.shubin@maquefel.me> Organization: Bootlin X-Mailer: Claws Mail 4.0.0 (GTK+ 3.24.33; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,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 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Nikita, nikita.shubin@maquefel.me wrote on Thu, 1 Jun 2023 08:45:29 +0300: > Technologic Systems has it's own nand controller implementation in CPLD. >=20 > This patch adds support for TS-72XX boards family. >=20 > Signed-off-by: Nikita Shubin > --- > drivers/mtd/nand/raw/Kconfig | 7 + > drivers/mtd/nand/raw/Makefile | 1 + > .../nand/raw/technologic-nand-controller.c | 151 ++++++++++++++++++ > 3 files changed, 159 insertions(+) > create mode 100644 drivers/mtd/nand/raw/technologic-nand-controller.c >=20 > diff --git a/drivers/mtd/nand/raw/Kconfig b/drivers/mtd/nand/raw/Kconfig > index b523354dfb00..94788da1a169 100644 > --- a/drivers/mtd/nand/raw/Kconfig > +++ b/drivers/mtd/nand/raw/Kconfig > @@ -456,6 +456,13 @@ config MTD_NAND_RENESAS > Enables support for the NAND controller found on Renesas R-Car > Gen3 and RZ/N1 SoC families. > =20 > +config MTD_NAND_TS72XX > + bool "ts72xx NAND controller" > + depends on ARCH_EP93XX && HAS_IOMEM > + help > + Enables support for NAND controller on ts72xx SBCs. > + This is a legacy driver based on gen_nand. > + > comment "Misc" > =20 > config MTD_SM_COMMON > diff --git a/drivers/mtd/nand/raw/Makefile b/drivers/mtd/nand/raw/Makefile > index 917cdfb815b9..783e990a0078 100644 > --- a/drivers/mtd/nand/raw/Makefile > +++ b/drivers/mtd/nand/raw/Makefile > @@ -23,6 +23,7 @@ omap2_nand-objs :=3D omap2.o > obj-$(CONFIG_MTD_NAND_OMAP2) +=3D omap2_nand.o > obj-$(CONFIG_MTD_NAND_OMAP_BCH_BUILD) +=3D omap_elm.o > obj-$(CONFIG_MTD_NAND_MARVELL) +=3D marvell_nand.o > +obj-$(CONFIG_MTD_NAND_TS72XX) +=3D technologic-nand-controller.o > obj-$(CONFIG_MTD_NAND_PLATFORM) +=3D plat_nand.o > obj-$(CONFIG_MTD_NAND_PASEMI) +=3D pasemi_nand.o > obj-$(CONFIG_MTD_NAND_ORION) +=3D orion_nand.o > diff --git a/drivers/mtd/nand/raw/technologic-nand-controller.c b/drivers= /mtd/nand/raw/technologic-nand-controller.c > new file mode 100644 > index 000000000000..09aeada933a1 > --- /dev/null > +++ b/drivers/mtd/nand/raw/technologic-nand-controller.c > @@ -0,0 +1,151 @@ > +// SPDX-License-Identifier: GPL-2.0 > +/* > + * Technologic Systems TS72xx NAND controller driver > + * > + * Copyright (C) 2023 Nikita Shubin > + * > + * derived: plat_nand.c > + * Author: Vitaly Wool > + */ > + > +#include > +#include > +#include > +#include > +#include > +#include > +#include > + > +#define TS72XX_NAND_CONTROL_ADDR_LINE 22 /* 0xN0400000 */ > +#define TS72XX_NAND_BUSY_ADDR_LINE 23 /* 0xN0800000 */ > + > +struct ts72xx_nand_data { > + struct nand_controller controller; > + struct nand_chip chip; > + void __iomem *io_base; > +}; > + > +static int ts72xx_nand_attach_chip(struct nand_chip *chip) > +{ > + if (chip->ecc.engine_type =3D=3D NAND_ECC_ENGINE_TYPE_SOFT && > + chip->ecc.algo =3D=3D NAND_ECC_ALGO_UNKNOWN) > + chip->ecc.algo =3D NAND_ECC_ALGO_HAMMING; I believe engine_type =3D=3D ON_HOST should return an error. > + > + return 0; > +} > + > +static const struct nand_controller_ops ts72xx_nand_ops =3D { > + .attach_chip =3D ts72xx_nand_attach_chip, > +}; > + > +static void ts72xx_nand_hwcontrol(struct nand_chip *chip, > + int cmd, unsigned int ctrl) > +{ > + if (ctrl & NAND_CTRL_CHANGE) { > + void __iomem *addr =3D chip->legacy.IO_ADDR_R; > + unsigned char bits; > + > + addr +=3D (1 << TS72XX_NAND_CONTROL_ADDR_LINE); > + > + bits =3D readb(addr) & ~0x07; > + bits |=3D (ctrl & NAND_NCE) << 2; /* bit 0 -> bit 2 */ > + bits |=3D (ctrl & NAND_CLE); /* bit 1 -> bit 1 */ > + bits |=3D (ctrl & NAND_ALE) >> 2; /* bit 2 -> bit 0 */ > + > + writeb(bits, addr); > + } > + > + if (cmd !=3D NAND_CMD_NONE) > + writeb(cmd, chip->legacy.IO_ADDR_W); > +} > + > +static int ts72xx_nand_device_ready(struct nand_chip *chip) > +{ > + void __iomem *addr =3D chip->legacy.IO_ADDR_R; > + > + addr +=3D (1 << TS72XX_NAND_BUSY_ADDR_LINE); > + > + return !!(readb(addr) & 0x20); > +} > + > +static int ts72xx_nand_probe(struct platform_device *pdev) > +{ > + struct ts72xx_nand_data *data; > + struct mtd_info *mtd; > + int err =3D 0; > + > + /* Allocate memory for the device structure (and zero it) */ > + data =3D devm_kzalloc(&pdev->dev, sizeof(struct ts72xx_nand_data), > + GFP_KERNEL); > + if (!data) > + return -ENOMEM; > + > + data->controller.ops =3D &ts72xx_nand_ops; > + nand_controller_init(&data->controller); > + data->chip.controller =3D &data->controller; > + > + data->io_base =3D devm_platform_ioremap_resource(pdev, 0); > + if (IS_ERR(data->io_base)) > + return PTR_ERR(data->io_base); > + > + nand_set_flash_node(&data->chip, pdev->dev.of_node); > + mtd =3D nand_to_mtd(&data->chip); > + mtd->dev.parent =3D &pdev->dev; > + > + data->chip.legacy.IO_ADDR_R =3D data->io_base; > + data->chip.legacy.IO_ADDR_W =3D data->io_base; > + data->chip.legacy.cmd_ctrl =3D ts72xx_nand_hwcontrol; > + data->chip.legacy.dev_ready =3D ts72xx_nand_device_ready; > + > + platform_set_drvdata(pdev, data); > + > + /* > + * This driver assumes that the default ECC engine should be TYPE_SOFT. > + * Set ->engine_type before registering the NAND devices in order to > + * provide a driver specific default value. > + */ > + data->chip.ecc.engine_type =3D NAND_ECC_ENGINE_TYPE_SOFT; > + > + /* Scan to find existence of the device */ > + err =3D nand_scan(&data->chip, 1); > + if (err) > + return err; > + > + err =3D mtd_device_parse_register(mtd, NULL, NULL, > + NULL, 0); The usual way -and more readable- is to jump to a goto label upon error, and return 0 in the normal path. > + > + if (!err) > + return err; > + > + nand_cleanup(&data->chip); > + > + return 0; > +} > + > +static void ts72xx_nand_remove(struct platform_device *pdev) > +{ > + struct ts72xx_nand_data *data =3D platform_get_drvdata(pdev); > + struct nand_chip *chip =3D &data->chip; > + int ret; > + > + ret =3D mtd_device_unregister(nand_to_mtd(chip)); > + WARN_ON(ret); > + nand_cleanup(chip); > +} > + > +static const struct of_device_id ts72xx_id_table[] =3D { > + { .compatible =3D "technologic,ts7200-nand" }, > + { /* sentinel */ } > +}; > +MODULE_DEVICE_TABLE(of, ts72xx_id_table); > + > +static struct platform_driver ts72xx_nand_driver =3D { > + .driver =3D { > + .name =3D "ts72xx-nand", > + .of_match_table =3D ts72xx_id_table, > + }, > + .probe =3D ts72xx_nand_probe, > + .remove_new =3D ts72xx_nand_remove, > +}; > +module_platform_driver(ts72xx_nand_driver); > + Thanks, Miqu=C3=A8l