1 /******************************************************************************
2 *
3 * Copyright (C) 2022-2023 Maxim Integrated Products, Inc. (now owned by
4 * Analog Devices, Inc.),
5 * Copyright (C) 2023-2024 Analog Devices, Inc.
6 *
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 *
19 ******************************************************************************/
20
21 /* **** Includes **** */
22 #include <string.h>
23 #include "mxc_errors.h"
24 #include "mxc_assert.h"
25 #include "mxc_sys.h"
26 #include "mxc_pins.h"
27 #include "hpb.h"
28 #include "hpb_reva.h"
29 #include "bbfc_regs.h"
30
31 /* **** Definitions **** */
32
33 /* **** Globals **** */
34
35 /* **** Functions **** */
36
37 /* ************************************************************************** */
MXC_HPB_RegRead8(mxc_hpb_cfg_reg_val_t * cfg_reg_val,uint32_t base_addr,unsigned int index)38 void MXC_HPB_RegRead8(mxc_hpb_cfg_reg_val_t *cfg_reg_val, uint32_t base_addr, unsigned int index)
39 {
40 MXC_HPB_RevA_RegRead8((mxc_hpb_reva_regs_t *)MXC_HPB, cfg_reg_val, base_addr, index);
41 }
42
43 /* ************************************************************************** */
MXC_HPB_RegWrite8(mxc_hpb_cfg_reg_val_t * cfg_reg_val,uint32_t base_addr,unsigned int index)44 void MXC_HPB_RegWrite8(mxc_hpb_cfg_reg_val_t *cfg_reg_val, uint32_t base_addr, unsigned int index)
45 {
46 MXC_HPB_RevA_RegWrite8((mxc_hpb_reva_regs_t *)MXC_HPB, cfg_reg_val, base_addr, index);
47 }
48
49 /* ************************************************************************** */
MXC_HPB_RegRead16(mxc_hpb_cfg_reg_val_t * cfg_reg_val,uint32_t base_addr,unsigned int index)50 void MXC_HPB_RegRead16(mxc_hpb_cfg_reg_val_t *cfg_reg_val, uint32_t base_addr, unsigned int index)
51 {
52 MXC_HPB_RevA_RegRead16((mxc_hpb_reva_regs_t *)MXC_HPB, cfg_reg_val, base_addr, index);
53 }
54
55 /* ************************************************************************** */
MXC_HPB_RegWrite16(mxc_hpb_cfg_reg_val_t * cfg_reg_val,uint32_t base_addr,unsigned int index)56 void MXC_HPB_RegWrite16(mxc_hpb_cfg_reg_val_t *cfg_reg_val, uint32_t base_addr, unsigned int index)
57 {
58 MXC_HPB_RevA_RegWrite16((mxc_hpb_reva_regs_t *)MXC_HPB, cfg_reg_val, base_addr, index);
59 }
60
61 /* ************************************************************************** */
MXC_HPB_Init(mxc_hpb_mem_config_t * mem0,mxc_hpb_mem_config_t * mem1)62 int MXC_HPB_Init(mxc_hpb_mem_config_t *mem0, mxc_hpb_mem_config_t *mem1)
63 {
64 /* Enable HyperBus Clocks */
65 MXC_SYS_ClockEnable(MXC_SYS_PERIPH_CLOCK_HBC);
66 MXC_SYS_ClockEnable(MXC_SYS_PERIPH_CLOCK_SCACHE);
67
68 /* Select drive strength on CK pin */
69 MXC_BBFC->bbfcr0 = (2 << MXC_F_BBFC_BBFCR0_CKPDRV_POS) | (MXC_S_BBFC_BBFCR0_RDSDLLEN_EN);
70
71 /* If Hyperbus, also select drive strength on NCK pin and enable RDS DLL */
72 if ((mem0 && (mem0->device_type != MXC_HPB_DEV_XCCELA_PSRAM)) ||
73 (mem1 && (mem1->device_type != MXC_HPB_DEV_XCCELA_PSRAM))) {
74 MXC_BBFC->bbfcr0 |= (2 << MXC_F_BBFC_BBFCR0_CKNPDRV_POS);
75 }
76
77 /* Configure HyperBus GPIO Pins */
78 if (mem0) {
79 MXC_GPIO_Config(&gpio_cfg_hyp_cs0);
80 }
81 if (mem1) {
82 MXC_GPIO_Config(&gpio_cfg_hyp_cs1);
83 }
84 MXC_GPIO_Config(&gpio_cfg_hyp);
85
86 /* Reset the controller */
87 MXC_SYS_Reset_Periph(MXC_SYS_RESET_HBC);
88
89 return MXC_HPB_RevA_Init((mxc_hpb_reva_regs_t *)MXC_HPB, mem0, mem1);
90 }
91
92 /* ************************************************************************** */
MXC_HPB_GetStatus(void)93 uint32_t MXC_HPB_GetStatus(void)
94 {
95 return MXC_HPB_RevA_GetStatus((mxc_hpb_reva_regs_t *)MXC_HPB);
96 }
97
98 /* ************************************************************************** */
MXC_HPB_EnableInt(unsigned polarity)99 void MXC_HPB_EnableInt(unsigned polarity)
100 {
101 MXC_HPB_RevA_EnableInt((mxc_hpb_reva_regs_t *)MXC_HPB, polarity);
102 }
103
104 /* ************************************************************************** */
MXC_HPB_GetFlag(void)105 unsigned MXC_HPB_GetFlag(void)
106 {
107 return MXC_HPB_RevA_GetFlag((mxc_hpb_reva_regs_t *)MXC_HPB);
108 }
109