1 /*
2 * SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7 // The LL layer for ESP32-H2 MODEM LPCON register operations
8
9 #pragma once
10
11 #include <stdlib.h>
12 #include "soc/soc.h"
13 #include "hal/assert.h"
14 #include "modem/modem_lpcon_struct.h"
15 #include "hal/modem_clock_types.h"
16
17 #ifdef __cplusplus
18 extern "C" {
19 #endif
20
21 __attribute__((always_inline))
modem_lpcon_ll_enable_test_clk(modem_lpcon_dev_t * hw,bool en)22 static inline void modem_lpcon_ll_enable_test_clk(modem_lpcon_dev_t *hw, bool en)
23 {
24 hw->test_conf.clk_en = en;
25 }
26
27 __attribute__((always_inline))
modem_lpcon_ll_enable_coex_lpclk_slow_osc(modem_lpcon_dev_t * hw,bool en)28 static inline void modem_lpcon_ll_enable_coex_lpclk_slow_osc(modem_lpcon_dev_t *hw, bool en)
29 {
30 hw->coex_lp_clk_conf.clk_coex_lp_sel_osc_slow = en;
31 }
32
33 __attribute__((always_inline))
modem_lpcon_ll_enable_coex_lpclk_fast_osc(modem_lpcon_dev_t * hw,bool en)34 static inline void modem_lpcon_ll_enable_coex_lpclk_fast_osc(modem_lpcon_dev_t *hw, bool en)
35 {
36 hw->coex_lp_clk_conf.clk_coex_lp_sel_osc_fast = en;
37 }
38
39 __attribute__((always_inline))
modem_lpcon_ll_enable_coex_lpclk_main_xtal(modem_lpcon_dev_t * hw,bool en)40 static inline void modem_lpcon_ll_enable_coex_lpclk_main_xtal(modem_lpcon_dev_t *hw, bool en)
41 {
42 hw->coex_lp_clk_conf.clk_coex_lp_sel_xtal = en;
43 }
44
45 __attribute__((always_inline))
modem_lpcon_ll_enable_coex_lpclk_32k_xtal(modem_lpcon_dev_t * hw,bool en)46 static inline void modem_lpcon_ll_enable_coex_lpclk_32k_xtal(modem_lpcon_dev_t *hw, bool en)
47 {
48 hw->coex_lp_clk_conf.clk_coex_lp_sel_xtal32k = en;
49 }
50
51 __attribute__((always_inline))
modem_lpcon_ll_set_coex_lpclk_divisor_value(modem_lpcon_dev_t * hw,uint32_t value)52 static inline void modem_lpcon_ll_set_coex_lpclk_divisor_value(modem_lpcon_dev_t *hw, uint32_t value)
53 {
54 hw->coex_lp_clk_conf.clk_coex_lp_div_num = value;
55 }
56
57 __attribute__((always_inline))
modem_lpcon_ll_get_coex_lpclk_divisor_value(modem_lpcon_dev_t * hw)58 static inline uint32_t modem_lpcon_ll_get_coex_lpclk_divisor_value(modem_lpcon_dev_t *hw)
59 {
60 return hw->coex_lp_clk_conf.clk_coex_lp_div_num;
61 }
62
63 __attribute__((always_inline))
modem_lpcon_ll_enable_coex_clock(modem_lpcon_dev_t * hw,bool en)64 static inline void modem_lpcon_ll_enable_coex_clock(modem_lpcon_dev_t *hw, bool en)
65 {
66 hw->clk_conf.clk_coex_en = en;
67 }
68
69 __attribute__((always_inline))
modem_lpcon_ll_enable_i2c_master_clock(modem_lpcon_dev_t * hw,bool en)70 static inline void modem_lpcon_ll_enable_i2c_master_clock(modem_lpcon_dev_t *hw, bool en)
71 {
72 hw->clk_conf.clk_i2c_mst_en = en;
73 }
74
75 __attribute__((always_inline))
modem_lpcon_ll_enable_fe_mem_clock(modem_lpcon_dev_t * hw,bool en)76 static inline void modem_lpcon_ll_enable_fe_mem_clock(modem_lpcon_dev_t *hw, bool en)
77 {
78 hw->clk_conf.clk_fe_mem_en = en;
79 }
80
81 __attribute__((always_inline))
modem_lpcon_ll_enable_coex_force_clock(modem_lpcon_dev_t * hw,bool en)82 static inline void modem_lpcon_ll_enable_coex_force_clock(modem_lpcon_dev_t *hw, bool en)
83 {
84 hw->clk_conf_force_on.clk_coex_fo = en;
85 }
86
87 __attribute__((always_inline))
modem_lpcon_ll_enable_i2c_master_force_clock(modem_lpcon_dev_t * hw,bool en)88 static inline void modem_lpcon_ll_enable_i2c_master_force_clock(modem_lpcon_dev_t *hw, bool en)
89 {
90 hw->clk_conf_force_on.clk_i2c_mst_fo = en;
91 }
92
93 __attribute__((always_inline))
modem_lpcon_ll_enable_fe_mem_force_clock(modem_lpcon_dev_t * hw,bool en)94 static inline void modem_lpcon_ll_enable_fe_mem_force_clock(modem_lpcon_dev_t *hw, bool en)
95 {
96 hw->clk_conf_force_on.clk_fe_mem_fo = en;
97 }
98
99 __attribute__((always_inline))
modem_lpcon_ll_reset_coex(modem_lpcon_dev_t * hw)100 static inline void modem_lpcon_ll_reset_coex(modem_lpcon_dev_t *hw)
101 {
102 hw->rst_conf.rst_coex = 1;
103 hw->rst_conf.rst_coex = 0;
104 }
105
106 __attribute__((always_inline))
modem_lpcon_ll_reset_i2c_master(modem_lpcon_dev_t * hw)107 static inline void modem_lpcon_ll_reset_i2c_master(modem_lpcon_dev_t *hw)
108 {
109 hw->rst_conf.rst_i2c_mst = 1;
110 hw->rst_conf.rst_i2c_mst = 0;
111 }
112
113 __attribute__((always_inline))
modem_lpcon_ll_reset_all(modem_lpcon_dev_t * hw)114 static inline void modem_lpcon_ll_reset_all(modem_lpcon_dev_t *hw)
115 {
116 hw->rst_conf.val = 0xf;
117 hw->rst_conf.val = 0;
118 }
119
120 __attribute__((always_inline))
modem_lpcon_ll_get_date(modem_lpcon_dev_t * hw)121 static inline uint32_t modem_lpcon_ll_get_date(modem_lpcon_dev_t *hw)
122 {
123 return hw->date.val;
124 }
125
126 #ifdef __cplusplus
127 }
128 #endif
129