···4242- interrupts : should contain eSPI interrupt, the device has one interrupt.4343- fsl,espi-num-chipselects : the number of the chipselect signals.44444545+Optional properties:4646+- fsl,csbef: chip select assertion time in bits before frame starts4747+- fsl,csaft: chip select negation time in bits after frame ends4848+4549Example:4650 spi@110000 {4751 #address-cells = <1>;···5551 interrupts = <53 0x2>;5652 interrupt-parent = <&mpic>;5753 fsl,espi-num-chipselects = <4>;5454+ fsl,csbef = <1>;5555+ fsl,csaft = <1>;5856 };
+24
Documentation/devicetree/bindings/spi/spi-dw.txt
···11+Synopsys DesignWare SPI master22+33+Required properties:44+- compatible: should be "snps,designware-spi"55+- #address-cells: see spi-bus.txt66+- #size-cells: see spi-bus.txt77+- reg: address and length of the spi master registers88+- interrupts: should contain one interrupt99+- clocks: spi clock phandle1010+- num-cs: see spi-bus.txt1111+1212+Optional properties:1313+- cs-gpios: see spi-bus.txt1414+1515+Example:1616+1717+spi: spi@4020a000 {1818+ compatible = "snps,designware-spi";1919+ interrupts = <11 1>;2020+ reg = <0x4020a000 0x1000>;2121+ clocks = <&pclk>;2222+ num-cs = <2>;2323+ cs-gpios = <&banka 0 0>;2424+};
+22
drivers/spi/spi-dw-mmio.c
···1616#include <linux/spi/spi.h>1717#include <linux/scatterlist.h>1818#include <linux/module.h>1919+#include <linux/of_gpio.h>19202021#include "spi-dw.h"2122···7069 dws->bus_num = pdev->id;7170 dws->num_cs = 4;7271 dws->max_freq = clk_get_rate(dwsmmio->clk);7272+7373+ if (pdev->dev.of_node) {7474+ int i;7575+7676+ for (i = 0; i < dws->num_cs; i++) {7777+ int cs_gpio = of_get_named_gpio(pdev->dev.of_node,7878+ "cs-gpios", i);7979+8080+ if (cs_gpio == -EPROBE_DEFER) {8181+ ret = cs_gpio;8282+ goto out;8383+ }8484+8585+ if (gpio_is_valid(cs_gpio)) {8686+ ret = devm_gpio_request(&pdev->dev, cs_gpio,8787+ dev_name(&pdev->dev));8888+ if (ret)8989+ goto out;9090+ }9191+ }9292+ }73937494 ret = dw_spi_add_host(&pdev->dev, dws);7595 if (ret)
+22-175
drivers/spi/spi-dw.c
···2424#include <linux/delay.h>2525#include <linux/slab.h>2626#include <linux/spi/spi.h>2727+#include <linux/gpio.h>27282829#include "spi-dw.h"2930···3635#define RUNNING_STATE ((void *)1)3736#define DONE_STATE ((void *)2)3837#define ERROR_STATE ((void *)-1)3939-4040-#define QUEUE_RUNNING 04141-#define QUEUE_STOPPED 14242-4343-#define MRST_SPI_DEASSERT 04444-#define MRST_SPI_ASSERT 145384639/* Slave spi_dev related */4740struct chip_data {···258263static void giveback(struct dw_spi *dws)259264{260265 struct spi_transfer *last_transfer;261261- unsigned long flags;262266 struct spi_message *msg;263267264264- spin_lock_irqsave(&dws->lock, flags);265268 msg = dws->cur_msg;266269 dws->cur_msg = NULL;267270 dws->cur_transfer = NULL;268271 dws->prev_chip = dws->cur_chip;269272 dws->cur_chip = NULL;270273 dws->dma_mapped = 0;271271- queue_work(dws->workqueue, &dws->pump_messages);272272- spin_unlock_irqrestore(&dws->lock, flags);273274274275 last_transfer = list_last_entry(&msg->transfers, struct spi_transfer,275276 transfer_list);276277277277- if (!last_transfer->cs_change && dws->cs_control)278278- dws->cs_control(MRST_SPI_DEASSERT);278278+ if (!last_transfer->cs_change)279279+ spi_chip_sel(dws, dws->cur_msg->spi, 0);279280280280- msg->state = NULL;281281- if (msg->complete)282282- msg->complete(msg->context);281281+ spi_finalize_current_message(dws->master);283282}284283285284static void int_error_stop(struct dw_spi *dws, const char *msg)···491502 dw_writew(dws, DW_SPI_CTRL0, cr0);492503493504 spi_set_clk(dws, clk_div ? clk_div : chip->clk_div);494494- spi_chip_sel(dws, spi->chip_select);505505+ spi_chip_sel(dws, spi, 1);495506496507 /* Set the interrupt mask, for poll mode just disable all int */497508 spi_mask_intr(dws, 0xff);···518529 return;519530}520531521521-static void pump_messages(struct work_struct *work)532532+static int dw_spi_transfer_one_message(struct spi_master *master,533533+ struct spi_message *msg)522534{523523- struct dw_spi *dws =524524- container_of(work, struct dw_spi, pump_messages);525525- unsigned long flags;535535+ struct dw_spi *dws = spi_master_get_devdata(master);526536527527- /* Lock queue and check for queue work */528528- spin_lock_irqsave(&dws->lock, flags);529529- if (list_empty(&dws->queue) || dws->run == QUEUE_STOPPED) {530530- dws->busy = 0;531531- spin_unlock_irqrestore(&dws->lock, flags);532532- return;533533- }534534-535535- /* Make sure we are not already running a message */536536- if (dws->cur_msg) {537537- spin_unlock_irqrestore(&dws->lock, flags);538538- return;539539- }540540-541541- /* Extract head of queue */542542- dws->cur_msg = list_entry(dws->queue.next, struct spi_message, queue);543543- list_del_init(&dws->cur_msg->queue);544544-537537+ dws->cur_msg = msg;545538 /* Initial message state*/546539 dws->cur_msg->state = START_STATE;547540 dws->cur_transfer = list_entry(dws->cur_msg->transfers.next,···531560 transfer_list);532561 dws->cur_chip = spi_get_ctldata(dws->cur_msg->spi);533562534534- /* Mark as busy and launch transfers */563563+ /* Launch transfers */535564 tasklet_schedule(&dws->pump_transfers);536565537537- dws->busy = 1;538538- spin_unlock_irqrestore(&dws->lock, flags);539539-}540540-541541-/* spi_device use this to queue in their spi_msg */542542-static int dw_spi_transfer(struct spi_device *spi, struct spi_message *msg)543543-{544544- struct dw_spi *dws = spi_master_get_devdata(spi->master);545545- unsigned long flags;546546-547547- spin_lock_irqsave(&dws->lock, flags);548548-549549- if (dws->run == QUEUE_STOPPED) {550550- spin_unlock_irqrestore(&dws->lock, flags);551551- return -ESHUTDOWN;552552- }553553-554554- msg->actual_length = 0;555555- msg->status = -EINPROGRESS;556556- msg->state = START_STATE;557557-558558- list_add_tail(&msg->queue, &dws->queue);559559-560560- if (dws->run == QUEUE_RUNNING && !dws->busy) {561561-562562- if (dws->cur_transfer || dws->cur_msg)563563- queue_work(dws->workqueue,564564- &dws->pump_messages);565565- else {566566- /* If no other data transaction in air, just go */567567- spin_unlock_irqrestore(&dws->lock, flags);568568- pump_messages(&dws->pump_messages);569569- return 0;570570- }571571- }572572-573573- spin_unlock_irqrestore(&dws->lock, flags);574566 return 0;575567}576568···542608{543609 struct dw_spi_chip *chip_info = NULL;544610 struct chip_data *chip;611611+ int ret;545612546613 /* Only alloc on first setup */547614 chip = spi_get_ctldata(spi);···596661 | (spi->mode << SPI_MODE_OFFSET)597662 | (chip->tmode << SPI_TMOD_OFFSET);598663599599- return 0;600600-}601601-602602-static int init_queue(struct dw_spi *dws)603603-{604604- INIT_LIST_HEAD(&dws->queue);605605- spin_lock_init(&dws->lock);606606-607607- dws->run = QUEUE_STOPPED;608608- dws->busy = 0;609609-610610- tasklet_init(&dws->pump_transfers,611611- pump_transfers, (unsigned long)dws);612612-613613- INIT_WORK(&dws->pump_messages, pump_messages);614614- dws->workqueue = create_singlethread_workqueue(615615- dev_name(dws->master->dev.parent));616616- if (dws->workqueue == NULL)617617- return -EBUSY;618618-619619- return 0;620620-}621621-622622-static int start_queue(struct dw_spi *dws)623623-{624624- unsigned long flags;625625-626626- spin_lock_irqsave(&dws->lock, flags);627627-628628- if (dws->run == QUEUE_RUNNING || dws->busy) {629629- spin_unlock_irqrestore(&dws->lock, flags);630630- return -EBUSY;664664+ if (gpio_is_valid(spi->cs_gpio)) {665665+ ret = gpio_direction_output(spi->cs_gpio,666666+ !(spi->mode & SPI_CS_HIGH));667667+ if (ret)668668+ return ret;631669 }632670633633- dws->run = QUEUE_RUNNING;634634- dws->cur_msg = NULL;635635- dws->cur_transfer = NULL;636636- dws->cur_chip = NULL;637637- dws->prev_chip = NULL;638638- spin_unlock_irqrestore(&dws->lock, flags);639639-640640- queue_work(dws->workqueue, &dws->pump_messages);641641-642642- return 0;643643-}644644-645645-static int stop_queue(struct dw_spi *dws)646646-{647647- unsigned long flags;648648- unsigned limit = 50;649649- int status = 0;650650-651651- spin_lock_irqsave(&dws->lock, flags);652652- dws->run = QUEUE_STOPPED;653653- while ((!list_empty(&dws->queue) || dws->busy) && limit--) {654654- spin_unlock_irqrestore(&dws->lock, flags);655655- msleep(10);656656- spin_lock_irqsave(&dws->lock, flags);657657- }658658-659659- if (!list_empty(&dws->queue) || dws->busy)660660- status = -EBUSY;661661- spin_unlock_irqrestore(&dws->lock, flags);662662-663663- return status;664664-}665665-666666-static int destroy_queue(struct dw_spi *dws)667667-{668668- int status;669669-670670- status = stop_queue(dws);671671- if (status != 0)672672- return status;673673- destroy_workqueue(dws->workqueue);674671 return 0;675672}676673···661794 master->bus_num = dws->bus_num;662795 master->num_chipselect = dws->num_cs;663796 master->setup = dw_spi_setup;664664- master->transfer = dw_spi_transfer;797797+ master->transfer_one_message = dw_spi_transfer_one_message;665798 master->max_speed_hz = dws->max_freq;666799667800 /* Basic HW init */···675808 }676809 }677810678678- /* Initial and start queue */679679- ret = init_queue(dws);680680- if (ret) {681681- dev_err(&master->dev, "problem initializing queue\n");682682- goto err_diable_hw;683683- }684684- ret = start_queue(dws);685685- if (ret) {686686- dev_err(&master->dev, "problem starting queue\n");687687- goto err_diable_hw;688688- }811811+ tasklet_init(&dws->pump_transfers, pump_transfers, (unsigned long)dws);689812690813 spi_master_set_devdata(master, dws);691814 ret = devm_spi_register_master(dev, master);692815 if (ret) {693816 dev_err(&master->dev, "problem registering spi master\n");694694- goto err_queue_alloc;817817+ goto err_dma_exit;695818 }696819697820 mrst_spi_debugfs_init(dws);698821 return 0;699822700700-err_queue_alloc:701701- destroy_queue(dws);823823+err_dma_exit:702824 if (dws->dma_ops && dws->dma_ops->dma_exit)703825 dws->dma_ops->dma_exit(dws);704704-err_diable_hw:705826 spi_enable_chip(dws, 0);706827err_free_master:707828 spi_master_put(master);···699844700845void dw_spi_remove_host(struct dw_spi *dws)701846{702702- int status = 0;703703-704847 if (!dws)705848 return;706849 mrst_spi_debugfs_remove(dws);707707-708708- /* Remove the queue */709709- status = destroy_queue(dws);710710- if (status != 0)711711- dev_err(&dws->master->dev,712712- "dw_spi_remove: workqueue will not complete, message memory not freed\n");713850714851 if (dws->dma_ops && dws->dma_ops->dma_exit)715852 dws->dma_ops->dma_exit(dws);···715868{716869 int ret = 0;717870718718- ret = stop_queue(dws);871871+ ret = spi_master_suspend(dws->master);719872 if (ret)720873 return ret;721874 spi_enable_chip(dws, 0);···729882 int ret;730883731884 spi_hw_init(dws);732732- ret = start_queue(dws);885885+ ret = spi_master_resume(dws->master);733886 if (ret)734887 dev_err(&dws->master->dev, "fail to start queue (%d)\n", ret);735888 return ret;