Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp13781750rwd; Sat, 24 Jun 2023 06:27:07 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ71+NRZYH4g6NCCqDuyXexrNVjh+d55ltPUst81sbrW5aDtYxRbWy1oRU5f/4NcCuttUuMe X-Received: by 2002:a05:6a00:1595:b0:66a:6339:e8f9 with SMTP id u21-20020a056a00159500b0066a6339e8f9mr6063821pfk.0.1687613227355; Sat, 24 Jun 2023 06:27:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687613227; cv=none; d=google.com; s=arc-20160816; b=NpeuAUuN1VqsMVibQG0EbVyEC+4HFXETU6604zspIdzC+LcYD/nAtI6KP4fxvhwK/e u6dVwyDnlzKJG6oYYe6SrD3y33DBr7uUYhKcyfSMdO0xjWaxVSbrjvh811phg+51EaQr fG0yl3JYJjo7BkAeX39UyIuTtuf++o87UEBZw8uTYfShRzcJKZXkJhBoWmA36Eu7yR6I a4glXOUIYboFwkIBa5BawP1K2E+/M8GfE7iOh6yyqsgcviEUKjsHLGWOmwjUDSQCl02F SmCUCGvkSoO18vKtL+iXpUYPF559JHULElVTfmdDOIJJXF6g43Hy2GJV+HBgOdAxLeBx IGbg== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=x4HOHpTuxkhDI1uIn7GRBULu0rY5eOvyg0W/1k8C9T4=; fh=YH1c45Mpge+xNtJ1kFOxdo+BPPBT7vhfLXRnLmCy8mI=; b=k75SLtKTyWQUqGzsU2bgqHh0+AiFKcb3c3HS1BDzQXs4bt7HSEiKIklvHBf51z8xSY fkWCDSXxO0+hZTP32fyFOfdPMxawsUIqpitmwK9GZ1fsEgDKoeV/TOTHxFEXvtTaIy2Y p+MSUVfuEGHqHXqpA3O50mCN+gxlN3T8gDygY0B4QrRrUi+txkFNso1PUo+Til0rnGtr utBOxnuOAINu/VGafWu6wfUqZkVZrf3EUnJjhB6SeDe+sGB9SthcDAyLkPUh0NkEtO7d rCLWDxKMpmo1zPykPdt4w57+4ewQ9tqxIAc7/VeXL6tVcsQSZmdfsWjgIbUmH11RISgX 38Ww== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=rUrqWapO; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h14-20020a056a00218e00b00666982292a2si1309606pfi.166.2023.06.24.06.26.55; Sat, 24 Jun 2023 06:27:07 -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=@gmail.com header.s=20221208 header.b=rUrqWapO; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231230AbjFXNRG (ORCPT + 99 others); Sat, 24 Jun 2023 09:17:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56824 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229452AbjFXNRE (ORCPT ); Sat, 24 Jun 2023 09:17:04 -0400 Received: from mail-wm1-x32e.google.com (mail-wm1-x32e.google.com [IPv6:2a00:1450:4864:20::32e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4607BA9; Sat, 24 Jun 2023 06:17:03 -0700 (PDT) Received: by mail-wm1-x32e.google.com with SMTP id 5b1f17b1804b1-3f9c532fa45so16440875e9.2; Sat, 24 Jun 2023 06:17:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1687612621; x=1690204621; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=x4HOHpTuxkhDI1uIn7GRBULu0rY5eOvyg0W/1k8C9T4=; b=rUrqWapO4pYhvePnS7Vq1czHnSJ9zPSgqsffqLURJUNHIlAZ8ys2Si7q8pQzxZ74tt FBZszCa8TucARVI8q8sZ9Avu+4Lj6Ctpu46rODvpVqB85qOYaTwYqiX6LQlZb+GFLdXi nW9isyDNnVfiAdioaHD73UdoRS6Hzlo3qFVh2wPjkV/LjRolMt26XqzDM9xRpUkXeV0P a1D+kktEkyFfedDfIJFTLbpXVq1Sv/peqNNlFZGEGDc1PsG8gDz5zzBWi5Q2u+8RNkf7 /m2w4STUaHct/MJ2jp2F/Xb8cf5To/tikiCVX745Mml/Wtkd+V3xnDjwHz4NJZWDiild GNgA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687612621; x=1690204621; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=x4HOHpTuxkhDI1uIn7GRBULu0rY5eOvyg0W/1k8C9T4=; b=YrkOYko+1pWjCS4qQgaqmuX3nFHfLWi+ALVzt5E983Ho+M5Ie8FtuvJ85FYbl83/vf 8DfV3LzI7dvmiO6sImQoatFl/h/7Q8W5PFS1VRIv1MCCiK1s5U9eBAqBz684q7Rf0HRY C1Dr/dZ9LzEDTqdbSbEyWv7ZwxCQzdISGHXH9OH0P/PSTbmT5n2dOolu+UmOUMU0iWIv hCbwc+j8OiRcrCk9SZKZ5g5LN18eyIhWcEo/ju2TEwjfyWB3U9Po1EmLM4iyE54FnuHw ifr8IH01LxD7YUofd8jtslGV1GdfmEQrErxs6RDf1n+6IQnEeNF+NrcIXHXTYhHXCVdZ ZA0A== X-Gm-Message-State: AC+VfDzUne0Ay/v8L/LY4uzDoUOyvprXM1vnpeOVGT8rxvEvtM9TDiEF xo+Xk/HW2X48DJbSlwJDaf2id4CH6it0ZuQm X-Received: by 2002:a1c:f70a:0:b0:3f7:34dc:ed0d with SMTP id v10-20020a1cf70a000000b003f734dced0dmr16795214wmh.25.1687612620714; Sat, 24 Jun 2023 06:17:00 -0700 (PDT) Received: from user-PC.. ([92.51.95.194]) by smtp.gmail.com with ESMTPSA id l1-20020a1ced01000000b003f9b0830107sm5107428wmh.41.2023.06.24.06.16.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 24 Jun 2023 06:17:00 -0700 (PDT) From: Maksim Kiselev To: linux-spi@vger.kernel.org Cc: Maksim Kiselev , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Chen-Yu Tsai , Jernej Skrabec , Samuel Holland , Paul Walmsley , Palmer Dabbelt , Albert Ou , Mark Brown , Andre Przywara , Cristian Ciocaltea , devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v1 1/3] spi: sun6i: add quirk for dual and quad SPI modes support Date: Sat, 24 Jun 2023 16:16:22 +0300 Message-Id: <20230624131632.2972546-2-bigunclemax@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230624131632.2972546-1-bigunclemax@gmail.com> References: <20230624131632.2972546-1-bigunclemax@gmail.com> 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,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,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 New Allwinner's SPI controllers can support dual and quad SPI modes. To enable one of these modes, we should set the corresponding bit in the SUN6I_BURST_CTL_CNT_REG register. DRM (28 bits) for dual mode and Quad_EN (29 bits) for quad transmission. Signed-off-by: Maksim Kiselev --- drivers/spi/spi-sun6i.c | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/drivers/spi/spi-sun6i.c b/drivers/spi/spi-sun6i.c index 30d541612253..cec2747235ab 100644 --- a/drivers/spi/spi-sun6i.c +++ b/drivers/spi/spi-sun6i.c @@ -83,6 +83,9 @@ #define SUN6I_XMIT_CNT_REG 0x34 #define SUN6I_BURST_CTL_CNT_REG 0x38 +#define SUN6I_BURST_CTL_CNT_STC_MASK GENMASK(23, 0) +#define SUN6I_BURST_CTL_CNT_DRM BIT(28) +#define SUN6I_BURST_CTL_CNT_QUAD_EN BIT(29) #define SUN6I_TXDATA_REG 0x200 #define SUN6I_RXDATA_REG 0x300 @@ -90,6 +93,7 @@ struct sun6i_spi_cfg { unsigned long fifo_depth; bool has_clk_ctl; + u32 mode_bits; }; struct sun6i_spi { @@ -266,7 +270,7 @@ static int sun6i_spi_transfer_one(struct spi_master *master, unsigned int div, div_cdr1, div_cdr2, timeout; unsigned int start, end, tx_time; unsigned int trig_level; - unsigned int tx_len = 0, rx_len = 0; + unsigned int tx_len = 0, rx_len = 0, nbits = 0; bool use_dma; int ret = 0; u32 reg; @@ -418,13 +422,29 @@ static int sun6i_spi_transfer_one(struct spi_master *master, sun6i_spi_write(sspi, SUN6I_GBL_CTL_REG, reg); /* Setup the transfer now... */ - if (sspi->tx_buf) + if (sspi->tx_buf) { tx_len = tfr->len; + nbits = tfr->tx_nbits; + } else if (tfr->rx_buf) { + nbits = tfr->rx_nbits; + } + + switch (nbits) { + case SPI_NBITS_DUAL: + reg = SUN6I_BURST_CTL_CNT_DRM; + break; + case SPI_NBITS_QUAD: + reg = SUN6I_BURST_CTL_CNT_QUAD_EN; + break; + case SPI_NBITS_SINGLE: + default: + reg = FIELD_PREP(SUN6I_BURST_CTL_CNT_STC_MASK, tx_len); + } /* Setup the counters */ + sun6i_spi_write(sspi, SUN6I_BURST_CTL_CNT_REG, reg); sun6i_spi_write(sspi, SUN6I_BURST_CNT_REG, tfr->len); sun6i_spi_write(sspi, SUN6I_XMIT_CNT_REG, tx_len); - sun6i_spi_write(sspi, SUN6I_BURST_CTL_CNT_REG, tx_len); if (!use_dma) { /* Fill the TX FIFO */ @@ -623,7 +643,8 @@ static int sun6i_spi_probe(struct platform_device *pdev) master->set_cs = sun6i_spi_set_cs; master->transfer_one = sun6i_spi_transfer_one; master->num_chipselect = 4; - master->mode_bits = SPI_CPOL | SPI_CPHA | SPI_CS_HIGH | SPI_LSB_FIRST; + master->mode_bits = SPI_CPOL | SPI_CPHA | SPI_CS_HIGH | SPI_LSB_FIRST | + sspi->cfg->mode_bits; master->bits_per_word_mask = SPI_BPW_MASK(8); master->dev.of_node = pdev->dev.of_node; master->auto_runtime_pm = true; -- 2.39.2