10
10
#include <zephyr/drivers/mspi.h>
11
11
#include <zephyr/drivers/pinctrl.h>
12
12
#include <zephyr/drivers/counter.h>
13
+ #include <zephyr/drivers/gpio.h>
13
14
#include <zephyr/ipc/ipc_service.h>
14
15
#include <zephyr/pm/device.h>
15
16
#if !defined(CONFIG_MULTITHREADING )
@@ -26,10 +27,12 @@ LOG_MODULE_REGISTER(mspi_nrfe, CONFIG_MSPI_LOG_LEVEL);
26
27
#define MAX_RX_MSG_SIZE (DT_REG_SIZE(DT_NODELABEL(sram_rx)))
27
28
#define IPC_TIMEOUT_MS 100
28
29
#define EP_SEND_TIMEOUT_MS 10
30
+
29
31
#define EXTREME_DRIVE_FREQ_THRESHOLD 32000000
30
32
#define CNT0_TOP_CALCULATE (freq ) (NRFX_CEIL_DIV(SystemCoreClock, freq * 2) - 1)
31
33
#define DATA_LINE_INDEX (pinctr_fun ) (pinctr_fun - NRF_FUN_SDP_MSPI_DQ0)
32
34
#define DATA_PIN_UNUSED UINT8_MAX
35
+ #define DEVICES_MAX 5
33
36
34
37
#ifdef CONFIG_SOC_NRF54L15
35
38
@@ -40,7 +43,6 @@ LOG_MODULE_REGISTER(mspi_nrfe, CONFIG_MSPI_LOG_LEVEL);
40
43
#else
41
44
#error "Unsupported SoC for SDP MSPI"
42
45
#endif
43
-
44
46
#define SDP_MPSI_PINCTRL_DEV_CONFIG_INIT (node_id ) \
45
47
{ \
46
48
.reg = PINCTRL_REG_NONE, \
@@ -97,6 +99,7 @@ static const struct mspi_nrfe_config dev_config = {
97
99
};
98
100
99
101
static struct mspi_nrfe_data dev_data ;
102
+ static bool is_reset_sent [DEVICES_MAX ];
100
103
101
104
static void ep_recv (const void * data , size_t len , void * priv );
102
105
@@ -821,6 +824,77 @@ static int api_transceive(const struct device *dev, const struct mspi_dev_id *de
821
824
return 0 ;
822
825
}
823
826
827
+ static int api_reset_config (const struct device * dev , const struct mspi_dev_id * dev_id ,
828
+ const struct gpio_dt_spec * spec , uint8_t gpio_port_num ,
829
+ gpio_flags_t extra_flags )
830
+ {
831
+ const struct mspi_nrfe_config * drv_cfg = dev -> config ;
832
+ const struct pinctrl_state * state = & drv_cfg -> pcfg -> states [PINCTRL_STATE_DEFAULT ];
833
+ gpio_flags_t flags = spec -> dt_flags | extra_flags ;
834
+ uint8_t pin_number = spec -> pin ;
835
+ nrfe_mspi_reset_config_msg_t mspi_reset_config ;
836
+
837
+ /*
838
+ * Check if reset pin is not the same as any pin declared for MSPI device.
839
+ * If it is and it is valid, send the information to FLPR, otherwise treat it as a regular
840
+ * GPIO pin.
841
+ */
842
+ if (gpio_port_num == NRFE_MSPI_PORT_NUMBER ) {
843
+ for (uint8_t i = 0 ; i < state -> pin_cnt ; i ++ ) {
844
+ if (pin_number == NRF_PIN_NUMBER_TO_PIN (NRF_GET_PIN (state -> pins [i ]))) {
845
+ switch (NRF_GET_FUN (state -> pins [i ])) {
846
+ case NRF_FUN_SDP_MSPI_DQ0 :
847
+ case NRF_FUN_SDP_MSPI_DQ1 :
848
+ LOG_ERR ("Reset pin cannot be the same as D0 or "
849
+ "D1." );
850
+ return - EINVAL ;
851
+ case NRF_FUN_SDP_MSPI_SCK :
852
+ LOG_ERR ("Reset pin cannot be the same as CLK." );
853
+ return - EINVAL ;
854
+ case NRF_FUN_SDP_MSPI_CS0 :
855
+ case NRF_FUN_SDP_MSPI_CS1 :
856
+ case NRF_FUN_SDP_MSPI_CS2 :
857
+ case NRF_FUN_SDP_MSPI_CS3 :
858
+ LOG_ERR ("Reset pin cannot be the same as any CS." );
859
+ return - EINVAL ;
860
+ case NRF_FUN_SDP_MSPI_DQ2 :
861
+ case NRF_FUN_SDP_MSPI_DQ3 :
862
+ is_reset_sent [dev_id -> dev_idx ] = true;
863
+ mspi_reset_config .device_index = dev_id -> dev_idx ;
864
+ mspi_reset_config .reset_config .pin_number = pin_number ;
865
+ mspi_reset_config .reset_config .inversed =
866
+ ((flags & GPIO_ACTIVE_LOW ) != 0 );
867
+ /* Send reset configuration to FLPR */
868
+ return send_data (NRFE_MSPI_CONFIG_RESET ,
869
+ (const void * )& mspi_reset_config ,
870
+ sizeof (nrfe_mspi_reset_config_msg_t ));
871
+ default :
872
+ break ;
873
+ }
874
+ }
875
+ }
876
+ }
877
+
878
+ return gpio_pin_configure_dt (spec , flags );
879
+ }
880
+
881
+ static int api_reset_set (const struct device * dev , const struct gpio_dt_spec * spec ,
882
+ const struct mspi_dev_id * dev_id , int value )
883
+ {
884
+ nrfe_mspi_reset_set_msg_t mspi_reset_set ;
885
+
886
+ if (is_reset_sent [dev_id -> dev_idx ]) {
887
+ mspi_reset_set .device_index = dev_id -> dev_idx ;
888
+ mspi_reset_set .value = value ;
889
+ return send_data (NRFE_MSPI_SET_RESET , (const void * )& mspi_reset_set ,
890
+ sizeof (nrfe_mspi_reset_set_msg_t ));
891
+ } else {
892
+ return gpio_pin_set_dt (spec , value );
893
+ }
894
+
895
+ return 0 ;
896
+ }
897
+
824
898
#if CONFIG_PM_DEVICE
825
899
/**
826
900
* @brief Callback function to handle power management actions.
@@ -968,11 +1042,16 @@ static int nrfe_mspi_init(const struct device *dev)
968
1042
return ret ;
969
1043
}
970
1044
971
- static const struct mspi_driver_api drv_api = {
972
- .config = api_config ,
973
- .dev_config = api_dev_config ,
974
- .get_channel_status = api_get_channel_status ,
975
- .transceive = api_transceive ,
1045
+ static const struct nrf_mspi_driver_api drv_api = {
1046
+ .std_api =
1047
+ {
1048
+ .config = api_config ,
1049
+ .dev_config = api_dev_config ,
1050
+ .get_channel_status = api_get_channel_status ,
1051
+ .transceive = api_transceive ,
1052
+ },
1053
+ .reset_pin_config = api_reset_config ,
1054
+ .reset_pin_set = api_reset_set ,
976
1055
};
977
1056
978
1057
PM_DEVICE_DT_INST_DEFINE (0 , dev_pm_action_cb );
0 commit comments