From 30671860d746ead98296662c226be275041ed18a Mon Sep 17 00:00:00 2001 From: Siva Durga Prasad Paladugu Date: Sun, 30 Jan 2022 22:22:39 -0700 Subject: [PATCH] spi: zynq_qspi: Add a check for baudrate and set default if not in limits Add a check afer baudrate calculation to see if the resultant value falls within the range, else set it to default baudrate value. Signed-off-by: Siva Durga Prasad Paladugu Signed-off-by: Ashok Reddy Soma Link: https://lore.kernel.org/r/20220131052240.23403-4-ashok.reddy.soma@xilinx.com Signed-off-by: Michal Simek --- drivers/spi/zynq_qspi.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/drivers/spi/zynq_qspi.c b/drivers/spi/zynq_qspi.c index aa060d7940..2963f48bb0 100644 --- a/drivers/spi/zynq_qspi.c +++ b/drivers/spi/zynq_qspi.c @@ -49,6 +49,9 @@ DECLARE_GLOBAL_DATA_PTR; #define ZYNQ_QSPI_CR_BAUD_SHIFT 3 /* Baud rate divisor shift */ #define ZYNQ_QSPI_CR_SS_SHIFT 10 /* Slave select shift */ +#define ZYNQ_QSPI_MAX_BAUD_RATE 0x7 +#define ZYNQ_QSPI_DEFAULT_BAUD_RATE 0x2 + #define ZYNQ_QSPI_FIFO_DEPTH 63 #define ZYNQ_QSPI_WAIT (CONFIG_SYS_HZ / 100) /* 10 ms */ @@ -621,6 +624,9 @@ static int zynq_qspi_set_speed(struct udevice *bus, uint speed) (2 << baud_rate_val)) > speed)) baud_rate_val++; + if (baud_rate_val > ZYNQ_QSPI_MAX_BAUD_RATE) + baud_rate_val = ZYNQ_QSPI_DEFAULT_BAUD_RATE; + plat->speed_hz = speed / (2 << baud_rate_val); } confr &= ~ZYNQ_QSPI_CR_BAUD_MASK; -- 2.39.5