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 )
@@ -27,6 +28,7 @@ LOG_MODULE_REGISTER(mspi_nrfe, CONFIG_MSPI_LOG_LEVEL);
27
28
#define IPC_TIMEOUT_MS 100
28
29
#define EP_SEND_TIMEOUT_MS 10
29
30
#define CNT0_TOP_CALCULATE (freq ) (NRFX_CEIL_DIV(SystemCoreClock, freq * 2) - 1)
31
+ #define DEVICES_MAX 5
30
32
31
33
#define SDP_MPSI_PINCTRL_DEV_CONFIG_INIT (node_id ) \
32
34
{ \
@@ -84,6 +86,7 @@ static const struct mspi_nrfe_config dev_config = {
84
86
};
85
87
86
88
static struct mspi_nrfe_data dev_data ;
89
+ static bool is_reset_sent [DEVICES_MAX ];
87
90
88
91
static void ep_recv (const void * data , size_t len , void * priv );
89
92
@@ -643,6 +646,77 @@ static int api_transceive(const struct device *dev, const struct mspi_dev_id *de
643
646
return 0 ;
644
647
}
645
648
649
+ static int api_reset_config (const struct device * dev , const struct mspi_dev_id * dev_id ,
650
+ const struct gpio_dt_spec * spec , uint8_t gpio_port_num ,
651
+ gpio_flags_t extra_flags )
652
+ {
653
+ const struct mspi_nrfe_config * drv_cfg = dev -> config ;
654
+ const struct pinctrl_state * state = & drv_cfg -> pcfg -> states [PINCTRL_STATE_DEFAULT ];
655
+ gpio_flags_t flags = spec -> dt_flags | extra_flags ;
656
+ uint8_t pin_number = spec -> pin ;
657
+ nrfe_mspi_reset_config_msg_t mspi_reset_config ;
658
+
659
+ /*
660
+ * Check if reset pin is not the same as any pin declared for MSPI device.
661
+ * If it is and it is valid, send the information to FLPR, otherwise treat it as a regular
662
+ * GPIO pin.
663
+ */
664
+ if (gpio_port_num == NRFE_MSPI_PORT_NUMBER ) {
665
+ for (uint8_t i = 0 ; i < state -> pin_cnt ; i ++ ) {
666
+ if (pin_number == NRF_PIN_NUMBER_TO_PIN (NRF_GET_PIN (state -> pins [i ]))) {
667
+ switch (NRF_GET_FUN (state -> pins [i ])) {
668
+ case NRF_FUN_SDP_MSPI_DQ0 :
669
+ case NRF_FUN_SDP_MSPI_DQ1 :
670
+ LOG_ERR ("Reset pin cannot be the same as D0 or "
671
+ "D1." );
672
+ return - EINVAL ;
673
+ case NRF_FUN_SDP_MSPI_SCK :
674
+ LOG_ERR ("Reset pin cannot be the same as CLK." );
675
+ return - EINVAL ;
676
+ case NRF_FUN_SDP_MSPI_CS0 :
677
+ case NRF_FUN_SDP_MSPI_CS1 :
678
+ case NRF_FUN_SDP_MSPI_CS2 :
679
+ case NRF_FUN_SDP_MSPI_CS3 :
680
+ LOG_ERR ("Reset pin cannot be the same as any CS." );
681
+ return - EINVAL ;
682
+ case NRF_FUN_SDP_MSPI_DQ2 :
683
+ case NRF_FUN_SDP_MSPI_DQ3 :
684
+ is_reset_sent [dev_id -> dev_idx ] = true;
685
+ mspi_reset_config .device_index = dev_id -> dev_idx ;
686
+ mspi_reset_config .reset_config .pin_number = pin_number ;
687
+ mspi_reset_config .reset_config .inversed =
688
+ ((flags & GPIO_ACTIVE_LOW ) != 0 );
689
+ /* Send reset configuration to FLPR */
690
+ return send_data (NRFE_MSPI_CONFIG_RESET ,
691
+ (const void * )& mspi_reset_config ,
692
+ sizeof (nrfe_mspi_reset_config_msg_t ));
693
+ default :
694
+ break ;
695
+ }
696
+ }
697
+ }
698
+ }
699
+
700
+ return gpio_pin_configure_dt (spec , flags );
701
+ }
702
+
703
+ static int api_reset_set (const struct device * dev , const struct gpio_dt_spec * spec ,
704
+ const struct mspi_dev_id * dev_id , int value )
705
+ {
706
+ nrfe_mspi_reset_set_msg_t mspi_reset_set ;
707
+
708
+ if (is_reset_sent [dev_id -> dev_idx ]) {
709
+ mspi_reset_set .device_index = dev_id -> dev_idx ;
710
+ mspi_reset_set .value = value ;
711
+ return send_data (NRFE_MSPI_SET_RESET , (const void * )& mspi_reset_set ,
712
+ sizeof (nrfe_mspi_reset_set_msg_t ));
713
+ } else {
714
+ return gpio_pin_set_dt (spec , value );
715
+ }
716
+
717
+ return 0 ;
718
+ }
719
+
646
720
#if CONFIG_PM_DEVICE
647
721
/**
648
722
* @brief Callback function to handle power management actions.
@@ -790,11 +864,16 @@ static int nrfe_mspi_init(const struct device *dev)
790
864
return ret ;
791
865
}
792
866
793
- static const struct mspi_driver_api drv_api = {
794
- .config = api_config ,
795
- .dev_config = api_dev_config ,
796
- .get_channel_status = api_get_channel_status ,
797
- .transceive = api_transceive ,
867
+ static const struct nrf_mspi_driver_api drv_api = {
868
+ .std_api =
869
+ {
870
+ .config = api_config ,
871
+ .dev_config = api_dev_config ,
872
+ .get_channel_status = api_get_channel_status ,
873
+ .transceive = api_transceive ,
874
+ },
875
+ .reset_pin_config = api_reset_config ,
876
+ .reset_pin_set = api_reset_set ,
798
877
};
799
878
800
879
PM_DEVICE_DT_INST_DEFINE (0 , dev_pm_action_cb );
0 commit comments