aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/spi/spi-fsl-cpm.c
diff options
context:
space:
mode:
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;