Rajan Vaja | 5529a01 | 2018-01-17 02:39:23 -0800 | [diff] [blame] | 1 | /* |
Michal Simek | 2a47faa | 2023-04-14 08:43:51 +0200 | [diff] [blame] | 2 | * Copyright (c) 2018-2022, Arm Limited and Contributors. All rights reserved. |
Jay Buddhabhatti | 26e138a | 2022-12-21 23:03:35 -0800 | [diff] [blame] | 3 | * Copyright (c) 2022-2023, Advanced Micro Devices, Inc. All rights reserved. |
Rajan Vaja | 5529a01 | 2018-01-17 02:39:23 -0800 | [diff] [blame] | 4 | * |
| 5 | * SPDX-License-Identifier: BSD-3-Clause |
| 6 | */ |
| 7 | |
| 8 | /* |
| 9 | * ZynqMP system level PM-API functions for ioctl. |
| 10 | */ |
| 11 | |
| 12 | #include <arch_helpers.h> |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 13 | #include <drivers/delay_timer.h> |
| 14 | #include <lib/mmio.h> |
| 15 | #include <plat/common/platform.h> |
Jolly Shah | 16fe5ab | 2019-01-08 11:16:16 -0800 | [diff] [blame] | 16 | #include <zynqmp_def.h> |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 17 | |
Rajan Vaja | 3511613 | 2018-01-17 02:39:25 -0800 | [diff] [blame] | 18 | #include "pm_api_clock.h" |
Rajan Vaja | 5529a01 | 2018-01-17 02:39:23 -0800 | [diff] [blame] | 19 | #include "pm_api_ioctl.h" |
Rajan Vaja | 5529a01 | 2018-01-17 02:39:23 -0800 | [diff] [blame] | 20 | #include "pm_client.h" |
| 21 | #include "pm_common.h" |
| 22 | #include "pm_ipi.h" |
Jay Buddhabhatti | 26e138a | 2022-12-21 23:03:35 -0800 | [diff] [blame] | 23 | #include "zynqmp_pm_api_sys.h" |
Rajan Vaja | 5529a01 | 2018-01-17 02:39:23 -0800 | [diff] [blame] | 24 | |
| 25 | /** |
| 26 | * pm_ioctl_get_rpu_oper_mode () - Get current RPU operation mode |
| 27 | * @mode Buffer to store value of oper mode(Split/Lock-step) |
| 28 | * |
| 29 | * This function provides current configured RPU operational mode. |
| 30 | * |
| 31 | * @return Returns status, either success or error+reason |
| 32 | */ |
Venkatesh Yadav Abbarapu | e7c4538 | 2022-05-19 14:49:49 +0530 | [diff] [blame] | 33 | static enum pm_ret_status pm_ioctl_get_rpu_oper_mode(uint32_t *mode) |
Rajan Vaja | 5529a01 | 2018-01-17 02:39:23 -0800 | [diff] [blame] | 34 | { |
Venkatesh Yadav Abbarapu | e7c4538 | 2022-05-19 14:49:49 +0530 | [diff] [blame] | 35 | uint32_t val; |
Rajan Vaja | 5529a01 | 2018-01-17 02:39:23 -0800 | [diff] [blame] | 36 | |
| 37 | val = mmio_read_32(ZYNQMP_RPU_GLBL_CNTL); |
| 38 | val &= ZYNQMP_SLSPLIT_MASK; |
Venkatesh Yadav Abbarapu | a2ca35d | 2022-07-04 11:40:27 +0530 | [diff] [blame] | 39 | if (val == 0U) { |
Rajan Vaja | 5529a01 | 2018-01-17 02:39:23 -0800 | [diff] [blame] | 40 | *mode = PM_RPU_MODE_LOCKSTEP; |
Venkatesh Yadav Abbarapu | 987fad3 | 2022-04-29 13:52:00 +0530 | [diff] [blame] | 41 | } else { |
Jolly Shah | 69fb5bf | 2018-02-07 16:25:41 -0800 | [diff] [blame] | 42 | *mode = PM_RPU_MODE_SPLIT; |
Venkatesh Yadav Abbarapu | 987fad3 | 2022-04-29 13:52:00 +0530 | [diff] [blame] | 43 | } |
Rajan Vaja | 5529a01 | 2018-01-17 02:39:23 -0800 | [diff] [blame] | 44 | |
| 45 | return PM_RET_SUCCESS; |
| 46 | } |
| 47 | |
| 48 | /** |
| 49 | * pm_ioctl_set_rpu_oper_mode () - Configure RPU operation mode |
| 50 | * @mode Value to set for oper mode(Split/Lock-step) |
| 51 | * |
| 52 | * This function configures RPU operational mode(Split/Lock-step). |
| 53 | * It also sets TCM combined mode in RPU lock-step and TCM non-combined |
| 54 | * mode for RPU split mode. In case of Lock step mode, RPU1's output is |
| 55 | * clamped. |
| 56 | * |
| 57 | * @return Returns status, either success or error+reason |
| 58 | */ |
Venkatesh Yadav Abbarapu | e7c4538 | 2022-05-19 14:49:49 +0530 | [diff] [blame] | 59 | static enum pm_ret_status pm_ioctl_set_rpu_oper_mode(uint32_t mode) |
Rajan Vaja | 5529a01 | 2018-01-17 02:39:23 -0800 | [diff] [blame] | 60 | { |
Venkatesh Yadav Abbarapu | e7c4538 | 2022-05-19 14:49:49 +0530 | [diff] [blame] | 61 | uint32_t val; |
Rajan Vaja | 5529a01 | 2018-01-17 02:39:23 -0800 | [diff] [blame] | 62 | |
Venkatesh Yadav Abbarapu | 987fad3 | 2022-04-29 13:52:00 +0530 | [diff] [blame] | 63 | if (mmio_read_32(CRL_APB_RST_LPD_TOP) & CRL_APB_RPU_AMBA_RESET) { |
Rajan Vaja | 5529a01 | 2018-01-17 02:39:23 -0800 | [diff] [blame] | 64 | return PM_RET_ERROR_ACCESS; |
Venkatesh Yadav Abbarapu | 987fad3 | 2022-04-29 13:52:00 +0530 | [diff] [blame] | 65 | } |
Rajan Vaja | 5529a01 | 2018-01-17 02:39:23 -0800 | [diff] [blame] | 66 | |
| 67 | val = mmio_read_32(ZYNQMP_RPU_GLBL_CNTL); |
| 68 | |
| 69 | if (mode == PM_RPU_MODE_SPLIT) { |
| 70 | val |= ZYNQMP_SLSPLIT_MASK; |
| 71 | val &= ~ZYNQMP_TCM_COMB_MASK; |
| 72 | val &= ~ZYNQMP_SLCLAMP_MASK; |
| 73 | } else if (mode == PM_RPU_MODE_LOCKSTEP) { |
| 74 | val &= ~ZYNQMP_SLSPLIT_MASK; |
| 75 | val |= ZYNQMP_TCM_COMB_MASK; |
| 76 | val |= ZYNQMP_SLCLAMP_MASK; |
| 77 | } else { |
| 78 | return PM_RET_ERROR_ARGS; |
| 79 | } |
| 80 | |
| 81 | mmio_write_32(ZYNQMP_RPU_GLBL_CNTL, val); |
| 82 | |
| 83 | return PM_RET_SUCCESS; |
| 84 | } |
| 85 | |
| 86 | /** |
| 87 | * pm_ioctl_config_boot_addr() - Configure RPU boot address |
| 88 | * @nid Node ID of RPU |
| 89 | * @value Value to set for boot address (TCM/OCM) |
| 90 | * |
| 91 | * This function configures RPU boot address(memory). |
| 92 | * |
| 93 | * @return Returns status, either success or error+reason |
| 94 | */ |
| 95 | static enum pm_ret_status pm_ioctl_config_boot_addr(enum pm_node_id nid, |
Venkatesh Yadav Abbarapu | e7c4538 | 2022-05-19 14:49:49 +0530 | [diff] [blame] | 96 | uint32_t value) |
Rajan Vaja | 5529a01 | 2018-01-17 02:39:23 -0800 | [diff] [blame] | 97 | { |
Venkatesh Yadav Abbarapu | e7c4538 | 2022-05-19 14:49:49 +0530 | [diff] [blame] | 98 | uint32_t rpu_cfg_addr, val; |
Rajan Vaja | 5529a01 | 2018-01-17 02:39:23 -0800 | [diff] [blame] | 99 | |
Venkatesh Yadav Abbarapu | 987fad3 | 2022-04-29 13:52:00 +0530 | [diff] [blame] | 100 | if (nid == NODE_RPU_0) { |
Rajan Vaja | 5529a01 | 2018-01-17 02:39:23 -0800 | [diff] [blame] | 101 | rpu_cfg_addr = ZYNQMP_RPU0_CFG; |
Venkatesh Yadav Abbarapu | 987fad3 | 2022-04-29 13:52:00 +0530 | [diff] [blame] | 102 | } else if (nid == NODE_RPU_1) { |
Rajan Vaja | 5529a01 | 2018-01-17 02:39:23 -0800 | [diff] [blame] | 103 | rpu_cfg_addr = ZYNQMP_RPU1_CFG; |
Venkatesh Yadav Abbarapu | 987fad3 | 2022-04-29 13:52:00 +0530 | [diff] [blame] | 104 | } else { |
Rajan Vaja | 5529a01 | 2018-01-17 02:39:23 -0800 | [diff] [blame] | 105 | return PM_RET_ERROR_ARGS; |
Venkatesh Yadav Abbarapu | 987fad3 | 2022-04-29 13:52:00 +0530 | [diff] [blame] | 106 | } |
Rajan Vaja | 5529a01 | 2018-01-17 02:39:23 -0800 | [diff] [blame] | 107 | |
| 108 | val = mmio_read_32(rpu_cfg_addr); |
| 109 | |
Venkatesh Yadav Abbarapu | 987fad3 | 2022-04-29 13:52:00 +0530 | [diff] [blame] | 110 | if (value == PM_RPU_BOOTMEM_LOVEC) { |
Rajan Vaja | 5529a01 | 2018-01-17 02:39:23 -0800 | [diff] [blame] | 111 | val &= ~ZYNQMP_VINITHI_MASK; |
Venkatesh Yadav Abbarapu | 987fad3 | 2022-04-29 13:52:00 +0530 | [diff] [blame] | 112 | } else if (value == PM_RPU_BOOTMEM_HIVEC) { |
Rajan Vaja | 5529a01 | 2018-01-17 02:39:23 -0800 | [diff] [blame] | 113 | val |= ZYNQMP_VINITHI_MASK; |
Venkatesh Yadav Abbarapu | 987fad3 | 2022-04-29 13:52:00 +0530 | [diff] [blame] | 114 | } else { |
Rajan Vaja | 5529a01 | 2018-01-17 02:39:23 -0800 | [diff] [blame] | 115 | return PM_RET_ERROR_ARGS; |
Venkatesh Yadav Abbarapu | 987fad3 | 2022-04-29 13:52:00 +0530 | [diff] [blame] | 116 | } |
Rajan Vaja | 5529a01 | 2018-01-17 02:39:23 -0800 | [diff] [blame] | 117 | |
| 118 | mmio_write_32(rpu_cfg_addr, val); |
| 119 | |
| 120 | return PM_RET_SUCCESS; |
| 121 | } |
| 122 | |
| 123 | /** |
| 124 | * pm_ioctl_config_tcm_comb() - Configure TCM combined mode |
| 125 | * @value Value to set (Split/Combined) |
| 126 | * |
| 127 | * This function configures TCM to be in split mode or combined |
| 128 | * mode. |
| 129 | * |
| 130 | * @return Returns status, either success or error+reason |
| 131 | */ |
Venkatesh Yadav Abbarapu | e7c4538 | 2022-05-19 14:49:49 +0530 | [diff] [blame] | 132 | static enum pm_ret_status pm_ioctl_config_tcm_comb(uint32_t value) |
Rajan Vaja | 5529a01 | 2018-01-17 02:39:23 -0800 | [diff] [blame] | 133 | { |
Venkatesh Yadav Abbarapu | e7c4538 | 2022-05-19 14:49:49 +0530 | [diff] [blame] | 134 | uint32_t val; |
Rajan Vaja | 5529a01 | 2018-01-17 02:39:23 -0800 | [diff] [blame] | 135 | |
| 136 | val = mmio_read_32(ZYNQMP_RPU_GLBL_CNTL); |
| 137 | |
Venkatesh Yadav Abbarapu | 987fad3 | 2022-04-29 13:52:00 +0530 | [diff] [blame] | 138 | if (value == PM_RPU_TCM_SPLIT) { |
Rajan Vaja | 5529a01 | 2018-01-17 02:39:23 -0800 | [diff] [blame] | 139 | val &= ~ZYNQMP_TCM_COMB_MASK; |
Venkatesh Yadav Abbarapu | 987fad3 | 2022-04-29 13:52:00 +0530 | [diff] [blame] | 140 | } else if (value == PM_RPU_TCM_COMB) { |
Rajan Vaja | 5529a01 | 2018-01-17 02:39:23 -0800 | [diff] [blame] | 141 | val |= ZYNQMP_TCM_COMB_MASK; |
Venkatesh Yadav Abbarapu | 987fad3 | 2022-04-29 13:52:00 +0530 | [diff] [blame] | 142 | } else { |
Rajan Vaja | 5529a01 | 2018-01-17 02:39:23 -0800 | [diff] [blame] | 143 | return PM_RET_ERROR_ARGS; |
Venkatesh Yadav Abbarapu | 987fad3 | 2022-04-29 13:52:00 +0530 | [diff] [blame] | 144 | } |
Rajan Vaja | 5529a01 | 2018-01-17 02:39:23 -0800 | [diff] [blame] | 145 | |
| 146 | mmio_write_32(ZYNQMP_RPU_GLBL_CNTL, val); |
| 147 | |
| 148 | return PM_RET_SUCCESS; |
| 149 | } |
| 150 | |
| 151 | /** |
Rajan Vaja | aea41bb | 2018-01-17 02:39:24 -0800 | [diff] [blame] | 152 | * pm_ioctl_set_tapdelay_bypass() - Enable/Disable tap delay bypass |
| 153 | * @type Type of tap delay to enable/disable (e.g. QSPI) |
| 154 | * @value Enable/Disable |
| 155 | * |
| 156 | * This function enable/disable tap delay bypass. |
| 157 | * |
| 158 | * @return Returns status, either success or error+reason |
| 159 | */ |
Venkatesh Yadav Abbarapu | e7c4538 | 2022-05-19 14:49:49 +0530 | [diff] [blame] | 160 | static enum pm_ret_status pm_ioctl_set_tapdelay_bypass(uint32_t type, |
| 161 | uint32_t value) |
Rajan Vaja | aea41bb | 2018-01-17 02:39:24 -0800 | [diff] [blame] | 162 | { |
| 163 | if ((value != PM_TAPDELAY_BYPASS_ENABLE && |
Venkatesh Yadav Abbarapu | 987fad3 | 2022-04-29 13:52:00 +0530 | [diff] [blame] | 164 | value != PM_TAPDELAY_BYPASS_DISABLE) || type >= PM_TAPDELAY_MAX) { |
Rajan Vaja | aea41bb | 2018-01-17 02:39:24 -0800 | [diff] [blame] | 165 | return PM_RET_ERROR_ARGS; |
Venkatesh Yadav Abbarapu | 987fad3 | 2022-04-29 13:52:00 +0530 | [diff] [blame] | 166 | } |
Rajan Vaja | aea41bb | 2018-01-17 02:39:24 -0800 | [diff] [blame] | 167 | |
| 168 | return pm_mmio_write(IOU_TAPDLY_BYPASS, TAP_DELAY_MASK, value << type); |
| 169 | } |
| 170 | |
| 171 | /** |
| 172 | * pm_ioctl_set_sgmii_mode() - Set SGMII mode for the GEM device |
| 173 | * @nid Node ID of the device |
| 174 | * @value Enable/Disable |
| 175 | * |
| 176 | * This function enable/disable SGMII mode for the GEM device. |
| 177 | * While enabling SGMII mode, it also ties the GEM PCS Signal |
| 178 | * Detect to 1 and selects EMIO for RX clock generation. |
| 179 | * |
| 180 | * @return Returns status, either success or error+reason |
| 181 | */ |
| 182 | static enum pm_ret_status pm_ioctl_set_sgmii_mode(enum pm_node_id nid, |
Venkatesh Yadav Abbarapu | e7c4538 | 2022-05-19 14:49:49 +0530 | [diff] [blame] | 183 | uint32_t value) |
Rajan Vaja | aea41bb | 2018-01-17 02:39:24 -0800 | [diff] [blame] | 184 | { |
Venkatesh Yadav Abbarapu | e7c4538 | 2022-05-19 14:49:49 +0530 | [diff] [blame] | 185 | uint32_t val, mask, shift; |
Jolly Shah | 69fb5bf | 2018-02-07 16:25:41 -0800 | [diff] [blame] | 186 | enum pm_ret_status ret; |
Rajan Vaja | aea41bb | 2018-01-17 02:39:24 -0800 | [diff] [blame] | 187 | |
Venkatesh Yadav Abbarapu | 987fad3 | 2022-04-29 13:52:00 +0530 | [diff] [blame] | 188 | if (value != PM_SGMII_DISABLE && value != PM_SGMII_ENABLE) { |
Rajan Vaja | aea41bb | 2018-01-17 02:39:24 -0800 | [diff] [blame] | 189 | return PM_RET_ERROR_ARGS; |
Venkatesh Yadav Abbarapu | 987fad3 | 2022-04-29 13:52:00 +0530 | [diff] [blame] | 190 | } |
Rajan Vaja | aea41bb | 2018-01-17 02:39:24 -0800 | [diff] [blame] | 191 | |
| 192 | switch (nid) { |
| 193 | case NODE_ETH_0: |
| 194 | shift = 0; |
| 195 | break; |
| 196 | case NODE_ETH_1: |
| 197 | shift = 1; |
| 198 | break; |
| 199 | case NODE_ETH_2: |
| 200 | shift = 2; |
| 201 | break; |
| 202 | case NODE_ETH_3: |
| 203 | shift = 3; |
| 204 | break; |
| 205 | default: |
| 206 | return PM_RET_ERROR_ARGS; |
| 207 | } |
| 208 | |
| 209 | if (value == PM_SGMII_DISABLE) { |
| 210 | mask = GEM_SGMII_MASK << GEM_CLK_CTRL_OFFSET * shift; |
Jolly Shah | 69fb5bf | 2018-02-07 16:25:41 -0800 | [diff] [blame] | 211 | ret = pm_mmio_write(IOU_GEM_CLK_CTRL, mask, 0U); |
Rajan Vaja | aea41bb | 2018-01-17 02:39:24 -0800 | [diff] [blame] | 212 | } else { |
| 213 | /* Tie the GEM PCS Signal Detect to 1 */ |
| 214 | mask = SGMII_SD_MASK << SGMII_SD_OFFSET * shift; |
| 215 | val = SGMII_PCS_SD_1 << SGMII_SD_OFFSET * shift; |
| 216 | ret = pm_mmio_write(IOU_GEM_CTRL, mask, val); |
Venkatesh Yadav Abbarapu | 987fad3 | 2022-04-29 13:52:00 +0530 | [diff] [blame] | 217 | if (ret != PM_RET_SUCCESS) { |
Rajan Vaja | aea41bb | 2018-01-17 02:39:24 -0800 | [diff] [blame] | 218 | return ret; |
Venkatesh Yadav Abbarapu | 987fad3 | 2022-04-29 13:52:00 +0530 | [diff] [blame] | 219 | } |
Rajan Vaja | aea41bb | 2018-01-17 02:39:24 -0800 | [diff] [blame] | 220 | |
| 221 | /* Set the GEM to SGMII mode */ |
| 222 | mask = GEM_CLK_CTRL_MASK << GEM_CLK_CTRL_OFFSET * shift; |
| 223 | val = GEM_RX_SRC_SEL_GTR | GEM_SGMII_MODE; |
| 224 | val <<= GEM_CLK_CTRL_OFFSET * shift; |
| 225 | ret = pm_mmio_write(IOU_GEM_CLK_CTRL, mask, val); |
| 226 | } |
| 227 | |
| 228 | return ret; |
| 229 | } |
| 230 | |
| 231 | /** |
| 232 | * pm_ioctl_sd_dll_reset() - Reset DLL logic |
| 233 | * @nid Node ID of the device |
| 234 | * @type Reset type |
| 235 | * |
| 236 | * This function resets DLL logic for the SD device. |
| 237 | * |
| 238 | * @return Returns status, either success or error+reason |
| 239 | */ |
| 240 | static enum pm_ret_status pm_ioctl_sd_dll_reset(enum pm_node_id nid, |
Venkatesh Yadav Abbarapu | e7c4538 | 2022-05-19 14:49:49 +0530 | [diff] [blame] | 241 | uint32_t type) |
Rajan Vaja | aea41bb | 2018-01-17 02:39:24 -0800 | [diff] [blame] | 242 | { |
Venkatesh Yadav Abbarapu | e7c4538 | 2022-05-19 14:49:49 +0530 | [diff] [blame] | 243 | uint32_t mask, val; |
Jolly Shah | 69fb5bf | 2018-02-07 16:25:41 -0800 | [diff] [blame] | 244 | enum pm_ret_status ret; |
Rajan Vaja | aea41bb | 2018-01-17 02:39:24 -0800 | [diff] [blame] | 245 | |
| 246 | if (nid == NODE_SD_0) { |
| 247 | mask = ZYNQMP_SD0_DLL_RST_MASK; |
| 248 | val = ZYNQMP_SD0_DLL_RST; |
| 249 | } else if (nid == NODE_SD_1) { |
| 250 | mask = ZYNQMP_SD1_DLL_RST_MASK; |
| 251 | val = ZYNQMP_SD1_DLL_RST; |
| 252 | } else { |
| 253 | return PM_RET_ERROR_ARGS; |
| 254 | } |
| 255 | |
| 256 | switch (type) { |
| 257 | case PM_DLL_RESET_ASSERT: |
| 258 | case PM_DLL_RESET_PULSE: |
| 259 | ret = pm_mmio_write(ZYNQMP_SD_DLL_CTRL, mask, val); |
Venkatesh Yadav Abbarapu | 987fad3 | 2022-04-29 13:52:00 +0530 | [diff] [blame] | 260 | if (ret != PM_RET_SUCCESS) { |
Rajan Vaja | aea41bb | 2018-01-17 02:39:24 -0800 | [diff] [blame] | 261 | return ret; |
Venkatesh Yadav Abbarapu | 987fad3 | 2022-04-29 13:52:00 +0530 | [diff] [blame] | 262 | } |
Rajan Vaja | aea41bb | 2018-01-17 02:39:24 -0800 | [diff] [blame] | 263 | |
Venkatesh Yadav Abbarapu | 987fad3 | 2022-04-29 13:52:00 +0530 | [diff] [blame] | 264 | if (type == PM_DLL_RESET_ASSERT) { |
Rajan Vaja | aea41bb | 2018-01-17 02:39:24 -0800 | [diff] [blame] | 265 | break; |
Venkatesh Yadav Abbarapu | 987fad3 | 2022-04-29 13:52:00 +0530 | [diff] [blame] | 266 | } |
Rajan Vaja | aea41bb | 2018-01-17 02:39:24 -0800 | [diff] [blame] | 267 | mdelay(1); |
Daniel Boulby | 8942a1b | 2018-06-22 14:16:03 +0100 | [diff] [blame] | 268 | /* Fallthrough */ |
Rajan Vaja | aea41bb | 2018-01-17 02:39:24 -0800 | [diff] [blame] | 269 | case PM_DLL_RESET_RELEASE: |
| 270 | ret = pm_mmio_write(ZYNQMP_SD_DLL_CTRL, mask, 0); |
| 271 | break; |
| 272 | default: |
| 273 | ret = PM_RET_ERROR_ARGS; |
Jolly Shah | 69fb5bf | 2018-02-07 16:25:41 -0800 | [diff] [blame] | 274 | break; |
Rajan Vaja | aea41bb | 2018-01-17 02:39:24 -0800 | [diff] [blame] | 275 | } |
| 276 | |
| 277 | return ret; |
| 278 | } |
| 279 | |
| 280 | /** |
| 281 | * pm_ioctl_sd_set_tapdelay() - Set tap delay for the SD device |
| 282 | * @nid Node ID of the device |
| 283 | * @type Type of tap delay to set (input/output) |
| 284 | * @value Value to set fot the tap delay |
| 285 | * |
| 286 | * This function sets input/output tap delay for the SD device. |
| 287 | * |
| 288 | * @return Returns status, either success or error+reason |
| 289 | */ |
| 290 | static enum pm_ret_status pm_ioctl_sd_set_tapdelay(enum pm_node_id nid, |
| 291 | enum tap_delay_type type, |
Venkatesh Yadav Abbarapu | e7c4538 | 2022-05-19 14:49:49 +0530 | [diff] [blame] | 292 | uint32_t value) |
Rajan Vaja | aea41bb | 2018-01-17 02:39:24 -0800 | [diff] [blame] | 293 | { |
Venkatesh Yadav Abbarapu | e7c4538 | 2022-05-19 14:49:49 +0530 | [diff] [blame] | 294 | uint32_t shift; |
Jolly Shah | 69fb5bf | 2018-02-07 16:25:41 -0800 | [diff] [blame] | 295 | enum pm_ret_status ret; |
Venkatesh Yadav Abbarapu | e7c4538 | 2022-05-19 14:49:49 +0530 | [diff] [blame] | 296 | uint32_t val, mask; |
Rajan Vaja | aea41bb | 2018-01-17 02:39:24 -0800 | [diff] [blame] | 297 | |
Sai Krishna Potthuri | ad48c50 | 2020-10-20 07:00:06 -0600 | [diff] [blame] | 298 | if (nid == NODE_SD_0) { |
Rajan Vaja | aea41bb | 2018-01-17 02:39:24 -0800 | [diff] [blame] | 299 | shift = 0; |
Sai Krishna Potthuri | ad48c50 | 2020-10-20 07:00:06 -0600 | [diff] [blame] | 300 | mask = ZYNQMP_SD0_DLL_RST_MASK; |
| 301 | } else if (nid == NODE_SD_1) { |
Rajan Vaja | aea41bb | 2018-01-17 02:39:24 -0800 | [diff] [blame] | 302 | shift = ZYNQMP_SD_TAP_OFFSET; |
Sai Krishna Potthuri | ad48c50 | 2020-10-20 07:00:06 -0600 | [diff] [blame] | 303 | mask = ZYNQMP_SD1_DLL_RST_MASK; |
| 304 | } else { |
Rajan Vaja | aea41bb | 2018-01-17 02:39:24 -0800 | [diff] [blame] | 305 | return PM_RET_ERROR_ARGS; |
Sai Krishna Potthuri | ad48c50 | 2020-10-20 07:00:06 -0600 | [diff] [blame] | 306 | } |
Rajan Vaja | aea41bb | 2018-01-17 02:39:24 -0800 | [diff] [blame] | 307 | |
Sai Krishna Potthuri | ad48c50 | 2020-10-20 07:00:06 -0600 | [diff] [blame] | 308 | ret = pm_mmio_read(ZYNQMP_SD_DLL_CTRL, &val); |
| 309 | if (ret != PM_RET_SUCCESS) { |
Rajan Vaja | aea41bb | 2018-01-17 02:39:24 -0800 | [diff] [blame] | 310 | return ret; |
Sai Krishna Potthuri | ad48c50 | 2020-10-20 07:00:06 -0600 | [diff] [blame] | 311 | } |
| 312 | |
Venkatesh Yadav Abbarapu | a2ca35d | 2022-07-04 11:40:27 +0530 | [diff] [blame] | 313 | if ((val & mask) == 0U) { |
Sai Krishna Potthuri | ad48c50 | 2020-10-20 07:00:06 -0600 | [diff] [blame] | 314 | ret = pm_ioctl_sd_dll_reset(nid, PM_DLL_RESET_ASSERT); |
| 315 | if (ret != PM_RET_SUCCESS) { |
| 316 | return ret; |
| 317 | } |
| 318 | } |
Rajan Vaja | aea41bb | 2018-01-17 02:39:24 -0800 | [diff] [blame] | 319 | |
| 320 | if (type == PM_TAPDELAY_INPUT) { |
| 321 | ret = pm_mmio_write(ZYNQMP_SD_ITAP_DLY, |
Jolly Shah | 69fb5bf | 2018-02-07 16:25:41 -0800 | [diff] [blame] | 322 | (ZYNQMP_SD_ITAPCHGWIN_MASK << shift), |
| 323 | (ZYNQMP_SD_ITAPCHGWIN << shift)); |
Venkatesh Yadav Abbarapu | 987fad3 | 2022-04-29 13:52:00 +0530 | [diff] [blame] | 324 | |
| 325 | if (ret != PM_RET_SUCCESS) { |
Rajan Vaja | aea41bb | 2018-01-17 02:39:24 -0800 | [diff] [blame] | 326 | goto reset_release; |
Venkatesh Yadav Abbarapu | 987fad3 | 2022-04-29 13:52:00 +0530 | [diff] [blame] | 327 | } |
| 328 | |
Venkatesh Yadav Abbarapu | a2ca35d | 2022-07-04 11:40:27 +0530 | [diff] [blame] | 329 | if (value == 0U) { |
Sai Krishna Potthuri | 15da582 | 2020-10-30 00:09:43 -0600 | [diff] [blame] | 330 | ret = pm_mmio_write(ZYNQMP_SD_ITAP_DLY, |
| 331 | (ZYNQMP_SD_ITAPDLYENA_MASK << |
| 332 | shift), 0); |
Venkatesh Yadav Abbarapu | 987fad3 | 2022-04-29 13:52:00 +0530 | [diff] [blame] | 333 | } else { |
Sai Krishna Potthuri | 15da582 | 2020-10-30 00:09:43 -0600 | [diff] [blame] | 334 | ret = pm_mmio_write(ZYNQMP_SD_ITAP_DLY, |
| 335 | (ZYNQMP_SD_ITAPDLYENA_MASK << |
| 336 | shift), (ZYNQMP_SD_ITAPDLYENA << |
| 337 | shift)); |
Venkatesh Yadav Abbarapu | 987fad3 | 2022-04-29 13:52:00 +0530 | [diff] [blame] | 338 | } |
| 339 | |
| 340 | if (ret != PM_RET_SUCCESS) { |
Rajan Vaja | aea41bb | 2018-01-17 02:39:24 -0800 | [diff] [blame] | 341 | goto reset_release; |
Venkatesh Yadav Abbarapu | 987fad3 | 2022-04-29 13:52:00 +0530 | [diff] [blame] | 342 | } |
| 343 | |
Rajan Vaja | aea41bb | 2018-01-17 02:39:24 -0800 | [diff] [blame] | 344 | ret = pm_mmio_write(ZYNQMP_SD_ITAP_DLY, |
Jolly Shah | 69fb5bf | 2018-02-07 16:25:41 -0800 | [diff] [blame] | 345 | (ZYNQMP_SD_ITAPDLYSEL_MASK << shift), |
| 346 | (value << shift)); |
Venkatesh Yadav Abbarapu | 987fad3 | 2022-04-29 13:52:00 +0530 | [diff] [blame] | 347 | |
| 348 | if (ret != PM_RET_SUCCESS) { |
Rajan Vaja | aea41bb | 2018-01-17 02:39:24 -0800 | [diff] [blame] | 349 | goto reset_release; |
Venkatesh Yadav Abbarapu | 987fad3 | 2022-04-29 13:52:00 +0530 | [diff] [blame] | 350 | } |
| 351 | |
Rajan Vaja | aea41bb | 2018-01-17 02:39:24 -0800 | [diff] [blame] | 352 | ret = pm_mmio_write(ZYNQMP_SD_ITAP_DLY, |
Jolly Shah | 69fb5bf | 2018-02-07 16:25:41 -0800 | [diff] [blame] | 353 | (ZYNQMP_SD_ITAPCHGWIN_MASK << shift), 0); |
Rajan Vaja | aea41bb | 2018-01-17 02:39:24 -0800 | [diff] [blame] | 354 | } else if (type == PM_TAPDELAY_OUTPUT) { |
| 355 | ret = pm_mmio_write(ZYNQMP_SD_OTAP_DLY, |
Sai Krishna Potthuri | 15da582 | 2020-10-30 00:09:43 -0600 | [diff] [blame] | 356 | (ZYNQMP_SD_OTAPDLYENA_MASK << shift), 0); |
Venkatesh Yadav Abbarapu | 987fad3 | 2022-04-29 13:52:00 +0530 | [diff] [blame] | 357 | |
| 358 | if (ret != PM_RET_SUCCESS) { |
Rajan Vaja | aea41bb | 2018-01-17 02:39:24 -0800 | [diff] [blame] | 359 | goto reset_release; |
Venkatesh Yadav Abbarapu | 987fad3 | 2022-04-29 13:52:00 +0530 | [diff] [blame] | 360 | } |
| 361 | |
Rajan Vaja | aea41bb | 2018-01-17 02:39:24 -0800 | [diff] [blame] | 362 | ret = pm_mmio_write(ZYNQMP_SD_OTAP_DLY, |
Jolly Shah | 69fb5bf | 2018-02-07 16:25:41 -0800 | [diff] [blame] | 363 | (ZYNQMP_SD_OTAPDLYSEL_MASK << shift), |
| 364 | (value << shift)); |
Rajan Vaja | aea41bb | 2018-01-17 02:39:24 -0800 | [diff] [blame] | 365 | } else { |
| 366 | ret = PM_RET_ERROR_ARGS; |
| 367 | } |
| 368 | |
| 369 | reset_release: |
Sai Krishna Potthuri | ad48c50 | 2020-10-20 07:00:06 -0600 | [diff] [blame] | 370 | if ((val & mask) == 0) { |
| 371 | (void)pm_ioctl_sd_dll_reset(nid, PM_DLL_RESET_RELEASE); |
| 372 | } |
| 373 | |
Rajan Vaja | aea41bb | 2018-01-17 02:39:24 -0800 | [diff] [blame] | 374 | return ret; |
| 375 | } |
| 376 | |
| 377 | /** |
Rajan Vaja | 3511613 | 2018-01-17 02:39:25 -0800 | [diff] [blame] | 378 | * pm_ioctl_set_pll_frac_mode() - Ioctl function for |
| 379 | * setting pll mode |
Jolly Shah | cb5bc75 | 2019-01-02 12:46:46 -0800 | [diff] [blame] | 380 | * @pll PLL clock id |
Rajan Vaja | 3511613 | 2018-01-17 02:39:25 -0800 | [diff] [blame] | 381 | * @mode Mode fraction/integar |
| 382 | * |
| 383 | * This function sets PLL mode |
| 384 | * |
| 385 | * @return Returns status, either success or error+reason |
| 386 | */ |
| 387 | static enum pm_ret_status pm_ioctl_set_pll_frac_mode |
Venkatesh Yadav Abbarapu | e7c4538 | 2022-05-19 14:49:49 +0530 | [diff] [blame] | 388 | (uint32_t pll, uint32_t mode) |
Rajan Vaja | 3511613 | 2018-01-17 02:39:25 -0800 | [diff] [blame] | 389 | { |
Jolly Shah | cb5bc75 | 2019-01-02 12:46:46 -0800 | [diff] [blame] | 390 | return pm_clock_set_pll_mode(pll, mode); |
Rajan Vaja | 3511613 | 2018-01-17 02:39:25 -0800 | [diff] [blame] | 391 | } |
| 392 | |
| 393 | /** |
| 394 | * pm_ioctl_get_pll_frac_mode() - Ioctl function for |
| 395 | * getting pll mode |
Jolly Shah | 77eb52f | 2019-01-02 12:49:21 -0800 | [diff] [blame] | 396 | * @pll PLL clock id |
Rajan Vaja | 3511613 | 2018-01-17 02:39:25 -0800 | [diff] [blame] | 397 | * @mode Mode fraction/integar |
| 398 | * |
| 399 | * This function return current PLL mode |
| 400 | * |
| 401 | * @return Returns status, either success or error+reason |
| 402 | */ |
| 403 | static enum pm_ret_status pm_ioctl_get_pll_frac_mode |
Venkatesh Yadav Abbarapu | e7c4538 | 2022-05-19 14:49:49 +0530 | [diff] [blame] | 404 | (uint32_t pll, uint32_t *mode) |
Rajan Vaja | 3511613 | 2018-01-17 02:39:25 -0800 | [diff] [blame] | 405 | { |
Jolly Shah | 77eb52f | 2019-01-02 12:49:21 -0800 | [diff] [blame] | 406 | return pm_clock_get_pll_mode(pll, mode); |
Rajan Vaja | 3511613 | 2018-01-17 02:39:25 -0800 | [diff] [blame] | 407 | } |
| 408 | |
| 409 | /** |
| 410 | * pm_ioctl_set_pll_frac_data() - Ioctl function for |
| 411 | * setting pll fraction data |
Jolly Shah | 68116ef | 2019-01-02 12:42:56 -0800 | [diff] [blame] | 412 | * @pll PLL clock id |
Rajan Vaja | 3511613 | 2018-01-17 02:39:25 -0800 | [diff] [blame] | 413 | * @data fraction data |
| 414 | * |
| 415 | * This function sets fraction data. |
| 416 | * It is valid for fraction mode only. |
| 417 | * |
| 418 | * @return Returns status, either success or error+reason |
| 419 | */ |
| 420 | static enum pm_ret_status pm_ioctl_set_pll_frac_data |
Venkatesh Yadav Abbarapu | e7c4538 | 2022-05-19 14:49:49 +0530 | [diff] [blame] | 421 | (uint32_t pll, uint32_t data) |
Rajan Vaja | 3511613 | 2018-01-17 02:39:25 -0800 | [diff] [blame] | 422 | { |
Jolly Shah | 68116ef | 2019-01-02 12:42:56 -0800 | [diff] [blame] | 423 | enum pm_node_id pll_nid; |
| 424 | enum pm_ret_status status; |
| 425 | |
| 426 | /* Get PLL node ID using PLL clock ID */ |
| 427 | status = pm_clock_get_pll_node_id(pll, &pll_nid); |
Venkatesh Yadav Abbarapu | 987fad3 | 2022-04-29 13:52:00 +0530 | [diff] [blame] | 428 | if (status != PM_RET_SUCCESS) { |
Jolly Shah | 68116ef | 2019-01-02 12:42:56 -0800 | [diff] [blame] | 429 | return status; |
Venkatesh Yadav Abbarapu | 987fad3 | 2022-04-29 13:52:00 +0530 | [diff] [blame] | 430 | } |
Jolly Shah | 68116ef | 2019-01-02 12:42:56 -0800 | [diff] [blame] | 431 | |
| 432 | return pm_pll_set_parameter(pll_nid, PM_PLL_PARAM_DATA, data); |
Rajan Vaja | 3511613 | 2018-01-17 02:39:25 -0800 | [diff] [blame] | 433 | } |
| 434 | |
| 435 | /** |
| 436 | * pm_ioctl_get_pll_frac_data() - Ioctl function for |
| 437 | * getting pll fraction data |
Jolly Shah | b4c9946 | 2019-01-02 12:40:17 -0800 | [diff] [blame] | 438 | * @pll PLL clock id |
Rajan Vaja | 3511613 | 2018-01-17 02:39:25 -0800 | [diff] [blame] | 439 | * @data fraction data |
| 440 | * |
| 441 | * This function returns fraction data value. |
| 442 | * |
| 443 | * @return Returns status, either success or error+reason |
| 444 | */ |
| 445 | static enum pm_ret_status pm_ioctl_get_pll_frac_data |
Venkatesh Yadav Abbarapu | e7c4538 | 2022-05-19 14:49:49 +0530 | [diff] [blame] | 446 | (uint32_t pll, uint32_t *data) |
Rajan Vaja | 3511613 | 2018-01-17 02:39:25 -0800 | [diff] [blame] | 447 | { |
Jolly Shah | b4c9946 | 2019-01-02 12:40:17 -0800 | [diff] [blame] | 448 | enum pm_node_id pll_nid; |
| 449 | enum pm_ret_status status; |
| 450 | |
| 451 | /* Get PLL node ID using PLL clock ID */ |
| 452 | status = pm_clock_get_pll_node_id(pll, &pll_nid); |
Venkatesh Yadav Abbarapu | 987fad3 | 2022-04-29 13:52:00 +0530 | [diff] [blame] | 453 | if (status != PM_RET_SUCCESS) { |
Jolly Shah | b4c9946 | 2019-01-02 12:40:17 -0800 | [diff] [blame] | 454 | return status; |
Venkatesh Yadav Abbarapu | 987fad3 | 2022-04-29 13:52:00 +0530 | [diff] [blame] | 455 | } |
Jolly Shah | b4c9946 | 2019-01-02 12:40:17 -0800 | [diff] [blame] | 456 | |
| 457 | return pm_pll_get_parameter(pll_nid, PM_PLL_PARAM_DATA, data); |
Rajan Vaja | 3511613 | 2018-01-17 02:39:25 -0800 | [diff] [blame] | 458 | } |
| 459 | |
| 460 | /** |
Rajan Vaja | 393c0a2 | 2018-01-17 02:39:27 -0800 | [diff] [blame] | 461 | * pm_ioctl_write_ggs() - Ioctl function for writing |
| 462 | * global general storage (ggs) |
| 463 | * @index GGS register index |
| 464 | * @value Register value to be written |
| 465 | * |
| 466 | * This function writes value to GGS register. |
| 467 | * |
| 468 | * @return Returns status, either success or error+reason |
| 469 | */ |
Venkatesh Yadav Abbarapu | e7c4538 | 2022-05-19 14:49:49 +0530 | [diff] [blame] | 470 | static enum pm_ret_status pm_ioctl_write_ggs(uint32_t index, |
| 471 | uint32_t value) |
Rajan Vaja | 393c0a2 | 2018-01-17 02:39:27 -0800 | [diff] [blame] | 472 | { |
Venkatesh Yadav Abbarapu | 987fad3 | 2022-04-29 13:52:00 +0530 | [diff] [blame] | 473 | if (index >= GGS_NUM_REGS) { |
Rajan Vaja | 393c0a2 | 2018-01-17 02:39:27 -0800 | [diff] [blame] | 474 | return PM_RET_ERROR_ARGS; |
Venkatesh Yadav Abbarapu | 987fad3 | 2022-04-29 13:52:00 +0530 | [diff] [blame] | 475 | } |
Rajan Vaja | 393c0a2 | 2018-01-17 02:39:27 -0800 | [diff] [blame] | 476 | |
Jolly Shah | 69fb5bf | 2018-02-07 16:25:41 -0800 | [diff] [blame] | 477 | return pm_mmio_write(GGS_BASEADDR + (index << 2), |
| 478 | 0xFFFFFFFFU, value); |
Rajan Vaja | 393c0a2 | 2018-01-17 02:39:27 -0800 | [diff] [blame] | 479 | } |
| 480 | |
| 481 | /** |
| 482 | * pm_ioctl_read_ggs() - Ioctl function for reading |
| 483 | * global general storage (ggs) |
| 484 | * @index GGS register index |
| 485 | * @value Register value |
| 486 | * |
| 487 | * This function returns GGS register value. |
| 488 | * |
| 489 | * @return Returns status, either success or error+reason |
| 490 | */ |
Venkatesh Yadav Abbarapu | e7c4538 | 2022-05-19 14:49:49 +0530 | [diff] [blame] | 491 | static enum pm_ret_status pm_ioctl_read_ggs(uint32_t index, |
| 492 | uint32_t *value) |
Rajan Vaja | 393c0a2 | 2018-01-17 02:39:27 -0800 | [diff] [blame] | 493 | { |
Venkatesh Yadav Abbarapu | 987fad3 | 2022-04-29 13:52:00 +0530 | [diff] [blame] | 494 | if (index >= GGS_NUM_REGS) { |
Rajan Vaja | 393c0a2 | 2018-01-17 02:39:27 -0800 | [diff] [blame] | 495 | return PM_RET_ERROR_ARGS; |
Venkatesh Yadav Abbarapu | 987fad3 | 2022-04-29 13:52:00 +0530 | [diff] [blame] | 496 | } |
Rajan Vaja | 393c0a2 | 2018-01-17 02:39:27 -0800 | [diff] [blame] | 497 | |
| 498 | return pm_mmio_read(GGS_BASEADDR + (index << 2), value); |
| 499 | } |
| 500 | |
| 501 | /** |
| 502 | * pm_ioctl_write_pggs() - Ioctl function for writing persistent |
| 503 | * global general storage (pggs) |
| 504 | * @index PGGS register index |
| 505 | * @value Register value to be written |
| 506 | * |
| 507 | * This function writes value to PGGS register. |
| 508 | * |
| 509 | * @return Returns status, either success or error+reason |
| 510 | */ |
Venkatesh Yadav Abbarapu | e7c4538 | 2022-05-19 14:49:49 +0530 | [diff] [blame] | 511 | static enum pm_ret_status pm_ioctl_write_pggs(uint32_t index, |
| 512 | uint32_t value) |
Rajan Vaja | 393c0a2 | 2018-01-17 02:39:27 -0800 | [diff] [blame] | 513 | { |
Venkatesh Yadav Abbarapu | 987fad3 | 2022-04-29 13:52:00 +0530 | [diff] [blame] | 514 | if (index >= PGGS_NUM_REGS) { |
Rajan Vaja | 393c0a2 | 2018-01-17 02:39:27 -0800 | [diff] [blame] | 515 | return PM_RET_ERROR_ARGS; |
Venkatesh Yadav Abbarapu | 987fad3 | 2022-04-29 13:52:00 +0530 | [diff] [blame] | 516 | } |
Rajan Vaja | 393c0a2 | 2018-01-17 02:39:27 -0800 | [diff] [blame] | 517 | |
Jolly Shah | 69fb5bf | 2018-02-07 16:25:41 -0800 | [diff] [blame] | 518 | return pm_mmio_write(PGGS_BASEADDR + (index << 2), |
| 519 | 0xFFFFFFFFU, value); |
Rajan Vaja | 393c0a2 | 2018-01-17 02:39:27 -0800 | [diff] [blame] | 520 | } |
| 521 | |
| 522 | /** |
Siva Durga Prasad Paladugu | a22b885 | 2018-09-04 17:27:12 +0530 | [diff] [blame] | 523 | * pm_ioctl_afi() - Ioctl function for writing afi values |
| 524 | * |
| 525 | * @index AFI register index |
| 526 | * @value Register value to be written |
| 527 | * |
| 528 | * |
| 529 | * @return Returns status, either success or error+reason |
| 530 | */ |
Venkatesh Yadav Abbarapu | e7c4538 | 2022-05-19 14:49:49 +0530 | [diff] [blame] | 531 | static enum pm_ret_status pm_ioctl_afi(uint32_t index, |
| 532 | uint32_t value) |
Siva Durga Prasad Paladugu | a22b885 | 2018-09-04 17:27:12 +0530 | [diff] [blame] | 533 | { |
Venkatesh Yadav Abbarapu | e7c4538 | 2022-05-19 14:49:49 +0530 | [diff] [blame] | 534 | uint32_t mask; |
| 535 | uint32_t regarr[] = {0xFD360000U, |
Venkatesh Yadav Abbarapu | ed4f1e8 | 2022-04-29 09:58:30 +0530 | [diff] [blame] | 536 | 0xFD360014U, |
| 537 | 0xFD370000U, |
| 538 | 0xFD370014U, |
| 539 | 0xFD380000U, |
| 540 | 0xFD380014U, |
| 541 | 0xFD390000U, |
| 542 | 0xFD390014U, |
| 543 | 0xFD3a0000U, |
| 544 | 0xFD3a0014U, |
| 545 | 0xFD3b0000U, |
| 546 | 0xFD3b0014U, |
| 547 | 0xFF9b0000U, |
| 548 | 0xFF9b0014U, |
| 549 | 0xFD615000U, |
| 550 | 0xFF419000U, |
Siva Durga Prasad Paladugu | a22b885 | 2018-09-04 17:27:12 +0530 | [diff] [blame] | 551 | }; |
| 552 | |
Venkatesh Yadav Abbarapu | 987fad3 | 2022-04-29 13:52:00 +0530 | [diff] [blame] | 553 | if (index >= ARRAY_SIZE(regarr)) { |
Siva Durga Prasad Paladugu | a22b885 | 2018-09-04 17:27:12 +0530 | [diff] [blame] | 554 | return PM_RET_ERROR_ARGS; |
Venkatesh Yadav Abbarapu | 987fad3 | 2022-04-29 13:52:00 +0530 | [diff] [blame] | 555 | } |
Siva Durga Prasad Paladugu | a22b885 | 2018-09-04 17:27:12 +0530 | [diff] [blame] | 556 | |
Akshay Belsare | af00b31 | 2022-08-23 11:39:35 +0530 | [diff] [blame] | 557 | if (index <= AFIFM6_WRCTRL) { |
Siva Durga Prasad Paladugu | a22b885 | 2018-09-04 17:27:12 +0530 | [diff] [blame] | 558 | mask = FABRIC_WIDTH; |
Venkatesh Yadav Abbarapu | 987fad3 | 2022-04-29 13:52:00 +0530 | [diff] [blame] | 559 | } else { |
Siva Durga Prasad Paladugu | a22b885 | 2018-09-04 17:27:12 +0530 | [diff] [blame] | 560 | mask = 0xf00; |
Venkatesh Yadav Abbarapu | 987fad3 | 2022-04-29 13:52:00 +0530 | [diff] [blame] | 561 | } |
Siva Durga Prasad Paladugu | a22b885 | 2018-09-04 17:27:12 +0530 | [diff] [blame] | 562 | |
| 563 | return pm_mmio_write(regarr[index], mask, value); |
| 564 | } |
| 565 | |
| 566 | /** |
Rajan Vaja | 393c0a2 | 2018-01-17 02:39:27 -0800 | [diff] [blame] | 567 | * pm_ioctl_read_pggs() - Ioctl function for reading persistent |
| 568 | * global general storage (pggs) |
| 569 | * @index PGGS register index |
| 570 | * @value Register value |
| 571 | * |
| 572 | * This function returns PGGS register value. |
| 573 | * |
| 574 | * @return Returns status, either success or error+reason |
| 575 | */ |
Venkatesh Yadav Abbarapu | e7c4538 | 2022-05-19 14:49:49 +0530 | [diff] [blame] | 576 | static enum pm_ret_status pm_ioctl_read_pggs(uint32_t index, |
| 577 | uint32_t *value) |
Rajan Vaja | 393c0a2 | 2018-01-17 02:39:27 -0800 | [diff] [blame] | 578 | { |
Venkatesh Yadav Abbarapu | 987fad3 | 2022-04-29 13:52:00 +0530 | [diff] [blame] | 579 | if (index >= PGGS_NUM_REGS) { |
Rajan Vaja | 393c0a2 | 2018-01-17 02:39:27 -0800 | [diff] [blame] | 580 | return PM_RET_ERROR_ARGS; |
Venkatesh Yadav Abbarapu | 987fad3 | 2022-04-29 13:52:00 +0530 | [diff] [blame] | 581 | } |
Rajan Vaja | 393c0a2 | 2018-01-17 02:39:27 -0800 | [diff] [blame] | 582 | |
| 583 | return pm_mmio_read(PGGS_BASEADDR + (index << 2), value); |
| 584 | } |
| 585 | |
| 586 | /** |
Siva Durga Prasad Paladugu | ed1d5cb | 2018-09-04 17:03:25 +0530 | [diff] [blame] | 587 | * pm_ioctl_ulpi_reset() - Ioctl function for performing ULPI reset |
| 588 | * |
| 589 | * This function peerforms the ULPI reset sequence for resetting |
| 590 | * the ULPI transceiver. |
| 591 | * |
| 592 | * @return Returns status, either success or error+reason |
| 593 | */ |
| 594 | static enum pm_ret_status pm_ioctl_ulpi_reset(void) |
| 595 | { |
| 596 | enum pm_ret_status ret; |
| 597 | |
| 598 | ret = pm_mmio_write(CRL_APB_BOOT_PIN_CTRL, CRL_APB_BOOT_PIN_MASK, |
| 599 | ZYNQMP_ULPI_RESET_VAL_HIGH); |
Venkatesh Yadav Abbarapu | 987fad3 | 2022-04-29 13:52:00 +0530 | [diff] [blame] | 600 | if (ret != PM_RET_SUCCESS) { |
Siva Durga Prasad Paladugu | ed1d5cb | 2018-09-04 17:03:25 +0530 | [diff] [blame] | 601 | return ret; |
Venkatesh Yadav Abbarapu | 987fad3 | 2022-04-29 13:52:00 +0530 | [diff] [blame] | 602 | } |
Siva Durga Prasad Paladugu | ed1d5cb | 2018-09-04 17:03:25 +0530 | [diff] [blame] | 603 | |
| 604 | /* Drive ULPI assert for atleast 1ms */ |
| 605 | mdelay(1); |
| 606 | |
| 607 | ret = pm_mmio_write(CRL_APB_BOOT_PIN_CTRL, CRL_APB_BOOT_PIN_MASK, |
| 608 | ZYNQMP_ULPI_RESET_VAL_LOW); |
Venkatesh Yadav Abbarapu | 987fad3 | 2022-04-29 13:52:00 +0530 | [diff] [blame] | 609 | if (ret != PM_RET_SUCCESS) { |
Siva Durga Prasad Paladugu | ed1d5cb | 2018-09-04 17:03:25 +0530 | [diff] [blame] | 610 | return ret; |
Venkatesh Yadav Abbarapu | 987fad3 | 2022-04-29 13:52:00 +0530 | [diff] [blame] | 611 | } |
Siva Durga Prasad Paladugu | ed1d5cb | 2018-09-04 17:03:25 +0530 | [diff] [blame] | 612 | |
| 613 | /* Drive ULPI de-assert for atleast 1ms */ |
| 614 | mdelay(1); |
| 615 | |
| 616 | ret = pm_mmio_write(CRL_APB_BOOT_PIN_CTRL, CRL_APB_BOOT_PIN_MASK, |
| 617 | ZYNQMP_ULPI_RESET_VAL_HIGH); |
| 618 | |
| 619 | return ret; |
| 620 | } |
| 621 | |
| 622 | /** |
Siva Durga Prasad Paladugu | ac8526f | 2018-09-04 17:12:51 +0530 | [diff] [blame] | 623 | * pm_ioctl_set_boot_health_status() - Ioctl for setting healthy boot status |
| 624 | * |
| 625 | * This function sets healthy bit value to indicate boot health status |
| 626 | * to firmware. |
| 627 | * |
| 628 | * @return Returns status, either success or error+reason |
| 629 | */ |
Venkatesh Yadav Abbarapu | e7c4538 | 2022-05-19 14:49:49 +0530 | [diff] [blame] | 630 | static enum pm_ret_status pm_ioctl_set_boot_health_status(uint32_t value) |
Siva Durga Prasad Paladugu | ac8526f | 2018-09-04 17:12:51 +0530 | [diff] [blame] | 631 | { |
Tejas Patel | 6552a55 | 2020-11-22 23:37:55 -0800 | [diff] [blame] | 632 | return pm_mmio_write(PMU_GLOBAL_GEN_STORAGE4, |
Siva Durga Prasad Paladugu | ac8526f | 2018-09-04 17:12:51 +0530 | [diff] [blame] | 633 | PM_BOOT_HEALTH_STATUS_MASK, value); |
| 634 | } |
| 635 | |
| 636 | /** |
Rajan Vaja | 5529a01 | 2018-01-17 02:39:23 -0800 | [diff] [blame] | 637 | * pm_api_ioctl() - PM IOCTL API for device control and configs |
| 638 | * @node_id Node ID of the device |
| 639 | * @ioctl_id ID of the requested IOCTL |
| 640 | * @arg1 Argument 1 to requested IOCTL call |
| 641 | * @arg2 Argument 2 to requested IOCTL call |
| 642 | * @value Returned output value |
| 643 | * |
| 644 | * This function calls IOCTL to firmware for device control and configuration. |
| 645 | * |
| 646 | * @return Returns status, either success or error+reason |
| 647 | */ |
| 648 | enum pm_ret_status pm_api_ioctl(enum pm_node_id nid, |
Venkatesh Yadav Abbarapu | e7c4538 | 2022-05-19 14:49:49 +0530 | [diff] [blame] | 649 | uint32_t ioctl_id, |
| 650 | uint32_t arg1, |
| 651 | uint32_t arg2, |
| 652 | uint32_t *value) |
Rajan Vaja | 5529a01 | 2018-01-17 02:39:23 -0800 | [diff] [blame] | 653 | { |
Jolly Shah | 69fb5bf | 2018-02-07 16:25:41 -0800 | [diff] [blame] | 654 | enum pm_ret_status ret; |
Rajan Vaja | 0c0615a | 2021-10-12 03:30:09 -0700 | [diff] [blame] | 655 | uint32_t payload[PAYLOAD_ARG_CNT]; |
Rajan Vaja | 5529a01 | 2018-01-17 02:39:23 -0800 | [diff] [blame] | 656 | |
| 657 | switch (ioctl_id) { |
| 658 | case IOCTL_GET_RPU_OPER_MODE: |
| 659 | ret = pm_ioctl_get_rpu_oper_mode(value); |
| 660 | break; |
| 661 | case IOCTL_SET_RPU_OPER_MODE: |
| 662 | ret = pm_ioctl_set_rpu_oper_mode(arg1); |
| 663 | break; |
| 664 | case IOCTL_RPU_BOOT_ADDR_CONFIG: |
| 665 | ret = pm_ioctl_config_boot_addr(nid, arg1); |
| 666 | break; |
| 667 | case IOCTL_TCM_COMB_CONFIG: |
| 668 | ret = pm_ioctl_config_tcm_comb(arg1); |
| 669 | break; |
Rajan Vaja | aea41bb | 2018-01-17 02:39:24 -0800 | [diff] [blame] | 670 | case IOCTL_SET_TAPDELAY_BYPASS: |
| 671 | ret = pm_ioctl_set_tapdelay_bypass(arg1, arg2); |
| 672 | break; |
| 673 | case IOCTL_SET_SGMII_MODE: |
| 674 | ret = pm_ioctl_set_sgmii_mode(nid, arg1); |
| 675 | break; |
| 676 | case IOCTL_SD_DLL_RESET: |
| 677 | ret = pm_ioctl_sd_dll_reset(nid, arg1); |
| 678 | break; |
| 679 | case IOCTL_SET_SD_TAPDELAY: |
| 680 | ret = pm_ioctl_sd_set_tapdelay(nid, arg1, arg2); |
| 681 | break; |
Rajan Vaja | 3511613 | 2018-01-17 02:39:25 -0800 | [diff] [blame] | 682 | case IOCTL_SET_PLL_FRAC_MODE: |
| 683 | ret = pm_ioctl_set_pll_frac_mode(arg1, arg2); |
| 684 | break; |
| 685 | case IOCTL_GET_PLL_FRAC_MODE: |
| 686 | ret = pm_ioctl_get_pll_frac_mode(arg1, value); |
| 687 | break; |
| 688 | case IOCTL_SET_PLL_FRAC_DATA: |
| 689 | ret = pm_ioctl_set_pll_frac_data(arg1, arg2); |
| 690 | break; |
| 691 | case IOCTL_GET_PLL_FRAC_DATA: |
| 692 | ret = pm_ioctl_get_pll_frac_data(arg1, value); |
| 693 | break; |
Rajan Vaja | 393c0a2 | 2018-01-17 02:39:27 -0800 | [diff] [blame] | 694 | case IOCTL_WRITE_GGS: |
| 695 | ret = pm_ioctl_write_ggs(arg1, arg2); |
| 696 | break; |
| 697 | case IOCTL_READ_GGS: |
| 698 | ret = pm_ioctl_read_ggs(arg1, value); |
| 699 | break; |
| 700 | case IOCTL_WRITE_PGGS: |
| 701 | ret = pm_ioctl_write_pggs(arg1, arg2); |
| 702 | break; |
| 703 | case IOCTL_READ_PGGS: |
| 704 | ret = pm_ioctl_read_pggs(arg1, value); |
| 705 | break; |
Siva Durga Prasad Paladugu | ed1d5cb | 2018-09-04 17:03:25 +0530 | [diff] [blame] | 706 | case IOCTL_ULPI_RESET: |
| 707 | ret = pm_ioctl_ulpi_reset(); |
| 708 | break; |
Siva Durga Prasad Paladugu | ac8526f | 2018-09-04 17:12:51 +0530 | [diff] [blame] | 709 | case IOCTL_SET_BOOT_HEALTH_STATUS: |
| 710 | ret = pm_ioctl_set_boot_health_status(arg1); |
| 711 | break; |
Siva Durga Prasad Paladugu | a22b885 | 2018-09-04 17:27:12 +0530 | [diff] [blame] | 712 | case IOCTL_AFI: |
| 713 | ret = pm_ioctl_afi(arg1, arg2); |
| 714 | break; |
Rajan Vaja | 5529a01 | 2018-01-17 02:39:23 -0800 | [diff] [blame] | 715 | default: |
Rajan Vaja | 0c0615a | 2021-10-12 03:30:09 -0700 | [diff] [blame] | 716 | /* Send request to the PMU */ |
| 717 | PM_PACK_PAYLOAD5(payload, PM_IOCTL, nid, ioctl_id, arg1, arg2); |
| 718 | |
| 719 | ret = pm_ipi_send_sync(primary_proc, payload, value, 1); |
Jolly Shah | 69fb5bf | 2018-02-07 16:25:41 -0800 | [diff] [blame] | 720 | break; |
Rajan Vaja | 5529a01 | 2018-01-17 02:39:23 -0800 | [diff] [blame] | 721 | } |
| 722 | |
| 723 | return ret; |
| 724 | } |
Ronak Jain | 325bad1 | 2021-12-21 01:39:59 -0800 | [diff] [blame] | 725 | |
| 726 | /** |
| 727 | * pm_update_ioctl_bitmask() - API to get supported IOCTL ID mask |
| 728 | * @bit_mask Returned bit mask of supported IOCTL IDs |
| 729 | */ |
Prasad Kummari | e078311 | 2023-04-26 11:02:07 +0530 | [diff] [blame^] | 730 | enum pm_ret_status tfa_ioctl_bitmask(uint32_t *bit_mask) |
Ronak Jain | 325bad1 | 2021-12-21 01:39:59 -0800 | [diff] [blame] | 731 | { |
| 732 | uint8_t supported_ids[] = { |
| 733 | IOCTL_GET_RPU_OPER_MODE, |
| 734 | IOCTL_SET_RPU_OPER_MODE, |
| 735 | IOCTL_RPU_BOOT_ADDR_CONFIG, |
| 736 | IOCTL_TCM_COMB_CONFIG, |
| 737 | IOCTL_SET_TAPDELAY_BYPASS, |
| 738 | IOCTL_SET_SGMII_MODE, |
| 739 | IOCTL_SD_DLL_RESET, |
| 740 | IOCTL_SET_SD_TAPDELAY, |
| 741 | IOCTL_SET_PLL_FRAC_MODE, |
| 742 | IOCTL_GET_PLL_FRAC_MODE, |
| 743 | IOCTL_SET_PLL_FRAC_DATA, |
| 744 | IOCTL_GET_PLL_FRAC_DATA, |
| 745 | IOCTL_WRITE_GGS, |
| 746 | IOCTL_READ_GGS, |
| 747 | IOCTL_WRITE_PGGS, |
| 748 | IOCTL_READ_PGGS, |
| 749 | IOCTL_ULPI_RESET, |
| 750 | IOCTL_SET_BOOT_HEALTH_STATUS, |
| 751 | IOCTL_AFI, |
| 752 | }; |
| 753 | uint8_t i, ioctl_id; |
Venkatesh Yadav Abbarapu | e7c4538 | 2022-05-19 14:49:49 +0530 | [diff] [blame] | 754 | int32_t ret; |
Ronak Jain | 325bad1 | 2021-12-21 01:39:59 -0800 | [diff] [blame] | 755 | |
| 756 | for (i = 0U; i < ARRAY_SIZE(supported_ids); i++) { |
| 757 | ioctl_id = supported_ids[i]; |
| 758 | if (ioctl_id >= 64U) { |
| 759 | return PM_RET_ERROR_NOTSUPPORTED; |
| 760 | } |
| 761 | ret = check_api_dependency(ioctl_id); |
| 762 | if (ret == PM_RET_SUCCESS) { |
HariBabu Gattem | b0c70f5 | 2022-09-29 23:59:11 -0700 | [diff] [blame] | 763 | bit_mask[ioctl_id / 32U] |= BIT(ioctl_id % 32U); |
Ronak Jain | 325bad1 | 2021-12-21 01:39:59 -0800 | [diff] [blame] | 764 | } |
| 765 | } |
| 766 | |
| 767 | return PM_RET_SUCCESS; |
| 768 | } |