Lines Matching +full:use +full:- +full:internal +full:- +full:divider
1 // SPDX-License-Identifier: GPL-2.0-only
6 * Copyright (C) 2007-2008 Marvell Ltd.
30 * It is up to the implementer to only use the chip selects
74 * have both is for managing the armada-370-spi case with old
111 return orion_spi->base + reg; in spi_reg()
145 orion_spi = spi_master_get_devdata(spi->master); in orion_spi_baudrate_set()
146 devdata = orion_spi->devdata; in orion_spi_baudrate_set()
148 tclk_hz = clk_get_rate(orion_spi->clk); in orion_spi_baudrate_set()
150 if (devdata->typ == ARMADA_SPI) { in orion_spi_baudrate_set()
161 /* best integer divider: */ in orion_spi_baudrate_set()
162 unsigned divider = DIV_ROUND_UP(tclk_hz, speed); in orion_spi_baudrate_set() local
165 if (divider < 16) { in orion_spi_baudrate_set()
166 /* This is the easy case, divider is less than 16 */ in orion_spi_baudrate_set()
167 spr = divider; in orion_spi_baudrate_set()
173 * Find the highest bit set in divider. This and the in orion_spi_baudrate_set()
178 sppr = fls(divider) - 4; in orion_spi_baudrate_set()
181 * As SPR only has 4 bits, we have to round divider up in orion_spi_baudrate_set()
185 divider = (divider + two_pow_sppr - 1) & -two_pow_sppr; in orion_spi_baudrate_set()
188 * recalculate sppr as rounding up divider might have in orion_spi_baudrate_set()
194 sppr = fls(divider) - 4; in orion_spi_baudrate_set()
195 spr = divider >> sppr; in orion_spi_baudrate_set()
203 return -EINVAL; in orion_spi_baudrate_set()
217 return -EINVAL; in orion_spi_baudrate_set()
227 reg = ((reg & ~devdata->prescale_mask) | prescale); in orion_spi_baudrate_set()
239 orion_spi = spi_master_get_devdata(spi->master); in orion_spi_mode_set()
243 if (spi->mode & SPI_CPOL) in orion_spi_mode_set()
245 if (spi->mode & SPI_CPHA) in orion_spi_mode_set()
247 if (spi->mode & SPI_LSB_FIRST) in orion_spi_mode_set()
261 orion_spi = spi_master_get_devdata(spi->master); in orion_spi_50mhz_ac_timing_erratum()
264 * Erratum description: (Erratum NO. FE-9144572) The device in orion_spi_50mhz_ac_timing_erratum()
280 if (clk_get_rate(orion_spi->clk) == 250000000 && in orion_spi_50mhz_ac_timing_erratum()
281 speed == 50000000 && spi->mode & SPI_CPOL && in orion_spi_50mhz_ac_timing_erratum()
282 spi->mode & SPI_CPHA) in orion_spi_50mhz_ac_timing_erratum()
297 unsigned int speed = spi->max_speed_hz; in orion_spi_setup_transfer()
298 unsigned int bits_per_word = spi->bits_per_word; in orion_spi_setup_transfer()
301 orion_spi = spi_master_get_devdata(spi->master); in orion_spi_setup_transfer()
303 if ((t != NULL) && t->speed_hz) in orion_spi_setup_transfer()
304 speed = t->speed_hz; in orion_spi_setup_transfer()
306 if ((t != NULL) && t->bits_per_word) in orion_spi_setup_transfer()
307 bits_per_word = t->bits_per_word; in orion_spi_setup_transfer()
311 if (orion_spi->devdata->is_errata_50mhz_ac) in orion_spi_setup_transfer()
334 orion_spi = spi_master_get_devdata(spi->master); in orion_spi_set_cs()
339 /* Clear existing chip-select and assertion state */ in orion_spi_set_cs()
343 * If this line is using a GPIO to control chip select, this internal in orion_spi_set_cs()
349 val |= ORION_SPI_CS(spi->chip_select); in orion_spi_set_cs()
379 return -1; in orion_spi_wait_till_ready()
390 cs_single_byte = spi->mode & SPI_CS_WORD; in orion_spi_write_read_8bit()
392 orion_spi = spi_master_get_devdata(spi->master); in orion_spi_write_read_8bit()
415 dev_err(&spi->dev, "TXS timed out\n"); in orion_spi_write_read_8bit()
416 return -1; in orion_spi_write_read_8bit()
438 if (spi->mode & SPI_CS_WORD) { in orion_spi_write_read_16bit()
439 dev_err(&spi->dev, "SPI_CS_WORD is only supported for 8 bit words\n"); in orion_spi_write_read_16bit()
440 return -1; in orion_spi_write_read_16bit()
443 orion_spi = spi_master_get_devdata(spi->master); in orion_spi_write_read_16bit()
457 dev_err(&spi->dev, "TXS timed out\n"); in orion_spi_write_read_16bit()
458 return -1; in orion_spi_write_read_16bit()
473 int cs = spi->chip_select; in orion_spi_write_read()
476 word_len = spi->bits_per_word; in orion_spi_write_read()
477 count = xfer->len; in orion_spi_write_read()
479 orion_spi = spi_master_get_devdata(spi->master); in orion_spi_write_read()
482 * Use SPI direct write mode if base address is available in orion_spi_write_read()
486 vaddr = orion_spi->child[cs].direct_access.vaddr; in orion_spi_write_read()
488 if (vaddr && xfer->tx_buf && word_len == 8 && (spi->mode & SPI_CS_WORD) == 0) { in orion_spi_write_read()
493 * Send the TX-data to the SPI device via the direct in orion_spi_write_read()
496 iowrite32_rep(vaddr, xfer->tx_buf, cnt); in orion_spi_write_read()
498 u32 *buf = (u32 *)xfer->tx_buf; in orion_spi_write_read()
507 const u8 *tx = xfer->tx_buf; in orion_spi_write_read()
508 u8 *rx = xfer->rx_buf; in orion_spi_write_read()
513 count--; in orion_spi_write_read()
514 spi_delay_exec(&xfer->word_delay, xfer); in orion_spi_write_read()
517 const u16 *tx = xfer->tx_buf; in orion_spi_write_read()
518 u16 *rx = xfer->rx_buf; in orion_spi_write_read()
523 count -= 2; in orion_spi_write_read()
524 spi_delay_exec(&xfer->word_delay, xfer); in orion_spi_write_read()
529 return xfer->len - count; in orion_spi_write_read()
542 if (t->len) in orion_spi_transfer_one()
552 struct orion_spi *orion_spi = spi_master_get_devdata(spi->master); in orion_spi_setup()
553 struct device *dev = orion_spi->dev; in orion_spi_setup()
617 .compatible = "marvell,orion-spi",
621 .compatible = "marvell,armada-370-spi",
625 .compatible = "marvell,armada-375-spi",
629 .compatible = "marvell,armada-380-spi",
633 .compatible = "marvell,armada-390-spi",
637 .compatible = "marvell,armada-xp-spi",
655 master = spi_alloc_master(&pdev->dev, sizeof(*spi)); in orion_spi_probe()
657 dev_dbg(&pdev->dev, "master allocation failed\n"); in orion_spi_probe()
658 return -ENOMEM; in orion_spi_probe()
661 if (pdev->id != -1) in orion_spi_probe()
662 master->bus_num = pdev->id; in orion_spi_probe()
663 if (pdev->dev.of_node) { in orion_spi_probe()
666 if (!of_property_read_u32(pdev->dev.of_node, "cell-index", in orion_spi_probe()
668 master->bus_num = cell_index; in orion_spi_probe()
672 master->mode_bits = SPI_CPHA | SPI_CPOL | SPI_LSB_FIRST | SPI_CS_WORD; in orion_spi_probe()
673 master->set_cs = orion_spi_set_cs; in orion_spi_probe()
674 master->transfer_one = orion_spi_transfer_one; in orion_spi_probe()
675 master->num_chipselect = ORION_NUM_CHIPSELECTS; in orion_spi_probe()
676 master->setup = orion_spi_setup; in orion_spi_probe()
677 master->bits_per_word_mask = SPI_BPW_MASK(8) | SPI_BPW_MASK(16); in orion_spi_probe()
678 master->auto_runtime_pm = true; in orion_spi_probe()
679 master->use_gpio_descriptors = true; in orion_spi_probe()
680 master->flags = SPI_MASTER_GPIO_SS; in orion_spi_probe()
685 spi->master = master; in orion_spi_probe()
686 spi->dev = &pdev->dev; in orion_spi_probe()
688 devdata = device_get_match_data(&pdev->dev); in orion_spi_probe()
690 spi->devdata = devdata; in orion_spi_probe()
692 spi->clk = devm_clk_get(&pdev->dev, NULL); in orion_spi_probe()
693 if (IS_ERR(spi->clk)) { in orion_spi_probe()
694 status = PTR_ERR(spi->clk); in orion_spi_probe()
698 status = clk_prepare_enable(spi->clk); in orion_spi_probe()
703 spi->axi_clk = devm_clk_get(&pdev->dev, "axi"); in orion_spi_probe()
704 if (PTR_ERR(spi->axi_clk) == -EPROBE_DEFER) { in orion_spi_probe()
705 status = -EPROBE_DEFER; in orion_spi_probe()
708 if (!IS_ERR(spi->axi_clk)) in orion_spi_probe()
709 clk_prepare_enable(spi->axi_clk); in orion_spi_probe()
711 tclk_hz = clk_get_rate(spi->clk); in orion_spi_probe()
714 * With old device tree, armada-370-spi could be used with in orion_spi_probe()
720 if (of_device_is_compatible(pdev->dev.of_node, in orion_spi_probe()
721 "marvell,armada-370-spi")) in orion_spi_probe()
722 master->max_speed_hz = min(devdata->max_hz, in orion_spi_probe()
723 DIV_ROUND_UP(tclk_hz, devdata->min_divisor)); in orion_spi_probe()
724 else if (devdata->min_divisor) in orion_spi_probe()
725 master->max_speed_hz = in orion_spi_probe()
726 DIV_ROUND_UP(tclk_hz, devdata->min_divisor); in orion_spi_probe()
728 master->max_speed_hz = devdata->max_hz; in orion_spi_probe()
729 master->min_speed_hz = DIV_ROUND_UP(tclk_hz, devdata->max_divisor); in orion_spi_probe()
732 spi->base = devm_ioremap_resource(&pdev->dev, r); in orion_spi_probe()
733 if (IS_ERR(spi->base)) { in orion_spi_probe()
734 status = PTR_ERR(spi->base); in orion_spi_probe()
738 for_each_available_child_of_node(pdev->dev.of_node, np) { in orion_spi_probe()
742 /* Get chip-select number from the "reg" property */ in orion_spi_probe()
745 dev_err(&pdev->dev, in orion_spi_probe()
754 * node is not configured and this device should not use the in orion_spi_probe()
758 status = of_address_to_resource(pdev->dev.of_node, cs + 1, r); in orion_spi_probe()
768 dir_acc = &spi->child[cs].direct_access; in orion_spi_probe()
769 dir_acc->vaddr = devm_ioremap(&pdev->dev, r->start, PAGE_SIZE); in orion_spi_probe()
770 if (!dir_acc->vaddr) { in orion_spi_probe()
771 status = -ENOMEM; in orion_spi_probe()
775 dir_acc->size = PAGE_SIZE; in orion_spi_probe()
777 dev_info(&pdev->dev, "CS%d configured for direct access\n", cs); in orion_spi_probe()
780 pm_runtime_set_active(&pdev->dev); in orion_spi_probe()
781 pm_runtime_use_autosuspend(&pdev->dev); in orion_spi_probe()
782 pm_runtime_set_autosuspend_delay(&pdev->dev, SPI_AUTOSUSPEND_TIMEOUT); in orion_spi_probe()
783 pm_runtime_enable(&pdev->dev); in orion_spi_probe()
789 master->dev.of_node = pdev->dev.of_node; in orion_spi_probe()
797 pm_runtime_disable(&pdev->dev); in orion_spi_probe()
799 clk_disable_unprepare(spi->axi_clk); in orion_spi_probe()
801 clk_disable_unprepare(spi->clk); in orion_spi_probe()
813 pm_runtime_get_sync(&pdev->dev); in orion_spi_remove()
814 clk_disable_unprepare(spi->axi_clk); in orion_spi_remove()
815 clk_disable_unprepare(spi->clk); in orion_spi_remove()
818 pm_runtime_disable(&pdev->dev); in orion_spi_remove()
831 clk_disable_unprepare(spi->axi_clk); in orion_spi_runtime_suspend()
832 clk_disable_unprepare(spi->clk); in orion_spi_runtime_suspend()
841 if (!IS_ERR(spi->axi_clk)) in orion_spi_runtime_resume()
842 clk_prepare_enable(spi->axi_clk); in orion_spi_runtime_resume()
843 return clk_prepare_enable(spi->clk); in orion_spi_runtime_resume()