···395395 help396396 This selects a driver for the PPC4xx SPI Controller.397397398398-config SPI_PXA2XX_PXADMA399399- bool "PXA2xx SSP legacy PXA DMA API support"400400- depends on SPI_PXA2XX && ARCH_PXA401401- help402402- Enable PXA private legacy DMA API support. Note that this is403403- deprecated in favor of generic DMA engine API.404404-405398config SPI_PXA2XX_DMA406399 def_bool y407407- depends on SPI_PXA2XX && !SPI_PXA2XX_PXADMA400400+ depends on SPI_PXA2XX408401409402config SPI_PXA2XX410403 tristate "PXA2xx SSP SPI master"···422429 Rockchip SPI controller support DMA transport and PIO mode.423430 The main usecase of this controller is to use spi flash as boot424431 device.432432+433433+config SPI_RB4XX434434+ tristate "Mikrotik RB4XX SPI master"435435+ depends on SPI_MASTER && ATH79436436+ help437437+ SPI controller driver for the Mikrotik RB4xx series boards.425438426439config SPI_RSPI427440 tristate "Renesas RSPI/QSPI controller"
···11-/*22- * PXA2xx SPI private DMA support.33- *44- * Copyright (C) 2005 Stephen Street / StreetFire Sound Labs55- *66- * This program is free software; you can redistribute it and/or modify77- * it under the terms of the GNU General Public License as published by88- * the Free Software Foundation; either version 2 of the License, or99- * (at your option) any later version.1010- *1111- * This program is distributed in the hope that it will be useful,1212- * but WITHOUT ANY WARRANTY; without even the implied warranty of1313- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the1414- * GNU General Public License for more details.1515- */1616-1717-#include <linux/delay.h>1818-#include <linux/device.h>1919-#include <linux/dma-mapping.h>2020-#include <linux/pxa2xx_ssp.h>2121-#include <linux/spi/spi.h>2222-#include <linux/spi/pxa2xx_spi.h>2323-2424-#include <mach/dma.h>2525-#include "spi-pxa2xx.h"2626-2727-#define DMA_INT_MASK (DCSR_ENDINTR | DCSR_STARTINTR | DCSR_BUSERR)2828-#define RESET_DMA_CHANNEL (DCSR_NODESC | DMA_INT_MASK)2929-3030-bool pxa2xx_spi_dma_is_possible(size_t len)3131-{3232- /* Try to map dma buffer and do a dma transfer if successful, but3333- * only if the length is non-zero and less than MAX_DMA_LEN.3434- *3535- * Zero-length non-descriptor DMA is illegal on PXA2xx; force use3636- * of PIO instead. Care is needed above because the transfer may3737- * have have been passed with buffers that are already dma mapped.3838- * A zero-length transfer in PIO mode will not try to write/read3939- * to/from the buffers4040- *4141- * REVISIT large transfers are exactly where we most want to be4242- * using DMA. If this happens much, split those transfers into4343- * multiple DMA segments rather than forcing PIO.4444- */4545- return len > 0 && len <= MAX_DMA_LEN;4646-}4747-4848-int pxa2xx_spi_map_dma_buffers(struct driver_data *drv_data)4949-{5050- struct spi_message *msg = drv_data->cur_msg;5151- struct device *dev = &msg->spi->dev;5252-5353- if (!drv_data->cur_chip->enable_dma)5454- return 0;5555-5656- if (msg->is_dma_mapped)5757- return drv_data->rx_dma && drv_data->tx_dma;5858-5959- if (!IS_DMA_ALIGNED(drv_data->rx) || !IS_DMA_ALIGNED(drv_data->tx))6060- return 0;6161-6262- /* Modify setup if rx buffer is null */6363- if (drv_data->rx == NULL) {6464- *drv_data->null_dma_buf = 0;6565- drv_data->rx = drv_data->null_dma_buf;6666- drv_data->rx_map_len = 4;6767- } else6868- drv_data->rx_map_len = drv_data->len;6969-7070-7171- /* Modify setup if tx buffer is null */7272- if (drv_data->tx == NULL) {7373- *drv_data->null_dma_buf = 0;7474- drv_data->tx = drv_data->null_dma_buf;7575- drv_data->tx_map_len = 4;7676- } else7777- drv_data->tx_map_len = drv_data->len;7878-7979- /* Stream map the tx buffer. Always do DMA_TO_DEVICE first8080- * so we flush the cache *before* invalidating it, in case8181- * the tx and rx buffers overlap.8282- */8383- drv_data->tx_dma = dma_map_single(dev, drv_data->tx,8484- drv_data->tx_map_len, DMA_TO_DEVICE);8585- if (dma_mapping_error(dev, drv_data->tx_dma))8686- return 0;8787-8888- /* Stream map the rx buffer */8989- drv_data->rx_dma = dma_map_single(dev, drv_data->rx,9090- drv_data->rx_map_len, DMA_FROM_DEVICE);9191- if (dma_mapping_error(dev, drv_data->rx_dma)) {9292- dma_unmap_single(dev, drv_data->tx_dma,9393- drv_data->tx_map_len, DMA_TO_DEVICE);9494- return 0;9595- }9696-9797- return 1;9898-}9999-100100-static void pxa2xx_spi_unmap_dma_buffers(struct driver_data *drv_data)101101-{102102- struct device *dev;103103-104104- if (!drv_data->dma_mapped)105105- return;106106-107107- if (!drv_data->cur_msg->is_dma_mapped) {108108- dev = &drv_data->cur_msg->spi->dev;109109- dma_unmap_single(dev, drv_data->rx_dma,110110- drv_data->rx_map_len, DMA_FROM_DEVICE);111111- dma_unmap_single(dev, drv_data->tx_dma,112112- drv_data->tx_map_len, DMA_TO_DEVICE);113113- }114114-115115- drv_data->dma_mapped = 0;116116-}117117-118118-static int wait_ssp_rx_stall(struct driver_data *drv_data)119119-{120120- unsigned long limit = loops_per_jiffy << 1;121121-122122- while ((pxa2xx_spi_read(drv_data, SSSR) & SSSR_BSY) && --limit)123123- cpu_relax();124124-125125- return limit;126126-}127127-128128-static int wait_dma_channel_stop(int channel)129129-{130130- unsigned long limit = loops_per_jiffy << 1;131131-132132- while (!(DCSR(channel) & DCSR_STOPSTATE) && --limit)133133- cpu_relax();134134-135135- return limit;136136-}137137-138138-static void pxa2xx_spi_dma_error_stop(struct driver_data *drv_data,139139- const char *msg)140140-{141141- /* Stop and reset */142142- DCSR(drv_data->rx_channel) = RESET_DMA_CHANNEL;143143- DCSR(drv_data->tx_channel) = RESET_DMA_CHANNEL;144144- write_SSSR_CS(drv_data, drv_data->clear_sr);145145- pxa2xx_spi_write(drv_data, SSCR1,146146- pxa2xx_spi_read(drv_data, SSCR1)147147- & ~drv_data->dma_cr1);148148- if (!pxa25x_ssp_comp(drv_data))149149- pxa2xx_spi_write(drv_data, SSTO, 0);150150- pxa2xx_spi_flush(drv_data);151151- pxa2xx_spi_write(drv_data, SSCR0,152152- pxa2xx_spi_read(drv_data, SSCR0) & ~SSCR0_SSE);153153-154154- pxa2xx_spi_unmap_dma_buffers(drv_data);155155-156156- dev_err(&drv_data->pdev->dev, "%s\n", msg);157157-158158- drv_data->cur_msg->state = ERROR_STATE;159159- tasklet_schedule(&drv_data->pump_transfers);160160-}161161-162162-static void pxa2xx_spi_dma_transfer_complete(struct driver_data *drv_data)163163-{164164- struct spi_message *msg = drv_data->cur_msg;165165-166166- /* Clear and disable interrupts on SSP and DMA channels*/167167- pxa2xx_spi_write(drv_data, SSCR1,168168- pxa2xx_spi_read(drv_data, SSCR1)169169- & ~drv_data->dma_cr1);170170- write_SSSR_CS(drv_data, drv_data->clear_sr);171171- DCSR(drv_data->tx_channel) = RESET_DMA_CHANNEL;172172- DCSR(drv_data->rx_channel) = RESET_DMA_CHANNEL;173173-174174- if (wait_dma_channel_stop(drv_data->rx_channel) == 0)175175- dev_err(&drv_data->pdev->dev,176176- "dma_handler: dma rx channel stop failed\n");177177-178178- if (wait_ssp_rx_stall(drv_data->ioaddr) == 0)179179- dev_err(&drv_data->pdev->dev,180180- "dma_transfer: ssp rx stall failed\n");181181-182182- pxa2xx_spi_unmap_dma_buffers(drv_data);183183-184184- /* update the buffer pointer for the amount completed in dma */185185- drv_data->rx += drv_data->len -186186- (DCMD(drv_data->rx_channel) & DCMD_LENGTH);187187-188188- /* read trailing data from fifo, it does not matter how many189189- * bytes are in the fifo just read until buffer is full190190- * or fifo is empty, which ever occurs first */191191- drv_data->read(drv_data);192192-193193- /* return count of what was actually read */194194- msg->actual_length += drv_data->len -195195- (drv_data->rx_end - drv_data->rx);196196-197197- /* Transfer delays and chip select release are198198- * handled in pump_transfers or giveback199199- */200200-201201- /* Move to next transfer */202202- msg->state = pxa2xx_spi_next_transfer(drv_data);203203-204204- /* Schedule transfer tasklet */205205- tasklet_schedule(&drv_data->pump_transfers);206206-}207207-208208-void pxa2xx_spi_dma_handler(int channel, void *data)209209-{210210- struct driver_data *drv_data = data;211211- u32 irq_status = DCSR(channel) & DMA_INT_MASK;212212-213213- if (irq_status & DCSR_BUSERR) {214214-215215- if (channel == drv_data->tx_channel)216216- pxa2xx_spi_dma_error_stop(drv_data,217217- "dma_handler: bad bus address on tx channel");218218- else219219- pxa2xx_spi_dma_error_stop(drv_data,220220- "dma_handler: bad bus address on rx channel");221221- return;222222- }223223-224224- /* PXA255x_SSP has no timeout interrupt, wait for tailing bytes */225225- if ((channel == drv_data->tx_channel)226226- && (irq_status & DCSR_ENDINTR)227227- && (drv_data->ssp_type == PXA25x_SSP)) {228228-229229- /* Wait for rx to stall */230230- if (wait_ssp_rx_stall(drv_data) == 0)231231- dev_err(&drv_data->pdev->dev,232232- "dma_handler: ssp rx stall failed\n");233233-234234- /* finish this transfer, start the next */235235- pxa2xx_spi_dma_transfer_complete(drv_data);236236- }237237-}238238-239239-irqreturn_t pxa2xx_spi_dma_transfer(struct driver_data *drv_data)240240-{241241- u32 irq_status;242242-243243- irq_status = pxa2xx_spi_read(drv_data, SSSR) & drv_data->mask_sr;244244- if (irq_status & SSSR_ROR) {245245- pxa2xx_spi_dma_error_stop(drv_data,246246- "dma_transfer: fifo overrun");247247- return IRQ_HANDLED;248248- }249249-250250- /* Check for false positive timeout */251251- if ((irq_status & SSSR_TINT)252252- && (DCSR(drv_data->tx_channel) & DCSR_RUN)) {253253- pxa2xx_spi_write(drv_data, SSSR, SSSR_TINT);254254- return IRQ_HANDLED;255255- }256256-257257- if (irq_status & SSSR_TINT || drv_data->rx == drv_data->rx_end) {258258-259259- /* Clear and disable timeout interrupt, do the rest in260260- * dma_transfer_complete */261261- if (!pxa25x_ssp_comp(drv_data))262262- pxa2xx_spi_write(drv_data, SSTO, 0);263263-264264- /* finish this transfer, start the next */265265- pxa2xx_spi_dma_transfer_complete(drv_data);266266-267267- return IRQ_HANDLED;268268- }269269-270270- /* Opps problem detected */271271- return IRQ_NONE;272272-}273273-274274-int pxa2xx_spi_dma_prepare(struct driver_data *drv_data, u32 dma_burst)275275-{276276- u32 dma_width;277277-278278- switch (drv_data->n_bytes) {279279- case 1:280280- dma_width = DCMD_WIDTH1;281281- break;282282- case 2:283283- dma_width = DCMD_WIDTH2;284284- break;285285- default:286286- dma_width = DCMD_WIDTH4;287287- break;288288- }289289-290290- /* Setup rx DMA Channel */291291- DCSR(drv_data->rx_channel) = RESET_DMA_CHANNEL;292292- DSADR(drv_data->rx_channel) = drv_data->ssdr_physical;293293- DTADR(drv_data->rx_channel) = drv_data->rx_dma;294294- if (drv_data->rx == drv_data->null_dma_buf)295295- /* No target address increment */296296- DCMD(drv_data->rx_channel) = DCMD_FLOWSRC297297- | dma_width298298- | dma_burst299299- | drv_data->len;300300- else301301- DCMD(drv_data->rx_channel) = DCMD_INCTRGADDR302302- | DCMD_FLOWSRC303303- | dma_width304304- | dma_burst305305- | drv_data->len;306306-307307- /* Setup tx DMA Channel */308308- DCSR(drv_data->tx_channel) = RESET_DMA_CHANNEL;309309- DSADR(drv_data->tx_channel) = drv_data->tx_dma;310310- DTADR(drv_data->tx_channel) = drv_data->ssdr_physical;311311- if (drv_data->tx == drv_data->null_dma_buf)312312- /* No source address increment */313313- DCMD(drv_data->tx_channel) = DCMD_FLOWTRG314314- | dma_width315315- | dma_burst316316- | drv_data->len;317317- else318318- DCMD(drv_data->tx_channel) = DCMD_INCSRCADDR319319- | DCMD_FLOWTRG320320- | dma_width321321- | dma_burst322322- | drv_data->len;323323-324324- /* Enable dma end irqs on SSP to detect end of transfer */325325- if (drv_data->ssp_type == PXA25x_SSP)326326- DCMD(drv_data->tx_channel) |= DCMD_ENDIRQEN;327327-328328- return 0;329329-}330330-331331-void pxa2xx_spi_dma_start(struct driver_data *drv_data)332332-{333333- DCSR(drv_data->rx_channel) |= DCSR_RUN;334334- DCSR(drv_data->tx_channel) |= DCSR_RUN;335335-}336336-337337-int pxa2xx_spi_dma_setup(struct driver_data *drv_data)338338-{339339- struct device *dev = &drv_data->pdev->dev;340340- struct ssp_device *ssp = drv_data->ssp;341341-342342- /* Get two DMA channels (rx and tx) */343343- drv_data->rx_channel = pxa_request_dma("pxa2xx_spi_ssp_rx",344344- DMA_PRIO_HIGH,345345- pxa2xx_spi_dma_handler,346346- drv_data);347347- if (drv_data->rx_channel < 0) {348348- dev_err(dev, "problem (%d) requesting rx channel\n",349349- drv_data->rx_channel);350350- return -ENODEV;351351- }352352- drv_data->tx_channel = pxa_request_dma("pxa2xx_spi_ssp_tx",353353- DMA_PRIO_MEDIUM,354354- pxa2xx_spi_dma_handler,355355- drv_data);356356- if (drv_data->tx_channel < 0) {357357- dev_err(dev, "problem (%d) requesting tx channel\n",358358- drv_data->tx_channel);359359- pxa_free_dma(drv_data->rx_channel);360360- return -ENODEV;361361- }362362-363363- DRCMR(ssp->drcmr_rx) = DRCMR_MAPVLD | drv_data->rx_channel;364364- DRCMR(ssp->drcmr_tx) = DRCMR_MAPVLD | drv_data->tx_channel;365365-366366- return 0;367367-}368368-369369-void pxa2xx_spi_dma_release(struct driver_data *drv_data)370370-{371371- struct ssp_device *ssp = drv_data->ssp;372372-373373- DRCMR(ssp->drcmr_rx) = 0;374374- DRCMR(ssp->drcmr_tx) = 0;375375-376376- if (drv_data->tx_channel != 0)377377- pxa_free_dma(drv_data->tx_channel);378378- if (drv_data->rx_channel != 0)379379- pxa_free_dma(drv_data->rx_channel);380380-}381381-382382-void pxa2xx_spi_dma_resume(struct driver_data *drv_data)383383-{384384- if (drv_data->rx_channel != -1)385385- DRCMR(drv_data->ssp->drcmr_rx) =386386- DRCMR_MAPVLD | drv_data->rx_channel;387387- if (drv_data->tx_channel != -1)388388- DRCMR(drv_data->ssp->drcmr_tx) =389389- DRCMR_MAPVLD | drv_data->tx_channel;390390-}391391-392392-int pxa2xx_spi_set_dma_burst_and_threshold(struct chip_data *chip,393393- struct spi_device *spi,394394- u8 bits_per_word, u32 *burst_code,395395- u32 *threshold)396396-{397397- struct pxa2xx_spi_chip *chip_info =398398- (struct pxa2xx_spi_chip *)spi->controller_data;399399- int bytes_per_word;400400- int burst_bytes;401401- int thresh_words;402402- int req_burst_size;403403- int retval = 0;404404-405405- /* Set the threshold (in registers) to equal the same amount of data406406- * as represented by burst size (in bytes). The computation below407407- * is (burst_size rounded up to nearest 8 byte, word or long word)408408- * divided by (bytes/register); the tx threshold is the inverse of409409- * the rx, so that there will always be enough data in the rx fifo410410- * to satisfy a burst, and there will always be enough space in the411411- * tx fifo to accept a burst (a tx burst will overwrite the fifo if412412- * there is not enough space), there must always remain enough empty413413- * space in the rx fifo for any data loaded to the tx fifo.414414- * Whenever burst_size (in bytes) equals bits/word, the fifo threshold415415- * will be 8, or half the fifo;416416- * The threshold can only be set to 2, 4 or 8, but not 16, because417417- * to burst 16 to the tx fifo, the fifo would have to be empty;418418- * however, the minimum fifo trigger level is 1, and the tx will419419- * request service when the fifo is at this level, with only 15 spaces.420420- */421421-422422- /* find bytes/word */423423- if (bits_per_word <= 8)424424- bytes_per_word = 1;425425- else if (bits_per_word <= 16)426426- bytes_per_word = 2;427427- else428428- bytes_per_word = 4;429429-430430- /* use struct pxa2xx_spi_chip->dma_burst_size if available */431431- if (chip_info)432432- req_burst_size = chip_info->dma_burst_size;433433- else {434434- switch (chip->dma_burst_size) {435435- default:436436- /* if the default burst size is not set,437437- * do it now */438438- chip->dma_burst_size = DCMD_BURST8;439439- case DCMD_BURST8:440440- req_burst_size = 8;441441- break;442442- case DCMD_BURST16:443443- req_burst_size = 16;444444- break;445445- case DCMD_BURST32:446446- req_burst_size = 32;447447- break;448448- }449449- }450450- if (req_burst_size <= 8) {451451- *burst_code = DCMD_BURST8;452452- burst_bytes = 8;453453- } else if (req_burst_size <= 16) {454454- if (bytes_per_word == 1) {455455- /* don't burst more than 1/2 the fifo */456456- *burst_code = DCMD_BURST8;457457- burst_bytes = 8;458458- retval = 1;459459- } else {460460- *burst_code = DCMD_BURST16;461461- burst_bytes = 16;462462- }463463- } else {464464- if (bytes_per_word == 1) {465465- /* don't burst more than 1/2 the fifo */466466- *burst_code = DCMD_BURST8;467467- burst_bytes = 8;468468- retval = 1;469469- } else if (bytes_per_word == 2) {470470- /* don't burst more than 1/2 the fifo */471471- *burst_code = DCMD_BURST16;472472- burst_bytes = 16;473473- retval = 1;474474- } else {475475- *burst_code = DCMD_BURST32;476476- burst_bytes = 32;477477- }478478- }479479-480480- thresh_words = burst_bytes / bytes_per_word;481481-482482- /* thresh_words will be between 2 and 8 */483483- *threshold = (SSCR1_RxTresh(thresh_words) & SSCR1_RFT)484484- | (SSCR1_TxTresh(16-thresh_words) & SSCR1_TFT);485485-486486- return retval;487487-}