aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/spi/amba-pl022.c
diff options
context:
space:
mode:
authorGlenn Elliott <gelliott@cs.unc.edu>2012-03-04 19:47:13 -0500
committerGlenn Elliott <gelliott@cs.unc.edu>2012-03-04 19:47:13 -0500
commitc71c03bda1e86c9d5198c5d83f712e695c4f2a1e (patch)
treeecb166cb3e2b7e2adb3b5e292245fefd23381ac8 /drivers/spi/amba-pl022.c
parentea53c912f8a86a8567697115b6a0d8152beee5c8 (diff)
parent6a00f206debf8a5c8899055726ad127dbeeed098 (diff)
Merge branch 'mpi-master' into wip-k-fmlpwip-k-fmlp
Conflicts: litmus/sched_cedf.c
Diffstat (limited to 'drivers/spi/amba-pl022.c')
-rw-r--r--drivers/spi/amba-pl022.c878
1 files changed, 613 insertions, 265 deletions
diff --git a/drivers/spi/amba-pl022.c b/drivers/spi/amba-pl022.c
index 4c37c4e28647..d18ce9e946d8 100644
--- a/drivers/spi/amba-pl022.c
+++ b/drivers/spi/amba-pl022.c
@@ -24,12 +24,6 @@
24 * GNU General Public License for more details. 24 * GNU General Public License for more details.
25 */ 25 */
26 26
27/*
28 * TODO:
29 * - add timeout on polled transfers
30 * - add generic DMA framework support
31 */
32
33#include <linux/init.h> 27#include <linux/init.h>
34#include <linux/module.h> 28#include <linux/module.h>
35#include <linux/device.h> 29#include <linux/device.h>
@@ -45,6 +39,9 @@
45#include <linux/amba/pl022.h> 39#include <linux/amba/pl022.h>
46#include <linux/io.h> 40#include <linux/io.h>
47#include <linux/slab.h> 41#include <linux/slab.h>
42#include <linux/dmaengine.h>
43#include <linux/dma-mapping.h>
44#include <linux/scatterlist.h>
48 45
49/* 46/*
50 * This macro is used to define some register default values. 47 * This macro is used to define some register default values.
@@ -251,11 +248,6 @@
251#define STATE_ERROR ((void *) -1) 248#define STATE_ERROR ((void *) -1)
252 249
253/* 250/*
254 * Queue State
255 */
256#define QUEUE_RUNNING (0)
257#define QUEUE_STOPPED (1)
258/*
259 * SSP State - Whether Enabled or Disabled 251 * SSP State - Whether Enabled or Disabled
260 */ 252 */
261#define SSP_DISABLED (0) 253#define SSP_DISABLED (0)
@@ -290,6 +282,8 @@
290 282
291#define CLEAR_ALL_INTERRUPTS 0x3 283#define CLEAR_ALL_INTERRUPTS 0x3
292 284
285#define SPI_POLLING_TIMEOUT 1000
286
293 287
294/* 288/*
295 * The type of reading going on on this chip 289 * The type of reading going on on this chip
@@ -327,22 +321,24 @@ struct vendor_data {
327 bool unidir; 321 bool unidir;
328 bool extended_cr; 322 bool extended_cr;
329 bool pl023; 323 bool pl023;
324 bool loopback;
330}; 325};
331 326
332/** 327/**
333 * struct pl022 - This is the private SSP driver data structure 328 * struct pl022 - This is the private SSP driver data structure
334 * @adev: AMBA device model hookup 329 * @adev: AMBA device model hookup
335 * @vendor: Vendor data for the IP block 330 * @vendor: vendor data for the IP block
336 * @phybase: The physical memory where the SSP device resides 331 * @phybase: the physical memory where the SSP device resides
337 * @virtbase: The virtual memory where the SSP is mapped 332 * @virtbase: the virtual memory where the SSP is mapped
333 * @clk: outgoing clock "SPICLK" for the SPI bus
338 * @master: SPI framework hookup 334 * @master: SPI framework hookup
339 * @master_info: controller-specific data from machine setup 335 * @master_info: controller-specific data from machine setup
340 * @regs: SSP controller register's virtual address
341 * @pump_messages: Work struct for scheduling work to the workqueue
342 * @lock: spinlock to syncronise access to driver data
343 * @workqueue: a workqueue on which any spi_message request is queued 336 * @workqueue: a workqueue on which any spi_message request is queued
337 * @pump_messages: work struct for scheduling work to the workqueue
338 * @queue_lock: spinlock to syncronise access to message queue
339 * @queue: message queue
344 * @busy: workqueue is busy 340 * @busy: workqueue is busy
345 * @run: workqueue is running 341 * @running: workqueue is running
346 * @pump_transfers: Tasklet used in Interrupt Transfer mode 342 * @pump_transfers: Tasklet used in Interrupt Transfer mode
347 * @cur_msg: Pointer to current spi_message being processed 343 * @cur_msg: Pointer to current spi_message being processed
348 * @cur_transfer: Pointer to current spi_transfer 344 * @cur_transfer: Pointer to current spi_transfer
@@ -351,8 +347,14 @@ struct vendor_data {
351 * @tx_end: end position in TX buffer to be read 347 * @tx_end: end position in TX buffer to be read
352 * @rx: current position in RX buffer to be written 348 * @rx: current position in RX buffer to be written
353 * @rx_end: end position in RX buffer to be written 349 * @rx_end: end position in RX buffer to be written
354 * @readingtype: the type of read currently going on 350 * @read: the type of read currently going on
355 * @writingtype: the type or write currently going on 351 * @write: the type of write currently going on
352 * @exp_fifo_level: expected FIFO level
353 * @dma_rx_channel: optional channel for RX DMA
354 * @dma_tx_channel: optional channel for TX DMA
355 * @sgt_rx: scattertable for the RX transfer
356 * @sgt_tx: scattertable for the TX transfer
357 * @dummypage: a dummy page used for driving data on the bus with DMA
356 */ 358 */
357struct pl022 { 359struct pl022 {
358 struct amba_device *adev; 360 struct amba_device *adev;
@@ -367,8 +369,8 @@ struct pl022 {
367 struct work_struct pump_messages; 369 struct work_struct pump_messages;
368 spinlock_t queue_lock; 370 spinlock_t queue_lock;
369 struct list_head queue; 371 struct list_head queue;
370 int busy; 372 bool busy;
371 int run; 373 bool running;
372 /* Message transfer pump */ 374 /* Message transfer pump */
373 struct tasklet_struct pump_transfers; 375 struct tasklet_struct pump_transfers;
374 struct spi_message *cur_msg; 376 struct spi_message *cur_msg;
@@ -381,6 +383,14 @@ struct pl022 {
381 enum ssp_reading read; 383 enum ssp_reading read;
382 enum ssp_writing write; 384 enum ssp_writing write;
383 u32 exp_fifo_level; 385 u32 exp_fifo_level;
386 /* DMA settings */
387#ifdef CONFIG_DMA_ENGINE
388 struct dma_chan *dma_rx_channel;
389 struct dma_chan *dma_tx_channel;
390 struct sg_table sgt_rx;
391 struct sg_table sgt_tx;
392 char *dummypage;
393#endif
384}; 394};
385 395
386/** 396/**
@@ -392,8 +402,8 @@ struct pl022 {
392 * @cpsr: Value of Clock prescale register 402 * @cpsr: Value of Clock prescale register
393 * @n_bytes: how many bytes(power of 2) reqd for a given data width of client 403 * @n_bytes: how many bytes(power of 2) reqd for a given data width of client
394 * @enable_dma: Whether to enable DMA or not 404 * @enable_dma: Whether to enable DMA or not
395 * @write: function ptr to be used to write when doing xfer for this chip
396 * @read: function ptr to be used to read when doing xfer for this chip 405 * @read: function ptr to be used to read when doing xfer for this chip
406 * @write: function ptr to be used to write when doing xfer for this chip
397 * @cs_control: chip select callback provided by chip 407 * @cs_control: chip select callback provided by chip
398 * @xfer_type: polling/interrupt/DMA 408 * @xfer_type: polling/interrupt/DMA
399 * 409 *
@@ -406,7 +416,7 @@ struct chip_data {
406 u16 dmacr; 416 u16 dmacr;
407 u16 cpsr; 417 u16 cpsr;
408 u8 n_bytes; 418 u8 n_bytes;
409 u8 enable_dma:1; 419 bool enable_dma;
410 enum ssp_reading read; 420 enum ssp_reading read;
411 enum ssp_writing write; 421 enum ssp_writing write;
412 void (*cs_control) (u32 command); 422 void (*cs_control) (u32 command);
@@ -503,9 +513,10 @@ static void giveback(struct pl022 *pl022)
503 msg->state = NULL; 513 msg->state = NULL;
504 if (msg->complete) 514 if (msg->complete)
505 msg->complete(msg->context); 515 msg->complete(msg->context);
506 /* This message is completed, so let's turn off the clocks! */ 516 /* This message is completed, so let's turn off the clocks & power */
507 clk_disable(pl022->clk); 517 clk_disable(pl022->clk);
508 amba_pclk_disable(pl022->adev); 518 amba_pclk_disable(pl022->adev);
519 amba_vcore_disable(pl022->adev);
509} 520}
510 521
511/** 522/**
@@ -647,7 +658,7 @@ static void readwriter(struct pl022 *pl022)
647{ 658{
648 659
649 /* 660 /*
650 * The FIFO depth is different inbetween primecell variants. 661 * The FIFO depth is different between primecell variants.
651 * I believe filling in too much in the FIFO might cause 662 * I believe filling in too much in the FIFO might cause
652 * errons in 8bit wide transfers on ARM variants (just 8 words 663 * errons in 8bit wide transfers on ARM variants (just 8 words
653 * FIFO, means only 8x8 = 64 bits in FIFO) at least. 664 * FIFO, means only 8x8 = 64 bits in FIFO) at least.
@@ -708,7 +719,7 @@ static void readwriter(struct pl022 *pl022)
708 * This inner reader takes care of things appearing in the RX 719 * This inner reader takes care of things appearing in the RX
709 * FIFO as we're transmitting. This will happen a lot since the 720 * FIFO as we're transmitting. This will happen a lot since the
710 * clock starts running when you put things into the TX FIFO, 721 * clock starts running when you put things into the TX FIFO,
711 * and then things are continously clocked into the RX FIFO. 722 * and then things are continuously clocked into the RX FIFO.
712 */ 723 */
713 while ((readw(SSP_SR(pl022->virtbase)) & SSP_SR_MASK_RNE) 724 while ((readw(SSP_SR(pl022->virtbase)) & SSP_SR_MASK_RNE)
714 && (pl022->rx < pl022->rx_end)) { 725 && (pl022->rx < pl022->rx_end)) {
@@ -763,6 +774,364 @@ static void *next_transfer(struct pl022 *pl022)
763 } 774 }
764 return STATE_DONE; 775 return STATE_DONE;
765} 776}
777
778/*
779 * This DMA functionality is only compiled in if we have
780 * access to the generic DMA devices/DMA engine.
781 */
782#ifdef CONFIG_DMA_ENGINE
783static void unmap_free_dma_scatter(struct pl022 *pl022)
784{
785 /* Unmap and free the SG tables */
786 dma_unmap_sg(pl022->dma_tx_channel->device->dev, pl022->sgt_tx.sgl,
787 pl022->sgt_tx.nents, DMA_TO_DEVICE);
788 dma_unmap_sg(pl022->dma_rx_channel->device->dev, pl022->sgt_rx.sgl,
789 pl022->sgt_rx.nents, DMA_FROM_DEVICE);
790 sg_free_table(&pl022->sgt_rx);
791 sg_free_table(&pl022->sgt_tx);
792}
793
794static void dma_callback(void *data)
795{
796 struct pl022 *pl022 = data;
797 struct spi_message *msg = pl022->cur_msg;
798
799 BUG_ON(!pl022->sgt_rx.sgl);
800
801#ifdef VERBOSE_DEBUG
802 /*
803 * Optionally dump out buffers to inspect contents, this is
804 * good if you want to convince yourself that the loopback
805 * read/write contents are the same, when adopting to a new
806 * DMA engine.
807 */
808 {
809 struct scatterlist *sg;
810 unsigned int i;
811
812 dma_sync_sg_for_cpu(&pl022->adev->dev,
813 pl022->sgt_rx.sgl,
814 pl022->sgt_rx.nents,
815 DMA_FROM_DEVICE);
816
817 for_each_sg(pl022->sgt_rx.sgl, sg, pl022->sgt_rx.nents, i) {
818 dev_dbg(&pl022->adev->dev, "SPI RX SG ENTRY: %d", i);
819 print_hex_dump(KERN_ERR, "SPI RX: ",
820 DUMP_PREFIX_OFFSET,
821 16,
822 1,
823 sg_virt(sg),
824 sg_dma_len(sg),
825 1);
826 }
827 for_each_sg(pl022->sgt_tx.sgl, sg, pl022->sgt_tx.nents, i) {
828 dev_dbg(&pl022->adev->dev, "SPI TX SG ENTRY: %d", i);
829 print_hex_dump(KERN_ERR, "SPI TX: ",
830 DUMP_PREFIX_OFFSET,
831 16,
832 1,
833 sg_virt(sg),
834 sg_dma_len(sg),
835 1);
836 }
837 }
838#endif
839
840 unmap_free_dma_scatter(pl022);
841
842 /* Update total bytes transferred */
843 msg->actual_length += pl022->cur_transfer->len;
844 if (pl022->cur_transfer->cs_change)
845 pl022->cur_chip->
846 cs_control(SSP_CHIP_DESELECT);
847
848 /* Move to next transfer */
849 msg->state = next_transfer(pl022);
850 tasklet_schedule(&pl022->pump_transfers);
851}
852
853static void setup_dma_scatter(struct pl022 *pl022,
854 void *buffer,
855 unsigned int length,
856 struct sg_table *sgtab)
857{
858 struct scatterlist *sg;
859 int bytesleft = length;
860 void *bufp = buffer;
861 int mapbytes;
862 int i;
863
864 if (buffer) {
865 for_each_sg(sgtab->sgl, sg, sgtab->nents, i) {
866 /*
867 * If there are less bytes left than what fits
868 * in the current page (plus page alignment offset)
869 * we just feed in this, else we stuff in as much
870 * as we can.
871 */
872 if (bytesleft < (PAGE_SIZE - offset_in_page(bufp)))
873 mapbytes = bytesleft;
874 else
875 mapbytes = PAGE_SIZE - offset_in_page(bufp);
876 sg_set_page(sg, virt_to_page(bufp),
877 mapbytes, offset_in_page(bufp));
878 bufp += mapbytes;
879 bytesleft -= mapbytes;
880 dev_dbg(&pl022->adev->dev,
881 "set RX/TX target page @ %p, %d bytes, %d left\n",
882 bufp, mapbytes, bytesleft);
883 }
884 } else {
885 /* Map the dummy buffer on every page */
886 for_each_sg(sgtab->sgl, sg, sgtab->nents, i) {
887 if (bytesleft < PAGE_SIZE)
888 mapbytes = bytesleft;
889 else
890 mapbytes = PAGE_SIZE;
891 sg_set_page(sg, virt_to_page(pl022->dummypage),
892 mapbytes, 0);
893 bytesleft -= mapbytes;
894 dev_dbg(&pl022->adev->dev,
895 "set RX/TX to dummy page %d bytes, %d left\n",
896 mapbytes, bytesleft);
897
898 }
899 }
900 BUG_ON(bytesleft);
901}
902
903/**
904 * configure_dma - configures the channels for the next transfer
905 * @pl022: SSP driver's private data structure
906 */
907static int configure_dma(struct pl022 *pl022)
908{
909 struct dma_slave_config rx_conf = {
910 .src_addr = SSP_DR(pl022->phybase),
911 .direction = DMA_FROM_DEVICE,
912 .src_maxburst = pl022->vendor->fifodepth >> 1,
913 };
914 struct dma_slave_config tx_conf = {
915 .dst_addr = SSP_DR(pl022->phybase),
916 .direction = DMA_TO_DEVICE,
917 .dst_maxburst = pl022->vendor->fifodepth >> 1,
918 };
919 unsigned int pages;
920 int ret;
921 int rx_sglen, tx_sglen;
922 struct dma_chan *rxchan = pl022->dma_rx_channel;
923 struct dma_chan *txchan = pl022->dma_tx_channel;
924 struct dma_async_tx_descriptor *rxdesc;
925 struct dma_async_tx_descriptor *txdesc;
926
927 /* Check that the channels are available */
928 if (!rxchan || !txchan)
929 return -ENODEV;
930
931 switch (pl022->read) {
932 case READING_NULL:
933 /* Use the same as for writing */
934 rx_conf.src_addr_width = DMA_SLAVE_BUSWIDTH_UNDEFINED;
935 break;
936 case READING_U8:
937 rx_conf.src_addr_width = DMA_SLAVE_BUSWIDTH_1_BYTE;
938 break;
939 case READING_U16:
940 rx_conf.src_addr_width = DMA_SLAVE_BUSWIDTH_2_BYTES;
941 break;
942 case READING_U32:
943 rx_conf.src_addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES;
944 break;
945 }
946
947 switch (pl022->write) {
948 case WRITING_NULL:
949 /* Use the same as for reading */
950 tx_conf.dst_addr_width = DMA_SLAVE_BUSWIDTH_UNDEFINED;
951 break;
952 case WRITING_U8:
953 tx_conf.dst_addr_width = DMA_SLAVE_BUSWIDTH_1_BYTE;
954 break;
955 case WRITING_U16:
956 tx_conf.dst_addr_width = DMA_SLAVE_BUSWIDTH_2_BYTES;
957 break;
958 case WRITING_U32:
959 tx_conf.dst_addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES;
960 break;
961 }
962
963 /* SPI pecularity: we need to read and write the same width */
964 if (rx_conf.src_addr_width == DMA_SLAVE_BUSWIDTH_UNDEFINED)
965 rx_conf.src_addr_width = tx_conf.dst_addr_width;
966 if (tx_conf.dst_addr_width == DMA_SLAVE_BUSWIDTH_UNDEFINED)
967 tx_conf.dst_addr_width = rx_conf.src_addr_width;
968 BUG_ON(rx_conf.src_addr_width != tx_conf.dst_addr_width);
969
970 dmaengine_slave_config(rxchan, &rx_conf);
971 dmaengine_slave_config(txchan, &tx_conf);
972
973 /* Create sglists for the transfers */
974 pages = (pl022->cur_transfer->len >> PAGE_SHIFT) + 1;
975 dev_dbg(&pl022->adev->dev, "using %d pages for transfer\n", pages);
976
977 ret = sg_alloc_table(&pl022->sgt_rx, pages, GFP_KERNEL);
978 if (ret)
979 goto err_alloc_rx_sg;
980
981 ret = sg_alloc_table(&pl022->sgt_tx, pages, GFP_KERNEL);
982 if (ret)
983 goto err_alloc_tx_sg;
984
985 /* Fill in the scatterlists for the RX+TX buffers */
986 setup_dma_scatter(pl022, pl022->rx,
987 pl022->cur_transfer->len, &pl022->sgt_rx);
988 setup_dma_scatter(pl022, pl022->tx,
989 pl022->cur_transfer->len, &pl022->sgt_tx);
990
991 /* Map DMA buffers */
992 rx_sglen = dma_map_sg(rxchan->device->dev, pl022->sgt_rx.sgl,
993 pl022->sgt_rx.nents, DMA_FROM_DEVICE);
994 if (!rx_sglen)
995 goto err_rx_sgmap;
996
997 tx_sglen = dma_map_sg(txchan->device->dev, pl022->sgt_tx.sgl,
998 pl022->sgt_tx.nents, DMA_TO_DEVICE);
999 if (!tx_sglen)
1000 goto err_tx_sgmap;
1001
1002 /* Send both scatterlists */
1003 rxdesc = rxchan->device->device_prep_slave_sg(rxchan,
1004 pl022->sgt_rx.sgl,
1005 rx_sglen,
1006 DMA_FROM_DEVICE,
1007 DMA_PREP_INTERRUPT | DMA_CTRL_ACK);
1008 if (!rxdesc)
1009 goto err_rxdesc;
1010
1011 txdesc = txchan->device->device_prep_slave_sg(txchan,
1012 pl022->sgt_tx.sgl,
1013 tx_sglen,
1014 DMA_TO_DEVICE,
1015 DMA_PREP_INTERRUPT | DMA_CTRL_ACK);
1016 if (!txdesc)
1017 goto err_txdesc;
1018
1019 /* Put the callback on the RX transfer only, that should finish last */
1020 rxdesc->callback = dma_callback;
1021 rxdesc->callback_param = pl022;
1022
1023 /* Submit and fire RX and TX with TX last so we're ready to read! */
1024 dmaengine_submit(rxdesc);
1025 dmaengine_submit(txdesc);
1026 dma_async_issue_pending(rxchan);
1027 dma_async_issue_pending(txchan);
1028
1029 return 0;
1030
1031err_txdesc:
1032 dmaengine_terminate_all(txchan);
1033err_rxdesc:
1034 dmaengine_terminate_all(rxchan);
1035 dma_unmap_sg(txchan->device->dev, pl022->sgt_tx.sgl,
1036 pl022->sgt_tx.nents, DMA_TO_DEVICE);
1037err_tx_sgmap:
1038 dma_unmap_sg(rxchan->device->dev, pl022->sgt_rx.sgl,
1039 pl022->sgt_tx.nents, DMA_FROM_DEVICE);
1040err_rx_sgmap:
1041 sg_free_table(&pl022->sgt_tx);
1042err_alloc_tx_sg:
1043 sg_free_table(&pl022->sgt_rx);
1044err_alloc_rx_sg:
1045 return -ENOMEM;
1046}
1047
1048static int __init pl022_dma_probe(struct pl022 *pl022)
1049{
1050 dma_cap_mask_t mask;
1051
1052 /* Try to acquire a generic DMA engine slave channel */
1053 dma_cap_zero(mask);
1054 dma_cap_set(DMA_SLAVE, mask);
1055 /*
1056 * We need both RX and TX channels to do DMA, else do none
1057 * of them.
1058 */
1059 pl022->dma_rx_channel = dma_request_channel(mask,
1060 pl022->master_info->dma_filter,
1061 pl022->master_info->dma_rx_param);
1062 if (!pl022->dma_rx_channel) {
1063 dev_dbg(&pl022->adev->dev, "no RX DMA channel!\n");
1064 goto err_no_rxchan;
1065 }
1066
1067 pl022->dma_tx_channel = dma_request_channel(mask,
1068 pl022->master_info->dma_filter,
1069 pl022->master_info->dma_tx_param);
1070 if (!pl022->dma_tx_channel) {
1071 dev_dbg(&pl022->adev->dev, "no TX DMA channel!\n");
1072 goto err_no_txchan;
1073 }
1074
1075 pl022->dummypage = kmalloc(PAGE_SIZE, GFP_KERNEL);
1076 if (!pl022->dummypage) {
1077 dev_dbg(&pl022->adev->dev, "no DMA dummypage!\n");
1078 goto err_no_dummypage;
1079 }
1080
1081 dev_info(&pl022->adev->dev, "setup for DMA on RX %s, TX %s\n",
1082 dma_chan_name(pl022->dma_rx_channel),
1083 dma_chan_name(pl022->dma_tx_channel));
1084
1085 return 0;
1086
1087err_no_dummypage:
1088 dma_release_channel(pl022->dma_tx_channel);
1089err_no_txchan:
1090 dma_release_channel(pl022->dma_rx_channel);
1091 pl022->dma_rx_channel = NULL;
1092err_no_rxchan:
1093 dev_err(&pl022->adev->dev,
1094 "Failed to work in dma mode, work without dma!\n");
1095 return -ENODEV;
1096}
1097
1098static void terminate_dma(struct pl022 *pl022)
1099{
1100 struct dma_chan *rxchan = pl022->dma_rx_channel;
1101 struct dma_chan *txchan = pl022->dma_tx_channel;
1102
1103 dmaengine_terminate_all(rxchan);
1104 dmaengine_terminate_all(txchan);
1105 unmap_free_dma_scatter(pl022);
1106}
1107
1108static void pl022_dma_remove(struct pl022 *pl022)
1109{
1110 if (pl022->busy)
1111 terminate_dma(pl022);
1112 if (pl022->dma_tx_channel)
1113 dma_release_channel(pl022->dma_tx_channel);
1114 if (pl022->dma_rx_channel)
1115 dma_release_channel(pl022->dma_rx_channel);
1116 kfree(pl022->dummypage);
1117}
1118
1119#else
1120static inline int configure_dma(struct pl022 *pl022)
1121{
1122 return -ENODEV;
1123}
1124
1125static inline int pl022_dma_probe(struct pl022 *pl022)
1126{
1127 return 0;
1128}
1129
1130static inline void pl022_dma_remove(struct pl022 *pl022)
1131{
1132}
1133#endif
1134
766/** 1135/**
767 * pl022_interrupt_handler - Interrupt handler for SSP controller 1136 * pl022_interrupt_handler - Interrupt handler for SSP controller
768 * 1137 *
@@ -794,14 +1163,17 @@ static irqreturn_t pl022_interrupt_handler(int irq, void *dev_id)
794 if (unlikely(!irq_status)) 1163 if (unlikely(!irq_status))
795 return IRQ_NONE; 1164 return IRQ_NONE;
796 1165
797 /* This handles the error code interrupts */ 1166 /*
1167 * This handles the FIFO interrupts, the timeout
1168 * interrupts are flatly ignored, they cannot be
1169 * trusted.
1170 */
798 if (unlikely(irq_status & SSP_MIS_MASK_RORMIS)) { 1171 if (unlikely(irq_status & SSP_MIS_MASK_RORMIS)) {
799 /* 1172 /*
800 * Overrun interrupt - bail out since our Data has been 1173 * Overrun interrupt - bail out since our Data has been
801 * corrupted 1174 * corrupted
802 */ 1175 */
803 dev_err(&pl022->adev->dev, 1176 dev_err(&pl022->adev->dev, "FIFO overrun\n");
804 "FIFO overrun\n");
805 if (readw(SSP_SR(pl022->virtbase)) & SSP_SR_MASK_RFF) 1177 if (readw(SSP_SR(pl022->virtbase)) & SSP_SR_MASK_RFF)
806 dev_err(&pl022->adev->dev, 1178 dev_err(&pl022->adev->dev,
807 "RXFIFO is full\n"); 1179 "RXFIFO is full\n");
@@ -851,7 +1223,7 @@ static irqreturn_t pl022_interrupt_handler(int irq, void *dev_id)
851 "number of bytes on a 16bit bus?)\n", 1223 "number of bytes on a 16bit bus?)\n",
852 (u32) (pl022->rx - pl022->rx_end)); 1224 (u32) (pl022->rx - pl022->rx_end));
853 } 1225 }
854 /* Update total bytes transfered */ 1226 /* Update total bytes transferred */
855 msg->actual_length += pl022->cur_transfer->len; 1227 msg->actual_length += pl022->cur_transfer->len;
856 if (pl022->cur_transfer->cs_change) 1228 if (pl022->cur_transfer->cs_change)
857 pl022->cur_chip-> 1229 pl022->cur_chip->
@@ -896,8 +1268,8 @@ static int set_up_next_transfer(struct pl022 *pl022,
896} 1268}
897 1269
898/** 1270/**
899 * pump_transfers - Tasklet function which schedules next interrupt transfer 1271 * pump_transfers - Tasklet function which schedules next transfer
900 * when running in interrupt transfer mode. 1272 * when running in interrupt or DMA transfer mode.
901 * @data: SSP driver private data structure 1273 * @data: SSP driver private data structure
902 * 1274 *
903 */ 1275 */
@@ -954,65 +1326,23 @@ static void pump_transfers(unsigned long data)
954 } 1326 }
955 /* Flush the FIFOs and let's go! */ 1327 /* Flush the FIFOs and let's go! */
956 flush(pl022); 1328 flush(pl022);
957 writew(ENABLE_ALL_INTERRUPTS, SSP_IMSC(pl022->virtbase));
958}
959
960/**
961 * NOT IMPLEMENTED
962 * configure_dma - It configures the DMA pipes for DMA transfers
963 * @data: SSP driver's private data structure
964 *
965 */
966static int configure_dma(void *data)
967{
968 struct pl022 *pl022 = data;
969 dev_dbg(&pl022->adev->dev, "configure DMA\n");
970 return -ENOTSUPP;
971}
972
973/**
974 * do_dma_transfer - It handles transfers of the current message
975 * if it is DMA xfer.
976 * NOT FULLY IMPLEMENTED
977 * @data: SSP driver's private data structure
978 */
979static void do_dma_transfer(void *data)
980{
981 struct pl022 *pl022 = data;
982 1329
983 if (configure_dma(data)) { 1330 if (pl022->cur_chip->enable_dma) {
984 dev_dbg(&pl022->adev->dev, "configuration of DMA Failed!\n"); 1331 if (configure_dma(pl022)) {
985 goto err_config_dma; 1332 dev_dbg(&pl022->adev->dev,
986 } 1333 "configuration of DMA failed, fall back to interrupt mode\n");
987 1334 goto err_config_dma;
988 /* TODO: Implememt DMA setup of pipes here */ 1335 }
989
990 /* Enable target chip, set up transfer */
991 pl022->cur_chip->cs_control(SSP_CHIP_SELECT);
992 if (set_up_next_transfer(pl022, pl022->cur_transfer)) {
993 /* Error path */
994 pl022->cur_msg->state = STATE_ERROR;
995 pl022->cur_msg->status = -EIO;
996 giveback(pl022);
997 return; 1336 return;
998 } 1337 }
999 /* Enable SSP */
1000 writew((readw(SSP_CR1(pl022->virtbase)) | SSP_CR1_MASK_SSE),
1001 SSP_CR1(pl022->virtbase));
1002
1003 /* TODO: Enable the DMA transfer here */
1004 return;
1005 1338
1006 err_config_dma: 1339err_config_dma:
1007 pl022->cur_msg->state = STATE_ERROR; 1340 writew(ENABLE_ALL_INTERRUPTS, SSP_IMSC(pl022->virtbase));
1008 pl022->cur_msg->status = -EIO;
1009 giveback(pl022);
1010 return;
1011} 1341}
1012 1342
1013static void do_interrupt_transfer(void *data) 1343static void do_interrupt_dma_transfer(struct pl022 *pl022)
1014{ 1344{
1015 struct pl022 *pl022 = data; 1345 u32 irqflags = ENABLE_ALL_INTERRUPTS;
1016 1346
1017 /* Enable target chip */ 1347 /* Enable target chip */
1018 pl022->cur_chip->cs_control(SSP_CHIP_SELECT); 1348 pl022->cur_chip->cs_control(SSP_CHIP_SELECT);
@@ -1023,19 +1353,31 @@ static void do_interrupt_transfer(void *data)
1023 giveback(pl022); 1353 giveback(pl022);
1024 return; 1354 return;
1025 } 1355 }
1356 /* If we're using DMA, set up DMA here */
1357 if (pl022->cur_chip->enable_dma) {
1358 /* Configure DMA transfer */
1359 if (configure_dma(pl022)) {
1360 dev_dbg(&pl022->adev->dev,
1361 "configuration of DMA failed, fall back to interrupt mode\n");
1362 goto err_config_dma;
1363 }
1364 /* Disable interrupts in DMA mode, IRQ from DMA controller */
1365 irqflags = DISABLE_ALL_INTERRUPTS;
1366 }
1367err_config_dma:
1026 /* Enable SSP, turn on interrupts */ 1368 /* Enable SSP, turn on interrupts */
1027 writew((readw(SSP_CR1(pl022->virtbase)) | SSP_CR1_MASK_SSE), 1369 writew((readw(SSP_CR1(pl022->virtbase)) | SSP_CR1_MASK_SSE),
1028 SSP_CR1(pl022->virtbase)); 1370 SSP_CR1(pl022->virtbase));
1029 writew(ENABLE_ALL_INTERRUPTS, SSP_IMSC(pl022->virtbase)); 1371 writew(irqflags, SSP_IMSC(pl022->virtbase));
1030} 1372}
1031 1373
1032static void do_polling_transfer(void *data) 1374static void do_polling_transfer(struct pl022 *pl022)
1033{ 1375{
1034 struct pl022 *pl022 = data;
1035 struct spi_message *message = NULL; 1376 struct spi_message *message = NULL;
1036 struct spi_transfer *transfer = NULL; 1377 struct spi_transfer *transfer = NULL;
1037 struct spi_transfer *previous = NULL; 1378 struct spi_transfer *previous = NULL;
1038 struct chip_data *chip; 1379 struct chip_data *chip;
1380 unsigned long time, timeout;
1039 1381
1040 chip = pl022->cur_chip; 1382 chip = pl022->cur_chip;
1041 message = pl022->cur_msg; 1383 message = pl022->cur_msg;
@@ -1073,18 +1415,28 @@ static void do_polling_transfer(void *data)
1073 SSP_CR1(pl022->virtbase)); 1415 SSP_CR1(pl022->virtbase));
1074 1416
1075 dev_dbg(&pl022->adev->dev, "polling transfer ongoing ...\n"); 1417 dev_dbg(&pl022->adev->dev, "polling transfer ongoing ...\n");
1076 /* FIXME: insert a timeout so we don't hang here indefinately */ 1418
1077 while (pl022->tx < pl022->tx_end || pl022->rx < pl022->rx_end) 1419 timeout = jiffies + msecs_to_jiffies(SPI_POLLING_TIMEOUT);
1420 while (pl022->tx < pl022->tx_end || pl022->rx < pl022->rx_end) {
1421 time = jiffies;
1078 readwriter(pl022); 1422 readwriter(pl022);
1423 if (time_after(time, timeout)) {
1424 dev_warn(&pl022->adev->dev,
1425 "%s: timeout!\n", __func__);
1426 message->state = STATE_ERROR;
1427 goto out;
1428 }
1429 cpu_relax();
1430 }
1079 1431
1080 /* Update total byte transfered */ 1432 /* Update total byte transferred */
1081 message->actual_length += pl022->cur_transfer->len; 1433 message->actual_length += pl022->cur_transfer->len;
1082 if (pl022->cur_transfer->cs_change) 1434 if (pl022->cur_transfer->cs_change)
1083 pl022->cur_chip->cs_control(SSP_CHIP_DESELECT); 1435 pl022->cur_chip->cs_control(SSP_CHIP_DESELECT);
1084 /* Move to next transfer */ 1436 /* Move to next transfer */
1085 message->state = next_transfer(pl022); 1437 message->state = next_transfer(pl022);
1086 } 1438 }
1087 1439out:
1088 /* Handle end of message */ 1440 /* Handle end of message */
1089 if (message->state == STATE_DONE) 1441 if (message->state == STATE_DONE)
1090 message->status = 0; 1442 message->status = 0;
@@ -1101,7 +1453,7 @@ static void do_polling_transfer(void *data)
1101 * 1453 *
1102 * This function checks if there is any spi message in the queue that 1454 * This function checks if there is any spi message in the queue that
1103 * needs processing and delegate control to appropriate function 1455 * needs processing and delegate control to appropriate function
1104 * do_polling_transfer()/do_interrupt_transfer()/do_dma_transfer() 1456 * do_polling_transfer()/do_interrupt_dma_transfer()
1105 * based on the kind of the transfer 1457 * based on the kind of the transfer
1106 * 1458 *
1107 */ 1459 */
@@ -1113,8 +1465,8 @@ static void pump_messages(struct work_struct *work)
1113 1465
1114 /* Lock queue and check for queue work */ 1466 /* Lock queue and check for queue work */
1115 spin_lock_irqsave(&pl022->queue_lock, flags); 1467 spin_lock_irqsave(&pl022->queue_lock, flags);
1116 if (list_empty(&pl022->queue) || pl022->run == QUEUE_STOPPED) { 1468 if (list_empty(&pl022->queue) || !pl022->running) {
1117 pl022->busy = 0; 1469 pl022->busy = false;
1118 spin_unlock_irqrestore(&pl022->queue_lock, flags); 1470 spin_unlock_irqrestore(&pl022->queue_lock, flags);
1119 return; 1471 return;
1120 } 1472 }
@@ -1128,7 +1480,7 @@ static void pump_messages(struct work_struct *work)
1128 list_entry(pl022->queue.next, struct spi_message, queue); 1480 list_entry(pl022->queue.next, struct spi_message, queue);
1129 1481
1130 list_del_init(&pl022->cur_msg->queue); 1482 list_del_init(&pl022->cur_msg->queue);
1131 pl022->busy = 1; 1483 pl022->busy = true;
1132 spin_unlock_irqrestore(&pl022->queue_lock, flags); 1484 spin_unlock_irqrestore(&pl022->queue_lock, flags);
1133 1485
1134 /* Initial message state */ 1486 /* Initial message state */
@@ -1140,9 +1492,11 @@ static void pump_messages(struct work_struct *work)
1140 /* Setup the SPI using the per chip configuration */ 1492 /* Setup the SPI using the per chip configuration */
1141 pl022->cur_chip = spi_get_ctldata(pl022->cur_msg->spi); 1493 pl022->cur_chip = spi_get_ctldata(pl022->cur_msg->spi);
1142 /* 1494 /*
1143 * We enable the clocks here, then the clocks will be disabled when 1495 * We enable the core voltage and clocks here, then the clocks
1144 * giveback() is called in each method (poll/interrupt/DMA) 1496 * and core will be disabled when giveback() is called in each method
1497 * (poll/interrupt/DMA)
1145 */ 1498 */
1499 amba_vcore_enable(pl022->adev);
1146 amba_pclk_enable(pl022->adev); 1500 amba_pclk_enable(pl022->adev);
1147 clk_enable(pl022->clk); 1501 clk_enable(pl022->clk);
1148 restore_state(pl022); 1502 restore_state(pl022);
@@ -1150,10 +1504,8 @@ static void pump_messages(struct work_struct *work)
1150 1504
1151 if (pl022->cur_chip->xfer_type == POLLING_TRANSFER) 1505 if (pl022->cur_chip->xfer_type == POLLING_TRANSFER)
1152 do_polling_transfer(pl022); 1506 do_polling_transfer(pl022);
1153 else if (pl022->cur_chip->xfer_type == INTERRUPT_TRANSFER)
1154 do_interrupt_transfer(pl022);
1155 else 1507 else
1156 do_dma_transfer(pl022); 1508 do_interrupt_dma_transfer(pl022);
1157} 1509}
1158 1510
1159 1511
@@ -1162,8 +1514,8 @@ static int __init init_queue(struct pl022 *pl022)
1162 INIT_LIST_HEAD(&pl022->queue); 1514 INIT_LIST_HEAD(&pl022->queue);
1163 spin_lock_init(&pl022->queue_lock); 1515 spin_lock_init(&pl022->queue_lock);
1164 1516
1165 pl022->run = QUEUE_STOPPED; 1517 pl022->running = false;
1166 pl022->busy = 0; 1518 pl022->busy = false;
1167 1519
1168 tasklet_init(&pl022->pump_transfers, 1520 tasklet_init(&pl022->pump_transfers,
1169 pump_transfers, (unsigned long)pl022); 1521 pump_transfers, (unsigned long)pl022);
@@ -1184,12 +1536,12 @@ static int start_queue(struct pl022 *pl022)
1184 1536
1185 spin_lock_irqsave(&pl022->queue_lock, flags); 1537 spin_lock_irqsave(&pl022->queue_lock, flags);
1186 1538
1187 if (pl022->run == QUEUE_RUNNING || pl022->busy) { 1539 if (pl022->running || pl022->busy) {
1188 spin_unlock_irqrestore(&pl022->queue_lock, flags); 1540 spin_unlock_irqrestore(&pl022->queue_lock, flags);
1189 return -EBUSY; 1541 return -EBUSY;
1190 } 1542 }
1191 1543
1192 pl022->run = QUEUE_RUNNING; 1544 pl022->running = true;
1193 pl022->cur_msg = NULL; 1545 pl022->cur_msg = NULL;
1194 pl022->cur_transfer = NULL; 1546 pl022->cur_transfer = NULL;
1195 pl022->cur_chip = NULL; 1547 pl022->cur_chip = NULL;
@@ -1213,7 +1565,7 @@ static int stop_queue(struct pl022 *pl022)
1213 * A wait_queue on the pl022->busy could be used, but then the common 1565 * A wait_queue on the pl022->busy could be used, but then the common
1214 * execution path (pump_messages) would be required to call wake_up or 1566 * execution path (pump_messages) would be required to call wake_up or
1215 * friends on every SPI message. Do this instead */ 1567 * friends on every SPI message. Do this instead */
1216 while (!list_empty(&pl022->queue) && pl022->busy && limit--) { 1568 while ((!list_empty(&pl022->queue) || pl022->busy) && limit--) {
1217 spin_unlock_irqrestore(&pl022->queue_lock, flags); 1569 spin_unlock_irqrestore(&pl022->queue_lock, flags);
1218 msleep(10); 1570 msleep(10);
1219 spin_lock_irqsave(&pl022->queue_lock, flags); 1571 spin_lock_irqsave(&pl022->queue_lock, flags);
@@ -1221,7 +1573,8 @@ static int stop_queue(struct pl022 *pl022)
1221 1573
1222 if (!list_empty(&pl022->queue) || pl022->busy) 1574 if (!list_empty(&pl022->queue) || pl022->busy)
1223 status = -EBUSY; 1575 status = -EBUSY;
1224 else pl022->run = QUEUE_STOPPED; 1576 else
1577 pl022->running = false;
1225 1578
1226 spin_unlock_irqrestore(&pl022->queue_lock, flags); 1579 spin_unlock_irqrestore(&pl022->queue_lock, flags);
1227 1580
@@ -1248,100 +1601,56 @@ static int destroy_queue(struct pl022 *pl022)
1248} 1601}
1249 1602
1250static int verify_controller_parameters(struct pl022 *pl022, 1603static int verify_controller_parameters(struct pl022 *pl022,
1251 struct pl022_config_chip *chip_info) 1604 struct pl022_config_chip const *chip_info)
1252{ 1605{
1253 if ((chip_info->lbm != LOOPBACK_ENABLED)
1254 && (chip_info->lbm != LOOPBACK_DISABLED)) {
1255 dev_err(chip_info->dev,
1256 "loopback Mode is configured incorrectly\n");
1257 return -EINVAL;
1258 }
1259 if ((chip_info->iface < SSP_INTERFACE_MOTOROLA_SPI) 1606 if ((chip_info->iface < SSP_INTERFACE_MOTOROLA_SPI)
1260 || (chip_info->iface > SSP_INTERFACE_UNIDIRECTIONAL)) { 1607 || (chip_info->iface > SSP_INTERFACE_UNIDIRECTIONAL)) {
1261 dev_err(chip_info->dev, 1608 dev_err(&pl022->adev->dev,
1262 "interface is configured incorrectly\n"); 1609 "interface is configured incorrectly\n");
1263 return -EINVAL; 1610 return -EINVAL;
1264 } 1611 }
1265 if ((chip_info->iface == SSP_INTERFACE_UNIDIRECTIONAL) && 1612 if ((chip_info->iface == SSP_INTERFACE_UNIDIRECTIONAL) &&
1266 (!pl022->vendor->unidir)) { 1613 (!pl022->vendor->unidir)) {
1267 dev_err(chip_info->dev, 1614 dev_err(&pl022->adev->dev,
1268 "unidirectional mode not supported in this " 1615 "unidirectional mode not supported in this "
1269 "hardware version\n"); 1616 "hardware version\n");
1270 return -EINVAL; 1617 return -EINVAL;
1271 } 1618 }
1272 if ((chip_info->hierarchy != SSP_MASTER) 1619 if ((chip_info->hierarchy != SSP_MASTER)
1273 && (chip_info->hierarchy != SSP_SLAVE)) { 1620 && (chip_info->hierarchy != SSP_SLAVE)) {
1274 dev_err(chip_info->dev, 1621 dev_err(&pl022->adev->dev,
1275 "hierarchy is configured incorrectly\n"); 1622 "hierarchy is configured incorrectly\n");
1276 return -EINVAL; 1623 return -EINVAL;
1277 } 1624 }
1278 if (((chip_info->clk_freq).cpsdvsr < CPSDVR_MIN)
1279 || ((chip_info->clk_freq).cpsdvsr > CPSDVR_MAX)) {
1280 dev_err(chip_info->dev,
1281 "cpsdvsr is configured incorrectly\n");
1282 return -EINVAL;
1283 }
1284 if ((chip_info->endian_rx != SSP_RX_MSB)
1285 && (chip_info->endian_rx != SSP_RX_LSB)) {
1286 dev_err(chip_info->dev,
1287 "RX FIFO endianess is configured incorrectly\n");
1288 return -EINVAL;
1289 }
1290 if ((chip_info->endian_tx != SSP_TX_MSB)
1291 && (chip_info->endian_tx != SSP_TX_LSB)) {
1292 dev_err(chip_info->dev,
1293 "TX FIFO endianess is configured incorrectly\n");
1294 return -EINVAL;
1295 }
1296 if ((chip_info->data_size < SSP_DATA_BITS_4)
1297 || (chip_info->data_size > SSP_DATA_BITS_32)) {
1298 dev_err(chip_info->dev,
1299 "DATA Size is configured incorrectly\n");
1300 return -EINVAL;
1301 }
1302 if ((chip_info->com_mode != INTERRUPT_TRANSFER) 1625 if ((chip_info->com_mode != INTERRUPT_TRANSFER)
1303 && (chip_info->com_mode != DMA_TRANSFER) 1626 && (chip_info->com_mode != DMA_TRANSFER)
1304 && (chip_info->com_mode != POLLING_TRANSFER)) { 1627 && (chip_info->com_mode != POLLING_TRANSFER)) {
1305 dev_err(chip_info->dev, 1628 dev_err(&pl022->adev->dev,
1306 "Communication mode is configured incorrectly\n"); 1629 "Communication mode is configured incorrectly\n");
1307 return -EINVAL; 1630 return -EINVAL;
1308 } 1631 }
1309 if ((chip_info->rx_lev_trig < SSP_RX_1_OR_MORE_ELEM) 1632 if ((chip_info->rx_lev_trig < SSP_RX_1_OR_MORE_ELEM)
1310 || (chip_info->rx_lev_trig > SSP_RX_32_OR_MORE_ELEM)) { 1633 || (chip_info->rx_lev_trig > SSP_RX_32_OR_MORE_ELEM)) {
1311 dev_err(chip_info->dev, 1634 dev_err(&pl022->adev->dev,
1312 "RX FIFO Trigger Level is configured incorrectly\n"); 1635 "RX FIFO Trigger Level is configured incorrectly\n");
1313 return -EINVAL; 1636 return -EINVAL;
1314 } 1637 }
1315 if ((chip_info->tx_lev_trig < SSP_TX_1_OR_MORE_EMPTY_LOC) 1638 if ((chip_info->tx_lev_trig < SSP_TX_1_OR_MORE_EMPTY_LOC)
1316 || (chip_info->tx_lev_trig > SSP_TX_32_OR_MORE_EMPTY_LOC)) { 1639 || (chip_info->tx_lev_trig > SSP_TX_32_OR_MORE_EMPTY_LOC)) {
1317 dev_err(chip_info->dev, 1640 dev_err(&pl022->adev->dev,
1318 "TX FIFO Trigger Level is configured incorrectly\n"); 1641 "TX FIFO Trigger Level is configured incorrectly\n");
1319 return -EINVAL; 1642 return -EINVAL;
1320 } 1643 }
1321 if (chip_info->iface == SSP_INTERFACE_MOTOROLA_SPI) {
1322 if ((chip_info->clk_phase != SSP_CLK_FIRST_EDGE)
1323 && (chip_info->clk_phase != SSP_CLK_SECOND_EDGE)) {
1324 dev_err(chip_info->dev,
1325 "Clock Phase is configured incorrectly\n");
1326 return -EINVAL;
1327 }
1328 if ((chip_info->clk_pol != SSP_CLK_POL_IDLE_LOW)
1329 && (chip_info->clk_pol != SSP_CLK_POL_IDLE_HIGH)) {
1330 dev_err(chip_info->dev,
1331 "Clock Polarity is configured incorrectly\n");
1332 return -EINVAL;
1333 }
1334 }
1335 if (chip_info->iface == SSP_INTERFACE_NATIONAL_MICROWIRE) { 1644 if (chip_info->iface == SSP_INTERFACE_NATIONAL_MICROWIRE) {
1336 if ((chip_info->ctrl_len < SSP_BITS_4) 1645 if ((chip_info->ctrl_len < SSP_BITS_4)
1337 || (chip_info->ctrl_len > SSP_BITS_32)) { 1646 || (chip_info->ctrl_len > SSP_BITS_32)) {
1338 dev_err(chip_info->dev, 1647 dev_err(&pl022->adev->dev,
1339 "CTRL LEN is configured incorrectly\n"); 1648 "CTRL LEN is configured incorrectly\n");
1340 return -EINVAL; 1649 return -EINVAL;
1341 } 1650 }
1342 if ((chip_info->wait_state != SSP_MWIRE_WAIT_ZERO) 1651 if ((chip_info->wait_state != SSP_MWIRE_WAIT_ZERO)
1343 && (chip_info->wait_state != SSP_MWIRE_WAIT_ONE)) { 1652 && (chip_info->wait_state != SSP_MWIRE_WAIT_ONE)) {
1344 dev_err(chip_info->dev, 1653 dev_err(&pl022->adev->dev,
1345 "Wait State is configured incorrectly\n"); 1654 "Wait State is configured incorrectly\n");
1346 return -EINVAL; 1655 return -EINVAL;
1347 } 1656 }
@@ -1350,24 +1659,20 @@ static int verify_controller_parameters(struct pl022 *pl022,
1350 if ((chip_info->duplex != 1659 if ((chip_info->duplex !=
1351 SSP_MICROWIRE_CHANNEL_FULL_DUPLEX) 1660 SSP_MICROWIRE_CHANNEL_FULL_DUPLEX)
1352 && (chip_info->duplex != 1661 && (chip_info->duplex !=
1353 SSP_MICROWIRE_CHANNEL_HALF_DUPLEX)) 1662 SSP_MICROWIRE_CHANNEL_HALF_DUPLEX)) {
1354 dev_err(chip_info->dev, 1663 dev_err(&pl022->adev->dev,
1355 "Microwire duplex mode is configured incorrectly\n"); 1664 "Microwire duplex mode is configured incorrectly\n");
1356 return -EINVAL; 1665 return -EINVAL;
1666 }
1357 } else { 1667 } else {
1358 if (chip_info->duplex != SSP_MICROWIRE_CHANNEL_FULL_DUPLEX) 1668 if (chip_info->duplex != SSP_MICROWIRE_CHANNEL_FULL_DUPLEX)
1359 dev_err(chip_info->dev, 1669 dev_err(&pl022->adev->dev,
1360 "Microwire half duplex mode requested," 1670 "Microwire half duplex mode requested,"
1361 " but this is only available in the" 1671 " but this is only available in the"
1362 " ST version of PL022\n"); 1672 " ST version of PL022\n");
1363 return -EINVAL; 1673 return -EINVAL;
1364 } 1674 }
1365 } 1675 }
1366 if (chip_info->cs_control == NULL) {
1367 dev_warn(chip_info->dev,
1368 "Chip Select Function is NULL for this chip\n");
1369 chip_info->cs_control = null_cs_control;
1370 }
1371 return 0; 1676 return 0;
1372} 1677}
1373 1678
@@ -1387,7 +1692,7 @@ static int pl022_transfer(struct spi_device *spi, struct spi_message *msg)
1387 1692
1388 spin_lock_irqsave(&pl022->queue_lock, flags); 1693 spin_lock_irqsave(&pl022->queue_lock, flags);
1389 1694
1390 if (pl022->run == QUEUE_STOPPED) { 1695 if (!pl022->running) {
1391 spin_unlock_irqrestore(&pl022->queue_lock, flags); 1696 spin_unlock_irqrestore(&pl022->queue_lock, flags);
1392 return -ESHUTDOWN; 1697 return -ESHUTDOWN;
1393 } 1698 }
@@ -1396,7 +1701,7 @@ static int pl022_transfer(struct spi_device *spi, struct spi_message *msg)
1396 msg->state = STATE_START; 1701 msg->state = STATE_START;
1397 1702
1398 list_add_tail(&msg->queue, &pl022->queue); 1703 list_add_tail(&msg->queue, &pl022->queue);
1399 if (pl022->run == QUEUE_RUNNING && !pl022->busy) 1704 if (pl022->running && !pl022->busy)
1400 queue_work(pl022->workqueue, &pl022->pump_messages); 1705 queue_work(pl022->workqueue, &pl022->pump_messages);
1401 1706
1402 spin_unlock_irqrestore(&pl022->queue_lock, flags); 1707 spin_unlock_irqrestore(&pl022->queue_lock, flags);
@@ -1467,22 +1772,24 @@ static int calculate_effective_freq(struct pl022 *pl022,
1467 return 0; 1772 return 0;
1468} 1773}
1469 1774
1470/** 1775
1471 * NOT IMPLEMENTED 1776/*
1472 * process_dma_info - Processes the DMA info provided by client drivers 1777 * A piece of default chip info unless the platform
1473 * @chip_info: chip info provided by client device 1778 * supplies it.
1474 * @chip: Runtime state maintained by the SSP controller for each spi device
1475 *
1476 * This function processes and stores DMA config provided by client driver
1477 * into the runtime state maintained by the SSP controller driver
1478 */ 1779 */
1479static int process_dma_info(struct pl022_config_chip *chip_info, 1780static const struct pl022_config_chip pl022_default_chip_info = {
1480 struct chip_data *chip) 1781 .com_mode = POLLING_TRANSFER,
1481{ 1782 .iface = SSP_INTERFACE_MOTOROLA_SPI,
1482 dev_err(chip_info->dev, 1783 .hierarchy = SSP_SLAVE,
1483 "cannot process DMA info, DMA not implemented!\n"); 1784 .slave_tx_disable = DO_NOT_DRIVE_TX,
1484 return -ENOTSUPP; 1785 .rx_lev_trig = SSP_RX_1_OR_MORE_ELEM,
1485} 1786 .tx_lev_trig = SSP_TX_1_OR_MORE_EMPTY_LOC,
1787 .ctrl_len = SSP_BITS_8,
1788 .wait_state = SSP_MWIRE_WAIT_ZERO,
1789 .duplex = SSP_MICROWIRE_CHANNEL_FULL_DUPLEX,
1790 .cs_control = null_cs_control,
1791};
1792
1486 1793
1487/** 1794/**
1488 * pl022_setup - setup function registered to SPI master framework 1795 * pl022_setup - setup function registered to SPI master framework
@@ -1496,23 +1803,15 @@ static int process_dma_info(struct pl022_config_chip *chip_info,
1496 * controller hardware here, that is not done until the actual transfer 1803 * controller hardware here, that is not done until the actual transfer
1497 * commence. 1804 * commence.
1498 */ 1805 */
1499
1500/* FIXME: JUST GUESSING the spi->mode bits understood by this driver */
1501#define MODEBITS (SPI_CPOL | SPI_CPHA | SPI_CS_HIGH \
1502 | SPI_LSB_FIRST | SPI_LOOP)
1503
1504static int pl022_setup(struct spi_device *spi) 1806static int pl022_setup(struct spi_device *spi)
1505{ 1807{
1506 struct pl022_config_chip *chip_info; 1808 struct pl022_config_chip const *chip_info;
1507 struct chip_data *chip; 1809 struct chip_data *chip;
1810 struct ssp_clock_params clk_freq = {0, };
1508 int status = 0; 1811 int status = 0;
1509 struct pl022 *pl022 = spi_master_get_devdata(spi->master); 1812 struct pl022 *pl022 = spi_master_get_devdata(spi->master);
1510 1813 unsigned int bits = spi->bits_per_word;
1511 if (spi->mode & ~MODEBITS) { 1814 u32 tmp;
1512 dev_dbg(&spi->dev, "unsupported mode bits %x\n",
1513 spi->mode & ~MODEBITS);
1514 return -EINVAL;
1515 }
1516 1815
1517 if (!spi->max_speed_hz) 1816 if (!spi->max_speed_hz)
1518 return -EINVAL; 1817 return -EINVAL;
@@ -1535,48 +1834,13 @@ static int pl022_setup(struct spi_device *spi)
1535 chip_info = spi->controller_data; 1834 chip_info = spi->controller_data;
1536 1835
1537 if (chip_info == NULL) { 1836 if (chip_info == NULL) {
1837 chip_info = &pl022_default_chip_info;
1538 /* spi_board_info.controller_data not is supplied */ 1838 /* spi_board_info.controller_data not is supplied */
1539 dev_dbg(&spi->dev, 1839 dev_dbg(&spi->dev,
1540 "using default controller_data settings\n"); 1840 "using default controller_data settings\n");
1541 1841 } else
1542 chip_info =
1543 kzalloc(sizeof(struct pl022_config_chip), GFP_KERNEL);
1544
1545 if (!chip_info) {
1546 dev_err(&spi->dev,
1547 "cannot allocate controller data\n");
1548 status = -ENOMEM;
1549 goto err_first_setup;
1550 }
1551
1552 dev_dbg(&spi->dev, "allocated memory for controller data\n");
1553
1554 /* Pointer back to the SPI device */
1555 chip_info->dev = &spi->dev;
1556 /*
1557 * Set controller data default values:
1558 * Polling is supported by default
1559 */
1560 chip_info->lbm = LOOPBACK_DISABLED;
1561 chip_info->com_mode = POLLING_TRANSFER;
1562 chip_info->iface = SSP_INTERFACE_MOTOROLA_SPI;
1563 chip_info->hierarchy = SSP_SLAVE;
1564 chip_info->slave_tx_disable = DO_NOT_DRIVE_TX;
1565 chip_info->endian_tx = SSP_TX_LSB;
1566 chip_info->endian_rx = SSP_RX_LSB;
1567 chip_info->data_size = SSP_DATA_BITS_12;
1568 chip_info->rx_lev_trig = SSP_RX_1_OR_MORE_ELEM;
1569 chip_info->tx_lev_trig = SSP_TX_1_OR_MORE_EMPTY_LOC;
1570 chip_info->clk_phase = SSP_CLK_SECOND_EDGE;
1571 chip_info->clk_pol = SSP_CLK_POL_IDLE_LOW;
1572 chip_info->ctrl_len = SSP_BITS_8;
1573 chip_info->wait_state = SSP_MWIRE_WAIT_ZERO;
1574 chip_info->duplex = SSP_MICROWIRE_CHANNEL_FULL_DUPLEX;
1575 chip_info->cs_control = null_cs_control;
1576 } else {
1577 dev_dbg(&spi->dev, 1842 dev_dbg(&spi->dev,
1578 "using user supplied controller_data settings\n"); 1843 "using user supplied controller_data settings\n");
1579 }
1580 1844
1581 /* 1845 /*
1582 * We can override with custom divisors, else we use the board 1846 * We can override with custom divisors, else we use the board
@@ -1586,29 +1850,49 @@ static int pl022_setup(struct spi_device *spi)
1586 && (0 == chip_info->clk_freq.scr)) { 1850 && (0 == chip_info->clk_freq.scr)) {
1587 status = calculate_effective_freq(pl022, 1851 status = calculate_effective_freq(pl022,
1588 spi->max_speed_hz, 1852 spi->max_speed_hz,
1589 &chip_info->clk_freq); 1853 &clk_freq);
1590 if (status < 0) 1854 if (status < 0)
1591 goto err_config_params; 1855 goto err_config_params;
1592 } else { 1856 } else {
1593 if ((chip_info->clk_freq.cpsdvsr % 2) != 0) 1857 memcpy(&clk_freq, &chip_info->clk_freq, sizeof(clk_freq));
1594 chip_info->clk_freq.cpsdvsr = 1858 if ((clk_freq.cpsdvsr % 2) != 0)
1595 chip_info->clk_freq.cpsdvsr - 1; 1859 clk_freq.cpsdvsr =
1860 clk_freq.cpsdvsr - 1;
1861 }
1862 if ((clk_freq.cpsdvsr < CPSDVR_MIN)
1863 || (clk_freq.cpsdvsr > CPSDVR_MAX)) {
1864 status = -EINVAL;
1865 dev_err(&spi->dev,
1866 "cpsdvsr is configured incorrectly\n");
1867 goto err_config_params;
1596 } 1868 }
1869
1870
1597 status = verify_controller_parameters(pl022, chip_info); 1871 status = verify_controller_parameters(pl022, chip_info);
1598 if (status) { 1872 if (status) {
1599 dev_err(&spi->dev, "controller data is incorrect"); 1873 dev_err(&spi->dev, "controller data is incorrect");
1600 goto err_config_params; 1874 goto err_config_params;
1601 } 1875 }
1876
1602 /* Now set controller state based on controller data */ 1877 /* Now set controller state based on controller data */
1603 chip->xfer_type = chip_info->com_mode; 1878 chip->xfer_type = chip_info->com_mode;
1604 chip->cs_control = chip_info->cs_control; 1879 if (!chip_info->cs_control) {
1605 1880 chip->cs_control = null_cs_control;
1606 if (chip_info->data_size <= 8) { 1881 dev_warn(&spi->dev,
1607 dev_dbg(&spi->dev, "1 <= n <=8 bits per word\n"); 1882 "chip select function is NULL for this chip\n");
1883 } else
1884 chip->cs_control = chip_info->cs_control;
1885
1886 if (bits <= 3) {
1887 /* PL022 doesn't support less than 4-bits */
1888 status = -ENOTSUPP;
1889 goto err_config_params;
1890 } else if (bits <= 8) {
1891 dev_dbg(&spi->dev, "4 <= n <=8 bits per word\n");
1608 chip->n_bytes = 1; 1892 chip->n_bytes = 1;
1609 chip->read = READING_U8; 1893 chip->read = READING_U8;
1610 chip->write = WRITING_U8; 1894 chip->write = WRITING_U8;
1611 } else if (chip_info->data_size <= 16) { 1895 } else if (bits <= 16) {
1612 dev_dbg(&spi->dev, "9 <= n <= 16 bits per word\n"); 1896 dev_dbg(&spi->dev, "9 <= n <= 16 bits per word\n");
1613 chip->n_bytes = 2; 1897 chip->n_bytes = 2;
1614 chip->read = READING_U16; 1898 chip->read = READING_U16;
@@ -1625,6 +1909,7 @@ static int pl022_setup(struct spi_device *spi)
1625 dev_err(&spi->dev, 1909 dev_err(&spi->dev,
1626 "a standard pl022 can only handle " 1910 "a standard pl022 can only handle "
1627 "1 <= n <= 16 bit words\n"); 1911 "1 <= n <= 16 bit words\n");
1912 status = -ENOTSUPP;
1628 goto err_config_params; 1913 goto err_config_params;
1629 } 1914 }
1630 } 1915 }
@@ -1636,17 +1921,14 @@ static int pl022_setup(struct spi_device *spi)
1636 chip->cpsr = 0; 1921 chip->cpsr = 0;
1637 if ((chip_info->com_mode == DMA_TRANSFER) 1922 if ((chip_info->com_mode == DMA_TRANSFER)
1638 && ((pl022->master_info)->enable_dma)) { 1923 && ((pl022->master_info)->enable_dma)) {
1639 chip->enable_dma = 1; 1924 chip->enable_dma = true;
1640 dev_dbg(&spi->dev, "DMA mode set in controller state\n"); 1925 dev_dbg(&spi->dev, "DMA mode set in controller state\n");
1641 status = process_dma_info(chip_info, chip);
1642 if (status < 0)
1643 goto err_config_params;
1644 SSP_WRITE_BITS(chip->dmacr, SSP_DMA_ENABLED, 1926 SSP_WRITE_BITS(chip->dmacr, SSP_DMA_ENABLED,
1645 SSP_DMACR_MASK_RXDMAE, 0); 1927 SSP_DMACR_MASK_RXDMAE, 0);
1646 SSP_WRITE_BITS(chip->dmacr, SSP_DMA_ENABLED, 1928 SSP_WRITE_BITS(chip->dmacr, SSP_DMA_ENABLED,
1647 SSP_DMACR_MASK_TXDMAE, 1); 1929 SSP_DMACR_MASK_TXDMAE, 1);
1648 } else { 1930 } else {
1649 chip->enable_dma = 0; 1931 chip->enable_dma = false;
1650 dev_dbg(&spi->dev, "DMA mode NOT set in controller state\n"); 1932 dev_dbg(&spi->dev, "DMA mode NOT set in controller state\n");
1651 SSP_WRITE_BITS(chip->dmacr, SSP_DMA_DISABLED, 1933 SSP_WRITE_BITS(chip->dmacr, SSP_DMA_DISABLED,
1652 SSP_DMACR_MASK_RXDMAE, 0); 1934 SSP_DMACR_MASK_RXDMAE, 0);
@@ -1654,10 +1936,12 @@ static int pl022_setup(struct spi_device *spi)
1654 SSP_DMACR_MASK_TXDMAE, 1); 1936 SSP_DMACR_MASK_TXDMAE, 1);
1655 } 1937 }
1656 1938
1657 chip->cpsr = chip_info->clk_freq.cpsdvsr; 1939 chip->cpsr = clk_freq.cpsdvsr;
1658 1940
1659 /* Special setup for the ST micro extended control registers */ 1941 /* Special setup for the ST micro extended control registers */
1660 if (pl022->vendor->extended_cr) { 1942 if (pl022->vendor->extended_cr) {
1943 u32 etx;
1944
1661 if (pl022->vendor->pl023) { 1945 if (pl022->vendor->pl023) {
1662 /* These bits are only in the PL023 */ 1946 /* These bits are only in the PL023 */
1663 SSP_WRITE_BITS(chip->cr1, chip_info->clkdelay, 1947 SSP_WRITE_BITS(chip->cr1, chip_info->clkdelay,
@@ -1673,29 +1957,51 @@ static int pl022_setup(struct spi_device *spi)
1673 SSP_WRITE_BITS(chip->cr1, chip_info->wait_state, 1957 SSP_WRITE_BITS(chip->cr1, chip_info->wait_state,
1674 SSP_CR1_MASK_MWAIT_ST, 6); 1958 SSP_CR1_MASK_MWAIT_ST, 6);
1675 } 1959 }
1676 SSP_WRITE_BITS(chip->cr0, chip_info->data_size, 1960 SSP_WRITE_BITS(chip->cr0, bits - 1,
1677 SSP_CR0_MASK_DSS_ST, 0); 1961 SSP_CR0_MASK_DSS_ST, 0);
1678 SSP_WRITE_BITS(chip->cr1, chip_info->endian_rx, 1962
1679 SSP_CR1_MASK_RENDN_ST, 4); 1963 if (spi->mode & SPI_LSB_FIRST) {
1680 SSP_WRITE_BITS(chip->cr1, chip_info->endian_tx, 1964 tmp = SSP_RX_LSB;
1681 SSP_CR1_MASK_TENDN_ST, 5); 1965 etx = SSP_TX_LSB;
1966 } else {
1967 tmp = SSP_RX_MSB;
1968 etx = SSP_TX_MSB;
1969 }
1970 SSP_WRITE_BITS(chip->cr1, tmp, SSP_CR1_MASK_RENDN_ST, 4);
1971 SSP_WRITE_BITS(chip->cr1, etx, SSP_CR1_MASK_TENDN_ST, 5);
1682 SSP_WRITE_BITS(chip->cr1, chip_info->rx_lev_trig, 1972 SSP_WRITE_BITS(chip->cr1, chip_info->rx_lev_trig,
1683 SSP_CR1_MASK_RXIFLSEL_ST, 7); 1973 SSP_CR1_MASK_RXIFLSEL_ST, 7);
1684 SSP_WRITE_BITS(chip->cr1, chip_info->tx_lev_trig, 1974 SSP_WRITE_BITS(chip->cr1, chip_info->tx_lev_trig,
1685 SSP_CR1_MASK_TXIFLSEL_ST, 10); 1975 SSP_CR1_MASK_TXIFLSEL_ST, 10);
1686 } else { 1976 } else {
1687 SSP_WRITE_BITS(chip->cr0, chip_info->data_size, 1977 SSP_WRITE_BITS(chip->cr0, bits - 1,
1688 SSP_CR0_MASK_DSS, 0); 1978 SSP_CR0_MASK_DSS, 0);
1689 SSP_WRITE_BITS(chip->cr0, chip_info->iface, 1979 SSP_WRITE_BITS(chip->cr0, chip_info->iface,
1690 SSP_CR0_MASK_FRF, 4); 1980 SSP_CR0_MASK_FRF, 4);
1691 } 1981 }
1982
1692 /* Stuff that is common for all versions */ 1983 /* Stuff that is common for all versions */
1693 SSP_WRITE_BITS(chip->cr0, chip_info->clk_pol, SSP_CR0_MASK_SPO, 6); 1984 if (spi->mode & SPI_CPOL)
1694 SSP_WRITE_BITS(chip->cr0, chip_info->clk_phase, SSP_CR0_MASK_SPH, 7); 1985 tmp = SSP_CLK_POL_IDLE_HIGH;
1695 SSP_WRITE_BITS(chip->cr0, chip_info->clk_freq.scr, SSP_CR0_MASK_SCR, 8); 1986 else
1987 tmp = SSP_CLK_POL_IDLE_LOW;
1988 SSP_WRITE_BITS(chip->cr0, tmp, SSP_CR0_MASK_SPO, 6);
1989
1990 if (spi->mode & SPI_CPHA)
1991 tmp = SSP_CLK_SECOND_EDGE;
1992 else
1993 tmp = SSP_CLK_FIRST_EDGE;
1994 SSP_WRITE_BITS(chip->cr0, tmp, SSP_CR0_MASK_SPH, 7);
1995
1996 SSP_WRITE_BITS(chip->cr0, clk_freq.scr, SSP_CR0_MASK_SCR, 8);
1696 /* Loopback is available on all versions except PL023 */ 1997 /* Loopback is available on all versions except PL023 */
1697 if (!pl022->vendor->pl023) 1998 if (pl022->vendor->loopback) {
1698 SSP_WRITE_BITS(chip->cr1, chip_info->lbm, SSP_CR1_MASK_LBM, 0); 1999 if (spi->mode & SPI_LOOP)
2000 tmp = LOOPBACK_ENABLED;
2001 else
2002 tmp = LOOPBACK_DISABLED;
2003 SSP_WRITE_BITS(chip->cr1, tmp, SSP_CR1_MASK_LBM, 0);
2004 }
1699 SSP_WRITE_BITS(chip->cr1, SSP_DISABLED, SSP_CR1_MASK_SSE, 1); 2005 SSP_WRITE_BITS(chip->cr1, SSP_DISABLED, SSP_CR1_MASK_SSE, 1);
1700 SSP_WRITE_BITS(chip->cr1, chip_info->hierarchy, SSP_CR1_MASK_MS, 2); 2006 SSP_WRITE_BITS(chip->cr1, chip_info->hierarchy, SSP_CR1_MASK_MS, 2);
1701 SSP_WRITE_BITS(chip->cr1, chip_info->slave_tx_disable, SSP_CR1_MASK_SOD, 3); 2007 SSP_WRITE_BITS(chip->cr1, chip_info->slave_tx_disable, SSP_CR1_MASK_SOD, 3);
@@ -1704,7 +2010,7 @@ static int pl022_setup(struct spi_device *spi)
1704 spi_set_ctldata(spi, chip); 2010 spi_set_ctldata(spi, chip);
1705 return status; 2011 return status;
1706 err_config_params: 2012 err_config_params:
1707 err_first_setup: 2013 spi_set_ctldata(spi, NULL);
1708 kfree(chip); 2014 kfree(chip);
1709 return status; 2015 return status;
1710} 2016}
@@ -1726,7 +2032,7 @@ static void pl022_cleanup(struct spi_device *spi)
1726 2032
1727 2033
1728static int __devinit 2034static int __devinit
1729pl022_probe(struct amba_device *adev, struct amba_id *id) 2035pl022_probe(struct amba_device *adev, const struct amba_id *id)
1730{ 2036{
1731 struct device *dev = &adev->dev; 2037 struct device *dev = &adev->dev;
1732 struct pl022_ssp_controller *platform_info = adev->dev.platform_data; 2038 struct pl022_ssp_controller *platform_info = adev->dev.platform_data;
@@ -1766,12 +2072,21 @@ pl022_probe(struct amba_device *adev, struct amba_id *id)
1766 master->setup = pl022_setup; 2072 master->setup = pl022_setup;
1767 master->transfer = pl022_transfer; 2073 master->transfer = pl022_transfer;
1768 2074
2075 /*
2076 * Supports mode 0-3, loopback, and active low CS. Transfers are
2077 * always MS bit first on the original pl022.
2078 */
2079 master->mode_bits = SPI_CPOL | SPI_CPHA | SPI_CS_HIGH | SPI_LOOP;
2080 if (pl022->vendor->extended_cr)
2081 master->mode_bits |= SPI_LSB_FIRST;
2082
1769 dev_dbg(&adev->dev, "BUSNO: %d\n", master->bus_num); 2083 dev_dbg(&adev->dev, "BUSNO: %d\n", master->bus_num);
1770 2084
1771 status = amba_request_regions(adev, NULL); 2085 status = amba_request_regions(adev, NULL);
1772 if (status) 2086 if (status)
1773 goto err_no_ioregion; 2087 goto err_no_ioregion;
1774 2088
2089 pl022->phybase = adev->res.start;
1775 pl022->virtbase = ioremap(adev->res.start, resource_size(&adev->res)); 2090 pl022->virtbase = ioremap(adev->res.start, resource_size(&adev->res));
1776 if (pl022->virtbase == NULL) { 2091 if (pl022->virtbase == NULL) {
1777 status = -ENOMEM; 2092 status = -ENOMEM;
@@ -1798,6 +2113,14 @@ pl022_probe(struct amba_device *adev, struct amba_id *id)
1798 dev_err(&adev->dev, "probe - cannot get IRQ (%d)\n", status); 2113 dev_err(&adev->dev, "probe - cannot get IRQ (%d)\n", status);
1799 goto err_no_irq; 2114 goto err_no_irq;
1800 } 2115 }
2116
2117 /* Get DMA channels */
2118 if (platform_info->enable_dma) {
2119 status = pl022_dma_probe(pl022);
2120 if (status != 0)
2121 platform_info->enable_dma = 0;
2122 }
2123
1801 /* Initialize and start queue */ 2124 /* Initialize and start queue */
1802 status = init_queue(pl022); 2125 status = init_queue(pl022);
1803 if (status != 0) { 2126 if (status != 0) {
@@ -1817,15 +2140,20 @@ pl022_probe(struct amba_device *adev, struct amba_id *id)
1817 "probe - problem registering spi master\n"); 2140 "probe - problem registering spi master\n");
1818 goto err_spi_register; 2141 goto err_spi_register;
1819 } 2142 }
1820 dev_dbg(dev, "probe succeded\n"); 2143 dev_dbg(dev, "probe succeeded\n");
1821 /* Disable the silicon block pclk and clock it when needed */ 2144 /*
2145 * Disable the silicon block pclk and any voltage domain and just
2146 * power it up and clock it when it's needed
2147 */
1822 amba_pclk_disable(adev); 2148 amba_pclk_disable(adev);
2149 amba_vcore_disable(adev);
1823 return 0; 2150 return 0;
1824 2151
1825 err_spi_register: 2152 err_spi_register:
1826 err_start_queue: 2153 err_start_queue:
1827 err_init_queue: 2154 err_init_queue:
1828 destroy_queue(pl022); 2155 destroy_queue(pl022);
2156 pl022_dma_remove(pl022);
1829 free_irq(adev->irq[0], pl022); 2157 free_irq(adev->irq[0], pl022);
1830 err_no_irq: 2158 err_no_irq:
1831 clk_put(pl022->clk); 2159 clk_put(pl022->clk);
@@ -1856,6 +2184,7 @@ pl022_remove(struct amba_device *adev)
1856 return status; 2184 return status;
1857 } 2185 }
1858 load_ssp_default_config(pl022); 2186 load_ssp_default_config(pl022);
2187 pl022_dma_remove(pl022);
1859 free_irq(adev->irq[0], pl022); 2188 free_irq(adev->irq[0], pl022);
1860 clk_disable(pl022->clk); 2189 clk_disable(pl022->clk);
1861 clk_put(pl022->clk); 2190 clk_put(pl022->clk);
@@ -1865,7 +2194,7 @@ pl022_remove(struct amba_device *adev)
1865 spi_unregister_master(pl022->master); 2194 spi_unregister_master(pl022->master);
1866 spi_master_put(pl022->master); 2195 spi_master_put(pl022->master);
1867 amba_set_drvdata(adev, NULL); 2196 amba_set_drvdata(adev, NULL);
1868 dev_dbg(&adev->dev, "remove succeded\n"); 2197 dev_dbg(&adev->dev, "remove succeeded\n");
1869 return 0; 2198 return 0;
1870} 2199}
1871 2200
@@ -1881,9 +2210,11 @@ static int pl022_suspend(struct amba_device *adev, pm_message_t state)
1881 return status; 2210 return status;
1882 } 2211 }
1883 2212
2213 amba_vcore_enable(adev);
1884 amba_pclk_enable(adev); 2214 amba_pclk_enable(adev);
1885 load_ssp_default_config(pl022); 2215 load_ssp_default_config(pl022);
1886 amba_pclk_disable(adev); 2216 amba_pclk_disable(adev);
2217 amba_vcore_disable(adev);
1887 dev_dbg(&adev->dev, "suspended\n"); 2218 dev_dbg(&adev->dev, "suspended\n");
1888 return 0; 2219 return 0;
1889} 2220}
@@ -1913,6 +2244,7 @@ static struct vendor_data vendor_arm = {
1913 .unidir = false, 2244 .unidir = false,
1914 .extended_cr = false, 2245 .extended_cr = false,
1915 .pl023 = false, 2246 .pl023 = false,
2247 .loopback = true,
1916}; 2248};
1917 2249
1918 2250
@@ -1922,6 +2254,7 @@ static struct vendor_data vendor_st = {
1922 .unidir = false, 2254 .unidir = false,
1923 .extended_cr = true, 2255 .extended_cr = true,
1924 .pl023 = false, 2256 .pl023 = false,
2257 .loopback = true,
1925}; 2258};
1926 2259
1927static struct vendor_data vendor_st_pl023 = { 2260static struct vendor_data vendor_st_pl023 = {
@@ -1930,6 +2263,16 @@ static struct vendor_data vendor_st_pl023 = {
1930 .unidir = false, 2263 .unidir = false,
1931 .extended_cr = true, 2264 .extended_cr = true,
1932 .pl023 = true, 2265 .pl023 = true,
2266 .loopback = false,
2267};
2268
2269static struct vendor_data vendor_db5500_pl023 = {
2270 .fifodepth = 32,
2271 .max_bpw = 32,
2272 .unidir = false,
2273 .extended_cr = true,
2274 .pl023 = true,
2275 .loopback = true,
1933}; 2276};
1934 2277
1935static struct amba_id pl022_ids[] = { 2278static struct amba_id pl022_ids[] = {
@@ -1963,6 +2306,11 @@ static struct amba_id pl022_ids[] = {
1963 .mask = 0xffffffff, 2306 .mask = 0xffffffff,
1964 .data = &vendor_st_pl023, 2307 .data = &vendor_st_pl023,
1965 }, 2308 },
2309 {
2310 .id = 0x10080023,
2311 .mask = 0xffffffff,
2312 .data = &vendor_db5500_pl023,
2313 },
1966 { 0, 0 }, 2314 { 0, 0 },
1967}; 2315};
1968 2316