Received: by 2002:a25:ef43:0:0:0:0:0 with SMTP id w3csp520306ybm; Thu, 28 May 2020 08:30:36 -0700 (PDT) X-Google-Smtp-Source: ABdhPJycDT+fR05hsxOXK4tiDs2KIWIqOfnJbiL8CEi4M0NGXU3leEe6Mr29b/qxHEjMqpe9NvJv X-Received: by 2002:a17:906:538d:: with SMTP id g13mr3493049ejo.194.1590679836136; Thu, 28 May 2020 08:30:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1590679836; cv=none; d=google.com; s=arc-20160816; b=TeRvt8QDHEG4Ra2O2xdX4cFMJ+m2qhfLAuqi3ynobKqAoPTPoXPrAIHw988zGclBld e+wgasCblc2JBqYyWqovMBmYa2FDPmqtMhOza7833cAwvAthUHFORjrX13075prRuf96 j2HsbfiXDB3zRPcVtTgz7dfOw4c/SDn/nbKPsf8oRzoTHYa7sMXIuveqz5Ls/08ypOYx eDpLunXU8C4VWvW2QyMiNKxOn+1B0K8l0YFk/mjwsRMd8Io3obFiJso9fBTxTp7ZaVHW TDxPpfB9jYYOW7tYS4INMVnqlG0qMp60UMrQTymwLW13+p/gx7Mj6R2DPss6EKf4hO+k ZXnA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from; bh=p1ZsFy5TShgnlNReCAmuIZ/lg+t3Y2jAIhwM8PiLOY0=; b=SW7t9F4XHOKhpSbirBGrHxzT5uDUNCFXutX/ERQI4mP90bo7mA09Pd9b5LtmPxqV+6 ImZjKmwFhWp0hZMEUiszhAf6/0LlNDcklyRMjKEIoaRoC49a5xiTA/dGKtvJioeVcg2N Zqa3kmid0/pNTE1ROtiYg6mH9xmVBTCmiQ8/6j5n+4Ie43XPk+HoiMZQsVpK7RqcUOLd xnvXFGtCvfodNtLph3VJj13JZY1NhrAdeD/fIHY3oj5Y8C8e4cQiRqguLZVnSBNS8803 GAcH66qVeurGbF1yCtGeqmv/VF6sTH+ZbZSJQSONY0SmVB6SQsDfdHoJglaaiwrYSB/V 7JtQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id l24si1075361ejr.561.2020.05.28.08.30.08; Thu, 28 May 2020 08:30:36 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2404388AbgE1P2R (ORCPT + 99 others); Thu, 28 May 2020 11:28:17 -0400 Received: from lists.gateworks.com ([108.161.130.12]:57323 "EHLO lists.gateworks.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2404080AbgE1P2P (ORCPT ); Thu, 28 May 2020 11:28:15 -0400 Received: from 068-189-091-139.biz.spectrum.com ([68.189.91.139] helo=tharvey.pdc.gateworks.com) by lists.gateworks.com with esmtp (Exim 4.82) (envelope-from ) id 1jeKUi-0000Yg-Hz; Thu, 28 May 2020 15:30:56 +0000 From: Tim Harvey To: Wolfgang Grandegger , Marc Kleine-Budde , linux-can@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Cc: "David S . Miller" , Sean Nyekjaer , Andy Shevchenko , =?UTF-8?q?Timo=20Schl=C3=BC=C3=9Fler?= , "Gustavo A . R . Silva" , Tim Harvey Subject: [PATCH] can: mcp251x: add support for half duplex controllers Date: Thu, 28 May 2020 08:27:57 -0700 Message-Id: <1590679677-2678-1-git-send-email-tharvey@gateworks.com> X-Mailer: git-send-email 2.7.4 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Some SPI host controllers do not support full-duplex SPI and are marked as such via the SPI_CONTROLLER_HALF_DUPLEX controller flag. For such controllers use half duplex transactions but retain full duplex transactions for the controllers that can handle those. Signed-off-by: Tim Harvey --- drivers/net/can/spi/mcp251x.c | 34 +++++++++++++++++++++++++++------- 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/drivers/net/can/spi/mcp251x.c b/drivers/net/can/spi/mcp251x.c index 5009ff2..203ef20 100644 --- a/drivers/net/can/spi/mcp251x.c +++ b/drivers/net/can/spi/mcp251x.c @@ -290,8 +290,12 @@ static u8 mcp251x_read_reg(struct spi_device *spi, u8 reg) priv->spi_tx_buf[0] = INSTRUCTION_READ; priv->spi_tx_buf[1] = reg; - mcp251x_spi_trans(spi, 3); - val = priv->spi_rx_buf[2]; + if (spi->controller->flags & SPI_CONTROLLER_HALF_DUPLEX) { + spi_write_then_read(spi, priv->spi_tx_buf, 2, &val, 1); + } else { + mcp251x_spi_trans(spi, 3); + val = priv->spi_rx_buf[2]; + } return val; } @@ -303,10 +307,18 @@ static void mcp251x_read_2regs(struct spi_device *spi, u8 reg, u8 *v1, u8 *v2) priv->spi_tx_buf[0] = INSTRUCTION_READ; priv->spi_tx_buf[1] = reg; - mcp251x_spi_trans(spi, 4); + if (spi->controller->flags & SPI_CONTROLLER_HALF_DUPLEX) { + u8 val[2] = { 0 }; - *v1 = priv->spi_rx_buf[2]; - *v2 = priv->spi_rx_buf[3]; + spi_write_then_read(spi, priv->spi_tx_buf, 2, val, 2); + *v1 = val[0]; + *v2 = val[1]; + } else { + mcp251x_spi_trans(spi, 4); + + *v1 = priv->spi_rx_buf[2]; + *v2 = priv->spi_rx_buf[3]; + } } static void mcp251x_write_reg(struct spi_device *spi, u8 reg, u8 val) @@ -409,8 +421,16 @@ static void mcp251x_hw_rx_frame(struct spi_device *spi, u8 *buf, buf[i] = mcp251x_read_reg(spi, RXBCTRL(buf_idx) + i); } else { priv->spi_tx_buf[RXBCTRL_OFF] = INSTRUCTION_READ_RXB(buf_idx); - mcp251x_spi_trans(spi, SPI_TRANSFER_BUF_LEN); - memcpy(buf, priv->spi_rx_buf, SPI_TRANSFER_BUF_LEN); + if (spi->controller->flags & SPI_CONTROLLER_HALF_DUPLEX) { + spi_write_then_read(spi, priv->spi_tx_buf, 1, + priv->spi_rx_buf, + SPI_TRANSFER_BUF_LEN); + memcpy(buf + 1, priv->spi_rx_buf, + SPI_TRANSFER_BUF_LEN - 1); + } else { + mcp251x_spi_trans(spi, SPI_TRANSFER_BUF_LEN); + memcpy(buf, priv->spi_rx_buf, SPI_TRANSFER_BUF_LEN); + } } } -- 2.7.4