Received: by 2002:a05:6a10:9afc:0:0:0:0 with SMTP id t28csp329165pxm; Wed, 2 Mar 2022 16:31:56 -0800 (PST) X-Google-Smtp-Source: ABdhPJx1qdb46bNU5CPd/WGAQAfYGIaPGQ9hJfFHxYA6166JnHS1wyETs0bJwb59UV5LzTHMC1A7 X-Received: by 2002:a63:3fc3:0:b0:373:d98:51b0 with SMTP id m186-20020a633fc3000000b003730d9851b0mr27944744pga.356.1646267516036; Wed, 02 Mar 2022 16:31:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646267516; cv=none; d=google.com; s=arc-20160816; b=MJSxblSuL7f6ZXkXCgqc/5o2wS+qroTuqm27w3eXP6AYNcRTQZrRyRIMZqGx9Au4zi frzNzlfBtuPLQa3CTFSlvnNoA2gN+R70eXap3lhvN23hb63TVWvsFUQJGQhTF6+Oz97h LeF33cc4TuDdcRiigzgDhu6mzTlbYEwduC5xeRtpe0KUOdyjkmpFw2HqFZRAmMweEbls 7UezCXZIpH3jUfBOD/a6aRZZxd1OMEWRiGD+Ln5wKA6lJFjOiUXgPoQ/O70V6eVlNEFW yMmlpPaHk+OgAkcs0ep/IUQS4gDqSEAXZI+iTC+skgTZssIOTKr6HdcMlQNl0CBZk7ff m4nQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=5wkcZfN4pZ3a3l+3rbDL3hrP2CqpjYo6641YbuD1Z7Y=; b=G83qQrStfiKsZzg7ryPoWthojG7Pqea8jgB8iN7m1Qd70yZjK0G32ZsvPrHugJDfYv FSjVkxEOaqH8/EwLe+GwmgkELAvNectlSqL6EpvPUaGBlm6lQDUQcok+JvpyWvFoxm2k zUyix5x2luDfA/+0qbO1Nd2ZsB3vbG5d4mIa31LTUvnj6PmyzFd5t+7rP1/LwJgyj9Lf jdwCiluFCJlgllJaNZaX6jVxZIIaaaXShV9AHZSMoq/nDMk9YcIYOT8ffNrRSA/RTiwu QsKnALcTbZ0E0mkvtbv5bazuAMIQlvZInDc/OImT5euwTTsO1qBd4WX04vDdu20dFqpg w2Hg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@jms.id.au header.s=google header.b=VL8GKslk; 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 q9-20020a170902dac900b0014ff9239f3asi658583plx.226.2022.03.02.16.31.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Mar 2022 16:31:56 -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 header.i=@jms.id.au header.s=google header.b=VL8GKslk; 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 DBE60230E4C; Wed, 2 Mar 2022 15:42:26 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229480AbiCBWdG (ORCPT + 99 others); Wed, 2 Mar 2022 17:33:06 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40130 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232086AbiCBWcy (ORCPT ); Wed, 2 Mar 2022 17:32:54 -0500 Received: from mail-qt1-x830.google.com (mail-qt1-x830.google.com [IPv6:2607:f8b0:4864:20::830]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CD0F1EA747; Wed, 2 Mar 2022 14:32:10 -0800 (PST) Received: by mail-qt1-x830.google.com with SMTP id f18so3077949qtb.3; Wed, 02 Mar 2022 14:32:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=jms.id.au; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=5wkcZfN4pZ3a3l+3rbDL3hrP2CqpjYo6641YbuD1Z7Y=; b=VL8GKslkQfyhvjQaT0mMN7BaIwmwFq6sacRCmQHljoQBA+THJ2vLpspjYcX9md1xBh 7Lx71zUGLAqELrHktKtYMZ6c5rddsL/B6uzoCbrYu+ZgogUpnaN090340zyTGohsd7uf 8kWEeBScAb+bXOLZWfG7EA2lSEpJzE2Vs4WjM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=5wkcZfN4pZ3a3l+3rbDL3hrP2CqpjYo6641YbuD1Z7Y=; b=M6bShvz7WAVy+Wz/K0puFguUKCUDV2rg0h0QzPfPPJtGISfduPtfanDhTMucPG7t+G zRyk/5/ZlkaFB/soVhJV3yiC/UAVWUfZaHPadwJYeBNbVpdr4bJ3q932oCZVGGtzN54l gop5qRJRoAAu0I3UzXYNcSD7p63FiFEFO7LZ2q113G59aawzS6l93IsFt5Ah6uIiTH77 1yG7v9G1ElKUMNzlGC0um4eG/ep8jh2x4fH/iBodadngq1UDi4RC1z7zHZYv3/RYIrUo 03b91iqakoJarxt0oXmwD/0VOtq8j7R8u7MWJp0jhqUdobpcRmKV+ZNI8Xv8CbF6u2pJ u8sA== X-Gm-Message-State: AOAM533j1W+rUDsTyKEvke6CUcjTcL3+Q6E8pI0HxB1Vc1EGVNdOEYRF o66LRfzRknOgxzyT1llfDczzaTxdyJ7byiWGvGw= X-Received: by 2002:ac8:5d89:0:b0:2df:f357:c681 with SMTP id d9-20020ac85d89000000b002dff357c681mr18831790qtx.475.1646260329845; Wed, 02 Mar 2022 14:32:09 -0800 (PST) MIME-Version: 1.0 References: <20220302173114.927476-1-clg@kaod.org> <20220302173114.927476-7-clg@kaod.org> In-Reply-To: <20220302173114.927476-7-clg@kaod.org> From: Joel Stanley Date: Wed, 2 Mar 2022 22:31:57 +0000 Message-ID: Subject: Re: [PATCH v2 06/10] spi: aspeed: Adjust direct mapping to device size To: =?UTF-8?Q?C=C3=A9dric_Le_Goater?= Cc: linux-spi@vger.kernel.org, linux-mtd , Mark Brown , Tudor Ambarus , Pratyush Yadav , Miquel Raynal , Richard Weinberger , Vignesh Raghavendra , linux-aspeed , Andrew Jeffery , Chin-Ting Kuo , devicetree , Rob Herring , Linux ARM , Linux Kernel Mailing List Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable 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 On Wed, 2 Mar 2022 at 17:31, C=C3=A9dric Le Goater wrote: > > The segment registers of the FMC/SPI controllers provide a way to > configure the mapping window of the flash device contents on the AHB > bus. Adjust this window to the size of the spi-mem mapping. > > Things get more complex with multiple devices. The driver needs to > also adjust the window of the next device to make sure that there is > no overlap, even if there is no available device. The proposal below > is not perfect but it is covering all the cases we have seen on > different boards with one and two devices on the same bus. > > Signed-off-by: C=C3=A9dric Le Goater Reviewed-by: Joel Stanley > --- > drivers/spi/spi-aspeed-smc.c | 88 ++++++++++++++++++++++++++++++++++++ > 1 file changed, 88 insertions(+) > > diff --git a/drivers/spi/spi-aspeed-smc.c b/drivers/spi/spi-aspeed-smc.c > index b4854b521477..974ab215ec34 100644 > --- a/drivers/spi/spi-aspeed-smc.c > +++ b/drivers/spi/spi-aspeed-smc.c > @@ -405,6 +405,92 @@ static int aspeed_spi_chip_set_default_window(struct= aspeed_spi_chip *chip) > return chip->ahb_window_size ? 0 : -1; > } > > +static int aspeed_spi_set_window(struct aspeed_spi *aspi, > + const struct aspeed_spi_window *win) > +{ > + u32 start =3D aspi->ahb_base_phy + win->offset; > + u32 end =3D start + win->size; > + void __iomem *seg_reg =3D aspi->regs + CE0_SEGMENT_ADDR_REG + win= ->cs * 4; > + u32 seg_val_backup =3D readl(seg_reg); > + u32 seg_val =3D aspi->data->segment_reg(aspi, start, end); > + > + if (seg_val =3D=3D seg_val_backup) > + return 0; > + > + writel(seg_val, seg_reg); > + > + /* > + * Restore initial value if something goes wrong else we could > + * loose access to the chip. > + */ > + if (seg_val !=3D readl(seg_reg)) { > + dev_err(aspi->dev, "CE%d invalid window [ 0x%.8x - 0x%.8x= ] %dMB", > + win->cs, start, end - 1, win->size >> 20); > + writel(seg_val_backup, seg_reg); > + return -EIO; > + } > + > + if (win->size) > + dev_dbg(aspi->dev, "CE%d new window [ 0x%.8x - 0x%.8x ] %= dMB", > + win->cs, start, end - 1, win->size >> 20); > + else > + dev_dbg(aspi->dev, "CE%d window closed", win->cs); > + > + return 0; > +} > + > +/* > + * Yet to be done when possible : > + * - Align mappings on flash size (we don't have the info) > + * - ioremap each window, not strictly necessary since the overall windo= w > + * is correct. > + */ > +static int aspeed_spi_chip_adjust_window(struct aspeed_spi_chip *chip, > + u32 local_offset, u32 size) > +{ > + struct aspeed_spi *aspi =3D chip->aspi; > + struct aspeed_spi_window windows[ASPEED_SPI_MAX_NUM_CS] =3D { 0 }= ; > + struct aspeed_spi_window *win =3D &windows[chip->cs]; > + int ret; > + > + aspeed_spi_get_windows(aspi, windows); > + > + /* Adjust this chip window */ > + win->offset +=3D local_offset; > + win->size =3D size; > + > + if (win->offset + win->size > aspi->ahb_window_size) { > + win->size =3D aspi->ahb_window_size - win->offset; > + dev_warn(aspi->dev, "CE%d window resized to %dMB", chip->= cs, win->size >> 20); > + } > + > + ret =3D aspeed_spi_set_window(aspi, win); > + if (ret) > + return ret; > + > + /* Update chip mapping info */ > + chip->ahb_base =3D aspi->ahb_base + win->offset; > + chip->ahb_window_size =3D win->size; > + > + /* > + * Also adjust next chip window to make sure that it does not > + * overlap with the current window. > + */ > + if (chip->cs < aspi->data->max_cs - 1) { > + struct aspeed_spi_window *next =3D &windows[chip->cs + 1]= ; > + > + /* Change offset and size to keep the same end address */ > + if ((next->offset + next->size) > (win->offset + win->siz= e)) > + next->size =3D (next->offset + next->size) - (win= ->offset + win->size); > + else > + next->size =3D 0; > + next->offset =3D win->offset + win->size; > + > + aspeed_spi_set_window(aspi, next); > + } > + return 0; > +} > + > static int aspeed_spi_dirmap_create(struct spi_mem_dirmap_desc *desc) > { > struct aspeed_spi *aspi =3D spi_controller_get_devdata(desc->mem-= >spi->master); > @@ -419,6 +505,8 @@ static int aspeed_spi_dirmap_create(struct spi_mem_di= rmap_desc *desc) > if (op->data.dir !=3D SPI_MEM_DATA_IN) > return -EOPNOTSUPP; > > + aspeed_spi_chip_adjust_window(chip, desc->info.offset, desc->info= .length); > + > if (desc->info.length > chip->ahb_window_size) > dev_warn(aspi->dev, "CE%d window (%dMB) too small for map= ping", > chip->cs, chip->ahb_window_size >> 20); > -- > 2.34.1 >