From patchwork Sun Feb 14 10:04:29 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephan Olbrich X-Patchwork-Id: 8301681 Return-Path: X-Original-To: patchwork-linux-spi@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 34BBA9F372 for ; Sun, 14 Feb 2016 10:05:50 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 66073203C4 for ; Sun, 14 Feb 2016 10:05:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 77315203C1 for ; Sun, 14 Feb 2016 10:05:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751288AbcBNKFr (ORCPT ); Sun, 14 Feb 2016 05:05:47 -0500 Received: from mout.gmx.net ([212.227.15.19]:52943 "EHLO mout.gmx.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751272AbcBNKFj (ORCPT ); Sun, 14 Feb 2016 05:05:39 -0500 Received: from chaos-desktop.fritz.box ([94.218.169.41]) by mail.gmx.com (mrgmx003) with ESMTPSA (Nemesis) id 0MIuSH-1aXNS90qkL-002VF7; Sun, 14 Feb 2016 11:05:00 +0100 From: Stephan Olbrich To: Mark Brown , Stephen Warren , Lee Jones , Eric Anholt , linux-spi@vger.kernel.org, linux-rpi-kernel@lists.infradead.org, linux-arm-kernel@lists.infradead.org, Martin Sperl Cc: Stephan Olbrich Subject: [PATCH v2 2/2] spi: bcm2835aux: fix CPOL/CPHA setting Date: Sun, 14 Feb 2016 11:04:29 +0100 Message-Id: <1455444269-4797-3-git-send-email-stephanolbrich@gmx.de> X-Mailer: git-send-email 2.5.0 In-Reply-To: <1455444269-4797-1-git-send-email-stephanolbrich@gmx.de> References: <1455444269-4797-1-git-send-email-stephanolbrich@gmx.de> X-Provags-ID: V03:K0:5Bhgt8XRBnumU5W7cAE+/xBtr8ib/P/XaHZe5LqSBkPVjZAYDfY e9Y7bg/IvQ6+PKgsICiyG1M3xQhZJxEKYjY7vNwS9Q9+BJSMhoLY4o7ugZoNT2A4ct6OOFO TMoNBxf08KvFTgwFPX3lJjSS6uCKhrKXQfr0F0TogFcjl59uTEHDrYToaS7mygFbG981WTI nz7Gjs01kiJTLlZrOq+1g== X-UI-Out-Filterresults: notjunk:1; V01:K0:A2U1U/jYEbk=:GtONNunrwICNN0drivfwve r3rl7QSbB/0UEBHaOXUH3WHyW6EjTy7gII1+r+9+P/QVt5/iSyt8rSZcze/O7uTOzxwYtnjf1 hjrm5cK00811Stfm6g+XzRlQY7x08RLwuLDBzQzq9FQ/yp944Ufe34LYXR0XS5oGge00oduiY jKJ3675BjFnbv6BnsibMV6UE6rsv0y1hQ/vQXOPs9JRUAdawZSRVLLpdOZvn8dqhwotGlWqER Po/5uizM3JnE6vk1AFBDtNqnxHqYA22flZ0nQHCxyw8GUYnFU4wUR1aQUsymrEARVmYeSN7Em uvcaqift50cLomSwRqAwZ3qRUGZHabrZvUr+Pi1KQItt12nnQS1vqQqDa7Ofid7LboPIMvfF+ lgdLoSOuZ41G5fVtVztSlumKv/5qsA0e5VGL6/pBXZ+2sb0c1B0QKWuEcrpCJUzci2zJaWrdk ZmkYMbxUxhLvr6BvSTAxC/StClpJqkqwQgbh/V7vkGOokBOWPtlhS2kR3o63IDHfXrtvll5mC wd9mH23y08aZgHF6loGCddiAfvyBpxOC30yMzt+N9LZ6CmaSY+JD0tcGaKtw9tELIznP6RdSo IXH9BvhKLhDmieTmr905Za1rf2M8nY/LwfSJauaJkkck2xRx2Qs6NQrqwAezjgVzf/vXF1rWS ESXTf3fboNcKxrm2XsAjgISvcv0C3r+h8TBxKRrpBbn5XZPw8re85knM2kyxpDw681QhcYjem Rqn4jrSctCjmru6KkARFecXQCTjOIVQU6K3VBLjYurxFuEKdBuhHnAdvdUo= Sender: linux-spi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-spi@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The auxiliary spi supports only CPHA=0 modes as the first bit is always output to the pin before the first clock cycle. In CPHA=1 modes the first clock edge outputs the second bit hence the slave can never read the first bit. Also the CPHA registers switch between clocking data in/out on rising/falling edge hence depend on the CPOL setting. Signed-off-by: Stephan Olbrich --- drivers/spi/spi-bcm2835aux.c | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/drivers/spi/spi-bcm2835aux.c b/drivers/spi/spi-bcm2835aux.c index 103335e..7428091 100644 --- a/drivers/spi/spi-bcm2835aux.c +++ b/drivers/spi/spi-bcm2835aux.c @@ -64,9 +64,9 @@ #define BCM2835_AUX_SPI_CNTL0_VAR_WIDTH 0x00004000 #define BCM2835_AUX_SPI_CNTL0_DOUTHOLD 0x00003000 #define BCM2835_AUX_SPI_CNTL0_ENABLE 0x00000800 -#define BCM2835_AUX_SPI_CNTL0_CPHA_IN 0x00000400 +#define BCM2835_AUX_SPI_CNTL0_IN_RISING 0x00000400 #define BCM2835_AUX_SPI_CNTL0_CLEARFIFO 0x00000200 -#define BCM2835_AUX_SPI_CNTL0_CPHA_OUT 0x00000100 +#define BCM2835_AUX_SPI_CNTL0_OUT_RISING 0x00000100 #define BCM2835_AUX_SPI_CNTL0_CPOL 0x00000080 #define BCM2835_AUX_SPI_CNTL0_MSBF_OUT 0x00000040 #define BCM2835_AUX_SPI_CNTL0_SHIFTLEN 0x0000003F @@ -92,9 +92,6 @@ #define BCM2835_AUX_SPI_POLLING_LIMIT_US 30 #define BCM2835_AUX_SPI_POLLING_JIFFIES 2 -#define BCM2835_AUX_SPI_MODE_BITS (SPI_CPOL | SPI_CPHA | SPI_CS_HIGH \ - | SPI_NO_CS) - struct bcm2835aux_spi { void __iomem *regs; struct clk *clk; @@ -389,12 +386,12 @@ static int bcm2835aux_spi_prepare_message(struct spi_master *master, bs->cntl[1] = BCM2835_AUX_SPI_CNTL1_MSBF_IN; /* handle all the modes */ - if (spi->mode & SPI_CPOL) + if (spi->mode & SPI_CPOL) { bs->cntl[0] |= BCM2835_AUX_SPI_CNTL0_CPOL; - if (spi->mode & SPI_CPHA) - bs->cntl[0] |= BCM2835_AUX_SPI_CNTL0_CPHA_OUT | - BCM2835_AUX_SPI_CNTL0_CPHA_IN; - + bs->cntl[0] |= BCM2835_AUX_SPI_CNTL0_OUT_RISING; + } else { + bs->cntl[0] |= BCM2835_AUX_SPI_CNTL0_IN_RISING; + } bcm2835aux_wr(bs, BCM2835_AUX_SPI_CNTL1, bs->cntl[1]); bcm2835aux_wr(bs, BCM2835_AUX_SPI_CNTL0, bs->cntl[0]); @@ -434,7 +431,7 @@ static int bcm2835aux_spi_probe(struct platform_device *pdev) } platform_set_drvdata(pdev, master); - master->mode_bits = BCM2835_AUX_SPI_MODE_BITS; + master->mode_bits = (SPI_CPOL | SPI_CS_HIGH | SPI_NO_CS); master->bits_per_word_mask = SPI_BPW_MASK(8); master->num_chipselect = -1; master->transfer_one = bcm2835aux_spi_transfer_one;