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

Configure Feed

Select the types of activity you want to include in your feed.

Merge remote-tracking branches 'spi/topic/dw', 'spi/topic/fsl', 'spi/topic/fsl-espi' and 'spi/topic/id-const' into spi-next

+125 -209
+6
Documentation/devicetree/bindings/spi/fsl-spi.txt
··· 42 42 - interrupts : should contain eSPI interrupt, the device has one interrupt. 43 43 - fsl,espi-num-chipselects : the number of the chipselect signals. 44 44 45 + Optional properties: 46 + - fsl,csbef: chip select assertion time in bits before frame starts 47 + - fsl,csaft: chip select negation time in bits after frame ends 48 + 45 49 Example: 46 50 spi@110000 { 47 51 #address-cells = <1>; ··· 55 51 interrupts = <53 0x2>; 56 52 interrupt-parent = <&mpic>; 57 53 fsl,espi-num-chipselects = <4>; 54 + fsl,csbef = <1>; 55 + fsl,csaft = <1>; 58 56 };
+24
Documentation/devicetree/bindings/spi/spi-dw.txt
··· 1 + Synopsys DesignWare SPI master 2 + 3 + Required properties: 4 + - compatible: should be "snps,designware-spi" 5 + - #address-cells: see spi-bus.txt 6 + - #size-cells: see spi-bus.txt 7 + - reg: address and length of the spi master registers 8 + - interrupts: should contain one interrupt 9 + - clocks: spi clock phandle 10 + - num-cs: see spi-bus.txt 11 + 12 + Optional properties: 13 + - cs-gpios: see spi-bus.txt 14 + 15 + Example: 16 + 17 + spi: spi@4020a000 { 18 + compatible = "snps,designware-spi"; 19 + interrupts = <11 1>; 20 + reg = <0x4020a000 0x1000>; 21 + clocks = <&pclk>; 22 + num-cs = <2>; 23 + cs-gpios = <&banka 0 0>; 24 + };
+22
drivers/spi/spi-dw-mmio.c
··· 16 16 #include <linux/spi/spi.h> 17 17 #include <linux/scatterlist.h> 18 18 #include <linux/module.h> 19 + #include <linux/of_gpio.h> 19 20 20 21 #include "spi-dw.h" 21 22 ··· 70 69 dws->bus_num = pdev->id; 71 70 dws->num_cs = 4; 72 71 dws->max_freq = clk_get_rate(dwsmmio->clk); 72 + 73 + if (pdev->dev.of_node) { 74 + int i; 75 + 76 + for (i = 0; i < dws->num_cs; i++) { 77 + int cs_gpio = of_get_named_gpio(pdev->dev.of_node, 78 + "cs-gpios", i); 79 + 80 + if (cs_gpio == -EPROBE_DEFER) { 81 + ret = cs_gpio; 82 + goto out; 83 + } 84 + 85 + if (gpio_is_valid(cs_gpio)) { 86 + ret = devm_gpio_request(&pdev->dev, cs_gpio, 87 + dev_name(&pdev->dev)); 88 + if (ret) 89 + goto out; 90 + } 91 + } 92 + } 73 93 74 94 ret = dw_spi_add_host(&pdev->dev, dws); 75 95 if (ret)
+22 -175
drivers/spi/spi-dw.c
··· 24 24 #include <linux/delay.h> 25 25 #include <linux/slab.h> 26 26 #include <linux/spi/spi.h> 27 + #include <linux/gpio.h> 27 28 28 29 #include "spi-dw.h" 29 30 ··· 36 35 #define RUNNING_STATE ((void *)1) 37 36 #define DONE_STATE ((void *)2) 38 37 #define ERROR_STATE ((void *)-1) 39 - 40 - #define QUEUE_RUNNING 0 41 - #define QUEUE_STOPPED 1 42 - 43 - #define MRST_SPI_DEASSERT 0 44 - #define MRST_SPI_ASSERT 1 45 38 46 39 /* Slave spi_dev related */ 47 40 struct chip_data { ··· 258 263 static void giveback(struct dw_spi *dws) 259 264 { 260 265 struct spi_transfer *last_transfer; 261 - unsigned long flags; 262 266 struct spi_message *msg; 263 267 264 - spin_lock_irqsave(&dws->lock, flags); 265 268 msg = dws->cur_msg; 266 269 dws->cur_msg = NULL; 267 270 dws->cur_transfer = NULL; 268 271 dws->prev_chip = dws->cur_chip; 269 272 dws->cur_chip = NULL; 270 273 dws->dma_mapped = 0; 271 - queue_work(dws->workqueue, &dws->pump_messages); 272 - spin_unlock_irqrestore(&dws->lock, flags); 273 274 274 275 last_transfer = list_last_entry(&msg->transfers, struct spi_transfer, 275 276 transfer_list); 276 277 277 - if (!last_transfer->cs_change && dws->cs_control) 278 - dws->cs_control(MRST_SPI_DEASSERT); 278 + if (!last_transfer->cs_change) 279 + spi_chip_sel(dws, dws->cur_msg->spi, 0); 279 280 280 - msg->state = NULL; 281 - if (msg->complete) 282 - msg->complete(msg->context); 281 + spi_finalize_current_message(dws->master); 283 282 } 284 283 285 284 static void int_error_stop(struct dw_spi *dws, const char *msg) ··· 491 502 dw_writew(dws, DW_SPI_CTRL0, cr0); 492 503 493 504 spi_set_clk(dws, clk_div ? clk_div : chip->clk_div); 494 - spi_chip_sel(dws, spi->chip_select); 505 + spi_chip_sel(dws, spi, 1); 495 506 496 507 /* Set the interrupt mask, for poll mode just disable all int */ 497 508 spi_mask_intr(dws, 0xff); ··· 518 529 return; 519 530 } 520 531 521 - static void pump_messages(struct work_struct *work) 532 + static int dw_spi_transfer_one_message(struct spi_master *master, 533 + struct spi_message *msg) 522 534 { 523 - struct dw_spi *dws = 524 - container_of(work, struct dw_spi, pump_messages); 525 - unsigned long flags; 535 + struct dw_spi *dws = spi_master_get_devdata(master); 526 536 527 - /* Lock queue and check for queue work */ 528 - spin_lock_irqsave(&dws->lock, flags); 529 - if (list_empty(&dws->queue) || dws->run == QUEUE_STOPPED) { 530 - dws->busy = 0; 531 - spin_unlock_irqrestore(&dws->lock, flags); 532 - return; 533 - } 534 - 535 - /* Make sure we are not already running a message */ 536 - if (dws->cur_msg) { 537 - spin_unlock_irqrestore(&dws->lock, flags); 538 - return; 539 - } 540 - 541 - /* Extract head of queue */ 542 - dws->cur_msg = list_entry(dws->queue.next, struct spi_message, queue); 543 - list_del_init(&dws->cur_msg->queue); 544 - 537 + dws->cur_msg = msg; 545 538 /* Initial message state*/ 546 539 dws->cur_msg->state = START_STATE; 547 540 dws->cur_transfer = list_entry(dws->cur_msg->transfers.next, ··· 531 560 transfer_list); 532 561 dws->cur_chip = spi_get_ctldata(dws->cur_msg->spi); 533 562 534 - /* Mark as busy and launch transfers */ 563 + /* Launch transfers */ 535 564 tasklet_schedule(&dws->pump_transfers); 536 565 537 - dws->busy = 1; 538 - spin_unlock_irqrestore(&dws->lock, flags); 539 - } 540 - 541 - /* spi_device use this to queue in their spi_msg */ 542 - static int dw_spi_transfer(struct spi_device *spi, struct spi_message *msg) 543 - { 544 - struct dw_spi *dws = spi_master_get_devdata(spi->master); 545 - unsigned long flags; 546 - 547 - spin_lock_irqsave(&dws->lock, flags); 548 - 549 - if (dws->run == QUEUE_STOPPED) { 550 - spin_unlock_irqrestore(&dws->lock, flags); 551 - return -ESHUTDOWN; 552 - } 553 - 554 - msg->actual_length = 0; 555 - msg->status = -EINPROGRESS; 556 - msg->state = START_STATE; 557 - 558 - list_add_tail(&msg->queue, &dws->queue); 559 - 560 - if (dws->run == QUEUE_RUNNING && !dws->busy) { 561 - 562 - if (dws->cur_transfer || dws->cur_msg) 563 - queue_work(dws->workqueue, 564 - &dws->pump_messages); 565 - else { 566 - /* If no other data transaction in air, just go */ 567 - spin_unlock_irqrestore(&dws->lock, flags); 568 - pump_messages(&dws->pump_messages); 569 - return 0; 570 - } 571 - } 572 - 573 - spin_unlock_irqrestore(&dws->lock, flags); 574 566 return 0; 575 567 } 576 568 ··· 542 608 { 543 609 struct dw_spi_chip *chip_info = NULL; 544 610 struct chip_data *chip; 611 + int ret; 545 612 546 613 /* Only alloc on first setup */ 547 614 chip = spi_get_ctldata(spi); ··· 596 661 | (spi->mode << SPI_MODE_OFFSET) 597 662 | (chip->tmode << SPI_TMOD_OFFSET); 598 663 599 - return 0; 600 - } 601 - 602 - static int init_queue(struct dw_spi *dws) 603 - { 604 - INIT_LIST_HEAD(&dws->queue); 605 - spin_lock_init(&dws->lock); 606 - 607 - dws->run = QUEUE_STOPPED; 608 - dws->busy = 0; 609 - 610 - tasklet_init(&dws->pump_transfers, 611 - pump_transfers, (unsigned long)dws); 612 - 613 - INIT_WORK(&dws->pump_messages, pump_messages); 614 - dws->workqueue = create_singlethread_workqueue( 615 - dev_name(dws->master->dev.parent)); 616 - if (dws->workqueue == NULL) 617 - return -EBUSY; 618 - 619 - return 0; 620 - } 621 - 622 - static int start_queue(struct dw_spi *dws) 623 - { 624 - unsigned long flags; 625 - 626 - spin_lock_irqsave(&dws->lock, flags); 627 - 628 - if (dws->run == QUEUE_RUNNING || dws->busy) { 629 - spin_unlock_irqrestore(&dws->lock, flags); 630 - return -EBUSY; 664 + if (gpio_is_valid(spi->cs_gpio)) { 665 + ret = gpio_direction_output(spi->cs_gpio, 666 + !(spi->mode & SPI_CS_HIGH)); 667 + if (ret) 668 + return ret; 631 669 } 632 670 633 - dws->run = QUEUE_RUNNING; 634 - dws->cur_msg = NULL; 635 - dws->cur_transfer = NULL; 636 - dws->cur_chip = NULL; 637 - dws->prev_chip = NULL; 638 - spin_unlock_irqrestore(&dws->lock, flags); 639 - 640 - queue_work(dws->workqueue, &dws->pump_messages); 641 - 642 - return 0; 643 - } 644 - 645 - static int stop_queue(struct dw_spi *dws) 646 - { 647 - unsigned long flags; 648 - unsigned limit = 50; 649 - int status = 0; 650 - 651 - spin_lock_irqsave(&dws->lock, flags); 652 - dws->run = QUEUE_STOPPED; 653 - while ((!list_empty(&dws->queue) || dws->busy) && limit--) { 654 - spin_unlock_irqrestore(&dws->lock, flags); 655 - msleep(10); 656 - spin_lock_irqsave(&dws->lock, flags); 657 - } 658 - 659 - if (!list_empty(&dws->queue) || dws->busy) 660 - status = -EBUSY; 661 - spin_unlock_irqrestore(&dws->lock, flags); 662 - 663 - return status; 664 - } 665 - 666 - static int destroy_queue(struct dw_spi *dws) 667 - { 668 - int status; 669 - 670 - status = stop_queue(dws); 671 - if (status != 0) 672 - return status; 673 - destroy_workqueue(dws->workqueue); 674 671 return 0; 675 672 } 676 673 ··· 661 794 master->bus_num = dws->bus_num; 662 795 master->num_chipselect = dws->num_cs; 663 796 master->setup = dw_spi_setup; 664 - master->transfer = dw_spi_transfer; 797 + master->transfer_one_message = dw_spi_transfer_one_message; 665 798 master->max_speed_hz = dws->max_freq; 666 799 667 800 /* Basic HW init */ ··· 675 808 } 676 809 } 677 810 678 - /* Initial and start queue */ 679 - ret = init_queue(dws); 680 - if (ret) { 681 - dev_err(&master->dev, "problem initializing queue\n"); 682 - goto err_diable_hw; 683 - } 684 - ret = start_queue(dws); 685 - if (ret) { 686 - dev_err(&master->dev, "problem starting queue\n"); 687 - goto err_diable_hw; 688 - } 811 + tasklet_init(&dws->pump_transfers, pump_transfers, (unsigned long)dws); 689 812 690 813 spi_master_set_devdata(master, dws); 691 814 ret = devm_spi_register_master(dev, master); 692 815 if (ret) { 693 816 dev_err(&master->dev, "problem registering spi master\n"); 694 - goto err_queue_alloc; 817 + goto err_dma_exit; 695 818 } 696 819 697 820 mrst_spi_debugfs_init(dws); 698 821 return 0; 699 822 700 - err_queue_alloc: 701 - destroy_queue(dws); 823 + err_dma_exit: 702 824 if (dws->dma_ops && dws->dma_ops->dma_exit) 703 825 dws->dma_ops->dma_exit(dws); 704 - err_diable_hw: 705 826 spi_enable_chip(dws, 0); 706 827 err_free_master: 707 828 spi_master_put(master); ··· 699 844 700 845 void dw_spi_remove_host(struct dw_spi *dws) 701 846 { 702 - int status = 0; 703 - 704 847 if (!dws) 705 848 return; 706 849 mrst_spi_debugfs_remove(dws); 707 - 708 - /* Remove the queue */ 709 - status = destroy_queue(dws); 710 - if (status != 0) 711 - dev_err(&dws->master->dev, 712 - "dw_spi_remove: workqueue will not complete, message memory not freed\n"); 713 850 714 851 if (dws->dma_ops && dws->dma_ops->dma_exit) 715 852 dws->dma_ops->dma_exit(dws); ··· 715 868 { 716 869 int ret = 0; 717 870 718 - ret = stop_queue(dws); 871 + ret = spi_master_suspend(dws->master); 719 872 if (ret) 720 873 return ret; 721 874 spi_enable_chip(dws, 0); ··· 729 882 int ret; 730 883 731 884 spi_hw_init(dws); 732 - ret = start_queue(dws); 885 + ret = spi_master_resume(dws->master); 733 886 if (ret) 734 887 dev_err(&dws->master->dev, "fail to start queue (%d)\n", ret); 735 888 return ret;
+11 -13
drivers/spi/spi-dw.h
··· 3 3 4 4 #include <linux/io.h> 5 5 #include <linux/scatterlist.h> 6 + #include <linux/gpio.h> 6 7 7 8 /* Register offsets */ 8 9 #define DW_SPI_CTRL0 0x00 ··· 105 104 u16 bus_num; 106 105 u16 num_cs; /* supported slave numbers */ 107 106 108 - /* Driver message queue */ 109 - struct workqueue_struct *workqueue; 110 - struct work_struct pump_messages; 111 - spinlock_t lock; 112 - struct list_head queue; 113 - int busy; 114 - int run; 115 - 116 107 /* Message Transfer pump */ 117 108 struct tasklet_struct pump_transfers; 118 109 ··· 179 186 dw_writel(dws, DW_SPI_BAUDR, div); 180 187 } 181 188 182 - static inline void spi_chip_sel(struct dw_spi *dws, u16 cs) 189 + static inline void spi_chip_sel(struct dw_spi *dws, struct spi_device *spi, 190 + int active) 183 191 { 184 - if (cs > dws->num_cs) 185 - return; 192 + u16 cs = spi->chip_select; 193 + int gpio_val = active ? (spi->mode & SPI_CS_HIGH) : 194 + !(spi->mode & SPI_CS_HIGH); 186 195 187 196 if (dws->cs_control) 188 - dws->cs_control(1); 197 + dws->cs_control(active); 198 + if (gpio_is_valid(spi->cs_gpio)) 199 + gpio_set_value(spi->cs_gpio, gpio_val); 189 200 190 - dw_writel(dws, DW_SPI_SER, 1 << cs); 201 + if (active) 202 + dw_writel(dws, DW_SPI_SER, 1 << cs); 191 203 } 192 204 193 205 /* Disable IRQ bits */
+1 -1
drivers/spi/spi-fsl-dspi.c
··· 406 406 return IRQ_HANDLED; 407 407 } 408 408 409 - static struct of_device_id fsl_dspi_dt_ids[] = { 409 + static const struct of_device_id fsl_dspi_dt_ids[] = { 410 410 { .compatible = "fsl,vf610-dspi", .data = NULL, }, 411 411 { /* sentinel */ } 412 412 };
+33 -7
drivers/spi/spi-fsl-espi.c
··· 348 348 } 349 349 350 350 espi_trans->tx_buf = local_buf; 351 - espi_trans->rx_buf = local_buf + espi_trans->n_tx; 351 + espi_trans->rx_buf = local_buf; 352 352 fsl_espi_do_trans(m, espi_trans); 353 353 354 354 espi_trans->actual_length = espi_trans->len; ··· 397 397 espi_trans->n_rx = trans_len; 398 398 espi_trans->len = trans_len + n_tx; 399 399 espi_trans->tx_buf = local_buf; 400 - espi_trans->rx_buf = local_buf + n_tx; 400 + espi_trans->rx_buf = local_buf; 401 401 fsl_espi_do_trans(m, espi_trans); 402 402 403 403 memcpy(rx_buf + pos, espi_trans->rx_buf + n_tx, trans_len); ··· 458 458 return -EINVAL; 459 459 460 460 if (!cs) { 461 - cs = kzalloc(sizeof *cs, GFP_KERNEL); 461 + cs = devm_kzalloc(&spi->dev, sizeof(*cs), GFP_KERNEL); 462 462 if (!cs) 463 463 return -ENOMEM; 464 464 spi->controller_state = cs; ··· 586 586 struct spi_master *master; 587 587 struct mpc8xxx_spi *mpc8xxx_spi; 588 588 struct fsl_espi_reg *reg_base; 589 - u32 regval; 590 - int i, ret = 0; 589 + struct device_node *nc; 590 + const __be32 *prop; 591 + u32 regval, csmode; 592 + int i, len, ret = 0; 591 593 592 594 master = spi_alloc_master(dev, sizeof(struct mpc8xxx_spi)); 593 595 if (!master) { ··· 636 634 mpc8xxx_spi_write_reg(&reg_base->event, 0xffffffff); 637 635 638 636 /* Init eSPI CS mode register */ 639 - for (i = 0; i < pdata->max_chipselect; i++) 640 - mpc8xxx_spi_write_reg(&reg_base->csmode[i], CSMODE_INIT_VAL); 637 + for_each_available_child_of_node(master->dev.of_node, nc) { 638 + /* get chip select */ 639 + prop = of_get_property(nc, "reg", &len); 640 + if (!prop || len < sizeof(*prop)) 641 + continue; 642 + i = be32_to_cpup(prop); 643 + if (i < 0 || i >= pdata->max_chipselect) 644 + continue; 645 + 646 + csmode = CSMODE_INIT_VAL; 647 + /* check if CSBEF is set in device tree */ 648 + prop = of_get_property(nc, "fsl,csbef", &len); 649 + if (prop && len >= sizeof(*prop)) { 650 + csmode &= ~(CSMODE_BEF(0xf)); 651 + csmode |= CSMODE_BEF(be32_to_cpup(prop)); 652 + } 653 + /* check if CSAFT is set in device tree */ 654 + prop = of_get_property(nc, "fsl,csaft", &len); 655 + if (prop && len >= sizeof(*prop)) { 656 + csmode &= ~(CSMODE_AFT(0xf)); 657 + csmode |= CSMODE_AFT(be32_to_cpup(prop)); 658 + } 659 + mpc8xxx_spi_write_reg(&reg_base->csmode[i], csmode); 660 + 661 + dev_info(dev, "cs=%d, init_csmode=0x%x\n", i, csmode); 662 + } 641 663 642 664 /* Enable SPI interface */ 643 665 regval = pdata->initial_spmode | SPMODE_INIT_VAL | SPMODE_ENABLE;
-6
drivers/spi/spi-fsl-lib.c
··· 99 99 return 0; 100 100 } 101 101 102 - void mpc8xxx_spi_cleanup(struct spi_device *spi) 103 - { 104 - kfree(spi->controller_state); 105 - } 106 - 107 102 const char *mpc8xxx_spi_strmode(unsigned int flags) 108 103 { 109 104 if (flags & SPI_QE_CPU_MODE) { ··· 129 134 | SPI_LSB_FIRST | SPI_LOOP; 130 135 131 136 master->transfer = mpc8xxx_spi_transfer; 132 - master->cleanup = mpc8xxx_spi_cleanup; 133 137 master->dev.of_node = dev->of_node; 134 138 135 139 mpc8xxx_spi = spi_master_get_devdata(master);
-1
drivers/spi/spi-fsl-lib.h
··· 124 124 extern int mpc8xxx_spi_bufs(struct mpc8xxx_spi *mspi, 125 125 struct spi_transfer *t, unsigned int len); 126 126 extern int mpc8xxx_spi_transfer(struct spi_device *spi, struct spi_message *m); 127 - extern void mpc8xxx_spi_cleanup(struct spi_device *spi); 128 127 extern const char *mpc8xxx_spi_strmode(unsigned int flags); 129 128 extern int mpc8xxx_spi_probe(struct device *dev, struct resource *mem, 130 129 unsigned int irq);
+1 -1
drivers/spi/spi-fsl-spi.c
··· 431 431 return -EINVAL; 432 432 433 433 if (!cs) { 434 - cs = kzalloc(sizeof *cs, GFP_KERNEL); 434 + cs = devm_kzalloc(&spi->dev, sizeof(*cs), GFP_KERNEL); 435 435 if (!cs) 436 436 return -ENOMEM; 437 437 spi->controller_state = cs;
+1 -1
drivers/spi/spi-gpio.c
··· 340 340 } 341 341 342 342 #ifdef CONFIG_OF 343 - static struct of_device_id spi_gpio_dt_ids[] = { 343 + static const struct of_device_id spi_gpio_dt_ids[] = { 344 344 { .compatible = "spi-gpio" }, 345 345 {} 346 346 };
+1 -1
drivers/spi/spi-qup.c
··· 749 749 return 0; 750 750 } 751 751 752 - static struct of_device_id spi_qup_dt_match[] = { 752 + static const struct of_device_id spi_qup_dt_match[] = { 753 753 { .compatible = "qcom,spi-qup-v2.1.1", }, 754 754 { .compatible = "qcom,spi-qup-v2.2.1", }, 755 755 { }
+1 -1
drivers/spi/spi-tegra114.c
··· 1012 1012 return IRQ_WAKE_THREAD; 1013 1013 } 1014 1014 1015 - static struct of_device_id tegra_spi_of_match[] = { 1015 + static const struct of_device_id tegra_spi_of_match[] = { 1016 1016 { .compatible = "nvidia,tegra114-spi", }, 1017 1017 {} 1018 1018 };
+1 -1
drivers/spi/spi-tegra20-sflash.c
··· 419 419 return handle_cpu_based_xfer(tsd); 420 420 } 421 421 422 - static struct of_device_id tegra_sflash_of_match[] = { 422 + static const struct of_device_id tegra_sflash_of_match[] = { 423 423 { .compatible = "nvidia,tegra20-sflash", }, 424 424 {} 425 425 };
+1 -1
drivers/spi/spi-tegra20-slink.c
··· 1001 1001 .cs_hold_time = false, 1002 1002 }; 1003 1003 1004 - static struct of_device_id tegra_slink_of_match[] = { 1004 + static const struct of_device_id tegra_slink_of_match[] = { 1005 1005 { .compatible = "nvidia,tegra30-slink", .data = &tegra30_spi_cdata, }, 1006 1006 { .compatible = "nvidia,tegra20-slink", .data = &tegra20_spi_cdata, }, 1007 1007 {}