Lines Matching +full:host +full:- +full:only
1 // SPDX-License-Identifier: GPL-2.0-only
6 * Copyright (C) 2007-2008 Marvell Ltd.
29 * It is up to the implementer to only use the chip selects
72 * min_divisor and max_hz should be exclusive, the only we can
73 * have both is for managing the armada-370-spi case with old
93 struct spi_controller *host; member
110 return orion_spi->base + reg; in spi_reg()
144 orion_spi = spi_controller_get_devdata(spi->controller); in orion_spi_baudrate_set()
145 devdata = orion_spi->devdata; in orion_spi_baudrate_set()
147 tclk_hz = clk_get_rate(orion_spi->clk); in orion_spi_baudrate_set()
149 if (devdata->typ == ARMADA_SPI) { in orion_spi_baudrate_set()
177 sppr = fls(divider) - 4; in orion_spi_baudrate_set()
180 * As SPR only has 4 bits, we have to round divider up in orion_spi_baudrate_set()
184 divider = (divider + two_pow_sppr - 1) & -two_pow_sppr; in orion_spi_baudrate_set()
193 sppr = fls(divider) - 4; in orion_spi_baudrate_set()
202 return -EINVAL; in orion_spi_baudrate_set()
216 return -EINVAL; in orion_spi_baudrate_set()
226 reg = ((reg & ~devdata->prescale_mask) | prescale); in orion_spi_baudrate_set()
238 orion_spi = spi_controller_get_devdata(spi->controller); in orion_spi_mode_set()
242 if (spi->mode & SPI_CPOL) in orion_spi_mode_set()
244 if (spi->mode & SPI_CPHA) in orion_spi_mode_set()
246 if (spi->mode & SPI_LSB_FIRST) in orion_spi_mode_set()
260 orion_spi = spi_controller_get_devdata(spi->controller); in orion_spi_50mhz_ac_timing_erratum()
263 * Erratum description: (Erratum NO. FE-9144572) The device in orion_spi_50mhz_ac_timing_erratum()
279 if (clk_get_rate(orion_spi->clk) == 250000000 && in orion_spi_50mhz_ac_timing_erratum()
280 speed == 50000000 && spi->mode & SPI_CPOL && in orion_spi_50mhz_ac_timing_erratum()
281 spi->mode & SPI_CPHA) in orion_spi_50mhz_ac_timing_erratum()
290 * called only when no transfer is active on the bus
296 unsigned int speed = spi->max_speed_hz; in orion_spi_setup_transfer()
297 unsigned int bits_per_word = spi->bits_per_word; in orion_spi_setup_transfer()
300 orion_spi = spi_controller_get_devdata(spi->controller); in orion_spi_setup_transfer()
302 if ((t != NULL) && t->speed_hz) in orion_spi_setup_transfer()
303 speed = t->speed_hz; in orion_spi_setup_transfer()
305 if ((t != NULL) && t->bits_per_word) in orion_spi_setup_transfer()
306 bits_per_word = t->bits_per_word; in orion_spi_setup_transfer()
310 if (orion_spi->devdata->is_errata_50mhz_ac) in orion_spi_setup_transfer()
333 orion_spi = spi_controller_get_devdata(spi->controller); in orion_spi_set_cs()
338 /* Clear existing chip-select and assertion state */ in orion_spi_set_cs()
378 return -1; in orion_spi_wait_till_ready()
389 cs_single_byte = spi->mode & SPI_CS_WORD; in orion_spi_write_read_8bit()
391 orion_spi = spi_controller_get_devdata(spi->controller); in orion_spi_write_read_8bit()
414 dev_err(&spi->dev, "TXS timed out\n"); in orion_spi_write_read_8bit()
415 return -1; in orion_spi_write_read_8bit()
437 if (spi->mode & SPI_CS_WORD) { in orion_spi_write_read_16bit()
438 dev_err(&spi->dev, "SPI_CS_WORD is only supported for 8 bit words\n"); in orion_spi_write_read_16bit()
439 return -1; in orion_spi_write_read_16bit()
442 orion_spi = spi_controller_get_devdata(spi->controller); in orion_spi_write_read_16bit()
456 dev_err(&spi->dev, "TXS timed out\n"); in orion_spi_write_read_16bit()
457 return -1; in orion_spi_write_read_16bit()
475 word_len = spi->bits_per_word; in orion_spi_write_read()
476 count = xfer->len; in orion_spi_write_read()
478 orion_spi = spi_controller_get_devdata(spi->controller); in orion_spi_write_read()
485 vaddr = orion_spi->child[cs].direct_access.vaddr; in orion_spi_write_read()
487 if (vaddr && xfer->tx_buf && word_len == 8 && (spi->mode & SPI_CS_WORD) == 0) { in orion_spi_write_read()
492 * Send the TX-data to the SPI device via the direct in orion_spi_write_read()
495 iowrite32_rep(vaddr, xfer->tx_buf, cnt); in orion_spi_write_read()
497 u32 *buf = (u32 *)xfer->tx_buf; in orion_spi_write_read()
506 const u8 *tx = xfer->tx_buf; in orion_spi_write_read()
507 u8 *rx = xfer->rx_buf; in orion_spi_write_read()
512 count--; in orion_spi_write_read()
513 spi_delay_exec(&xfer->word_delay, xfer); in orion_spi_write_read()
516 const u16 *tx = xfer->tx_buf; in orion_spi_write_read()
517 u16 *rx = xfer->rx_buf; in orion_spi_write_read()
522 count -= 2; in orion_spi_write_read()
523 spi_delay_exec(&xfer->word_delay, xfer); in orion_spi_write_read()
528 return xfer->len - count; in orion_spi_write_read()
531 static int orion_spi_transfer_one(struct spi_controller *host, in orion_spi_transfer_one() argument
541 if (t->len) in orion_spi_transfer_one()
551 struct orion_spi *orion_spi = spi_controller_get_devdata(spi->controller); in orion_spi_setup()
552 struct device *dev = orion_spi->dev; in orion_spi_setup()
616 .compatible = "marvell,orion-spi",
620 .compatible = "marvell,armada-370-spi",
624 .compatible = "marvell,armada-375-spi",
628 .compatible = "marvell,armada-380-spi",
632 .compatible = "marvell,armada-390-spi",
636 .compatible = "marvell,armada-xp-spi",
647 struct spi_controller *host; in orion_spi_probe() local
654 host = spi_alloc_host(&pdev->dev, sizeof(*spi)); in orion_spi_probe()
655 if (host == NULL) { in orion_spi_probe()
656 dev_dbg(&pdev->dev, "host allocation failed\n"); in orion_spi_probe()
657 return -ENOMEM; in orion_spi_probe()
660 if (pdev->id != -1) in orion_spi_probe()
661 host->bus_num = pdev->id; in orion_spi_probe()
662 if (pdev->dev.of_node) { in orion_spi_probe()
665 if (!of_property_read_u32(pdev->dev.of_node, "cell-index", in orion_spi_probe()
667 host->bus_num = cell_index; in orion_spi_probe()
671 host->mode_bits = SPI_CPHA | SPI_CPOL | SPI_LSB_FIRST | SPI_CS_WORD; in orion_spi_probe()
672 host->set_cs = orion_spi_set_cs; in orion_spi_probe()
673 host->transfer_one = orion_spi_transfer_one; in orion_spi_probe()
674 host->num_chipselect = ORION_NUM_CHIPSELECTS; in orion_spi_probe()
675 host->setup = orion_spi_setup; in orion_spi_probe()
676 host->bits_per_word_mask = SPI_BPW_MASK(8) | SPI_BPW_MASK(16); in orion_spi_probe()
677 host->auto_runtime_pm = true; in orion_spi_probe()
678 host->use_gpio_descriptors = true; in orion_spi_probe()
679 host->flags = SPI_CONTROLLER_GPIO_SS; in orion_spi_probe()
681 platform_set_drvdata(pdev, host); in orion_spi_probe()
683 spi = spi_controller_get_devdata(host); in orion_spi_probe()
684 spi->host = host; in orion_spi_probe()
685 spi->dev = &pdev->dev; in orion_spi_probe()
687 devdata = device_get_match_data(&pdev->dev); in orion_spi_probe()
689 spi->devdata = devdata; in orion_spi_probe()
691 spi->clk = devm_clk_get_enabled(&pdev->dev, NULL); in orion_spi_probe()
692 if (IS_ERR(spi->clk)) { in orion_spi_probe()
693 status = PTR_ERR(spi->clk); in orion_spi_probe()
697 /* The following clock is only used by some SoCs */ in orion_spi_probe()
698 spi->axi_clk = devm_clk_get(&pdev->dev, "axi"); in orion_spi_probe()
699 if (PTR_ERR(spi->axi_clk) == -EPROBE_DEFER) { in orion_spi_probe()
700 status = -EPROBE_DEFER; in orion_spi_probe()
703 if (!IS_ERR(spi->axi_clk)) in orion_spi_probe()
704 clk_prepare_enable(spi->axi_clk); in orion_spi_probe()
706 tclk_hz = clk_get_rate(spi->clk); in orion_spi_probe()
709 * With old device tree, armada-370-spi could be used with in orion_spi_probe()
715 if (of_device_is_compatible(pdev->dev.of_node, in orion_spi_probe()
716 "marvell,armada-370-spi")) in orion_spi_probe()
717 host->max_speed_hz = min(devdata->max_hz, in orion_spi_probe()
718 DIV_ROUND_UP(tclk_hz, devdata->min_divisor)); in orion_spi_probe()
719 else if (devdata->min_divisor) in orion_spi_probe()
720 host->max_speed_hz = in orion_spi_probe()
721 DIV_ROUND_UP(tclk_hz, devdata->min_divisor); in orion_spi_probe()
723 host->max_speed_hz = devdata->max_hz; in orion_spi_probe()
724 host->min_speed_hz = DIV_ROUND_UP(tclk_hz, devdata->max_divisor); in orion_spi_probe()
726 spi->base = devm_platform_get_and_ioremap_resource(pdev, 0, &r); in orion_spi_probe()
727 if (IS_ERR(spi->base)) { in orion_spi_probe()
728 status = PTR_ERR(spi->base); in orion_spi_probe()
732 for_each_available_child_of_node(pdev->dev.of_node, np) { in orion_spi_probe()
736 /* Get chip-select number from the "reg" property */ in orion_spi_probe()
739 dev_err(&pdev->dev, in orion_spi_probe()
752 status = of_address_to_resource(pdev->dev.of_node, cs + 1, r); in orion_spi_probe()
757 * Only map one page for direct access. This is enough for the in orion_spi_probe()
758 * simple TX transfer which only writes to the first word. in orion_spi_probe()
762 dir_acc = &spi->child[cs].direct_access; in orion_spi_probe()
763 dir_acc->vaddr = devm_ioremap(&pdev->dev, r->start, PAGE_SIZE); in orion_spi_probe()
764 if (!dir_acc->vaddr) { in orion_spi_probe()
765 status = -ENOMEM; in orion_spi_probe()
769 dir_acc->size = PAGE_SIZE; in orion_spi_probe()
771 dev_info(&pdev->dev, "CS%d configured for direct access\n", cs); in orion_spi_probe()
774 pm_runtime_set_active(&pdev->dev); in orion_spi_probe()
775 pm_runtime_use_autosuspend(&pdev->dev); in orion_spi_probe()
776 pm_runtime_set_autosuspend_delay(&pdev->dev, SPI_AUTOSUSPEND_TIMEOUT); in orion_spi_probe()
777 pm_runtime_enable(&pdev->dev); in orion_spi_probe()
783 host->dev.of_node = pdev->dev.of_node; in orion_spi_probe()
784 status = spi_register_controller(host); in orion_spi_probe()
791 pm_runtime_disable(&pdev->dev); in orion_spi_probe()
793 clk_disable_unprepare(spi->axi_clk); in orion_spi_probe()
795 spi_controller_put(host); in orion_spi_probe()
802 struct spi_controller *host = platform_get_drvdata(pdev); in orion_spi_remove() local
803 struct orion_spi *spi = spi_controller_get_devdata(host); in orion_spi_remove()
805 pm_runtime_get_sync(&pdev->dev); in orion_spi_remove()
806 clk_disable_unprepare(spi->axi_clk); in orion_spi_remove()
808 spi_unregister_controller(host); in orion_spi_remove()
809 pm_runtime_disable(&pdev->dev); in orion_spi_remove()
817 struct spi_controller *host = dev_get_drvdata(dev); in orion_spi_runtime_suspend() local
818 struct orion_spi *spi = spi_controller_get_devdata(host); in orion_spi_runtime_suspend()
820 clk_disable_unprepare(spi->axi_clk); in orion_spi_runtime_suspend()
821 clk_disable_unprepare(spi->clk); in orion_spi_runtime_suspend()
827 struct spi_controller *host = dev_get_drvdata(dev); in orion_spi_runtime_resume() local
828 struct orion_spi *spi = spi_controller_get_devdata(host); in orion_spi_runtime_resume()
830 if (!IS_ERR(spi->axi_clk)) in orion_spi_runtime_resume()
831 clk_prepare_enable(spi->axi_clk); in orion_spi_runtime_resume()
832 return clk_prepare_enable(spi->clk); in orion_spi_runtime_resume()