aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/spi/spi-fsl-cpm.c
diff options
context:
space:
mode:
authorChristophe Leroy <christophe.leroy@c-s.fr>2015-04-22 10:28:20 -0400
committerMark Brown <broonie@kernel.org>2015-04-22 15:46:45 -0400
commit575bec53181526ed01c0936ec008e1b70f8f5f31 (patch)
tree4d3f871549e505cb598dd73154e356b2ef1c8d93 /drivers/spi/spi-fsl-cpm.c
parentc517d838eb7d07bbe9507871fab3931deccff539 (diff)
spi: fsl-spi: use devm_ioremap_resource() to map parameter ram on CPM1
On CPM2, the SPI parameter RAM is dynamically allocated in the dualport RAM whereas in CPM1, it is statically allocated to a default address with capability to relocate it somewhere else via the use of CPM micropatch. The address of the parameter RAM is given by the boot loader and expected to be mapped via devm_ioremap_resource() In the current implementation, in function fsl_spi_cpm_get_pram() there is a confusion between the SPI_BASE register and the base of the SPI parameter RAM. Fortunatly, it is working properly with MPC866 and MPC885 because they do set SPI_BASE, but on MPC860 and other old MPC8xx that doesn't set SPI_BASE, pram_ofs is not properly set. Also, the parameter RAM is not properly mapped with devm_ioremap_resource() as it should but still gets accessible by chance through the full RAM which is mapped from somewhere else. This patch applies to the SPI driver the same principle as for the CPM UART: when the CPM is of type CPM1, we simply do an devm_ioremap_resource() of the area provided via the device tree. Signed-off-by: Christophe Leroy <christophe.leroy@c-s.fr> Signed-off-by: Mark Brown <broonie@kernel.org>
Diffstat (limited to 'drivers/spi/spi-fsl-cpm.c')
-rw-r--r--drivers/spi/spi-fsl-cpm.c35
1 files changed, 18 insertions, 17 deletions
diff --git a/drivers/spi/spi-fsl-cpm.c b/drivers/spi/spi-fsl-cpm.c
index 9c46a3058743..6f466ab1201a 100644
--- a/drivers/spi/spi-fsl-cpm.c
+++ b/drivers/spi/spi-fsl-cpm.c
@@ -24,6 +24,7 @@
24#include <linux/of_address.h> 24#include <linux/of_address.h>
25#include <linux/spi/spi.h> 25#include <linux/spi/spi.h>
26#include <linux/types.h> 26#include <linux/types.h>
27#include <linux/platform_device.h>
27 28
28#include "spi-fsl-cpm.h" 29#include "spi-fsl-cpm.h"
29#include "spi-fsl-lib.h" 30#include "spi-fsl-lib.h"
@@ -269,17 +270,6 @@ static unsigned long fsl_spi_cpm_get_pram(struct mpc8xxx_spi *mspi)
269 if (mspi->flags & SPI_CPM2) { 270 if (mspi->flags & SPI_CPM2) {
270 pram_ofs = cpm_muram_alloc(SPI_PRAM_SIZE, 64); 271 pram_ofs = cpm_muram_alloc(SPI_PRAM_SIZE, 64);
271 out_be16(spi_base, pram_ofs); 272 out_be16(spi_base, pram_ofs);
272 } else {
273 struct spi_pram __iomem *pram = spi_base;
274 u16 rpbase = in_be16(&pram->rpbase);
275
276 /* Microcode relocation patch applied? */
277 if (rpbase) {
278 pram_ofs = rpbase;
279 } else {
280 pram_ofs = cpm_muram_alloc(SPI_PRAM_SIZE, 64);
281 out_be16(spi_base, pram_ofs);
282 }
283 } 273 }
284 274
285 iounmap(spi_base); 275 iounmap(spi_base);
@@ -292,7 +282,6 @@ int fsl_spi_cpm_init(struct mpc8xxx_spi *mspi)
292 struct device_node *np = dev->of_node; 282 struct device_node *np = dev->of_node;
293 const u32 *iprop; 283 const u32 *iprop;
294 int size; 284 int size;
295 unsigned long pram_ofs;
296 unsigned long bds_ofs; 285 unsigned long bds_ofs;
297 286
298 if (!(mspi->flags & SPI_CPM_MODE)) 287 if (!(mspi->flags & SPI_CPM_MODE))
@@ -319,8 +308,21 @@ int fsl_spi_cpm_init(struct mpc8xxx_spi *mspi)
319 } 308 }
320 } 309 }
321 310
322 pram_ofs = fsl_spi_cpm_get_pram(mspi); 311 if (mspi->flags & SPI_CPM1) {
323 if (IS_ERR_VALUE(pram_ofs)) { 312 struct resource *res;
313
314 res = platform_get_resource(to_platform_device(dev),
315 IORESOURCE_MEM, 1);
316 mspi->pram = devm_ioremap_resource(dev, res);
317 } else {
318 unsigned long pram_ofs = fsl_spi_cpm_get_pram(mspi);
319
320 if (IS_ERR_VALUE(pram_ofs))
321 mspi->pram = NULL;
322 else
323 mspi->pram = cpm_muram_addr(pram_ofs);
324 }
325 if (mspi->pram == NULL) {
324 dev_err(dev, "can't allocate spi parameter ram\n"); 326 dev_err(dev, "can't allocate spi parameter ram\n");
325 goto err_pram; 327 goto err_pram;
326 } 328 }
@@ -346,8 +348,6 @@ int fsl_spi_cpm_init(struct mpc8xxx_spi *mspi)
346 goto err_dummy_rx; 348 goto err_dummy_rx;
347 } 349 }
348 350
349 mspi->pram = cpm_muram_addr(pram_ofs);
350
351 mspi->tx_bd = cpm_muram_addr(bds_ofs); 351 mspi->tx_bd = cpm_muram_addr(bds_ofs);
352 mspi->rx_bd = cpm_muram_addr(bds_ofs + sizeof(*mspi->tx_bd)); 352 mspi->rx_bd = cpm_muram_addr(bds_ofs + sizeof(*mspi->tx_bd));
353 353
@@ -375,7 +375,8 @@ err_dummy_rx:
375err_dummy_tx: 375err_dummy_tx:
376 cpm_muram_free(bds_ofs); 376 cpm_muram_free(bds_ofs);
377err_bds: 377err_bds:
378 cpm_muram_free(pram_ofs); 378 if (!(mspi->flags & SPI_CPM1))
379 cpm_muram_free(cpm_muram_offset(mspi->pram));
379err_pram: 380err_pram:
380 fsl_spi_free_dummy_rx(); 381 fsl_spi_free_dummy_rx();
381 return -ENOMEM; 382 return -ENOMEM;