1 /*
2  * Copyright (c) 2024 Nordic Semiconductor ASA
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 /**
8  * @brief File containing QSPI device specific definitions for the
9  * Zephyr OS layer of the Wi-Fi driver.
10  */
11 
12 #include <zephyr/kernel.h>
13 #include <zephyr/sys/printk.h>
14 #include <zephyr/drivers/gpio.h>
15 #include <zephyr/drivers/wifi/nrf_wifi/bus/qspi_if.h>
16 #include <stdio.h>
17 #include <string.h>
18 
19 #include "spi_if.h"
20 
21 static struct qspi_config config;
22 
23 #if defined(CONFIG_NRF70_ON_QSPI)
24 static struct qspi_dev qspi = {.init = qspi_init,
25 			       .deinit = qspi_deinit,
26 			       .read = qspi_read,
27 			       .write = qspi_write,
28 			       .hl_read = qspi_hl_read};
29 #else
30 static struct qspi_dev spim = {.init = spim_init,
31 			       .deinit = spim_deinit,
32 			       .read = spim_read,
33 			       .write = spim_write,
34 			       .hl_read = spim_hl_read};
35 #endif
36 
qspi_defconfig(void)37 struct qspi_config *qspi_defconfig(void)
38 {
39 	memset(&config, 0, sizeof(struct qspi_config));
40 #if defined(CONFIG_NRF70_ON_QSPI)
41 	config.addrmode = NRF_QSPI_ADDRMODE_24BIT;
42 	config.RDC4IO = 0xA0;
43 	config.easydma = true;
44 	config.quad_spi = true;
45 #endif
46 	config.addrmask = 0x800000; /* set bit23 (incr. addr mode) */
47 
48 	config.test_name = "QSPI TEST";
49 	config.test_hlread = false;
50 	config.test_iteration = 0;
51 
52 	config.qspi_slave_latency = 0;
53 
54 	config.encryption = config.CMD_CNONCE = false;
55 
56 #if defined(CONFIG_NRF70_ON_QSPI) && (NRF_QSPI_HAS_XIP_ENC || NRF_QSPI_HAS_DMA_ENC)
57 
58 	/*For #Bit 6 Enable below: i.e ALL Ones for QSPI Key*/
59 	memset(&config.p_cfg.key, 0xff, sizeof(config.p_cfg.key));
60 
61 	config.p_cfg.nonce[0] = 0x16181648;
62 	config.p_cfg.nonce[1] = 0x0;
63 	config.p_cfg.nonce[2] = 0x1;
64 
65 #endif /*CONFIG_NRF70_ON_QSPI && (NRF_QSPI_HAS_XIP_ENC || NRF_QSPI_HAS_DMA_ENC)*/
66 
67 	return &config;
68 }
69 
qspi_get_config(void)70 struct qspi_config *qspi_get_config(void)
71 {
72 	return &config;
73 }
74 
qspi_dev(void)75 struct qspi_dev *qspi_dev(void)
76 {
77 #if CONFIG_NRF70_ON_QSPI
78 	return &qspi;
79 #else
80 	return &spim;
81 #endif
82 }
83