blob: 49b401168fc9dc2fa019155bbac868c5919950a2 [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;
Pratyush Yadav8e0be9e2021-06-26 00:47:07 +053029 int read_delay;
Pratyush Yadav8dcf3e22021-06-26 00:47:08 +053030 u32 wr_delay;
Stefan Roese1c60fe72014-11-07 12:37:49 +010031
Jason Rush1b4df5e2018-01-23 17:13:09 -060032 /* Flash parameters */
Stefan Roese1c60fe72014-11-07 12:37:49 +010033 u32 page_size;
34 u32 block_size;
35 u32 tshsl_ns;
36 u32 tsd2d_ns;
37 u32 tchsh_ns;
38 u32 tslch_ns;
Pratyush Yadave1814ad2021-06-26 00:47:09 +053039
40 /* Transaction protocol parameters. */
41 u8 inst_width;
42 u8 addr_width;
43 u8 data_width;
44 bool dtr;
Stefan Roese1c60fe72014-11-07 12:37:49 +010045};
46
47struct cadence_spi_priv {
48 void *regbase;
49 void *ahbbase;
50 size_t cmd_len;
51 u8 cmd_buf[32];
52 size_t data_len;
53
54 int qspi_is_init;
55 unsigned int qspi_calibrated_hz;
56 unsigned int qspi_calibrated_cs;
Chin Liang See36431f92015-10-17 08:31:55 -050057 unsigned int previous_hz;
Simon Goldschmidt46e56a42019-03-01 20:12:35 +010058
59 struct reset_ctl_bulk resets;
Stefan Roese1c60fe72014-11-07 12:37:49 +010060};
61
62/* Functions call declaration */
Simon Glassb75b15b2020-12-03 16:55:23 -070063void cadence_qspi_apb_controller_init(struct cadence_spi_plat *plat);
Stefan Roese1c60fe72014-11-07 12:37:49 +010064void cadence_qspi_apb_controller_enable(void *reg_base_addr);
65void cadence_qspi_apb_controller_disable(void *reg_base_addr);
Vignesh Raghavendra6b7df222020-01-27 10:36:40 +053066void cadence_qspi_apb_dac_mode_enable(void *reg_base);
Stefan Roese1c60fe72014-11-07 12:37:49 +010067
Pratyush Yadave1814ad2021-06-26 00:47:09 +053068int cadence_qspi_apb_command_read_setup(struct cadence_spi_plat *plat,
69 const struct spi_mem_op *op);
70int cadence_qspi_apb_command_read(struct cadence_spi_plat *plat,
Vignesh Raghavendra27516a32020-01-27 10:36:39 +053071 const struct spi_mem_op *op);
Pratyush Yadave1814ad2021-06-26 00:47:09 +053072int cadence_qspi_apb_command_write_setup(struct cadence_spi_plat *plat,
73 const struct spi_mem_op *op);
74int cadence_qspi_apb_command_write(struct cadence_spi_plat *plat,
Vignesh Raghavendra27516a32020-01-27 10:36:39 +053075 const struct spi_mem_op *op);
Stefan Roese1c60fe72014-11-07 12:37:49 +010076
Simon Glassb75b15b2020-12-03 16:55:23 -070077int cadence_qspi_apb_read_setup(struct cadence_spi_plat *plat,
Vignesh Raghavendra6b7df222020-01-27 10:36:40 +053078 const struct spi_mem_op *op);
Simon Glassb75b15b2020-12-03 16:55:23 -070079int cadence_qspi_apb_read_execute(struct cadence_spi_plat *plat,
Vignesh Raghavendra6b7df222020-01-27 10:36:40 +053080 const struct spi_mem_op *op);
Simon Glassb75b15b2020-12-03 16:55:23 -070081int cadence_qspi_apb_write_setup(struct cadence_spi_plat *plat,
Vignesh Raghavendra6b7df222020-01-27 10:36:40 +053082 const struct spi_mem_op *op);
Simon Glassb75b15b2020-12-03 16:55:23 -070083int cadence_qspi_apb_write_execute(struct cadence_spi_plat *plat,
Vignesh Raghavendra6b7df222020-01-27 10:36:40 +053084 const struct spi_mem_op *op);
Stefan Roese1c60fe72014-11-07 12:37:49 +010085
86void cadence_qspi_apb_chipselect(void *reg_base,
87 unsigned int chip_select, unsigned int decoder_enable);
Phil Edworthyeef2edc2016-11-29 12:58:31 +000088void cadence_qspi_apb_set_clk_mode(void *reg_base, uint mode);
Stefan Roese1c60fe72014-11-07 12:37:49 +010089void cadence_qspi_apb_config_baudrate_div(void *reg_base,
90 unsigned int ref_clk_hz, unsigned int sclk_hz);
91void cadence_qspi_apb_delay(void *reg_base,
92 unsigned int ref_clk, unsigned int sclk_hz,
93 unsigned int tshsl_ns, unsigned int tsd2d_ns,
94 unsigned int tchsh_ns, unsigned int tslch_ns);
95void cadence_qspi_apb_enter_xip(void *reg_base, char xip_dummy);
96void cadence_qspi_apb_readdata_capture(void *reg_base,
97 unsigned int bypass, unsigned int delay);
98
99#endif /* __CADENCE_QSPI_H__ */