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

Merge remote-tracking branches 'spi/topic/pxa', 'spi/topic/rb4xx', 'spi/topic/rspi', 'spi/topic/s3c64xx' and 'spi/topic/sh-msiof' into spi-next

+329 -586
+7 -8
drivers/spi/Kconfig
··· 395 395 help 396 396 This selects a driver for the PPC4xx SPI Controller. 397 397 398 - config SPI_PXA2XX_PXADMA 399 - bool "PXA2xx SSP legacy PXA DMA API support" 400 - depends on SPI_PXA2XX && ARCH_PXA 401 - help 402 - Enable PXA private legacy DMA API support. Note that this is 403 - deprecated in favor of generic DMA engine API. 404 - 405 398 config SPI_PXA2XX_DMA 406 399 def_bool y 407 - depends on SPI_PXA2XX && !SPI_PXA2XX_PXADMA 400 + depends on SPI_PXA2XX 408 401 409 402 config SPI_PXA2XX 410 403 tristate "PXA2xx SSP SPI master" ··· 422 429 Rockchip SPI controller support DMA transport and PIO mode. 423 430 The main usecase of this controller is to use spi flash as boot 424 431 device. 432 + 433 + config SPI_RB4XX 434 + tristate "Mikrotik RB4XX SPI master" 435 + depends on SPI_MASTER && ATH79 436 + help 437 + SPI controller driver for the Mikrotik RB4xx series boards. 425 438 426 439 config SPI_RSPI 427 440 tristate "Renesas RSPI/QSPI controller"
+1 -1
drivers/spi/Makefile
··· 60 60 obj-$(CONFIG_SPI_PL022) += spi-pl022.o 61 61 obj-$(CONFIG_SPI_PPC4xx) += spi-ppc4xx.o 62 62 spi-pxa2xx-platform-objs := spi-pxa2xx.o 63 - spi-pxa2xx-platform-$(CONFIG_SPI_PXA2XX_PXADMA) += spi-pxa2xx-pxadma.o 64 63 spi-pxa2xx-platform-$(CONFIG_SPI_PXA2XX_DMA) += spi-pxa2xx-dma.o 65 64 obj-$(CONFIG_SPI_PXA2XX) += spi-pxa2xx-platform.o 66 65 obj-$(CONFIG_SPI_PXA2XX_PCI) += spi-pxa2xx-pci.o 67 66 obj-$(CONFIG_SPI_QUP) += spi-qup.o 68 67 obj-$(CONFIG_SPI_ROCKCHIP) += spi-rockchip.o 68 + obj-$(CONFIG_SPI_RB4XX) += spi-rb4xx.o 69 69 obj-$(CONFIG_SPI_RSPI) += spi-rspi.o 70 70 obj-$(CONFIG_SPI_S3C24XX) += spi-s3c24xx-hw.o 71 71 spi-s3c24xx-hw-y := spi-s3c24xx.o
+4 -4
drivers/spi/spi-pxa2xx-pci.c
··· 62 62 .max_clk_rate = 3686400, 63 63 }, 64 64 [PORT_BYT] = { 65 - .type = LPSS_SSP, 65 + .type = LPSS_BYT_SSP, 66 66 .port_id = 0, 67 67 .num_chipselect = 1, 68 68 .max_clk_rate = 50000000, ··· 70 70 .rx_param = &byt_rx_param, 71 71 }, 72 72 [PORT_BSW0] = { 73 - .type = LPSS_SSP, 73 + .type = LPSS_BYT_SSP, 74 74 .port_id = 0, 75 75 .num_chipselect = 1, 76 76 .max_clk_rate = 50000000, ··· 78 78 .rx_param = &bsw0_rx_param, 79 79 }, 80 80 [PORT_BSW1] = { 81 - .type = LPSS_SSP, 81 + .type = LPSS_BYT_SSP, 82 82 .port_id = 1, 83 83 .num_chipselect = 1, 84 84 .max_clk_rate = 50000000, ··· 86 86 .rx_param = &bsw1_rx_param, 87 87 }, 88 88 [PORT_BSW2] = { 89 - .type = LPSS_SSP, 89 + .type = LPSS_BYT_SSP, 90 90 .port_id = 2, 91 91 .num_chipselect = 1, 92 92 .max_clk_rate = 50000000,
-487
drivers/spi/spi-pxa2xx-pxadma.c
··· 1 - /* 2 - * PXA2xx SPI private DMA support. 3 - * 4 - * Copyright (C) 2005 Stephen Street / StreetFire Sound Labs 5 - * 6 - * This program is free software; you can redistribute it and/or modify 7 - * it under the terms of the GNU General Public License as published by 8 - * the Free Software Foundation; either version 2 of the License, or 9 - * (at your option) any later version. 10 - * 11 - * This program is distributed in the hope that it will be useful, 12 - * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 - * GNU General Public License for more details. 15 - */ 16 - 17 - #include <linux/delay.h> 18 - #include <linux/device.h> 19 - #include <linux/dma-mapping.h> 20 - #include <linux/pxa2xx_ssp.h> 21 - #include <linux/spi/spi.h> 22 - #include <linux/spi/pxa2xx_spi.h> 23 - 24 - #include <mach/dma.h> 25 - #include "spi-pxa2xx.h" 26 - 27 - #define DMA_INT_MASK (DCSR_ENDINTR | DCSR_STARTINTR | DCSR_BUSERR) 28 - #define RESET_DMA_CHANNEL (DCSR_NODESC | DMA_INT_MASK) 29 - 30 - bool pxa2xx_spi_dma_is_possible(size_t len) 31 - { 32 - /* Try to map dma buffer and do a dma transfer if successful, but 33 - * only if the length is non-zero and less than MAX_DMA_LEN. 34 - * 35 - * Zero-length non-descriptor DMA is illegal on PXA2xx; force use 36 - * of PIO instead. Care is needed above because the transfer may 37 - * have have been passed with buffers that are already dma mapped. 38 - * A zero-length transfer in PIO mode will not try to write/read 39 - * to/from the buffers 40 - * 41 - * REVISIT large transfers are exactly where we most want to be 42 - * using DMA. If this happens much, split those transfers into 43 - * multiple DMA segments rather than forcing PIO. 44 - */ 45 - return len > 0 && len <= MAX_DMA_LEN; 46 - } 47 - 48 - int pxa2xx_spi_map_dma_buffers(struct driver_data *drv_data) 49 - { 50 - struct spi_message *msg = drv_data->cur_msg; 51 - struct device *dev = &msg->spi->dev; 52 - 53 - if (!drv_data->cur_chip->enable_dma) 54 - return 0; 55 - 56 - if (msg->is_dma_mapped) 57 - return drv_data->rx_dma && drv_data->tx_dma; 58 - 59 - if (!IS_DMA_ALIGNED(drv_data->rx) || !IS_DMA_ALIGNED(drv_data->tx)) 60 - return 0; 61 - 62 - /* Modify setup if rx buffer is null */ 63 - if (drv_data->rx == NULL) { 64 - *drv_data->null_dma_buf = 0; 65 - drv_data->rx = drv_data->null_dma_buf; 66 - drv_data->rx_map_len = 4; 67 - } else 68 - drv_data->rx_map_len = drv_data->len; 69 - 70 - 71 - /* Modify setup if tx buffer is null */ 72 - if (drv_data->tx == NULL) { 73 - *drv_data->null_dma_buf = 0; 74 - drv_data->tx = drv_data->null_dma_buf; 75 - drv_data->tx_map_len = 4; 76 - } else 77 - drv_data->tx_map_len = drv_data->len; 78 - 79 - /* Stream map the tx buffer. Always do DMA_TO_DEVICE first 80 - * so we flush the cache *before* invalidating it, in case 81 - * the tx and rx buffers overlap. 82 - */ 83 - drv_data->tx_dma = dma_map_single(dev, drv_data->tx, 84 - drv_data->tx_map_len, DMA_TO_DEVICE); 85 - if (dma_mapping_error(dev, drv_data->tx_dma)) 86 - return 0; 87 - 88 - /* Stream map the rx buffer */ 89 - drv_data->rx_dma = dma_map_single(dev, drv_data->rx, 90 - drv_data->rx_map_len, DMA_FROM_DEVICE); 91 - if (dma_mapping_error(dev, drv_data->rx_dma)) { 92 - dma_unmap_single(dev, drv_data->tx_dma, 93 - drv_data->tx_map_len, DMA_TO_DEVICE); 94 - return 0; 95 - } 96 - 97 - return 1; 98 - } 99 - 100 - static void pxa2xx_spi_unmap_dma_buffers(struct driver_data *drv_data) 101 - { 102 - struct device *dev; 103 - 104 - if (!drv_data->dma_mapped) 105 - return; 106 - 107 - if (!drv_data->cur_msg->is_dma_mapped) { 108 - dev = &drv_data->cur_msg->spi->dev; 109 - dma_unmap_single(dev, drv_data->rx_dma, 110 - drv_data->rx_map_len, DMA_FROM_DEVICE); 111 - dma_unmap_single(dev, drv_data->tx_dma, 112 - drv_data->tx_map_len, DMA_TO_DEVICE); 113 - } 114 - 115 - drv_data->dma_mapped = 0; 116 - } 117 - 118 - static int wait_ssp_rx_stall(struct driver_data *drv_data) 119 - { 120 - unsigned long limit = loops_per_jiffy << 1; 121 - 122 - while ((pxa2xx_spi_read(drv_data, SSSR) & SSSR_BSY) && --limit) 123 - cpu_relax(); 124 - 125 - return limit; 126 - } 127 - 128 - static int wait_dma_channel_stop(int channel) 129 - { 130 - unsigned long limit = loops_per_jiffy << 1; 131 - 132 - while (!(DCSR(channel) & DCSR_STOPSTATE) && --limit) 133 - cpu_relax(); 134 - 135 - return limit; 136 - } 137 - 138 - static void pxa2xx_spi_dma_error_stop(struct driver_data *drv_data, 139 - const char *msg) 140 - { 141 - /* Stop and reset */ 142 - DCSR(drv_data->rx_channel) = RESET_DMA_CHANNEL; 143 - DCSR(drv_data->tx_channel) = RESET_DMA_CHANNEL; 144 - write_SSSR_CS(drv_data, drv_data->clear_sr); 145 - pxa2xx_spi_write(drv_data, SSCR1, 146 - pxa2xx_spi_read(drv_data, SSCR1) 147 - & ~drv_data->dma_cr1); 148 - if (!pxa25x_ssp_comp(drv_data)) 149 - pxa2xx_spi_write(drv_data, SSTO, 0); 150 - pxa2xx_spi_flush(drv_data); 151 - pxa2xx_spi_write(drv_data, SSCR0, 152 - pxa2xx_spi_read(drv_data, SSCR0) & ~SSCR0_SSE); 153 - 154 - pxa2xx_spi_unmap_dma_buffers(drv_data); 155 - 156 - dev_err(&drv_data->pdev->dev, "%s\n", msg); 157 - 158 - drv_data->cur_msg->state = ERROR_STATE; 159 - tasklet_schedule(&drv_data->pump_transfers); 160 - } 161 - 162 - static void pxa2xx_spi_dma_transfer_complete(struct driver_data *drv_data) 163 - { 164 - struct spi_message *msg = drv_data->cur_msg; 165 - 166 - /* Clear and disable interrupts on SSP and DMA channels*/ 167 - pxa2xx_spi_write(drv_data, SSCR1, 168 - pxa2xx_spi_read(drv_data, SSCR1) 169 - & ~drv_data->dma_cr1); 170 - write_SSSR_CS(drv_data, drv_data->clear_sr); 171 - DCSR(drv_data->tx_channel) = RESET_DMA_CHANNEL; 172 - DCSR(drv_data->rx_channel) = RESET_DMA_CHANNEL; 173 - 174 - if (wait_dma_channel_stop(drv_data->rx_channel) == 0) 175 - dev_err(&drv_data->pdev->dev, 176 - "dma_handler: dma rx channel stop failed\n"); 177 - 178 - if (wait_ssp_rx_stall(drv_data->ioaddr) == 0) 179 - dev_err(&drv_data->pdev->dev, 180 - "dma_transfer: ssp rx stall failed\n"); 181 - 182 - pxa2xx_spi_unmap_dma_buffers(drv_data); 183 - 184 - /* update the buffer pointer for the amount completed in dma */ 185 - drv_data->rx += drv_data->len - 186 - (DCMD(drv_data->rx_channel) & DCMD_LENGTH); 187 - 188 - /* read trailing data from fifo, it does not matter how many 189 - * bytes are in the fifo just read until buffer is full 190 - * or fifo is empty, which ever occurs first */ 191 - drv_data->read(drv_data); 192 - 193 - /* return count of what was actually read */ 194 - msg->actual_length += drv_data->len - 195 - (drv_data->rx_end - drv_data->rx); 196 - 197 - /* Transfer delays and chip select release are 198 - * handled in pump_transfers or giveback 199 - */ 200 - 201 - /* Move to next transfer */ 202 - msg->state = pxa2xx_spi_next_transfer(drv_data); 203 - 204 - /* Schedule transfer tasklet */ 205 - tasklet_schedule(&drv_data->pump_transfers); 206 - } 207 - 208 - void pxa2xx_spi_dma_handler(int channel, void *data) 209 - { 210 - struct driver_data *drv_data = data; 211 - u32 irq_status = DCSR(channel) & DMA_INT_MASK; 212 - 213 - if (irq_status & DCSR_BUSERR) { 214 - 215 - if (channel == drv_data->tx_channel) 216 - pxa2xx_spi_dma_error_stop(drv_data, 217 - "dma_handler: bad bus address on tx channel"); 218 - else 219 - pxa2xx_spi_dma_error_stop(drv_data, 220 - "dma_handler: bad bus address on rx channel"); 221 - return; 222 - } 223 - 224 - /* PXA255x_SSP has no timeout interrupt, wait for tailing bytes */ 225 - if ((channel == drv_data->tx_channel) 226 - && (irq_status & DCSR_ENDINTR) 227 - && (drv_data->ssp_type == PXA25x_SSP)) { 228 - 229 - /* Wait for rx to stall */ 230 - if (wait_ssp_rx_stall(drv_data) == 0) 231 - dev_err(&drv_data->pdev->dev, 232 - "dma_handler: ssp rx stall failed\n"); 233 - 234 - /* finish this transfer, start the next */ 235 - pxa2xx_spi_dma_transfer_complete(drv_data); 236 - } 237 - } 238 - 239 - irqreturn_t pxa2xx_spi_dma_transfer(struct driver_data *drv_data) 240 - { 241 - u32 irq_status; 242 - 243 - irq_status = pxa2xx_spi_read(drv_data, SSSR) & drv_data->mask_sr; 244 - if (irq_status & SSSR_ROR) { 245 - pxa2xx_spi_dma_error_stop(drv_data, 246 - "dma_transfer: fifo overrun"); 247 - return IRQ_HANDLED; 248 - } 249 - 250 - /* Check for false positive timeout */ 251 - if ((irq_status & SSSR_TINT) 252 - && (DCSR(drv_data->tx_channel) & DCSR_RUN)) { 253 - pxa2xx_spi_write(drv_data, SSSR, SSSR_TINT); 254 - return IRQ_HANDLED; 255 - } 256 - 257 - if (irq_status & SSSR_TINT || drv_data->rx == drv_data->rx_end) { 258 - 259 - /* Clear and disable timeout interrupt, do the rest in 260 - * dma_transfer_complete */ 261 - if (!pxa25x_ssp_comp(drv_data)) 262 - pxa2xx_spi_write(drv_data, SSTO, 0); 263 - 264 - /* finish this transfer, start the next */ 265 - pxa2xx_spi_dma_transfer_complete(drv_data); 266 - 267 - return IRQ_HANDLED; 268 - } 269 - 270 - /* Opps problem detected */ 271 - return IRQ_NONE; 272 - } 273 - 274 - int pxa2xx_spi_dma_prepare(struct driver_data *drv_data, u32 dma_burst) 275 - { 276 - u32 dma_width; 277 - 278 - switch (drv_data->n_bytes) { 279 - case 1: 280 - dma_width = DCMD_WIDTH1; 281 - break; 282 - case 2: 283 - dma_width = DCMD_WIDTH2; 284 - break; 285 - default: 286 - dma_width = DCMD_WIDTH4; 287 - break; 288 - } 289 - 290 - /* Setup rx DMA Channel */ 291 - DCSR(drv_data->rx_channel) = RESET_DMA_CHANNEL; 292 - DSADR(drv_data->rx_channel) = drv_data->ssdr_physical; 293 - DTADR(drv_data->rx_channel) = drv_data->rx_dma; 294 - if (drv_data->rx == drv_data->null_dma_buf) 295 - /* No target address increment */ 296 - DCMD(drv_data->rx_channel) = DCMD_FLOWSRC 297 - | dma_width 298 - | dma_burst 299 - | drv_data->len; 300 - else 301 - DCMD(drv_data->rx_channel) = DCMD_INCTRGADDR 302 - | DCMD_FLOWSRC 303 - | dma_width 304 - | dma_burst 305 - | drv_data->len; 306 - 307 - /* Setup tx DMA Channel */ 308 - DCSR(drv_data->tx_channel) = RESET_DMA_CHANNEL; 309 - DSADR(drv_data->tx_channel) = drv_data->tx_dma; 310 - DTADR(drv_data->tx_channel) = drv_data->ssdr_physical; 311 - if (drv_data->tx == drv_data->null_dma_buf) 312 - /* No source address increment */ 313 - DCMD(drv_data->tx_channel) = DCMD_FLOWTRG 314 - | dma_width 315 - | dma_burst 316 - | drv_data->len; 317 - else 318 - DCMD(drv_data->tx_channel) = DCMD_INCSRCADDR 319 - | DCMD_FLOWTRG 320 - | dma_width 321 - | dma_burst 322 - | drv_data->len; 323 - 324 - /* Enable dma end irqs on SSP to detect end of transfer */ 325 - if (drv_data->ssp_type == PXA25x_SSP) 326 - DCMD(drv_data->tx_channel) |= DCMD_ENDIRQEN; 327 - 328 - return 0; 329 - } 330 - 331 - void pxa2xx_spi_dma_start(struct driver_data *drv_data) 332 - { 333 - DCSR(drv_data->rx_channel) |= DCSR_RUN; 334 - DCSR(drv_data->tx_channel) |= DCSR_RUN; 335 - } 336 - 337 - int pxa2xx_spi_dma_setup(struct driver_data *drv_data) 338 - { 339 - struct device *dev = &drv_data->pdev->dev; 340 - struct ssp_device *ssp = drv_data->ssp; 341 - 342 - /* Get two DMA channels (rx and tx) */ 343 - drv_data->rx_channel = pxa_request_dma("pxa2xx_spi_ssp_rx", 344 - DMA_PRIO_HIGH, 345 - pxa2xx_spi_dma_handler, 346 - drv_data); 347 - if (drv_data->rx_channel < 0) { 348 - dev_err(dev, "problem (%d) requesting rx channel\n", 349 - drv_data->rx_channel); 350 - return -ENODEV; 351 - } 352 - drv_data->tx_channel = pxa_request_dma("pxa2xx_spi_ssp_tx", 353 - DMA_PRIO_MEDIUM, 354 - pxa2xx_spi_dma_handler, 355 - drv_data); 356 - if (drv_data->tx_channel < 0) { 357 - dev_err(dev, "problem (%d) requesting tx channel\n", 358 - drv_data->tx_channel); 359 - pxa_free_dma(drv_data->rx_channel); 360 - return -ENODEV; 361 - } 362 - 363 - DRCMR(ssp->drcmr_rx) = DRCMR_MAPVLD | drv_data->rx_channel; 364 - DRCMR(ssp->drcmr_tx) = DRCMR_MAPVLD | drv_data->tx_channel; 365 - 366 - return 0; 367 - } 368 - 369 - void pxa2xx_spi_dma_release(struct driver_data *drv_data) 370 - { 371 - struct ssp_device *ssp = drv_data->ssp; 372 - 373 - DRCMR(ssp->drcmr_rx) = 0; 374 - DRCMR(ssp->drcmr_tx) = 0; 375 - 376 - if (drv_data->tx_channel != 0) 377 - pxa_free_dma(drv_data->tx_channel); 378 - if (drv_data->rx_channel != 0) 379 - pxa_free_dma(drv_data->rx_channel); 380 - } 381 - 382 - void pxa2xx_spi_dma_resume(struct driver_data *drv_data) 383 - { 384 - if (drv_data->rx_channel != -1) 385 - DRCMR(drv_data->ssp->drcmr_rx) = 386 - DRCMR_MAPVLD | drv_data->rx_channel; 387 - if (drv_data->tx_channel != -1) 388 - DRCMR(drv_data->ssp->drcmr_tx) = 389 - DRCMR_MAPVLD | drv_data->tx_channel; 390 - } 391 - 392 - int pxa2xx_spi_set_dma_burst_and_threshold(struct chip_data *chip, 393 - struct spi_device *spi, 394 - u8 bits_per_word, u32 *burst_code, 395 - u32 *threshold) 396 - { 397 - struct pxa2xx_spi_chip *chip_info = 398 - (struct pxa2xx_spi_chip *)spi->controller_data; 399 - int bytes_per_word; 400 - int burst_bytes; 401 - int thresh_words; 402 - int req_burst_size; 403 - int retval = 0; 404 - 405 - /* Set the threshold (in registers) to equal the same amount of data 406 - * as represented by burst size (in bytes). The computation below 407 - * is (burst_size rounded up to nearest 8 byte, word or long word) 408 - * divided by (bytes/register); the tx threshold is the inverse of 409 - * the rx, so that there will always be enough data in the rx fifo 410 - * to satisfy a burst, and there will always be enough space in the 411 - * tx fifo to accept a burst (a tx burst will overwrite the fifo if 412 - * there is not enough space), there must always remain enough empty 413 - * space in the rx fifo for any data loaded to the tx fifo. 414 - * Whenever burst_size (in bytes) equals bits/word, the fifo threshold 415 - * will be 8, or half the fifo; 416 - * The threshold can only be set to 2, 4 or 8, but not 16, because 417 - * to burst 16 to the tx fifo, the fifo would have to be empty; 418 - * however, the minimum fifo trigger level is 1, and the tx will 419 - * request service when the fifo is at this level, with only 15 spaces. 420 - */ 421 - 422 - /* find bytes/word */ 423 - if (bits_per_word <= 8) 424 - bytes_per_word = 1; 425 - else if (bits_per_word <= 16) 426 - bytes_per_word = 2; 427 - else 428 - bytes_per_word = 4; 429 - 430 - /* use struct pxa2xx_spi_chip->dma_burst_size if available */ 431 - if (chip_info) 432 - req_burst_size = chip_info->dma_burst_size; 433 - else { 434 - switch (chip->dma_burst_size) { 435 - default: 436 - /* if the default burst size is not set, 437 - * do it now */ 438 - chip->dma_burst_size = DCMD_BURST8; 439 - case DCMD_BURST8: 440 - req_burst_size = 8; 441 - break; 442 - case DCMD_BURST16: 443 - req_burst_size = 16; 444 - break; 445 - case DCMD_BURST32: 446 - req_burst_size = 32; 447 - break; 448 - } 449 - } 450 - if (req_burst_size <= 8) { 451 - *burst_code = DCMD_BURST8; 452 - burst_bytes = 8; 453 - } else if (req_burst_size <= 16) { 454 - if (bytes_per_word == 1) { 455 - /* don't burst more than 1/2 the fifo */ 456 - *burst_code = DCMD_BURST8; 457 - burst_bytes = 8; 458 - retval = 1; 459 - } else { 460 - *burst_code = DCMD_BURST16; 461 - burst_bytes = 16; 462 - } 463 - } else { 464 - if (bytes_per_word == 1) { 465 - /* don't burst more than 1/2 the fifo */ 466 - *burst_code = DCMD_BURST8; 467 - burst_bytes = 8; 468 - retval = 1; 469 - } else if (bytes_per_word == 2) { 470 - /* don't burst more than 1/2 the fifo */ 471 - *burst_code = DCMD_BURST16; 472 - burst_bytes = 16; 473 - retval = 1; 474 - } else { 475 - *burst_code = DCMD_BURST32; 476 - burst_bytes = 32; 477 - } 478 - } 479 - 480 - thresh_words = burst_bytes / bytes_per_word; 481 - 482 - /* thresh_words will be between 2 and 8 */ 483 - *threshold = (SSCR1_RxTresh(thresh_words) & SSCR1_RFT) 484 - | (SSCR1_TxTresh(16-thresh_words) & SSCR1_TFT); 485 - 486 - return retval; 487 - }
+94 -63
drivers/spi/spi-pxa2xx.c
··· 60 60 | QUARK_X1000_SSCR1_TFT \ 61 61 | SSCR1_SPH | SSCR1_SPO | SSCR1_LBM) 62 62 63 - #define LPSS_RX_THRESH_DFLT 64 64 - #define LPSS_TX_LOTHRESH_DFLT 160 65 - #define LPSS_TX_HITHRESH_DFLT 224 66 - 67 - /* Offset from drv_data->lpss_base */ 68 - #define GENERAL_REG 0x08 69 63 #define GENERAL_REG_RXTO_HOLDOFF_DISABLE BIT(24) 70 - #define SSP_REG 0x0c 71 - #define SPI_CS_CONTROL 0x18 72 64 #define SPI_CS_CONTROL_SW_MODE BIT(0) 73 65 #define SPI_CS_CONTROL_CS_HIGH BIT(1) 74 66 67 + struct lpss_config { 68 + /* LPSS offset from drv_data->ioaddr */ 69 + unsigned offset; 70 + /* Register offsets from drv_data->lpss_base or -1 */ 71 + int reg_general; 72 + int reg_ssp; 73 + int reg_cs_ctrl; 74 + /* FIFO thresholds */ 75 + u32 rx_threshold; 76 + u32 tx_threshold_lo; 77 + u32 tx_threshold_hi; 78 + }; 79 + 80 + /* Keep these sorted with enum pxa_ssp_type */ 81 + static const struct lpss_config lpss_platforms[] = { 82 + { /* LPSS_LPT_SSP */ 83 + .offset = 0x800, 84 + .reg_general = 0x08, 85 + .reg_ssp = 0x0c, 86 + .reg_cs_ctrl = 0x18, 87 + .rx_threshold = 64, 88 + .tx_threshold_lo = 160, 89 + .tx_threshold_hi = 224, 90 + }, 91 + { /* LPSS_BYT_SSP */ 92 + .offset = 0x400, 93 + .reg_general = 0x08, 94 + .reg_ssp = 0x0c, 95 + .reg_cs_ctrl = 0x18, 96 + .rx_threshold = 64, 97 + .tx_threshold_lo = 160, 98 + .tx_threshold_hi = 224, 99 + }, 100 + }; 101 + 102 + static inline const struct lpss_config 103 + *lpss_get_config(const struct driver_data *drv_data) 104 + { 105 + return &lpss_platforms[drv_data->ssp_type - LPSS_LPT_SSP]; 106 + } 107 + 75 108 static bool is_lpss_ssp(const struct driver_data *drv_data) 76 109 { 77 - return drv_data->ssp_type == LPSS_SSP; 110 + switch (drv_data->ssp_type) { 111 + case LPSS_LPT_SSP: 112 + case LPSS_BYT_SSP: 113 + return true; 114 + default: 115 + return false; 116 + } 78 117 } 79 118 80 119 static bool is_quark_x1000_ssp(const struct driver_data *drv_data) ··· 231 192 */ 232 193 static void lpss_ssp_setup(struct driver_data *drv_data) 233 194 { 234 - unsigned offset = 0x400; 235 - u32 value, orig; 195 + const struct lpss_config *config; 196 + u32 value; 236 197 237 - /* 238 - * Perform auto-detection of the LPSS SSP private registers. They 239 - * can be either at 1k or 2k offset from the base address. 240 - */ 241 - orig = readl(drv_data->ioaddr + offset + SPI_CS_CONTROL); 242 - 243 - /* Test SPI_CS_CONTROL_SW_MODE bit enabling */ 244 - value = orig | SPI_CS_CONTROL_SW_MODE; 245 - writel(value, drv_data->ioaddr + offset + SPI_CS_CONTROL); 246 - value = readl(drv_data->ioaddr + offset + SPI_CS_CONTROL); 247 - if (value != (orig | SPI_CS_CONTROL_SW_MODE)) { 248 - offset = 0x800; 249 - goto detection_done; 250 - } 251 - 252 - orig = readl(drv_data->ioaddr + offset + SPI_CS_CONTROL); 253 - 254 - /* Test SPI_CS_CONTROL_SW_MODE bit disabling */ 255 - value = orig & ~SPI_CS_CONTROL_SW_MODE; 256 - writel(value, drv_data->ioaddr + offset + SPI_CS_CONTROL); 257 - value = readl(drv_data->ioaddr + offset + SPI_CS_CONTROL); 258 - if (value != (orig & ~SPI_CS_CONTROL_SW_MODE)) { 259 - offset = 0x800; 260 - goto detection_done; 261 - } 262 - 263 - detection_done: 264 - /* Now set the LPSS base */ 265 - drv_data->lpss_base = drv_data->ioaddr + offset; 198 + config = lpss_get_config(drv_data); 199 + drv_data->lpss_base = drv_data->ioaddr + config->offset; 266 200 267 201 /* Enable software chip select control */ 268 202 value = SPI_CS_CONTROL_SW_MODE | SPI_CS_CONTROL_CS_HIGH; 269 - __lpss_ssp_write_priv(drv_data, SPI_CS_CONTROL, value); 203 + __lpss_ssp_write_priv(drv_data, config->reg_cs_ctrl, value); 270 204 271 205 /* Enable multiblock DMA transfers */ 272 206 if (drv_data->master_info->enable_dma) { 273 - __lpss_ssp_write_priv(drv_data, SSP_REG, 1); 207 + __lpss_ssp_write_priv(drv_data, config->reg_ssp, 1); 274 208 275 - value = __lpss_ssp_read_priv(drv_data, GENERAL_REG); 276 - value |= GENERAL_REG_RXTO_HOLDOFF_DISABLE; 277 - __lpss_ssp_write_priv(drv_data, GENERAL_REG, value); 209 + if (config->reg_general >= 0) { 210 + value = __lpss_ssp_read_priv(drv_data, 211 + config->reg_general); 212 + value |= GENERAL_REG_RXTO_HOLDOFF_DISABLE; 213 + __lpss_ssp_write_priv(drv_data, 214 + config->reg_general, value); 215 + } 278 216 } 279 217 } 280 218 281 219 static void lpss_ssp_cs_control(struct driver_data *drv_data, bool enable) 282 220 { 221 + const struct lpss_config *config; 283 222 u32 value; 284 223 285 - value = __lpss_ssp_read_priv(drv_data, SPI_CS_CONTROL); 224 + config = lpss_get_config(drv_data); 225 + 226 + value = __lpss_ssp_read_priv(drv_data, config->reg_cs_ctrl); 286 227 if (enable) 287 228 value &= ~SPI_CS_CONTROL_CS_HIGH; 288 229 else 289 230 value |= SPI_CS_CONTROL_CS_HIGH; 290 - __lpss_ssp_write_priv(drv_data, SPI_CS_CONTROL, value); 231 + __lpss_ssp_write_priv(drv_data, config->reg_cs_ctrl, value); 291 232 } 292 233 293 234 static void cs_assert(struct driver_data *drv_data) ··· 1094 1075 { 1095 1076 struct pxa2xx_spi_chip *chip_info = NULL; 1096 1077 struct chip_data *chip; 1078 + const struct lpss_config *config; 1097 1079 struct driver_data *drv_data = spi_master_get_devdata(spi->master); 1098 1080 unsigned int clk_div; 1099 1081 uint tx_thres, tx_hi_thres, rx_thres; ··· 1105 1085 tx_hi_thres = 0; 1106 1086 rx_thres = RX_THRESH_QUARK_X1000_DFLT; 1107 1087 break; 1108 - case LPSS_SSP: 1109 - tx_thres = LPSS_TX_LOTHRESH_DFLT; 1110 - tx_hi_thres = LPSS_TX_HITHRESH_DFLT; 1111 - rx_thres = LPSS_RX_THRESH_DFLT; 1088 + case LPSS_LPT_SSP: 1089 + case LPSS_BYT_SSP: 1090 + config = lpss_get_config(drv_data); 1091 + tx_thres = config->tx_threshold_lo; 1092 + tx_hi_thres = config->tx_threshold_hi; 1093 + rx_thres = config->rx_threshold; 1112 1094 break; 1113 1095 default: 1114 1096 tx_thres = TX_THRESH_DFLT; ··· 1264 1242 } 1265 1243 1266 1244 #ifdef CONFIG_ACPI 1245 + 1246 + static const struct acpi_device_id pxa2xx_spi_acpi_match[] = { 1247 + { "INT33C0", LPSS_LPT_SSP }, 1248 + { "INT33C1", LPSS_LPT_SSP }, 1249 + { "INT3430", LPSS_LPT_SSP }, 1250 + { "INT3431", LPSS_LPT_SSP }, 1251 + { "80860F0E", LPSS_BYT_SSP }, 1252 + { "8086228E", LPSS_BYT_SSP }, 1253 + { }, 1254 + }; 1255 + MODULE_DEVICE_TABLE(acpi, pxa2xx_spi_acpi_match); 1256 + 1267 1257 static struct pxa2xx_spi_master * 1268 1258 pxa2xx_spi_acpi_get_pdata(struct platform_device *pdev) 1269 1259 { ··· 1283 1249 struct acpi_device *adev; 1284 1250 struct ssp_device *ssp; 1285 1251 struct resource *res; 1286 - int devid; 1252 + const struct acpi_device_id *id; 1253 + int devid, type; 1287 1254 1288 1255 if (!ACPI_HANDLE(&pdev->dev) || 1289 1256 acpi_bus_get_device(ACPI_HANDLE(&pdev->dev), &adev)) 1257 + return NULL; 1258 + 1259 + id = acpi_match_device(pdev->dev.driver->acpi_match_table, &pdev->dev); 1260 + if (id) 1261 + type = (int)id->driver_data; 1262 + else 1290 1263 return NULL; 1291 1264 1292 1265 pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL); ··· 1313 1272 1314 1273 ssp->clk = devm_clk_get(&pdev->dev, NULL); 1315 1274 ssp->irq = platform_get_irq(pdev, 0); 1316 - ssp->type = LPSS_SSP; 1275 + ssp->type = type; 1317 1276 ssp->pdev = pdev; 1318 1277 1319 1278 ssp->port_id = -1; ··· 1326 1285 return pdata; 1327 1286 } 1328 1287 1329 - static struct acpi_device_id pxa2xx_spi_acpi_match[] = { 1330 - { "INT33C0", 0 }, 1331 - { "INT33C1", 0 }, 1332 - { "INT3430", 0 }, 1333 - { "INT3431", 0 }, 1334 - { "80860F0E", 0 }, 1335 - { "8086228E", 0 }, 1336 - { }, 1337 - }; 1338 - MODULE_DEVICE_TABLE(acpi, pxa2xx_spi_acpi_match); 1339 1288 #else 1340 1289 static inline struct pxa2xx_spi_master * 1341 1290 pxa2xx_spi_acpi_get_pdata(struct platform_device *pdev)
+1 -5
drivers/spi/spi-pxa2xx.h
··· 162 162 /* 163 163 * Select the right DMA implementation. 164 164 */ 165 - #if defined(CONFIG_SPI_PXA2XX_PXADMA) 166 - #define SPI_PXA2XX_USE_DMA 1 167 - #define MAX_DMA_LEN 8191 168 - #define DEFAULT_DMA_CR1 (SSCR1_TSRE | SSCR1_RSRE | SSCR1_TINTE) 169 - #elif defined(CONFIG_SPI_PXA2XX_DMA) 165 + #if defined(CONFIG_SPI_PXA2XX_DMA) 170 166 #define SPI_PXA2XX_USE_DMA 1 171 167 #define MAX_DMA_LEN SZ_64K 172 168 #define DEFAULT_DMA_CR1 (SSCR1_TSRE | SSCR1_RSRE | SSCR1_TRAIL)
+210
drivers/spi/spi-rb4xx.c
··· 1 + /* 2 + * SPI controller driver for the Mikrotik RB4xx boards 3 + * 4 + * Copyright (C) 2010 Gabor Juhos <juhosg@openwrt.org> 5 + * Copyright (C) 2015 Bert Vermeulen <bert@biot.com> 6 + * 7 + * This file was based on the patches for Linux 2.6.27.39 published by 8 + * MikroTik for their RouterBoard 4xx series devices. 9 + * 10 + * This program is free software; you can redistribute it and/or modify 11 + * it under the terms of the GNU General Public License version 2 as 12 + * published by the Free Software Foundation. 13 + * 14 + */ 15 + 16 + #include <linux/kernel.h> 17 + #include <linux/module.h> 18 + #include <linux/platform_device.h> 19 + #include <linux/clk.h> 20 + #include <linux/spi/spi.h> 21 + 22 + #include <asm/mach-ath79/ar71xx_regs.h> 23 + 24 + struct rb4xx_spi { 25 + void __iomem *base; 26 + struct clk *clk; 27 + }; 28 + 29 + static inline u32 rb4xx_read(struct rb4xx_spi *rbspi, u32 reg) 30 + { 31 + return __raw_readl(rbspi->base + reg); 32 + } 33 + 34 + static inline void rb4xx_write(struct rb4xx_spi *rbspi, u32 reg, u32 value) 35 + { 36 + __raw_writel(value, rbspi->base + reg); 37 + } 38 + 39 + static inline void do_spi_clk(struct rb4xx_spi *rbspi, u32 spi_ioc, int value) 40 + { 41 + u32 regval; 42 + 43 + regval = spi_ioc; 44 + if (value & BIT(0)) 45 + regval |= AR71XX_SPI_IOC_DO; 46 + 47 + rb4xx_write(rbspi, AR71XX_SPI_REG_IOC, regval); 48 + rb4xx_write(rbspi, AR71XX_SPI_REG_IOC, regval | AR71XX_SPI_IOC_CLK); 49 + } 50 + 51 + static void do_spi_byte(struct rb4xx_spi *rbspi, u32 spi_ioc, u8 byte) 52 + { 53 + int i; 54 + 55 + for (i = 7; i >= 0; i--) 56 + do_spi_clk(rbspi, spi_ioc, byte >> i); 57 + } 58 + 59 + /* The CS2 pin is used to clock in a second bit per clock cycle. */ 60 + static inline void do_spi_clk_two(struct rb4xx_spi *rbspi, u32 spi_ioc, 61 + u8 value) 62 + { 63 + u32 regval; 64 + 65 + regval = spi_ioc; 66 + if (value & BIT(1)) 67 + regval |= AR71XX_SPI_IOC_DO; 68 + if (value & BIT(0)) 69 + regval |= AR71XX_SPI_IOC_CS2; 70 + 71 + rb4xx_write(rbspi, AR71XX_SPI_REG_IOC, regval); 72 + rb4xx_write(rbspi, AR71XX_SPI_REG_IOC, regval | AR71XX_SPI_IOC_CLK); 73 + } 74 + 75 + /* Two bits at a time, msb first */ 76 + static void do_spi_byte_two(struct rb4xx_spi *rbspi, u32 spi_ioc, u8 byte) 77 + { 78 + do_spi_clk_two(rbspi, spi_ioc, byte >> 6); 79 + do_spi_clk_two(rbspi, spi_ioc, byte >> 4); 80 + do_spi_clk_two(rbspi, spi_ioc, byte >> 2); 81 + do_spi_clk_two(rbspi, spi_ioc, byte >> 0); 82 + } 83 + 84 + static void rb4xx_set_cs(struct spi_device *spi, bool enable) 85 + { 86 + struct rb4xx_spi *rbspi = spi_master_get_devdata(spi->master); 87 + 88 + /* 89 + * Setting CS is done along with bitbanging the actual values, 90 + * since it's all on the same hardware register. However the 91 + * CPLD needs CS deselected after every command. 92 + */ 93 + if (enable) 94 + rb4xx_write(rbspi, AR71XX_SPI_REG_IOC, 95 + AR71XX_SPI_IOC_CS0 | AR71XX_SPI_IOC_CS1); 96 + } 97 + 98 + static int rb4xx_transfer_one(struct spi_master *master, 99 + struct spi_device *spi, struct spi_transfer *t) 100 + { 101 + struct rb4xx_spi *rbspi = spi_master_get_devdata(master); 102 + int i; 103 + u32 spi_ioc; 104 + u8 *rx_buf; 105 + const u8 *tx_buf; 106 + 107 + /* 108 + * Prime the SPI register with the SPI device selected. The m25p80 boot 109 + * flash and CPLD share the CS0 pin. This works because the CPLD's 110 + * command set was designed to almost not clash with that of the 111 + * boot flash. 112 + */ 113 + if (spi->chip_select == 2) 114 + /* MMC */ 115 + spi_ioc = AR71XX_SPI_IOC_CS0; 116 + else 117 + /* Boot flash and CPLD */ 118 + spi_ioc = AR71XX_SPI_IOC_CS1; 119 + 120 + tx_buf = t->tx_buf; 121 + rx_buf = t->rx_buf; 122 + for (i = 0; i < t->len; ++i) { 123 + if (t->tx_nbits == SPI_NBITS_DUAL) 124 + /* CPLD can use two-wire transfers */ 125 + do_spi_byte_two(rbspi, spi_ioc, tx_buf[i]); 126 + else 127 + do_spi_byte(rbspi, spi_ioc, tx_buf[i]); 128 + if (!rx_buf) 129 + continue; 130 + rx_buf[i] = rb4xx_read(rbspi, AR71XX_SPI_REG_RDS); 131 + } 132 + spi_finalize_current_transfer(master); 133 + 134 + return 0; 135 + } 136 + 137 + static int rb4xx_spi_probe(struct platform_device *pdev) 138 + { 139 + struct spi_master *master; 140 + struct clk *ahb_clk; 141 + struct rb4xx_spi *rbspi; 142 + struct resource *r; 143 + int err; 144 + void __iomem *spi_base; 145 + 146 + r = platform_get_resource(pdev, IORESOURCE_MEM, 0); 147 + spi_base = devm_ioremap_resource(&pdev->dev, r); 148 + if (IS_ERR(spi_base)) 149 + return PTR_ERR(spi_base); 150 + 151 + master = spi_alloc_master(&pdev->dev, sizeof(*rbspi)); 152 + if (!master) 153 + return -ENOMEM; 154 + 155 + ahb_clk = devm_clk_get(&pdev->dev, "ahb"); 156 + if (IS_ERR(ahb_clk)) 157 + return PTR_ERR(ahb_clk); 158 + 159 + master->bus_num = 0; 160 + master->num_chipselect = 3; 161 + master->mode_bits = SPI_TX_DUAL; 162 + master->bits_per_word_mask = BIT(7); 163 + master->flags = SPI_MASTER_MUST_TX; 164 + master->transfer_one = rb4xx_transfer_one; 165 + master->set_cs = rb4xx_set_cs; 166 + 167 + err = devm_spi_register_master(&pdev->dev, master); 168 + if (err) { 169 + dev_err(&pdev->dev, "failed to register SPI master\n"); 170 + return err; 171 + } 172 + 173 + err = clk_prepare_enable(ahb_clk); 174 + if (err) 175 + return err; 176 + 177 + rbspi = spi_master_get_devdata(master); 178 + rbspi->base = spi_base; 179 + rbspi->clk = ahb_clk; 180 + platform_set_drvdata(pdev, rbspi); 181 + 182 + /* Enable SPI */ 183 + rb4xx_write(rbspi, AR71XX_SPI_REG_FS, AR71XX_SPI_FS_GPIO); 184 + 185 + return 0; 186 + } 187 + 188 + static int rb4xx_spi_remove(struct platform_device *pdev) 189 + { 190 + struct rb4xx_spi *rbspi = platform_get_drvdata(pdev); 191 + 192 + clk_disable_unprepare(rbspi->clk); 193 + 194 + return 0; 195 + } 196 + 197 + static struct platform_driver rb4xx_spi_drv = { 198 + .probe = rb4xx_spi_probe, 199 + .remove = rb4xx_spi_remove, 200 + .driver = { 201 + .name = "rb4xx-spi", 202 + }, 203 + }; 204 + 205 + module_platform_driver(rb4xx_spi_drv); 206 + 207 + MODULE_DESCRIPTION("Mikrotik RB4xx SPI controller driver"); 208 + MODULE_AUTHOR("Gabor Juhos <juhosg@openwrt.org>"); 209 + MODULE_AUTHOR("Bert Vermeulen <bert@biot.com>"); 210 + MODULE_LICENSE("GPL v2");
+8 -15
drivers/spi/spi-rspi.c
··· 665 665 static int rspi_dma_check_then_transfer(struct rspi_data *rspi, 666 666 struct spi_transfer *xfer) 667 667 { 668 - if (rspi->master->can_dma && __rspi_can_dma(rspi, xfer)) { 669 - /* rx_buf can be NULL on RSPI on SH in TX-only Mode */ 670 - int ret = rspi_dma_transfer(rspi, &xfer->tx_sg, 671 - xfer->rx_buf ? &xfer->rx_sg : NULL); 672 - if (ret != -EAGAIN) 673 - return 0; 674 - } 668 + if (!rspi->master->can_dma || !__rspi_can_dma(rspi, xfer)) 669 + return -EAGAIN; 675 670 676 - return -EAGAIN; 671 + /* rx_buf can be NULL on RSPI on SH in TX-only Mode */ 672 + return rspi_dma_transfer(rspi, &xfer->tx_sg, 673 + xfer->rx_buf ? &xfer->rx_sg : NULL); 677 674 } 678 675 679 676 static int rspi_common_transfer(struct rspi_data *rspi, ··· 721 724 return rspi_common_transfer(rspi, xfer); 722 725 } 723 726 724 - static int qspi_trigger_transfer_out_int(struct rspi_data *rspi, const u8 *tx, 727 + static int qspi_trigger_transfer_out_in(struct rspi_data *rspi, const u8 *tx, 725 728 u8 *rx, unsigned int len) 726 729 { 727 730 int i, n, ret; ··· 768 771 if (ret != -EAGAIN) 769 772 return ret; 770 773 771 - ret = qspi_trigger_transfer_out_int(rspi, xfer->tx_buf, 774 + return qspi_trigger_transfer_out_in(rspi, xfer->tx_buf, 772 775 xfer->rx_buf, xfer->len); 773 - if (ret < 0) 774 - return ret; 775 - 776 - return 0; 777 776 } 778 777 779 778 static int qspi_transfer_out(struct rspi_data *rspi, struct spi_transfer *xfer) ··· 1293 1300 return ret; 1294 1301 } 1295 1302 1296 - static struct platform_device_id spi_driver_ids[] = { 1303 + static const struct platform_device_id spi_driver_ids[] = { 1297 1304 { "rspi", (kernel_ulong_t)&rspi_ops }, 1298 1305 { "rspi-rz", (kernel_ulong_t)&rspi_rz_ops }, 1299 1306 { "qspi", (kernel_ulong_t)&qspi_ops },
+1 -1
drivers/spi/spi-s3c64xx.c
··· 1347 1347 .quirks = S3C64XX_SPI_QUIRK_CS_AUTO, 1348 1348 }; 1349 1349 1350 - static struct platform_device_id s3c64xx_spi_driver_ids[] = { 1350 + static const struct platform_device_id s3c64xx_spi_driver_ids[] = { 1351 1351 { 1352 1352 .name = "s3c2443-spi", 1353 1353 .driver_data = (kernel_ulong_t)&s3c2443_spi_port_config,
+1 -1
drivers/spi/spi-sh-msiof.c
··· 1263 1263 return 0; 1264 1264 } 1265 1265 1266 - static struct platform_device_id spi_driver_ids[] = { 1266 + static const struct platform_device_id spi_driver_ids[] = { 1267 1267 { "spi_sh_msiof", (kernel_ulong_t)&sh_data }, 1268 1268 { "spi_r8a7790_msiof", (kernel_ulong_t)&r8a779x_data }, 1269 1269 { "spi_r8a7791_msiof", (kernel_ulong_t)&r8a779x_data },
+2 -1
include/linux/pxa2xx_ssp.h
··· 194 194 PXA168_SSP, 195 195 PXA910_SSP, 196 196 CE4100_SSP, 197 - LPSS_SSP, 198 197 QUARK_X1000_SSP, 198 + LPSS_LPT_SSP, /* Keep LPSS types sorted with lpss_platforms[] */ 199 + LPSS_BYT_SSP, 199 200 }; 200 201 201 202 struct ssp_device {