From mboxrd@z Thu Jan 1 00:00:00 1970 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id A3170C433EF for ; Tue, 12 Apr 2022 11:26:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=wHYEA16NcxFgVH9fvdhQrczvdZIgmm3eK3V5TjjchaE=; b=xzBL5Hb54spb+x fCaoDP8QnQMFEol7sH95ivzV8Q7obTyDBCiCDR+GFrLiOIL2QACSRNpPK/rfUSgAdkzDRR0ezWBzZ ZPv5yLJ7pAH3tJsihVlTNYoLaORwpBYl34zZSyf/v+vTM+KscNOnNS9Kw4TiWDkAlTxVOQA3OxYQ4 YVZmfiA4jluSttNhkNPjHUCRhk26LNDQN9eKj7EfNjWTkfgYh6i9StkGz3WMpPNMkHUU0IlCgE8GS f92E6rghPggkFnxabbeRcbiqNs9CwELYEzb++np9xuiT/qUyUmdNYJcCX3i52BZ+r7p+Fg/w8YSOa QV3/dbjwSOOQK7YUstqw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1neEdu-00DfCZ-2F; Tue, 12 Apr 2022 11:25:07 +0000 Received: from mail-lf1-x12a.google.com ([2a00:1450:4864:20::12a]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1neELr-00DXo6-4p for linux-arm-kernel@lists.infradead.org; Tue, 12 Apr 2022 11:06:28 +0000 Received: by mail-lf1-x12a.google.com with SMTP id y32so31555707lfa.6 for ; Tue, 12 Apr 2022 04:06:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=P00jqtd+ILMRR9Q3mnllZuR6cE+BJcMxpj1JrqSYISk=; b=lVB+k306E9WmYZwtVGX776xFikOkDj8MIVvynihNeUlVqtHPKszbHgxVOvZFoyZ18+ D7u4Sqd2codKn+ce6UTVew9fHiR5/0EGvTgwE6US1yPS7PwvoSScfnDjAwcP5vOuc4aZ YlGFHU4o2rYb9vg0B9MzkIX/K8t1JXkkFnlRm6EqJ5NgWGt7fyo1tIADEzIoANiIhEc9 WSbmC57CohCUfwQxQZAOX0y1PONDJ5VSgMlUSDSqBN7FcNKjdpM8a4l2vjE/IUc3ajQx KUwsC6OLFImvyC69ajRlE0bQyUm+mt/a395P4TqyVaMityHzlfoUMWZlhkRZwwXTwQne YbjQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=P00jqtd+ILMRR9Q3mnllZuR6cE+BJcMxpj1JrqSYISk=; b=lX5RBxdRzKvjnrk4d3oI0Bpxl0+pji1AIjmrriBGFSyZ5BlZNjY1gtVQqCvXxRpOls yNAhcJ+OFrPWMZhgmfM6ObRmEWJRvdPjUBqzkSuE4ddlP256J6ZghUFIwuAPPkqMOKF9 7LBGnqnuzibArS20X8Wszsb0kID8ftN+2qD6kIRoWUNig4e9DoLnAnhZ00RZit6jZAhw Yq/+dIWkpNzAwl5B8Dv6PGjoVckhau87D7pbhE4+rx7/TBmEa/5xd05rlh4/1Wm4j+SP ggAxX6GX4dsE2d+KKwpK1/3e74Ty3H/Lwy2c2pNxW4dVGULfUHFDJzhZ8f8mhI84V2vD zktw== X-Gm-Message-State: AOAM531ce5OjHQcPhus0F4OpdpFthpxf8lvUAvLdp8mkJzFW2HMTS0eh scwJfgA0bIn6MlaMKicEXFU= X-Google-Smtp-Source: ABdhPJy9aINakzkHjO+kqosgdA0fO5BWmaepRXpf61n5eIKv/mmt/i8Zy/XATZczcwChIiHU/T6/cw== X-Received: by 2002:a05:6512:1398:b0:445:bcef:e4fd with SMTP id p24-20020a056512139800b00445bcefe4fdmr24879325lfa.398.1649761585192; Tue, 12 Apr 2022 04:06:25 -0700 (PDT) Received: from mobilestation ([95.79.134.149]) by smtp.gmail.com with ESMTPSA id z16-20020a195e50000000b0044a77156ef5sm3623829lfi.242.2022.04.12.04.06.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Apr 2022 04:06:24 -0700 (PDT) Date: Tue, 12 Apr 2022 14:06:22 +0300 From: Serge Semin To: Brad Larson Cc: Serge Semin , linux-arm-kernel@lists.infradead.org, arnd@arndb.de, linus.walleij@linaro.org, bgolaszewski@baylibre.com, broonie@kernel.org, adrian.hunter@intel.com, ulf.hansson@linaro.org, olof@lixom.net, dac2@pensando.io, linux-gpio@vger.kernel.org, linux-spi@vger.kernel.org, linux-mmc@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 10/11] spi: dw: Add support for Pensando Elba SoC Message-ID: <20220412110622.2xsk3k63dafqxib5@mobilestation> References: <20220406233648.21644-1-brad@pensando.io> <20220406233648.21644-11-brad@pensando.io> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20220406233648.21644-11-brad@pensando.io> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220412_040627_249071_00A5E0B8 X-CRM114-Status: GOOD ( 34.18 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Wed, Apr 06, 2022 at 04:36:47PM -0700, Brad Larson wrote: > The Pensando Elba SoC includes a DW apb_ssi v4 controller > with device specific chip-select control. The Elba SoC > provides four chip-selects where the native DW IP supports > two chip-selects. The Elba DW_SPI instance has two native > CS signals that are always overridden. > > Signed-off-by: Brad Larson > --- > Change from V3: > - Use more descriptive dt property pensando,syscon-spics > - Minor changes from review input > > drivers/spi/spi-dw-mmio.c | 85 +++++++++++++++++++++++++++++++++++++++ > 1 file changed, 85 insertions(+) > > diff --git a/drivers/spi/spi-dw-mmio.c b/drivers/spi/spi-dw-mmio.c > index 5101c4c6017b..f4636b271818 100644 > --- a/drivers/spi/spi-dw-mmio.c > +++ b/drivers/spi/spi-dw-mmio.c > @@ -53,6 +53,24 @@ struct dw_spi_mscc { > void __iomem *spi_mst; /* Not sparx5 */ > }; > > +struct dw_spi_elba { > + struct regmap *regmap; > + unsigned int reg; > +}; > + > +/* > + * Elba SoC does not use ssi, pin override is used for cs 0,1 and > + * gpios for cs 2,3 as defined in the device tree. > + * > + * cs: | 1 0 > + * bit: |---3-------2-------1-------0 > + * | cs1 cs1_ovr cs0 cs0_ovr > + */ > +#define ELBA_SPICS_SHIFT(cs) (2 * (cs)) > +#define ELBA_SPICS_MASK(cs) (0x3 << ELBA_SPICS_SHIFT(cs)) > +#define ELBA_SPICS_SET(cs, val) \ > + ((((val) << 1) | 0x1) << ELBA_SPICS_SHIFT(cs)) > + > /* > * The Designware SPI controller (referred to as master in the documentation) > * automatically deasserts chip select when the tx fifo is empty. The chip > @@ -238,6 +256,72 @@ static int dw_spi_canaan_k210_init(struct platform_device *pdev, > return 0; > } > > +static void elba_spics_set_cs(struct dw_spi_elba *dwselba, int cs, int enable) > +{ > + regmap_update_bits(dwselba->regmap, dwselba->reg, ELBA_SPICS_MASK(cs), > + ELBA_SPICS_SET(cs, enable)); > +} > + > +static void dw_spi_elba_set_cs(struct spi_device *spi, bool enable) The methods naming is ambiguous. Moreover it breaks this module naming convention. Could you change them to something like: dw_spi_elba_override_cs() and dw_spi_elba_set_cs() ? > +{ > + struct dw_spi *dws = spi_master_get_devdata(spi->master); > + struct dw_spi_mmio *dwsmmio = container_of(dws, struct dw_spi_mmio, dws); > + struct dw_spi_elba *dwselba = dwsmmio->priv; > + u8 cs; > + > + cs = spi->chip_select; > + if (cs < 2) { > + /* overridden native chip-select */ > + elba_spics_set_cs(dwselba, spi->chip_select, enable); > + } > + > + /* > + * The DW SPI controller needs a native CS bit selected to start > + * the serial engine and the platform may have fewer native CSs > + * than needed, so use CS0 always. > + */ > + spi->chip_select = 0; > + dw_spi_set_cs(spi, enable); > + spi->chip_select = cs; > +} > + > +static int dw_spi_elba_init(struct platform_device *pdev, > + struct dw_spi_mmio *dwsmmio) > +{ > + struct of_phandle_args args; > + struct dw_spi_elba *dwselba; > + struct regmap *regmap; > + int rc; > + > + rc = of_parse_phandle_with_fixed_args(pdev->dev.of_node, > + "pensando,syscon-spics", 1, 0, &args); > + if (rc) { > + dev_err(&pdev->dev, "could not find spics\n"); > + return rc; > + } > + > + regmap = syscon_node_to_regmap(args.np); > + if (IS_ERR(regmap)) > + return dev_err_probe(&pdev->dev, PTR_ERR(regmap), > + "could not map spics"); > + > + dwselba = devm_kzalloc(&pdev->dev, sizeof(*dwselba), GFP_KERNEL); > + if (!dwselba) > + return -ENOMEM; > + > + dwselba->regmap = regmap; > + dwselba->reg = args.args[0]; > + > + /* deassert cs */ > + elba_spics_set_cs(dwselba, 0, 1); > + elba_spics_set_cs(dwselba, 1, 1); What if the CS lines are of the active-high type? In that case basically you get to do the opposite to what you claim in the comment here. Note the CS setting into the deactivated state is done in the spi_setup() method anyway, at the moment of the peripheral SPI device registration stage (see its calling the spi_set_cs() function). Thus what you are doing here is redundant. -Sergey > + > + dwsmmio->priv = dwselba; > + dwsmmio->dws.set_cs = dw_spi_elba_set_cs; > + > + return 0; > +} > + > static int dw_spi_mmio_probe(struct platform_device *pdev) > { > int (*init_func)(struct platform_device *pdev, > @@ -352,6 +436,7 @@ static const struct of_device_id dw_spi_mmio_of_match[] = { > { .compatible = "intel,keembay-ssi", .data = dw_spi_keembay_init}, > { .compatible = "microchip,sparx5-spi", dw_spi_mscc_sparx5_init}, > { .compatible = "canaan,k210-spi", dw_spi_canaan_k210_init}, > + { .compatible = "pensando,elba-spi", .data = dw_spi_elba_init}, > { /* end of table */} > }; > MODULE_DEVICE_TABLE(of, dw_spi_mmio_of_match); > -- > 2.17.1 > _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel