Linus Walleij | b43d65f | 2009-06-09 08:11:42 +0100 | [diff] [blame] | 1 | /* |
Linus Walleij | b43d65f | 2009-06-09 08:11:42 +0100 | [diff] [blame] | 2 | * A driver for the ARM PL022 PrimeCell SSP/SPI bus master. |
| 3 | * |
| 4 | * Copyright (C) 2008-2009 ST-Ericsson AB |
| 5 | * Copyright (C) 2006 STMicroelectronics Pvt. Ltd. |
| 6 | * |
| 7 | * Author: Linus Walleij <linus.walleij@stericsson.com> |
| 8 | * |
| 9 | * Initial version inspired by: |
| 10 | * linux-2.6.17-rc3-mm1/drivers/spi/pxa2xx_spi.c |
| 11 | * Initial adoption to PL022 by: |
| 12 | * Sachin Verma <sachin.verma@st.com> |
| 13 | * |
| 14 | * This program is free software; you can redistribute it and/or modify |
| 15 | * it under the terms of the GNU General Public License as published by |
| 16 | * the Free Software Foundation; either version 2 of the License, or |
| 17 | * (at your option) any later version. |
| 18 | * |
| 19 | * This program is distributed in the hope that it will be useful, |
| 20 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 21 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 22 | * GNU General Public License for more details. |
| 23 | */ |
| 24 | |
Linus Walleij | b43d65f | 2009-06-09 08:11:42 +0100 | [diff] [blame] | 25 | #include <linux/init.h> |
| 26 | #include <linux/module.h> |
| 27 | #include <linux/device.h> |
| 28 | #include <linux/ioport.h> |
| 29 | #include <linux/errno.h> |
| 30 | #include <linux/interrupt.h> |
| 31 | #include <linux/spi/spi.h> |
Linus Walleij | b43d65f | 2009-06-09 08:11:42 +0100 | [diff] [blame] | 32 | #include <linux/delay.h> |
| 33 | #include <linux/clk.h> |
| 34 | #include <linux/err.h> |
| 35 | #include <linux/amba/bus.h> |
| 36 | #include <linux/amba/pl022.h> |
| 37 | #include <linux/io.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 38 | #include <linux/slab.h> |
Linus Walleij | b1b6b9a | 2010-09-29 17:31:35 +0900 | [diff] [blame] | 39 | #include <linux/dmaengine.h> |
| 40 | #include <linux/dma-mapping.h> |
| 41 | #include <linux/scatterlist.h> |
Rabin Vincent | bcda6ff | 2011-06-16 10:14:40 +0200 | [diff] [blame] | 42 | #include <linux/pm_runtime.h> |
Roland Stigge | f6f46de | 2012-08-22 15:49:17 +0200 | [diff] [blame^] | 43 | #include <linux/gpio.h> |
Linus Walleij | b43d65f | 2009-06-09 08:11:42 +0100 | [diff] [blame] | 44 | |
| 45 | /* |
| 46 | * This macro is used to define some register default values. |
| 47 | * reg is masked with mask, the OR:ed with an (again masked) |
| 48 | * val shifted sb steps to the left. |
| 49 | */ |
| 50 | #define SSP_WRITE_BITS(reg, val, mask, sb) \ |
| 51 | ((reg) = (((reg) & ~(mask)) | (((val)<<(sb)) & (mask)))) |
| 52 | |
| 53 | /* |
| 54 | * This macro is also used to define some default values. |
| 55 | * It will just shift val by sb steps to the left and mask |
| 56 | * the result with mask. |
| 57 | */ |
| 58 | #define GEN_MASK_BITS(val, mask, sb) \ |
| 59 | (((val)<<(sb)) & (mask)) |
| 60 | |
| 61 | #define DRIVE_TX 0 |
| 62 | #define DO_NOT_DRIVE_TX 1 |
| 63 | |
| 64 | #define DO_NOT_QUEUE_DMA 0 |
| 65 | #define QUEUE_DMA 1 |
| 66 | |
| 67 | #define RX_TRANSFER 1 |
| 68 | #define TX_TRANSFER 2 |
| 69 | |
| 70 | /* |
| 71 | * Macros to access SSP Registers with their offsets |
| 72 | */ |
| 73 | #define SSP_CR0(r) (r + 0x000) |
| 74 | #define SSP_CR1(r) (r + 0x004) |
| 75 | #define SSP_DR(r) (r + 0x008) |
| 76 | #define SSP_SR(r) (r + 0x00C) |
| 77 | #define SSP_CPSR(r) (r + 0x010) |
| 78 | #define SSP_IMSC(r) (r + 0x014) |
| 79 | #define SSP_RIS(r) (r + 0x018) |
| 80 | #define SSP_MIS(r) (r + 0x01C) |
| 81 | #define SSP_ICR(r) (r + 0x020) |
| 82 | #define SSP_DMACR(r) (r + 0x024) |
| 83 | #define SSP_ITCR(r) (r + 0x080) |
| 84 | #define SSP_ITIP(r) (r + 0x084) |
| 85 | #define SSP_ITOP(r) (r + 0x088) |
| 86 | #define SSP_TDR(r) (r + 0x08C) |
| 87 | |
| 88 | #define SSP_PID0(r) (r + 0xFE0) |
| 89 | #define SSP_PID1(r) (r + 0xFE4) |
| 90 | #define SSP_PID2(r) (r + 0xFE8) |
| 91 | #define SSP_PID3(r) (r + 0xFEC) |
| 92 | |
| 93 | #define SSP_CID0(r) (r + 0xFF0) |
| 94 | #define SSP_CID1(r) (r + 0xFF4) |
| 95 | #define SSP_CID2(r) (r + 0xFF8) |
| 96 | #define SSP_CID3(r) (r + 0xFFC) |
| 97 | |
| 98 | /* |
| 99 | * SSP Control Register 0 - SSP_CR0 |
| 100 | */ |
Linus Walleij | 556f4ae | 2010-05-05 09:28:15 +0000 | [diff] [blame] | 101 | #define SSP_CR0_MASK_DSS (0x0FUL << 0) |
| 102 | #define SSP_CR0_MASK_FRF (0x3UL << 4) |
Linus Walleij | b43d65f | 2009-06-09 08:11:42 +0100 | [diff] [blame] | 103 | #define SSP_CR0_MASK_SPO (0x1UL << 6) |
| 104 | #define SSP_CR0_MASK_SPH (0x1UL << 7) |
| 105 | #define SSP_CR0_MASK_SCR (0xFFUL << 8) |
Linus Walleij | 556f4ae | 2010-05-05 09:28:15 +0000 | [diff] [blame] | 106 | |
| 107 | /* |
| 108 | * The ST version of this block moves som bits |
| 109 | * in SSP_CR0 and extends it to 32 bits |
| 110 | */ |
| 111 | #define SSP_CR0_MASK_DSS_ST (0x1FUL << 0) |
| 112 | #define SSP_CR0_MASK_HALFDUP_ST (0x1UL << 5) |
| 113 | #define SSP_CR0_MASK_CSS_ST (0x1FUL << 16) |
| 114 | #define SSP_CR0_MASK_FRF_ST (0x3UL << 21) |
| 115 | |
Linus Walleij | b43d65f | 2009-06-09 08:11:42 +0100 | [diff] [blame] | 116 | /* |
| 117 | * SSP Control Register 0 - SSP_CR1 |
| 118 | */ |
| 119 | #define SSP_CR1_MASK_LBM (0x1UL << 0) |
| 120 | #define SSP_CR1_MASK_SSE (0x1UL << 1) |
| 121 | #define SSP_CR1_MASK_MS (0x1UL << 2) |
| 122 | #define SSP_CR1_MASK_SOD (0x1UL << 3) |
Linus Walleij | b43d65f | 2009-06-09 08:11:42 +0100 | [diff] [blame] | 123 | |
| 124 | /* |
Linus Walleij | 556f4ae | 2010-05-05 09:28:15 +0000 | [diff] [blame] | 125 | * The ST version of this block adds some bits |
| 126 | * in SSP_CR1 |
Linus Walleij | b43d65f | 2009-06-09 08:11:42 +0100 | [diff] [blame] | 127 | */ |
Linus Walleij | 556f4ae | 2010-05-05 09:28:15 +0000 | [diff] [blame] | 128 | #define SSP_CR1_MASK_RENDN_ST (0x1UL << 4) |
| 129 | #define SSP_CR1_MASK_TENDN_ST (0x1UL << 5) |
| 130 | #define SSP_CR1_MASK_MWAIT_ST (0x1UL << 6) |
| 131 | #define SSP_CR1_MASK_RXIFLSEL_ST (0x7UL << 7) |
| 132 | #define SSP_CR1_MASK_TXIFLSEL_ST (0x7UL << 10) |
Linus Walleij | 781c7b1 | 2010-05-07 08:40:53 +0000 | [diff] [blame] | 133 | /* This one is only in the PL023 variant */ |
| 134 | #define SSP_CR1_MASK_FBCLKDEL_ST (0x7UL << 13) |
Linus Walleij | b43d65f | 2009-06-09 08:11:42 +0100 | [diff] [blame] | 135 | |
| 136 | /* |
| 137 | * SSP Status Register - SSP_SR |
| 138 | */ |
| 139 | #define SSP_SR_MASK_TFE (0x1UL << 0) /* Transmit FIFO empty */ |
| 140 | #define SSP_SR_MASK_TNF (0x1UL << 1) /* Transmit FIFO not full */ |
| 141 | #define SSP_SR_MASK_RNE (0x1UL << 2) /* Receive FIFO not empty */ |
Linus Walleij | 556f4ae | 2010-05-05 09:28:15 +0000 | [diff] [blame] | 142 | #define SSP_SR_MASK_RFF (0x1UL << 3) /* Receive FIFO full */ |
Linus Walleij | b43d65f | 2009-06-09 08:11:42 +0100 | [diff] [blame] | 143 | #define SSP_SR_MASK_BSY (0x1UL << 4) /* Busy Flag */ |
| 144 | |
| 145 | /* |
| 146 | * SSP Clock Prescale Register - SSP_CPSR |
| 147 | */ |
| 148 | #define SSP_CPSR_MASK_CPSDVSR (0xFFUL << 0) |
| 149 | |
| 150 | /* |
| 151 | * SSP Interrupt Mask Set/Clear Register - SSP_IMSC |
| 152 | */ |
| 153 | #define SSP_IMSC_MASK_RORIM (0x1UL << 0) /* Receive Overrun Interrupt mask */ |
| 154 | #define SSP_IMSC_MASK_RTIM (0x1UL << 1) /* Receive timeout Interrupt mask */ |
| 155 | #define SSP_IMSC_MASK_RXIM (0x1UL << 2) /* Receive FIFO Interrupt mask */ |
| 156 | #define SSP_IMSC_MASK_TXIM (0x1UL << 3) /* Transmit FIFO Interrupt mask */ |
| 157 | |
| 158 | /* |
| 159 | * SSP Raw Interrupt Status Register - SSP_RIS |
| 160 | */ |
| 161 | /* Receive Overrun Raw Interrupt status */ |
| 162 | #define SSP_RIS_MASK_RORRIS (0x1UL << 0) |
| 163 | /* Receive Timeout Raw Interrupt status */ |
| 164 | #define SSP_RIS_MASK_RTRIS (0x1UL << 1) |
| 165 | /* Receive FIFO Raw Interrupt status */ |
| 166 | #define SSP_RIS_MASK_RXRIS (0x1UL << 2) |
| 167 | /* Transmit FIFO Raw Interrupt status */ |
| 168 | #define SSP_RIS_MASK_TXRIS (0x1UL << 3) |
| 169 | |
| 170 | /* |
| 171 | * SSP Masked Interrupt Status Register - SSP_MIS |
| 172 | */ |
| 173 | /* Receive Overrun Masked Interrupt status */ |
| 174 | #define SSP_MIS_MASK_RORMIS (0x1UL << 0) |
| 175 | /* Receive Timeout Masked Interrupt status */ |
| 176 | #define SSP_MIS_MASK_RTMIS (0x1UL << 1) |
| 177 | /* Receive FIFO Masked Interrupt status */ |
| 178 | #define SSP_MIS_MASK_RXMIS (0x1UL << 2) |
| 179 | /* Transmit FIFO Masked Interrupt status */ |
| 180 | #define SSP_MIS_MASK_TXMIS (0x1UL << 3) |
| 181 | |
| 182 | /* |
| 183 | * SSP Interrupt Clear Register - SSP_ICR |
| 184 | */ |
| 185 | /* Receive Overrun Raw Clear Interrupt bit */ |
| 186 | #define SSP_ICR_MASK_RORIC (0x1UL << 0) |
| 187 | /* Receive Timeout Clear Interrupt bit */ |
| 188 | #define SSP_ICR_MASK_RTIC (0x1UL << 1) |
| 189 | |
| 190 | /* |
| 191 | * SSP DMA Control Register - SSP_DMACR |
| 192 | */ |
| 193 | /* Receive DMA Enable bit */ |
| 194 | #define SSP_DMACR_MASK_RXDMAE (0x1UL << 0) |
| 195 | /* Transmit DMA Enable bit */ |
| 196 | #define SSP_DMACR_MASK_TXDMAE (0x1UL << 1) |
| 197 | |
| 198 | /* |
| 199 | * SSP Integration Test control Register - SSP_ITCR |
| 200 | */ |
| 201 | #define SSP_ITCR_MASK_ITEN (0x1UL << 0) |
| 202 | #define SSP_ITCR_MASK_TESTFIFO (0x1UL << 1) |
| 203 | |
| 204 | /* |
| 205 | * SSP Integration Test Input Register - SSP_ITIP |
| 206 | */ |
| 207 | #define ITIP_MASK_SSPRXD (0x1UL << 0) |
| 208 | #define ITIP_MASK_SSPFSSIN (0x1UL << 1) |
| 209 | #define ITIP_MASK_SSPCLKIN (0x1UL << 2) |
| 210 | #define ITIP_MASK_RXDMAC (0x1UL << 3) |
| 211 | #define ITIP_MASK_TXDMAC (0x1UL << 4) |
| 212 | #define ITIP_MASK_SSPTXDIN (0x1UL << 5) |
| 213 | |
| 214 | /* |
| 215 | * SSP Integration Test output Register - SSP_ITOP |
| 216 | */ |
| 217 | #define ITOP_MASK_SSPTXD (0x1UL << 0) |
| 218 | #define ITOP_MASK_SSPFSSOUT (0x1UL << 1) |
| 219 | #define ITOP_MASK_SSPCLKOUT (0x1UL << 2) |
| 220 | #define ITOP_MASK_SSPOEn (0x1UL << 3) |
| 221 | #define ITOP_MASK_SSPCTLOEn (0x1UL << 4) |
| 222 | #define ITOP_MASK_RORINTR (0x1UL << 5) |
| 223 | #define ITOP_MASK_RTINTR (0x1UL << 6) |
| 224 | #define ITOP_MASK_RXINTR (0x1UL << 7) |
| 225 | #define ITOP_MASK_TXINTR (0x1UL << 8) |
| 226 | #define ITOP_MASK_INTR (0x1UL << 9) |
| 227 | #define ITOP_MASK_RXDMABREQ (0x1UL << 10) |
| 228 | #define ITOP_MASK_RXDMASREQ (0x1UL << 11) |
| 229 | #define ITOP_MASK_TXDMABREQ (0x1UL << 12) |
| 230 | #define ITOP_MASK_TXDMASREQ (0x1UL << 13) |
| 231 | |
| 232 | /* |
| 233 | * SSP Test Data Register - SSP_TDR |
| 234 | */ |
Linus Walleij | 556f4ae | 2010-05-05 09:28:15 +0000 | [diff] [blame] | 235 | #define TDR_MASK_TESTDATA (0xFFFFFFFF) |
Linus Walleij | b43d65f | 2009-06-09 08:11:42 +0100 | [diff] [blame] | 236 | |
| 237 | /* |
| 238 | * Message State |
| 239 | * we use the spi_message.state (void *) pointer to |
| 240 | * hold a single state value, that's why all this |
| 241 | * (void *) casting is done here. |
| 242 | */ |
Linus Walleij | 556f4ae | 2010-05-05 09:28:15 +0000 | [diff] [blame] | 243 | #define STATE_START ((void *) 0) |
| 244 | #define STATE_RUNNING ((void *) 1) |
| 245 | #define STATE_DONE ((void *) 2) |
| 246 | #define STATE_ERROR ((void *) -1) |
Linus Walleij | b43d65f | 2009-06-09 08:11:42 +0100 | [diff] [blame] | 247 | |
| 248 | /* |
Linus Walleij | b43d65f | 2009-06-09 08:11:42 +0100 | [diff] [blame] | 249 | * SSP State - Whether Enabled or Disabled |
| 250 | */ |
Linus Walleij | 556f4ae | 2010-05-05 09:28:15 +0000 | [diff] [blame] | 251 | #define SSP_DISABLED (0) |
| 252 | #define SSP_ENABLED (1) |
Linus Walleij | b43d65f | 2009-06-09 08:11:42 +0100 | [diff] [blame] | 253 | |
| 254 | /* |
| 255 | * SSP DMA State - Whether DMA Enabled or Disabled |
| 256 | */ |
Linus Walleij | 556f4ae | 2010-05-05 09:28:15 +0000 | [diff] [blame] | 257 | #define SSP_DMA_DISABLED (0) |
| 258 | #define SSP_DMA_ENABLED (1) |
Linus Walleij | b43d65f | 2009-06-09 08:11:42 +0100 | [diff] [blame] | 259 | |
| 260 | /* |
| 261 | * SSP Clock Defaults |
| 262 | */ |
Linus Walleij | 556f4ae | 2010-05-05 09:28:15 +0000 | [diff] [blame] | 263 | #define SSP_DEFAULT_CLKRATE 0x2 |
| 264 | #define SSP_DEFAULT_PRESCALE 0x40 |
Linus Walleij | b43d65f | 2009-06-09 08:11:42 +0100 | [diff] [blame] | 265 | |
| 266 | /* |
| 267 | * SSP Clock Parameter ranges |
| 268 | */ |
| 269 | #define CPSDVR_MIN 0x02 |
| 270 | #define CPSDVR_MAX 0xFE |
| 271 | #define SCR_MIN 0x00 |
| 272 | #define SCR_MAX 0xFF |
| 273 | |
| 274 | /* |
| 275 | * SSP Interrupt related Macros |
| 276 | */ |
| 277 | #define DEFAULT_SSP_REG_IMSC 0x0UL |
| 278 | #define DISABLE_ALL_INTERRUPTS DEFAULT_SSP_REG_IMSC |
| 279 | #define ENABLE_ALL_INTERRUPTS (~DEFAULT_SSP_REG_IMSC) |
| 280 | |
| 281 | #define CLEAR_ALL_INTERRUPTS 0x3 |
| 282 | |
Magnus Templing | a18c266 | 2011-05-19 18:05:34 +0200 | [diff] [blame] | 283 | #define SPI_POLLING_TIMEOUT 1000 |
| 284 | |
Linus Walleij | b43d65f | 2009-06-09 08:11:42 +0100 | [diff] [blame] | 285 | /* |
| 286 | * The type of reading going on on this chip |
| 287 | */ |
| 288 | enum ssp_reading { |
| 289 | READING_NULL, |
| 290 | READING_U8, |
| 291 | READING_U16, |
| 292 | READING_U32 |
| 293 | }; |
| 294 | |
| 295 | /** |
| 296 | * The type of writing going on on this chip |
| 297 | */ |
| 298 | enum ssp_writing { |
| 299 | WRITING_NULL, |
| 300 | WRITING_U8, |
| 301 | WRITING_U16, |
| 302 | WRITING_U32 |
| 303 | }; |
| 304 | |
| 305 | /** |
| 306 | * struct vendor_data - vendor-specific config parameters |
| 307 | * for PL022 derivates |
| 308 | * @fifodepth: depth of FIFOs (both) |
| 309 | * @max_bpw: maximum number of bits per word |
| 310 | * @unidir: supports unidirection transfers |
Linus Walleij | 556f4ae | 2010-05-05 09:28:15 +0000 | [diff] [blame] | 311 | * @extended_cr: 32 bit wide control register 0 with extra |
| 312 | * features and extra features in CR1 as found in the ST variants |
Linus Walleij | 781c7b1 | 2010-05-07 08:40:53 +0000 | [diff] [blame] | 313 | * @pl023: supports a subset of the ST extensions called "PL023" |
Linus Walleij | b43d65f | 2009-06-09 08:11:42 +0100 | [diff] [blame] | 314 | */ |
| 315 | struct vendor_data { |
| 316 | int fifodepth; |
| 317 | int max_bpw; |
| 318 | bool unidir; |
Linus Walleij | 556f4ae | 2010-05-05 09:28:15 +0000 | [diff] [blame] | 319 | bool extended_cr; |
Linus Walleij | 781c7b1 | 2010-05-07 08:40:53 +0000 | [diff] [blame] | 320 | bool pl023; |
Philippe Langlais | 06fb01f | 2011-03-23 11:05:16 +0100 | [diff] [blame] | 321 | bool loopback; |
Linus Walleij | b43d65f | 2009-06-09 08:11:42 +0100 | [diff] [blame] | 322 | }; |
| 323 | |
| 324 | /** |
| 325 | * struct pl022 - This is the private SSP driver data structure |
| 326 | * @adev: AMBA device model hookup |
Linus Walleij | 12e8b32 | 2011-02-08 13:03:55 +0100 | [diff] [blame] | 327 | * @vendor: vendor data for the IP block |
| 328 | * @phybase: the physical memory where the SSP device resides |
| 329 | * @virtbase: the virtual memory where the SSP is mapped |
| 330 | * @clk: outgoing clock "SPICLK" for the SPI bus |
Linus Walleij | b43d65f | 2009-06-09 08:11:42 +0100 | [diff] [blame] | 331 | * @master: SPI framework hookup |
| 332 | * @master_info: controller-specific data from machine setup |
Chris Blair | 14af60b | 2012-02-02 13:59:34 +0100 | [diff] [blame] | 333 | * @kworker: thread struct for message pump |
| 334 | * @kworker_task: pointer to task for message pump kworker thread |
| 335 | * @pump_messages: work struct for scheduling work to the message pump |
Linus Walleij | 12e8b32 | 2011-02-08 13:03:55 +0100 | [diff] [blame] | 336 | * @queue_lock: spinlock to syncronise access to message queue |
| 337 | * @queue: message queue |
Chris Blair | 14af60b | 2012-02-02 13:59:34 +0100 | [diff] [blame] | 338 | * @busy: message pump is busy |
| 339 | * @running: message pump is running |
Linus Walleij | b43d65f | 2009-06-09 08:11:42 +0100 | [diff] [blame] | 340 | * @pump_transfers: Tasklet used in Interrupt Transfer mode |
| 341 | * @cur_msg: Pointer to current spi_message being processed |
| 342 | * @cur_transfer: Pointer to current spi_transfer |
| 343 | * @cur_chip: pointer to current clients chip(assigned from controller_state) |
Virupax Sadashivpetimath | 8b8d719 | 2011-11-10 12:43:24 +0530 | [diff] [blame] | 344 | * @next_msg_cs_active: the next message in the queue has been examined |
| 345 | * and it was found that it uses the same chip select as the previous |
| 346 | * message, so we left it active after the previous transfer, and it's |
| 347 | * active already. |
Linus Walleij | b43d65f | 2009-06-09 08:11:42 +0100 | [diff] [blame] | 348 | * @tx: current position in TX buffer to be read |
| 349 | * @tx_end: end position in TX buffer to be read |
| 350 | * @rx: current position in RX buffer to be written |
| 351 | * @rx_end: end position in RX buffer to be written |
Linus Walleij | 12e8b32 | 2011-02-08 13:03:55 +0100 | [diff] [blame] | 352 | * @read: the type of read currently going on |
| 353 | * @write: the type of write currently going on |
| 354 | * @exp_fifo_level: expected FIFO level |
| 355 | * @dma_rx_channel: optional channel for RX DMA |
| 356 | * @dma_tx_channel: optional channel for TX DMA |
| 357 | * @sgt_rx: scattertable for the RX transfer |
| 358 | * @sgt_tx: scattertable for the TX transfer |
| 359 | * @dummypage: a dummy page used for driving data on the bus with DMA |
Roland Stigge | f6f46de | 2012-08-22 15:49:17 +0200 | [diff] [blame^] | 360 | * @cur_cs: current chip select (gpio) |
| 361 | * @chipselects: list of chipselects (gpios) |
Linus Walleij | b43d65f | 2009-06-09 08:11:42 +0100 | [diff] [blame] | 362 | */ |
| 363 | struct pl022 { |
| 364 | struct amba_device *adev; |
| 365 | struct vendor_data *vendor; |
| 366 | resource_size_t phybase; |
| 367 | void __iomem *virtbase; |
| 368 | struct clk *clk; |
| 369 | struct spi_master *master; |
| 370 | struct pl022_ssp_controller *master_info; |
Linus Walleij | ffbbdd2 | 2012-02-22 10:05:38 +0100 | [diff] [blame] | 371 | /* Message per-transfer pump */ |
Linus Walleij | b43d65f | 2009-06-09 08:11:42 +0100 | [diff] [blame] | 372 | struct tasklet_struct pump_transfers; |
| 373 | struct spi_message *cur_msg; |
| 374 | struct spi_transfer *cur_transfer; |
| 375 | struct chip_data *cur_chip; |
Virupax Sadashivpetimath | 8b8d719 | 2011-11-10 12:43:24 +0530 | [diff] [blame] | 376 | bool next_msg_cs_active; |
Linus Walleij | b43d65f | 2009-06-09 08:11:42 +0100 | [diff] [blame] | 377 | void *tx; |
| 378 | void *tx_end; |
| 379 | void *rx; |
| 380 | void *rx_end; |
| 381 | enum ssp_reading read; |
| 382 | enum ssp_writing write; |
Linus Walleij | fc05475 | 2010-01-22 13:53:30 +0100 | [diff] [blame] | 383 | u32 exp_fifo_level; |
Linus Walleij | 083be3f | 2011-06-16 10:14:28 +0200 | [diff] [blame] | 384 | enum ssp_rx_level_trig rx_lev_trig; |
| 385 | enum ssp_tx_level_trig tx_lev_trig; |
Linus Walleij | b1b6b9a | 2010-09-29 17:31:35 +0900 | [diff] [blame] | 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; |
Linus Walleij | ffbbdd2 | 2012-02-22 10:05:38 +0100 | [diff] [blame] | 393 | bool dma_running; |
Linus Walleij | b1b6b9a | 2010-09-29 17:31:35 +0900 | [diff] [blame] | 394 | #endif |
Roland Stigge | f6f46de | 2012-08-22 15:49:17 +0200 | [diff] [blame^] | 395 | int cur_cs; |
| 396 | int *chipselects; |
Linus Walleij | b43d65f | 2009-06-09 08:11:42 +0100 | [diff] [blame] | 397 | }; |
| 398 | |
| 399 | /** |
| 400 | * struct chip_data - To maintain runtime state of SSP for each client chip |
Linus Walleij | 556f4ae | 2010-05-05 09:28:15 +0000 | [diff] [blame] | 401 | * @cr0: Value of control register CR0 of SSP - on later ST variants this |
| 402 | * register is 32 bits wide rather than just 16 |
Linus Walleij | b43d65f | 2009-06-09 08:11:42 +0100 | [diff] [blame] | 403 | * @cr1: Value of control register CR1 of SSP |
| 404 | * @dmacr: Value of DMA control Register of SSP |
| 405 | * @cpsr: Value of Clock prescale register |
| 406 | * @n_bytes: how many bytes(power of 2) reqd for a given data width of client |
| 407 | * @enable_dma: Whether to enable DMA or not |
Linus Walleij | b43d65f | 2009-06-09 08:11:42 +0100 | [diff] [blame] | 408 | * @read: function ptr to be used to read when doing xfer for this chip |
Linus Walleij | 12e8b32 | 2011-02-08 13:03:55 +0100 | [diff] [blame] | 409 | * @write: function ptr to be used to write when doing xfer for this chip |
Linus Walleij | b43d65f | 2009-06-09 08:11:42 +0100 | [diff] [blame] | 410 | * @cs_control: chip select callback provided by chip |
| 411 | * @xfer_type: polling/interrupt/DMA |
| 412 | * |
| 413 | * Runtime state of the SSP controller, maintained per chip, |
| 414 | * This would be set according to the current message that would be served |
| 415 | */ |
| 416 | struct chip_data { |
Linus Walleij | 556f4ae | 2010-05-05 09:28:15 +0000 | [diff] [blame] | 417 | u32 cr0; |
Linus Walleij | b43d65f | 2009-06-09 08:11:42 +0100 | [diff] [blame] | 418 | u16 cr1; |
| 419 | u16 dmacr; |
| 420 | u16 cpsr; |
| 421 | u8 n_bytes; |
Linus Walleij | b1b6b9a | 2010-09-29 17:31:35 +0900 | [diff] [blame] | 422 | bool enable_dma; |
Linus Walleij | b43d65f | 2009-06-09 08:11:42 +0100 | [diff] [blame] | 423 | enum ssp_reading read; |
| 424 | enum ssp_writing write; |
| 425 | void (*cs_control) (u32 command); |
| 426 | int xfer_type; |
| 427 | }; |
| 428 | |
| 429 | /** |
| 430 | * null_cs_control - Dummy chip select function |
| 431 | * @command: select/delect the chip |
| 432 | * |
| 433 | * If no chip select function is provided by client this is used as dummy |
| 434 | * chip select |
| 435 | */ |
| 436 | static void null_cs_control(u32 command) |
| 437 | { |
| 438 | pr_debug("pl022: dummy chip select control, CS=0x%x\n", command); |
| 439 | } |
| 440 | |
Roland Stigge | f6f46de | 2012-08-22 15:49:17 +0200 | [diff] [blame^] | 441 | static void pl022_cs_control(struct pl022 *pl022, u32 command) |
| 442 | { |
| 443 | if (gpio_is_valid(pl022->cur_cs)) |
| 444 | gpio_set_value(pl022->cur_cs, command); |
| 445 | else |
| 446 | pl022->cur_chip->cs_control(command); |
| 447 | } |
| 448 | |
Linus Walleij | b43d65f | 2009-06-09 08:11:42 +0100 | [diff] [blame] | 449 | /** |
| 450 | * giveback - current spi_message is over, schedule next message and call |
| 451 | * callback of this message. Assumes that caller already |
| 452 | * set message->status; dma and pio irqs are blocked |
| 453 | * @pl022: SSP driver private data structure |
| 454 | */ |
| 455 | static void giveback(struct pl022 *pl022) |
| 456 | { |
| 457 | struct spi_transfer *last_transfer; |
Virupax Sadashivpetimath | 8b8d719 | 2011-11-10 12:43:24 +0530 | [diff] [blame] | 458 | pl022->next_msg_cs_active = false; |
Linus Walleij | b43d65f | 2009-06-09 08:11:42 +0100 | [diff] [blame] | 459 | |
Virupax Sadashivpetimath | 8b8d719 | 2011-11-10 12:43:24 +0530 | [diff] [blame] | 460 | last_transfer = list_entry(pl022->cur_msg->transfers.prev, |
Linus Walleij | b43d65f | 2009-06-09 08:11:42 +0100 | [diff] [blame] | 461 | struct spi_transfer, |
| 462 | transfer_list); |
| 463 | |
| 464 | /* Delay if requested before any change in chip select */ |
| 465 | if (last_transfer->delay_usecs) |
| 466 | /* |
| 467 | * FIXME: This runs in interrupt context. |
| 468 | * Is this really smart? |
| 469 | */ |
| 470 | udelay(last_transfer->delay_usecs); |
| 471 | |
Virupax Sadashivpetimath | 8b8d719 | 2011-11-10 12:43:24 +0530 | [diff] [blame] | 472 | if (!last_transfer->cs_change) { |
Linus Walleij | b43d65f | 2009-06-09 08:11:42 +0100 | [diff] [blame] | 473 | struct spi_message *next_msg; |
| 474 | |
Virupax Sadashivpetimath | 8b8d719 | 2011-11-10 12:43:24 +0530 | [diff] [blame] | 475 | /* |
| 476 | * cs_change was not set. We can keep the chip select |
| 477 | * enabled if there is message in the queue and it is |
| 478 | * for the same spi device. |
Linus Walleij | b43d65f | 2009-06-09 08:11:42 +0100 | [diff] [blame] | 479 | * |
| 480 | * We cannot postpone this until pump_messages, because |
| 481 | * after calling msg->complete (below) the driver that |
| 482 | * sent the current message could be unloaded, which |
| 483 | * could invalidate the cs_control() callback... |
| 484 | */ |
Linus Walleij | b43d65f | 2009-06-09 08:11:42 +0100 | [diff] [blame] | 485 | /* get a pointer to the next message, if any */ |
Linus Walleij | ffbbdd2 | 2012-02-22 10:05:38 +0100 | [diff] [blame] | 486 | next_msg = spi_get_next_queued_message(pl022->master); |
Linus Walleij | b43d65f | 2009-06-09 08:11:42 +0100 | [diff] [blame] | 487 | |
Virupax Sadashivpetimath | 8b8d719 | 2011-11-10 12:43:24 +0530 | [diff] [blame] | 488 | /* |
| 489 | * see if the next and current messages point |
| 490 | * to the same spi device. |
Linus Walleij | b43d65f | 2009-06-09 08:11:42 +0100 | [diff] [blame] | 491 | */ |
Virupax Sadashivpetimath | 8b8d719 | 2011-11-10 12:43:24 +0530 | [diff] [blame] | 492 | if (next_msg && next_msg->spi != pl022->cur_msg->spi) |
Linus Walleij | b43d65f | 2009-06-09 08:11:42 +0100 | [diff] [blame] | 493 | next_msg = NULL; |
Virupax Sadashivpetimath | 8b8d719 | 2011-11-10 12:43:24 +0530 | [diff] [blame] | 494 | if (!next_msg || pl022->cur_msg->state == STATE_ERROR) |
Roland Stigge | f6f46de | 2012-08-22 15:49:17 +0200 | [diff] [blame^] | 495 | pl022_cs_control(pl022, SSP_CHIP_DESELECT); |
Virupax Sadashivpetimath | 8b8d719 | 2011-11-10 12:43:24 +0530 | [diff] [blame] | 496 | else |
| 497 | pl022->next_msg_cs_active = true; |
Linus Walleij | ffbbdd2 | 2012-02-22 10:05:38 +0100 | [diff] [blame] | 498 | |
Linus Walleij | b43d65f | 2009-06-09 08:11:42 +0100 | [diff] [blame] | 499 | } |
Virupax Sadashivpetimath | 8b8d719 | 2011-11-10 12:43:24 +0530 | [diff] [blame] | 500 | |
Virupax Sadashivpetimath | 8b8d719 | 2011-11-10 12:43:24 +0530 | [diff] [blame] | 501 | pl022->cur_msg = NULL; |
| 502 | pl022->cur_transfer = NULL; |
| 503 | pl022->cur_chip = NULL; |
Linus Walleij | ffbbdd2 | 2012-02-22 10:05:38 +0100 | [diff] [blame] | 504 | spi_finalize_current_message(pl022->master); |
Virupax Sadashivpetimath | fd31694 | 2012-06-12 15:10:58 +0200 | [diff] [blame] | 505 | |
| 506 | /* disable the SPI/SSP operation */ |
| 507 | writew((readw(SSP_CR1(pl022->virtbase)) & |
| 508 | (~SSP_CR1_MASK_SSE)), SSP_CR1(pl022->virtbase)); |
| 509 | |
Linus Walleij | b43d65f | 2009-06-09 08:11:42 +0100 | [diff] [blame] | 510 | } |
| 511 | |
| 512 | /** |
| 513 | * flush - flush the FIFO to reach a clean state |
| 514 | * @pl022: SSP driver private data structure |
| 515 | */ |
| 516 | static int flush(struct pl022 *pl022) |
| 517 | { |
| 518 | unsigned long limit = loops_per_jiffy << 1; |
| 519 | |
| 520 | dev_dbg(&pl022->adev->dev, "flush\n"); |
| 521 | do { |
| 522 | while (readw(SSP_SR(pl022->virtbase)) & SSP_SR_MASK_RNE) |
| 523 | readw(SSP_DR(pl022->virtbase)); |
| 524 | } while ((readw(SSP_SR(pl022->virtbase)) & SSP_SR_MASK_BSY) && limit--); |
Linus Walleij | fc05475 | 2010-01-22 13:53:30 +0100 | [diff] [blame] | 525 | |
| 526 | pl022->exp_fifo_level = 0; |
| 527 | |
Linus Walleij | b43d65f | 2009-06-09 08:11:42 +0100 | [diff] [blame] | 528 | return limit; |
| 529 | } |
| 530 | |
| 531 | /** |
| 532 | * restore_state - Load configuration of current chip |
| 533 | * @pl022: SSP driver private data structure |
| 534 | */ |
| 535 | static void restore_state(struct pl022 *pl022) |
| 536 | { |
| 537 | struct chip_data *chip = pl022->cur_chip; |
| 538 | |
Linus Walleij | 556f4ae | 2010-05-05 09:28:15 +0000 | [diff] [blame] | 539 | if (pl022->vendor->extended_cr) |
| 540 | writel(chip->cr0, SSP_CR0(pl022->virtbase)); |
| 541 | else |
| 542 | writew(chip->cr0, SSP_CR0(pl022->virtbase)); |
Linus Walleij | b43d65f | 2009-06-09 08:11:42 +0100 | [diff] [blame] | 543 | writew(chip->cr1, SSP_CR1(pl022->virtbase)); |
| 544 | writew(chip->dmacr, SSP_DMACR(pl022->virtbase)); |
| 545 | writew(chip->cpsr, SSP_CPSR(pl022->virtbase)); |
| 546 | writew(DISABLE_ALL_INTERRUPTS, SSP_IMSC(pl022->virtbase)); |
| 547 | writew(CLEAR_ALL_INTERRUPTS, SSP_ICR(pl022->virtbase)); |
| 548 | } |
| 549 | |
Linus Walleij | b43d65f | 2009-06-09 08:11:42 +0100 | [diff] [blame] | 550 | /* |
| 551 | * Default SSP Register Values |
| 552 | */ |
| 553 | #define DEFAULT_SSP_REG_CR0 ( \ |
| 554 | GEN_MASK_BITS(SSP_DATA_BITS_12, SSP_CR0_MASK_DSS, 0) | \ |
Linus Walleij | 556f4ae | 2010-05-05 09:28:15 +0000 | [diff] [blame] | 555 | GEN_MASK_BITS(SSP_INTERFACE_MOTOROLA_SPI, SSP_CR0_MASK_FRF, 4) | \ |
Linus Walleij | b43d65f | 2009-06-09 08:11:42 +0100 | [diff] [blame] | 556 | GEN_MASK_BITS(SSP_CLK_POL_IDLE_LOW, SSP_CR0_MASK_SPO, 6) | \ |
Linus Walleij | ee2b805 | 2009-08-15 15:12:05 +0100 | [diff] [blame] | 557 | GEN_MASK_BITS(SSP_CLK_SECOND_EDGE, SSP_CR0_MASK_SPH, 7) | \ |
Linus Walleij | 556f4ae | 2010-05-05 09:28:15 +0000 | [diff] [blame] | 558 | GEN_MASK_BITS(SSP_DEFAULT_CLKRATE, SSP_CR0_MASK_SCR, 8) \ |
| 559 | ) |
| 560 | |
| 561 | /* ST versions have slightly different bit layout */ |
| 562 | #define DEFAULT_SSP_REG_CR0_ST ( \ |
| 563 | GEN_MASK_BITS(SSP_DATA_BITS_12, SSP_CR0_MASK_DSS_ST, 0) | \ |
| 564 | GEN_MASK_BITS(SSP_MICROWIRE_CHANNEL_FULL_DUPLEX, SSP_CR0_MASK_HALFDUP_ST, 5) | \ |
| 565 | GEN_MASK_BITS(SSP_CLK_POL_IDLE_LOW, SSP_CR0_MASK_SPO, 6) | \ |
| 566 | GEN_MASK_BITS(SSP_CLK_SECOND_EDGE, SSP_CR0_MASK_SPH, 7) | \ |
| 567 | GEN_MASK_BITS(SSP_DEFAULT_CLKRATE, SSP_CR0_MASK_SCR, 8) | \ |
| 568 | GEN_MASK_BITS(SSP_BITS_8, SSP_CR0_MASK_CSS_ST, 16) | \ |
| 569 | GEN_MASK_BITS(SSP_INTERFACE_MOTOROLA_SPI, SSP_CR0_MASK_FRF_ST, 21) \ |
Linus Walleij | b43d65f | 2009-06-09 08:11:42 +0100 | [diff] [blame] | 570 | ) |
| 571 | |
Linus Walleij | 781c7b1 | 2010-05-07 08:40:53 +0000 | [diff] [blame] | 572 | /* The PL023 version is slightly different again */ |
| 573 | #define DEFAULT_SSP_REG_CR0_ST_PL023 ( \ |
| 574 | GEN_MASK_BITS(SSP_DATA_BITS_12, SSP_CR0_MASK_DSS_ST, 0) | \ |
| 575 | GEN_MASK_BITS(SSP_CLK_POL_IDLE_LOW, SSP_CR0_MASK_SPO, 6) | \ |
| 576 | GEN_MASK_BITS(SSP_CLK_SECOND_EDGE, SSP_CR0_MASK_SPH, 7) | \ |
| 577 | GEN_MASK_BITS(SSP_DEFAULT_CLKRATE, SSP_CR0_MASK_SCR, 8) \ |
| 578 | ) |
| 579 | |
Linus Walleij | b43d65f | 2009-06-09 08:11:42 +0100 | [diff] [blame] | 580 | #define DEFAULT_SSP_REG_CR1 ( \ |
| 581 | GEN_MASK_BITS(LOOPBACK_DISABLED, SSP_CR1_MASK_LBM, 0) | \ |
| 582 | GEN_MASK_BITS(SSP_DISABLED, SSP_CR1_MASK_SSE, 1) | \ |
| 583 | GEN_MASK_BITS(SSP_MASTER, SSP_CR1_MASK_MS, 2) | \ |
Linus Walleij | 556f4ae | 2010-05-05 09:28:15 +0000 | [diff] [blame] | 584 | GEN_MASK_BITS(DO_NOT_DRIVE_TX, SSP_CR1_MASK_SOD, 3) \ |
Linus Walleij | b43d65f | 2009-06-09 08:11:42 +0100 | [diff] [blame] | 585 | ) |
| 586 | |
Linus Walleij | 556f4ae | 2010-05-05 09:28:15 +0000 | [diff] [blame] | 587 | /* ST versions extend this register to use all 16 bits */ |
| 588 | #define DEFAULT_SSP_REG_CR1_ST ( \ |
| 589 | DEFAULT_SSP_REG_CR1 | \ |
| 590 | GEN_MASK_BITS(SSP_RX_MSB, SSP_CR1_MASK_RENDN_ST, 4) | \ |
| 591 | GEN_MASK_BITS(SSP_TX_MSB, SSP_CR1_MASK_TENDN_ST, 5) | \ |
| 592 | GEN_MASK_BITS(SSP_MWIRE_WAIT_ZERO, SSP_CR1_MASK_MWAIT_ST, 6) |\ |
| 593 | GEN_MASK_BITS(SSP_RX_1_OR_MORE_ELEM, SSP_CR1_MASK_RXIFLSEL_ST, 7) | \ |
| 594 | GEN_MASK_BITS(SSP_TX_1_OR_MORE_EMPTY_LOC, SSP_CR1_MASK_TXIFLSEL_ST, 10) \ |
| 595 | ) |
| 596 | |
Linus Walleij | 781c7b1 | 2010-05-07 08:40:53 +0000 | [diff] [blame] | 597 | /* |
| 598 | * The PL023 variant has further differences: no loopback mode, no microwire |
| 599 | * support, and a new clock feedback delay setting. |
| 600 | */ |
| 601 | #define DEFAULT_SSP_REG_CR1_ST_PL023 ( \ |
| 602 | GEN_MASK_BITS(SSP_DISABLED, SSP_CR1_MASK_SSE, 1) | \ |
| 603 | GEN_MASK_BITS(SSP_MASTER, SSP_CR1_MASK_MS, 2) | \ |
| 604 | GEN_MASK_BITS(DO_NOT_DRIVE_TX, SSP_CR1_MASK_SOD, 3) | \ |
| 605 | GEN_MASK_BITS(SSP_RX_MSB, SSP_CR1_MASK_RENDN_ST, 4) | \ |
| 606 | GEN_MASK_BITS(SSP_TX_MSB, SSP_CR1_MASK_TENDN_ST, 5) | \ |
| 607 | GEN_MASK_BITS(SSP_RX_1_OR_MORE_ELEM, SSP_CR1_MASK_RXIFLSEL_ST, 7) | \ |
| 608 | GEN_MASK_BITS(SSP_TX_1_OR_MORE_EMPTY_LOC, SSP_CR1_MASK_TXIFLSEL_ST, 10) | \ |
| 609 | GEN_MASK_BITS(SSP_FEEDBACK_CLK_DELAY_NONE, SSP_CR1_MASK_FBCLKDEL_ST, 13) \ |
| 610 | ) |
Linus Walleij | 556f4ae | 2010-05-05 09:28:15 +0000 | [diff] [blame] | 611 | |
Linus Walleij | b43d65f | 2009-06-09 08:11:42 +0100 | [diff] [blame] | 612 | #define DEFAULT_SSP_REG_CPSR ( \ |
Linus Walleij | 556f4ae | 2010-05-05 09:28:15 +0000 | [diff] [blame] | 613 | GEN_MASK_BITS(SSP_DEFAULT_PRESCALE, SSP_CPSR_MASK_CPSDVSR, 0) \ |
Linus Walleij | b43d65f | 2009-06-09 08:11:42 +0100 | [diff] [blame] | 614 | ) |
| 615 | |
| 616 | #define DEFAULT_SSP_REG_DMACR (\ |
| 617 | GEN_MASK_BITS(SSP_DMA_DISABLED, SSP_DMACR_MASK_RXDMAE, 0) | \ |
| 618 | GEN_MASK_BITS(SSP_DMA_DISABLED, SSP_DMACR_MASK_TXDMAE, 1) \ |
| 619 | ) |
| 620 | |
Linus Walleij | 781c7b1 | 2010-05-07 08:40:53 +0000 | [diff] [blame] | 621 | /** |
| 622 | * load_ssp_default_config - Load default configuration for SSP |
| 623 | * @pl022: SSP driver private data structure |
| 624 | */ |
Linus Walleij | b43d65f | 2009-06-09 08:11:42 +0100 | [diff] [blame] | 625 | static void load_ssp_default_config(struct pl022 *pl022) |
| 626 | { |
Linus Walleij | 781c7b1 | 2010-05-07 08:40:53 +0000 | [diff] [blame] | 627 | if (pl022->vendor->pl023) { |
| 628 | writel(DEFAULT_SSP_REG_CR0_ST_PL023, SSP_CR0(pl022->virtbase)); |
| 629 | writew(DEFAULT_SSP_REG_CR1_ST_PL023, SSP_CR1(pl022->virtbase)); |
| 630 | } else if (pl022->vendor->extended_cr) { |
Linus Walleij | 556f4ae | 2010-05-05 09:28:15 +0000 | [diff] [blame] | 631 | writel(DEFAULT_SSP_REG_CR0_ST, SSP_CR0(pl022->virtbase)); |
| 632 | writew(DEFAULT_SSP_REG_CR1_ST, SSP_CR1(pl022->virtbase)); |
| 633 | } else { |
| 634 | writew(DEFAULT_SSP_REG_CR0, SSP_CR0(pl022->virtbase)); |
| 635 | writew(DEFAULT_SSP_REG_CR1, SSP_CR1(pl022->virtbase)); |
| 636 | } |
Linus Walleij | b43d65f | 2009-06-09 08:11:42 +0100 | [diff] [blame] | 637 | writew(DEFAULT_SSP_REG_DMACR, SSP_DMACR(pl022->virtbase)); |
| 638 | writew(DEFAULT_SSP_REG_CPSR, SSP_CPSR(pl022->virtbase)); |
| 639 | writew(DISABLE_ALL_INTERRUPTS, SSP_IMSC(pl022->virtbase)); |
| 640 | writew(CLEAR_ALL_INTERRUPTS, SSP_ICR(pl022->virtbase)); |
| 641 | } |
| 642 | |
| 643 | /** |
| 644 | * This will write to TX and read from RX according to the parameters |
| 645 | * set in pl022. |
| 646 | */ |
| 647 | static void readwriter(struct pl022 *pl022) |
| 648 | { |
| 649 | |
| 650 | /* |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 651 | * The FIFO depth is different between primecell variants. |
Linus Walleij | b43d65f | 2009-06-09 08:11:42 +0100 | [diff] [blame] | 652 | * I believe filling in too much in the FIFO might cause |
| 653 | * errons in 8bit wide transfers on ARM variants (just 8 words |
| 654 | * FIFO, means only 8x8 = 64 bits in FIFO) at least. |
| 655 | * |
Linus Walleij | fc05475 | 2010-01-22 13:53:30 +0100 | [diff] [blame] | 656 | * To prevent this issue, the TX FIFO is only filled to the |
| 657 | * unused RX FIFO fill length, regardless of what the TX |
| 658 | * FIFO status flag indicates. |
Linus Walleij | b43d65f | 2009-06-09 08:11:42 +0100 | [diff] [blame] | 659 | */ |
| 660 | dev_dbg(&pl022->adev->dev, |
| 661 | "%s, rx: %p, rxend: %p, tx: %p, txend: %p\n", |
| 662 | __func__, pl022->rx, pl022->rx_end, pl022->tx, pl022->tx_end); |
| 663 | |
| 664 | /* Read as much as you can */ |
| 665 | while ((readw(SSP_SR(pl022->virtbase)) & SSP_SR_MASK_RNE) |
| 666 | && (pl022->rx < pl022->rx_end)) { |
| 667 | switch (pl022->read) { |
| 668 | case READING_NULL: |
| 669 | readw(SSP_DR(pl022->virtbase)); |
| 670 | break; |
| 671 | case READING_U8: |
| 672 | *(u8 *) (pl022->rx) = |
| 673 | readw(SSP_DR(pl022->virtbase)) & 0xFFU; |
| 674 | break; |
| 675 | case READING_U16: |
| 676 | *(u16 *) (pl022->rx) = |
| 677 | (u16) readw(SSP_DR(pl022->virtbase)); |
| 678 | break; |
| 679 | case READING_U32: |
| 680 | *(u32 *) (pl022->rx) = |
| 681 | readl(SSP_DR(pl022->virtbase)); |
| 682 | break; |
| 683 | } |
| 684 | pl022->rx += (pl022->cur_chip->n_bytes); |
Linus Walleij | fc05475 | 2010-01-22 13:53:30 +0100 | [diff] [blame] | 685 | pl022->exp_fifo_level--; |
Linus Walleij | b43d65f | 2009-06-09 08:11:42 +0100 | [diff] [blame] | 686 | } |
| 687 | /* |
Linus Walleij | fc05475 | 2010-01-22 13:53:30 +0100 | [diff] [blame] | 688 | * Write as much as possible up to the RX FIFO size |
Linus Walleij | b43d65f | 2009-06-09 08:11:42 +0100 | [diff] [blame] | 689 | */ |
Linus Walleij | fc05475 | 2010-01-22 13:53:30 +0100 | [diff] [blame] | 690 | while ((pl022->exp_fifo_level < pl022->vendor->fifodepth) |
Linus Walleij | b43d65f | 2009-06-09 08:11:42 +0100 | [diff] [blame] | 691 | && (pl022->tx < pl022->tx_end)) { |
| 692 | switch (pl022->write) { |
| 693 | case WRITING_NULL: |
| 694 | writew(0x0, SSP_DR(pl022->virtbase)); |
| 695 | break; |
| 696 | case WRITING_U8: |
| 697 | writew(*(u8 *) (pl022->tx), SSP_DR(pl022->virtbase)); |
| 698 | break; |
| 699 | case WRITING_U16: |
| 700 | writew((*(u16 *) (pl022->tx)), SSP_DR(pl022->virtbase)); |
| 701 | break; |
| 702 | case WRITING_U32: |
| 703 | writel(*(u32 *) (pl022->tx), SSP_DR(pl022->virtbase)); |
| 704 | break; |
| 705 | } |
| 706 | pl022->tx += (pl022->cur_chip->n_bytes); |
Linus Walleij | fc05475 | 2010-01-22 13:53:30 +0100 | [diff] [blame] | 707 | pl022->exp_fifo_level++; |
Linus Walleij | b43d65f | 2009-06-09 08:11:42 +0100 | [diff] [blame] | 708 | /* |
| 709 | * This inner reader takes care of things appearing in the RX |
| 710 | * FIFO as we're transmitting. This will happen a lot since the |
| 711 | * clock starts running when you put things into the TX FIFO, |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 712 | * and then things are continuously clocked into the RX FIFO. |
Linus Walleij | b43d65f | 2009-06-09 08:11:42 +0100 | [diff] [blame] | 713 | */ |
| 714 | while ((readw(SSP_SR(pl022->virtbase)) & SSP_SR_MASK_RNE) |
| 715 | && (pl022->rx < pl022->rx_end)) { |
| 716 | switch (pl022->read) { |
| 717 | case READING_NULL: |
| 718 | readw(SSP_DR(pl022->virtbase)); |
| 719 | break; |
| 720 | case READING_U8: |
| 721 | *(u8 *) (pl022->rx) = |
| 722 | readw(SSP_DR(pl022->virtbase)) & 0xFFU; |
| 723 | break; |
| 724 | case READING_U16: |
| 725 | *(u16 *) (pl022->rx) = |
| 726 | (u16) readw(SSP_DR(pl022->virtbase)); |
| 727 | break; |
| 728 | case READING_U32: |
| 729 | *(u32 *) (pl022->rx) = |
| 730 | readl(SSP_DR(pl022->virtbase)); |
| 731 | break; |
| 732 | } |
| 733 | pl022->rx += (pl022->cur_chip->n_bytes); |
Linus Walleij | fc05475 | 2010-01-22 13:53:30 +0100 | [diff] [blame] | 734 | pl022->exp_fifo_level--; |
Linus Walleij | b43d65f | 2009-06-09 08:11:42 +0100 | [diff] [blame] | 735 | } |
| 736 | } |
| 737 | /* |
| 738 | * When we exit here the TX FIFO should be full and the RX FIFO |
| 739 | * should be empty |
| 740 | */ |
| 741 | } |
| 742 | |
Linus Walleij | b43d65f | 2009-06-09 08:11:42 +0100 | [diff] [blame] | 743 | /** |
| 744 | * next_transfer - Move to the Next transfer in the current spi message |
| 745 | * @pl022: SSP driver private data structure |
| 746 | * |
| 747 | * This function moves though the linked list of spi transfers in the |
| 748 | * current spi message and returns with the state of current spi |
| 749 | * message i.e whether its last transfer is done(STATE_DONE) or |
| 750 | * Next transfer is ready(STATE_RUNNING) |
| 751 | */ |
| 752 | static void *next_transfer(struct pl022 *pl022) |
| 753 | { |
| 754 | struct spi_message *msg = pl022->cur_msg; |
| 755 | struct spi_transfer *trans = pl022->cur_transfer; |
| 756 | |
| 757 | /* Move to next transfer */ |
| 758 | if (trans->transfer_list.next != &msg->transfers) { |
| 759 | pl022->cur_transfer = |
| 760 | list_entry(trans->transfer_list.next, |
| 761 | struct spi_transfer, transfer_list); |
| 762 | return STATE_RUNNING; |
| 763 | } |
| 764 | return STATE_DONE; |
| 765 | } |
Linus Walleij | b1b6b9a | 2010-09-29 17:31:35 +0900 | [diff] [blame] | 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 */ |
Linus Walleij | b729889 | 2010-12-22 23:13:07 +0100 | [diff] [blame] | 775 | dma_unmap_sg(pl022->dma_tx_channel->device->dev, pl022->sgt_tx.sgl, |
Linus Walleij | b1b6b9a | 2010-09-29 17:31:35 +0900 | [diff] [blame] | 776 | pl022->sgt_tx.nents, DMA_TO_DEVICE); |
Linus Walleij | b729889 | 2010-12-22 23:13:07 +0100 | [diff] [blame] | 777 | dma_unmap_sg(pl022->dma_rx_channel->device->dev, pl022->sgt_rx.sgl, |
Linus Walleij | b1b6b9a | 2010-09-29 17:31:35 +0900 | [diff] [blame] | 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 | |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 831 | /* Update total bytes transferred */ |
Linus Walleij | b1b6b9a | 2010-09-29 17:31:35 +0900 | [diff] [blame] | 832 | msg->actual_length += pl022->cur_transfer->len; |
| 833 | if (pl022->cur_transfer->cs_change) |
Roland Stigge | f6f46de | 2012-08-22 15:49:17 +0200 | [diff] [blame^] | 834 | pl022_cs_control(pl022, SSP_CHIP_DESELECT); |
Linus Walleij | b1b6b9a | 2010-09-29 17:31:35 +0900 | [diff] [blame] | 835 | |
| 836 | /* Move to next transfer */ |
| 837 | msg->state = next_transfer(pl022); |
| 838 | tasklet_schedule(&pl022->pump_transfers); |
| 839 | } |
| 840 | |
| 841 | static void setup_dma_scatter(struct pl022 *pl022, |
| 842 | void *buffer, |
| 843 | unsigned int length, |
| 844 | struct sg_table *sgtab) |
| 845 | { |
| 846 | struct scatterlist *sg; |
| 847 | int bytesleft = length; |
| 848 | void *bufp = buffer; |
| 849 | int mapbytes; |
| 850 | int i; |
| 851 | |
| 852 | if (buffer) { |
| 853 | for_each_sg(sgtab->sgl, sg, sgtab->nents, i) { |
| 854 | /* |
| 855 | * If there are less bytes left than what fits |
| 856 | * in the current page (plus page alignment offset) |
| 857 | * we just feed in this, else we stuff in as much |
| 858 | * as we can. |
| 859 | */ |
| 860 | if (bytesleft < (PAGE_SIZE - offset_in_page(bufp))) |
| 861 | mapbytes = bytesleft; |
| 862 | else |
| 863 | mapbytes = PAGE_SIZE - offset_in_page(bufp); |
| 864 | sg_set_page(sg, virt_to_page(bufp), |
| 865 | mapbytes, offset_in_page(bufp)); |
| 866 | bufp += mapbytes; |
| 867 | bytesleft -= mapbytes; |
| 868 | dev_dbg(&pl022->adev->dev, |
| 869 | "set RX/TX target page @ %p, %d bytes, %d left\n", |
| 870 | bufp, mapbytes, bytesleft); |
| 871 | } |
| 872 | } else { |
| 873 | /* Map the dummy buffer on every page */ |
| 874 | for_each_sg(sgtab->sgl, sg, sgtab->nents, i) { |
| 875 | if (bytesleft < PAGE_SIZE) |
| 876 | mapbytes = bytesleft; |
| 877 | else |
| 878 | mapbytes = PAGE_SIZE; |
| 879 | sg_set_page(sg, virt_to_page(pl022->dummypage), |
| 880 | mapbytes, 0); |
| 881 | bytesleft -= mapbytes; |
| 882 | dev_dbg(&pl022->adev->dev, |
| 883 | "set RX/TX to dummy page %d bytes, %d left\n", |
| 884 | mapbytes, bytesleft); |
| 885 | |
| 886 | } |
| 887 | } |
| 888 | BUG_ON(bytesleft); |
| 889 | } |
| 890 | |
| 891 | /** |
| 892 | * configure_dma - configures the channels for the next transfer |
| 893 | * @pl022: SSP driver's private data structure |
| 894 | */ |
| 895 | static int configure_dma(struct pl022 *pl022) |
| 896 | { |
| 897 | struct dma_slave_config rx_conf = { |
| 898 | .src_addr = SSP_DR(pl022->phybase), |
Vinod Koul | a485df4 | 2011-10-14 10:47:38 +0530 | [diff] [blame] | 899 | .direction = DMA_DEV_TO_MEM, |
Viresh Kumar | 258aea7 | 2012-02-01 16:12:19 +0530 | [diff] [blame] | 900 | .device_fc = false, |
Linus Walleij | b1b6b9a | 2010-09-29 17:31:35 +0900 | [diff] [blame] | 901 | }; |
| 902 | struct dma_slave_config tx_conf = { |
| 903 | .dst_addr = SSP_DR(pl022->phybase), |
Vinod Koul | a485df4 | 2011-10-14 10:47:38 +0530 | [diff] [blame] | 904 | .direction = DMA_MEM_TO_DEV, |
Viresh Kumar | 258aea7 | 2012-02-01 16:12:19 +0530 | [diff] [blame] | 905 | .device_fc = false, |
Linus Walleij | b1b6b9a | 2010-09-29 17:31:35 +0900 | [diff] [blame] | 906 | }; |
| 907 | unsigned int pages; |
| 908 | int ret; |
Linus Walleij | 082086f | 2010-12-22 23:13:37 +0100 | [diff] [blame] | 909 | int rx_sglen, tx_sglen; |
Linus Walleij | b1b6b9a | 2010-09-29 17:31:35 +0900 | [diff] [blame] | 910 | struct dma_chan *rxchan = pl022->dma_rx_channel; |
| 911 | struct dma_chan *txchan = pl022->dma_tx_channel; |
| 912 | struct dma_async_tx_descriptor *rxdesc; |
| 913 | struct dma_async_tx_descriptor *txdesc; |
Linus Walleij | b1b6b9a | 2010-09-29 17:31:35 +0900 | [diff] [blame] | 914 | |
| 915 | /* Check that the channels are available */ |
| 916 | if (!rxchan || !txchan) |
| 917 | return -ENODEV; |
| 918 | |
Linus Walleij | 083be3f | 2011-06-16 10:14:28 +0200 | [diff] [blame] | 919 | /* |
| 920 | * If supplied, the DMA burstsize should equal the FIFO trigger level. |
| 921 | * Notice that the DMA engine uses one-to-one mapping. Since we can |
| 922 | * not trigger on 2 elements this needs explicit mapping rather than |
| 923 | * calculation. |
| 924 | */ |
| 925 | switch (pl022->rx_lev_trig) { |
| 926 | case SSP_RX_1_OR_MORE_ELEM: |
| 927 | rx_conf.src_maxburst = 1; |
| 928 | break; |
| 929 | case SSP_RX_4_OR_MORE_ELEM: |
| 930 | rx_conf.src_maxburst = 4; |
| 931 | break; |
| 932 | case SSP_RX_8_OR_MORE_ELEM: |
| 933 | rx_conf.src_maxburst = 8; |
| 934 | break; |
| 935 | case SSP_RX_16_OR_MORE_ELEM: |
| 936 | rx_conf.src_maxburst = 16; |
| 937 | break; |
| 938 | case SSP_RX_32_OR_MORE_ELEM: |
| 939 | rx_conf.src_maxburst = 32; |
| 940 | break; |
| 941 | default: |
| 942 | rx_conf.src_maxburst = pl022->vendor->fifodepth >> 1; |
| 943 | break; |
| 944 | } |
| 945 | |
| 946 | switch (pl022->tx_lev_trig) { |
| 947 | case SSP_TX_1_OR_MORE_EMPTY_LOC: |
| 948 | tx_conf.dst_maxburst = 1; |
| 949 | break; |
| 950 | case SSP_TX_4_OR_MORE_EMPTY_LOC: |
| 951 | tx_conf.dst_maxburst = 4; |
| 952 | break; |
| 953 | case SSP_TX_8_OR_MORE_EMPTY_LOC: |
| 954 | tx_conf.dst_maxburst = 8; |
| 955 | break; |
| 956 | case SSP_TX_16_OR_MORE_EMPTY_LOC: |
| 957 | tx_conf.dst_maxburst = 16; |
| 958 | break; |
| 959 | case SSP_TX_32_OR_MORE_EMPTY_LOC: |
| 960 | tx_conf.dst_maxburst = 32; |
| 961 | break; |
| 962 | default: |
| 963 | tx_conf.dst_maxburst = pl022->vendor->fifodepth >> 1; |
| 964 | break; |
| 965 | } |
| 966 | |
Linus Walleij | b1b6b9a | 2010-09-29 17:31:35 +0900 | [diff] [blame] | 967 | switch (pl022->read) { |
| 968 | case READING_NULL: |
| 969 | /* Use the same as for writing */ |
| 970 | rx_conf.src_addr_width = DMA_SLAVE_BUSWIDTH_UNDEFINED; |
| 971 | break; |
| 972 | case READING_U8: |
| 973 | rx_conf.src_addr_width = DMA_SLAVE_BUSWIDTH_1_BYTE; |
| 974 | break; |
| 975 | case READING_U16: |
| 976 | rx_conf.src_addr_width = DMA_SLAVE_BUSWIDTH_2_BYTES; |
| 977 | break; |
| 978 | case READING_U32: |
| 979 | rx_conf.src_addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES; |
| 980 | break; |
| 981 | } |
| 982 | |
| 983 | switch (pl022->write) { |
| 984 | case WRITING_NULL: |
| 985 | /* Use the same as for reading */ |
| 986 | tx_conf.dst_addr_width = DMA_SLAVE_BUSWIDTH_UNDEFINED; |
| 987 | break; |
| 988 | case WRITING_U8: |
| 989 | tx_conf.dst_addr_width = DMA_SLAVE_BUSWIDTH_1_BYTE; |
| 990 | break; |
| 991 | case WRITING_U16: |
| 992 | tx_conf.dst_addr_width = DMA_SLAVE_BUSWIDTH_2_BYTES; |
| 993 | break; |
| 994 | case WRITING_U32: |
Joe Perches | bc3f67a | 2010-11-14 19:04:47 -0800 | [diff] [blame] | 995 | tx_conf.dst_addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES; |
Linus Walleij | b1b6b9a | 2010-09-29 17:31:35 +0900 | [diff] [blame] | 996 | break; |
| 997 | } |
| 998 | |
| 999 | /* SPI pecularity: we need to read and write the same width */ |
| 1000 | if (rx_conf.src_addr_width == DMA_SLAVE_BUSWIDTH_UNDEFINED) |
| 1001 | rx_conf.src_addr_width = tx_conf.dst_addr_width; |
| 1002 | if (tx_conf.dst_addr_width == DMA_SLAVE_BUSWIDTH_UNDEFINED) |
| 1003 | tx_conf.dst_addr_width = rx_conf.src_addr_width; |
| 1004 | BUG_ON(rx_conf.src_addr_width != tx_conf.dst_addr_width); |
| 1005 | |
Linus Walleij | ecd442f | 2011-02-08 13:03:12 +0100 | [diff] [blame] | 1006 | dmaengine_slave_config(rxchan, &rx_conf); |
| 1007 | dmaengine_slave_config(txchan, &tx_conf); |
Linus Walleij | b1b6b9a | 2010-09-29 17:31:35 +0900 | [diff] [blame] | 1008 | |
| 1009 | /* Create sglists for the transfers */ |
Viresh Kumar | b181565 | 2011-08-10 17:12:11 +0530 | [diff] [blame] | 1010 | pages = DIV_ROUND_UP(pl022->cur_transfer->len, PAGE_SIZE); |
Linus Walleij | b1b6b9a | 2010-09-29 17:31:35 +0900 | [diff] [blame] | 1011 | dev_dbg(&pl022->adev->dev, "using %d pages for transfer\n", pages); |
| 1012 | |
Viresh Kumar | 538a18d | 2011-08-10 14:20:55 +0530 | [diff] [blame] | 1013 | ret = sg_alloc_table(&pl022->sgt_rx, pages, GFP_ATOMIC); |
Linus Walleij | b1b6b9a | 2010-09-29 17:31:35 +0900 | [diff] [blame] | 1014 | if (ret) |
| 1015 | goto err_alloc_rx_sg; |
| 1016 | |
Viresh Kumar | 538a18d | 2011-08-10 14:20:55 +0530 | [diff] [blame] | 1017 | ret = sg_alloc_table(&pl022->sgt_tx, pages, GFP_ATOMIC); |
Linus Walleij | b1b6b9a | 2010-09-29 17:31:35 +0900 | [diff] [blame] | 1018 | if (ret) |
| 1019 | goto err_alloc_tx_sg; |
| 1020 | |
| 1021 | /* Fill in the scatterlists for the RX+TX buffers */ |
| 1022 | setup_dma_scatter(pl022, pl022->rx, |
| 1023 | pl022->cur_transfer->len, &pl022->sgt_rx); |
| 1024 | setup_dma_scatter(pl022, pl022->tx, |
| 1025 | pl022->cur_transfer->len, &pl022->sgt_tx); |
| 1026 | |
| 1027 | /* Map DMA buffers */ |
Linus Walleij | 082086f | 2010-12-22 23:13:37 +0100 | [diff] [blame] | 1028 | rx_sglen = dma_map_sg(rxchan->device->dev, pl022->sgt_rx.sgl, |
Linus Walleij | b1b6b9a | 2010-09-29 17:31:35 +0900 | [diff] [blame] | 1029 | pl022->sgt_rx.nents, DMA_FROM_DEVICE); |
Linus Walleij | 082086f | 2010-12-22 23:13:37 +0100 | [diff] [blame] | 1030 | if (!rx_sglen) |
Linus Walleij | b1b6b9a | 2010-09-29 17:31:35 +0900 | [diff] [blame] | 1031 | goto err_rx_sgmap; |
| 1032 | |
Linus Walleij | 082086f | 2010-12-22 23:13:37 +0100 | [diff] [blame] | 1033 | tx_sglen = dma_map_sg(txchan->device->dev, pl022->sgt_tx.sgl, |
Linus Walleij | b1b6b9a | 2010-09-29 17:31:35 +0900 | [diff] [blame] | 1034 | pl022->sgt_tx.nents, DMA_TO_DEVICE); |
Linus Walleij | 082086f | 2010-12-22 23:13:37 +0100 | [diff] [blame] | 1035 | if (!tx_sglen) |
Linus Walleij | b1b6b9a | 2010-09-29 17:31:35 +0900 | [diff] [blame] | 1036 | goto err_tx_sgmap; |
| 1037 | |
| 1038 | /* Send both scatterlists */ |
Alexandre Bounine | 1605282 | 2012-03-08 16:11:18 -0500 | [diff] [blame] | 1039 | rxdesc = dmaengine_prep_slave_sg(rxchan, |
Linus Walleij | b1b6b9a | 2010-09-29 17:31:35 +0900 | [diff] [blame] | 1040 | pl022->sgt_rx.sgl, |
Linus Walleij | 082086f | 2010-12-22 23:13:37 +0100 | [diff] [blame] | 1041 | rx_sglen, |
Vinod Koul | a485df4 | 2011-10-14 10:47:38 +0530 | [diff] [blame] | 1042 | DMA_DEV_TO_MEM, |
Linus Walleij | b1b6b9a | 2010-09-29 17:31:35 +0900 | [diff] [blame] | 1043 | DMA_PREP_INTERRUPT | DMA_CTRL_ACK); |
| 1044 | if (!rxdesc) |
| 1045 | goto err_rxdesc; |
| 1046 | |
Alexandre Bounine | 1605282 | 2012-03-08 16:11:18 -0500 | [diff] [blame] | 1047 | txdesc = dmaengine_prep_slave_sg(txchan, |
Linus Walleij | b1b6b9a | 2010-09-29 17:31:35 +0900 | [diff] [blame] | 1048 | pl022->sgt_tx.sgl, |
Linus Walleij | 082086f | 2010-12-22 23:13:37 +0100 | [diff] [blame] | 1049 | tx_sglen, |
Vinod Koul | a485df4 | 2011-10-14 10:47:38 +0530 | [diff] [blame] | 1050 | DMA_MEM_TO_DEV, |
Linus Walleij | b1b6b9a | 2010-09-29 17:31:35 +0900 | [diff] [blame] | 1051 | DMA_PREP_INTERRUPT | DMA_CTRL_ACK); |
| 1052 | if (!txdesc) |
| 1053 | goto err_txdesc; |
| 1054 | |
| 1055 | /* Put the callback on the RX transfer only, that should finish last */ |
| 1056 | rxdesc->callback = dma_callback; |
| 1057 | rxdesc->callback_param = pl022; |
| 1058 | |
| 1059 | /* Submit and fire RX and TX with TX last so we're ready to read! */ |
Linus Walleij | ecd442f | 2011-02-08 13:03:12 +0100 | [diff] [blame] | 1060 | dmaengine_submit(rxdesc); |
| 1061 | dmaengine_submit(txdesc); |
| 1062 | dma_async_issue_pending(rxchan); |
| 1063 | dma_async_issue_pending(txchan); |
Linus Walleij | ffbbdd2 | 2012-02-22 10:05:38 +0100 | [diff] [blame] | 1064 | pl022->dma_running = true; |
Linus Walleij | b1b6b9a | 2010-09-29 17:31:35 +0900 | [diff] [blame] | 1065 | |
| 1066 | return 0; |
| 1067 | |
Linus Walleij | b1b6b9a | 2010-09-29 17:31:35 +0900 | [diff] [blame] | 1068 | err_txdesc: |
Linus Walleij | ecd442f | 2011-02-08 13:03:12 +0100 | [diff] [blame] | 1069 | dmaengine_terminate_all(txchan); |
Linus Walleij | b1b6b9a | 2010-09-29 17:31:35 +0900 | [diff] [blame] | 1070 | err_rxdesc: |
Linus Walleij | ecd442f | 2011-02-08 13:03:12 +0100 | [diff] [blame] | 1071 | dmaengine_terminate_all(rxchan); |
Linus Walleij | b729889 | 2010-12-22 23:13:07 +0100 | [diff] [blame] | 1072 | dma_unmap_sg(txchan->device->dev, pl022->sgt_tx.sgl, |
Linus Walleij | b1b6b9a | 2010-09-29 17:31:35 +0900 | [diff] [blame] | 1073 | pl022->sgt_tx.nents, DMA_TO_DEVICE); |
| 1074 | err_tx_sgmap: |
Linus Walleij | b729889 | 2010-12-22 23:13:07 +0100 | [diff] [blame] | 1075 | dma_unmap_sg(rxchan->device->dev, pl022->sgt_rx.sgl, |
Linus Walleij | b1b6b9a | 2010-09-29 17:31:35 +0900 | [diff] [blame] | 1076 | pl022->sgt_tx.nents, DMA_FROM_DEVICE); |
| 1077 | err_rx_sgmap: |
| 1078 | sg_free_table(&pl022->sgt_tx); |
| 1079 | err_alloc_tx_sg: |
| 1080 | sg_free_table(&pl022->sgt_rx); |
| 1081 | err_alloc_rx_sg: |
| 1082 | return -ENOMEM; |
| 1083 | } |
| 1084 | |
Russell King | a5ab629 | 2012-02-13 09:52:29 +0000 | [diff] [blame] | 1085 | static int __devinit pl022_dma_probe(struct pl022 *pl022) |
Linus Walleij | b1b6b9a | 2010-09-29 17:31:35 +0900 | [diff] [blame] | 1086 | { |
| 1087 | dma_cap_mask_t mask; |
| 1088 | |
| 1089 | /* Try to acquire a generic DMA engine slave channel */ |
| 1090 | dma_cap_zero(mask); |
| 1091 | dma_cap_set(DMA_SLAVE, mask); |
| 1092 | /* |
| 1093 | * We need both RX and TX channels to do DMA, else do none |
| 1094 | * of them. |
| 1095 | */ |
| 1096 | pl022->dma_rx_channel = dma_request_channel(mask, |
| 1097 | pl022->master_info->dma_filter, |
| 1098 | pl022->master_info->dma_rx_param); |
| 1099 | if (!pl022->dma_rx_channel) { |
Viresh Kumar | 43c6401 | 2011-05-16 09:40:10 +0530 | [diff] [blame] | 1100 | dev_dbg(&pl022->adev->dev, "no RX DMA channel!\n"); |
Linus Walleij | b1b6b9a | 2010-09-29 17:31:35 +0900 | [diff] [blame] | 1101 | goto err_no_rxchan; |
| 1102 | } |
| 1103 | |
| 1104 | pl022->dma_tx_channel = dma_request_channel(mask, |
| 1105 | pl022->master_info->dma_filter, |
| 1106 | pl022->master_info->dma_tx_param); |
| 1107 | if (!pl022->dma_tx_channel) { |
Viresh Kumar | 43c6401 | 2011-05-16 09:40:10 +0530 | [diff] [blame] | 1108 | dev_dbg(&pl022->adev->dev, "no TX DMA channel!\n"); |
Linus Walleij | b1b6b9a | 2010-09-29 17:31:35 +0900 | [diff] [blame] | 1109 | goto err_no_txchan; |
| 1110 | } |
| 1111 | |
| 1112 | pl022->dummypage = kmalloc(PAGE_SIZE, GFP_KERNEL); |
| 1113 | if (!pl022->dummypage) { |
Viresh Kumar | 43c6401 | 2011-05-16 09:40:10 +0530 | [diff] [blame] | 1114 | dev_dbg(&pl022->adev->dev, "no DMA dummypage!\n"); |
Linus Walleij | b1b6b9a | 2010-09-29 17:31:35 +0900 | [diff] [blame] | 1115 | goto err_no_dummypage; |
| 1116 | } |
| 1117 | |
| 1118 | dev_info(&pl022->adev->dev, "setup for DMA on RX %s, TX %s\n", |
| 1119 | dma_chan_name(pl022->dma_rx_channel), |
| 1120 | dma_chan_name(pl022->dma_tx_channel)); |
| 1121 | |
| 1122 | return 0; |
| 1123 | |
| 1124 | err_no_dummypage: |
| 1125 | dma_release_channel(pl022->dma_tx_channel); |
| 1126 | err_no_txchan: |
| 1127 | dma_release_channel(pl022->dma_rx_channel); |
| 1128 | pl022->dma_rx_channel = NULL; |
| 1129 | err_no_rxchan: |
Viresh Kumar | 43c6401 | 2011-05-16 09:40:10 +0530 | [diff] [blame] | 1130 | dev_err(&pl022->adev->dev, |
| 1131 | "Failed to work in dma mode, work without dma!\n"); |
Linus Walleij | b1b6b9a | 2010-09-29 17:31:35 +0900 | [diff] [blame] | 1132 | return -ENODEV; |
| 1133 | } |
| 1134 | |
| 1135 | static void terminate_dma(struct pl022 *pl022) |
| 1136 | { |
| 1137 | struct dma_chan *rxchan = pl022->dma_rx_channel; |
| 1138 | struct dma_chan *txchan = pl022->dma_tx_channel; |
| 1139 | |
Linus Walleij | ecd442f | 2011-02-08 13:03:12 +0100 | [diff] [blame] | 1140 | dmaengine_terminate_all(rxchan); |
| 1141 | dmaengine_terminate_all(txchan); |
Linus Walleij | b1b6b9a | 2010-09-29 17:31:35 +0900 | [diff] [blame] | 1142 | unmap_free_dma_scatter(pl022); |
Linus Walleij | ffbbdd2 | 2012-02-22 10:05:38 +0100 | [diff] [blame] | 1143 | pl022->dma_running = false; |
Linus Walleij | b1b6b9a | 2010-09-29 17:31:35 +0900 | [diff] [blame] | 1144 | } |
| 1145 | |
| 1146 | static void pl022_dma_remove(struct pl022 *pl022) |
| 1147 | { |
Linus Walleij | ffbbdd2 | 2012-02-22 10:05:38 +0100 | [diff] [blame] | 1148 | if (pl022->dma_running) |
Linus Walleij | b1b6b9a | 2010-09-29 17:31:35 +0900 | [diff] [blame] | 1149 | terminate_dma(pl022); |
| 1150 | if (pl022->dma_tx_channel) |
| 1151 | dma_release_channel(pl022->dma_tx_channel); |
| 1152 | if (pl022->dma_rx_channel) |
| 1153 | dma_release_channel(pl022->dma_rx_channel); |
| 1154 | kfree(pl022->dummypage); |
| 1155 | } |
| 1156 | |
| 1157 | #else |
| 1158 | static inline int configure_dma(struct pl022 *pl022) |
| 1159 | { |
| 1160 | return -ENODEV; |
| 1161 | } |
| 1162 | |
| 1163 | static inline int pl022_dma_probe(struct pl022 *pl022) |
| 1164 | { |
| 1165 | return 0; |
| 1166 | } |
| 1167 | |
| 1168 | static inline void pl022_dma_remove(struct pl022 *pl022) |
| 1169 | { |
| 1170 | } |
| 1171 | #endif |
| 1172 | |
Linus Walleij | b43d65f | 2009-06-09 08:11:42 +0100 | [diff] [blame] | 1173 | /** |
| 1174 | * pl022_interrupt_handler - Interrupt handler for SSP controller |
| 1175 | * |
| 1176 | * This function handles interrupts generated for an interrupt based transfer. |
| 1177 | * If a receive overrun (ROR) interrupt is there then we disable SSP, flag the |
| 1178 | * current message's state as STATE_ERROR and schedule the tasklet |
| 1179 | * pump_transfers which will do the postprocessing of the current message by |
| 1180 | * calling giveback(). Otherwise it reads data from RX FIFO till there is no |
| 1181 | * more data, and writes data in TX FIFO till it is not full. If we complete |
| 1182 | * the transfer we move to the next transfer and schedule the tasklet. |
| 1183 | */ |
| 1184 | static irqreturn_t pl022_interrupt_handler(int irq, void *dev_id) |
| 1185 | { |
| 1186 | struct pl022 *pl022 = dev_id; |
| 1187 | struct spi_message *msg = pl022->cur_msg; |
| 1188 | u16 irq_status = 0; |
| 1189 | u16 flag = 0; |
| 1190 | |
| 1191 | if (unlikely(!msg)) { |
| 1192 | dev_err(&pl022->adev->dev, |
| 1193 | "bad message state in interrupt handler"); |
| 1194 | /* Never fail */ |
| 1195 | return IRQ_HANDLED; |
| 1196 | } |
| 1197 | |
| 1198 | /* Read the Interrupt Status Register */ |
| 1199 | irq_status = readw(SSP_MIS(pl022->virtbase)); |
| 1200 | |
| 1201 | if (unlikely(!irq_status)) |
| 1202 | return IRQ_NONE; |
| 1203 | |
Linus Walleij | b1b6b9a | 2010-09-29 17:31:35 +0900 | [diff] [blame] | 1204 | /* |
| 1205 | * This handles the FIFO interrupts, the timeout |
| 1206 | * interrupts are flatly ignored, they cannot be |
| 1207 | * trusted. |
| 1208 | */ |
Linus Walleij | b43d65f | 2009-06-09 08:11:42 +0100 | [diff] [blame] | 1209 | if (unlikely(irq_status & SSP_MIS_MASK_RORMIS)) { |
| 1210 | /* |
| 1211 | * Overrun interrupt - bail out since our Data has been |
| 1212 | * corrupted |
| 1213 | */ |
Linus Walleij | b1b6b9a | 2010-09-29 17:31:35 +0900 | [diff] [blame] | 1214 | dev_err(&pl022->adev->dev, "FIFO overrun\n"); |
Linus Walleij | b43d65f | 2009-06-09 08:11:42 +0100 | [diff] [blame] | 1215 | if (readw(SSP_SR(pl022->virtbase)) & SSP_SR_MASK_RFF) |
| 1216 | dev_err(&pl022->adev->dev, |
| 1217 | "RXFIFO is full\n"); |
| 1218 | if (readw(SSP_SR(pl022->virtbase)) & SSP_SR_MASK_TNF) |
| 1219 | dev_err(&pl022->adev->dev, |
| 1220 | "TXFIFO is full\n"); |
| 1221 | |
| 1222 | /* |
| 1223 | * Disable and clear interrupts, disable SSP, |
| 1224 | * mark message with bad status so it can be |
| 1225 | * retried. |
| 1226 | */ |
| 1227 | writew(DISABLE_ALL_INTERRUPTS, |
| 1228 | SSP_IMSC(pl022->virtbase)); |
| 1229 | writew(CLEAR_ALL_INTERRUPTS, SSP_ICR(pl022->virtbase)); |
| 1230 | writew((readw(SSP_CR1(pl022->virtbase)) & |
| 1231 | (~SSP_CR1_MASK_SSE)), SSP_CR1(pl022->virtbase)); |
| 1232 | msg->state = STATE_ERROR; |
| 1233 | |
| 1234 | /* Schedule message queue handler */ |
| 1235 | tasklet_schedule(&pl022->pump_transfers); |
| 1236 | return IRQ_HANDLED; |
| 1237 | } |
| 1238 | |
| 1239 | readwriter(pl022); |
| 1240 | |
| 1241 | if ((pl022->tx == pl022->tx_end) && (flag == 0)) { |
| 1242 | flag = 1; |
Chris Blair | 172289d | 2011-06-04 07:57:47 +0100 | [diff] [blame] | 1243 | /* Disable Transmit interrupt, enable receive interrupt */ |
| 1244 | writew((readw(SSP_IMSC(pl022->virtbase)) & |
| 1245 | ~SSP_IMSC_MASK_TXIM) | SSP_IMSC_MASK_RXIM, |
Linus Walleij | b43d65f | 2009-06-09 08:11:42 +0100 | [diff] [blame] | 1246 | SSP_IMSC(pl022->virtbase)); |
| 1247 | } |
| 1248 | |
| 1249 | /* |
| 1250 | * Since all transactions must write as much as shall be read, |
| 1251 | * we can conclude the entire transaction once RX is complete. |
| 1252 | * At this point, all TX will always be finished. |
| 1253 | */ |
| 1254 | if (pl022->rx >= pl022->rx_end) { |
| 1255 | writew(DISABLE_ALL_INTERRUPTS, |
| 1256 | SSP_IMSC(pl022->virtbase)); |
| 1257 | writew(CLEAR_ALL_INTERRUPTS, SSP_ICR(pl022->virtbase)); |
| 1258 | if (unlikely(pl022->rx > pl022->rx_end)) { |
| 1259 | dev_warn(&pl022->adev->dev, "read %u surplus " |
| 1260 | "bytes (did you request an odd " |
| 1261 | "number of bytes on a 16bit bus?)\n", |
| 1262 | (u32) (pl022->rx - pl022->rx_end)); |
| 1263 | } |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 1264 | /* Update total bytes transferred */ |
Linus Walleij | b43d65f | 2009-06-09 08:11:42 +0100 | [diff] [blame] | 1265 | msg->actual_length += pl022->cur_transfer->len; |
| 1266 | if (pl022->cur_transfer->cs_change) |
Roland Stigge | f6f46de | 2012-08-22 15:49:17 +0200 | [diff] [blame^] | 1267 | pl022_cs_control(pl022, SSP_CHIP_DESELECT); |
Linus Walleij | b43d65f | 2009-06-09 08:11:42 +0100 | [diff] [blame] | 1268 | /* Move to next transfer */ |
| 1269 | msg->state = next_transfer(pl022); |
| 1270 | tasklet_schedule(&pl022->pump_transfers); |
| 1271 | return IRQ_HANDLED; |
| 1272 | } |
| 1273 | |
| 1274 | return IRQ_HANDLED; |
| 1275 | } |
| 1276 | |
| 1277 | /** |
| 1278 | * This sets up the pointers to memory for the next message to |
| 1279 | * send out on the SPI bus. |
| 1280 | */ |
| 1281 | static int set_up_next_transfer(struct pl022 *pl022, |
| 1282 | struct spi_transfer *transfer) |
| 1283 | { |
| 1284 | int residue; |
| 1285 | |
| 1286 | /* Sanity check the message for this bus width */ |
| 1287 | residue = pl022->cur_transfer->len % pl022->cur_chip->n_bytes; |
| 1288 | if (unlikely(residue != 0)) { |
| 1289 | dev_err(&pl022->adev->dev, |
| 1290 | "message of %u bytes to transmit but the current " |
| 1291 | "chip bus has a data width of %u bytes!\n", |
| 1292 | pl022->cur_transfer->len, |
| 1293 | pl022->cur_chip->n_bytes); |
| 1294 | dev_err(&pl022->adev->dev, "skipping this message\n"); |
| 1295 | return -EIO; |
| 1296 | } |
| 1297 | pl022->tx = (void *)transfer->tx_buf; |
| 1298 | pl022->tx_end = pl022->tx + pl022->cur_transfer->len; |
| 1299 | pl022->rx = (void *)transfer->rx_buf; |
| 1300 | pl022->rx_end = pl022->rx + pl022->cur_transfer->len; |
| 1301 | pl022->write = |
| 1302 | pl022->tx ? pl022->cur_chip->write : WRITING_NULL; |
| 1303 | pl022->read = pl022->rx ? pl022->cur_chip->read : READING_NULL; |
| 1304 | return 0; |
| 1305 | } |
| 1306 | |
| 1307 | /** |
Linus Walleij | b1b6b9a | 2010-09-29 17:31:35 +0900 | [diff] [blame] | 1308 | * pump_transfers - Tasklet function which schedules next transfer |
| 1309 | * when running in interrupt or DMA transfer mode. |
Linus Walleij | b43d65f | 2009-06-09 08:11:42 +0100 | [diff] [blame] | 1310 | * @data: SSP driver private data structure |
| 1311 | * |
| 1312 | */ |
| 1313 | static void pump_transfers(unsigned long data) |
| 1314 | { |
| 1315 | struct pl022 *pl022 = (struct pl022 *) data; |
| 1316 | struct spi_message *message = NULL; |
| 1317 | struct spi_transfer *transfer = NULL; |
| 1318 | struct spi_transfer *previous = NULL; |
| 1319 | |
| 1320 | /* Get current state information */ |
| 1321 | message = pl022->cur_msg; |
| 1322 | transfer = pl022->cur_transfer; |
| 1323 | |
| 1324 | /* Handle for abort */ |
| 1325 | if (message->state == STATE_ERROR) { |
| 1326 | message->status = -EIO; |
| 1327 | giveback(pl022); |
| 1328 | return; |
| 1329 | } |
| 1330 | |
| 1331 | /* Handle end of message */ |
| 1332 | if (message->state == STATE_DONE) { |
| 1333 | message->status = 0; |
| 1334 | giveback(pl022); |
| 1335 | return; |
| 1336 | } |
| 1337 | |
| 1338 | /* Delay if requested at end of transfer before CS change */ |
| 1339 | if (message->state == STATE_RUNNING) { |
| 1340 | previous = list_entry(transfer->transfer_list.prev, |
| 1341 | struct spi_transfer, |
| 1342 | transfer_list); |
| 1343 | if (previous->delay_usecs) |
| 1344 | /* |
| 1345 | * FIXME: This runs in interrupt context. |
| 1346 | * Is this really smart? |
| 1347 | */ |
| 1348 | udelay(previous->delay_usecs); |
| 1349 | |
Virupax Sadashivpetimath | 8b8d719 | 2011-11-10 12:43:24 +0530 | [diff] [blame] | 1350 | /* Reselect chip select only if cs_change was requested */ |
Linus Walleij | b43d65f | 2009-06-09 08:11:42 +0100 | [diff] [blame] | 1351 | if (previous->cs_change) |
Roland Stigge | f6f46de | 2012-08-22 15:49:17 +0200 | [diff] [blame^] | 1352 | pl022_cs_control(pl022, SSP_CHIP_SELECT); |
Linus Walleij | b43d65f | 2009-06-09 08:11:42 +0100 | [diff] [blame] | 1353 | } else { |
| 1354 | /* STATE_START */ |
| 1355 | message->state = STATE_RUNNING; |
| 1356 | } |
| 1357 | |
| 1358 | if (set_up_next_transfer(pl022, transfer)) { |
| 1359 | message->state = STATE_ERROR; |
| 1360 | message->status = -EIO; |
| 1361 | giveback(pl022); |
| 1362 | return; |
| 1363 | } |
| 1364 | /* Flush the FIFOs and let's go! */ |
| 1365 | flush(pl022); |
Linus Walleij | b1b6b9a | 2010-09-29 17:31:35 +0900 | [diff] [blame] | 1366 | |
| 1367 | if (pl022->cur_chip->enable_dma) { |
| 1368 | if (configure_dma(pl022)) { |
| 1369 | dev_dbg(&pl022->adev->dev, |
| 1370 | "configuration of DMA failed, fall back to interrupt mode\n"); |
| 1371 | goto err_config_dma; |
| 1372 | } |
| 1373 | return; |
| 1374 | } |
| 1375 | |
| 1376 | err_config_dma: |
Chris Blair | 172289d | 2011-06-04 07:57:47 +0100 | [diff] [blame] | 1377 | /* enable all interrupts except RX */ |
| 1378 | writew(ENABLE_ALL_INTERRUPTS & ~SSP_IMSC_MASK_RXIM, SSP_IMSC(pl022->virtbase)); |
Linus Walleij | b43d65f | 2009-06-09 08:11:42 +0100 | [diff] [blame] | 1379 | } |
| 1380 | |
Linus Walleij | b1b6b9a | 2010-09-29 17:31:35 +0900 | [diff] [blame] | 1381 | static void do_interrupt_dma_transfer(struct pl022 *pl022) |
Linus Walleij | b43d65f | 2009-06-09 08:11:42 +0100 | [diff] [blame] | 1382 | { |
Chris Blair | 172289d | 2011-06-04 07:57:47 +0100 | [diff] [blame] | 1383 | /* |
| 1384 | * Default is to enable all interrupts except RX - |
| 1385 | * this will be enabled once TX is complete |
| 1386 | */ |
| 1387 | u32 irqflags = ENABLE_ALL_INTERRUPTS & ~SSP_IMSC_MASK_RXIM; |
Linus Walleij | b43d65f | 2009-06-09 08:11:42 +0100 | [diff] [blame] | 1388 | |
Virupax Sadashivpetimath | 8b8d719 | 2011-11-10 12:43:24 +0530 | [diff] [blame] | 1389 | /* Enable target chip, if not already active */ |
| 1390 | if (!pl022->next_msg_cs_active) |
Roland Stigge | f6f46de | 2012-08-22 15:49:17 +0200 | [diff] [blame^] | 1391 | pl022_cs_control(pl022, SSP_CHIP_SELECT); |
Virupax Sadashivpetimath | 8b8d719 | 2011-11-10 12:43:24 +0530 | [diff] [blame] | 1392 | |
Linus Walleij | b43d65f | 2009-06-09 08:11:42 +0100 | [diff] [blame] | 1393 | if (set_up_next_transfer(pl022, pl022->cur_transfer)) { |
| 1394 | /* Error path */ |
| 1395 | pl022->cur_msg->state = STATE_ERROR; |
| 1396 | pl022->cur_msg->status = -EIO; |
| 1397 | giveback(pl022); |
| 1398 | return; |
| 1399 | } |
Linus Walleij | b1b6b9a | 2010-09-29 17:31:35 +0900 | [diff] [blame] | 1400 | /* If we're using DMA, set up DMA here */ |
| 1401 | if (pl022->cur_chip->enable_dma) { |
| 1402 | /* Configure DMA transfer */ |
| 1403 | if (configure_dma(pl022)) { |
| 1404 | dev_dbg(&pl022->adev->dev, |
| 1405 | "configuration of DMA failed, fall back to interrupt mode\n"); |
| 1406 | goto err_config_dma; |
| 1407 | } |
| 1408 | /* Disable interrupts in DMA mode, IRQ from DMA controller */ |
| 1409 | irqflags = DISABLE_ALL_INTERRUPTS; |
| 1410 | } |
| 1411 | err_config_dma: |
Linus Walleij | b43d65f | 2009-06-09 08:11:42 +0100 | [diff] [blame] | 1412 | /* Enable SSP, turn on interrupts */ |
| 1413 | writew((readw(SSP_CR1(pl022->virtbase)) | SSP_CR1_MASK_SSE), |
| 1414 | SSP_CR1(pl022->virtbase)); |
Linus Walleij | b1b6b9a | 2010-09-29 17:31:35 +0900 | [diff] [blame] | 1415 | writew(irqflags, SSP_IMSC(pl022->virtbase)); |
Linus Walleij | b43d65f | 2009-06-09 08:11:42 +0100 | [diff] [blame] | 1416 | } |
| 1417 | |
Linus Walleij | b1b6b9a | 2010-09-29 17:31:35 +0900 | [diff] [blame] | 1418 | static void do_polling_transfer(struct pl022 *pl022) |
Linus Walleij | b43d65f | 2009-06-09 08:11:42 +0100 | [diff] [blame] | 1419 | { |
Linus Walleij | b43d65f | 2009-06-09 08:11:42 +0100 | [diff] [blame] | 1420 | struct spi_message *message = NULL; |
| 1421 | struct spi_transfer *transfer = NULL; |
| 1422 | struct spi_transfer *previous = NULL; |
| 1423 | struct chip_data *chip; |
Magnus Templing | a18c266 | 2011-05-19 18:05:34 +0200 | [diff] [blame] | 1424 | unsigned long time, timeout; |
Linus Walleij | b43d65f | 2009-06-09 08:11:42 +0100 | [diff] [blame] | 1425 | |
| 1426 | chip = pl022->cur_chip; |
| 1427 | message = pl022->cur_msg; |
| 1428 | |
| 1429 | while (message->state != STATE_DONE) { |
| 1430 | /* Handle for abort */ |
| 1431 | if (message->state == STATE_ERROR) |
| 1432 | break; |
| 1433 | transfer = pl022->cur_transfer; |
| 1434 | |
| 1435 | /* Delay if requested at end of transfer */ |
| 1436 | if (message->state == STATE_RUNNING) { |
| 1437 | previous = |
| 1438 | list_entry(transfer->transfer_list.prev, |
| 1439 | struct spi_transfer, transfer_list); |
| 1440 | if (previous->delay_usecs) |
| 1441 | udelay(previous->delay_usecs); |
| 1442 | if (previous->cs_change) |
Roland Stigge | f6f46de | 2012-08-22 15:49:17 +0200 | [diff] [blame^] | 1443 | pl022_cs_control(pl022, SSP_CHIP_SELECT); |
Linus Walleij | b43d65f | 2009-06-09 08:11:42 +0100 | [diff] [blame] | 1444 | } else { |
| 1445 | /* STATE_START */ |
| 1446 | message->state = STATE_RUNNING; |
Virupax Sadashivpetimath | 8b8d719 | 2011-11-10 12:43:24 +0530 | [diff] [blame] | 1447 | if (!pl022->next_msg_cs_active) |
Roland Stigge | f6f46de | 2012-08-22 15:49:17 +0200 | [diff] [blame^] | 1448 | pl022_cs_control(pl022, SSP_CHIP_SELECT); |
Linus Walleij | b43d65f | 2009-06-09 08:11:42 +0100 | [diff] [blame] | 1449 | } |
| 1450 | |
| 1451 | /* Configuration Changing Per Transfer */ |
| 1452 | if (set_up_next_transfer(pl022, transfer)) { |
| 1453 | /* Error path */ |
| 1454 | message->state = STATE_ERROR; |
| 1455 | break; |
| 1456 | } |
| 1457 | /* Flush FIFOs and enable SSP */ |
| 1458 | flush(pl022); |
| 1459 | writew((readw(SSP_CR1(pl022->virtbase)) | SSP_CR1_MASK_SSE), |
| 1460 | SSP_CR1(pl022->virtbase)); |
| 1461 | |
Linus Walleij | 556f4ae | 2010-05-05 09:28:15 +0000 | [diff] [blame] | 1462 | dev_dbg(&pl022->adev->dev, "polling transfer ongoing ...\n"); |
Magnus Templing | a18c266 | 2011-05-19 18:05:34 +0200 | [diff] [blame] | 1463 | |
| 1464 | timeout = jiffies + msecs_to_jiffies(SPI_POLLING_TIMEOUT); |
| 1465 | while (pl022->tx < pl022->tx_end || pl022->rx < pl022->rx_end) { |
| 1466 | time = jiffies; |
Linus Walleij | b43d65f | 2009-06-09 08:11:42 +0100 | [diff] [blame] | 1467 | readwriter(pl022); |
Magnus Templing | a18c266 | 2011-05-19 18:05:34 +0200 | [diff] [blame] | 1468 | if (time_after(time, timeout)) { |
| 1469 | dev_warn(&pl022->adev->dev, |
| 1470 | "%s: timeout!\n", __func__); |
| 1471 | message->state = STATE_ERROR; |
| 1472 | goto out; |
| 1473 | } |
Linus Walleij | 521999b | 2011-05-19 20:01:25 +0200 | [diff] [blame] | 1474 | cpu_relax(); |
Magnus Templing | a18c266 | 2011-05-19 18:05:34 +0200 | [diff] [blame] | 1475 | } |
Linus Walleij | b43d65f | 2009-06-09 08:11:42 +0100 | [diff] [blame] | 1476 | |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 1477 | /* Update total byte transferred */ |
Linus Walleij | b43d65f | 2009-06-09 08:11:42 +0100 | [diff] [blame] | 1478 | message->actual_length += pl022->cur_transfer->len; |
| 1479 | if (pl022->cur_transfer->cs_change) |
Roland Stigge | f6f46de | 2012-08-22 15:49:17 +0200 | [diff] [blame^] | 1480 | pl022_cs_control(pl022, SSP_CHIP_DESELECT); |
Linus Walleij | b43d65f | 2009-06-09 08:11:42 +0100 | [diff] [blame] | 1481 | /* Move to next transfer */ |
| 1482 | message->state = next_transfer(pl022); |
| 1483 | } |
Magnus Templing | a18c266 | 2011-05-19 18:05:34 +0200 | [diff] [blame] | 1484 | out: |
Linus Walleij | b43d65f | 2009-06-09 08:11:42 +0100 | [diff] [blame] | 1485 | /* Handle end of message */ |
| 1486 | if (message->state == STATE_DONE) |
| 1487 | message->status = 0; |
| 1488 | else |
| 1489 | message->status = -EIO; |
| 1490 | |
| 1491 | giveback(pl022); |
| 1492 | return; |
| 1493 | } |
| 1494 | |
Linus Walleij | ffbbdd2 | 2012-02-22 10:05:38 +0100 | [diff] [blame] | 1495 | static int pl022_transfer_one_message(struct spi_master *master, |
| 1496 | struct spi_message *msg) |
Linus Walleij | b43d65f | 2009-06-09 08:11:42 +0100 | [diff] [blame] | 1497 | { |
Linus Walleij | ffbbdd2 | 2012-02-22 10:05:38 +0100 | [diff] [blame] | 1498 | struct pl022 *pl022 = spi_master_get_devdata(master); |
Linus Walleij | b43d65f | 2009-06-09 08:11:42 +0100 | [diff] [blame] | 1499 | |
| 1500 | /* Initial message state */ |
Linus Walleij | ffbbdd2 | 2012-02-22 10:05:38 +0100 | [diff] [blame] | 1501 | pl022->cur_msg = msg; |
| 1502 | msg->state = STATE_START; |
| 1503 | |
| 1504 | pl022->cur_transfer = list_entry(msg->transfers.next, |
| 1505 | struct spi_transfer, transfer_list); |
Linus Walleij | b43d65f | 2009-06-09 08:11:42 +0100 | [diff] [blame] | 1506 | |
| 1507 | /* Setup the SPI using the per chip configuration */ |
Linus Walleij | ffbbdd2 | 2012-02-22 10:05:38 +0100 | [diff] [blame] | 1508 | pl022->cur_chip = spi_get_ctldata(msg->spi); |
Roland Stigge | f6f46de | 2012-08-22 15:49:17 +0200 | [diff] [blame^] | 1509 | pl022->cur_cs = pl022->chipselects[msg->spi->chip_select]; |
Chris Blair | d4b6af2 | 2011-11-04 07:43:41 +0000 | [diff] [blame] | 1510 | |
Linus Walleij | b43d65f | 2009-06-09 08:11:42 +0100 | [diff] [blame] | 1511 | restore_state(pl022); |
| 1512 | flush(pl022); |
| 1513 | |
| 1514 | if (pl022->cur_chip->xfer_type == POLLING_TRANSFER) |
| 1515 | do_polling_transfer(pl022); |
Linus Walleij | b43d65f | 2009-06-09 08:11:42 +0100 | [diff] [blame] | 1516 | else |
Linus Walleij | b1b6b9a | 2010-09-29 17:31:35 +0900 | [diff] [blame] | 1517 | do_interrupt_dma_transfer(pl022); |
Linus Walleij | b43d65f | 2009-06-09 08:11:42 +0100 | [diff] [blame] | 1518 | |
| 1519 | return 0; |
| 1520 | } |
| 1521 | |
Linus Walleij | ffbbdd2 | 2012-02-22 10:05:38 +0100 | [diff] [blame] | 1522 | static int pl022_prepare_transfer_hardware(struct spi_master *master) |
Linus Walleij | b43d65f | 2009-06-09 08:11:42 +0100 | [diff] [blame] | 1523 | { |
Linus Walleij | ffbbdd2 | 2012-02-22 10:05:38 +0100 | [diff] [blame] | 1524 | struct pl022 *pl022 = spi_master_get_devdata(master); |
Linus Walleij | b43d65f | 2009-06-09 08:11:42 +0100 | [diff] [blame] | 1525 | |
Linus Walleij | ffbbdd2 | 2012-02-22 10:05:38 +0100 | [diff] [blame] | 1526 | /* |
| 1527 | * Just make sure we have all we need to run the transfer by syncing |
| 1528 | * with the runtime PM framework. |
| 1529 | */ |
| 1530 | pm_runtime_get_sync(&pl022->adev->dev); |
Linus Walleij | b43d65f | 2009-06-09 08:11:42 +0100 | [diff] [blame] | 1531 | return 0; |
| 1532 | } |
| 1533 | |
Linus Walleij | ffbbdd2 | 2012-02-22 10:05:38 +0100 | [diff] [blame] | 1534 | static int pl022_unprepare_transfer_hardware(struct spi_master *master) |
Linus Walleij | b43d65f | 2009-06-09 08:11:42 +0100 | [diff] [blame] | 1535 | { |
Linus Walleij | ffbbdd2 | 2012-02-22 10:05:38 +0100 | [diff] [blame] | 1536 | struct pl022 *pl022 = spi_master_get_devdata(master); |
Linus Walleij | b43d65f | 2009-06-09 08:11:42 +0100 | [diff] [blame] | 1537 | |
Linus Walleij | ffbbdd2 | 2012-02-22 10:05:38 +0100 | [diff] [blame] | 1538 | /* nothing more to do - disable spi/ssp and power off */ |
| 1539 | writew((readw(SSP_CR1(pl022->virtbase)) & |
| 1540 | (~SSP_CR1_MASK_SSE)), SSP_CR1(pl022->virtbase)); |
Linus Walleij | b43d65f | 2009-06-09 08:11:42 +0100 | [diff] [blame] | 1541 | |
Linus Walleij | ffbbdd2 | 2012-02-22 10:05:38 +0100 | [diff] [blame] | 1542 | if (pl022->master_info->autosuspend_delay > 0) { |
| 1543 | pm_runtime_mark_last_busy(&pl022->adev->dev); |
| 1544 | pm_runtime_put_autosuspend(&pl022->adev->dev); |
| 1545 | } else { |
| 1546 | pm_runtime_put(&pl022->adev->dev); |
Linus Walleij | b43d65f | 2009-06-09 08:11:42 +0100 | [diff] [blame] | 1547 | } |
| 1548 | |
Linus Walleij | b43d65f | 2009-06-09 08:11:42 +0100 | [diff] [blame] | 1549 | return 0; |
| 1550 | } |
| 1551 | |
| 1552 | static int verify_controller_parameters(struct pl022 *pl022, |
Linus Walleij | f9d629c | 2010-10-01 13:33:13 +0200 | [diff] [blame] | 1553 | struct pl022_config_chip const *chip_info) |
Linus Walleij | b43d65f | 2009-06-09 08:11:42 +0100 | [diff] [blame] | 1554 | { |
Linus Walleij | b43d65f | 2009-06-09 08:11:42 +0100 | [diff] [blame] | 1555 | if ((chip_info->iface < SSP_INTERFACE_MOTOROLA_SPI) |
| 1556 | || (chip_info->iface > SSP_INTERFACE_UNIDIRECTIONAL)) { |
Linus Walleij | 5a1c98b | 2010-10-01 11:47:32 +0200 | [diff] [blame] | 1557 | dev_err(&pl022->adev->dev, |
Linus Walleij | b43d65f | 2009-06-09 08:11:42 +0100 | [diff] [blame] | 1558 | "interface is configured incorrectly\n"); |
| 1559 | return -EINVAL; |
| 1560 | } |
| 1561 | if ((chip_info->iface == SSP_INTERFACE_UNIDIRECTIONAL) && |
| 1562 | (!pl022->vendor->unidir)) { |
Linus Walleij | 5a1c98b | 2010-10-01 11:47:32 +0200 | [diff] [blame] | 1563 | dev_err(&pl022->adev->dev, |
Linus Walleij | b43d65f | 2009-06-09 08:11:42 +0100 | [diff] [blame] | 1564 | "unidirectional mode not supported in this " |
| 1565 | "hardware version\n"); |
| 1566 | return -EINVAL; |
| 1567 | } |
| 1568 | if ((chip_info->hierarchy != SSP_MASTER) |
| 1569 | && (chip_info->hierarchy != SSP_SLAVE)) { |
Linus Walleij | 5a1c98b | 2010-10-01 11:47:32 +0200 | [diff] [blame] | 1570 | dev_err(&pl022->adev->dev, |
Linus Walleij | b43d65f | 2009-06-09 08:11:42 +0100 | [diff] [blame] | 1571 | "hierarchy is configured incorrectly\n"); |
| 1572 | return -EINVAL; |
| 1573 | } |
Linus Walleij | b43d65f | 2009-06-09 08:11:42 +0100 | [diff] [blame] | 1574 | if ((chip_info->com_mode != INTERRUPT_TRANSFER) |
| 1575 | && (chip_info->com_mode != DMA_TRANSFER) |
| 1576 | && (chip_info->com_mode != POLLING_TRANSFER)) { |
Linus Walleij | 5a1c98b | 2010-10-01 11:47:32 +0200 | [diff] [blame] | 1577 | dev_err(&pl022->adev->dev, |
Linus Walleij | b43d65f | 2009-06-09 08:11:42 +0100 | [diff] [blame] | 1578 | "Communication mode is configured incorrectly\n"); |
| 1579 | return -EINVAL; |
| 1580 | } |
Linus Walleij | 78b2b91 | 2011-06-16 10:14:46 +0200 | [diff] [blame] | 1581 | switch (chip_info->rx_lev_trig) { |
| 1582 | case SSP_RX_1_OR_MORE_ELEM: |
| 1583 | case SSP_RX_4_OR_MORE_ELEM: |
| 1584 | case SSP_RX_8_OR_MORE_ELEM: |
| 1585 | /* These are always OK, all variants can handle this */ |
| 1586 | break; |
| 1587 | case SSP_RX_16_OR_MORE_ELEM: |
| 1588 | if (pl022->vendor->fifodepth < 16) { |
| 1589 | dev_err(&pl022->adev->dev, |
| 1590 | "RX FIFO Trigger Level is configured incorrectly\n"); |
| 1591 | return -EINVAL; |
| 1592 | } |
| 1593 | break; |
| 1594 | case SSP_RX_32_OR_MORE_ELEM: |
| 1595 | if (pl022->vendor->fifodepth < 32) { |
| 1596 | dev_err(&pl022->adev->dev, |
| 1597 | "RX FIFO Trigger Level is configured incorrectly\n"); |
| 1598 | return -EINVAL; |
| 1599 | } |
| 1600 | break; |
| 1601 | default: |
Linus Walleij | 5a1c98b | 2010-10-01 11:47:32 +0200 | [diff] [blame] | 1602 | dev_err(&pl022->adev->dev, |
Linus Walleij | b43d65f | 2009-06-09 08:11:42 +0100 | [diff] [blame] | 1603 | "RX FIFO Trigger Level is configured incorrectly\n"); |
| 1604 | return -EINVAL; |
Linus Walleij | 78b2b91 | 2011-06-16 10:14:46 +0200 | [diff] [blame] | 1605 | break; |
Linus Walleij | b43d65f | 2009-06-09 08:11:42 +0100 | [diff] [blame] | 1606 | } |
Linus Walleij | 78b2b91 | 2011-06-16 10:14:46 +0200 | [diff] [blame] | 1607 | switch (chip_info->tx_lev_trig) { |
| 1608 | case SSP_TX_1_OR_MORE_EMPTY_LOC: |
| 1609 | case SSP_TX_4_OR_MORE_EMPTY_LOC: |
| 1610 | case SSP_TX_8_OR_MORE_EMPTY_LOC: |
| 1611 | /* These are always OK, all variants can handle this */ |
| 1612 | break; |
| 1613 | case SSP_TX_16_OR_MORE_EMPTY_LOC: |
| 1614 | if (pl022->vendor->fifodepth < 16) { |
| 1615 | dev_err(&pl022->adev->dev, |
| 1616 | "TX FIFO Trigger Level is configured incorrectly\n"); |
| 1617 | return -EINVAL; |
| 1618 | } |
| 1619 | break; |
| 1620 | case SSP_TX_32_OR_MORE_EMPTY_LOC: |
| 1621 | if (pl022->vendor->fifodepth < 32) { |
| 1622 | dev_err(&pl022->adev->dev, |
| 1623 | "TX FIFO Trigger Level is configured incorrectly\n"); |
| 1624 | return -EINVAL; |
| 1625 | } |
| 1626 | break; |
| 1627 | default: |
Linus Walleij | 5a1c98b | 2010-10-01 11:47:32 +0200 | [diff] [blame] | 1628 | dev_err(&pl022->adev->dev, |
Linus Walleij | b43d65f | 2009-06-09 08:11:42 +0100 | [diff] [blame] | 1629 | "TX FIFO Trigger Level is configured incorrectly\n"); |
| 1630 | return -EINVAL; |
Linus Walleij | 78b2b91 | 2011-06-16 10:14:46 +0200 | [diff] [blame] | 1631 | break; |
Linus Walleij | b43d65f | 2009-06-09 08:11:42 +0100 | [diff] [blame] | 1632 | } |
Linus Walleij | b43d65f | 2009-06-09 08:11:42 +0100 | [diff] [blame] | 1633 | if (chip_info->iface == SSP_INTERFACE_NATIONAL_MICROWIRE) { |
| 1634 | if ((chip_info->ctrl_len < SSP_BITS_4) |
| 1635 | || (chip_info->ctrl_len > SSP_BITS_32)) { |
Linus Walleij | 5a1c98b | 2010-10-01 11:47:32 +0200 | [diff] [blame] | 1636 | dev_err(&pl022->adev->dev, |
Linus Walleij | b43d65f | 2009-06-09 08:11:42 +0100 | [diff] [blame] | 1637 | "CTRL LEN is configured incorrectly\n"); |
| 1638 | return -EINVAL; |
| 1639 | } |
| 1640 | if ((chip_info->wait_state != SSP_MWIRE_WAIT_ZERO) |
| 1641 | && (chip_info->wait_state != SSP_MWIRE_WAIT_ONE)) { |
Linus Walleij | 5a1c98b | 2010-10-01 11:47:32 +0200 | [diff] [blame] | 1642 | dev_err(&pl022->adev->dev, |
Linus Walleij | b43d65f | 2009-06-09 08:11:42 +0100 | [diff] [blame] | 1643 | "Wait State is configured incorrectly\n"); |
| 1644 | return -EINVAL; |
| 1645 | } |
Linus Walleij | 556f4ae | 2010-05-05 09:28:15 +0000 | [diff] [blame] | 1646 | /* Half duplex is only available in the ST Micro version */ |
| 1647 | if (pl022->vendor->extended_cr) { |
| 1648 | if ((chip_info->duplex != |
| 1649 | SSP_MICROWIRE_CHANNEL_FULL_DUPLEX) |
| 1650 | && (chip_info->duplex != |
Julia Lawall | 4a4fd47 | 2010-09-29 17:31:30 +0900 | [diff] [blame] | 1651 | SSP_MICROWIRE_CHANNEL_HALF_DUPLEX)) { |
Linus Walleij | 5a1c98b | 2010-10-01 11:47:32 +0200 | [diff] [blame] | 1652 | dev_err(&pl022->adev->dev, |
Linus Walleij | 556f4ae | 2010-05-05 09:28:15 +0000 | [diff] [blame] | 1653 | "Microwire duplex mode is configured incorrectly\n"); |
| 1654 | return -EINVAL; |
Julia Lawall | 4a4fd47 | 2010-09-29 17:31:30 +0900 | [diff] [blame] | 1655 | } |
Linus Walleij | 556f4ae | 2010-05-05 09:28:15 +0000 | [diff] [blame] | 1656 | } else { |
| 1657 | if (chip_info->duplex != SSP_MICROWIRE_CHANNEL_FULL_DUPLEX) |
Linus Walleij | 5a1c98b | 2010-10-01 11:47:32 +0200 | [diff] [blame] | 1658 | dev_err(&pl022->adev->dev, |
Linus Walleij | 556f4ae | 2010-05-05 09:28:15 +0000 | [diff] [blame] | 1659 | "Microwire half duplex mode requested," |
| 1660 | " but this is only available in the" |
| 1661 | " ST version of PL022\n"); |
Linus Walleij | b43d65f | 2009-06-09 08:11:42 +0100 | [diff] [blame] | 1662 | return -EINVAL; |
| 1663 | } |
| 1664 | } |
Linus Walleij | b43d65f | 2009-06-09 08:11:42 +0100 | [diff] [blame] | 1665 | return 0; |
| 1666 | } |
| 1667 | |
Viresh Kumar | 0379b2a | 2011-08-10 14:20:57 +0530 | [diff] [blame] | 1668 | static inline u32 spi_rate(u32 rate, u16 cpsdvsr, u16 scr) |
| 1669 | { |
| 1670 | return rate / (cpsdvsr * (1 + scr)); |
| 1671 | } |
| 1672 | |
| 1673 | static int calculate_effective_freq(struct pl022 *pl022, int freq, struct |
| 1674 | ssp_clock_params * clk_freq) |
Linus Walleij | b43d65f | 2009-06-09 08:11:42 +0100 | [diff] [blame] | 1675 | { |
| 1676 | /* Lets calculate the frequency parameters */ |
Viresh Kumar | 0379b2a | 2011-08-10 14:20:57 +0530 | [diff] [blame] | 1677 | u16 cpsdvsr = CPSDVR_MIN, scr = SCR_MIN; |
| 1678 | u32 rate, max_tclk, min_tclk, best_freq = 0, best_cpsdvsr = 0, |
| 1679 | best_scr = 0, tmp, found = 0; |
Linus Walleij | b43d65f | 2009-06-09 08:11:42 +0100 | [diff] [blame] | 1680 | |
| 1681 | rate = clk_get_rate(pl022->clk); |
| 1682 | /* cpsdvscr = 2 & scr 0 */ |
Viresh Kumar | 0379b2a | 2011-08-10 14:20:57 +0530 | [diff] [blame] | 1683 | max_tclk = spi_rate(rate, CPSDVR_MIN, SCR_MIN); |
Linus Walleij | b43d65f | 2009-06-09 08:11:42 +0100 | [diff] [blame] | 1684 | /* cpsdvsr = 254 & scr = 255 */ |
Viresh Kumar | 0379b2a | 2011-08-10 14:20:57 +0530 | [diff] [blame] | 1685 | min_tclk = spi_rate(rate, CPSDVR_MAX, SCR_MAX); |
Linus Walleij | b43d65f | 2009-06-09 08:11:42 +0100 | [diff] [blame] | 1686 | |
Viresh Kumar | ea505bc | 2012-04-19 11:48:15 +0530 | [diff] [blame] | 1687 | if (freq > max_tclk) |
| 1688 | dev_warn(&pl022->adev->dev, |
| 1689 | "Max speed that can be programmed is %d Hz, you requested %d\n", |
| 1690 | max_tclk, freq); |
| 1691 | |
| 1692 | if (freq < min_tclk) { |
Linus Walleij | b43d65f | 2009-06-09 08:11:42 +0100 | [diff] [blame] | 1693 | dev_err(&pl022->adev->dev, |
Viresh Kumar | ea505bc | 2012-04-19 11:48:15 +0530 | [diff] [blame] | 1694 | "Requested frequency: %d Hz is less than minimum possible %d Hz\n", |
| 1695 | freq, min_tclk); |
Linus Walleij | b43d65f | 2009-06-09 08:11:42 +0100 | [diff] [blame] | 1696 | return -EINVAL; |
| 1697 | } |
Viresh Kumar | 0379b2a | 2011-08-10 14:20:57 +0530 | [diff] [blame] | 1698 | |
| 1699 | /* |
| 1700 | * best_freq will give closest possible available rate (<= requested |
| 1701 | * freq) for all values of scr & cpsdvsr. |
| 1702 | */ |
| 1703 | while ((cpsdvsr <= CPSDVR_MAX) && !found) { |
| 1704 | while (scr <= SCR_MAX) { |
| 1705 | tmp = spi_rate(rate, cpsdvsr, scr); |
| 1706 | |
Viresh Kumar | 5eb806a | 2012-04-19 14:44:21 +0530 | [diff] [blame] | 1707 | if (tmp > freq) { |
| 1708 | /* we need lower freq */ |
Viresh Kumar | 0379b2a | 2011-08-10 14:20:57 +0530 | [diff] [blame] | 1709 | scr++; |
Viresh Kumar | 5eb806a | 2012-04-19 14:44:21 +0530 | [diff] [blame] | 1710 | continue; |
| 1711 | } |
| 1712 | |
Viresh Kumar | 0379b2a | 2011-08-10 14:20:57 +0530 | [diff] [blame] | 1713 | /* |
Viresh Kumar | 5eb806a | 2012-04-19 14:44:21 +0530 | [diff] [blame] | 1714 | * If found exact value, mark found and break. |
| 1715 | * If found more closer value, update and break. |
Viresh Kumar | 0379b2a | 2011-08-10 14:20:57 +0530 | [diff] [blame] | 1716 | */ |
Viresh Kumar | 5eb806a | 2012-04-19 14:44:21 +0530 | [diff] [blame] | 1717 | if (tmp > best_freq) { |
Viresh Kumar | 0379b2a | 2011-08-10 14:20:57 +0530 | [diff] [blame] | 1718 | best_freq = tmp; |
| 1719 | best_cpsdvsr = cpsdvsr; |
| 1720 | best_scr = scr; |
| 1721 | |
| 1722 | if (tmp == freq) |
Viresh Kumar | 5eb806a | 2012-04-19 14:44:21 +0530 | [diff] [blame] | 1723 | found = 1; |
Viresh Kumar | 0379b2a | 2011-08-10 14:20:57 +0530 | [diff] [blame] | 1724 | } |
Viresh Kumar | 5eb806a | 2012-04-19 14:44:21 +0530 | [diff] [blame] | 1725 | /* |
| 1726 | * increased scr will give lower rates, which are not |
| 1727 | * required |
| 1728 | */ |
| 1729 | break; |
Viresh Kumar | 0379b2a | 2011-08-10 14:20:57 +0530 | [diff] [blame] | 1730 | } |
| 1731 | cpsdvsr += 2; |
| 1732 | scr = SCR_MIN; |
| 1733 | } |
| 1734 | |
Viresh Kumar | 5eb806a | 2012-04-19 14:44:21 +0530 | [diff] [blame] | 1735 | WARN(!best_freq, "pl022: Matching cpsdvsr and scr not found for %d Hz rate \n", |
| 1736 | freq); |
| 1737 | |
Viresh Kumar | 0379b2a | 2011-08-10 14:20:57 +0530 | [diff] [blame] | 1738 | clk_freq->cpsdvsr = (u8) (best_cpsdvsr & 0xFF); |
| 1739 | clk_freq->scr = (u8) (best_scr & 0xFF); |
| 1740 | dev_dbg(&pl022->adev->dev, |
| 1741 | "SSP Target Frequency is: %u, Effective Frequency is %u\n", |
| 1742 | freq, best_freq); |
| 1743 | dev_dbg(&pl022->adev->dev, "SSP cpsdvsr = %d, scr = %d\n", |
| 1744 | clk_freq->cpsdvsr, clk_freq->scr); |
| 1745 | |
Linus Walleij | b43d65f | 2009-06-09 08:11:42 +0100 | [diff] [blame] | 1746 | return 0; |
| 1747 | } |
| 1748 | |
Linus Walleij | f9d629c | 2010-10-01 13:33:13 +0200 | [diff] [blame] | 1749 | /* |
| 1750 | * A piece of default chip info unless the platform |
| 1751 | * supplies it. |
| 1752 | */ |
| 1753 | static const struct pl022_config_chip pl022_default_chip_info = { |
| 1754 | .com_mode = POLLING_TRANSFER, |
| 1755 | .iface = SSP_INTERFACE_MOTOROLA_SPI, |
| 1756 | .hierarchy = SSP_SLAVE, |
| 1757 | .slave_tx_disable = DO_NOT_DRIVE_TX, |
| 1758 | .rx_lev_trig = SSP_RX_1_OR_MORE_ELEM, |
| 1759 | .tx_lev_trig = SSP_TX_1_OR_MORE_EMPTY_LOC, |
| 1760 | .ctrl_len = SSP_BITS_8, |
| 1761 | .wait_state = SSP_MWIRE_WAIT_ZERO, |
| 1762 | .duplex = SSP_MICROWIRE_CHANNEL_FULL_DUPLEX, |
| 1763 | .cs_control = null_cs_control, |
| 1764 | }; |
| 1765 | |
Linus Walleij | b43d65f | 2009-06-09 08:11:42 +0100 | [diff] [blame] | 1766 | /** |
Linus Walleij | b43d65f | 2009-06-09 08:11:42 +0100 | [diff] [blame] | 1767 | * pl022_setup - setup function registered to SPI master framework |
| 1768 | * @spi: spi device which is requesting setup |
| 1769 | * |
| 1770 | * This function is registered to the SPI framework for this SPI master |
| 1771 | * controller. If it is the first time when setup is called by this device, |
| 1772 | * this function will initialize the runtime state for this chip and save |
| 1773 | * the same in the device structure. Else it will update the runtime info |
| 1774 | * with the updated chip info. Nothing is really being written to the |
| 1775 | * controller hardware here, that is not done until the actual transfer |
| 1776 | * commence. |
| 1777 | */ |
Linus Walleij | b43d65f | 2009-06-09 08:11:42 +0100 | [diff] [blame] | 1778 | static int pl022_setup(struct spi_device *spi) |
| 1779 | { |
Linus Walleij | f9d629c | 2010-10-01 13:33:13 +0200 | [diff] [blame] | 1780 | struct pl022_config_chip const *chip_info; |
Linus Walleij | b43d65f | 2009-06-09 08:11:42 +0100 | [diff] [blame] | 1781 | struct chip_data *chip; |
Jonas Aaberg | c4a4784 | 2011-02-28 16:42:41 +0100 | [diff] [blame] | 1782 | struct ssp_clock_params clk_freq = { .cpsdvsr = 0, .scr = 0}; |
Linus Walleij | b43d65f | 2009-06-09 08:11:42 +0100 | [diff] [blame] | 1783 | int status = 0; |
| 1784 | struct pl022 *pl022 = spi_master_get_devdata(spi->master); |
Kevin Wells | bde435a | 2010-09-16 06:18:50 -0700 | [diff] [blame] | 1785 | unsigned int bits = spi->bits_per_word; |
| 1786 | u32 tmp; |
Linus Walleij | b43d65f | 2009-06-09 08:11:42 +0100 | [diff] [blame] | 1787 | |
| 1788 | if (!spi->max_speed_hz) |
| 1789 | return -EINVAL; |
| 1790 | |
| 1791 | /* Get controller_state if one is supplied */ |
| 1792 | chip = spi_get_ctldata(spi); |
| 1793 | |
| 1794 | if (chip == NULL) { |
| 1795 | chip = kzalloc(sizeof(struct chip_data), GFP_KERNEL); |
| 1796 | if (!chip) { |
| 1797 | dev_err(&spi->dev, |
| 1798 | "cannot allocate controller state\n"); |
| 1799 | return -ENOMEM; |
| 1800 | } |
| 1801 | dev_dbg(&spi->dev, |
| 1802 | "allocated memory for controller's runtime state\n"); |
| 1803 | } |
| 1804 | |
| 1805 | /* Get controller data if one is supplied */ |
| 1806 | chip_info = spi->controller_data; |
| 1807 | |
| 1808 | if (chip_info == NULL) { |
Linus Walleij | f9d629c | 2010-10-01 13:33:13 +0200 | [diff] [blame] | 1809 | chip_info = &pl022_default_chip_info; |
Linus Walleij | b43d65f | 2009-06-09 08:11:42 +0100 | [diff] [blame] | 1810 | /* spi_board_info.controller_data not is supplied */ |
| 1811 | dev_dbg(&spi->dev, |
| 1812 | "using default controller_data settings\n"); |
Linus Walleij | f9d629c | 2010-10-01 13:33:13 +0200 | [diff] [blame] | 1813 | } else |
Linus Walleij | b43d65f | 2009-06-09 08:11:42 +0100 | [diff] [blame] | 1814 | dev_dbg(&spi->dev, |
| 1815 | "using user supplied controller_data settings\n"); |
Linus Walleij | b43d65f | 2009-06-09 08:11:42 +0100 | [diff] [blame] | 1816 | |
| 1817 | /* |
| 1818 | * We can override with custom divisors, else we use the board |
| 1819 | * frequency setting |
| 1820 | */ |
| 1821 | if ((0 == chip_info->clk_freq.cpsdvsr) |
| 1822 | && (0 == chip_info->clk_freq.scr)) { |
| 1823 | status = calculate_effective_freq(pl022, |
| 1824 | spi->max_speed_hz, |
Linus Walleij | f9d629c | 2010-10-01 13:33:13 +0200 | [diff] [blame] | 1825 | &clk_freq); |
Linus Walleij | b43d65f | 2009-06-09 08:11:42 +0100 | [diff] [blame] | 1826 | if (status < 0) |
| 1827 | goto err_config_params; |
| 1828 | } else { |
Linus Walleij | f9d629c | 2010-10-01 13:33:13 +0200 | [diff] [blame] | 1829 | memcpy(&clk_freq, &chip_info->clk_freq, sizeof(clk_freq)); |
| 1830 | if ((clk_freq.cpsdvsr % 2) != 0) |
| 1831 | clk_freq.cpsdvsr = |
| 1832 | clk_freq.cpsdvsr - 1; |
Linus Walleij | b43d65f | 2009-06-09 08:11:42 +0100 | [diff] [blame] | 1833 | } |
Linus Walleij | f9d629c | 2010-10-01 13:33:13 +0200 | [diff] [blame] | 1834 | if ((clk_freq.cpsdvsr < CPSDVR_MIN) |
| 1835 | || (clk_freq.cpsdvsr > CPSDVR_MAX)) { |
Virupax Sadashivpetimath | e3f88ae | 2011-06-13 16:23:46 +0530 | [diff] [blame] | 1836 | status = -EINVAL; |
Linus Walleij | f9d629c | 2010-10-01 13:33:13 +0200 | [diff] [blame] | 1837 | dev_err(&spi->dev, |
| 1838 | "cpsdvsr is configured incorrectly\n"); |
| 1839 | goto err_config_params; |
| 1840 | } |
| 1841 | |
Linus Walleij | b43d65f | 2009-06-09 08:11:42 +0100 | [diff] [blame] | 1842 | status = verify_controller_parameters(pl022, chip_info); |
| 1843 | if (status) { |
| 1844 | dev_err(&spi->dev, "controller data is incorrect"); |
| 1845 | goto err_config_params; |
| 1846 | } |
Linus Walleij | f9d629c | 2010-10-01 13:33:13 +0200 | [diff] [blame] | 1847 | |
Linus Walleij | 083be3f | 2011-06-16 10:14:28 +0200 | [diff] [blame] | 1848 | pl022->rx_lev_trig = chip_info->rx_lev_trig; |
| 1849 | pl022->tx_lev_trig = chip_info->tx_lev_trig; |
| 1850 | |
Linus Walleij | b43d65f | 2009-06-09 08:11:42 +0100 | [diff] [blame] | 1851 | /* Now set controller state based on controller data */ |
| 1852 | chip->xfer_type = chip_info->com_mode; |
Linus Walleij | f9d629c | 2010-10-01 13:33:13 +0200 | [diff] [blame] | 1853 | if (!chip_info->cs_control) { |
| 1854 | chip->cs_control = null_cs_control; |
Roland Stigge | f6f46de | 2012-08-22 15:49:17 +0200 | [diff] [blame^] | 1855 | if (!gpio_is_valid(pl022->chipselects[spi->chip_select])) |
| 1856 | dev_warn(&spi->dev, |
| 1857 | "invalid chip select\n"); |
Linus Walleij | f9d629c | 2010-10-01 13:33:13 +0200 | [diff] [blame] | 1858 | } else |
| 1859 | chip->cs_control = chip_info->cs_control; |
Linus Walleij | b43d65f | 2009-06-09 08:11:42 +0100 | [diff] [blame] | 1860 | |
Vinit Shenoy | eb798c6 | 2012-04-17 12:40:13 +0530 | [diff] [blame] | 1861 | /* Check bits per word with vendor specific range */ |
| 1862 | if ((bits <= 3) || (bits > pl022->vendor->max_bpw)) { |
Kevin Wells | bde435a | 2010-09-16 06:18:50 -0700 | [diff] [blame] | 1863 | status = -ENOTSUPP; |
Vinit Shenoy | eb798c6 | 2012-04-17 12:40:13 +0530 | [diff] [blame] | 1864 | dev_err(&spi->dev, "illegal data size for this controller!\n"); |
| 1865 | dev_err(&spi->dev, "This controller can only handle 4 <= n <= %d bit words\n", |
| 1866 | pl022->vendor->max_bpw); |
Kevin Wells | bde435a | 2010-09-16 06:18:50 -0700 | [diff] [blame] | 1867 | goto err_config_params; |
| 1868 | } else if (bits <= 8) { |
| 1869 | dev_dbg(&spi->dev, "4 <= n <=8 bits per word\n"); |
Linus Walleij | b43d65f | 2009-06-09 08:11:42 +0100 | [diff] [blame] | 1870 | chip->n_bytes = 1; |
| 1871 | chip->read = READING_U8; |
| 1872 | chip->write = WRITING_U8; |
Kevin Wells | bde435a | 2010-09-16 06:18:50 -0700 | [diff] [blame] | 1873 | } else if (bits <= 16) { |
Linus Walleij | b43d65f | 2009-06-09 08:11:42 +0100 | [diff] [blame] | 1874 | dev_dbg(&spi->dev, "9 <= n <= 16 bits per word\n"); |
| 1875 | chip->n_bytes = 2; |
| 1876 | chip->read = READING_U16; |
| 1877 | chip->write = WRITING_U16; |
| 1878 | } else { |
Vinit Shenoy | eb798c6 | 2012-04-17 12:40:13 +0530 | [diff] [blame] | 1879 | dev_dbg(&spi->dev, "17 <= n <= 32 bits per word\n"); |
| 1880 | chip->n_bytes = 4; |
| 1881 | chip->read = READING_U32; |
| 1882 | chip->write = WRITING_U32; |
Linus Walleij | b43d65f | 2009-06-09 08:11:42 +0100 | [diff] [blame] | 1883 | } |
| 1884 | |
| 1885 | /* Now Initialize all register settings required for this chip */ |
| 1886 | chip->cr0 = 0; |
| 1887 | chip->cr1 = 0; |
| 1888 | chip->dmacr = 0; |
| 1889 | chip->cpsr = 0; |
| 1890 | if ((chip_info->com_mode == DMA_TRANSFER) |
| 1891 | && ((pl022->master_info)->enable_dma)) { |
Linus Walleij | b1b6b9a | 2010-09-29 17:31:35 +0900 | [diff] [blame] | 1892 | chip->enable_dma = true; |
Linus Walleij | b43d65f | 2009-06-09 08:11:42 +0100 | [diff] [blame] | 1893 | dev_dbg(&spi->dev, "DMA mode set in controller state\n"); |
Linus Walleij | b43d65f | 2009-06-09 08:11:42 +0100 | [diff] [blame] | 1894 | SSP_WRITE_BITS(chip->dmacr, SSP_DMA_ENABLED, |
| 1895 | SSP_DMACR_MASK_RXDMAE, 0); |
| 1896 | SSP_WRITE_BITS(chip->dmacr, SSP_DMA_ENABLED, |
| 1897 | SSP_DMACR_MASK_TXDMAE, 1); |
| 1898 | } else { |
Linus Walleij | b1b6b9a | 2010-09-29 17:31:35 +0900 | [diff] [blame] | 1899 | chip->enable_dma = false; |
Linus Walleij | b43d65f | 2009-06-09 08:11:42 +0100 | [diff] [blame] | 1900 | dev_dbg(&spi->dev, "DMA mode NOT set in controller state\n"); |
| 1901 | SSP_WRITE_BITS(chip->dmacr, SSP_DMA_DISABLED, |
| 1902 | SSP_DMACR_MASK_RXDMAE, 0); |
| 1903 | SSP_WRITE_BITS(chip->dmacr, SSP_DMA_DISABLED, |
| 1904 | SSP_DMACR_MASK_TXDMAE, 1); |
| 1905 | } |
| 1906 | |
Linus Walleij | f9d629c | 2010-10-01 13:33:13 +0200 | [diff] [blame] | 1907 | chip->cpsr = clk_freq.cpsdvsr; |
Linus Walleij | b43d65f | 2009-06-09 08:11:42 +0100 | [diff] [blame] | 1908 | |
Linus Walleij | 556f4ae | 2010-05-05 09:28:15 +0000 | [diff] [blame] | 1909 | /* Special setup for the ST micro extended control registers */ |
| 1910 | if (pl022->vendor->extended_cr) { |
Kevin Wells | bde435a | 2010-09-16 06:18:50 -0700 | [diff] [blame] | 1911 | u32 etx; |
| 1912 | |
Linus Walleij | 781c7b1 | 2010-05-07 08:40:53 +0000 | [diff] [blame] | 1913 | if (pl022->vendor->pl023) { |
| 1914 | /* These bits are only in the PL023 */ |
| 1915 | SSP_WRITE_BITS(chip->cr1, chip_info->clkdelay, |
| 1916 | SSP_CR1_MASK_FBCLKDEL_ST, 13); |
| 1917 | } else { |
| 1918 | /* These bits are in the PL022 but not PL023 */ |
| 1919 | SSP_WRITE_BITS(chip->cr0, chip_info->duplex, |
| 1920 | SSP_CR0_MASK_HALFDUP_ST, 5); |
| 1921 | SSP_WRITE_BITS(chip->cr0, chip_info->ctrl_len, |
| 1922 | SSP_CR0_MASK_CSS_ST, 16); |
| 1923 | SSP_WRITE_BITS(chip->cr0, chip_info->iface, |
| 1924 | SSP_CR0_MASK_FRF_ST, 21); |
| 1925 | SSP_WRITE_BITS(chip->cr1, chip_info->wait_state, |
| 1926 | SSP_CR1_MASK_MWAIT_ST, 6); |
| 1927 | } |
Kevin Wells | bde435a | 2010-09-16 06:18:50 -0700 | [diff] [blame] | 1928 | SSP_WRITE_BITS(chip->cr0, bits - 1, |
Linus Walleij | 556f4ae | 2010-05-05 09:28:15 +0000 | [diff] [blame] | 1929 | SSP_CR0_MASK_DSS_ST, 0); |
Kevin Wells | bde435a | 2010-09-16 06:18:50 -0700 | [diff] [blame] | 1930 | |
| 1931 | if (spi->mode & SPI_LSB_FIRST) { |
| 1932 | tmp = SSP_RX_LSB; |
| 1933 | etx = SSP_TX_LSB; |
| 1934 | } else { |
| 1935 | tmp = SSP_RX_MSB; |
| 1936 | etx = SSP_TX_MSB; |
| 1937 | } |
| 1938 | SSP_WRITE_BITS(chip->cr1, tmp, SSP_CR1_MASK_RENDN_ST, 4); |
| 1939 | SSP_WRITE_BITS(chip->cr1, etx, SSP_CR1_MASK_TENDN_ST, 5); |
Linus Walleij | 556f4ae | 2010-05-05 09:28:15 +0000 | [diff] [blame] | 1940 | SSP_WRITE_BITS(chip->cr1, chip_info->rx_lev_trig, |
| 1941 | SSP_CR1_MASK_RXIFLSEL_ST, 7); |
| 1942 | SSP_WRITE_BITS(chip->cr1, chip_info->tx_lev_trig, |
| 1943 | SSP_CR1_MASK_TXIFLSEL_ST, 10); |
| 1944 | } else { |
Kevin Wells | bde435a | 2010-09-16 06:18:50 -0700 | [diff] [blame] | 1945 | SSP_WRITE_BITS(chip->cr0, bits - 1, |
Linus Walleij | 556f4ae | 2010-05-05 09:28:15 +0000 | [diff] [blame] | 1946 | SSP_CR0_MASK_DSS, 0); |
| 1947 | SSP_WRITE_BITS(chip->cr0, chip_info->iface, |
| 1948 | SSP_CR0_MASK_FRF, 4); |
| 1949 | } |
Kevin Wells | bde435a | 2010-09-16 06:18:50 -0700 | [diff] [blame] | 1950 | |
Linus Walleij | 556f4ae | 2010-05-05 09:28:15 +0000 | [diff] [blame] | 1951 | /* Stuff that is common for all versions */ |
Kevin Wells | bde435a | 2010-09-16 06:18:50 -0700 | [diff] [blame] | 1952 | if (spi->mode & SPI_CPOL) |
| 1953 | tmp = SSP_CLK_POL_IDLE_HIGH; |
| 1954 | else |
| 1955 | tmp = SSP_CLK_POL_IDLE_LOW; |
| 1956 | SSP_WRITE_BITS(chip->cr0, tmp, SSP_CR0_MASK_SPO, 6); |
| 1957 | |
| 1958 | if (spi->mode & SPI_CPHA) |
| 1959 | tmp = SSP_CLK_SECOND_EDGE; |
| 1960 | else |
| 1961 | tmp = SSP_CLK_FIRST_EDGE; |
| 1962 | SSP_WRITE_BITS(chip->cr0, tmp, SSP_CR0_MASK_SPH, 7); |
| 1963 | |
Linus Walleij | f9d629c | 2010-10-01 13:33:13 +0200 | [diff] [blame] | 1964 | SSP_WRITE_BITS(chip->cr0, clk_freq.scr, SSP_CR0_MASK_SCR, 8); |
Linus Walleij | 781c7b1 | 2010-05-07 08:40:53 +0000 | [diff] [blame] | 1965 | /* Loopback is available on all versions except PL023 */ |
Philippe Langlais | 06fb01f | 2011-03-23 11:05:16 +0100 | [diff] [blame] | 1966 | if (pl022->vendor->loopback) { |
Kevin Wells | bde435a | 2010-09-16 06:18:50 -0700 | [diff] [blame] | 1967 | if (spi->mode & SPI_LOOP) |
| 1968 | tmp = LOOPBACK_ENABLED; |
| 1969 | else |
| 1970 | tmp = LOOPBACK_DISABLED; |
| 1971 | SSP_WRITE_BITS(chip->cr1, tmp, SSP_CR1_MASK_LBM, 0); |
| 1972 | } |
Linus Walleij | b43d65f | 2009-06-09 08:11:42 +0100 | [diff] [blame] | 1973 | SSP_WRITE_BITS(chip->cr1, SSP_DISABLED, SSP_CR1_MASK_SSE, 1); |
| 1974 | SSP_WRITE_BITS(chip->cr1, chip_info->hierarchy, SSP_CR1_MASK_MS, 2); |
Viresh Kumar | f1e45f8 | 2011-08-10 14:20:54 +0530 | [diff] [blame] | 1975 | SSP_WRITE_BITS(chip->cr1, chip_info->slave_tx_disable, SSP_CR1_MASK_SOD, |
| 1976 | 3); |
Linus Walleij | b43d65f | 2009-06-09 08:11:42 +0100 | [diff] [blame] | 1977 | |
| 1978 | /* Save controller_state */ |
| 1979 | spi_set_ctldata(spi, chip); |
| 1980 | return status; |
| 1981 | err_config_params: |
Kevin Wells | bde435a | 2010-09-16 06:18:50 -0700 | [diff] [blame] | 1982 | spi_set_ctldata(spi, NULL); |
Linus Walleij | b43d65f | 2009-06-09 08:11:42 +0100 | [diff] [blame] | 1983 | kfree(chip); |
| 1984 | return status; |
| 1985 | } |
| 1986 | |
| 1987 | /** |
| 1988 | * pl022_cleanup - cleanup function registered to SPI master framework |
| 1989 | * @spi: spi device which is requesting cleanup |
| 1990 | * |
| 1991 | * This function is registered to the SPI framework for this SPI master |
| 1992 | * controller. It will free the runtime state of chip. |
| 1993 | */ |
| 1994 | static void pl022_cleanup(struct spi_device *spi) |
| 1995 | { |
| 1996 | struct chip_data *chip = spi_get_ctldata(spi); |
| 1997 | |
| 1998 | spi_set_ctldata(spi, NULL); |
| 1999 | kfree(chip); |
| 2000 | } |
| 2001 | |
Kevin Wells | b422588 | 2010-07-27 16:39:30 +0000 | [diff] [blame] | 2002 | static int __devinit |
Russell King | aa25afa | 2011-02-19 15:55:00 +0000 | [diff] [blame] | 2003 | pl022_probe(struct amba_device *adev, const struct amba_id *id) |
Linus Walleij | b43d65f | 2009-06-09 08:11:42 +0100 | [diff] [blame] | 2004 | { |
| 2005 | struct device *dev = &adev->dev; |
| 2006 | struct pl022_ssp_controller *platform_info = adev->dev.platform_data; |
| 2007 | struct spi_master *master; |
| 2008 | struct pl022 *pl022 = NULL; /*Data for this driver */ |
Roland Stigge | f6f46de | 2012-08-22 15:49:17 +0200 | [diff] [blame^] | 2009 | int status = 0, i; |
Linus Walleij | b43d65f | 2009-06-09 08:11:42 +0100 | [diff] [blame] | 2010 | |
| 2011 | dev_info(&adev->dev, |
| 2012 | "ARM PL022 driver, device ID: 0x%08x\n", adev->periphid); |
| 2013 | if (platform_info == NULL) { |
| 2014 | dev_err(&adev->dev, "probe - no platform data supplied\n"); |
| 2015 | status = -ENODEV; |
| 2016 | goto err_no_pdata; |
| 2017 | } |
| 2018 | |
| 2019 | /* Allocate master with space for data */ |
Roland Stigge | f6f46de | 2012-08-22 15:49:17 +0200 | [diff] [blame^] | 2020 | master = spi_alloc_master(dev, sizeof(struct pl022) + sizeof(int) * |
| 2021 | platform_info->num_chipselect); |
Linus Walleij | b43d65f | 2009-06-09 08:11:42 +0100 | [diff] [blame] | 2022 | if (master == NULL) { |
| 2023 | dev_err(&adev->dev, "probe - cannot alloc SPI master\n"); |
| 2024 | status = -ENOMEM; |
| 2025 | goto err_no_master; |
| 2026 | } |
| 2027 | |
| 2028 | pl022 = spi_master_get_devdata(master); |
| 2029 | pl022->master = master; |
| 2030 | pl022->master_info = platform_info; |
| 2031 | pl022->adev = adev; |
| 2032 | pl022->vendor = id->data; |
Roland Stigge | f6f46de | 2012-08-22 15:49:17 +0200 | [diff] [blame^] | 2033 | /* Point chipselects to allocated memory beyond the main struct */ |
| 2034 | pl022->chipselects = (int *) pl022 + sizeof(struct pl022); |
Linus Walleij | b43d65f | 2009-06-09 08:11:42 +0100 | [diff] [blame] | 2035 | |
| 2036 | /* |
| 2037 | * Bus Number Which has been Assigned to this SSP controller |
| 2038 | * on this board |
| 2039 | */ |
| 2040 | master->bus_num = platform_info->bus_id; |
| 2041 | master->num_chipselect = platform_info->num_chipselect; |
| 2042 | master->cleanup = pl022_cleanup; |
| 2043 | master->setup = pl022_setup; |
Linus Walleij | ffbbdd2 | 2012-02-22 10:05:38 +0100 | [diff] [blame] | 2044 | master->prepare_transfer_hardware = pl022_prepare_transfer_hardware; |
| 2045 | master->transfer_one_message = pl022_transfer_one_message; |
| 2046 | master->unprepare_transfer_hardware = pl022_unprepare_transfer_hardware; |
| 2047 | master->rt = platform_info->rt; |
Linus Walleij | b43d65f | 2009-06-09 08:11:42 +0100 | [diff] [blame] | 2048 | |
Roland Stigge | f6f46de | 2012-08-22 15:49:17 +0200 | [diff] [blame^] | 2049 | if (platform_info->num_chipselect && platform_info->chipselects) |
| 2050 | for (i = 0; i < platform_info->num_chipselect; i++) |
| 2051 | pl022->chipselects[i] = platform_info->chipselects[i]; |
| 2052 | |
Kevin Wells | bde435a | 2010-09-16 06:18:50 -0700 | [diff] [blame] | 2053 | /* |
| 2054 | * Supports mode 0-3, loopback, and active low CS. Transfers are |
| 2055 | * always MS bit first on the original pl022. |
| 2056 | */ |
| 2057 | master->mode_bits = SPI_CPOL | SPI_CPHA | SPI_CS_HIGH | SPI_LOOP; |
| 2058 | if (pl022->vendor->extended_cr) |
| 2059 | master->mode_bits |= SPI_LSB_FIRST; |
| 2060 | |
Linus Walleij | b43d65f | 2009-06-09 08:11:42 +0100 | [diff] [blame] | 2061 | dev_dbg(&adev->dev, "BUSNO: %d\n", master->bus_num); |
| 2062 | |
| 2063 | status = amba_request_regions(adev, NULL); |
| 2064 | if (status) |
| 2065 | goto err_no_ioregion; |
| 2066 | |
Linus Walleij | b1b6b9a | 2010-09-29 17:31:35 +0900 | [diff] [blame] | 2067 | pl022->phybase = adev->res.start; |
Linus Walleij | b43d65f | 2009-06-09 08:11:42 +0100 | [diff] [blame] | 2068 | pl022->virtbase = ioremap(adev->res.start, resource_size(&adev->res)); |
| 2069 | if (pl022->virtbase == NULL) { |
| 2070 | status = -ENOMEM; |
| 2071 | goto err_no_ioremap; |
| 2072 | } |
| 2073 | printk(KERN_INFO "pl022: mapped registers from 0x%08x to %p\n", |
| 2074 | adev->res.start, pl022->virtbase); |
| 2075 | |
Linus Walleij | 2fb30d1 | 2012-06-12 16:14:51 +0200 | [diff] [blame] | 2076 | pm_runtime_enable(dev); |
| 2077 | pm_runtime_resume(dev); |
| 2078 | |
Linus Walleij | b43d65f | 2009-06-09 08:11:42 +0100 | [diff] [blame] | 2079 | pl022->clk = clk_get(&adev->dev, NULL); |
| 2080 | if (IS_ERR(pl022->clk)) { |
| 2081 | status = PTR_ERR(pl022->clk); |
| 2082 | dev_err(&adev->dev, "could not retrieve SSP/SPI bus clock\n"); |
| 2083 | goto err_no_clk; |
| 2084 | } |
Russell King | 7ff6bcf | 2011-09-22 14:27:11 +0100 | [diff] [blame] | 2085 | |
| 2086 | status = clk_prepare(pl022->clk); |
| 2087 | if (status) { |
| 2088 | dev_err(&adev->dev, "could not prepare SSP/SPI bus clock\n"); |
| 2089 | goto err_clk_prep; |
| 2090 | } |
| 2091 | |
Ulf Hansson | 71e63e7 | 2011-11-04 08:10:09 +0100 | [diff] [blame] | 2092 | status = clk_enable(pl022->clk); |
| 2093 | if (status) { |
| 2094 | dev_err(&adev->dev, "could not enable SSP/SPI bus clock\n"); |
| 2095 | goto err_no_clk_en; |
| 2096 | } |
| 2097 | |
Linus Walleij | ffbbdd2 | 2012-02-22 10:05:38 +0100 | [diff] [blame] | 2098 | /* Initialize transfer pump */ |
| 2099 | tasklet_init(&pl022->pump_transfers, pump_transfers, |
| 2100 | (unsigned long)pl022); |
| 2101 | |
Linus Walleij | b43d65f | 2009-06-09 08:11:42 +0100 | [diff] [blame] | 2102 | /* Disable SSP */ |
Linus Walleij | b43d65f | 2009-06-09 08:11:42 +0100 | [diff] [blame] | 2103 | writew((readw(SSP_CR1(pl022->virtbase)) & (~SSP_CR1_MASK_SSE)), |
| 2104 | SSP_CR1(pl022->virtbase)); |
| 2105 | load_ssp_default_config(pl022); |
Linus Walleij | b43d65f | 2009-06-09 08:11:42 +0100 | [diff] [blame] | 2106 | |
| 2107 | status = request_irq(adev->irq[0], pl022_interrupt_handler, 0, "pl022", |
| 2108 | pl022); |
| 2109 | if (status < 0) { |
| 2110 | dev_err(&adev->dev, "probe - cannot get IRQ (%d)\n", status); |
| 2111 | goto err_no_irq; |
| 2112 | } |
Linus Walleij | b1b6b9a | 2010-09-29 17:31:35 +0900 | [diff] [blame] | 2113 | |
| 2114 | /* Get DMA channels */ |
| 2115 | if (platform_info->enable_dma) { |
| 2116 | status = pl022_dma_probe(pl022); |
| 2117 | if (status != 0) |
Viresh Kumar | 43c6401 | 2011-05-16 09:40:10 +0530 | [diff] [blame] | 2118 | platform_info->enable_dma = 0; |
Linus Walleij | b1b6b9a | 2010-09-29 17:31:35 +0900 | [diff] [blame] | 2119 | } |
| 2120 | |
Linus Walleij | b43d65f | 2009-06-09 08:11:42 +0100 | [diff] [blame] | 2121 | /* Register with the SPI framework */ |
| 2122 | amba_set_drvdata(adev, pl022); |
| 2123 | status = spi_register_master(master); |
| 2124 | if (status != 0) { |
| 2125 | dev_err(&adev->dev, |
| 2126 | "probe - problem registering spi master\n"); |
| 2127 | goto err_spi_register; |
| 2128 | } |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 2129 | dev_dbg(dev, "probe succeeded\n"); |
Russell King | 92b97f0 | 2011-08-14 09:13:48 +0100 | [diff] [blame] | 2130 | |
| 2131 | /* let runtime pm put suspend */ |
Chris Blair | 53e4ace | 2011-11-08 08:54:46 +0000 | [diff] [blame] | 2132 | if (platform_info->autosuspend_delay > 0) { |
| 2133 | dev_info(&adev->dev, |
| 2134 | "will use autosuspend for runtime pm, delay %dms\n", |
| 2135 | platform_info->autosuspend_delay); |
| 2136 | pm_runtime_set_autosuspend_delay(dev, |
| 2137 | platform_info->autosuspend_delay); |
| 2138 | pm_runtime_use_autosuspend(dev); |
| 2139 | pm_runtime_put_autosuspend(dev); |
| 2140 | } else { |
| 2141 | pm_runtime_put(dev); |
| 2142 | } |
Linus Walleij | b43d65f | 2009-06-09 08:11:42 +0100 | [diff] [blame] | 2143 | return 0; |
| 2144 | |
| 2145 | err_spi_register: |
Viresh Kumar | 3e3ea71 | 2011-08-10 14:20:58 +0530 | [diff] [blame] | 2146 | if (platform_info->enable_dma) |
| 2147 | pl022_dma_remove(pl022); |
| 2148 | |
Linus Walleij | b43d65f | 2009-06-09 08:11:42 +0100 | [diff] [blame] | 2149 | free_irq(adev->irq[0], pl022); |
| 2150 | err_no_irq: |
Ulf Hansson | 71e63e7 | 2011-11-04 08:10:09 +0100 | [diff] [blame] | 2151 | clk_disable(pl022->clk); |
| 2152 | err_no_clk_en: |
Russell King | 7ff6bcf | 2011-09-22 14:27:11 +0100 | [diff] [blame] | 2153 | clk_unprepare(pl022->clk); |
| 2154 | err_clk_prep: |
Linus Walleij | b43d65f | 2009-06-09 08:11:42 +0100 | [diff] [blame] | 2155 | clk_put(pl022->clk); |
| 2156 | err_no_clk: |
| 2157 | iounmap(pl022->virtbase); |
| 2158 | err_no_ioremap: |
| 2159 | amba_release_regions(adev); |
| 2160 | err_no_ioregion: |
| 2161 | spi_master_put(master); |
| 2162 | err_no_master: |
| 2163 | err_no_pdata: |
| 2164 | return status; |
| 2165 | } |
| 2166 | |
Kevin Wells | b422588 | 2010-07-27 16:39:30 +0000 | [diff] [blame] | 2167 | static int __devexit |
Linus Walleij | b43d65f | 2009-06-09 08:11:42 +0100 | [diff] [blame] | 2168 | pl022_remove(struct amba_device *adev) |
| 2169 | { |
| 2170 | struct pl022 *pl022 = amba_get_drvdata(adev); |
Linus Walleij | 50658b6 | 2011-08-02 11:29:24 +0200 | [diff] [blame] | 2171 | |
Linus Walleij | b43d65f | 2009-06-09 08:11:42 +0100 | [diff] [blame] | 2172 | if (!pl022) |
| 2173 | return 0; |
| 2174 | |
Russell King | 92b97f0 | 2011-08-14 09:13:48 +0100 | [diff] [blame] | 2175 | /* |
| 2176 | * undo pm_runtime_put() in probe. I assume that we're not |
| 2177 | * accessing the primecell here. |
| 2178 | */ |
| 2179 | pm_runtime_get_noresume(&adev->dev); |
| 2180 | |
Linus Walleij | b43d65f | 2009-06-09 08:11:42 +0100 | [diff] [blame] | 2181 | load_ssp_default_config(pl022); |
Viresh Kumar | 3e3ea71 | 2011-08-10 14:20:58 +0530 | [diff] [blame] | 2182 | if (pl022->master_info->enable_dma) |
| 2183 | pl022_dma_remove(pl022); |
| 2184 | |
Linus Walleij | b43d65f | 2009-06-09 08:11:42 +0100 | [diff] [blame] | 2185 | free_irq(adev->irq[0], pl022); |
| 2186 | clk_disable(pl022->clk); |
Russell King | 7ff6bcf | 2011-09-22 14:27:11 +0100 | [diff] [blame] | 2187 | clk_unprepare(pl022->clk); |
Linus Walleij | b43d65f | 2009-06-09 08:11:42 +0100 | [diff] [blame] | 2188 | clk_put(pl022->clk); |
Linus Walleij | 2fb30d1 | 2012-06-12 16:14:51 +0200 | [diff] [blame] | 2189 | pm_runtime_disable(&adev->dev); |
Linus Walleij | b43d65f | 2009-06-09 08:11:42 +0100 | [diff] [blame] | 2190 | iounmap(pl022->virtbase); |
| 2191 | amba_release_regions(adev); |
| 2192 | tasklet_disable(&pl022->pump_transfers); |
| 2193 | spi_unregister_master(pl022->master); |
Linus Walleij | b43d65f | 2009-06-09 08:11:42 +0100 | [diff] [blame] | 2194 | amba_set_drvdata(adev, NULL); |
Linus Walleij | b43d65f | 2009-06-09 08:11:42 +0100 | [diff] [blame] | 2195 | return 0; |
| 2196 | } |
| 2197 | |
Russell King | 92b97f0 | 2011-08-14 09:13:48 +0100 | [diff] [blame] | 2198 | #ifdef CONFIG_SUSPEND |
Peter Hüwe | 6cfa627 | 2011-09-05 21:07:23 +0100 | [diff] [blame] | 2199 | static int pl022_suspend(struct device *dev) |
Linus Walleij | b43d65f | 2009-06-09 08:11:42 +0100 | [diff] [blame] | 2200 | { |
Russell King | 92b97f0 | 2011-08-14 09:13:48 +0100 | [diff] [blame] | 2201 | struct pl022 *pl022 = dev_get_drvdata(dev); |
Linus Walleij | ffbbdd2 | 2012-02-22 10:05:38 +0100 | [diff] [blame] | 2202 | int ret; |
Linus Walleij | b43d65f | 2009-06-09 08:11:42 +0100 | [diff] [blame] | 2203 | |
Linus Walleij | ffbbdd2 | 2012-02-22 10:05:38 +0100 | [diff] [blame] | 2204 | ret = spi_master_suspend(pl022->master); |
| 2205 | if (ret) { |
| 2206 | dev_warn(dev, "cannot suspend master\n"); |
| 2207 | return ret; |
Linus Walleij | b43d65f | 2009-06-09 08:11:42 +0100 | [diff] [blame] | 2208 | } |
| 2209 | |
Peter Hüwe | 6cfa627 | 2011-09-05 21:07:23 +0100 | [diff] [blame] | 2210 | dev_dbg(dev, "suspended\n"); |
Linus Walleij | b43d65f | 2009-06-09 08:11:42 +0100 | [diff] [blame] | 2211 | return 0; |
| 2212 | } |
| 2213 | |
Russell King | 92b97f0 | 2011-08-14 09:13:48 +0100 | [diff] [blame] | 2214 | static int pl022_resume(struct device *dev) |
Linus Walleij | b43d65f | 2009-06-09 08:11:42 +0100 | [diff] [blame] | 2215 | { |
Russell King | 92b97f0 | 2011-08-14 09:13:48 +0100 | [diff] [blame] | 2216 | struct pl022 *pl022 = dev_get_drvdata(dev); |
Linus Walleij | ffbbdd2 | 2012-02-22 10:05:38 +0100 | [diff] [blame] | 2217 | int ret; |
Linus Walleij | b43d65f | 2009-06-09 08:11:42 +0100 | [diff] [blame] | 2218 | |
| 2219 | /* Start the queue running */ |
Linus Walleij | ffbbdd2 | 2012-02-22 10:05:38 +0100 | [diff] [blame] | 2220 | ret = spi_master_resume(pl022->master); |
| 2221 | if (ret) |
| 2222 | dev_err(dev, "problem starting queue (%d)\n", ret); |
Linus Walleij | b43d65f | 2009-06-09 08:11:42 +0100 | [diff] [blame] | 2223 | else |
Russell King | 92b97f0 | 2011-08-14 09:13:48 +0100 | [diff] [blame] | 2224 | dev_dbg(dev, "resumed\n"); |
Linus Walleij | b43d65f | 2009-06-09 08:11:42 +0100 | [diff] [blame] | 2225 | |
Linus Walleij | ffbbdd2 | 2012-02-22 10:05:38 +0100 | [diff] [blame] | 2226 | return ret; |
Linus Walleij | b43d65f | 2009-06-09 08:11:42 +0100 | [diff] [blame] | 2227 | } |
Linus Walleij | b43d65f | 2009-06-09 08:11:42 +0100 | [diff] [blame] | 2228 | #endif /* CONFIG_PM */ |
| 2229 | |
Russell King | 92b97f0 | 2011-08-14 09:13:48 +0100 | [diff] [blame] | 2230 | #ifdef CONFIG_PM_RUNTIME |
| 2231 | static int pl022_runtime_suspend(struct device *dev) |
| 2232 | { |
| 2233 | struct pl022 *pl022 = dev_get_drvdata(dev); |
| 2234 | |
| 2235 | clk_disable(pl022->clk); |
Russell King | 92b97f0 | 2011-08-14 09:13:48 +0100 | [diff] [blame] | 2236 | |
| 2237 | return 0; |
| 2238 | } |
| 2239 | |
| 2240 | static int pl022_runtime_resume(struct device *dev) |
| 2241 | { |
| 2242 | struct pl022 *pl022 = dev_get_drvdata(dev); |
| 2243 | |
Russell King | 92b97f0 | 2011-08-14 09:13:48 +0100 | [diff] [blame] | 2244 | clk_enable(pl022->clk); |
| 2245 | |
| 2246 | return 0; |
| 2247 | } |
| 2248 | #endif |
| 2249 | |
| 2250 | static const struct dev_pm_ops pl022_dev_pm_ops = { |
| 2251 | SET_SYSTEM_SLEEP_PM_OPS(pl022_suspend, pl022_resume) |
| 2252 | SET_RUNTIME_PM_OPS(pl022_runtime_suspend, pl022_runtime_resume, NULL) |
| 2253 | }; |
| 2254 | |
Linus Walleij | b43d65f | 2009-06-09 08:11:42 +0100 | [diff] [blame] | 2255 | static struct vendor_data vendor_arm = { |
| 2256 | .fifodepth = 8, |
| 2257 | .max_bpw = 16, |
| 2258 | .unidir = false, |
Linus Walleij | 556f4ae | 2010-05-05 09:28:15 +0000 | [diff] [blame] | 2259 | .extended_cr = false, |
Linus Walleij | 781c7b1 | 2010-05-07 08:40:53 +0000 | [diff] [blame] | 2260 | .pl023 = false, |
Philippe Langlais | 06fb01f | 2011-03-23 11:05:16 +0100 | [diff] [blame] | 2261 | .loopback = true, |
Linus Walleij | b43d65f | 2009-06-09 08:11:42 +0100 | [diff] [blame] | 2262 | }; |
| 2263 | |
Linus Walleij | b43d65f | 2009-06-09 08:11:42 +0100 | [diff] [blame] | 2264 | static struct vendor_data vendor_st = { |
| 2265 | .fifodepth = 32, |
| 2266 | .max_bpw = 32, |
| 2267 | .unidir = false, |
Linus Walleij | 556f4ae | 2010-05-05 09:28:15 +0000 | [diff] [blame] | 2268 | .extended_cr = true, |
Linus Walleij | 781c7b1 | 2010-05-07 08:40:53 +0000 | [diff] [blame] | 2269 | .pl023 = false, |
Philippe Langlais | 06fb01f | 2011-03-23 11:05:16 +0100 | [diff] [blame] | 2270 | .loopback = true, |
Linus Walleij | 781c7b1 | 2010-05-07 08:40:53 +0000 | [diff] [blame] | 2271 | }; |
| 2272 | |
| 2273 | static struct vendor_data vendor_st_pl023 = { |
| 2274 | .fifodepth = 32, |
| 2275 | .max_bpw = 32, |
| 2276 | .unidir = false, |
| 2277 | .extended_cr = true, |
| 2278 | .pl023 = true, |
Philippe Langlais | 06fb01f | 2011-03-23 11:05:16 +0100 | [diff] [blame] | 2279 | .loopback = false, |
| 2280 | }; |
| 2281 | |
Linus Walleij | b43d65f | 2009-06-09 08:11:42 +0100 | [diff] [blame] | 2282 | static struct amba_id pl022_ids[] = { |
| 2283 | { |
| 2284 | /* |
| 2285 | * ARM PL022 variant, this has a 16bit wide |
| 2286 | * and 8 locations deep TX/RX FIFO |
| 2287 | */ |
| 2288 | .id = 0x00041022, |
| 2289 | .mask = 0x000fffff, |
| 2290 | .data = &vendor_arm, |
| 2291 | }, |
| 2292 | { |
| 2293 | /* |
| 2294 | * ST Micro derivative, this has 32bit wide |
| 2295 | * and 32 locations deep TX/RX FIFO |
| 2296 | */ |
Srinidhi Kasagar | e89e04f | 2009-10-05 06:13:53 +0100 | [diff] [blame] | 2297 | .id = 0x01080022, |
Linus Walleij | b43d65f | 2009-06-09 08:11:42 +0100 | [diff] [blame] | 2298 | .mask = 0xffffffff, |
| 2299 | .data = &vendor_st, |
| 2300 | }, |
Linus Walleij | 781c7b1 | 2010-05-07 08:40:53 +0000 | [diff] [blame] | 2301 | { |
| 2302 | /* |
| 2303 | * ST-Ericsson derivative "PL023" (this is not |
| 2304 | * an official ARM number), this is a PL022 SSP block |
| 2305 | * stripped to SPI mode only, it has 32bit wide |
| 2306 | * and 32 locations deep TX/RX FIFO but no extended |
| 2307 | * CR0/CR1 register |
| 2308 | */ |
Viresh Kumar | f1e45f8 | 2011-08-10 14:20:54 +0530 | [diff] [blame] | 2309 | .id = 0x00080023, |
| 2310 | .mask = 0xffffffff, |
| 2311 | .data = &vendor_st_pl023, |
Linus Walleij | 781c7b1 | 2010-05-07 08:40:53 +0000 | [diff] [blame] | 2312 | }, |
Linus Walleij | b43d65f | 2009-06-09 08:11:42 +0100 | [diff] [blame] | 2313 | { 0, 0 }, |
| 2314 | }; |
| 2315 | |
Dave Martin | 7eeac71 | 2011-10-05 15:15:22 +0100 | [diff] [blame] | 2316 | MODULE_DEVICE_TABLE(amba, pl022_ids); |
| 2317 | |
Linus Walleij | b43d65f | 2009-06-09 08:11:42 +0100 | [diff] [blame] | 2318 | static struct amba_driver pl022_driver = { |
| 2319 | .drv = { |
| 2320 | .name = "ssp-pl022", |
Russell King | 92b97f0 | 2011-08-14 09:13:48 +0100 | [diff] [blame] | 2321 | .pm = &pl022_dev_pm_ops, |
Linus Walleij | b43d65f | 2009-06-09 08:11:42 +0100 | [diff] [blame] | 2322 | }, |
| 2323 | .id_table = pl022_ids, |
| 2324 | .probe = pl022_probe, |
Kevin Wells | b422588 | 2010-07-27 16:39:30 +0000 | [diff] [blame] | 2325 | .remove = __devexit_p(pl022_remove), |
Linus Walleij | b43d65f | 2009-06-09 08:11:42 +0100 | [diff] [blame] | 2326 | }; |
| 2327 | |
Linus Walleij | b43d65f | 2009-06-09 08:11:42 +0100 | [diff] [blame] | 2328 | static int __init pl022_init(void) |
| 2329 | { |
| 2330 | return amba_driver_register(&pl022_driver); |
| 2331 | } |
Linus Walleij | 25c8e03 | 2010-09-06 11:02:12 +0200 | [diff] [blame] | 2332 | subsys_initcall(pl022_init); |
Linus Walleij | b43d65f | 2009-06-09 08:11:42 +0100 | [diff] [blame] | 2333 | |
| 2334 | static void __exit pl022_exit(void) |
| 2335 | { |
| 2336 | amba_driver_unregister(&pl022_driver); |
| 2337 | } |
Linus Walleij | b43d65f | 2009-06-09 08:11:42 +0100 | [diff] [blame] | 2338 | module_exit(pl022_exit); |
| 2339 | |
| 2340 | MODULE_AUTHOR("Linus Walleij <linus.walleij@stericsson.com>"); |
| 2341 | MODULE_DESCRIPTION("PL022 SSP Controller Driver"); |
| 2342 | MODULE_LICENSE("GPL"); |