1 /* 2 * Copyright 2024 Microchip Technology Inc. and its subsidiaries. 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 */ 6 #ifndef _MEC_VCI_H 7 #define _MEC_VCI_H 8 9 #include <stdbool.h> 10 #include <stddef.h> 11 #include <stdint.h> 12 13 #include <device_mec5.h> 14 #include "mec_vci_api.h" 15 #include "mec_retval.h" 16 17 /* Interfaces to any C modules */ 18 #ifdef __cplusplus 19 extern "C" 20 { 21 #endif 22 23 enum mec_vci_sel { 24 MEC_VCI_IN0_POS = 0, 25 MEC_VCI_IN1_POS, 26 MEC_VCI_IN2_POS, 27 MEC_VCI_IN3_POS, 28 MEC_VCI_IN4_POS, 29 MEC_VCI_IN5_POS, 30 MEC_VCI_IN6_POS, 31 MEC_VCI_OVRD_IN = 8, 32 MEC_VCI_OUT, 33 MEC_VCI_IN_WEEK_ALARM_POS = 16, 34 MEC_VCI_IN_RTC_ALARM_POS, 35 }; 36 37 int mec_hal_vci_pin_disable(uint8_t vci_id); 38 39 /* Return current state of VCI pin inputs. If latching is enabled 40 * the current state is the latched state otherwise the state is 41 * live pin after filtering and polarity are applied. 42 * b[6:0] = VCI_IN[6:0] 43 * b[8] = current VCI_OVRD_IN state 44 * b[9] = current VCI_OUT state 45 * b[16] = Week Alarm state 46 * b[17] = RTC Alaram state 47 */ 48 uint32_t mec_hal_vci_in_pin_states(struct mec_vci_regs *regs); 49 50 /* VCI_IN[] pin filter enable/disable */ 51 int mec_hal_vci_in_filter_enable(struct mec_vci_regs *regs, uint8_t enable); 52 53 /* set the state of software controlled VCI_OUT pin state 54 * This value has no effect on VCI_OUT pin unless the FW_EXT bit is 1. 55 */ 56 int mec_hal_vci_sw_vci_out_set(struct mec_vci_regs *regs, uint8_t pin_state); 57 58 /* Enable software control of VCI_OUT pin state */ 59 int mec_hal_vci_sw_vci_out_enable(struct mec_vci_regs *regs, uint8_t enable); 60 61 uint8_t mec_hal_vci_out_get(struct mec_vci_regs *regs); 62 uint8_t mec_hal_vci_ovrd_in_get(struct mec_vci_regs *regs); 63 64 /* Return bitmap of VCI_IN[6:0] input latched state */ 65 uint32_t mec_hal_vci_in_latched_get(struct mec_vci_regs *regs); 66 67 int mec_hal_vci_in_latch_enable(struct mec_vci_regs *regs, uint32_t latch_bitmap); 68 int mec_hal_vci_in_latch_disable(struct mec_vci_regs *regs, uint32_t latch_bitmap); 69 uint32_t mec_hal_vci_in_latch_enable_get(struct mec_vci_regs *regs); 70 71 /* clear latched state of selected VCI inputs */ 72 int mec_hal_vci_in_latch_reset(struct mec_vci_regs *regs, uint32_t latch_bitmap); 73 int mec_hal_vci_in_input_enable(struct mec_vci_regs *regs, uint32_t latch_bitmap); 74 uint32_t mec_hal_vci_in_input_enable_get(struct mec_vci_regs *regs); 75 76 /* Program the delay after nSYS_SHDN asserts before VCI logic re-asserts 77 * VCI_OUT. A value of zero disables the delay. Non-zero values should 78 * be in the range [125, 32000] milliseconds. 79 */ 80 int mec_hal_vci_out_power_on_delay(struct mec_vci_regs *regs, uint32_t delay_ms); 81 82 /* Set the polarity of selected VCI_IN[n] pins. 83 * Polarity = 1 Active High 84 * = 0 Active Low 85 */ 86 int mec_hal_vci_in_polarity(struct mec_vci_regs *regs, uint32_t vci_in_bitmap, 87 uint32_t polarity_bitmap); 88 89 /* Return bitmap of detected positive edges on VCI_IN[] pins */ 90 uint32_t mec_hal_vci_pedge_detect(struct mec_vci_regs *regs); 91 92 /* Return bitmap of detected negative edges on VCI_IN[] pins */ 93 uint32_t mec_hal_vci_nedge_detect(struct mec_vci_regs *regs); 94 95 /* Clear edge detection logic */ 96 void mec_hal_vci_pedge_detect_clr(struct mec_vci_regs *regs, uint32_t bitmap); 97 void mec_hal_vci_nedge_detect_clr(struct mec_vci_regs *regs, uint32_t bitmap); 98 void mec_hal_vci_edge_detect_clr_all(struct mec_vci_regs *regs); 99 100 /* Select which VCI_IN[] pin edge detector are enabled when the chip 101 * is powered only by the VBAT power rail (VTR Core is off). 102 * When the chip is on (VTR Core ON) this register has no effect on 103 * the edge detector enables. 104 */ 105 uint32_t mec_hal_vci_vbat_edge_detect_get(struct mec_vci_regs *regs); 106 int mec_hal_vci_vbat_edge_detect(struct mec_vci_regs *regs, uint32_t bitmap); 107 108 #ifdef MEC5_VCI_HAS_LID_DETECT 109 int mec_hal_vci_lid_detect_enable(struct mec_vci_regs *regs); 110 #endif 111 112 #ifdef __cplusplus 113 } 114 #endif 115 116 #endif /* #ifndef _MEC_VCI_H */ 117