Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753140AbbLJF4K (ORCPT ); Thu, 10 Dec 2015 00:56:10 -0500 Received: from mail-db3on0143.outbound.protection.outlook.com ([157.55.234.143]:31072 "EHLO emea01-db3-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751041AbbLJF4I (ORCPT ); Thu, 10 Dec 2015 00:56:08 -0500 Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=bhuvanchandra.dv@toradex.com; From: Bhuvanchandra DV To: CC: , , , Bhuvanchandra DV Subject: [PATCH v2] spi-fsl-dspi: Fix CTAR Register access Date: Thu, 10 Dec 2015 11:25:30 +0530 Message-ID: <1449726930-7378-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: SIXPR04CA0081.apcprd04.prod.outlook.com (10.141.119.39) To DB4PR05MB271.eurprd05.prod.outlook.com (10.242.158.26) X-Microsoft-Exchange-Diagnostics: 1;DB4PR05MB271;2:12fAeA77p2ctxgjzwzx/xYGww9VyK1jtmoHTruyGeTeVpPzfezpgf5/2c+IfhY6EerU51odZ2fQAZRIEvD6r/olLf7LIaiP2oGZpt/HvAQRGEQE89GMmXy6RajnurM3O5OVJ5nqqM/wz577sM4noHg==;3:iXNrE0fO1HH2AeuJyI3b8ASimoFpqsg7fNKLwgxEntZcXiGt84y23qoksw35xQmFkdFYHDLaKceI0Y6EwLxZv30UpL2OGbTtRJEhyzfKGZSM02JwfgObbKx4kvrVhadv;25:H1wvjKyp/u3HTVJlpgbYjr2fuBFz6AMhuiHQ4FXmm9Krx9MlDoKEObe9zAYtblL0CgbrLYKtHI2brW7bCiywyfWRIkES2aXbTAWQlU5qCKM+2UIkzgHN48xlXsZ/W3AhF1qA67XdgIvy/+/3KRWr8meAEnRJ19tSDMp6xWHx7XtC2CboEH/F77yu7X4SE8IkCysiP8w1AO6XPsNvuk353rw1fwiqSWyV2EYlhRg1L7BGeZSZEMV5YWos1KXVKc6UqbojkXOM6my/tGKa19Li8Q==;20:/lXvJKBgiQ8z0QZrslurCfuvfzF2Cr9VbQWgCxaJqKCequkWo66C41OTZYu42a8MCYP7rmHVLgtTNVcDn8Ey0JCY//o8I/kqvjEDwZnHMF7JVSV4yukmmdRG6NJh3VfbNKky/+k/0r1pwNkiQ1aGXoQkSxoaPIaU2yhrLYnoJfLiAjUca4PfPvz06xqb0i0CMzvUULMi/nsVf+2G5ohSvik51oNIumUQUzP3FYmJEYpywNJDvPElXpHtGp8F7FaCkd/5jnlW2z6bvw/2QVq38FbGozYXuVwerkY9T8UsuKjwu0ja2F2Nutdx5S+pfLoObcTy2ev7caEBDbMUqtFyjA== X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:DB4PR05MB271; X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(90676262408878); X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(601004)(2401047)(520078)(8121501046)(5005006)(10201501046)(3002001);SRVR:DB4PR05MB271;BCL:0;PCL:0;RULEID:;SRVR:DB4PR05MB271; X-Microsoft-Exchange-Diagnostics: 1;DB4PR05MB271;4:9PeLBFmQDqnl+vyFz9DymapzaTxEtaG2Y1aA+NWNXWciEw7ql4KsQ6f2ANN07x8EbfXOzRzxPMCsn1O+BCXE5sPAadp3C22T5UlopMbazncD2K7aoy9hCS3fYkND6ZAjUzNjN9zVLM3mJdMckm9ZOh7j9OxG7TjW0rIbs5qDXBUFORijqosMiHPV/dfFYcUrTYD2aE99UxSmH9ZBHfoP7xh9Owdr1XEoB7zLpd0yZU/oCTF3fv+1+bSJUVU/N8vx+WIkkzOAs+px5kI8fHF9KIpcuai3enbO8C9daN8i/ehCFIF3f1OLcr0imIFUjs7sFYowxZF5XB33EE2oce+pwvf4eWNLE2OUcZUB3VJE9d6gAjYOSJbBjxu+ozHFV9H59ewudfgVXP4GqyJ4bi44R55JYDrnRnf1qJyl8WODBsLcvZkpwA5uaPE1+iA0smwg X-Forefront-PRVS: 078693968A X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10019020)(6009001)(189002)(199003)(19580405001)(105586002)(33646002)(77096005)(5001960100002)(66066001)(19580395003)(122386002)(97736004)(53416004)(110136002)(50226001)(42186005)(106356001)(48376002)(47776003)(86362001)(50466002)(69596002)(101416001)(81156007)(92566002)(107886002)(189998001)(40100003)(6116002)(229853001)(50986999)(36756003)(5004730100002)(1096002)(2351001)(586003)(3846002)(4001430100002)(87976001)(230783001)(5003940100001)(5008740100001);DIR:OUT;SFP:1102;SCL:1;SRVR:DB4PR05MB271;H:linuxdev-in.toradex.int;FPR:;SPF:None;PTR:InfoNoRecords;MX:1;A:1;LANG:en; X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1;DB4PR05MB271;23:ecsEVwMHkqYcLtuxMA5OTNyozROPLBJutu2Gz17Qo2?= =?us-ascii?Q?yy5ZHgEivyurfZF1hs+O8XIAffrS0iqbFfPj/nDvcImArE17cFcSTBbIDi7H?= =?us-ascii?Q?XgT3kAcxKVh6P9Ii7PcSqefZe6IziyxYpQtLqeYQ69QqPsZQ0/cnU3H0/vke?= =?us-ascii?Q?HpdExg8KqccD+BfivK+6564+hf4Or2hKG/IFs5L4MUtQZC9sPi+YzMqb5r7m?= =?us-ascii?Q?B3uHUS2sfu2nTEpebxZPGzAWtWuW+WD2wGONO3JS7JtK+VH9cdrDHbOm8E6Q?= =?us-ascii?Q?YzQZ1AzmxaWvuwTLzN8XNn5GAgK4a/FGZ++perNT738GtONUwsYW0JgoMNSS?= =?us-ascii?Q?59rB3He/gNmcZGOGF5/HlJN1PZNzV1Rj8/tYWvs++4DnrGJ3ZIm8zHFiy0Qy?= =?us-ascii?Q?tww5CKgW7fYjaNNsNjk88AuVkXs4ivYv1cOjKsiSFs9uu0EV9uFFlN/KpUIS?= =?us-ascii?Q?0PKjVpVpymz6SQNTs6FTqXSGL4NecVzMhQYrd/XA/cbzRIHubgUuTTIdySJE?= =?us-ascii?Q?AeaaseKsh1jPLtChRhpgsw4qCX0SK+OgoD3RT8wrQSS299uxKVFIxu/wfSYo?= =?us-ascii?Q?hRGdSY4XbBGKnk/hWRhV40fzkcnbENk92h0MX8iUAgIgoD/jxa7lEkeKtuYs?= =?us-ascii?Q?DyPzsDQkwIsVp1Ome6uF/7ii3HO/c1sNJcZ7w/uO+/x4r/c6mH86wCdswipz?= =?us-ascii?Q?aldp4bMhcrKJgBP8QXEvR4urWHCXjYFc1EiOb2skGnh2eQKMH0bZJIcaKGKC?= =?us-ascii?Q?gr2sxhcNG/YPanKjXqnKIBdRHcQ05l1vD8GVaWOg1QlJh1Uit85v6v2qUlpj?= =?us-ascii?Q?RbDCeds7eTs7s/kq7DdzEAH6lOxE9CxNBoBRLMhosTc/CPM94qw84HClr4wz?= =?us-ascii?Q?CYj9CDeo7VwqOvJdi9E5Ac9fJAomIOC3QlH1ZwlTGt0dy6LnXroueTPp15Iv?= =?us-ascii?Q?Yx/lAGn4mu17qfEfNIr7DweZOXXVC4i+fty39Ckwi/CVBENlBkJcV6XAP+1G?= =?us-ascii?Q?8Vox9+dBEmzEnqq+0apbmWkEKzV0BQJF1WWDfjFJ4o6Zk3mV32OKukDhmssg?= =?us-ascii?Q?cDiFewIXiKt0Iq4caTS+Y73ztrwKZc6dq0izRokC6mOc463eLonZ3mWXwcUQ?= =?us-ascii?Q?Hqy4BakyA=3D?= X-Microsoft-Exchange-Diagnostics: 1;DB4PR05MB271;5:oqn7rz496ouu1s7sDe4KOVeOxusub1YNBOKjewl6Pp8B14nFm28lu08+toMwQHDCmoj4dNcTxC+NYKKoBusaymVCaUkDiQikuDh3pltFu8jl8GIVQbxCN97ItpriXLKzFiJfuDJCxziut+MAh6CFTQ==;24:IMRg2KoHeErIHrVyC0Snxs5ZY3sIEzTEHQZkFhQUTP59763dZTH0WpxsYRyQCACUJ8HAOTq3Kz4hcKqFDLQIq9PRL6jDypSz9jng8mHlgh8= SpamDiagnosticOutput: 1:23 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: toradex.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Dec 2015 05:55:58.0999 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB4PR05MB271 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3141 Lines: 82 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 | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/drivers/spi/spi-fsl-dspi.c b/drivers/spi/spi-fsl-dspi.c index 59a1143..39412c9 100644 --- a/drivers/spi/spi-fsl-dspi.c +++ b/drivers/spi/spi-fsl-dspi.c @@ -167,7 +167,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; } @@ -257,7 +257,7 @@ static u32 dspi_data_to_pushr(struct fsl_dspi *dspi, int tx_word) return SPI_PUSHR_TXDATA(d16) | SPI_PUSHR_PCS(dspi->cs) | - SPI_PUSHR_CTAS(dspi->cs) | + SPI_PUSHR_CTAS(0) | SPI_PUSHR_CONT; } @@ -290,7 +290,7 @@ static int dspi_eoq_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; } @@ -339,7 +339,7 @@ static int dspi_tcfq_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; } @@ -407,7 +407,7 @@ 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); trans_mode = dspi->devtype_data->trans_mode; @@ -566,7 +566,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), + SPI_CTAR(0), SPI_FRAME_BITS_MASK, SPI_FRAME_BITS(16)); dspi->dataflags &= ~TRAN_STATE_WORD_ODD_NUM; -- 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/