Lines Matching full:spi
3 * Marvell Orion SPI controller driver
14 #include <linux/spi/spi.h>
74 * have both is for managing the armada-370-spi case with old
136 static int orion_spi_baudrate_set(struct spi_device *spi, unsigned int speed) in orion_spi_baudrate_set() argument
145 orion_spi = spi_master_get_devdata(spi->master); in orion_spi_baudrate_set()
222 /* Convert the rate to SPI clock divisor value. */ in orion_spi_baudrate_set()
234 orion_spi_mode_set(struct spi_device *spi) in orion_spi_mode_set() argument
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()
256 orion_spi_50mhz_ac_timing_erratum(struct spi_device *spi, unsigned int speed) in orion_spi_50mhz_ac_timing_erratum() argument
261 orion_spi = spi_master_get_devdata(spi->master); in orion_spi_50mhz_ac_timing_erratum()
265 * SPI interface supports frequencies of up to 50 MHz. in orion_spi_50mhz_ac_timing_erratum()
267 * 250 MHz and the SPI interfaces is configured for 50MHz SPI in orion_spi_50mhz_ac_timing_erratum()
269 * reads from the SPI device. in orion_spi_50mhz_ac_timing_erratum()
272 * 1. Set CPOL=CPHA=0 in "SPI Interface Configuration in orion_spi_50mhz_ac_timing_erratum()
274 * 2. Set TMISO_SAMPLE value to 0x2 in "SPI Timing Parameters 1 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()
294 orion_spi_setup_transfer(struct spi_device *spi, struct spi_transfer *t) in orion_spi_setup_transfer() argument
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()
309 orion_spi_mode_set(spi); in orion_spi_setup_transfer()
312 orion_spi_50mhz_ac_timing_erratum(spi, speed); in orion_spi_setup_transfer()
314 rc = orion_spi_baudrate_set(spi, speed); in orion_spi_setup_transfer()
328 static void orion_spi_set_cs(struct spi_device *spi, bool enable) in orion_spi_set_cs() argument
334 orion_spi = spi_master_get_devdata(spi->master); in orion_spi_set_cs()
349 val |= ORION_SPI_CS(spi->chip_select); in orion_spi_set_cs()
383 orion_spi_write_read_8bit(struct spi_device *spi, in orion_spi_write_read_8bit() argument
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()
395 orion_spi_set_cs(spi, 0); in orion_spi_write_read_8bit()
411 orion_spi_set_cs(spi, 1); in orion_spi_write_read_8bit()
415 dev_err(&spi->dev, "TXS timed out\n"); in orion_spi_write_read_8bit()
423 orion_spi_set_cs(spi, 1); in orion_spi_write_read_8bit()
432 orion_spi_write_read_16bit(struct spi_device *spi, in orion_spi_write_read_16bit() argument
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()
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()
468 orion_spi_write_read(struct spi_device *spi, struct spi_transfer *xfer) in orion_spi_write_read() argument
473 int cs = spi->chip_select; in orion_spi_write_read()
476 word_len = spi->bits_per_word; 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()
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()
511 if (orion_spi_write_read_8bit(spi, &tx, &rx) < 0) in orion_spi_write_read()
521 if (orion_spi_write_read_16bit(spi, &tx, &rx) < 0) in orion_spi_write_read()
533 struct spi_device *spi, in orion_spi_transfer_one() argument
538 status = orion_spi_setup_transfer(spi, t); in orion_spi_transfer_one()
543 orion_spi_write_read(spi, t); in orion_spi_transfer_one()
548 static int orion_spi_setup(struct spi_device *spi) in orion_spi_setup() argument
552 struct orion_spi *orion_spi = spi_master_get_devdata(spi->master); in orion_spi_setup()
558 ret = orion_spi_setup_transfer(spi, NULL); in orion_spi_setup()
572 /* Don't deassert CS between the direct mapped SPI transfers */ in orion_spi_reset()
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",
649 struct orion_spi *spi; in orion_spi_probe() local
655 master = spi_alloc_master(&pdev->dev, sizeof(*spi)); in orion_spi_probe()
671 /* we support all 4 SPI modes and LSB first option */ in orion_spi_probe()
684 spi = spi_master_get_devdata(master); in orion_spi_probe()
685 spi->master = master; in orion_spi_probe()
686 spi->dev = &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()
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()
721 "marvell,armada-370-spi")) 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()
752 * Check if an address is configured for this SPI device. If in orion_spi_probe()
765 * This needs to get extended for the direct SPI NOR / SPI NAND in orion_spi_probe()
768 dir_acc = &spi->child[cs].direct_access; in orion_spi_probe()
785 status = orion_spi_reset(spi); 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()
811 struct orion_spi *spi = spi_master_get_devdata(master); in orion_spi_remove() local
814 clk_disable_unprepare(spi->axi_clk); in orion_spi_remove()
815 clk_disable_unprepare(spi->clk); in orion_spi_remove()
829 struct orion_spi *spi = spi_master_get_devdata(master); in orion_spi_runtime_suspend() local
831 clk_disable_unprepare(spi->axi_clk); in orion_spi_runtime_suspend()
832 clk_disable_unprepare(spi->clk); in orion_spi_runtime_suspend()
839 struct orion_spi *spi = spi_master_get_devdata(master); in orion_spi_runtime_resume() local
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()
865 MODULE_DESCRIPTION("Orion SPI driver");