Received: by 2002:ac0:98c7:0:0:0:0:0 with SMTP id g7-v6csp5898982imd; Wed, 31 Oct 2018 03:59:06 -0700 (PDT) X-Google-Smtp-Source: AJdET5d15x2DAy6qgKF1E4FQO5PobPPBkOekBgHybt82ZgWMG2bRj+v1EwG3Rvghsr9Bsq1db1xS X-Received: by 2002:a17:902:6bc1:: with SMTP id m1-v6mr2933568plt.34.1540983546195; Wed, 31 Oct 2018 03:59:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1540983546; cv=none; d=google.com; s=arc-20160816; b=uAs4bSzAxz9mZb19GZFw1wS7k7qzcMfS1Y0H4PadL+LYZb9YFhkSEumxdn5E9Oq0Pa poRmeMfPe3LgQRdbe1IP9wZ3Z0epsrOYoWTjzvURzNmbzwLpzywECyQ2DKthlLaEp4Py ehBuQ9tNDBom3WoQia+kRhi320yguy+cKo8cPaBT8rfHAYrtlTti6jWEJM7hHd68KW2x OAE+7YLsiMToiea3v99oqexDDTQ5dmE0JPc8VtlvpoMgGJiQyy6kVC3nb1o01EJJSb3I SdKan10PxcAVLEU9w+CSOb3j3ovXwdzMae5BJFD4ivrrjO4ASebWV9qYEiasuS+hIr7H S3AA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=++UB/yUzA/hcZ0KOxwbRsSFfrZpczcagwpjMv41IvqQ=; b=SL9ArVPFSeCrSYD+9H5t9wH9z51Wdmkhdv+Bq5BHFPDa6ki8HlmgAdTRZ86fK0Chir 6hZ3RF6GS8vvKYqMF93Q/93GBot/EI8AL1GJb0kb46m2RqkjYZe4BqTGpSjrDx9WAIEP HSqI0b7ouI2XCSqgEKHHR4gteCoh1RSkcYDyNCDBgT3lP4Pt4LNSS06U1xPu9/mh3CjD dxixEEIUZdjDocAr5TC+QMJu8M6wM+5iRKZNhomBV7IZP4FtpYhoBsov6tY9noqtXN3a PQQe6JiaRqMNyozQSirWNdjdLJGG2dvPCObm2wQqMtPKJV6WMuuqJ9X9+72/rhuUWrbN TMbA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=ulga7dAy; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l68-v6si26218229pfl.268.2018.10.31.03.58.48; Wed, 31 Oct 2018 03:59:06 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=ulga7dAy; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729165AbeJaTzx (ORCPT + 99 others); Wed, 31 Oct 2018 15:55:53 -0400 Received: from mail-ed1-f66.google.com ([209.85.208.66]:35515 "EHLO mail-ed1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727980AbeJaTzw (ORCPT ); Wed, 31 Oct 2018 15:55:52 -0400 Received: by mail-ed1-f66.google.com with SMTP id d6-v6so5124232edi.2; Wed, 31 Oct 2018 03:58:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=++UB/yUzA/hcZ0KOxwbRsSFfrZpczcagwpjMv41IvqQ=; b=ulga7dAyn+DGwytYeHgUjjcjPtUEeNkZ4VCytHsNSPLubiYrM7HfeUMabQgms9K6wk 7LmMnF9mzXJ0JpSxIipODWpy6myaeG6NCVaT8i0Oxr2K+nvZBni/G8SsVjqELklwWh9O HLjjA4z5/xFHU9de62F8PZQe9WsKwYImlAjbfVG9jJgx0S0Abvb8tBj1TCaP+kFEEldW Ie7P8xoWgYyypu1TZ5PoloRNPz8d9Oa/lTy23GFrWQIRmzRxiJfLbPPQUOF9vGqA/47a VcqM7CzCq9Zdnr2MFPcm1fFu5jTpBUB80lFsu074iv0/kgtEdHJhtTgRk3SMJ0Yblf1f nkZA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=++UB/yUzA/hcZ0KOxwbRsSFfrZpczcagwpjMv41IvqQ=; b=Fl3rqwHXORNXUMdFI1PG0A14YfSP5erm+WNOvRpWMn10EageAzbgVWqSPDI+PDesTH 5gNmlb6PpVQ9xu8u46Zsyvj3ECsiVJfeV0u0qDfdAqlv1tMTtqhEYmYqLcnHLp8HRsal P9Z2m4a9FwixeFkO7M1ZIFdLU5Qoh1Dou5FKuch6emkKGAGz/Ms6npNFwTpVth6zPWuZ NT1hLoLtBUFxyrsy/IQOlDh2bvmVgEQIRnRnTPjGIBRuCqKbn5ndcIn/6fgjiGDvB3zt DVdAOkqJuOWQFbhU+RYBhewX0KIBzlidD2ciCW69wnhbxxHQxHNhjo6NeDwdtS8LBg7k eCFg== X-Gm-Message-State: AGRZ1gILcfLWWX8JrzRPlJu4t8z2T4IaKB+7EoXGYs/f2kJ7+JkGEA+t g6Nu7gnKLsSsM2Odli1+qbuIwhKPeos= X-Received: by 2002:a50:a985:: with SMTP id n5-v6mr1692833edc.120.1540983494630; Wed, 31 Oct 2018 03:58:14 -0700 (PDT) Received: from localhost.localdomain ([5.57.50.195]) by smtp.gmail.com with ESMTPSA id a40-v6sm9041108edd.61.2018.10.31.03.58.13 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 31 Oct 2018 03:58:13 -0700 (PDT) From: Emil Renner Berthing To: linux-spi@vger.kernel.org Cc: Emil Renner Berthing , Addy Ke , Mark Brown , Heiko Stuebner , linux-arm-kernel@lists.infradead.org, linux-rockchip@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v1 13/14] spi: rockchip: support 4bit words Date: Wed, 31 Oct 2018 11:57:10 +0100 Message-Id: <20181031105711.19575-14-esmil@mailme.dk> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181031105711.19575-1-esmil@mailme.dk> References: <20181031105711.19575-1-esmil@mailme.dk> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Emil Renner Berthing The hardware supports 4, 8 and 16bit spi words, so add the missing support for 4bit words. Signed-off-by: Emil Renner Berthing --- drivers/spi/spi-rockchip.c | 41 +++++++++++++++++++++++++++----------- 1 file changed, 29 insertions(+), 12 deletions(-) diff --git a/drivers/spi/spi-rockchip.c b/drivers/spi/spi-rockchip.c index 1297f081818d..9e47e81553a1 100644 --- a/drivers/spi/spi-rockchip.c +++ b/drivers/spi/spi-rockchip.c @@ -54,6 +54,9 @@ /* Bit fields in CTRLR0 */ #define CR0_DFS_OFFSET 0 +#define CR0_DFS_4BIT 0x0 +#define CR0_DFS_8BIT 0x1 +#define CR0_DFS_16BIT 0x2 #define CR0_CFS_OFFSET 2 @@ -464,15 +467,14 @@ static void rockchip_spi_config(struct rockchip_spi *rs, struct spi_device *spi, struct spi_transfer *xfer, bool use_dma) { - u32 dmacr = 0; - u32 cr0 = CR0_FRF_SPI << CR0_FRF_OFFSET | CR0_BHT_8BIT << CR0_BHT_OFFSET | CR0_SSD_ONE << CR0_SSD_OFFSET | CR0_EM_BIG << CR0_EM_OFFSET; + u32 cr1; + u32 dmacr = 0; cr0 |= rs->rsd << CR0_RSD_OFFSET; - cr0 |= (rs->n_bytes << CR0_DFS_OFFSET); cr0 |= (spi->mode & 0x3U) << CR0_SCPH_OFFSET; if (xfer->rx_buf && xfer->tx_buf) @@ -482,6 +484,27 @@ static void rockchip_spi_config(struct rockchip_spi *rs, else if (use_dma) cr0 |= CR0_XFM_TO << CR0_XFM_OFFSET; + switch (xfer->bits_per_word) { + case 4: + cr0 |= CR0_DFS_4BIT << CR0_DFS_OFFSET; + cr1 = xfer->len - 1; + break; + case 8: + cr0 |= CR0_DFS_8BIT << CR0_DFS_OFFSET; + cr1 = xfer->len - 1; + break; + case 16: + cr0 |= CR0_DFS_16BIT << CR0_DFS_OFFSET; + cr1 = xfer->len / 2 - 1; + break; + default: + /* we only whitelist 4, 8 and 16 bit words in + * master->bits_per_word_mask, so this shouldn't + * happen + */ + unreachable(); + } + if (use_dma) { if (xfer->tx_buf) dmacr |= TF_DMA_EN; @@ -490,13 +513,7 @@ static void rockchip_spi_config(struct rockchip_spi *rs, } writel_relaxed(cr0, rs->regs + ROCKCHIP_SPI_CTRLR0); - - if (rs->n_bytes == 1) - writel_relaxed(xfer->len - 1, rs->regs + ROCKCHIP_SPI_CTRLR1); - else if (rs->n_bytes == 2) - writel_relaxed((xfer->len / 2) - 1, rs->regs + ROCKCHIP_SPI_CTRLR1); - else - writel_relaxed((xfer->len * 2) - 1, rs->regs + ROCKCHIP_SPI_CTRLR1); + writel_relaxed(cr1, rs->regs + ROCKCHIP_SPI_CTRLR1); /* unfortunately setting the fifo threshold level to generate an * interrupt exactly when the fifo is full doesn't seem to work, @@ -545,7 +562,7 @@ static int rockchip_spi_transfer_one( return -EINVAL; } - rs->n_bytes = xfer->bits_per_word >> 3; + rs->n_bytes = xfer->bits_per_word <= 8 ? 1 : 2; use_dma = master->can_dma ? master->can_dma(master, spi, xfer) : false; @@ -667,7 +684,7 @@ static int rockchip_spi_probe(struct platform_device *pdev) master->mode_bits = SPI_CPOL | SPI_CPHA | SPI_LOOP; master->num_chipselect = ROCKCHIP_SPI_MAX_CS_NUM; master->dev.of_node = pdev->dev.of_node; - master->bits_per_word_mask = SPI_BPW_MASK(16) | SPI_BPW_MASK(8); + master->bits_per_word_mask = SPI_BPW_MASK(16) | SPI_BPW_MASK(8) | SPI_BPW_MASK(4); master->min_speed_hz = rs->freq / BAUDR_SCKDV_MAX; master->max_speed_hz = min(rs->freq / BAUDR_SCKDV_MIN, MAX_SCLK_OUT); -- 2.19.1