From patchwork Sun Apr 28 20:28:47 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jagan Teki X-Patchwork-Id: 328 Return-Path: X-Original-To: linux-amarula@patchwork.amarulasolutions.com Delivered-To: linux-amarula@patchwork.amarulasolutions.com Received: from mail-pg1-f197.google.com (mail-pg1-f197.google.com [209.85.215.197]) by ganimede.amarulasolutions.com (Postfix) with ESMTPS id CB13C3F08F for ; Sun, 28 Apr 2019 22:29:36 +0200 (CEST) Received: by mail-pg1-f197.google.com with SMTP id z7sf6106406pgc.1 for ; Sun, 28 Apr 2019 13:29:36 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1556483375; cv=pass; d=google.com; s=arc-20160816; b=aoh4g7lOCqdf0mS7daV92sjdZG29110AQlK8wB9Xau7RQGyMmO4FpUwOcvFIdWhxE4 R3Kq+ao8OxP9xw+2Nv88x9+e7OoJ7Kt3WSKPmWatcozi03cSF5e6N8ISBet3SlyiBgGw nsDpokc8cLMUK/jnl8GZjLXY0CJcl+lsxzwiS00kFOBQgwAAK/UtBnBSFt3wCu0ibYyp 3iR78du/0CWjvAVuof85z8f5CjR1J1aSPDDCs6FfXBKSTmjxWHkp7EfxbsY39KpI1JKa dmGTuofnLm60c75DQxMR2Yyfg4bvU2yPCH8MIXRGleWCSr5ZjM/kiJPDdU2vCKXKUYK2 dbdQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-unsubscribe:list-archive:list-help:list-post:list-id :mailing-list:precedence:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=Q7y8ddimOcH0+DzW0LOrl56s5eF5cE0HvYvWBme78HM=; b=rp8E8iD0bOEBvLLC6tTghe7nJaevSlealWc/5MD5VyT15rpAuvdslXy9y+hvmRUPew S5icJUs1M5KLg5xzqe1MPck5cvOcCQhAeY+2O1PNlbV9YcuSNQucGY0x77dQdhNdnVXl 2g+zkYsvwlhPQAkeVNCWZe0Se9CJfycy7H7x0/YlYTNIgF6JwfntZzkGzCv1mvCl4obc c/++RCteAIkcnCT8JMsdyHxGVSLuba6hjeOphHGGnRgEMbnModCuKKovPmZotIiySSBG T9Ji9nuOT7W5ueH3lx/UgUccKUBW3r+7si0X+Fz8Rx8DUr488WfEbL9nInoXsJyHsFuo n+vw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b="Gj0/sgbw"; spf=pass (google.com: domain of jagan@amarulasolutions.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=jagan@amarulasolutions.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amarulasolutions.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:x-original-sender:x-original-authentication-results :precedence:mailing-list:list-id:list-post:list-help:list-archive :list-unsubscribe; bh=Q7y8ddimOcH0+DzW0LOrl56s5eF5cE0HvYvWBme78HM=; b=VmYIUQqQtAUrEswF4phJAmGpoDlriCkxlB1c1T9rSqL9zbeRM0wwOtwZAVvxvczuJ6 SebucXhtpcmwz0GgmeYn9V5R9GmdMi9/f58gBBw4/eyqWj7RgocOyg+uB+/k0aICzbI7 Lttej6hN0mwfCyczYOfKJ3fRjS0uKpBI+/Kl4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :x-spam-checked-in-group:list-post:list-help:list-archive :list-unsubscribe; bh=Q7y8ddimOcH0+DzW0LOrl56s5eF5cE0HvYvWBme78HM=; b=I+iDnuGQXfvmho4HS2zqi005ZYYLTCXl2/KMemsxB/kOQAH83PIV+J3ZE55jQhRBqw DmQYH8P5kzQnKtoDAsMssyxUn7G7VnzPmEcnhx5zxLR9LmWgW5IHATO/XiszGt7iSgko KFlIZpsRAhezIb7X8+ziGVh97PAu6Pkdsn1Rkzva5Wnj4mFwYScLZdb4thtNZ4PWn/BT kKLNYqDJzhAS8gr/CXEpWdgbPhOVIqA7/BSVbclj2rGhfGHsf29/cZYyT4Fw5jj0DUzb nkgq4+gTmXkHTk5731wn2Lr9RQRXPBxoPASkVa1qGTrZyIQMyUB5lsvZcr2SLQOnZfs9 lxEQ== X-Gm-Message-State: APjAAAUjMaHaZJTRfOhDyrqOTHT+INvFpFQU5OTWt6etTMer3ndjy054 +IBH241olyr56vNgiv/NJ0xud/1m X-Google-Smtp-Source: APXvYqyEvpGTKqIWfErSAk105Ws2QPrt8MiIbxFTXumoUGgR5SiaVL3YKrAx/poY8pzBRt19vvwqNA== X-Received: by 2002:a63:2b41:: with SMTP id r62mr55531073pgr.403.1556483375600; Sun, 28 Apr 2019 13:29:35 -0700 (PDT) X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:a63:6b44:: with SMTP id g65ls551951pgc.8.gmail; Sun, 28 Apr 2019 13:29:35 -0700 (PDT) X-Received: by 2002:a63:2bc8:: with SMTP id r191mr19622776pgr.72.1556483375229; Sun, 28 Apr 2019 13:29:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556483375; cv=none; d=google.com; s=arc-20160816; b=ioYdyG9+qNMFmBZNHw6MGqbtmivHx084QCsvhpdLB2f2um0jSKMoM2AACQAzy+xfXN pMumuB+ZeIbaPusFxHt3pxh4qZzDDmNUp699Lo6qd1IB3s2kdGwubDrNoWvmU01jY9J1 VzMJu8NFyeIN9r3njOvMIQdUowUO4MMJjAUB1ydUmb1/mXR/kxzKatgWdxI0DiLWLmBX 8R92AQNVPWWGzNNBmJ2kIoJA41aSfDtSysFwAiuDIdDvHkNL427hcl7WNu2mPzqB57J/ 55yN2F5gPKrGlCw8MrUrTZM/gOCHZwfhe/oTSmLDCMoZoAMyJC/p0GY500HDyZ+tzL+M 88pg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=9z7Tvb7YtJKfwSMCWjYsme2ZetdCxq/rCgs8WiN4acI=; b=oVma+5HucZwiMdWHfFZEiHCUrhTfGxhEug2t3xUVmyujJyNjp7+B5nLyGEjbsUE2DQ wPqJMF+05HbAUy8qXa0ZIUrxGbw1w6SFBPxeqCuAhYyVe6NHnTwbjNI5/gzAf42M09ob U+WY4kWe24ybo7BuqBWpKVsmkQ26iwxxYT5H6Ifq3wtXWobpnSye4JLUM28HS3NzygB5 MJeMnyxr/orRGTMeDmZadsqlKSscVAnBaNb+EzVIGN5US5uBDTFFj43kt8y1bCIzL94h oAQbZ8pdFmRYyn/gSoJnoiwKGG+Ie76Tgw0TFdpsJrd02STvSWiqXPRfiC5gpPScnDDn 28ow== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b="Gj0/sgbw"; spf=pass (google.com: domain of jagan@amarulasolutions.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=jagan@amarulasolutions.com Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id 3sor2582281pfa.24.2019.04.28.13.29.35 for (Google Transport Security); Sun, 28 Apr 2019 13:29:35 -0700 (PDT) Received-SPF: pass (google.com: domain of jagan@amarulasolutions.com designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; X-Received: by 2002:aa7:8a92:: with SMTP id a18mr60052550pfc.218.1556483374949; Sun, 28 Apr 2019 13:29:34 -0700 (PDT) Received: from localhost.localdomain ([115.97.185.144]) by smtp.gmail.com with ESMTPSA id x66sm68841439pfb.78.2019.04.28.13.29.32 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 28 Apr 2019 13:29:34 -0700 (PDT) From: Jagan Teki To: Heiko Schocher , Tom Rini Cc: u-boot@lists.denx.de, linux-amarula@amarulasolutions.com, Mario Six Subject: [PATCH v2 12/19] spi: mpc8xxx: Make code more readable Date: Mon, 29 Apr 2019 01:58:47 +0530 Message-Id: <20190428202854.8590-13-jagan@amarulasolutions.com> X-Mailer: git-send-email 2.18.0.321.gffc6fa0e3 In-Reply-To: <20190428202854.8590-1-jagan@amarulasolutions.com> References: <20190428202854.8590-1-jagan@amarulasolutions.com> MIME-Version: 1.0 X-Original-Sender: jagan@amarulasolutions.com X-Original-Authentication-Results: mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b="Gj0/sgbw"; spf=pass (google.com: domain of jagan@amarulasolutions.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=jagan@amarulasolutions.com Content-Type: text/plain; charset="UTF-8" Precedence: list Mailing-list: list linux-amarula@amarulasolutions.com; contact linux-amarula+owners@amarulasolutions.com List-ID: X-Spam-Checked-In-Group: linux-amarula@amarulasolutions.com X-Google-Group-Id: 476853432473 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , From: Mario Six Introduce the to_prescale_mod and set_char_len inline functions to make the code more readable. Note that the added "if (bitlen > 16)" check does not change the semantics of the current code, and hence only preserves the current error (this will be fixed in a later patch in the series). Signed-off-by: Mario Six --- drivers/spi/mpc8xxx_spi.c | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/drivers/spi/mpc8xxx_spi.c b/drivers/spi/mpc8xxx_spi.c index 2a0f3cc06a..83fd8b3cc1 100644 --- a/drivers/spi/mpc8xxx_spi.c +++ b/drivers/spi/mpc8xxx_spi.c @@ -30,6 +30,16 @@ enum { SPI_COM_LST = BIT(31 - 9), }; +static inline u32 to_prescale_mod(u32 val) +{ + return (min(val, (u32)15) << 16); +} + +static void set_char_len(spi8xxx_t *spi, u32 val) +{ + clrsetbits_be32(&spi->mode, SPI_MODE_LEN_MASK, (val << 20)); +} + #define SPI_TIMEOUT 1000 struct spi_slave *spi_setup_slave(uint bus, uint cs, uint max_hz, uint mode) @@ -66,7 +76,7 @@ void spi_init(void) */ out_be32(&spi->mode, SPI_MODE_REV | SPI_MODE_MS | SPI_MODE_EN); /* Use SYSCLK / 8 (16.67MHz typ.) */ - clrsetbits_be32(&spi->mode, 0x000f0000, BIT(16)); + clrsetbits_be32(&spi->mode, SPI_MODE_PM_MASK, to_prescale_mod(1)); /* Clear all SPI events */ setbits_be32(&spi->event, 0xffffffff); /* Mask all SPI interrupts */ @@ -119,13 +129,14 @@ int spi_xfer(struct spi_slave *slave, uint bitlen, const void *dout, void *din, clrbits_be32(&spi->mode, SPI_MODE_EN); - if (bitlen <= 4) { - clrsetbits_be32(&spi->mode, 0x00f00000, (3 << 20)); - } else if (bitlen <= 16) { - clrsetbits_be32(&spi->mode, 0x00f00000, - ((bitlen - 1) << 20)); - } else { - clrbits_be32(&spi->mode, 0x00f00000); + if (bitlen <= 4) + set_char_len(spi, 3); + else if (bitlen <= 16) + set_char_len(spi, bitlen - 1); + else + set_char_len(spi, 0); + + if (bitlen > 16) { /* Set up the next iteration if sending > 32 bits */ bitlen -= 32; dout += 4;