Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp3504719pxb; Mon, 4 Apr 2022 19:07:07 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxbpr6aVnd5nmhdsY0LO9jhgckXuKfgXa8Hia5KzXMCphzX5wwgdgEC9Be6XaS3ZnCbHg2i X-Received: by 2002:a17:90b:1bc6:b0:1c7:69d:e80f with SMTP id oa6-20020a17090b1bc600b001c7069de80fmr1400106pjb.202.1649124427657; Mon, 04 Apr 2022 19:07:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649124427; cv=none; d=google.com; s=arc-20160816; b=Wni27R0rzUZlsfWT/lnmwnI9mRFwzhaAUoigP7fkmWL2esUanMyFf0xdwB541kBlGr 0amAIvpcwmZN4S43dwd2kTOsOQttqwaHD6JQ+SXCetJ8Ec4Bb45b3ol5tIaeTBsJ6/XF 2YwYJo4Sk3aqXMWz8/l6kLNPy3kAWK74M2qBxzxytb17gZM/IpXsDlA/GcXinBvYUDcr fpJfw9739Ly0ymlWdsTlXN6h7/9LoKDSbARsQ6zLVPDkLrbQvPv/syhV3QjVglD4GQ45 bFVQGPNLSlZkqjTleUumvFouqrKhlIlDE2eJoNaHRjxRk4E7Y017ojCixz929QbWAowY LLTg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id; bh=yIIjWW4VvepqGxz/RKxQE6rF5371GWJ4VuScgPS9hM0=; b=QUaldxVukASeyZthDg3Q+IqFjdMCIER8XTKkFcOlylDWBxDZFiKNZt+PwhkHRlkptK RgY4X91BoCWksYRGNApPkKb8QyMY7kh05yNrj7BBiHOC/RYbH7p0gRHAvZI8Z/J9EB3e +G713jz7EsK1cd32dx3YlN9confDmraWG/iKeRKtWG7IwGmAXarEyDV+t8t2c9TuJbhY rhFN+qJ+8ZzG5zGMlufhjS8jnpmexSe97rm+FVkwrA8esMdM7goNvesHFHWQqthgEXCT BcA6pGqcXDqh9Yoa4xAe3gKUYZlC+NLJh1x7cZSv/zXS9cx5JtJaJ/lJMrypLpymeCWt aTeg== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id i23-20020aa79097000000b004fa7bbaac00si10888165pfa.238.2022.04.04.19.07.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Apr 2022 19:07:07 -0700 (PDT) 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; 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 Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 10B472335F4; Mon, 4 Apr 2022 17:30:15 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377657AbiDDH0k (ORCPT + 99 others); Mon, 4 Apr 2022 03:26:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54658 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238908AbiDDH0i (ORCPT ); Mon, 4 Apr 2022 03:26:38 -0400 Received: from 9.mo552.mail-out.ovh.net (9.mo552.mail-out.ovh.net [87.98.180.222]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 67D033616C for ; Mon, 4 Apr 2022 00:24:40 -0700 (PDT) Received: from mxplan5.mail.ovh.net (unknown [10.108.1.93]) by mo552.mail-out.ovh.net (Postfix) with ESMTPS id 74BD722AA4; Mon, 4 Apr 2022 07:07:09 +0000 (UTC) Received: from kaod.org (37.59.142.102) by DAG4EX1.mxp5.local (172.16.2.31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Mon, 4 Apr 2022 09:07:08 +0200 Authentication-Results: garm.ovh; auth=pass (GARM-102R0043f1c04d9-24e1-4a64-8174-b0226c23ff7b, 193BEDB8EED17CFBFC1316EE01F9191BF107EB6B) smtp.auth=clg@kaod.org X-OVh-ClientIp: 82.64.250.170 Message-ID: <3b7ecaa4-1de9-3a4c-b057-805a5e6d2e48@kaod.org> Date: Mon, 4 Apr 2022 09:06:51 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.7.0 Subject: Re: [PATCH v4 03/11] spi: spi-mem: Convert Aspeed SMC driver to spi-mem Content-Language: en-US To: Pratyush Yadav CC: , , Mark Brown , Tudor Ambarus , Miquel Raynal , Richard Weinberger , Vignesh Raghavendra , , Joel Stanley , Andrew Jeffery , Chin-Ting Kuo , , Rob Herring , , , Tao Ren References: <20220325100849.2019209-1-clg@kaod.org> <20220325100849.2019209-4-clg@kaod.org> <20220330193343.qg5kcr6twerde6ho@ti.com> From: =?UTF-8?Q?C=c3=a9dric_Le_Goater?= In-Reply-To: <20220330193343.qg5kcr6twerde6ho@ti.com> Content-Type: text/plain; charset="UTF-8"; format=flowed Content-Transfer-Encoding: 8bit X-Originating-IP: [37.59.142.102] X-ClientProxiedBy: DAG4EX2.mxp5.local (172.16.2.32) To DAG4EX1.mxp5.local (172.16.2.31) X-Ovh-Tracer-GUID: e382a813-ab73-414e-b3c8-ba9556f6581c X-Ovh-Tracer-Id: 11032974666386082631 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: -100 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedvvddrudejuddguddujecutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfqggfjpdevjffgvefmvefgnecuuegrihhlohhuthemucehtddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjughrpefkffggfgfuvfhfhfgjtgfgihesthekredttdefjeenucfhrhhomhepveorughrihgtpgfnvggpifhorghtvghruceotghlgheskhgrohgurdhorhhgqeenucggtffrrghtthgvrhhnpeekleejfeevjeehiefhgeelgeeludduleeuvdffteduieegvdfgteevfeetkeetfeenucffohhmrghinhepsghufhdrihhnnecukfhppedtrddtrddtrddtpdefjedrheelrddugedvrddutddvnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmohguvgepshhmthhpohhuthdphhgvlhhopehmgihplhgrnhehrdhmrghilhdrohhvhhdrnhgvthdpihhnvghtpedtrddtrddtrddtpdhmrghilhhfrhhomheptghlgheskhgrohgurdhorhhgpdhnsggprhgtphhtthhopedupdhrtghpthhtoheprhgvnhhtrghordgsuhhpthesghhmrghilhdrtghomh X-Spam-Status: No, score=-2.5 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,NICE_REPLY_A, RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable 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 On 3/30/22 21:33, Pratyush Yadav wrote: > Hi Cedric, > > Thanks for doing the conversion. > > On 25/03/22 11:08AM, Cédric Le Goater wrote: >> This SPI driver adds support for the Aspeed static memory controllers >> of the AST2600, AST2500 and AST2400 SoCs using the spi-mem interface. >> >> * AST2600 Firmware SPI Memory Controller (FMC) >> . BMC firmware >> . 3 chip select pins (CE0 ~ CE2) >> . Only supports SPI type flash memory >> . different segment register interface >> . single, dual and quad mode. >> >> * AST2600 SPI Flash Controller (SPI1 and SPI2) >> . host firmware >> . 2 chip select pins (CE0 ~ CE1) >> . different segment register interface >> . single, dual and quad mode. >> >> * AST2500 Firmware SPI Memory Controller (FMC) >> . BMC firmware >> . 3 chip select pins (CE0 ~ CE2) >> . supports SPI type flash memory (CE0-CE1) >> . CE2 can be of NOR type flash but this is not supported by the driver >> . single, dual mode. >> >> * AST2500 SPI Flash Controller (SPI1 and SPI2) >> . host firmware >> . 2 chip select pins (CE0 ~ CE1) >> . single, dual mode. >> >> * AST2400 New Static Memory Controller (also referred as FMC) >> . BMC firmware >> . New register set >> . 5 chip select pins (CE0 ∼ CE4) >> . supports NOR flash, NAND flash and SPI flash memory. >> . single, dual and quad mode. >> >> Each controller has a memory range on which flash devices contents are >> mapped. Each device is assigned a window that can be changed at bootime >> with the Segment Address Registers. >> >> Each SPI flash device can then be accessed in two modes: Command and >> User. When in User mode, SPI transfers are initiated with accesses to >> the memory segment of a device. When in Command mode, memory >> operations on the memory segment of a device generate SPI commands >> automatically using a Control Register for the settings. >> >> This initial patch adds support for User mode. Command mode needs a little >> more work to check that the memory window on the AHB bus fits the device >> size. It will come later when support for direct mapping is added. >> >> Single and dual mode RX transfers are supported. Other types than SPI >> are not supported. >> >> Reviewed-by: Joel Stanley >> Tested-by: Joel Stanley >> Tested-by: Tao Ren >> Signed-off-by: Chin-Ting Kuo >> Signed-off-by: Cédric Le Goater >> --- >> drivers/mtd/spi-nor/controllers/aspeed-smc.c | 910 ------------------ >> drivers/spi/spi-aspeed-smc.c | 709 ++++++++++++++ >> .../devicetree/bindings/mtd/aspeed-smc.txt | 51 - >> MAINTAINERS | 1 + >> drivers/mtd/spi-nor/controllers/Kconfig | 10 - >> drivers/mtd/spi-nor/controllers/Makefile | 1 - >> drivers/spi/Kconfig | 11 + >> drivers/spi/Makefile | 1 + >> 8 files changed, 722 insertions(+), 972 deletions(-) >> delete mode 100644 drivers/mtd/spi-nor/controllers/aspeed-smc.c >> create mode 100644 drivers/spi/spi-aspeed-smc.c >> delete mode 100644 Documentation/devicetree/bindings/mtd/aspeed-smc.txt >> > [...] >> +static void aspeed_spi_send_cmd_addr(struct aspeed_spi_chip *chip, u8 addr_nbytes, >> + u64 offset, u32 opcode) >> +{ >> + struct aspeed_spi *aspi = chip->aspi; >> + __be32 temp; >> + u32 cmdaddr; >> + >> + switch (addr_nbytes) { >> + default: >> + dev_warn_once(aspi->dev, "Unexpected address width %u, defaulting to 3", >> + addr_nbytes); >> + fallthrough; > > I think it is better if you reject ops where addr width is not 3 or 4. > This you can drop this. Or if you really want to keep it, you can change > it to a WARN_ON() and return an error. OK. This is a left over from the initial driver. I have added both at WARN_ONCE() and a 'return -EOPNOTSUPP' >> + case 3: >> + cmdaddr = offset & 0xFFFFFF; >> + cmdaddr |= opcode << 24; >> + >> + temp = cpu_to_be32(cmdaddr); >> + aspeed_spi_write_to_ahb(chip->ahb_base, &temp, 4); >> + break; >> + case 4: >> + temp = cpu_to_be32(offset); >> + aspeed_spi_write_to_ahb(chip->ahb_base, &opcode, 1); >> + aspeed_spi_write_to_ahb(chip->ahb_base, &temp, 4); >> + break; >> + } >> +} >> + > [...] >> +/* support for 1-1-1, 1-1-2 or 1-1-4 */ >> +static bool aspeed_spi_supports_op(struct spi_mem *mem, const struct spi_mem_op *op) >> +{ >> + if (op->cmd.buswidth > 1) >> + return false; >> + >> + if (op->addr.nbytes != 0) { >> + if (op->addr.buswidth > 1 || op->addr.nbytes > 4) > > As mentioned above, this should reject ops with addr width 1 and 2. yes >> + return false; >> + } >> + >> + if (op->dummy.nbytes != 0) { >> + if (op->dummy.buswidth > 1 || op->dummy.nbytes > 7) >> + return false; >> + } >> + >> + if (op->data.nbytes != 0 && op->data.buswidth > 4) >> + return false; >> + >> + return spi_mem_default_supports_op(mem, op); >> +} >> + >> +static int do_aspeed_spi_exec_op(struct spi_mem *mem, const struct spi_mem_op *op) >> +{ >> + struct aspeed_spi *aspi = spi_controller_get_devdata(mem->spi->master); >> + struct aspeed_spi_chip *chip = &aspi->chips[mem->spi->chip_select]; >> + u32 addr_mode, addr_mode_backup; >> + u32 ctl_val; >> + int ret = 0; >> + >> + dev_dbg(aspi->dev, >> + "CE%d %s OP %#x mode:%d.%d.%d.%d naddr:%#x ndummies:%#x len:%#x", >> + chip->cs, op->data.dir == SPI_MEM_DATA_IN ? "read" : "write", >> + op->cmd.opcode, op->cmd.buswidth, op->addr.buswidth, >> + op->dummy.buswidth, op->data.buswidth, >> + op->addr.nbytes, op->dummy.nbytes, op->data.nbytes); >> + >> + addr_mode = readl(aspi->regs + CE_CTRL_REG); >> + addr_mode_backup = addr_mode; >> + >> + ctl_val = chip->ctl_val[ASPEED_SPI_BASE]; >> + ctl_val &= ~CTRL_IO_CMD_MASK; >> + >> + ctl_val |= op->cmd.opcode << CTRL_COMMAND_SHIFT; >> + >> + /* 4BYTE address mode */ >> + if (op->addr.nbytes) { >> + if (op->addr.nbytes == 4) >> + addr_mode |= (0x11 << chip->cs); >> + else >> + addr_mode &= ~(0x11 << chip->cs); >> + } >> + >> + if (op->dummy.buswidth && op->dummy.nbytes) > > Nitpick: op->dummy.nbytes being set should imply op->dummy.buswidth > 0. > >> + ctl_val |= CTRL_IO_DUMMY_SET(op->dummy.nbytes / op->dummy.buswidth); >> + >> + if (op->data.nbytes != 0) { >> + if (op->data.buswidth) > > Nitpick: op->data.nbytes != 0 should imply op->data.buswidth > 0. Indeed. Fixed both. >> + ctl_val |= aspeed_spi_get_io_mode(op); >> + } >> + >> + if (op->data.dir == SPI_MEM_DATA_OUT) >> + ctl_val |= CTRL_IO_MODE_WRITE; >> + else >> + ctl_val |= CTRL_IO_MODE_READ; >> + >> + if (addr_mode != addr_mode_backup) >> + writel(addr_mode, aspi->regs + CE_CTRL_REG); >> + writel(ctl_val, chip->ctl); >> + >> + if (op->data.dir == SPI_MEM_DATA_IN) { >> + if (!op->addr.nbytes) >> + ret = aspeed_spi_read_reg(chip, op); >> + else >> + ret = aspeed_spi_read_user(chip, op, op->addr.val, >> + op->data.nbytes, op->data.buf.in); >> + } else { >> + if (!op->addr.nbytes) >> + ret = aspeed_spi_write_reg(chip, op); >> + else >> + ret = aspeed_spi_write_user(chip, op); >> + } >> + >> + /* Restore defaults */ >> + if (addr_mode != addr_mode_backup) >> + writel(addr_mode_backup, aspi->regs + CE_CTRL_REG); >> + writel(chip->ctl_val[ASPEED_SPI_READ], chip->ctl); > > Why do you need to restore defaults here? Do you expect some other piece > of software to use it as well? We expect the controller to be correctly set when dirmap_read() is called. But it is only required in the next patch. > > The patch looks good to me apart from these. Thanks, C. > >> + return ret; >> +} >> + > [...] >