Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

spi/pl022: add PrimeCell generic DMA support

This extends the PL022 SSP/SPI driver with generic DMA engine
support using the PrimeCell DMA engine interface. Also fix up the
test code for the U300 platform.

Signed-off-by: Linus Walleij <linus.walleij@stericsson.com>
Signed-off-by: Grant Likely <grant.likely@secretlab.ca>

authored by

Linus Walleij and committed by
Grant Likely
b1b6b9aa cdbc8f04

+437 -91
+431 -91
drivers/spi/amba-pl022.c
··· 27 27 /* 28 28 * TODO: 29 29 * - add timeout on polled transfers 30 - * - add generic DMA framework support 31 30 */ 32 31 33 32 #include <linux/init.h> ··· 44 45 #include <linux/amba/pl022.h> 45 46 #include <linux/io.h> 46 47 #include <linux/slab.h> 48 + #include <linux/dmaengine.h> 49 + #include <linux/dma-mapping.h> 50 + #include <linux/scatterlist.h> 47 51 48 52 /* 49 53 * This macro is used to define some register default values. ··· 383 381 enum ssp_reading read; 384 382 enum ssp_writing write; 385 383 u32 exp_fifo_level; 384 + /* DMA settings */ 385 + #ifdef CONFIG_DMA_ENGINE 386 + struct dma_chan *dma_rx_channel; 387 + struct dma_chan *dma_tx_channel; 388 + struct sg_table sgt_rx; 389 + struct sg_table sgt_tx; 390 + char *dummypage; 391 + #endif 386 392 }; 387 393 388 394 /** ··· 416 406 u16 dmacr; 417 407 u16 cpsr; 418 408 u8 n_bytes; 419 - u8 enable_dma:1; 409 + bool enable_dma; 420 410 enum ssp_reading read; 421 411 enum ssp_writing write; 422 412 void (*cs_control) (u32 command); ··· 773 763 } 774 764 return STATE_DONE; 775 765 } 766 + 767 + /* 768 + * This DMA functionality is only compiled in if we have 769 + * access to the generic DMA devices/DMA engine. 770 + */ 771 + #ifdef CONFIG_DMA_ENGINE 772 + static void unmap_free_dma_scatter(struct pl022 *pl022) 773 + { 774 + /* Unmap and free the SG tables */ 775 + dma_unmap_sg(&pl022->adev->dev, pl022->sgt_tx.sgl, 776 + pl022->sgt_tx.nents, DMA_TO_DEVICE); 777 + dma_unmap_sg(&pl022->adev->dev, pl022->sgt_rx.sgl, 778 + pl022->sgt_rx.nents, DMA_FROM_DEVICE); 779 + sg_free_table(&pl022->sgt_rx); 780 + sg_free_table(&pl022->sgt_tx); 781 + } 782 + 783 + static void dma_callback(void *data) 784 + { 785 + struct pl022 *pl022 = data; 786 + struct spi_message *msg = pl022->cur_msg; 787 + 788 + BUG_ON(!pl022->sgt_rx.sgl); 789 + 790 + #ifdef VERBOSE_DEBUG 791 + /* 792 + * Optionally dump out buffers to inspect contents, this is 793 + * good if you want to convince yourself that the loopback 794 + * read/write contents are the same, when adopting to a new 795 + * DMA engine. 796 + */ 797 + { 798 + struct scatterlist *sg; 799 + unsigned int i; 800 + 801 + dma_sync_sg_for_cpu(&pl022->adev->dev, 802 + pl022->sgt_rx.sgl, 803 + pl022->sgt_rx.nents, 804 + DMA_FROM_DEVICE); 805 + 806 + for_each_sg(pl022->sgt_rx.sgl, sg, pl022->sgt_rx.nents, i) { 807 + dev_dbg(&pl022->adev->dev, "SPI RX SG ENTRY: %d", i); 808 + print_hex_dump(KERN_ERR, "SPI RX: ", 809 + DUMP_PREFIX_OFFSET, 810 + 16, 811 + 1, 812 + sg_virt(sg), 813 + sg_dma_len(sg), 814 + 1); 815 + } 816 + for_each_sg(pl022->sgt_tx.sgl, sg, pl022->sgt_tx.nents, i) { 817 + dev_dbg(&pl022->adev->dev, "SPI TX SG ENTRY: %d", i); 818 + print_hex_dump(KERN_ERR, "SPI TX: ", 819 + DUMP_PREFIX_OFFSET, 820 + 16, 821 + 1, 822 + sg_virt(sg), 823 + sg_dma_len(sg), 824 + 1); 825 + } 826 + } 827 + #endif 828 + 829 + unmap_free_dma_scatter(pl022); 830 + 831 + /* Update total bytes transfered */ 832 + msg->actual_length += pl022->cur_transfer->len; 833 + if (pl022->cur_transfer->cs_change) 834 + pl022->cur_chip-> 835 + cs_control(SSP_CHIP_DESELECT); 836 + 837 + /* Move to next transfer */ 838 + msg->state = next_transfer(pl022); 839 + tasklet_schedule(&pl022->pump_transfers); 840 + } 841 + 842 + static void setup_dma_scatter(struct pl022 *pl022, 843 + void *buffer, 844 + unsigned int length, 845 + struct sg_table *sgtab) 846 + { 847 + struct scatterlist *sg; 848 + int bytesleft = length; 849 + void *bufp = buffer; 850 + int mapbytes; 851 + int i; 852 + 853 + if (buffer) { 854 + for_each_sg(sgtab->sgl, sg, sgtab->nents, i) { 855 + /* 856 + * If there are less bytes left than what fits 857 + * in the current page (plus page alignment offset) 858 + * we just feed in this, else we stuff in as much 859 + * as we can. 860 + */ 861 + if (bytesleft < (PAGE_SIZE - offset_in_page(bufp))) 862 + mapbytes = bytesleft; 863 + else 864 + mapbytes = PAGE_SIZE - offset_in_page(bufp); 865 + sg_set_page(sg, virt_to_page(bufp), 866 + mapbytes, offset_in_page(bufp)); 867 + bufp += mapbytes; 868 + bytesleft -= mapbytes; 869 + dev_dbg(&pl022->adev->dev, 870 + "set RX/TX target page @ %p, %d bytes, %d left\n", 871 + bufp, mapbytes, bytesleft); 872 + } 873 + } else { 874 + /* Map the dummy buffer on every page */ 875 + for_each_sg(sgtab->sgl, sg, sgtab->nents, i) { 876 + if (bytesleft < PAGE_SIZE) 877 + mapbytes = bytesleft; 878 + else 879 + mapbytes = PAGE_SIZE; 880 + sg_set_page(sg, virt_to_page(pl022->dummypage), 881 + mapbytes, 0); 882 + bytesleft -= mapbytes; 883 + dev_dbg(&pl022->adev->dev, 884 + "set RX/TX to dummy page %d bytes, %d left\n", 885 + mapbytes, bytesleft); 886 + 887 + } 888 + } 889 + BUG_ON(bytesleft); 890 + } 891 + 892 + /** 893 + * configure_dma - configures the channels for the next transfer 894 + * @pl022: SSP driver's private data structure 895 + */ 896 + static int configure_dma(struct pl022 *pl022) 897 + { 898 + struct dma_slave_config rx_conf = { 899 + .src_addr = SSP_DR(pl022->phybase), 900 + .direction = DMA_FROM_DEVICE, 901 + .src_maxburst = pl022->vendor->fifodepth >> 1, 902 + }; 903 + struct dma_slave_config tx_conf = { 904 + .dst_addr = SSP_DR(pl022->phybase), 905 + .direction = DMA_TO_DEVICE, 906 + .dst_maxburst = pl022->vendor->fifodepth >> 1, 907 + }; 908 + unsigned int pages; 909 + int ret; 910 + int sglen; 911 + struct dma_chan *rxchan = pl022->dma_rx_channel; 912 + struct dma_chan *txchan = pl022->dma_tx_channel; 913 + struct dma_async_tx_descriptor *rxdesc; 914 + struct dma_async_tx_descriptor *txdesc; 915 + dma_cookie_t cookie; 916 + 917 + /* Check that the channels are available */ 918 + if (!rxchan || !txchan) 919 + return -ENODEV; 920 + 921 + switch (pl022->read) { 922 + case READING_NULL: 923 + /* Use the same as for writing */ 924 + rx_conf.src_addr_width = DMA_SLAVE_BUSWIDTH_UNDEFINED; 925 + break; 926 + case READING_U8: 927 + rx_conf.src_addr_width = DMA_SLAVE_BUSWIDTH_1_BYTE; 928 + break; 929 + case READING_U16: 930 + rx_conf.src_addr_width = DMA_SLAVE_BUSWIDTH_2_BYTES; 931 + break; 932 + case READING_U32: 933 + rx_conf.src_addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES; 934 + break; 935 + } 936 + 937 + switch (pl022->write) { 938 + case WRITING_NULL: 939 + /* Use the same as for reading */ 940 + tx_conf.dst_addr_width = DMA_SLAVE_BUSWIDTH_UNDEFINED; 941 + break; 942 + case WRITING_U8: 943 + tx_conf.dst_addr_width = DMA_SLAVE_BUSWIDTH_1_BYTE; 944 + break; 945 + case WRITING_U16: 946 + tx_conf.dst_addr_width = DMA_SLAVE_BUSWIDTH_2_BYTES; 947 + break; 948 + case WRITING_U32: 949 + tx_conf.dst_addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES;; 950 + break; 951 + } 952 + 953 + /* SPI pecularity: we need to read and write the same width */ 954 + if (rx_conf.src_addr_width == DMA_SLAVE_BUSWIDTH_UNDEFINED) 955 + rx_conf.src_addr_width = tx_conf.dst_addr_width; 956 + if (tx_conf.dst_addr_width == DMA_SLAVE_BUSWIDTH_UNDEFINED) 957 + tx_conf.dst_addr_width = rx_conf.src_addr_width; 958 + BUG_ON(rx_conf.src_addr_width != tx_conf.dst_addr_width); 959 + 960 + rxchan->device->device_control(rxchan, DMA_SLAVE_CONFIG, 961 + (unsigned long) &rx_conf); 962 + txchan->device->device_control(txchan, DMA_SLAVE_CONFIG, 963 + (unsigned long) &tx_conf); 964 + 965 + /* Create sglists for the transfers */ 966 + pages = (pl022->cur_transfer->len >> PAGE_SHIFT) + 1; 967 + dev_dbg(&pl022->adev->dev, "using %d pages for transfer\n", pages); 968 + 969 + ret = sg_alloc_table(&pl022->sgt_rx, pages, GFP_KERNEL); 970 + if (ret) 971 + goto err_alloc_rx_sg; 972 + 973 + ret = sg_alloc_table(&pl022->sgt_tx, pages, GFP_KERNEL); 974 + if (ret) 975 + goto err_alloc_tx_sg; 976 + 977 + /* Fill in the scatterlists for the RX+TX buffers */ 978 + setup_dma_scatter(pl022, pl022->rx, 979 + pl022->cur_transfer->len, &pl022->sgt_rx); 980 + setup_dma_scatter(pl022, pl022->tx, 981 + pl022->cur_transfer->len, &pl022->sgt_tx); 982 + 983 + /* Map DMA buffers */ 984 + sglen = dma_map_sg(&pl022->adev->dev, pl022->sgt_rx.sgl, 985 + pl022->sgt_rx.nents, DMA_FROM_DEVICE); 986 + if (!sglen) 987 + goto err_rx_sgmap; 988 + 989 + sglen = dma_map_sg(&pl022->adev->dev, pl022->sgt_tx.sgl, 990 + pl022->sgt_tx.nents, DMA_TO_DEVICE); 991 + if (!sglen) 992 + goto err_tx_sgmap; 993 + 994 + /* Send both scatterlists */ 995 + rxdesc = rxchan->device->device_prep_slave_sg(rxchan, 996 + pl022->sgt_rx.sgl, 997 + pl022->sgt_rx.nents, 998 + DMA_FROM_DEVICE, 999 + DMA_PREP_INTERRUPT | DMA_CTRL_ACK); 1000 + if (!rxdesc) 1001 + goto err_rxdesc; 1002 + 1003 + txdesc = txchan->device->device_prep_slave_sg(txchan, 1004 + pl022->sgt_tx.sgl, 1005 + pl022->sgt_tx.nents, 1006 + DMA_TO_DEVICE, 1007 + DMA_PREP_INTERRUPT | DMA_CTRL_ACK); 1008 + if (!txdesc) 1009 + goto err_txdesc; 1010 + 1011 + /* Put the callback on the RX transfer only, that should finish last */ 1012 + rxdesc->callback = dma_callback; 1013 + rxdesc->callback_param = pl022; 1014 + 1015 + /* Submit and fire RX and TX with TX last so we're ready to read! */ 1016 + cookie = rxdesc->tx_submit(rxdesc); 1017 + if (dma_submit_error(cookie)) 1018 + goto err_submit_rx; 1019 + cookie = txdesc->tx_submit(txdesc); 1020 + if (dma_submit_error(cookie)) 1021 + goto err_submit_tx; 1022 + rxchan->device->device_issue_pending(rxchan); 1023 + txchan->device->device_issue_pending(txchan); 1024 + 1025 + return 0; 1026 + 1027 + err_submit_tx: 1028 + err_submit_rx: 1029 + err_txdesc: 1030 + txchan->device->device_control(txchan, DMA_TERMINATE_ALL, 0); 1031 + err_rxdesc: 1032 + rxchan->device->device_control(rxchan, DMA_TERMINATE_ALL, 0); 1033 + dma_unmap_sg(&pl022->adev->dev, pl022->sgt_tx.sgl, 1034 + pl022->sgt_tx.nents, DMA_TO_DEVICE); 1035 + err_tx_sgmap: 1036 + dma_unmap_sg(&pl022->adev->dev, pl022->sgt_rx.sgl, 1037 + pl022->sgt_tx.nents, DMA_FROM_DEVICE); 1038 + err_rx_sgmap: 1039 + sg_free_table(&pl022->sgt_tx); 1040 + err_alloc_tx_sg: 1041 + sg_free_table(&pl022->sgt_rx); 1042 + err_alloc_rx_sg: 1043 + return -ENOMEM; 1044 + } 1045 + 1046 + static int __init pl022_dma_probe(struct pl022 *pl022) 1047 + { 1048 + dma_cap_mask_t mask; 1049 + 1050 + /* Try to acquire a generic DMA engine slave channel */ 1051 + dma_cap_zero(mask); 1052 + dma_cap_set(DMA_SLAVE, mask); 1053 + /* 1054 + * We need both RX and TX channels to do DMA, else do none 1055 + * of them. 1056 + */ 1057 + pl022->dma_rx_channel = dma_request_channel(mask, 1058 + pl022->master_info->dma_filter, 1059 + pl022->master_info->dma_rx_param); 1060 + if (!pl022->dma_rx_channel) { 1061 + dev_err(&pl022->adev->dev, "no RX DMA channel!\n"); 1062 + goto err_no_rxchan; 1063 + } 1064 + 1065 + pl022->dma_tx_channel = dma_request_channel(mask, 1066 + pl022->master_info->dma_filter, 1067 + pl022->master_info->dma_tx_param); 1068 + if (!pl022->dma_tx_channel) { 1069 + dev_err(&pl022->adev->dev, "no TX DMA channel!\n"); 1070 + goto err_no_txchan; 1071 + } 1072 + 1073 + pl022->dummypage = kmalloc(PAGE_SIZE, GFP_KERNEL); 1074 + if (!pl022->dummypage) { 1075 + dev_err(&pl022->adev->dev, "no DMA dummypage!\n"); 1076 + goto err_no_dummypage; 1077 + } 1078 + 1079 + dev_info(&pl022->adev->dev, "setup for DMA on RX %s, TX %s\n", 1080 + dma_chan_name(pl022->dma_rx_channel), 1081 + dma_chan_name(pl022->dma_tx_channel)); 1082 + 1083 + return 0; 1084 + 1085 + err_no_dummypage: 1086 + dma_release_channel(pl022->dma_tx_channel); 1087 + err_no_txchan: 1088 + dma_release_channel(pl022->dma_rx_channel); 1089 + pl022->dma_rx_channel = NULL; 1090 + err_no_rxchan: 1091 + return -ENODEV; 1092 + } 1093 + 1094 + static void terminate_dma(struct pl022 *pl022) 1095 + { 1096 + struct dma_chan *rxchan = pl022->dma_rx_channel; 1097 + struct dma_chan *txchan = pl022->dma_tx_channel; 1098 + 1099 + rxchan->device->device_control(rxchan, DMA_TERMINATE_ALL, 0); 1100 + txchan->device->device_control(txchan, DMA_TERMINATE_ALL, 0); 1101 + unmap_free_dma_scatter(pl022); 1102 + } 1103 + 1104 + static void pl022_dma_remove(struct pl022 *pl022) 1105 + { 1106 + if (pl022->busy) 1107 + terminate_dma(pl022); 1108 + if (pl022->dma_tx_channel) 1109 + dma_release_channel(pl022->dma_tx_channel); 1110 + if (pl022->dma_rx_channel) 1111 + dma_release_channel(pl022->dma_rx_channel); 1112 + kfree(pl022->dummypage); 1113 + } 1114 + 1115 + #else 1116 + static inline int configure_dma(struct pl022 *pl022) 1117 + { 1118 + return -ENODEV; 1119 + } 1120 + 1121 + static inline int pl022_dma_probe(struct pl022 *pl022) 1122 + { 1123 + return 0; 1124 + } 1125 + 1126 + static inline void pl022_dma_remove(struct pl022 *pl022) 1127 + { 1128 + } 1129 + #endif 1130 + 776 1131 /** 777 1132 * pl022_interrupt_handler - Interrupt handler for SSP controller 778 1133 * ··· 1169 794 if (unlikely(!irq_status)) 1170 795 return IRQ_NONE; 1171 796 1172 - /* This handles the error code interrupts */ 797 + /* 798 + * This handles the FIFO interrupts, the timeout 799 + * interrupts are flatly ignored, they cannot be 800 + * trusted. 801 + */ 1173 802 if (unlikely(irq_status & SSP_MIS_MASK_RORMIS)) { 1174 803 /* 1175 804 * Overrun interrupt - bail out since our Data has been 1176 805 * corrupted 1177 806 */ 1178 - dev_err(&pl022->adev->dev, 1179 - "FIFO overrun\n"); 807 + dev_err(&pl022->adev->dev, "FIFO overrun\n"); 1180 808 if (readw(SSP_SR(pl022->virtbase)) & SSP_SR_MASK_RFF) 1181 809 dev_err(&pl022->adev->dev, 1182 810 "RXFIFO is full\n"); ··· 1274 896 } 1275 897 1276 898 /** 1277 - * pump_transfers - Tasklet function which schedules next interrupt transfer 1278 - * when running in interrupt transfer mode. 899 + * pump_transfers - Tasklet function which schedules next transfer 900 + * when running in interrupt or DMA transfer mode. 1279 901 * @data: SSP driver private data structure 1280 902 * 1281 903 */ ··· 1332 954 } 1333 955 /* Flush the FIFOs and let's go! */ 1334 956 flush(pl022); 957 + 958 + if (pl022->cur_chip->enable_dma) { 959 + if (configure_dma(pl022)) { 960 + dev_dbg(&pl022->adev->dev, 961 + "configuration of DMA failed, fall back to interrupt mode\n"); 962 + goto err_config_dma; 963 + } 964 + return; 965 + } 966 + 967 + err_config_dma: 1335 968 writew(ENABLE_ALL_INTERRUPTS, SSP_IMSC(pl022->virtbase)); 1336 969 } 1337 970 1338 - /** 1339 - * NOT IMPLEMENTED 1340 - * configure_dma - It configures the DMA pipes for DMA transfers 1341 - * @data: SSP driver's private data structure 1342 - * 1343 - */ 1344 - static int configure_dma(void *data) 971 + static void do_interrupt_dma_transfer(struct pl022 *pl022) 1345 972 { 1346 - struct pl022 *pl022 = data; 1347 - dev_dbg(&pl022->adev->dev, "configure DMA\n"); 1348 - return -ENOTSUPP; 1349 - } 1350 - 1351 - /** 1352 - * do_dma_transfer - It handles transfers of the current message 1353 - * if it is DMA xfer. 1354 - * NOT FULLY IMPLEMENTED 1355 - * @data: SSP driver's private data structure 1356 - */ 1357 - static void do_dma_transfer(void *data) 1358 - { 1359 - struct pl022 *pl022 = data; 1360 - 1361 - if (configure_dma(data)) { 1362 - dev_dbg(&pl022->adev->dev, "configuration of DMA Failed!\n"); 1363 - goto err_config_dma; 1364 - } 1365 - 1366 - /* TODO: Implememt DMA setup of pipes here */ 1367 - 1368 - /* Enable target chip, set up transfer */ 1369 - pl022->cur_chip->cs_control(SSP_CHIP_SELECT); 1370 - if (set_up_next_transfer(pl022, pl022->cur_transfer)) { 1371 - /* Error path */ 1372 - pl022->cur_msg->state = STATE_ERROR; 1373 - pl022->cur_msg->status = -EIO; 1374 - giveback(pl022); 1375 - return; 1376 - } 1377 - /* Enable SSP */ 1378 - writew((readw(SSP_CR1(pl022->virtbase)) | SSP_CR1_MASK_SSE), 1379 - SSP_CR1(pl022->virtbase)); 1380 - 1381 - /* TODO: Enable the DMA transfer here */ 1382 - return; 1383 - 1384 - err_config_dma: 1385 - pl022->cur_msg->state = STATE_ERROR; 1386 - pl022->cur_msg->status = -EIO; 1387 - giveback(pl022); 1388 - return; 1389 - } 1390 - 1391 - static void do_interrupt_transfer(void *data) 1392 - { 1393 - struct pl022 *pl022 = data; 973 + u32 irqflags = ENABLE_ALL_INTERRUPTS; 1394 974 1395 975 /* Enable target chip */ 1396 976 pl022->cur_chip->cs_control(SSP_CHIP_SELECT); ··· 1359 1023 giveback(pl022); 1360 1024 return; 1361 1025 } 1026 + /* If we're using DMA, set up DMA here */ 1027 + if (pl022->cur_chip->enable_dma) { 1028 + /* Configure DMA transfer */ 1029 + if (configure_dma(pl022)) { 1030 + dev_dbg(&pl022->adev->dev, 1031 + "configuration of DMA failed, fall back to interrupt mode\n"); 1032 + goto err_config_dma; 1033 + } 1034 + /* Disable interrupts in DMA mode, IRQ from DMA controller */ 1035 + irqflags = DISABLE_ALL_INTERRUPTS; 1036 + } 1037 + err_config_dma: 1362 1038 /* Enable SSP, turn on interrupts */ 1363 1039 writew((readw(SSP_CR1(pl022->virtbase)) | SSP_CR1_MASK_SSE), 1364 1040 SSP_CR1(pl022->virtbase)); 1365 - writew(ENABLE_ALL_INTERRUPTS, SSP_IMSC(pl022->virtbase)); 1041 + writew(irqflags, SSP_IMSC(pl022->virtbase)); 1366 1042 } 1367 1043 1368 - static void do_polling_transfer(void *data) 1044 + static void do_polling_transfer(struct pl022 *pl022) 1369 1045 { 1370 - struct pl022 *pl022 = data; 1371 1046 struct spi_message *message = NULL; 1372 1047 struct spi_transfer *transfer = NULL; 1373 1048 struct spi_transfer *previous = NULL; ··· 1448 1101 * 1449 1102 * This function checks if there is any spi message in the queue that 1450 1103 * needs processing and delegate control to appropriate function 1451 - * do_polling_transfer()/do_interrupt_transfer()/do_dma_transfer() 1104 + * do_polling_transfer()/do_interrupt_dma_transfer() 1452 1105 * based on the kind of the transfer 1453 1106 * 1454 1107 */ ··· 1497 1150 1498 1151 if (pl022->cur_chip->xfer_type == POLLING_TRANSFER) 1499 1152 do_polling_transfer(pl022); 1500 - else if (pl022->cur_chip->xfer_type == INTERRUPT_TRANSFER) 1501 - do_interrupt_transfer(pl022); 1502 1153 else 1503 - do_dma_transfer(pl022); 1154 + do_interrupt_dma_transfer(pl022); 1504 1155 } 1505 1156 1506 1157 ··· 1814 1469 } 1815 1470 1816 1471 /** 1817 - * NOT IMPLEMENTED 1818 - * process_dma_info - Processes the DMA info provided by client drivers 1819 - * @chip_info: chip info provided by client device 1820 - * @chip: Runtime state maintained by the SSP controller for each spi device 1821 - * 1822 - * This function processes and stores DMA config provided by client driver 1823 - * into the runtime state maintained by the SSP controller driver 1824 - */ 1825 - static int process_dma_info(struct pl022_config_chip *chip_info, 1826 - struct chip_data *chip) 1827 - { 1828 - dev_err(chip_info->dev, 1829 - "cannot process DMA info, DMA not implemented!\n"); 1830 - return -ENOTSUPP; 1831 - } 1832 - 1833 - /** 1834 1472 * pl022_setup - setup function registered to SPI master framework 1835 1473 * @spi: spi device which is requesting setup 1836 1474 * ··· 1880 1552 1881 1553 dev_dbg(&spi->dev, "allocated memory for controller data\n"); 1882 1554 1883 - /* Pointer back to the SPI device */ 1884 - chip_info->dev = &spi->dev; 1885 1555 /* 1886 1556 * Set controller data default values: 1887 1557 * Polling is supported by default ··· 1904 1578 dev_dbg(&spi->dev, 1905 1579 "using user supplied controller_data settings\n"); 1906 1580 } 1581 + 1582 + /* Pointer back to the SPI device */ 1583 + chip_info->dev = &spi->dev; 1907 1584 1908 1585 /* 1909 1586 * We can override with custom divisors, else we use the board ··· 1966 1637 chip->cpsr = 0; 1967 1638 if ((chip_info->com_mode == DMA_TRANSFER) 1968 1639 && ((pl022->master_info)->enable_dma)) { 1969 - chip->enable_dma = 1; 1640 + chip->enable_dma = true; 1970 1641 dev_dbg(&spi->dev, "DMA mode set in controller state\n"); 1971 - status = process_dma_info(chip_info, chip); 1972 1642 if (status < 0) 1973 1643 goto err_config_params; 1974 1644 SSP_WRITE_BITS(chip->dmacr, SSP_DMA_ENABLED, ··· 1975 1647 SSP_WRITE_BITS(chip->dmacr, SSP_DMA_ENABLED, 1976 1648 SSP_DMACR_MASK_TXDMAE, 1); 1977 1649 } else { 1978 - chip->enable_dma = 0; 1650 + chip->enable_dma = false; 1979 1651 dev_dbg(&spi->dev, "DMA mode NOT set in controller state\n"); 1980 1652 SSP_WRITE_BITS(chip->dmacr, SSP_DMA_DISABLED, 1981 1653 SSP_DMACR_MASK_RXDMAE, 0); ··· 2101 1773 if (status) 2102 1774 goto err_no_ioregion; 2103 1775 1776 + pl022->phybase = adev->res.start; 2104 1777 pl022->virtbase = ioremap(adev->res.start, resource_size(&adev->res)); 2105 1778 if (pl022->virtbase == NULL) { 2106 1779 status = -ENOMEM; ··· 2128 1799 dev_err(&adev->dev, "probe - cannot get IRQ (%d)\n", status); 2129 1800 goto err_no_irq; 2130 1801 } 1802 + 1803 + /* Get DMA channels */ 1804 + if (platform_info->enable_dma) { 1805 + status = pl022_dma_probe(pl022); 1806 + if (status != 0) 1807 + goto err_no_dma; 1808 + } 1809 + 2131 1810 /* Initialize and start queue */ 2132 1811 status = init_queue(pl022); 2133 1812 if (status != 0) { ··· 2164 1827 err_start_queue: 2165 1828 err_init_queue: 2166 1829 destroy_queue(pl022); 1830 + pl022_dma_remove(pl022); 1831 + err_no_dma: 2167 1832 free_irq(adev->irq[0], pl022); 2168 1833 err_no_irq: 2169 1834 clk_put(pl022->clk); ··· 2196 1857 return status; 2197 1858 } 2198 1859 load_ssp_default_config(pl022); 1860 + pl022_dma_remove(pl022); 2199 1861 free_irq(adev->irq[0], pl022); 2200 1862 clk_disable(pl022->clk); 2201 1863 clk_put(pl022->clk);
+6
include/linux/amba/pl022.h
··· 228 228 }; 229 229 230 230 231 + struct dma_chan; 231 232 /** 232 233 * struct pl022_ssp_master - device.platform_data for SPI controller devices. 233 234 * @num_chipselect: chipselects are used to distinguish individual ··· 236 235 * each slave has a chipselect signal, but it's common that not 237 236 * every chipselect is connected to a slave. 238 237 * @enable_dma: if true enables DMA driven transfers. 238 + * @dma_rx_param: parameter to locate an RX DMA channel. 239 + * @dma_tx_param: parameter to locate a TX DMA channel. 239 240 */ 240 241 struct pl022_ssp_controller { 241 242 u16 bus_id; 242 243 u8 num_chipselect; 243 244 u8 enable_dma:1; 245 + bool (*dma_filter)(struct dma_chan *chan, void *filter_param); 246 + void *dma_rx_param; 247 + void *dma_tx_param; 244 248 }; 245 249 246 250 /**