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