1 /**
2 * Copyright (c) 2020 HiSilicon (Shanghai) Technologies CO., LIMITED.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 * Description: Provides adc port \n
16 *
17 * History: \n
18 * 2022-09-16, Create file. \n
19 */
20
21 #include "chip_core_irq.h"
22 #include "common_def.h"
23 #include "lpm_dev_ops.h"
24 #include "soc_osal.h"
25 #include "pinctrl_porting.h"
26 #include "pinctrl.h"
27 #include "debug_print.h"
28 #include "hal_adc_v154.h"
29 #include "efuse_porting.h"
30 #include "adc_porting.h"
31
32 #define ADC_BASE_ADDR 0x4400C000
33 #define CLDO_BASE_ADDR 0X44001138
34
35 static uintptr_t g_adc_base_addr = (uintptr_t)ADC_BASE_ADDR;
36 static uintptr_t g_cldo_cfg_addr = (uintptr_t)CLDO_BASE_ADDR;
37
adc_porting_base_addr_get(void)38 uintptr_t adc_porting_base_addr_get(void)
39 {
40 return g_adc_base_addr;
41 }
42
cldo_addr_get(void)43 uintptr_t cldo_addr_get(void)
44 {
45 return g_cldo_cfg_addr;
46 }
47
adc_port_clock_enable(bool on)48 void adc_port_clock_enable(bool on)
49 {
50 unused(on);
51 }
52
adc_port_init_clock(adc_clock_t clock)53 void adc_port_init_clock(adc_clock_t clock)
54 {
55 unused(clock);
56 }
57
adc_port_register_hal_funcs(void)58 void adc_port_register_hal_funcs(void)
59 {
60 hal_adc_register_funcs(hal_adc_v154_funcs_get());
61 }
62
irq_adc_handler(int32_t irq_num,const void * tmp)63 static int32_t irq_adc_handler(int32_t irq_num, const void *tmp)
64 {
65 unused(irq_num);
66 unused(tmp);
67 hal_adc_irq_handler();
68 return 0;
69 }
70
adc_port_register_irq(void)71 void adc_port_register_irq(void)
72 {
73 int ret = osal_irq_request(LSADC_IRQNR, (osal_irq_handler)irq_adc_handler, NULL, NULL, NULL);
74 if (ret != 0) {
75 print_str("adc_port_register_irq failed: %d\r\n", ret);
76 } else {
77 print_str("adc_port_register_irq succeed: %d\r\n", ret);
78 }
79 osal_irq_enable(LSADC_IRQNR);
80 }
81
adc_port_unregister_hal_funcs(void)82 void adc_port_unregister_hal_funcs(void)
83 {
84 hal_adc_unregister_funcs();
85 }
86
adc_port_unregister_irq(void)87 void adc_port_unregister_irq(void)
88 {
89 osal_irq_disable(LSADC_IRQNR);
90 osal_irq_free(LSADC_IRQNR, NULL);
91 }
92
adc_port_power_on(bool on)93 void adc_port_power_on(bool on)
94 {
95 unused(on);
96 }
97
adc_port_get_cfg(void)98 hal_adc_type_info_t *adc_port_get_cfg(void)
99 {
100 return NULL;
101 }
102
adc_port_get_cali_param(uint8_t * data_s,uint8_t * data_b,uint8_t * data_k)103 errcode_t adc_port_get_cali_param(uint8_t *data_s, uint8_t *data_b, uint8_t *data_k)
104 {
105 uint16_t data_len_s = 1, data_len_b = 2, data_len_k = 2;
106 efuse_idx efuse_id = EFUSE_GET_S_ID;
107 errcode_t res = efuse_read_item(efuse_id, data_s, data_len_s);
108 if (res != ERRCODE_SUCC) {
109 return res;
110 }
111
112 efuse_id = EFUSE_GET_B_ID;
113 res = efuse_read_item(efuse_id, data_b, data_len_b);
114 if (res != ERRCODE_SUCC) {
115 return res;
116 }
117
118 efuse_id = EFUSE_GET_K_ID;
119 res = efuse_read_item(efuse_id, data_k, data_len_k);
120 if (res != ERRCODE_SUCC) {
121 return res;
122 }
123 return res;
124 }