Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: BSD-3-Clause |
Mateusz Kulikowski | 73bec9c | 2016-03-31 23:12:29 +0200 | [diff] [blame] | 2 | /* |
| 3 | * Qualcomm SPMI bus driver |
| 4 | * |
| 5 | * (C) Copyright 2015 Mateusz Kulikowski <mateusz.kulikowski@gmail.com> |
| 6 | * |
| 7 | * Loosely based on Little Kernel driver |
Mateusz Kulikowski | 73bec9c | 2016-03-31 23:12:29 +0200 | [diff] [blame] | 8 | */ |
| 9 | |
Mateusz Kulikowski | 73bec9c | 2016-03-31 23:12:29 +0200 | [diff] [blame] | 10 | #include <dm.h> |
| 11 | #include <errno.h> |
| 12 | #include <fdtdec.h> |
Simon Glass | 3ba929a | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 13 | #include <asm/global_data.h> |
Mateusz Kulikowski | 73bec9c | 2016-03-31 23:12:29 +0200 | [diff] [blame] | 14 | #include <asm/io.h> |
Simon Glass | 9bc1564 | 2020-02-03 07:36:16 -0700 | [diff] [blame] | 15 | #include <dm/device_compat.h> |
Mateusz Kulikowski | 73bec9c | 2016-03-31 23:12:29 +0200 | [diff] [blame] | 16 | #include <spmi/spmi.h> |
| 17 | |
| 18 | DECLARE_GLOBAL_DATA_PTR; |
| 19 | |
Jorge Ramirez-Ortiz | 4bcef68 | 2018-01-10 11:33:28 +0100 | [diff] [blame] | 20 | /* PMIC Arbiter configuration registers */ |
Dzmitry Sankouski | 682351a | 2021-10-17 13:44:28 +0300 | [diff] [blame] | 21 | #define PMIC_ARB_VERSION 0x0000 |
| 22 | #define PMIC_ARB_VERSION_V2_MIN 0x20010000 |
| 23 | #define PMIC_ARB_VERSION_V3_MIN 0x30000000 |
| 24 | #define PMIC_ARB_VERSION_V5_MIN 0x50000000 |
Neil Armstrong | a243fb2 | 2024-04-05 10:21:56 +0200 | [diff] [blame] | 25 | #define PMIC_ARB_VERSION_V7_MIN 0x70000000 |
Jorge Ramirez-Ortiz | 4bcef68 | 2018-01-10 11:33:28 +0100 | [diff] [blame] | 26 | |
Dzmitry Sankouski | 682351a | 2021-10-17 13:44:28 +0300 | [diff] [blame] | 27 | #define APID_MAP_OFFSET_V1_V2_V3 (0x800) |
| 28 | #define APID_MAP_OFFSET_V5 (0x900) |
Neil Armstrong | a243fb2 | 2024-04-05 10:21:56 +0200 | [diff] [blame] | 29 | #define APID_MAP_OFFSET_V7 (0x2000) |
Dzmitry Sankouski | 682351a | 2021-10-17 13:44:28 +0300 | [diff] [blame] | 30 | #define ARB_CHANNEL_OFFSET(n) (0x4 * (n)) |
| 31 | #define SPMI_CH_OFFSET(chnl) ((chnl) * 0x8000) |
| 32 | #define SPMI_V5_OBS_CH_OFFSET(chnl) ((chnl) * 0x80) |
Neil Armstrong | a243fb2 | 2024-04-05 10:21:56 +0200 | [diff] [blame] | 33 | #define SPMI_V7_OBS_CH_OFFSET(chnl) ((chnl) * 0x20) |
Dzmitry Sankouski | 682351a | 2021-10-17 13:44:28 +0300 | [diff] [blame] | 34 | #define SPMI_V5_RW_CH_OFFSET(chnl) ((chnl) * 0x10000) |
Neil Armstrong | a243fb2 | 2024-04-05 10:21:56 +0200 | [diff] [blame] | 35 | #define SPMI_V7_RW_CH_OFFSET(chnl) ((chnl) * 0x1000) |
Mateusz Kulikowski | 73bec9c | 2016-03-31 23:12:29 +0200 | [diff] [blame] | 36 | |
Neil Armstrong | 3fe8367 | 2024-04-05 10:21:55 +0200 | [diff] [blame] | 37 | #define SPMI_OWNERSHIP_PERIPH2OWNER(x) ((x) & 0x7) |
| 38 | |
Dzmitry Sankouski | 682351a | 2021-10-17 13:44:28 +0300 | [diff] [blame] | 39 | #define SPMI_REG_CMD0 0x0 |
| 40 | #define SPMI_REG_CONFIG 0x4 |
| 41 | #define SPMI_REG_STATUS 0x8 |
| 42 | #define SPMI_REG_WDATA 0x10 |
| 43 | #define SPMI_REG_RDATA 0x18 |
Mateusz Kulikowski | 73bec9c | 2016-03-31 23:12:29 +0200 | [diff] [blame] | 44 | |
Dzmitry Sankouski | 682351a | 2021-10-17 13:44:28 +0300 | [diff] [blame] | 45 | #define SPMI_CMD_OPCODE_SHIFT 27 |
| 46 | #define SPMI_CMD_SLAVE_ID_SHIFT 20 |
| 47 | #define SPMI_CMD_ADDR_SHIFT 12 |
| 48 | #define SPMI_CMD_ADDR_OFFSET_SHIFT 4 |
| 49 | #define SPMI_CMD_BYTE_CNT_SHIFT 0 |
Mateusz Kulikowski | 73bec9c | 2016-03-31 23:12:29 +0200 | [diff] [blame] | 50 | |
Dzmitry Sankouski | 682351a | 2021-10-17 13:44:28 +0300 | [diff] [blame] | 51 | #define SPMI_CMD_EXT_REG_WRITE_LONG 0x00 |
| 52 | #define SPMI_CMD_EXT_REG_READ_LONG 0x01 |
Mateusz Kulikowski | 73bec9c | 2016-03-31 23:12:29 +0200 | [diff] [blame] | 53 | |
Dzmitry Sankouski | 682351a | 2021-10-17 13:44:28 +0300 | [diff] [blame] | 54 | #define SPMI_STATUS_DONE 0x1 |
Mateusz Kulikowski | 73bec9c | 2016-03-31 23:12:29 +0200 | [diff] [blame] | 55 | |
Dzmitry Sankouski | 682351a | 2021-10-17 13:44:28 +0300 | [diff] [blame] | 56 | #define SPMI_MAX_CHANNELS 128 |
Neil Armstrong | 3fe8367 | 2024-04-05 10:21:55 +0200 | [diff] [blame] | 57 | #define SPMI_MAX_CHANNELS_V5 512 |
Neil Armstrong | a243fb2 | 2024-04-05 10:21:56 +0200 | [diff] [blame] | 58 | #define SPMI_MAX_CHANNELS_V7 1024 |
Dzmitry Sankouski | 682351a | 2021-10-17 13:44:28 +0300 | [diff] [blame] | 59 | #define SPMI_MAX_SLAVES 16 |
| 60 | #define SPMI_MAX_PERIPH 256 |
| 61 | |
Neil Armstrong | 3fe8367 | 2024-04-05 10:21:55 +0200 | [diff] [blame] | 62 | #define SPMI_CHANNEL_READ_ONLY BIT(31) |
| 63 | #define SPMI_CHANNEL_MASK 0xffff |
| 64 | |
Dzmitry Sankouski | 682351a | 2021-10-17 13:44:28 +0300 | [diff] [blame] | 65 | enum arb_ver { |
| 66 | V1 = 1, |
| 67 | V2, |
| 68 | V3, |
Neil Armstrong | a243fb2 | 2024-04-05 10:21:56 +0200 | [diff] [blame] | 69 | V5 = 5, |
| 70 | V7 = 7 |
Dzmitry Sankouski | 682351a | 2021-10-17 13:44:28 +0300 | [diff] [blame] | 71 | }; |
| 72 | |
| 73 | /* |
| 74 | * PMIC arbiter version 5 uses different register offsets for read/write vs |
| 75 | * observer channels. |
| 76 | */ |
| 77 | enum pmic_arb_channel { |
| 78 | PMIC_ARB_CHANNEL_RW, |
| 79 | PMIC_ARB_CHANNEL_OBS, |
| 80 | }; |
Mateusz Kulikowski | 73bec9c | 2016-03-31 23:12:29 +0200 | [diff] [blame] | 81 | |
| 82 | struct msm_spmi_priv { |
Dzmitry Sankouski | 682351a | 2021-10-17 13:44:28 +0300 | [diff] [blame] | 83 | phys_addr_t arb_chnl; /* ARB channel mapping base */ |
Caleb Connolly | 99f591c | 2023-12-05 13:46:53 +0000 | [diff] [blame] | 84 | phys_addr_t spmi_chnls; /* SPMI channels */ |
Dzmitry Sankouski | 682351a | 2021-10-17 13:44:28 +0300 | [diff] [blame] | 85 | phys_addr_t spmi_obs; /* SPMI observer */ |
Neil Armstrong | 3fe8367 | 2024-04-05 10:21:55 +0200 | [diff] [blame] | 86 | phys_addr_t spmi_cnfg; /* SPMI config */ |
| 87 | u32 owner; /* Current owner */ |
| 88 | unsigned int max_channels; /* Max channels */ |
Mateusz Kulikowski | 73bec9c | 2016-03-31 23:12:29 +0200 | [diff] [blame] | 89 | /* SPMI channel map */ |
Neil Armstrong | 3fe8367 | 2024-04-05 10:21:55 +0200 | [diff] [blame] | 90 | uint32_t channel_map[SPMI_MAX_SLAVES][SPMI_MAX_PERIPH]; |
Dzmitry Sankouski | 682351a | 2021-10-17 13:44:28 +0300 | [diff] [blame] | 91 | /* SPMI bus arbiter version */ |
| 92 | u32 arb_ver; |
Mateusz Kulikowski | 73bec9c | 2016-03-31 23:12:29 +0200 | [diff] [blame] | 93 | }; |
| 94 | |
Neil Armstrong | dde6d55 | 2024-04-05 10:21:54 +0200 | [diff] [blame] | 95 | static u32 pmic_arb_fmt_cmd_v1(u8 opc, u8 sid, u8 pid, u8 off) |
| 96 | { |
| 97 | return (opc << 27) | (sid << 20) | (pid << 12) | (off << 4) | 1; |
| 98 | } |
| 99 | |
| 100 | static u32 pmic_arb_fmt_cmd_v2(u8 opc, u8 off) |
| 101 | { |
| 102 | return (opc << 27) | (off << 4) | 1; |
| 103 | } |
| 104 | |
Mateusz Kulikowski | 73bec9c | 2016-03-31 23:12:29 +0200 | [diff] [blame] | 105 | static int msm_spmi_write(struct udevice *dev, int usid, int pid, int off, |
| 106 | uint8_t val) |
| 107 | { |
| 108 | struct msm_spmi_priv *priv = dev_get_priv(dev); |
| 109 | unsigned channel; |
Dzmitry Sankouski | 682351a | 2021-10-17 13:44:28 +0300 | [diff] [blame] | 110 | unsigned int ch_offset; |
Mateusz Kulikowski | 73bec9c | 2016-03-31 23:12:29 +0200 | [diff] [blame] | 111 | uint32_t reg = 0; |
| 112 | |
| 113 | if (usid >= SPMI_MAX_SLAVES) |
| 114 | return -EIO; |
| 115 | if (pid >= SPMI_MAX_PERIPH) |
| 116 | return -EIO; |
Neil Armstrong | 3fe8367 | 2024-04-05 10:21:55 +0200 | [diff] [blame] | 117 | if (priv->channel_map[usid][pid] & SPMI_CHANNEL_READ_ONLY) |
| 118 | return -EPERM; |
Mateusz Kulikowski | 73bec9c | 2016-03-31 23:12:29 +0200 | [diff] [blame] | 119 | |
Neil Armstrong | 3fe8367 | 2024-04-05 10:21:55 +0200 | [diff] [blame] | 120 | channel = priv->channel_map[usid][pid] & SPMI_CHANNEL_MASK; |
Mateusz Kulikowski | 73bec9c | 2016-03-31 23:12:29 +0200 | [diff] [blame] | 121 | |
Caleb Connolly | 2b7001d | 2024-06-24 14:46:27 +0200 | [diff] [blame] | 122 | debug("%s: [%d:%d] %s: channel %d\n", dev->name, usid, pid, __func__, channel); |
Neil Armstrong | dde6d55 | 2024-04-05 10:21:54 +0200 | [diff] [blame] | 123 | |
| 124 | switch (priv->arb_ver) { |
| 125 | case V1: |
| 126 | ch_offset = SPMI_CH_OFFSET(channel); |
| 127 | |
| 128 | reg = pmic_arb_fmt_cmd_v1(SPMI_CMD_EXT_REG_WRITE_LONG, |
| 129 | usid, pid, off); |
| 130 | break; |
| 131 | |
| 132 | case V2: |
Neil Armstrong | 62f3439 | 2024-04-05 10:21:53 +0200 | [diff] [blame] | 133 | ch_offset = SPMI_CH_OFFSET(channel); |
| 134 | |
Neil Armstrong | dde6d55 | 2024-04-05 10:21:54 +0200 | [diff] [blame] | 135 | reg = pmic_arb_fmt_cmd_v2(SPMI_CMD_EXT_REG_WRITE_LONG, off); |
| 136 | break; |
| 137 | |
| 138 | case V5: |
| 139 | ch_offset = SPMI_V5_RW_CH_OFFSET(channel); |
| 140 | |
| 141 | reg = pmic_arb_fmt_cmd_v2(SPMI_CMD_EXT_REG_WRITE_LONG, off); |
| 142 | break; |
Neil Armstrong | a243fb2 | 2024-04-05 10:21:56 +0200 | [diff] [blame] | 143 | |
| 144 | case V7: |
| 145 | ch_offset = SPMI_V7_RW_CH_OFFSET(channel); |
| 146 | |
| 147 | reg = pmic_arb_fmt_cmd_v2(SPMI_CMD_EXT_REG_WRITE_LONG, off); |
| 148 | break; |
Neil Armstrong | dde6d55 | 2024-04-05 10:21:54 +0200 | [diff] [blame] | 149 | } |
| 150 | |
Mateusz Kulikowski | 73bec9c | 2016-03-31 23:12:29 +0200 | [diff] [blame] | 151 | /* Disable IRQ mode for the current channel*/ |
Neil Armstrong | 62f3439 | 2024-04-05 10:21:53 +0200 | [diff] [blame] | 152 | writel(0x0, priv->spmi_chnls + ch_offset + SPMI_REG_CONFIG); |
Mateusz Kulikowski | 73bec9c | 2016-03-31 23:12:29 +0200 | [diff] [blame] | 153 | |
| 154 | /* Write single byte */ |
Neil Armstrong | 62f3439 | 2024-04-05 10:21:53 +0200 | [diff] [blame] | 155 | writel(val, priv->spmi_chnls + ch_offset + SPMI_REG_WDATA); |
Mateusz Kulikowski | 73bec9c | 2016-03-31 23:12:29 +0200 | [diff] [blame] | 156 | |
Mateusz Kulikowski | 73bec9c | 2016-03-31 23:12:29 +0200 | [diff] [blame] | 157 | /* Send write command */ |
Neil Armstrong | 62f3439 | 2024-04-05 10:21:53 +0200 | [diff] [blame] | 158 | writel(reg, priv->spmi_chnls + ch_offset + SPMI_REG_CMD0); |
Mateusz Kulikowski | 73bec9c | 2016-03-31 23:12:29 +0200 | [diff] [blame] | 159 | |
| 160 | /* Wait till CMD DONE status */ |
| 161 | reg = 0; |
| 162 | while (!reg) { |
Neil Armstrong | 62f3439 | 2024-04-05 10:21:53 +0200 | [diff] [blame] | 163 | reg = readl(priv->spmi_chnls + ch_offset + |
Mateusz Kulikowski | 73bec9c | 2016-03-31 23:12:29 +0200 | [diff] [blame] | 164 | SPMI_REG_STATUS); |
| 165 | } |
| 166 | |
| 167 | if (reg ^ SPMI_STATUS_DONE) { |
| 168 | printf("SPMI write failure.\n"); |
| 169 | return -EIO; |
| 170 | } |
| 171 | |
| 172 | return 0; |
| 173 | } |
| 174 | |
| 175 | static int msm_spmi_read(struct udevice *dev, int usid, int pid, int off) |
| 176 | { |
| 177 | struct msm_spmi_priv *priv = dev_get_priv(dev); |
| 178 | unsigned channel; |
Dzmitry Sankouski | 682351a | 2021-10-17 13:44:28 +0300 | [diff] [blame] | 179 | unsigned int ch_offset; |
Mateusz Kulikowski | 73bec9c | 2016-03-31 23:12:29 +0200 | [diff] [blame] | 180 | uint32_t reg = 0; |
| 181 | |
| 182 | if (usid >= SPMI_MAX_SLAVES) |
| 183 | return -EIO; |
| 184 | if (pid >= SPMI_MAX_PERIPH) |
| 185 | return -EIO; |
| 186 | |
Neil Armstrong | 3fe8367 | 2024-04-05 10:21:55 +0200 | [diff] [blame] | 187 | channel = priv->channel_map[usid][pid] & SPMI_CHANNEL_MASK; |
Mateusz Kulikowski | 73bec9c | 2016-03-31 23:12:29 +0200 | [diff] [blame] | 188 | |
Caleb Connolly | 2b7001d | 2024-06-24 14:46:27 +0200 | [diff] [blame] | 189 | debug("%s: [%d:%d] %s: channel %d\n", dev->name, usid, pid, __func__, channel); |
Neil Armstrong | dde6d55 | 2024-04-05 10:21:54 +0200 | [diff] [blame] | 190 | |
| 191 | switch (priv->arb_ver) { |
| 192 | case V1: |
| 193 | ch_offset = SPMI_CH_OFFSET(channel); |
| 194 | |
| 195 | /* Prepare read command */ |
| 196 | reg = pmic_arb_fmt_cmd_v1(SPMI_CMD_EXT_REG_READ_LONG, |
| 197 | usid, pid, off); |
| 198 | break; |
| 199 | |
| 200 | case V2: |
Dzmitry Sankouski | 682351a | 2021-10-17 13:44:28 +0300 | [diff] [blame] | 201 | ch_offset = SPMI_CH_OFFSET(channel); |
| 202 | |
Neil Armstrong | dde6d55 | 2024-04-05 10:21:54 +0200 | [diff] [blame] | 203 | /* Prepare read command */ |
| 204 | reg = pmic_arb_fmt_cmd_v2(SPMI_CMD_EXT_REG_READ_LONG, off); |
| 205 | break; |
| 206 | |
| 207 | case V5: |
| 208 | ch_offset = SPMI_V5_OBS_CH_OFFSET(channel); |
| 209 | |
| 210 | /* Prepare read command */ |
| 211 | reg = pmic_arb_fmt_cmd_v2(SPMI_CMD_EXT_REG_READ_LONG, off); |
| 212 | break; |
Neil Armstrong | a243fb2 | 2024-04-05 10:21:56 +0200 | [diff] [blame] | 213 | |
| 214 | case V7: |
| 215 | ch_offset = SPMI_V7_OBS_CH_OFFSET(channel); |
| 216 | |
| 217 | /* Prepare read command */ |
| 218 | reg = pmic_arb_fmt_cmd_v2(SPMI_CMD_EXT_REG_READ_LONG, off); |
| 219 | break; |
Neil Armstrong | dde6d55 | 2024-04-05 10:21:54 +0200 | [diff] [blame] | 220 | } |
| 221 | |
Mateusz Kulikowski | 73bec9c | 2016-03-31 23:12:29 +0200 | [diff] [blame] | 222 | /* Disable IRQ mode for the current channel*/ |
Dzmitry Sankouski | 682351a | 2021-10-17 13:44:28 +0300 | [diff] [blame] | 223 | writel(0x0, priv->spmi_obs + ch_offset + SPMI_REG_CONFIG); |
Mateusz Kulikowski | 73bec9c | 2016-03-31 23:12:29 +0200 | [diff] [blame] | 224 | |
Mateusz Kulikowski | 73bec9c | 2016-03-31 23:12:29 +0200 | [diff] [blame] | 225 | /* Request read */ |
Dzmitry Sankouski | 682351a | 2021-10-17 13:44:28 +0300 | [diff] [blame] | 226 | writel(reg, priv->spmi_obs + ch_offset + SPMI_REG_CMD0); |
Mateusz Kulikowski | 73bec9c | 2016-03-31 23:12:29 +0200 | [diff] [blame] | 227 | |
| 228 | /* Wait till CMD DONE status */ |
| 229 | reg = 0; |
| 230 | while (!reg) { |
Dzmitry Sankouski | 682351a | 2021-10-17 13:44:28 +0300 | [diff] [blame] | 231 | reg = readl(priv->spmi_obs + ch_offset + SPMI_REG_STATUS); |
Mateusz Kulikowski | 73bec9c | 2016-03-31 23:12:29 +0200 | [diff] [blame] | 232 | } |
| 233 | |
| 234 | if (reg ^ SPMI_STATUS_DONE) { |
| 235 | printf("SPMI read failure.\n"); |
| 236 | return -EIO; |
| 237 | } |
| 238 | |
| 239 | /* Read the data */ |
Dzmitry Sankouski | 682351a | 2021-10-17 13:44:28 +0300 | [diff] [blame] | 240 | return readl(priv->spmi_obs + ch_offset + |
| 241 | SPMI_REG_RDATA) & 0xFF; |
Mateusz Kulikowski | 73bec9c | 2016-03-31 23:12:29 +0200 | [diff] [blame] | 242 | } |
| 243 | |
| 244 | static struct dm_spmi_ops msm_spmi_ops = { |
| 245 | .read = msm_spmi_read, |
| 246 | .write = msm_spmi_write, |
| 247 | }; |
| 248 | |
| 249 | static int msm_spmi_probe(struct udevice *dev) |
| 250 | { |
Mateusz Kulikowski | 73bec9c | 2016-03-31 23:12:29 +0200 | [diff] [blame] | 251 | struct msm_spmi_priv *priv = dev_get_priv(dev); |
Caleb Connolly | 99f591c | 2023-12-05 13:46:53 +0000 | [diff] [blame] | 252 | phys_addr_t core_addr; |
Jorge Ramirez-Ortiz | 4bcef68 | 2018-01-10 11:33:28 +0100 | [diff] [blame] | 253 | u32 hw_ver; |
Mateusz Kulikowski | 73bec9c | 2016-03-31 23:12:29 +0200 | [diff] [blame] | 254 | int i; |
| 255 | |
Caleb Connolly | 99f591c | 2023-12-05 13:46:53 +0000 | [diff] [blame] | 256 | core_addr = dev_read_addr_name(dev, "core"); |
| 257 | priv->spmi_chnls = dev_read_addr_name(dev, "chnls"); |
| 258 | priv->spmi_obs = dev_read_addr_name(dev, "obsrvr"); |
Neil Armstrong | 3fe8367 | 2024-04-05 10:21:55 +0200 | [diff] [blame] | 259 | dev_read_u32(dev, "qcom,ee", &priv->owner); |
Jorge Ramirez-Ortiz | 4bcef68 | 2018-01-10 11:33:28 +0100 | [diff] [blame] | 260 | |
Caleb Connolly | 99f591c | 2023-12-05 13:46:53 +0000 | [diff] [blame] | 261 | hw_ver = readl(core_addr + PMIC_ARB_VERSION); |
Dzmitry Sankouski | 682351a | 2021-10-17 13:44:28 +0300 | [diff] [blame] | 262 | |
| 263 | if (hw_ver < PMIC_ARB_VERSION_V3_MIN) { |
| 264 | priv->arb_ver = V2; |
Caleb Connolly | 99f591c | 2023-12-05 13:46:53 +0000 | [diff] [blame] | 265 | priv->arb_chnl = core_addr + APID_MAP_OFFSET_V1_V2_V3; |
Neil Armstrong | 3fe8367 | 2024-04-05 10:21:55 +0200 | [diff] [blame] | 266 | priv->max_channels = SPMI_MAX_CHANNELS; |
Dzmitry Sankouski | 682351a | 2021-10-17 13:44:28 +0300 | [diff] [blame] | 267 | } else if (hw_ver < PMIC_ARB_VERSION_V5_MIN) { |
| 268 | priv->arb_ver = V3; |
Caleb Connolly | 99f591c | 2023-12-05 13:46:53 +0000 | [diff] [blame] | 269 | priv->arb_chnl = core_addr + APID_MAP_OFFSET_V1_V2_V3; |
Neil Armstrong | 3fe8367 | 2024-04-05 10:21:55 +0200 | [diff] [blame] | 270 | priv->max_channels = SPMI_MAX_CHANNELS; |
Neil Armstrong | a243fb2 | 2024-04-05 10:21:56 +0200 | [diff] [blame] | 271 | } else if (hw_ver < PMIC_ARB_VERSION_V7_MIN) { |
Dzmitry Sankouski | 682351a | 2021-10-17 13:44:28 +0300 | [diff] [blame] | 272 | priv->arb_ver = V5; |
Caleb Connolly | 99f591c | 2023-12-05 13:46:53 +0000 | [diff] [blame] | 273 | priv->arb_chnl = core_addr + APID_MAP_OFFSET_V5; |
Caleb Connolly | be3832c | 2024-06-24 04:23:29 +0200 | [diff] [blame^] | 274 | priv->max_channels = SPMI_MAX_CHANNELS_V5; |
Neil Armstrong | a243fb2 | 2024-04-05 10:21:56 +0200 | [diff] [blame] | 275 | priv->spmi_cnfg = dev_read_addr_name(dev, "cnfg"); |
| 276 | } else { |
| 277 | /* TOFIX: handle second bus */ |
| 278 | priv->arb_ver = V7; |
| 279 | priv->arb_chnl = core_addr + APID_MAP_OFFSET_V7; |
| 280 | priv->max_channels = SPMI_MAX_CHANNELS_V7; |
Neil Armstrong | 3fe8367 | 2024-04-05 10:21:55 +0200 | [diff] [blame] | 281 | priv->spmi_cnfg = dev_read_addr_name(dev, "cnfg"); |
Dzmitry Sankouski | 682351a | 2021-10-17 13:44:28 +0300 | [diff] [blame] | 282 | } |
| 283 | |
Caleb Connolly | 99f591c | 2023-12-05 13:46:53 +0000 | [diff] [blame] | 284 | dev_dbg(dev, "PMIC Arb Version-%d (%#x)\n", hw_ver >> 28, hw_ver); |
Jorge Ramirez-Ortiz | 4bcef68 | 2018-01-10 11:33:28 +0100 | [diff] [blame] | 285 | |
Mateusz Kulikowski | 73bec9c | 2016-03-31 23:12:29 +0200 | [diff] [blame] | 286 | if (priv->arb_chnl == FDT_ADDR_T_NONE || |
Caleb Connolly | 99f591c | 2023-12-05 13:46:53 +0000 | [diff] [blame] | 287 | priv->spmi_chnls == FDT_ADDR_T_NONE || |
Mateusz Kulikowski | 73bec9c | 2016-03-31 23:12:29 +0200 | [diff] [blame] | 288 | priv->spmi_obs == FDT_ADDR_T_NONE) |
| 289 | return -EINVAL; |
| 290 | |
Caleb Connolly | 99f591c | 2023-12-05 13:46:53 +0000 | [diff] [blame] | 291 | dev_dbg(dev, "priv->arb_chnl address (%#08llx)\n", priv->arb_chnl); |
| 292 | dev_dbg(dev, "priv->spmi_chnls address (%#08llx)\n", priv->spmi_chnls); |
| 293 | dev_dbg(dev, "priv->spmi_obs address (%#08llx)\n", priv->spmi_obs); |
Mateusz Kulikowski | 73bec9c | 2016-03-31 23:12:29 +0200 | [diff] [blame] | 294 | /* Scan peripherals connected to each SPMI channel */ |
Neil Armstrong | 3fe8367 | 2024-04-05 10:21:55 +0200 | [diff] [blame] | 295 | for (i = 0; i < priv->max_channels; i++) { |
Mateusz Kulikowski | 73bec9c | 2016-03-31 23:12:29 +0200 | [diff] [blame] | 296 | uint32_t periph = readl(priv->arb_chnl + ARB_CHANNEL_OFFSET(i)); |
| 297 | uint8_t slave_id = (periph & 0xf0000) >> 16; |
| 298 | uint8_t pid = (periph & 0xff00) >> 8; |
| 299 | |
| 300 | priv->channel_map[slave_id][pid] = i; |
Neil Armstrong | 3fe8367 | 2024-04-05 10:21:55 +0200 | [diff] [blame] | 301 | |
| 302 | /* Mark channels read-only when from different owner */ |
Neil Armstrong | a243fb2 | 2024-04-05 10:21:56 +0200 | [diff] [blame] | 303 | if (priv->arb_ver == V5 || priv->arb_ver == V7) { |
Neil Armstrong | 3fe8367 | 2024-04-05 10:21:55 +0200 | [diff] [blame] | 304 | uint32_t cnfg = readl(priv->spmi_cnfg + ARB_CHANNEL_OFFSET(i)); |
| 305 | uint8_t owner = SPMI_OWNERSHIP_PERIPH2OWNER(cnfg); |
| 306 | |
| 307 | if (owner != priv->owner) |
| 308 | priv->channel_map[slave_id][pid] |= SPMI_CHANNEL_READ_ONLY; |
| 309 | } |
Mateusz Kulikowski | 73bec9c | 2016-03-31 23:12:29 +0200 | [diff] [blame] | 310 | } |
| 311 | return 0; |
| 312 | } |
| 313 | |
| 314 | static const struct udevice_id msm_spmi_ids[] = { |
| 315 | { .compatible = "qcom,spmi-pmic-arb" }, |
| 316 | { } |
| 317 | }; |
| 318 | |
| 319 | U_BOOT_DRIVER(msm_spmi) = { |
| 320 | .name = "msm_spmi", |
| 321 | .id = UCLASS_SPMI, |
| 322 | .of_match = msm_spmi_ids, |
| 323 | .ops = &msm_spmi_ops, |
| 324 | .probe = msm_spmi_probe, |
Dzmitry Sankouski | 682351a | 2021-10-17 13:44:28 +0300 | [diff] [blame] | 325 | .priv_auto = sizeof(struct msm_spmi_priv), |
Mateusz Kulikowski | 73bec9c | 2016-03-31 23:12:29 +0200 | [diff] [blame] | 326 | }; |