Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752166AbbLIGyy (ORCPT ); Wed, 9 Dec 2015 01:54:54 -0500 Received: from mail-db3on0110.outbound.protection.outlook.com ([157.55.234.110]:20608 "EHLO emea01-db3-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1750781AbbLIGyv (ORCPT ); Wed, 9 Dec 2015 01:54:51 -0500 X-Greylist: delayed 1031 seconds by postgrey-1.27 at vger.kernel.org; Wed, 09 Dec 2015 01:54:51 EST Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=bhuvanchandra.dv@toradex.com; From: Bhuvanchandra DV To: CC: , , , Bhuvanchandra DV Subject: [PATCH] spi-fsl-dspi: Fix CTAR Register access Date: Wed, 9 Dec 2015 11:51:39 +0530 Message-ID: <1449642099-13045-1-git-send-email-bhuvanchandra.dv@toradex.com> X-Mailer: git-send-email 2.6.2 MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [115.115.225.206] X-ClientProxiedBy: PN1PR01CA0036.INDPRD01.PROD.OUTLOOK.COM (25.164.136.136) To DB3PR05MB267.eurprd05.prod.outlook.com (10.141.4.26) X-Microsoft-Exchange-Diagnostics: 1;DB3PR05MB267;2:hn028+3gDhYrT5Q8WIV66bK1D7jP0/ygIMxif6r15HgpjobIbxlk//twFFTCmcKVpU6DmO4GDM0esKyFYvOJbpa32NMAV7s8MRoTHWThF5TR60LV5Jid0ZE2BJ6Jn1EVlwQZENS5t6hZhb8P/oUOjg==;3:9taMJshffoDUz8/I+Nmdsklpv/074ncQm6gFjBkEMOO6lxHULWKb0jUMhR+HVcDEeWEE0cMg+grWcovFBPvi39aq7B2SRm+YQvdfsFPBIfKspQM7VzFnXnU5oZ845tRY;25:nlSLd6hN3X2s9zUiLpWSLyMVsj4GtVbHvq5XVinKwp6aJBEakYUhcm2z9+tLzDYkKrcCeeFmbAMXlHlf9qYz6bgoeKYQTZP/lIJpTVBozuPy5YIxIUIzcT5qz8rLCICck5CQljWdk1Ve32mQUc5BxcoDkuC1/x01YHzzpAT9jlrgpN7VVnuR1m19fLVyfHv+eM+P6lNHxLlxi76LqZ2QOmp69Y8ttYowVgsfwFp17uOkveSJTJ+ITwcx6rESQq6iBW94LkvvB3+3jshM+G9Zcw==;20:5cEmzyH/JdRbQzYY1OpCCHwXe5f9MT4HitiMBWKv5DfVlBnsrhqS21vS0S2adBL7wIhgNhsAYYohyWbkKEu61HdSDwajA1prrIzOvNySVBC/LyBH9/scXKWgbXuoxK3jvbY15J/W9zbaHu7jTj6S3OqEeu5t4gtu/0p6/Ui5b6/8KCPZp8xenZJc4vvFdb3/ytDXc+PGIInefm3kqhbVoqB5Oicl2GP7VfNsx86PH/vqbaEWoXtVzku1myxYzhm1oV7IqvNRyVwA4LLVPHOwXHIMBAwyNU32/Isov+3BKVOHoodoCzPprlbqcyZAZHRmrI8NkXOJY5CS+RzbfiV8vw== X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:DB3PR05MB267; X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(90676262408878); X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(601004)(2401047)(8121501046)(520078)(5005006)(3002001)(10201501046);SRVR:DB3PR05MB267;BCL:0;PCL:0;RULEID:;SRVR:DB3PR05MB267; X-Microsoft-Exchange-Diagnostics: 1;DB3PR05MB267;4:mnCioLwB5w9cJTHPOxB04hwzhfg20hBborGVHnyqbOrl25sIpf2WTE6E8XMtpXh/dK/Pj1MB0kRVmWB/vw9eIqFdlvfPQl1fSQ7e4kKEoyTtcMSO1sa2Ahxqp74CMzZlKYITGcz2uQKmwxwSXQsnMZDComLHzklwM7K9yKh/Z/S+LoBzJjxDrcuwjihwgKOKLBGxaGMhZfTL6o9OfbKnDspZx+qKO1QLg/A+68DzpJ7QWXsSYkbMDqd8bR08PLY9T7Gurbb14LRADtE3kXx9LOeyj70DeJQlzLrMUPCpUt7sQ6Mq4BOWFHNd+m18D9nCxWKCQVoXtiDw/aVn3elz/IotMQi9vUdgVlTTTauOidG67SsqR/WF9NKxInMC7Pt9eU+9IFc1qvsEnQPUSp6r17Zs4yJ9utzR2LIkpSs+3bOwlhfzcCaFh7LaYsWnPJ99 X-Forefront-PRVS: 0785459C39 X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10019020)(6009001)(199003)(189002)(107886002)(42186005)(5003940100001)(50986999)(5004730100002)(122386002)(86362001)(19580405001)(4001430100002)(40100003)(586003)(50466002)(3846002)(19580395003)(6116002)(1096002)(53416004)(69596002)(105586002)(97736004)(101416001)(87976001)(189998001)(5008740100001)(48376002)(33646002)(230783001)(5001960100002)(106356001)(36756003)(229853001)(92566002)(81156007)(50226001)(110136002)(47776003)(2351001)(66066001)(77096005);DIR:OUT;SFP:1102;SCL:1;SRVR:DB3PR05MB267;H:linuxdev-in.toradex.int;FPR:;SPF:None;PTR:InfoNoRecords;A:1;MX:1;LANG:en; X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1;DB3PR05MB267;23:xQKlEx3+R9RC7XKkcdUEIpWpEa+nV8+2ExjPThxI3U?= =?us-ascii?Q?4cXWoBFtcne3pTQOhReNyDY287msp4Wylj9AmzcgX4pq4pWkkmPeTBlXnSJz?= =?us-ascii?Q?hcAvans69sC7RJ2jSsXUx+N2HDXfwLRUSh0hTgUymjn67a1Quon/LQ8++36I?= =?us-ascii?Q?Jp7TUJw5hTxwOKhypajInluRskVck8KIlbQhyZLZ9ZtIJvnn8TZRkeBLmzfd?= =?us-ascii?Q?ty4BSdPHKQz3WtCELsY1jzRO+drTyEzvcPx6YeBZ5njH8m53YlFzY4epwxIO?= =?us-ascii?Q?gLPSE0O/DiXc2uCMVHsvAZeSS9fpCd8v08aMow4LY+/mablFzW5YNayE/dEF?= =?us-ascii?Q?L1n1RIxEXAepSOGE/jZbP4yHYA3p7NTjdm5uDasAoUJmdOiz7p94EBcpTnZT?= =?us-ascii?Q?o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PD1zGvqkQIUoTnw==;24:expwroUSUEMoQU3sj6Cd9wG/gNEyZsnvkVFM5RuRqzzv0/jpTiNU8e0WYfLQkuowzNZNPZd166yxk3CsylW9zFqi72/K7o3tuQicS6Ywotk= SpamDiagnosticOutput: 1:23 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: toradex.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Dec 2015 06:22:19.3736 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB3PR05MB267 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3218 Lines: 86 DSPI instances in Vybrid have a different amount of chip selects and CTARs (Clock and transfer Attributes Register). In case of DSPI1 we only have 2 CTAR registers and 4 CS. In present driver implementation CTAR offset is derived from CS instance which will lead to out of bound access if chip select instance is greater than CTAR register instance, hence use single CTAR0 register for all CS instances. Since we write the CTAR register anyway before each access, there is no value in using the additional CTAR registers. Also one should not program a value in CTAS for a CTAR register that is not present, hence configure CTAS to use CTAR0. Signed-off-by: Bhuvanchandra DV --- drivers/spi/spi-fsl-dspi.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/drivers/spi/spi-fsl-dspi.c b/drivers/spi/spi-fsl-dspi.c index 01fa95b..b21c3c0 100644 --- a/drivers/spi/spi-fsl-dspi.c +++ b/drivers/spi/spi-fsl-dspi.c @@ -138,7 +138,7 @@ static inline int is_double_byte_mode(struct fsl_dspi *dspi) { unsigned int val; - regmap_read(dspi->regmap, SPI_CTAR(dspi->cs), &val); + regmap_read(dspi->regmap, SPI_CTAR(0), &val); return ((val & SPI_FRAME_BITS_MASK) == SPI_FRAME_BITS(8)) ? 0 : 1; } @@ -231,7 +231,7 @@ static int dspi_transfer_write(struct fsl_dspi *dspi) */ if (tx_word && (dspi->len == 1)) { dspi->dataflags |= TRAN_STATE_WORD_ODD_NUM; - regmap_update_bits(dspi->regmap, SPI_CTAR(dspi->cs), + regmap_update_bits(dspi->regmap, SPI_CTAR(0), SPI_FRAME_BITS_MASK, SPI_FRAME_BITS(8)); tx_word = 0; } @@ -250,7 +250,7 @@ static int dspi_transfer_write(struct fsl_dspi *dspi) dspi_pushr = SPI_PUSHR_TXDATA(d16) | SPI_PUSHR_PCS(dspi->cs) | - SPI_PUSHR_CTAS(dspi->cs) | + SPI_PUSHR_CTAS(0) | SPI_PUSHR_CONT; dspi->len -= 2; @@ -265,7 +265,7 @@ static int dspi_transfer_write(struct fsl_dspi *dspi) dspi_pushr = SPI_PUSHR_TXDATA(d8) | SPI_PUSHR_PCS(dspi->cs) | - SPI_PUSHR_CTAS(dspi->cs) | + SPI_PUSHR_CTAS(0) | SPI_PUSHR_CONT; dspi->len--; @@ -365,10 +365,10 @@ static int dspi_transfer_one_message(struct spi_master *master, regmap_update_bits(dspi->regmap, SPI_MCR, SPI_MCR_CLR_TXF | SPI_MCR_CLR_RXF, SPI_MCR_CLR_TXF | SPI_MCR_CLR_RXF); - regmap_write(dspi->regmap, SPI_CTAR(dspi->cs), + regmap_write(dspi->regmap, SPI_CTAR(0), dspi->cur_chip->ctar_val); if (transfer->speed_hz) - regmap_write(dspi->regmap, SPI_CTAR(dspi->cs), + regmap_write(dspi->regmap, SPI_CTAR(0), dspi->cur_chip->ctar_val); regmap_write(dspi->regmap, SPI_RSER, SPI_RSER_EOQFE); @@ -469,7 +469,7 @@ static irqreturn_t dspi_interrupt(int irq, void *dev_id) if (!dspi->len) { if (dspi->dataflags & TRAN_STATE_WORD_ODD_NUM) - regmap_update_bits(dspi->regmap, SPI_CTAR(dspi->cs), + regmap_update_bits(dspi->regmap, SPI_CTAR(0), SPI_FRAME_BITS_MASK, SPI_FRAME_BITS(16)); dspi->waitflags = 1; -- 2.6.2 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/