diff options
author | Paul Mackerras <paulus@samba.org> | 2008-12-03 04:11:06 -0500 |
---|---|---|
committer | Paul Mackerras <paulus@samba.org> | 2008-12-03 04:11:06 -0500 |
commit | 527491885554002837b5742202adc0ab5f536e54 (patch) | |
tree | 6d9c44776e0b4368eccd414b92b957fac3c5a4c6 /drivers/spi | |
parent | cea555d384b85271035814c5adad23e6c7fc5d2a (diff) | |
parent | 2434bbb30e79468c49cff3cff6005236f55ed188 (diff) |
Merge branch 'merge'
Diffstat (limited to 'drivers/spi')
-rw-r--r-- | drivers/spi/au1550_spi.c | 26 | ||||
-rw-r--r-- | drivers/spi/mpc52xx_psc_spi.c | 5 | ||||
-rw-r--r-- | drivers/spi/pxa2xx_spi.c | 24 | ||||
-rw-r--r-- | drivers/spi/spi_imx.c | 70 | ||||
-rw-r--r-- | drivers/spi/spi_s3c24xx_gpio.c | 3 | ||||
-rw-r--r-- | drivers/spi/spidev.c | 4 |
6 files changed, 72 insertions, 60 deletions
diff --git a/drivers/spi/au1550_spi.c b/drivers/spi/au1550_spi.c index 87b73e0169c5..b02f25c702fd 100644 --- a/drivers/spi/au1550_spi.c +++ b/drivers/spi/au1550_spi.c | |||
@@ -369,10 +369,23 @@ static int au1550_spi_dma_txrxb(struct spi_device *spi, struct spi_transfer *t) | |||
369 | dma_rx_addr = t->rx_dma; | 369 | dma_rx_addr = t->rx_dma; |
370 | 370 | ||
371 | /* | 371 | /* |
372 | * check if buffers are already dma mapped, map them otherwise | 372 | * check if buffers are already dma mapped, map them otherwise: |
373 | * - first map the TX buffer, so cache data gets written to memory | ||
374 | * - then map the RX buffer, so that cache entries (with | ||
375 | * soon-to-be-stale data) get removed | ||
373 | * use rx buffer in place of tx if tx buffer was not provided | 376 | * use rx buffer in place of tx if tx buffer was not provided |
374 | * use temp rx buffer (preallocated or realloc to fit) for rx dma | 377 | * use temp rx buffer (preallocated or realloc to fit) for rx dma |
375 | */ | 378 | */ |
379 | if (t->tx_buf) { | ||
380 | if (t->tx_dma == 0) { /* if DMA_ADDR_INVALID, map it */ | ||
381 | dma_tx_addr = dma_map_single(hw->dev, | ||
382 | (void *)t->tx_buf, | ||
383 | t->len, DMA_TO_DEVICE); | ||
384 | if (dma_mapping_error(hw->dev, dma_tx_addr)) | ||
385 | dev_err(hw->dev, "tx dma map error\n"); | ||
386 | } | ||
387 | } | ||
388 | |||
376 | if (t->rx_buf) { | 389 | if (t->rx_buf) { |
377 | if (t->rx_dma == 0) { /* if DMA_ADDR_INVALID, map it */ | 390 | if (t->rx_dma == 0) { /* if DMA_ADDR_INVALID, map it */ |
378 | dma_rx_addr = dma_map_single(hw->dev, | 391 | dma_rx_addr = dma_map_single(hw->dev, |
@@ -396,15 +409,8 @@ static int au1550_spi_dma_txrxb(struct spi_device *spi, struct spi_transfer *t) | |||
396 | dma_sync_single_for_device(hw->dev, dma_rx_addr, | 409 | dma_sync_single_for_device(hw->dev, dma_rx_addr, |
397 | t->len, DMA_FROM_DEVICE); | 410 | t->len, DMA_FROM_DEVICE); |
398 | } | 411 | } |
399 | if (t->tx_buf) { | 412 | |
400 | if (t->tx_dma == 0) { /* if DMA_ADDR_INVALID, map it */ | 413 | if (!t->tx_buf) { |
401 | dma_tx_addr = dma_map_single(hw->dev, | ||
402 | (void *)t->tx_buf, | ||
403 | t->len, DMA_TO_DEVICE); | ||
404 | if (dma_mapping_error(hw->dev, dma_tx_addr)) | ||
405 | dev_err(hw->dev, "tx dma map error\n"); | ||
406 | } | ||
407 | } else { | ||
408 | dma_sync_single_for_device(hw->dev, dma_rx_addr, | 414 | dma_sync_single_for_device(hw->dev, dma_rx_addr, |
409 | t->len, DMA_BIDIRECTIONAL); | 415 | t->len, DMA_BIDIRECTIONAL); |
410 | hw->tx = hw->rx; | 416 | hw->tx = hw->rx; |
diff --git a/drivers/spi/mpc52xx_psc_spi.c b/drivers/spi/mpc52xx_psc_spi.c index 0debe11b67b4..3b97803e1d11 100644 --- a/drivers/spi/mpc52xx_psc_spi.c +++ b/drivers/spi/mpc52xx_psc_spi.c | |||
@@ -142,6 +142,7 @@ static int mpc52xx_psc_spi_transfer_rxtx(struct spi_device *spi, | |||
142 | unsigned rfalarm; | 142 | unsigned rfalarm; |
143 | unsigned send_at_once = MPC52xx_PSC_BUFSIZE; | 143 | unsigned send_at_once = MPC52xx_PSC_BUFSIZE; |
144 | unsigned recv_at_once; | 144 | unsigned recv_at_once; |
145 | int last_block = 0; | ||
145 | 146 | ||
146 | if (!t->tx_buf && !t->rx_buf && t->len) | 147 | if (!t->tx_buf && !t->rx_buf && t->len) |
147 | return -EINVAL; | 148 | return -EINVAL; |
@@ -151,15 +152,17 @@ static int mpc52xx_psc_spi_transfer_rxtx(struct spi_device *spi, | |||
151 | while (rb < t->len) { | 152 | while (rb < t->len) { |
152 | if (t->len - rb > MPC52xx_PSC_BUFSIZE) { | 153 | if (t->len - rb > MPC52xx_PSC_BUFSIZE) { |
153 | rfalarm = MPC52xx_PSC_RFALARM; | 154 | rfalarm = MPC52xx_PSC_RFALARM; |
155 | last_block = 0; | ||
154 | } else { | 156 | } else { |
155 | send_at_once = t->len - sb; | 157 | send_at_once = t->len - sb; |
156 | rfalarm = MPC52xx_PSC_BUFSIZE - (t->len - rb); | 158 | rfalarm = MPC52xx_PSC_BUFSIZE - (t->len - rb); |
159 | last_block = 1; | ||
157 | } | 160 | } |
158 | 161 | ||
159 | dev_dbg(&spi->dev, "send %d bytes...\n", send_at_once); | 162 | dev_dbg(&spi->dev, "send %d bytes...\n", send_at_once); |
160 | for (; send_at_once; sb++, send_at_once--) { | 163 | for (; send_at_once; sb++, send_at_once--) { |
161 | /* set EOF flag before the last word is sent */ | 164 | /* set EOF flag before the last word is sent */ |
162 | if (send_at_once == 1) | 165 | if (send_at_once == 1 && last_block) |
163 | out_8(&psc->ircr2, 0x01); | 166 | out_8(&psc->ircr2, 0x01); |
164 | 167 | ||
165 | if (tx_buf) | 168 | if (tx_buf) |
diff --git a/drivers/spi/pxa2xx_spi.c b/drivers/spi/pxa2xx_spi.c index dae87b1a4c6e..cf12f2d84be2 100644 --- a/drivers/spi/pxa2xx_spi.c +++ b/drivers/spi/pxa2xx_spi.c | |||
@@ -352,21 +352,21 @@ static int map_dma_buffers(struct driver_data *drv_data) | |||
352 | } else | 352 | } else |
353 | drv_data->tx_map_len = drv_data->len; | 353 | drv_data->tx_map_len = drv_data->len; |
354 | 354 | ||
355 | /* Stream map the rx buffer */ | 355 | /* Stream map the tx buffer. Always do DMA_TO_DEVICE first |
356 | drv_data->rx_dma = dma_map_single(dev, drv_data->rx, | 356 | * so we flush the cache *before* invalidating it, in case |
357 | drv_data->rx_map_len, | 357 | * the tx and rx buffers overlap. |
358 | DMA_FROM_DEVICE); | 358 | */ |
359 | if (dma_mapping_error(dev, drv_data->rx_dma)) | ||
360 | return 0; | ||
361 | |||
362 | /* Stream map the tx buffer */ | ||
363 | drv_data->tx_dma = dma_map_single(dev, drv_data->tx, | 359 | drv_data->tx_dma = dma_map_single(dev, drv_data->tx, |
364 | drv_data->tx_map_len, | 360 | drv_data->tx_map_len, DMA_TO_DEVICE); |
365 | DMA_TO_DEVICE); | 361 | if (dma_mapping_error(dev, drv_data->tx_dma)) |
362 | return 0; | ||
366 | 363 | ||
367 | if (dma_mapping_error(dev, drv_data->tx_dma)) { | 364 | /* Stream map the rx buffer */ |
368 | dma_unmap_single(dev, drv_data->rx_dma, | 365 | drv_data->rx_dma = dma_map_single(dev, drv_data->rx, |
369 | drv_data->rx_map_len, DMA_FROM_DEVICE); | 366 | drv_data->rx_map_len, DMA_FROM_DEVICE); |
367 | if (dma_mapping_error(dev, drv_data->rx_dma)) { | ||
368 | dma_unmap_single(dev, drv_data->tx_dma, | ||
369 | drv_data->tx_map_len, DMA_TO_DEVICE); | ||
370 | return 0; | 370 | return 0; |
371 | } | 371 | } |
372 | 372 | ||
diff --git a/drivers/spi/spi_imx.c b/drivers/spi/spi_imx.c index 61ba147e384d..269a55ec52ef 100644 --- a/drivers/spi/spi_imx.c +++ b/drivers/spi/spi_imx.c | |||
@@ -506,20 +506,6 @@ static int map_dma_buffers(struct driver_data *drv_data) | |||
506 | if (!IS_DMA_ALIGNED(drv_data->rx) || !IS_DMA_ALIGNED(drv_data->tx)) | 506 | if (!IS_DMA_ALIGNED(drv_data->rx) || !IS_DMA_ALIGNED(drv_data->tx)) |
507 | return -1; | 507 | return -1; |
508 | 508 | ||
509 | /* NULL rx means write-only transfer and no map needed | ||
510 | since rx DMA will not be used */ | ||
511 | if (drv_data->rx) { | ||
512 | buf = drv_data->rx; | ||
513 | drv_data->rx_dma = dma_map_single( | ||
514 | dev, | ||
515 | buf, | ||
516 | drv_data->len, | ||
517 | DMA_FROM_DEVICE); | ||
518 | if (dma_mapping_error(dev, drv_data->rx_dma)) | ||
519 | return -1; | ||
520 | drv_data->rx_dma_needs_unmap = 1; | ||
521 | } | ||
522 | |||
523 | if (drv_data->tx == NULL) { | 509 | if (drv_data->tx == NULL) { |
524 | /* Read only message --> use drv_data->dummy_dma_buf for dummy | 510 | /* Read only message --> use drv_data->dummy_dma_buf for dummy |
525 | writes to achive reads */ | 511 | writes to achive reads */ |
@@ -533,18 +519,31 @@ static int map_dma_buffers(struct driver_data *drv_data) | |||
533 | buf, | 519 | buf, |
534 | drv_data->tx_map_len, | 520 | drv_data->tx_map_len, |
535 | DMA_TO_DEVICE); | 521 | DMA_TO_DEVICE); |
536 | if (dma_mapping_error(dev, drv_data->tx_dma)) { | 522 | if (dma_mapping_error(dev, drv_data->tx_dma)) |
537 | if (drv_data->rx_dma) { | ||
538 | dma_unmap_single(dev, | ||
539 | drv_data->rx_dma, | ||
540 | drv_data->len, | ||
541 | DMA_FROM_DEVICE); | ||
542 | drv_data->rx_dma_needs_unmap = 0; | ||
543 | } | ||
544 | return -1; | 523 | return -1; |
545 | } | ||
546 | drv_data->tx_dma_needs_unmap = 1; | 524 | drv_data->tx_dma_needs_unmap = 1; |
547 | 525 | ||
526 | /* NULL rx means write-only transfer and no map needed | ||
527 | * since rx DMA will not be used */ | ||
528 | if (drv_data->rx) { | ||
529 | buf = drv_data->rx; | ||
530 | drv_data->rx_dma = dma_map_single(dev, | ||
531 | buf, | ||
532 | drv_data->len, | ||
533 | DMA_FROM_DEVICE); | ||
534 | if (dma_mapping_error(dev, drv_data->rx_dma)) { | ||
535 | if (drv_data->tx_dma) { | ||
536 | dma_unmap_single(dev, | ||
537 | drv_data->tx_dma, | ||
538 | drv_data->tx_map_len, | ||
539 | DMA_TO_DEVICE); | ||
540 | drv_data->tx_dma_needs_unmap = 0; | ||
541 | } | ||
542 | return -1; | ||
543 | } | ||
544 | drv_data->rx_dma_needs_unmap = 1; | ||
545 | } | ||
546 | |||
548 | return 0; | 547 | return 0; |
549 | } | 548 | } |
550 | 549 | ||
@@ -1457,7 +1456,7 @@ static int __init spi_imx_probe(struct platform_device *pdev) | |||
1457 | struct device *dev = &pdev->dev; | 1456 | struct device *dev = &pdev->dev; |
1458 | struct spi_imx_master *platform_info; | 1457 | struct spi_imx_master *platform_info; |
1459 | struct spi_master *master; | 1458 | struct spi_master *master; |
1460 | struct driver_data *drv_data = NULL; | 1459 | struct driver_data *drv_data; |
1461 | struct resource *res; | 1460 | struct resource *res; |
1462 | int irq, status = 0; | 1461 | int irq, status = 0; |
1463 | 1462 | ||
@@ -1468,14 +1467,6 @@ static int __init spi_imx_probe(struct platform_device *pdev) | |||
1468 | goto err_no_pdata; | 1467 | goto err_no_pdata; |
1469 | } | 1468 | } |
1470 | 1469 | ||
1471 | drv_data->clk = clk_get(&pdev->dev, "perclk2"); | ||
1472 | if (IS_ERR(drv_data->clk)) { | ||
1473 | dev_err(&pdev->dev, "probe - cannot get get\n"); | ||
1474 | status = PTR_ERR(drv_data->clk); | ||
1475 | goto err_no_clk; | ||
1476 | } | ||
1477 | clk_enable(drv_data->clk); | ||
1478 | |||
1479 | /* Allocate master with space for drv_data */ | 1470 | /* Allocate master with space for drv_data */ |
1480 | master = spi_alloc_master(dev, sizeof(struct driver_data)); | 1471 | master = spi_alloc_master(dev, sizeof(struct driver_data)); |
1481 | if (!master) { | 1472 | if (!master) { |
@@ -1496,6 +1487,14 @@ static int __init spi_imx_probe(struct platform_device *pdev) | |||
1496 | 1487 | ||
1497 | drv_data->dummy_dma_buf = SPI_DUMMY_u32; | 1488 | drv_data->dummy_dma_buf = SPI_DUMMY_u32; |
1498 | 1489 | ||
1490 | drv_data->clk = clk_get(&pdev->dev, "perclk2"); | ||
1491 | if (IS_ERR(drv_data->clk)) { | ||
1492 | dev_err(&pdev->dev, "probe - cannot get clock\n"); | ||
1493 | status = PTR_ERR(drv_data->clk); | ||
1494 | goto err_no_clk; | ||
1495 | } | ||
1496 | clk_enable(drv_data->clk); | ||
1497 | |||
1499 | /* Find and map resources */ | 1498 | /* Find and map resources */ |
1500 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); | 1499 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
1501 | if (!res) { | 1500 | if (!res) { |
@@ -1631,12 +1630,13 @@ err_no_iomap: | |||
1631 | kfree(drv_data->ioarea); | 1630 | kfree(drv_data->ioarea); |
1632 | 1631 | ||
1633 | err_no_iores: | 1632 | err_no_iores: |
1634 | spi_master_put(master); | ||
1635 | |||
1636 | err_no_pdata: | ||
1637 | clk_disable(drv_data->clk); | 1633 | clk_disable(drv_data->clk); |
1638 | clk_put(drv_data->clk); | 1634 | clk_put(drv_data->clk); |
1635 | |||
1639 | err_no_clk: | 1636 | err_no_clk: |
1637 | spi_master_put(master); | ||
1638 | |||
1639 | err_no_pdata: | ||
1640 | err_no_mem: | 1640 | err_no_mem: |
1641 | return status; | 1641 | return status; |
1642 | } | 1642 | } |
diff --git a/drivers/spi/spi_s3c24xx_gpio.c b/drivers/spi/spi_s3c24xx_gpio.c index cc1f647f579b..f2447a5476bb 100644 --- a/drivers/spi/spi_s3c24xx_gpio.c +++ b/drivers/spi/spi_s3c24xx_gpio.c | |||
@@ -34,7 +34,7 @@ struct s3c2410_spigpio { | |||
34 | 34 | ||
35 | static inline struct s3c2410_spigpio *spidev_to_sg(struct spi_device *spi) | 35 | static inline struct s3c2410_spigpio *spidev_to_sg(struct spi_device *spi) |
36 | { | 36 | { |
37 | return spi->controller_data; | 37 | return spi_master_get_devdata(spi->master); |
38 | } | 38 | } |
39 | 39 | ||
40 | static inline void setsck(struct spi_device *dev, int on) | 40 | static inline void setsck(struct spi_device *dev, int on) |
@@ -118,6 +118,7 @@ static int s3c2410_spigpio_probe(struct platform_device *dev) | |||
118 | /* setup spi bitbang adaptor */ | 118 | /* setup spi bitbang adaptor */ |
119 | sp->bitbang.master = spi_master_get(master); | 119 | sp->bitbang.master = spi_master_get(master); |
120 | sp->bitbang.master->bus_num = info->bus_num; | 120 | sp->bitbang.master->bus_num = info->bus_num; |
121 | sp->bitbang.master->num_chipselect = info->num_chipselect; | ||
121 | sp->bitbang.chipselect = s3c2410_spigpio_chipselect; | 122 | sp->bitbang.chipselect = s3c2410_spigpio_chipselect; |
122 | 123 | ||
123 | sp->bitbang.txrx_word[SPI_MODE_0] = s3c2410_spigpio_txrx_mode0; | 124 | sp->bitbang.txrx_word[SPI_MODE_0] = s3c2410_spigpio_txrx_mode0; |
diff --git a/drivers/spi/spidev.c b/drivers/spi/spidev.c index 89a43755a453..5d869c4d3eb2 100644 --- a/drivers/spi/spidev.c +++ b/drivers/spi/spidev.c | |||
@@ -597,7 +597,9 @@ static int spidev_probe(struct spi_device *spi) | |||
597 | } | 597 | } |
598 | mutex_unlock(&device_list_lock); | 598 | mutex_unlock(&device_list_lock); |
599 | 599 | ||
600 | if (status != 0) | 600 | if (status == 0) |
601 | spi_set_drvdata(spi, spidev); | ||
602 | else | ||
601 | kfree(spidev); | 603 | kfree(spidev); |
602 | 604 | ||
603 | return status; | 605 | return status; |