blob: 64c5867609c004c00398e2a76fc5a23548b66604 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001/* SPDX-License-Identifier: GPL-2.0+ */
Stefan Roese1c60fe72014-11-07 12:37:49 +01002/*
3 * Copyright (C) 2012
4 * Altera Corporation <www.altera.com>
Stefan Roese1c60fe72014-11-07 12:37:49 +01005 */
6
7#ifndef __CADENCE_QSPI_H__
8#define __CADENCE_QSPI_H__
9
Simon Goldschmidt46e56a42019-03-01 20:12:35 +010010#include <reset.h>
11
Stefan Roese1c60fe72014-11-07 12:37:49 +010012#define CQSPI_IS_ADDR(cmd_len) (cmd_len > 1 ? 1 : 0)
13
14#define CQSPI_NO_DECODER_MAX_CS 4
15#define CQSPI_DECODER_MAX_CS 16
16#define CQSPI_READ_CAPTURE_MAX_DELAY 16
17
Simon Glassb75b15b2020-12-03 16:55:23 -070018struct cadence_spi_plat {
Simon Goldschmidtbaaa3fc2019-11-20 22:27:31 +010019 unsigned int ref_clk_hz;
Stefan Roese1c60fe72014-11-07 12:37:49 +010020 unsigned int max_hz;
21 void *regbase;
22 void *ahbbase;
Jason Rush1b4df5e2018-01-23 17:13:09 -060023 bool is_decoded_cs;
24 u32 fifo_depth;
25 u32 fifo_width;
26 u32 trigger_address;
Vignesh Raghavendra6b7df222020-01-27 10:36:40 +053027 fdt_addr_t ahbsize;
28 bool use_dac_mode;
Stefan Roese1c60fe72014-11-07 12:37:49 +010029
Jason Rush1b4df5e2018-01-23 17:13:09 -060030 /* Flash parameters */
Stefan Roese1c60fe72014-11-07 12:37:49 +010031 u32 page_size;
32 u32 block_size;
33 u32 tshsl_ns;
34 u32 tsd2d_ns;
35 u32 tchsh_ns;
36 u32 tslch_ns;
Stefan Roese1c60fe72014-11-07 12:37:49 +010037};
38
39struct cadence_spi_priv {
40 void *regbase;
41 void *ahbbase;
42 size_t cmd_len;
43 u8 cmd_buf[32];
44 size_t data_len;
45
46 int qspi_is_init;
47 unsigned int qspi_calibrated_hz;
48 unsigned int qspi_calibrated_cs;
Chin Liang See36431f92015-10-17 08:31:55 -050049 unsigned int previous_hz;
Simon Goldschmidt46e56a42019-03-01 20:12:35 +010050
51 struct reset_ctl_bulk resets;
Stefan Roese1c60fe72014-11-07 12:37:49 +010052};
53
54/* Functions call declaration */
Simon Glassb75b15b2020-12-03 16:55:23 -070055void cadence_qspi_apb_controller_init(struct cadence_spi_plat *plat);
Stefan Roese1c60fe72014-11-07 12:37:49 +010056void cadence_qspi_apb_controller_enable(void *reg_base_addr);
57void cadence_qspi_apb_controller_disable(void *reg_base_addr);
Vignesh Raghavendra6b7df222020-01-27 10:36:40 +053058void cadence_qspi_apb_dac_mode_enable(void *reg_base);
Stefan Roese1c60fe72014-11-07 12:37:49 +010059
60int cadence_qspi_apb_command_read(void *reg_base_addr,
Vignesh Raghavendra27516a32020-01-27 10:36:39 +053061 const struct spi_mem_op *op);
Stefan Roese1c60fe72014-11-07 12:37:49 +010062int cadence_qspi_apb_command_write(void *reg_base_addr,
Vignesh Raghavendra27516a32020-01-27 10:36:39 +053063 const struct spi_mem_op *op);
Stefan Roese1c60fe72014-11-07 12:37:49 +010064
Simon Glassb75b15b2020-12-03 16:55:23 -070065int cadence_qspi_apb_read_setup(struct cadence_spi_plat *plat,
Vignesh Raghavendra6b7df222020-01-27 10:36:40 +053066 const struct spi_mem_op *op);
Simon Glassb75b15b2020-12-03 16:55:23 -070067int cadence_qspi_apb_read_execute(struct cadence_spi_plat *plat,
Vignesh Raghavendra6b7df222020-01-27 10:36:40 +053068 const struct spi_mem_op *op);
Simon Glassb75b15b2020-12-03 16:55:23 -070069int cadence_qspi_apb_write_setup(struct cadence_spi_plat *plat,
Vignesh Raghavendra6b7df222020-01-27 10:36:40 +053070 const struct spi_mem_op *op);
Simon Glassb75b15b2020-12-03 16:55:23 -070071int cadence_qspi_apb_write_execute(struct cadence_spi_plat *plat,
Vignesh Raghavendra6b7df222020-01-27 10:36:40 +053072 const struct spi_mem_op *op);
Stefan Roese1c60fe72014-11-07 12:37:49 +010073
74void cadence_qspi_apb_chipselect(void *reg_base,
75 unsigned int chip_select, unsigned int decoder_enable);
Phil Edworthyeef2edc2016-11-29 12:58:31 +000076void cadence_qspi_apb_set_clk_mode(void *reg_base, uint mode);
Stefan Roese1c60fe72014-11-07 12:37:49 +010077void cadence_qspi_apb_config_baudrate_div(void *reg_base,
78 unsigned int ref_clk_hz, unsigned int sclk_hz);
79void cadence_qspi_apb_delay(void *reg_base,
80 unsigned int ref_clk, unsigned int sclk_hz,
81 unsigned int tshsl_ns, unsigned int tsd2d_ns,
82 unsigned int tchsh_ns, unsigned int tslch_ns);
83void cadence_qspi_apb_enter_xip(void *reg_base, char xip_dummy);
84void cadence_qspi_apb_readdata_capture(void *reg_base,
85 unsigned int bypass, unsigned int delay);
86
87#endif /* __CADENCE_QSPI_H__ */