Simon Glass | 837a66a | 2019-12-06 21:42:53 -0700 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
| 2 | /* |
| 3 | * Copyright (C) 2017 Intel Corp. |
| 4 | * Copyright 2019 Google LLC |
| 5 | * |
| 6 | * Taken partly from coreboot gpio.c |
| 7 | * |
| 8 | * Pinctrl is modelled as a separate device-tree node and device for each |
| 9 | * 'community' (basically a set of GPIOs). The separate devices work together |
| 10 | * and many functions permit any PINCTRL device to be provided as a parameter, |
| 11 | * since the pad numbering is unique across all devices. |
| 12 | * |
| 13 | * Each pinctrl has a single child GPIO device to handle GPIO access and |
| 14 | * therefore there is a simple GPIO driver included in this file. |
| 15 | */ |
| 16 | |
| 17 | #define LOG_CATEGORY UCLASS_GPIO |
| 18 | |
| 19 | #include <common.h> |
| 20 | #include <dm.h> |
| 21 | #include <irq.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 22 | #include <log.h> |
Simon Glass | 9bc1564 | 2020-02-03 07:36:16 -0700 | [diff] [blame] | 23 | #include <malloc.h> |
Simon Glass | 837a66a | 2019-12-06 21:42:53 -0700 | [diff] [blame] | 24 | #include <p2sb.h> |
| 25 | #include <spl.h> |
| 26 | #include <asm-generic/gpio.h> |
| 27 | #include <asm/intel_pinctrl.h> |
| 28 | #include <asm/intel_pinctrl_defs.h> |
| 29 | #include <asm/arch/gpio.h> |
Wolfgang Wallner | 9713216 | 2020-01-22 16:01:45 +0100 | [diff] [blame] | 30 | #include <asm/itss.h> |
Simon Glass | 837a66a | 2019-12-06 21:42:53 -0700 | [diff] [blame] | 31 | #include <dm/device-internal.h> |
| 32 | #include <dt-bindings/gpio/gpio.h> |
Simon Glass | d66c5f7 | 2020-02-03 07:36:15 -0700 | [diff] [blame] | 33 | #include <linux/err.h> |
Simon Glass | 837a66a | 2019-12-06 21:42:53 -0700 | [diff] [blame] | 34 | |
| 35 | #define GPIO_DW_SIZE(x) (sizeof(u32) * (x)) |
| 36 | #define PAD_CFG_OFFSET(x, dw_num) ((x) + GPIO_DW_SIZE(dw_num)) |
| 37 | #define PAD_CFG0_OFFSET(x) PAD_CFG_OFFSET(x, 0) |
| 38 | #define PAD_CFG1_OFFSET(x) PAD_CFG_OFFSET(x, 1) |
| 39 | |
| 40 | #define MISCCFG_GPE0_DW0_SHIFT 8 |
| 41 | #define MISCCFG_GPE0_DW0_MASK (0xf << MISCCFG_GPE0_DW0_SHIFT) |
| 42 | #define MISCCFG_GPE0_DW1_SHIFT 12 |
| 43 | #define MISCCFG_GPE0_DW1_MASK (0xf << MISCCFG_GPE0_DW1_SHIFT) |
| 44 | #define MISCCFG_GPE0_DW2_SHIFT 16 |
| 45 | #define MISCCFG_GPE0_DW2_MASK (0xf << MISCCFG_GPE0_DW2_SHIFT) |
| 46 | |
| 47 | #define GPI_SMI_STS_OFFSET(comm, group) ((comm)->gpi_smi_sts_reg_0 + \ |
| 48 | ((group) * sizeof(u32))) |
| 49 | #define GPI_SMI_EN_OFFSET(comm, group) ((comm)->gpi_smi_en_reg_0 + \ |
| 50 | ((group) * sizeof(u32))) |
| 51 | #define GPI_IS_OFFSET(comm, group) ((comm)->gpi_int_sts_reg_0 + \ |
| 52 | ((group) * sizeof(uint32_t))) |
| 53 | #define GPI_IE_OFFSET(comm, group) ((comm)->gpi_int_en_reg_0 + \ |
| 54 | ((group) * sizeof(uint32_t))) |
| 55 | |
| 56 | /** |
| 57 | * relative_pad_in_comm() - Get the relative position of a GPIO |
| 58 | * |
| 59 | * This finds the position of a GPIO within a community |
| 60 | * |
| 61 | * @comm: Community to search |
| 62 | * @gpio: Pad number to look up (assumed to be valid) |
| 63 | * @return offset, 0 for first GPIO in community |
| 64 | */ |
| 65 | static size_t relative_pad_in_comm(const struct pad_community *comm, |
| 66 | uint gpio) |
| 67 | { |
| 68 | return gpio - comm->first_pad; |
| 69 | } |
| 70 | |
| 71 | /** |
| 72 | * pinctrl_group_index() - Find group for a a pad |
| 73 | * |
| 74 | * Find the group within the community that the pad is a part of |
| 75 | * |
| 76 | * @comm: Community to search |
| 77 | * @relative_pad: Pad to look up |
| 78 | * @return group number if found (see community_n_groups, etc.), or |
| 79 | * -ESPIPE if no groups, or -ENOENT if not found |
| 80 | */ |
| 81 | static int pinctrl_group_index(const struct pad_community *comm, |
| 82 | uint relative_pad) |
| 83 | { |
| 84 | int i; |
| 85 | |
| 86 | if (!comm->groups) |
| 87 | return -ESPIPE; |
| 88 | |
| 89 | /* find the base pad number for this pad's group */ |
| 90 | for (i = 0; i < comm->num_groups; i++) { |
| 91 | if (relative_pad >= comm->groups[i].first_pad && |
| 92 | relative_pad < comm->groups[i].first_pad + |
| 93 | comm->groups[i].size) |
| 94 | return i; |
| 95 | } |
| 96 | |
| 97 | return -ENOENT; |
| 98 | } |
| 99 | |
| 100 | static int pinctrl_group_index_scaled(const struct pad_community *comm, |
| 101 | uint relative_pad, size_t scale) |
| 102 | { |
| 103 | int ret; |
| 104 | |
| 105 | ret = pinctrl_group_index(comm, relative_pad); |
| 106 | if (ret < 0) |
| 107 | return ret; |
| 108 | |
| 109 | return ret * scale; |
| 110 | } |
| 111 | |
| 112 | static int pinctrl_within_group(const struct pad_community *comm, |
| 113 | uint relative_pad) |
| 114 | { |
| 115 | int ret; |
| 116 | |
| 117 | ret = pinctrl_group_index(comm, relative_pad); |
| 118 | if (ret < 0) |
| 119 | return ret; |
| 120 | |
| 121 | return relative_pad - comm->groups[ret].first_pad; |
| 122 | } |
| 123 | |
| 124 | static u32 pinctrl_bitmask_within_group(const struct pad_community *comm, |
| 125 | uint relative_pad) |
| 126 | { |
| 127 | return 1U << pinctrl_within_group(comm, relative_pad); |
| 128 | } |
| 129 | |
| 130 | /** |
| 131 | * pinctrl_get_device() - Find the device for a particular pad |
| 132 | * |
| 133 | * Each pinctr, device is attached to one community and this supports a number |
| 134 | * of pads. This function finds the device which controls a particular pad. |
| 135 | * |
| 136 | * @pad: Pad to check |
| 137 | * @devp: Returns the device for that pad |
| 138 | * @return 0 if OK, -ENOTBLK if no device was found for the given pin |
| 139 | */ |
| 140 | static int pinctrl_get_device(uint pad, struct udevice **devp) |
| 141 | { |
| 142 | struct udevice *dev; |
| 143 | |
| 144 | /* |
| 145 | * We have to probe each one of these since the community link is only |
| 146 | * attached in intel_pinctrl_ofdata_to_platdata(). |
| 147 | */ |
| 148 | uclass_foreach_dev_probe(UCLASS_PINCTRL, dev) { |
| 149 | struct intel_pinctrl_priv *priv = dev_get_priv(dev); |
| 150 | const struct pad_community *comm = priv->comm; |
| 151 | |
| 152 | if (pad >= comm->first_pad && pad <= comm->last_pad) { |
| 153 | *devp = dev; |
| 154 | return 0; |
| 155 | } |
| 156 | } |
| 157 | printf("pad %d not found\n", pad); |
| 158 | |
| 159 | return -ENOTBLK; |
| 160 | } |
| 161 | |
| 162 | int intel_pinctrl_get_pad(uint pad, struct udevice **devp, uint *offsetp) |
| 163 | { |
| 164 | const struct pad_community *comm; |
| 165 | struct intel_pinctrl_priv *priv; |
| 166 | struct udevice *dev; |
| 167 | int ret; |
| 168 | |
| 169 | ret = pinctrl_get_device(pad, &dev); |
| 170 | if (ret) |
| 171 | return log_msg_ret("pad", ret); |
| 172 | priv = dev_get_priv(dev); |
| 173 | comm = priv->comm; |
| 174 | *devp = dev; |
| 175 | *offsetp = relative_pad_in_comm(comm, pad); |
| 176 | |
| 177 | return 0; |
| 178 | } |
| 179 | |
| 180 | static int pinctrl_configure_owner(struct udevice *dev, |
| 181 | const struct pad_config *cfg, |
| 182 | const struct pad_community *comm) |
| 183 | { |
| 184 | u32 hostsw_own; |
| 185 | u16 hostsw_own_offset; |
| 186 | int pin; |
| 187 | int ret; |
| 188 | |
| 189 | pin = relative_pad_in_comm(comm, cfg->pad); |
| 190 | |
| 191 | /* |
| 192 | * Based on the gpio pin number configure the corresponding bit in |
| 193 | * HOSTSW_OWN register. Value of 0x1 indicates GPIO Driver onwership. |
| 194 | */ |
| 195 | hostsw_own_offset = comm->host_own_reg_0; |
| 196 | ret = pinctrl_group_index_scaled(comm, pin, sizeof(u32)); |
| 197 | if (ret < 0) |
| 198 | return ret; |
| 199 | hostsw_own_offset += ret; |
| 200 | |
| 201 | hostsw_own = pcr_read32(dev, hostsw_own_offset); |
| 202 | |
| 203 | /* |
| 204 | *The 4th bit in pad_config 1 (RO) is used to indicate if the pad |
| 205 | * needs GPIO driver ownership. Set the bit if GPIO driver ownership |
| 206 | * requested, otherwise clear the bit. |
| 207 | */ |
| 208 | if (cfg->pad_config[1] & PAD_CFG1_GPIO_DRIVER) |
| 209 | hostsw_own |= pinctrl_bitmask_within_group(comm, pin); |
| 210 | else |
| 211 | hostsw_own &= ~pinctrl_bitmask_within_group(comm, pin); |
| 212 | |
| 213 | pcr_write32(dev, hostsw_own_offset, hostsw_own); |
| 214 | |
| 215 | return 0; |
| 216 | } |
| 217 | |
| 218 | static int gpi_enable_smi(struct udevice *dev, const struct pad_config *cfg, |
| 219 | const struct pad_community *comm) |
| 220 | { |
| 221 | u32 value; |
| 222 | u16 sts_reg; |
| 223 | u16 en_reg; |
| 224 | int group; |
| 225 | int pin; |
| 226 | int ret; |
| 227 | |
| 228 | if ((cfg->pad_config[0] & PAD_CFG0_ROUTE_SMI) != PAD_CFG0_ROUTE_SMI) |
| 229 | return 0; |
| 230 | |
| 231 | pin = relative_pad_in_comm(comm, cfg->pad); |
| 232 | ret = pinctrl_group_index(comm, pin); |
| 233 | if (ret < 0) |
| 234 | return ret; |
| 235 | group = ret; |
| 236 | |
| 237 | sts_reg = GPI_SMI_STS_OFFSET(comm, group); |
| 238 | value = pcr_read32(dev, sts_reg); |
| 239 | /* Write back 1 to reset the sts bits */ |
| 240 | pcr_write32(dev, sts_reg, value); |
| 241 | |
| 242 | /* Set enable bits */ |
| 243 | en_reg = GPI_SMI_EN_OFFSET(comm, group); |
| 244 | pcr_setbits32(dev, en_reg, pinctrl_bitmask_within_group(comm, pin)); |
| 245 | |
| 246 | return 0; |
| 247 | } |
| 248 | |
| 249 | static int pinctrl_configure_itss(struct udevice *dev, |
| 250 | const struct pad_config *cfg, |
| 251 | uint pad_cfg_offset) |
| 252 | { |
| 253 | struct intel_pinctrl_priv *priv = dev_get_priv(dev); |
| 254 | |
| 255 | if (!priv->itss_pol_cfg) |
| 256 | return -ENOSYS; |
| 257 | |
| 258 | int irq; |
| 259 | |
| 260 | /* |
| 261 | * Set up ITSS polarity if pad is routed to APIC. |
| 262 | * |
| 263 | * The ITSS takes only active high interrupt signals. Therefore, |
| 264 | * if the pad configuration indicates an inversion assume the |
| 265 | * intent is for the ITSS polarity. Before forwarding on the |
| 266 | * request to the APIC there's an inversion setting for how the |
| 267 | * signal is forwarded to the APIC. Honor the inversion setting |
| 268 | * in the GPIO pad configuration so that a hardware active low |
| 269 | * signal looks that way to the APIC (double inversion). |
| 270 | */ |
| 271 | if (!(cfg->pad_config[0] & PAD_CFG0_ROUTE_IOAPIC)) |
| 272 | return 0; |
| 273 | |
| 274 | irq = pcr_read32(dev, PAD_CFG1_OFFSET(pad_cfg_offset)); |
| 275 | irq &= PAD_CFG1_IRQ_MASK; |
| 276 | if (!irq) { |
| 277 | log_err("GPIO %u doesn't support APIC routing\n", cfg->pad); |
| 278 | |
| 279 | return -EPROTONOSUPPORT; |
| 280 | } |
| 281 | irq_set_polarity(priv->itss, irq, |
| 282 | cfg->pad_config[0] & PAD_CFG0_RX_POL_INVERT); |
| 283 | |
| 284 | return 0; |
| 285 | } |
| 286 | |
| 287 | /* Number of DWx config registers can be different for different SOCs */ |
| 288 | static uint pad_config_offset(struct intel_pinctrl_priv *priv, uint pad) |
| 289 | { |
| 290 | const struct pad_community *comm = priv->comm; |
| 291 | size_t offset; |
| 292 | |
| 293 | offset = relative_pad_in_comm(comm, pad); |
| 294 | offset *= GPIO_DW_SIZE(priv->num_cfgs); |
| 295 | |
| 296 | return offset + comm->pad_cfg_base; |
| 297 | } |
| 298 | |
| 299 | static int pinctrl_pad_reset_config_override(const struct pad_community *comm, |
| 300 | u32 config_value) |
| 301 | { |
| 302 | const struct reset_mapping *rst_map = comm->reset_map; |
| 303 | int i; |
| 304 | |
| 305 | /* Logical reset values equal chipset values */ |
| 306 | if (!rst_map || !comm->num_reset_vals) |
| 307 | return config_value; |
| 308 | |
| 309 | for (i = 0; i < comm->num_reset_vals; i++, rst_map++) { |
| 310 | if ((config_value & PAD_CFG0_RESET_MASK) == rst_map->logical) { |
| 311 | config_value &= ~PAD_CFG0_RESET_MASK; |
| 312 | config_value |= rst_map->chipset; |
| 313 | |
| 314 | return config_value; |
| 315 | } |
| 316 | } |
| 317 | log_err("Logical-to-Chipset mapping not found\n"); |
| 318 | |
| 319 | return -ENOENT; |
| 320 | } |
| 321 | |
| 322 | static const int mask[4] = { |
| 323 | PAD_CFG0_TX_STATE | |
| 324 | PAD_CFG0_TX_DISABLE | PAD_CFG0_RX_DISABLE | PAD_CFG0_MODE_MASK | |
| 325 | PAD_CFG0_ROUTE_MASK | PAD_CFG0_RXTENCFG_MASK | |
| 326 | PAD_CFG0_RXINV_MASK | PAD_CFG0_PREGFRXSEL | |
| 327 | PAD_CFG0_TRIG_MASK | PAD_CFG0_RXRAW1_MASK | |
| 328 | PAD_CFG0_RXPADSTSEL_MASK | PAD_CFG0_RESET_MASK, |
| 329 | |
| 330 | #ifdef CONFIG_INTEL_PINCTRL_IOSTANDBY |
| 331 | PAD_CFG1_IOSTERM_MASK | PAD_CFG1_PULL_MASK | PAD_CFG1_IOSSTATE_MASK, |
| 332 | #else |
| 333 | PAD_CFG1_IOSTERM_MASK | PAD_CFG1_PULL_MASK, |
| 334 | #endif |
| 335 | |
| 336 | PAD_CFG2_DEBOUNCE_MASK, |
| 337 | |
| 338 | 0, |
| 339 | }; |
| 340 | |
| 341 | /** |
| 342 | * pinctrl_configure_pad() - Configure a pad |
| 343 | * |
| 344 | * @dev: Pinctrl device containing the pad (see pinctrl_get_device()) |
| 345 | * @cfg: Configuration to apply |
| 346 | * @return 0 if OK, -ve on error |
| 347 | */ |
| 348 | static int pinctrl_configure_pad(struct udevice *dev, |
| 349 | const struct pad_config *cfg) |
| 350 | { |
| 351 | struct intel_pinctrl_priv *priv = dev_get_priv(dev); |
| 352 | const struct pad_community *comm = priv->comm; |
| 353 | uint config_offset; |
| 354 | u32 pad_conf, soc_pad_conf; |
| 355 | int ret; |
| 356 | int i; |
| 357 | |
| 358 | if (IS_ERR(comm)) |
| 359 | return PTR_ERR(comm); |
| 360 | config_offset = pad_config_offset(priv, cfg->pad); |
| 361 | for (i = 0; i < priv->num_cfgs; i++) { |
| 362 | pad_conf = pcr_read32(dev, PAD_CFG_OFFSET(config_offset, i)); |
| 363 | |
| 364 | soc_pad_conf = cfg->pad_config[i]; |
| 365 | if (i == 0) { |
| 366 | ret = pinctrl_pad_reset_config_override(comm, |
| 367 | soc_pad_conf); |
| 368 | if (ret < 0) |
| 369 | return ret; |
| 370 | soc_pad_conf = ret; |
| 371 | } |
| 372 | soc_pad_conf &= mask[i]; |
| 373 | soc_pad_conf |= pad_conf & ~mask[i]; |
| 374 | |
| 375 | log_debug("pinctrl_padcfg [0x%02x, %02zd] DW%d [0x%08x : 0x%08x : 0x%08x]\n", |
| 376 | comm->port, relative_pad_in_comm(comm, cfg->pad), i, |
| 377 | pad_conf,/* old value */ |
| 378 | /* value passed from pinctrl table */ |
| 379 | cfg->pad_config[i], |
| 380 | soc_pad_conf); /*new value*/ |
| 381 | pcr_write32(dev, PAD_CFG_OFFSET(config_offset, i), |
| 382 | soc_pad_conf); |
| 383 | } |
| 384 | ret = pinctrl_configure_itss(dev, cfg, config_offset); |
| 385 | if (ret && ret != -ENOSYS) |
| 386 | return log_msg_ret("itss config failed", ret); |
| 387 | ret = pinctrl_configure_owner(dev, cfg, comm); |
| 388 | if (ret) |
| 389 | return ret; |
| 390 | ret = gpi_enable_smi(dev, cfg, comm); |
| 391 | if (ret) |
| 392 | return ret; |
| 393 | |
| 394 | return 0; |
| 395 | } |
| 396 | |
Simon Glass | 25f16c1 | 2020-07-07 21:32:19 -0600 | [diff] [blame] | 397 | u32 intel_pinctrl_get_config_reg_offset(struct udevice *dev, uint offset) |
Simon Glass | 837a66a | 2019-12-06 21:42:53 -0700 | [diff] [blame] | 398 | { |
| 399 | struct intel_pinctrl_priv *priv = dev_get_priv(dev); |
| 400 | const struct pad_community *comm = priv->comm; |
| 401 | uint config_offset; |
| 402 | |
| 403 | assert(device_get_uclass_id(dev) == UCLASS_PINCTRL); |
| 404 | config_offset = comm->pad_cfg_base + offset * |
| 405 | GPIO_DW_SIZE(priv->num_cfgs); |
| 406 | |
| 407 | return config_offset; |
| 408 | } |
| 409 | |
Simon Glass | 25f16c1 | 2020-07-07 21:32:19 -0600 | [diff] [blame] | 410 | u32 intel_pinctrl_get_config_reg_addr(struct udevice *dev, uint offset) |
| 411 | { |
| 412 | uint config_offset = intel_pinctrl_get_config_reg_offset(dev, offset); |
| 413 | |
| 414 | return (u32)(ulong)pcr_reg_address(dev, config_offset); |
| 415 | } |
| 416 | |
Simon Glass | 837a66a | 2019-12-06 21:42:53 -0700 | [diff] [blame] | 417 | u32 intel_pinctrl_get_config_reg(struct udevice *dev, uint offset) |
| 418 | { |
Simon Glass | 25f16c1 | 2020-07-07 21:32:19 -0600 | [diff] [blame] | 419 | uint config_offset = intel_pinctrl_get_config_reg_offset(dev, offset); |
Simon Glass | 837a66a | 2019-12-06 21:42:53 -0700 | [diff] [blame] | 420 | |
| 421 | return pcr_read32(dev, config_offset); |
| 422 | } |
| 423 | |
| 424 | int intel_pinctrl_get_acpi_pin(struct udevice *dev, uint offset) |
| 425 | { |
| 426 | struct intel_pinctrl_priv *priv = dev_get_priv(dev); |
| 427 | const struct pad_community *comm = priv->comm; |
| 428 | int group; |
| 429 | |
Simon Glass | cf45178 | 2020-07-07 21:32:21 -0600 | [diff] [blame] | 430 | if (IS_ENABLED(CONFIG_INTEL_PINCTRL_MULTI_ACPI_DEVICES)) |
| 431 | return offset; |
Simon Glass | 837a66a | 2019-12-06 21:42:53 -0700 | [diff] [blame] | 432 | group = pinctrl_group_index(comm, offset); |
| 433 | |
| 434 | /* If pad base is not set then use GPIO number as ACPI pin number */ |
| 435 | if (comm->groups[group].acpi_pad_base == PAD_BASE_NONE) |
| 436 | return comm->first_pad + offset; |
| 437 | |
| 438 | /* |
| 439 | * If this group has a non-zero pad base then compute the ACPI pin |
| 440 | * number from the pad base and the relative pad in the group. |
| 441 | */ |
| 442 | return comm->groups[group].acpi_pad_base + |
| 443 | pinctrl_within_group(comm, offset); |
| 444 | } |
| 445 | |
| 446 | int pinctrl_route_gpe(struct udevice *itss, uint gpe0b, uint gpe0c, uint gpe0d) |
| 447 | { |
| 448 | struct udevice *pinctrl_dev; |
| 449 | u32 misccfg_value; |
| 450 | u32 misccfg_clr; |
| 451 | int ret; |
| 452 | |
| 453 | /* |
| 454 | * Get the group here for community specific MISCCFG register. |
| 455 | * If any of these returns -1 then there is some error in devicetree |
| 456 | * where the group is probably hardcoded and does not comply with the |
| 457 | * PMC group defines. So we return from here and MISCFG is set to |
| 458 | * default. |
| 459 | */ |
| 460 | ret = irq_route_pmc_gpio_gpe(itss, gpe0b); |
| 461 | if (ret) |
| 462 | return ret; |
| 463 | gpe0b = ret; |
| 464 | |
| 465 | ret = irq_route_pmc_gpio_gpe(itss, gpe0c); |
| 466 | if (ret) |
| 467 | return ret; |
| 468 | gpe0c = ret; |
| 469 | |
| 470 | ret = irq_route_pmc_gpio_gpe(itss, gpe0d); |
| 471 | if (ret) |
| 472 | return ret; |
| 473 | gpe0d = ret; |
| 474 | |
| 475 | misccfg_value = gpe0b << MISCCFG_GPE0_DW0_SHIFT; |
| 476 | misccfg_value |= gpe0c << MISCCFG_GPE0_DW1_SHIFT; |
| 477 | misccfg_value |= gpe0d << MISCCFG_GPE0_DW2_SHIFT; |
| 478 | |
| 479 | /* Program GPIO_MISCCFG */ |
| 480 | misccfg_clr = MISCCFG_GPE0_DW2_MASK | MISCCFG_GPE0_DW1_MASK | |
| 481 | MISCCFG_GPE0_DW0_MASK; |
| 482 | |
| 483 | log_debug("misccfg_clr:%x misccfg_value:%x\n", misccfg_clr, |
| 484 | misccfg_value); |
| 485 | uclass_foreach_dev_probe(UCLASS_PINCTRL, pinctrl_dev) { |
| 486 | pcr_clrsetbits32(pinctrl_dev, GPIO_MISCCFG, misccfg_clr, |
| 487 | misccfg_value); |
| 488 | } |
| 489 | |
| 490 | return 0; |
| 491 | } |
| 492 | |
| 493 | int pinctrl_gpi_clear_int_cfg(void) |
| 494 | { |
| 495 | struct udevice *dev; |
| 496 | struct uclass *uc; |
| 497 | int ret; |
| 498 | |
| 499 | ret = uclass_get(UCLASS_PINCTRL, &uc); |
| 500 | if (ret) |
| 501 | return log_msg_ret("pinctrl uc", ret); |
| 502 | uclass_foreach_dev(dev, uc) { |
| 503 | struct intel_pinctrl_priv *priv = dev_get_priv(dev); |
| 504 | const struct pad_community *comm = priv->comm; |
| 505 | uint sts_value; |
| 506 | int group; |
| 507 | |
| 508 | for (group = 0; group < comm->num_gpi_regs; group++) { |
| 509 | /* Clear the enable register */ |
| 510 | pcr_write32(dev, GPI_IE_OFFSET(comm, group), 0); |
| 511 | |
| 512 | /* Read and clear the set status register bits*/ |
| 513 | sts_value = pcr_read32(dev, |
| 514 | GPI_IS_OFFSET(comm, group)); |
| 515 | pcr_write32(dev, GPI_IS_OFFSET(comm, group), sts_value); |
| 516 | } |
| 517 | } |
| 518 | |
| 519 | return 0; |
| 520 | } |
| 521 | |
| 522 | int pinctrl_config_pads(struct udevice *dev, u32 *pads, int pads_count) |
| 523 | { |
| 524 | struct intel_pinctrl_priv *priv = dev_get_priv(dev); |
| 525 | const u32 *ptr; |
| 526 | int i; |
| 527 | |
| 528 | log_debug("%s: pads_count=%d\n", __func__, pads_count); |
| 529 | for (ptr = pads, i = 0; i < pads_count; |
| 530 | ptr += 1 + priv->num_cfgs, i++) { |
| 531 | struct udevice *pad_dev = NULL; |
| 532 | struct pad_config *cfg; |
| 533 | int ret; |
| 534 | |
| 535 | cfg = (struct pad_config *)ptr; |
| 536 | ret = pinctrl_get_device(cfg->pad, &pad_dev); |
| 537 | if (ret) |
| 538 | return ret; |
| 539 | ret = pinctrl_configure_pad(pad_dev, cfg); |
| 540 | if (ret) |
| 541 | return ret; |
| 542 | } |
| 543 | |
| 544 | return 0; |
| 545 | } |
| 546 | |
| 547 | int pinctrl_read_pads(struct udevice *dev, ofnode node, const char *prop, |
| 548 | u32 **padsp, int *pad_countp) |
| 549 | { |
| 550 | struct intel_pinctrl_priv *priv = dev_get_priv(dev); |
| 551 | u32 *pads; |
| 552 | int size; |
| 553 | int ret; |
| 554 | |
| 555 | *padsp = NULL; |
| 556 | *pad_countp = 0; |
| 557 | size = ofnode_read_size(node, prop); |
| 558 | if (size < 0) |
| 559 | return 0; |
| 560 | |
| 561 | pads = malloc(size); |
| 562 | if (!pads) |
| 563 | return -ENOMEM; |
| 564 | size /= sizeof(fdt32_t); |
| 565 | ret = ofnode_read_u32_array(node, prop, pads, size); |
| 566 | if (ret) { |
| 567 | free(pads); |
| 568 | return ret; |
| 569 | } |
| 570 | *pad_countp = size / (1 + priv->num_cfgs); |
| 571 | *padsp = pads; |
| 572 | |
| 573 | return 0; |
| 574 | } |
| 575 | |
| 576 | int pinctrl_count_pads(struct udevice *dev, u32 *pads, int size) |
| 577 | { |
| 578 | struct intel_pinctrl_priv *priv = dev_get_priv(dev); |
| 579 | int count = 0; |
| 580 | int i; |
| 581 | |
| 582 | for (i = 0; i < size;) { |
| 583 | u32 val; |
| 584 | int j; |
| 585 | |
| 586 | for (val = j = 0; j < priv->num_cfgs + 1; j++) |
| 587 | val |= pads[i + j]; |
| 588 | if (!val) |
| 589 | break; |
| 590 | count++; |
| 591 | i += priv->num_cfgs + 1; |
| 592 | } |
| 593 | |
| 594 | return count; |
| 595 | } |
| 596 | |
| 597 | int pinctrl_config_pads_for_node(struct udevice *dev, ofnode node) |
| 598 | { |
| 599 | int pads_count; |
| 600 | u32 *pads; |
| 601 | int ret; |
| 602 | |
| 603 | if (device_get_uclass_id(dev) != UCLASS_PINCTRL) |
| 604 | return log_msg_ret("uclass", -EPROTONOSUPPORT); |
| 605 | ret = pinctrl_read_pads(dev, node, "pads", &pads, &pads_count); |
| 606 | if (ret) |
| 607 | return log_msg_ret("no pads", ret); |
| 608 | ret = pinctrl_config_pads(dev, pads, pads_count); |
| 609 | free(pads); |
| 610 | if (ret) |
| 611 | return log_msg_ret("pad config", ret); |
| 612 | |
| 613 | return 0; |
| 614 | } |
| 615 | |
| 616 | int intel_pinctrl_ofdata_to_platdata(struct udevice *dev, |
| 617 | const struct pad_community *comm, |
| 618 | int num_cfgs) |
| 619 | { |
| 620 | struct p2sb_child_platdata *pplat = dev_get_parent_platdata(dev); |
| 621 | struct intel_pinctrl_priv *priv = dev_get_priv(dev); |
Simon Glass | 837a66a | 2019-12-06 21:42:53 -0700 | [diff] [blame] | 622 | |
| 623 | if (!comm) { |
| 624 | log_err("Cannot find community for pid %d\n", pplat->pid); |
| 625 | return -EDOM; |
| 626 | } |
Simon Glass | 837a66a | 2019-12-06 21:42:53 -0700 | [diff] [blame] | 627 | priv->comm = comm; |
| 628 | priv->num_cfgs = num_cfgs; |
| 629 | |
| 630 | return 0; |
| 631 | } |
| 632 | |
| 633 | int intel_pinctrl_probe(struct udevice *dev) |
| 634 | { |
| 635 | struct intel_pinctrl_priv *priv = dev_get_priv(dev); |
Simon Glass | 25885e5 | 2020-07-07 21:32:22 -0600 | [diff] [blame] | 636 | int ret; |
Simon Glass | 837a66a | 2019-12-06 21:42:53 -0700 | [diff] [blame] | 637 | |
| 638 | priv->itss_pol_cfg = true; |
Simon Glass | 25885e5 | 2020-07-07 21:32:22 -0600 | [diff] [blame] | 639 | ret = irq_first_device_type(X86_IRQT_ITSS, &priv->itss); |
| 640 | if (ret) |
| 641 | return log_msg_ret("Cannot find ITSS", ret); |
Simon Glass | 837a66a | 2019-12-06 21:42:53 -0700 | [diff] [blame] | 642 | |
| 643 | return 0; |
| 644 | } |
| 645 | |
| 646 | const struct pinctrl_ops intel_pinctrl_ops = { |
| 647 | /* No operations are supported, but DM expects this to be present */ |
| 648 | }; |