2018-05-06 21:58:06 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2014-11-07 11:37:49 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2012
|
|
|
|
* Altera Corporation <www.altera.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
2019-11-20 21:27:31 +00:00
|
|
|
#include <clk.h>
|
2020-05-10 17:40:05 +00:00
|
|
|
#include <log.h>
|
2019-12-05 10:16:06 +00:00
|
|
|
#include <asm-generic/io.h>
|
2014-11-07 11:37:49 +00:00
|
|
|
#include <dm.h>
|
|
|
|
#include <fdtdec.h>
|
|
|
|
#include <malloc.h>
|
2019-03-01 19:12:35 +00:00
|
|
|
#include <reset.h>
|
2014-11-07 11:37:49 +00:00
|
|
|
#include <spi.h>
|
2020-01-27 05:06:39 +00:00
|
|
|
#include <spi-mem.h>
|
2020-02-03 14:36:16 +00:00
|
|
|
#include <dm/device_compat.h>
|
2020-02-03 14:36:15 +00:00
|
|
|
#include <linux/err.h>
|
2016-09-21 02:28:55 +00:00
|
|
|
#include <linux/errno.h>
|
2020-01-27 05:06:40 +00:00
|
|
|
#include <linux/sizes.h>
|
2022-05-12 10:05:34 +00:00
|
|
|
#include <zynqmp_firmware.h>
|
2014-11-07 11:37:49 +00:00
|
|
|
#include "cadence_qspi.h"
|
2022-05-12 10:05:34 +00:00
|
|
|
#include <dt-bindings/power/xlnx-versal-power.h>
|
2014-11-07 11:37:49 +00:00
|
|
|
|
2021-06-25 19:17:08 +00:00
|
|
|
#define NSEC_PER_SEC 1000000000L
|
|
|
|
|
2014-11-07 11:37:49 +00:00
|
|
|
#define CQSPI_STIG_READ 0
|
|
|
|
#define CQSPI_STIG_WRITE 1
|
2020-01-27 05:06:40 +00:00
|
|
|
#define CQSPI_READ 2
|
|
|
|
#define CQSPI_WRITE 3
|
2014-11-07 11:37:49 +00:00
|
|
|
|
2022-08-24 11:38:47 +00:00
|
|
|
__weak int cadence_qspi_apb_dma_read(struct cadence_spi_priv *priv,
|
2022-05-12 10:05:32 +00:00
|
|
|
const struct spi_mem_op *op)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2022-05-12 10:05:33 +00:00
|
|
|
__weak int cadence_qspi_versal_flash_reset(struct udevice *dev)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-11-07 11:37:49 +00:00
|
|
|
static int cadence_spi_write_speed(struct udevice *bus, uint hz)
|
|
|
|
{
|
|
|
|
struct cadence_spi_priv *priv = dev_get_priv(bus);
|
|
|
|
|
|
|
|
cadence_qspi_apb_config_baudrate_div(priv->regbase,
|
2022-08-24 11:38:47 +00:00
|
|
|
priv->ref_clk_hz, hz);
|
2014-11-07 11:37:49 +00:00
|
|
|
|
|
|
|
/* Reconfigure delay timing if speed is changed. */
|
2022-08-24 11:38:47 +00:00
|
|
|
cadence_qspi_apb_delay(priv->regbase, priv->ref_clk_hz, hz,
|
|
|
|
priv->tshsl_ns, priv->tsd2d_ns,
|
|
|
|
priv->tchsh_ns, priv->tslch_ns);
|
2014-11-07 11:37:49 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2022-08-24 11:38:47 +00:00
|
|
|
static int cadence_spi_read_id(struct cadence_spi_priv *priv, u8 len,
|
2021-06-25 19:17:09 +00:00
|
|
|
u8 *idcode)
|
2020-01-27 05:06:39 +00:00
|
|
|
{
|
2022-08-24 11:38:46 +00:00
|
|
|
int err;
|
2022-08-24 11:38:47 +00:00
|
|
|
|
2020-01-27 05:06:39 +00:00
|
|
|
struct spi_mem_op op = SPI_MEM_OP(SPI_MEM_OP_CMD(0x9F, 1),
|
|
|
|
SPI_MEM_OP_NO_ADDR,
|
|
|
|
SPI_MEM_OP_NO_DUMMY,
|
|
|
|
SPI_MEM_OP_DATA_IN(len, idcode, 1));
|
|
|
|
|
2022-08-24 11:38:47 +00:00
|
|
|
err = cadence_qspi_apb_command_read_setup(priv, &op);
|
2022-08-24 11:38:46 +00:00
|
|
|
if (!err)
|
2022-08-24 11:38:47 +00:00
|
|
|
err = cadence_qspi_apb_command_read(priv, &op);
|
2022-08-24 11:38:46 +00:00
|
|
|
|
|
|
|
return err;
|
2020-01-27 05:06:39 +00:00
|
|
|
}
|
|
|
|
|
2014-11-07 11:37:49 +00:00
|
|
|
/* Calibration sequence to determine the read data capture delay register */
|
2015-10-17 13:31:55 +00:00
|
|
|
static int spi_calibration(struct udevice *bus, uint hz)
|
2014-11-07 11:37:49 +00:00
|
|
|
{
|
|
|
|
struct cadence_spi_priv *priv = dev_get_priv(bus);
|
|
|
|
void *base = priv->regbase;
|
|
|
|
unsigned int idcode = 0, temp = 0;
|
|
|
|
int err = 0, i, range_lo = -1, range_hi = -1;
|
|
|
|
|
|
|
|
/* start with slowest clock (1 MHz) */
|
|
|
|
cadence_spi_write_speed(bus, 1000000);
|
|
|
|
|
|
|
|
/* configure the read data capture delay register to 0 */
|
|
|
|
cadence_qspi_apb_readdata_capture(base, 1, 0);
|
|
|
|
|
|
|
|
/* Enable QSPI */
|
|
|
|
cadence_qspi_apb_controller_enable(base);
|
|
|
|
|
|
|
|
/* read the ID which will be our golden value */
|
2022-08-24 11:38:47 +00:00
|
|
|
err = cadence_spi_read_id(priv, 3, (u8 *)&idcode);
|
2014-11-07 11:37:49 +00:00
|
|
|
if (err) {
|
|
|
|
puts("SF: Calibration failed (read)\n");
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* use back the intended clock and find low range */
|
2015-10-17 13:31:55 +00:00
|
|
|
cadence_spi_write_speed(bus, hz);
|
2014-11-07 11:37:49 +00:00
|
|
|
for (i = 0; i < CQSPI_READ_CAPTURE_MAX_DELAY; i++) {
|
|
|
|
/* Disable QSPI */
|
|
|
|
cadence_qspi_apb_controller_disable(base);
|
|
|
|
|
|
|
|
/* reconfigure the read data capture delay register */
|
|
|
|
cadence_qspi_apb_readdata_capture(base, 1, i);
|
|
|
|
|
|
|
|
/* Enable back QSPI */
|
|
|
|
cadence_qspi_apb_controller_enable(base);
|
|
|
|
|
|
|
|
/* issue a RDID to get the ID value */
|
2022-08-24 11:38:47 +00:00
|
|
|
err = cadence_spi_read_id(priv, 3, (u8 *)&temp);
|
2014-11-07 11:37:49 +00:00
|
|
|
if (err) {
|
|
|
|
puts("SF: Calibration failed (read)\n");
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* search for range lo */
|
|
|
|
if (range_lo == -1 && temp == idcode) {
|
|
|
|
range_lo = i;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* search for range hi */
|
|
|
|
if (range_lo != -1 && temp != idcode) {
|
|
|
|
range_hi = i - 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
range_hi = i;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (range_lo == -1) {
|
|
|
|
puts("SF: Calibration failed (low range)\n");
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Disable QSPI for subsequent initialization */
|
|
|
|
cadence_qspi_apb_controller_disable(base);
|
|
|
|
|
|
|
|
/* configure the final value for read data capture delay register */
|
|
|
|
cadence_qspi_apb_readdata_capture(base, 1, (range_hi + range_lo) / 2);
|
|
|
|
debug("SF: Read data capture delay calibrated to %i (%i - %i)\n",
|
|
|
|
(range_hi + range_lo) / 2, range_lo, range_hi);
|
|
|
|
|
|
|
|
/* just to ensure we do once only when speed or chip select change */
|
2015-10-17 13:31:55 +00:00
|
|
|
priv->qspi_calibrated_hz = hz;
|
2014-11-07 11:37:49 +00:00
|
|
|
priv->qspi_calibrated_cs = spi_chip_select(bus);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int cadence_spi_set_speed(struct udevice *bus, uint hz)
|
|
|
|
{
|
|
|
|
struct cadence_spi_priv *priv = dev_get_priv(bus);
|
|
|
|
int err;
|
|
|
|
|
2022-08-24 11:38:47 +00:00
|
|
|
if (!hz || hz > priv->max_hz)
|
|
|
|
hz = priv->max_hz;
|
2014-11-07 11:37:49 +00:00
|
|
|
/* Disable QSPI */
|
|
|
|
cadence_qspi_apb_controller_disable(priv->regbase);
|
|
|
|
|
2015-10-17 13:31:55 +00:00
|
|
|
/*
|
2021-06-25 19:17:07 +00:00
|
|
|
* If the device tree already provides a read delay value, use that
|
|
|
|
* instead of calibrating.
|
2015-10-17 13:31:55 +00:00
|
|
|
*/
|
2022-08-24 11:38:47 +00:00
|
|
|
if (priv->read_delay >= 0) {
|
2021-06-25 19:17:07 +00:00
|
|
|
cadence_spi_write_speed(bus, hz);
|
|
|
|
cadence_qspi_apb_readdata_capture(priv->regbase, 1,
|
2022-08-24 11:38:47 +00:00
|
|
|
priv->read_delay);
|
2021-06-25 19:17:07 +00:00
|
|
|
} else if (priv->previous_hz != hz ||
|
|
|
|
priv->qspi_calibrated_hz != hz ||
|
|
|
|
priv->qspi_calibrated_cs != spi_chip_select(bus)) {
|
|
|
|
/*
|
|
|
|
* Calibration required for different current SCLK speed,
|
|
|
|
* requested SCLK speed or chip select
|
|
|
|
*/
|
2015-10-17 13:31:55 +00:00
|
|
|
err = spi_calibration(bus, hz);
|
2014-11-07 11:37:49 +00:00
|
|
|
if (err)
|
|
|
|
return err;
|
2015-10-17 13:31:55 +00:00
|
|
|
|
|
|
|
/* prevent calibration run when same as previous request */
|
|
|
|
priv->previous_hz = hz;
|
2014-11-07 11:37:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Enable QSPI */
|
|
|
|
cadence_qspi_apb_controller_enable(priv->regbase);
|
|
|
|
|
|
|
|
debug("%s: speed=%d\n", __func__, hz);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int cadence_spi_probe(struct udevice *bus)
|
|
|
|
{
|
2020-12-23 02:30:28 +00:00
|
|
|
struct cadence_spi_plat *plat = dev_get_plat(bus);
|
2014-11-07 11:37:49 +00:00
|
|
|
struct cadence_spi_priv *priv = dev_get_priv(bus);
|
2020-02-24 07:10:51 +00:00
|
|
|
struct clk clk;
|
2019-03-01 19:12:35 +00:00
|
|
|
int ret;
|
2014-11-07 11:37:49 +00:00
|
|
|
|
2022-08-24 11:38:47 +00:00
|
|
|
priv->regbase = plat->regbase;
|
|
|
|
priv->ahbbase = plat->ahbbase;
|
|
|
|
priv->is_dma = plat->is_dma;
|
|
|
|
priv->is_decoded_cs = plat->is_decoded_cs;
|
|
|
|
priv->fifo_depth = plat->fifo_depth;
|
|
|
|
priv->fifo_width = plat->fifo_width;
|
|
|
|
priv->trigger_address = plat->trigger_address;
|
|
|
|
priv->read_delay = plat->read_delay;
|
|
|
|
priv->ahbsize = plat->ahbsize;
|
|
|
|
priv->max_hz = plat->max_hz;
|
|
|
|
|
|
|
|
priv->page_size = plat->page_size;
|
|
|
|
priv->block_size = plat->block_size;
|
|
|
|
priv->tshsl_ns = plat->tshsl_ns;
|
|
|
|
priv->tsd2d_ns = plat->tsd2d_ns;
|
|
|
|
priv->tchsh_ns = plat->tchsh_ns;
|
|
|
|
priv->tslch_ns = plat->tslch_ns;
|
2014-11-07 11:37:49 +00:00
|
|
|
|
2023-02-05 22:44:33 +00:00
|
|
|
if (IS_ENABLED(CONFIG_ZYNQMP_FIRMWARE))
|
2022-05-12 10:05:34 +00:00
|
|
|
xilinx_pm_request(PM_REQUEST_NODE, PM_DEV_OSPI,
|
|
|
|
ZYNQMP_PM_CAPABILITY_ACCESS, ZYNQMP_PM_MAX_QOS,
|
|
|
|
ZYNQMP_PM_REQUEST_ACK_NO, NULL);
|
|
|
|
|
2022-08-24 11:38:47 +00:00
|
|
|
if (priv->ref_clk_hz == 0) {
|
2020-02-24 07:10:51 +00:00
|
|
|
ret = clk_get_by_index(bus, 0, &clk);
|
|
|
|
if (ret) {
|
2022-03-30 22:07:23 +00:00
|
|
|
#ifdef CONFIG_HAS_CQSPI_REF_CLK
|
2022-08-24 11:38:47 +00:00
|
|
|
priv->ref_clk_hz = CONFIG_CQSPI_REF_CLK;
|
2022-03-30 22:07:23 +00:00
|
|
|
#elif defined(CONFIG_ARCH_SOCFPGA)
|
2022-08-24 11:38:47 +00:00
|
|
|
priv->ref_clk_hz = cm_get_qspi_controller_clk_hz();
|
2020-02-24 07:10:51 +00:00
|
|
|
#else
|
|
|
|
return ret;
|
|
|
|
#endif
|
|
|
|
} else {
|
2022-08-24 11:38:47 +00:00
|
|
|
priv->ref_clk_hz = clk_get_rate(&clk);
|
2020-02-24 07:10:51 +00:00
|
|
|
clk_free(&clk);
|
2022-08-24 11:38:47 +00:00
|
|
|
if (IS_ERR_VALUE(priv->ref_clk_hz))
|
|
|
|
return priv->ref_clk_hz;
|
2020-02-24 07:10:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-22 16:23:25 +00:00
|
|
|
priv->resets = devm_reset_bulk_get_optional(bus);
|
|
|
|
if (priv->resets)
|
|
|
|
reset_deassert_bulk(priv->resets);
|
2019-03-01 19:12:35 +00:00
|
|
|
|
2014-11-07 11:37:49 +00:00
|
|
|
if (!priv->qspi_is_init) {
|
2022-08-24 11:38:47 +00:00
|
|
|
cadence_qspi_apb_controller_init(priv);
|
2014-11-07 11:37:49 +00:00
|
|
|
priv->qspi_is_init = 1;
|
|
|
|
}
|
|
|
|
|
2022-08-24 11:38:47 +00:00
|
|
|
priv->wr_delay = 50 * DIV_ROUND_UP(NSEC_PER_SEC, priv->ref_clk_hz);
|
2021-06-25 19:17:08 +00:00
|
|
|
|
2023-02-06 00:53:13 +00:00
|
|
|
if (IS_ENABLED(CONFIG_ARCH_VERSAL)) {
|
2022-05-12 10:05:33 +00:00
|
|
|
/* Versal platform uses spi calibration to set read delay */
|
2022-08-24 11:38:47 +00:00
|
|
|
if (priv->read_delay >= 0)
|
|
|
|
priv->read_delay = -1;
|
2022-05-12 10:05:33 +00:00
|
|
|
/* Reset ospi flash device */
|
|
|
|
ret = cadence_qspi_versal_flash_reset(bus);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2014-11-07 11:37:49 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-03-01 19:12:35 +00:00
|
|
|
static int cadence_spi_remove(struct udevice *dev)
|
|
|
|
{
|
|
|
|
struct cadence_spi_priv *priv = dev_get_priv(dev);
|
2022-02-22 16:23:25 +00:00
|
|
|
int ret = 0;
|
2019-03-01 19:12:35 +00:00
|
|
|
|
2022-02-22 16:23:25 +00:00
|
|
|
if (priv->resets)
|
|
|
|
ret = reset_release_bulk(priv->resets);
|
|
|
|
|
|
|
|
return ret;
|
2019-03-01 19:12:35 +00:00
|
|
|
}
|
|
|
|
|
2014-11-07 11:37:49 +00:00
|
|
|
static int cadence_spi_set_mode(struct udevice *bus, uint mode)
|
|
|
|
{
|
|
|
|
struct cadence_spi_priv *priv = dev_get_priv(bus);
|
|
|
|
|
|
|
|
/* Disable QSPI */
|
|
|
|
cadence_qspi_apb_controller_disable(priv->regbase);
|
|
|
|
|
|
|
|
/* Set SPI mode */
|
2016-11-29 12:58:31 +00:00
|
|
|
cadence_qspi_apb_set_clk_mode(priv->regbase, mode);
|
2014-11-07 11:37:49 +00:00
|
|
|
|
2020-01-27 05:06:40 +00:00
|
|
|
/* Enable Direct Access Controller */
|
2022-08-24 11:38:47 +00:00
|
|
|
if (priv->use_dac_mode)
|
2020-01-27 05:06:40 +00:00
|
|
|
cadence_qspi_apb_dac_mode_enable(priv->regbase);
|
|
|
|
|
2014-11-07 11:37:49 +00:00
|
|
|
/* Enable QSPI */
|
|
|
|
cadence_qspi_apb_controller_enable(priv->regbase);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-01-27 05:06:39 +00:00
|
|
|
static int cadence_spi_mem_exec_op(struct spi_slave *spi,
|
|
|
|
const struct spi_mem_op *op)
|
2014-11-07 11:37:49 +00:00
|
|
|
{
|
2020-01-27 05:06:39 +00:00
|
|
|
struct udevice *bus = spi->dev->parent;
|
2014-11-07 11:37:49 +00:00
|
|
|
struct cadence_spi_priv *priv = dev_get_priv(bus);
|
|
|
|
void *base = priv->regbase;
|
|
|
|
int err = 0;
|
2020-01-27 05:06:39 +00:00
|
|
|
u32 mode;
|
2014-11-07 11:37:49 +00:00
|
|
|
|
|
|
|
/* Set Chip select */
|
2020-01-27 05:06:39 +00:00
|
|
|
cadence_qspi_apb_chipselect(base, spi_chip_select(spi->dev),
|
2022-08-24 11:38:47 +00:00
|
|
|
priv->is_decoded_cs);
|
2014-11-07 11:37:49 +00:00
|
|
|
|
2020-01-27 05:06:39 +00:00
|
|
|
if (op->data.dir == SPI_MEM_DATA_IN && op->data.buf.in) {
|
2023-01-03 06:31:12 +00:00
|
|
|
/*
|
|
|
|
* Performing reads in DAC mode forces to read minimum 4 bytes
|
|
|
|
* which is unsupported on some flash devices during register
|
|
|
|
* reads, prefer STIG mode for such small reads.
|
|
|
|
*/
|
2023-04-12 10:58:55 +00:00
|
|
|
if (op->data.nbytes <= CQSPI_STIG_DATA_LEN_MAX)
|
2020-01-27 05:06:39 +00:00
|
|
|
mode = CQSPI_STIG_READ;
|
|
|
|
else
|
2020-01-27 05:06:40 +00:00
|
|
|
mode = CQSPI_READ;
|
2020-01-27 05:06:39 +00:00
|
|
|
} else {
|
2023-04-12 10:58:55 +00:00
|
|
|
if (op->data.nbytes <= CQSPI_STIG_DATA_LEN_MAX)
|
2020-01-27 05:06:39 +00:00
|
|
|
mode = CQSPI_STIG_WRITE;
|
|
|
|
else
|
2020-01-27 05:06:40 +00:00
|
|
|
mode = CQSPI_WRITE;
|
2020-01-27 05:06:39 +00:00
|
|
|
}
|
2014-11-07 11:37:49 +00:00
|
|
|
|
2020-01-27 05:06:39 +00:00
|
|
|
switch (mode) {
|
|
|
|
case CQSPI_STIG_READ:
|
2022-08-24 11:38:47 +00:00
|
|
|
err = cadence_qspi_apb_command_read_setup(priv, op);
|
2021-06-25 19:17:09 +00:00
|
|
|
if (!err)
|
2022-08-24 11:38:47 +00:00
|
|
|
err = cadence_qspi_apb_command_read(priv, op);
|
2014-11-07 11:37:49 +00:00
|
|
|
break;
|
2020-01-27 05:06:39 +00:00
|
|
|
case CQSPI_STIG_WRITE:
|
2022-08-24 11:38:47 +00:00
|
|
|
err = cadence_qspi_apb_command_write_setup(priv, op);
|
2021-06-25 19:17:09 +00:00
|
|
|
if (!err)
|
2022-08-24 11:38:47 +00:00
|
|
|
err = cadence_qspi_apb_command_write(priv, op);
|
2014-11-07 11:37:49 +00:00
|
|
|
break;
|
2020-01-27 05:06:40 +00:00
|
|
|
case CQSPI_READ:
|
2022-08-24 11:38:47 +00:00
|
|
|
err = cadence_qspi_apb_read_setup(priv, op);
|
2022-05-12 10:05:32 +00:00
|
|
|
if (!err) {
|
2022-08-24 11:38:47 +00:00
|
|
|
if (priv->is_dma)
|
|
|
|
err = cadence_qspi_apb_dma_read(priv, op);
|
2022-05-12 10:05:32 +00:00
|
|
|
else
|
2022-08-24 11:38:47 +00:00
|
|
|
err = cadence_qspi_apb_read_execute(priv, op);
|
2022-05-12 10:05:32 +00:00
|
|
|
}
|
2020-01-27 05:06:39 +00:00
|
|
|
break;
|
2020-01-27 05:06:40 +00:00
|
|
|
case CQSPI_WRITE:
|
2022-08-24 11:38:47 +00:00
|
|
|
err = cadence_qspi_apb_write_setup(priv, op);
|
2020-01-27 05:06:40 +00:00
|
|
|
if (!err)
|
2022-08-24 11:38:47 +00:00
|
|
|
err = cadence_qspi_apb_write_execute(priv, op);
|
2020-01-27 05:06:39 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
err = -1;
|
|
|
|
break;
|
2014-11-07 11:37:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2021-06-25 19:17:09 +00:00
|
|
|
static bool cadence_spi_mem_supports_op(struct spi_slave *slave,
|
|
|
|
const struct spi_mem_op *op)
|
|
|
|
{
|
|
|
|
bool all_true, all_false;
|
|
|
|
|
2023-04-12 10:58:54 +00:00
|
|
|
/*
|
|
|
|
* op->dummy.dtr is required for converting nbytes into ncycles.
|
|
|
|
* Also, don't check the dtr field of the op phase having zero nbytes.
|
|
|
|
*/
|
|
|
|
all_true = op->cmd.dtr &&
|
|
|
|
(!op->addr.nbytes || op->addr.dtr) &&
|
|
|
|
(!op->dummy.nbytes || op->dummy.dtr) &&
|
|
|
|
(!op->data.nbytes || op->data.dtr);
|
|
|
|
|
2021-06-25 19:17:09 +00:00
|
|
|
all_false = !op->cmd.dtr && !op->addr.dtr && !op->dummy.dtr &&
|
|
|
|
!op->data.dtr;
|
|
|
|
|
|
|
|
/* Mixed DTR modes not supported. */
|
|
|
|
if (!(all_true || all_false))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (all_true)
|
|
|
|
return spi_mem_dtr_supports_op(slave, op);
|
|
|
|
else
|
|
|
|
return spi_mem_default_supports_op(slave, op);
|
|
|
|
}
|
|
|
|
|
2020-12-03 23:55:21 +00:00
|
|
|
static int cadence_spi_of_to_plat(struct udevice *bus)
|
2014-11-07 11:37:49 +00:00
|
|
|
{
|
2020-12-23 02:30:28 +00:00
|
|
|
struct cadence_spi_plat *plat = dev_get_plat(bus);
|
2022-08-24 11:38:47 +00:00
|
|
|
struct cadence_spi_priv *priv = dev_get_priv(bus);
|
2019-05-09 20:11:56 +00:00
|
|
|
ofnode subnode;
|
2014-11-07 11:37:49 +00:00
|
|
|
|
2018-05-07 09:42:55 +00:00
|
|
|
plat->regbase = (void *)devfdt_get_addr_index(bus, 0);
|
2020-01-27 05:06:40 +00:00
|
|
|
plat->ahbbase = (void *)devfdt_get_addr_size_index(bus, 1,
|
|
|
|
&plat->ahbsize);
|
2019-05-09 20:11:56 +00:00
|
|
|
plat->is_decoded_cs = dev_read_bool(bus, "cdns,is-decoded-cs");
|
|
|
|
plat->fifo_depth = dev_read_u32_default(bus, "cdns,fifo-depth", 128);
|
|
|
|
plat->fifo_width = dev_read_u32_default(bus, "cdns,fifo-width", 4);
|
|
|
|
plat->trigger_address = dev_read_u32_default(bus,
|
|
|
|
"cdns,trigger-address",
|
|
|
|
0);
|
2020-01-27 05:06:40 +00:00
|
|
|
/* Use DAC mode only when MMIO window is at least 8M wide */
|
|
|
|
if (plat->ahbsize >= SZ_8M)
|
2022-08-24 11:38:47 +00:00
|
|
|
priv->use_dac_mode = true;
|
2014-11-07 11:37:49 +00:00
|
|
|
|
2022-05-12 10:05:32 +00:00
|
|
|
plat->is_dma = dev_read_bool(bus, "cdns,is-dma");
|
|
|
|
|
2022-12-09 01:39:50 +00:00
|
|
|
/* All other parameters are embedded in the child node */
|
2019-05-09 20:11:56 +00:00
|
|
|
subnode = dev_read_first_subnode(bus);
|
|
|
|
if (!ofnode_valid(subnode)) {
|
2014-11-07 11:37:49 +00:00
|
|
|
printf("Error: subnode with SPI flash config missing!\n");
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
|
2015-10-17 13:32:14 +00:00
|
|
|
/* Use 500 KHz as a suitable default */
|
2019-05-09 20:11:56 +00:00
|
|
|
plat->max_hz = ofnode_read_u32_default(subnode, "spi-max-frequency",
|
|
|
|
500000);
|
2015-10-17 13:32:14 +00:00
|
|
|
|
2014-11-07 11:37:49 +00:00
|
|
|
/* Read other parameters from DT */
|
2019-05-09 20:11:56 +00:00
|
|
|
plat->page_size = ofnode_read_u32_default(subnode, "page-size", 256);
|
|
|
|
plat->block_size = ofnode_read_u32_default(subnode, "block-size", 16);
|
|
|
|
plat->tshsl_ns = ofnode_read_u32_default(subnode, "cdns,tshsl-ns",
|
|
|
|
200);
|
|
|
|
plat->tsd2d_ns = ofnode_read_u32_default(subnode, "cdns,tsd2d-ns",
|
|
|
|
255);
|
|
|
|
plat->tchsh_ns = ofnode_read_u32_default(subnode, "cdns,tchsh-ns", 20);
|
|
|
|
plat->tslch_ns = ofnode_read_u32_default(subnode, "cdns,tslch-ns", 20);
|
2021-06-25 19:17:07 +00:00
|
|
|
/*
|
|
|
|
* Read delay should be an unsigned value but we use a signed integer
|
|
|
|
* so that negative values can indicate that the device tree did not
|
|
|
|
* specify any signed values and we need to perform the calibration
|
|
|
|
* sequence to find it out.
|
|
|
|
*/
|
|
|
|
plat->read_delay = ofnode_read_s32_default(subnode, "cdns,read-delay",
|
|
|
|
-1);
|
2014-11-07 11:37:49 +00:00
|
|
|
|
|
|
|
debug("%s: regbase=%p ahbbase=%p max-frequency=%d page-size=%d\n",
|
|
|
|
__func__, plat->regbase, plat->ahbbase, plat->max_hz,
|
|
|
|
plat->page_size);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-01-27 05:06:39 +00:00
|
|
|
static const struct spi_controller_mem_ops cadence_spi_mem_ops = {
|
|
|
|
.exec_op = cadence_spi_mem_exec_op,
|
2021-06-25 19:17:09 +00:00
|
|
|
.supports_op = cadence_spi_mem_supports_op,
|
2020-01-27 05:06:39 +00:00
|
|
|
};
|
|
|
|
|
2014-11-07 11:37:49 +00:00
|
|
|
static const struct dm_spi_ops cadence_spi_ops = {
|
|
|
|
.set_speed = cadence_spi_set_speed,
|
|
|
|
.set_mode = cadence_spi_set_mode,
|
2020-01-27 05:06:39 +00:00
|
|
|
.mem_ops = &cadence_spi_mem_ops,
|
2014-11-07 11:37:49 +00:00
|
|
|
/*
|
|
|
|
* cs_info is not needed, since we require all chip selects to be
|
|
|
|
* in the device tree explicitly
|
|
|
|
*/
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct udevice_id cadence_spi_ids[] = {
|
2018-11-02 10:54:51 +00:00
|
|
|
{ .compatible = "cdns,qspi-nor" },
|
2019-12-05 10:16:07 +00:00
|
|
|
{ .compatible = "ti,am654-ospi" },
|
2014-11-07 11:37:49 +00:00
|
|
|
{ }
|
|
|
|
};
|
|
|
|
|
|
|
|
U_BOOT_DRIVER(cadence_spi) = {
|
|
|
|
.name = "cadence_spi",
|
|
|
|
.id = UCLASS_SPI,
|
|
|
|
.of_match = cadence_spi_ids,
|
|
|
|
.ops = &cadence_spi_ops,
|
2020-12-03 23:55:21 +00:00
|
|
|
.of_to_plat = cadence_spi_of_to_plat,
|
2020-12-03 23:55:23 +00:00
|
|
|
.plat_auto = sizeof(struct cadence_spi_plat),
|
2020-12-03 23:55:17 +00:00
|
|
|
.priv_auto = sizeof(struct cadence_spi_priv),
|
2014-11-07 11:37:49 +00:00
|
|
|
.probe = cadence_spi_probe,
|
2019-03-01 19:12:35 +00:00
|
|
|
.remove = cadence_spi_remove,
|
|
|
|
.flags = DM_FLAG_OS_PREPARE,
|
2014-11-07 11:37:49 +00:00
|
|
|
};
|