1 /*
2  * Copyright (c) 2023 Pawel Osypiuk <pawelosyp@gmail.com>
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #include <soc.h>
8 #include <zephyr/device.h>
9 #if defined(CONFIG_BT_CTLR_DEBUG_PINS_CPUAPP)
10 #include <../subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/debug.h>
11 #else
12 #define DEBUG_SETUP()
13 #endif /* defined(CONFIG_BT_CTLR_DEBUG_PINS_CPUAPP) */
14 
15 #define LOG_LEVEL CONFIG_BT_HCI_DRIVER_LOG_LEVEL
16 #include <zephyr/logging/log.h>
17 LOG_MODULE_REGISTER(bt_hci_nrf53_support);
18 
bt_hci_transport_teardown(const struct device * dev)19 int bt_hci_transport_teardown(const struct device *dev)
20 {
21 	ARG_UNUSED(dev);
22     /* Put core into reset */
23 	NRF_RESET->NETWORK.FORCEOFF = RESET_NETWORK_FORCEOFF_FORCEOFF_Hold;
24 	LOG_DBG("Network MCU reseted.");
25 
26 	return 0;
27 }
28 
bt_hci_transport_setup(const struct device * dev)29 int bt_hci_transport_setup(const struct device *dev)
30 {
31 	ARG_UNUSED(dev);
32 #if !defined(CONFIG_TRUSTED_EXECUTION_NONSECURE) || defined(CONFIG_BUILD_WITH_TFM)
33 	/* Route Bluetooth Controller Debug Pins */
34 	DEBUG_SETUP();
35 #endif /* !defined(CONFIG_TRUSTED_EXECUTION_NONSECURE) || defined(CONFIG_BUILD_WITH_TFM) */
36 
37 #if !defined(CONFIG_TRUSTED_EXECUTION_NONSECURE)
38 	/* Retain nRF5340 Network MCU in Secure domain (bus
39 	 * accesses by Network MCU will have Secure attribute set).
40 	 */
41 	NRF_SPU->EXTDOMAIN[0].PERM = 1 << 4;
42 #endif /* !defined(CONFIG_TRUSTED_EXECUTION_NONSECURE) */
43 
44 	NRF_RESET->NETWORK.FORCEOFF = RESET_NETWORK_FORCEOFF_FORCEOFF_Release;
45 
46 	return 0;
47 }
48