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 Corporation. |
| 4 | * Copyright 2019 Google LLC |
| 5 | * |
| 6 | * Modified from coreboot gpio.h |
| 7 | */ |
| 8 | |
| 9 | #ifndef __ASM_INTEL_PINCTRL_H |
| 10 | #define __ASM_INTEL_PINCTRL_H |
| 11 | |
| 12 | #include <dm/pinctrl.h> |
| 13 | |
| 14 | /** |
| 15 | * struct pad_config - config for a pad |
| 16 | * @pad: offset of pad within community |
| 17 | * @pad_config: Pad config data corresponding to DW0, DW1, etc. |
| 18 | */ |
| 19 | struct pad_config { |
| 20 | int pad; |
| 21 | u32 pad_config[4]; |
| 22 | }; |
| 23 | |
| 24 | #include <asm/arch/gpio.h> |
| 25 | |
| 26 | /* GPIO community IOSF sideband clock gating */ |
| 27 | #define MISCCFG_GPSIDEDPCGEN BIT(5) |
| 28 | /* GPIO community RCOMP clock gating */ |
| 29 | #define MISCCFG_GPRCOMPCDLCGEN BIT(4) |
| 30 | /* GPIO community RTC clock gating */ |
| 31 | #define MISCCFG_GPRTCDLCGEN BIT(3) |
| 32 | /* GFX controller clock gating */ |
| 33 | #define MISCCFG_GSXSLCGEN BIT(2) |
| 34 | /* GPIO community partition clock gating */ |
| 35 | #define MISCCFG_GPDPCGEN BIT(1) |
| 36 | /* GPIO community local clock gating */ |
| 37 | #define MISCCFG_GPDLCGEN BIT(0) |
| 38 | /* Enable GPIO community power management configuration */ |
| 39 | #define MISCCFG_ENABLE_GPIO_PM_CONFIG (MISCCFG_GPSIDEDPCGEN | \ |
| 40 | MISCCFG_GPRCOMPCDLCGEN | MISCCFG_GPRTCDLCGEN | MISCCFG_GSXSLCGEN \ |
| 41 | | MISCCFG_GPDPCGEN | MISCCFG_GPDLCGEN) |
| 42 | |
| 43 | /* |
| 44 | * GPIO numbers may not be contiguous and instead will have a different |
| 45 | * starting pin number for each pad group. |
| 46 | */ |
| 47 | #define INTEL_GPP_BASE(first_of_community, start_of_group, end_of_group,\ |
| 48 | group_pad_base) \ |
| 49 | { \ |
| 50 | .first_pad = (start_of_group) - (first_of_community), \ |
| 51 | .size = (end_of_group) - (start_of_group) + 1, \ |
| 52 | .acpi_pad_base = (group_pad_base), \ |
| 53 | } |
| 54 | |
| 55 | /* |
| 56 | * A pad base of -1 indicates that this group uses contiguous numbering |
| 57 | * and a pad base should not be used for this group. |
| 58 | */ |
| 59 | #define PAD_BASE_NONE -1 |
| 60 | |
| 61 | /* The common/default group numbering is contiguous */ |
| 62 | #define INTEL_GPP(first_of_community, start_of_group, end_of_group) \ |
| 63 | INTEL_GPP_BASE(first_of_community, start_of_group, end_of_group,\ |
| 64 | PAD_BASE_NONE) |
| 65 | |
| 66 | /** |
| 67 | * struct reset_mapping - logical to actual value for PADRSTCFG in DW0 |
| 68 | * |
| 69 | * Note that the values are expected to be within the field placement of the |
| 70 | * register itself. i.e. if the reset field is at 31:30 then the values within |
| 71 | * logical and chipset should occupy 31:30. |
| 72 | */ |
| 73 | struct reset_mapping { |
| 74 | u32 logical; |
| 75 | u32 chipset; |
| 76 | }; |
| 77 | |
| 78 | /** |
| 79 | * struct pad_group - describes the groups within each community |
| 80 | * |
| 81 | * @first_pad: offset of first pad of the group relative to the community |
| 82 | * @size: size of the group |
| 83 | * @acpi_pad_base: starting pin number for the pads in this group when they are |
| 84 | * used in ACPI. This is only needed if the pins are not contiguous across |
| 85 | * groups. Most groups will have this set to PAD_BASE_NONE and use |
| 86 | * contiguous numbering for ACPI. |
| 87 | */ |
| 88 | struct pad_group { |
| 89 | int first_pad; |
| 90 | uint size; |
| 91 | int acpi_pad_base; |
| 92 | }; |
| 93 | |
| 94 | /** |
| 95 | * struct pad_community - community of pads |
| 96 | * |
| 97 | * This describes a community, or each group within a community when multiple |
| 98 | * groups exist inside a community |
| 99 | * |
| 100 | * @name: Community name |
| 101 | * @acpi_path: ACPI path |
| 102 | * @num_gpi_regs: number of gpi registers in community |
| 103 | * @max_pads_per_group: number of pads in each group; number of pads bit-mapped |
| 104 | * in each GPI status/en and Host Own Reg |
| 105 | * @first_pad: first pad in community |
| 106 | * @last_pad: last pad in community |
| 107 | * @host_own_reg_0: offset to Host Ownership Reg 0 |
| 108 | * @gpi_int_sts_reg_0: offset to GPI Int STS Reg 0 |
| 109 | * @gpi_int_en_reg_0: offset to GPI Int Enable Reg 0 |
| 110 | * @gpi_smi_sts_reg_0: offset to GPI SMI STS Reg 0 |
| 111 | * @gpi_smi_en_reg_0: offset to GPI SMI EN Reg 0 |
| 112 | * @pad_cfg_base: offset to first PAD_GFG_DW0 Reg |
| 113 | * @gpi_status_offset: specifies offset in struct gpi_status |
| 114 | * @port: PCR Port ID |
| 115 | * @reset_map: PADRSTCFG logical to chipset mapping |
| 116 | * @num_reset_vals: number of values in @reset_map |
| 117 | * @groups; list of groups for this community |
| 118 | * @num_groups: number of groups |
| 119 | */ |
| 120 | struct pad_community { |
| 121 | const char *name; |
| 122 | const char *acpi_path; |
| 123 | size_t num_gpi_regs; |
| 124 | size_t max_pads_per_group; |
| 125 | uint first_pad; |
| 126 | uint last_pad; |
| 127 | u16 host_own_reg_0; |
| 128 | u16 gpi_int_sts_reg_0; |
| 129 | u16 gpi_int_en_reg_0; |
| 130 | u16 gpi_smi_sts_reg_0; |
| 131 | u16 gpi_smi_en_reg_0; |
| 132 | u16 pad_cfg_base; |
| 133 | u8 gpi_status_offset; |
| 134 | u8 port; |
| 135 | const struct reset_mapping *reset_map; |
| 136 | size_t num_reset_vals; |
| 137 | const struct pad_group *groups; |
| 138 | size_t num_groups; |
| 139 | }; |
| 140 | |
| 141 | /** |
| 142 | * struct intel_pinctrl_priv - private data for each pinctrl device |
| 143 | * |
| 144 | * @comm: Pad community for this device |
| 145 | * @num_cfgs: Number of configuration words for each pad |
| 146 | * @itss: ITSS device (for interrupt handling) |
| 147 | * @itss_pol_cfg: Use to program Interrupt Polarity Control (IPCx) register |
| 148 | * Each bit represents IRQx Active High Polarity Disable configuration: |
| 149 | * when set to 1, the interrupt polarity associated with IRQx is inverted |
| 150 | * to appear as Active Low to IOAPIC and vice versa |
| 151 | */ |
| 152 | struct intel_pinctrl_priv { |
| 153 | const struct pad_community *comm; |
| 154 | int num_cfgs; |
| 155 | struct udevice *itss; |
| 156 | bool itss_pol_cfg; |
| 157 | }; |
| 158 | |
| 159 | /* Exported common operations for the pinctrl driver */ |
| 160 | extern const struct pinctrl_ops intel_pinctrl_ops; |
| 161 | |
| 162 | /* Exported common probe function for the pinctrl driver */ |
| 163 | int intel_pinctrl_probe(struct udevice *dev); |
| 164 | |
| 165 | /** |
| 166 | * intel_pinctrl_ofdata_to_platdata() - Handle common platdata setup |
| 167 | * |
| 168 | * @dev: Pinctrl device |
| 169 | * @comm: Pad community for this device |
| 170 | * @num_cfgs: Number of configuration words for each pad |
| 171 | * @return 0 if OK, -EDOM if @comm is NULL, other -ve value on other error |
| 172 | */ |
| 173 | int intel_pinctrl_ofdata_to_platdata(struct udevice *dev, |
| 174 | const struct pad_community *comm, |
| 175 | int num_cfgs); |
| 176 | |
| 177 | /** |
| 178 | * pinctrl_route_gpe() - set GPIO groups for the general-purpose-event blocks |
| 179 | * |
| 180 | * The values from PMC register GPE_CFG are passed which is then mapped to |
| 181 | * proper groups for MISCCFG. This basically sets the MISCCFG register bits: |
| 182 | * dw0 = gpe0_route[11:8]. This is ACPI GPE0b. |
| 183 | * dw1 = gpe0_route[15:12]. This is ACPI GPE0c. |
| 184 | * dw2 = gpe0_route[19:16]. This is ACPI GPE0d. |
| 185 | * |
| 186 | * @dev: ITSS device |
| 187 | * @gpe0b: Value for GPE0B |
| 188 | * @gpe0c: Value for GPE0C |
| 189 | * @gpe0d: Value for GPE0D |
| 190 | * @return 0 if OK, -ve on error |
| 191 | */ |
| 192 | int pinctrl_route_gpe(struct udevice *dev, uint gpe0b, uint gpe0c, uint gpe0d); |
| 193 | |
| 194 | /** |
| 195 | * pinctrl_config_pads() - Configure a list of pads |
| 196 | * |
| 197 | * Configures multiple pads using the provided data from the device tree. |
| 198 | * |
| 199 | * @dev: pinctrl device (any will do) |
| 200 | * @pads: Pad data, consisting of a pad number followed by num_cfgs entries |
| 201 | * containing the data for that pad (num_cfgs is set by the pinctrl device) |
| 202 | * @pads_count: Number of pads to configure |
| 203 | * @return 0 if OK, -ve on error |
| 204 | */ |
| 205 | int pinctrl_config_pads(struct udevice *dev, u32 *pads, int pads_count); |
| 206 | |
| 207 | /** |
| 208 | * pinctrl_gpi_clear_int_cfg() - Set up the interrupts for use |
| 209 | * |
| 210 | * This enables the interrupt inputs and clears the status register bits |
| 211 | * |
| 212 | * @return 0 if OK, -ve on error |
| 213 | */ |
| 214 | int pinctrl_gpi_clear_int_cfg(void); |
| 215 | |
| 216 | /** |
| 217 | * pinctrl_config_pads_for_node() - Configure pads |
| 218 | * |
| 219 | * Set up the pads using the data in a given node |
| 220 | * |
| 221 | * @dev: pinctrl device (any will do) |
| 222 | * @node: Node containing the 'pads' property with the data in it |
| 223 | * @return 0 if OK, -ve on error |
| 224 | */ |
| 225 | int pinctrl_config_pads_for_node(struct udevice *dev, ofnode node); |
| 226 | |
| 227 | /** |
| 228 | * pinctrl_read_pads() - Read pad data from a node |
| 229 | * |
| 230 | * @dev: pinctrl device (any will do, it is just used to get config) |
| 231 | * @node: Node to read pad data from |
| 232 | * @prop: Property name to use (e.g. "pads") |
| 233 | * @padsp: Returns a pointer to an allocated array of pad data, in the format: |
| 234 | * <pad> |
| 235 | * <pad_config0> |
| 236 | * <pad_config1> |
| 237 | * ... |
| 238 | * |
| 239 | * The number of pad config values is set by the pinctrl controller. |
| 240 | * The caller must free this array. |
| 241 | * @pad_countp: Returns the number of pads read |
| 242 | * @ereturn 0 if OK, -ve on error |
| 243 | */ |
| 244 | int pinctrl_read_pads(struct udevice *dev, ofnode node, const char *prop, |
| 245 | u32 **padsp, int *pad_countp); |
| 246 | |
| 247 | /** |
| 248 | * pinctrl_count_pads() - Count the number of pads in a pad array |
| 249 | * |
| 250 | * This used used with of-platdata where the array may be smaller than its |
| 251 | * maximum size. This function searches for the last pad in the array by finding |
| 252 | * the first 'zero' record |
| 253 | * |
| 254 | * This works out the number of records in the array. Each record has one word |
| 255 | * for the pad and num_cfgs words for the config. |
| 256 | * |
| 257 | * @dev: pinctrl device (any will do) |
| 258 | * @pads: Array of pad data |
| 259 | * @size: Size of pad data in bytes |
| 260 | * @return number of pads represented by the data |
| 261 | */ |
| 262 | int pinctrl_count_pads(struct udevice *dev, u32 *pads, int size); |
| 263 | |
| 264 | /** |
| 265 | * intel_pinctrl_get_config_reg_addr() - Get address of the pin config registers |
| 266 | * |
| 267 | * @dev: Pinctrl device |
| 268 | * @offset: GPIO offset within this device |
| 269 | * @return register offset within the GPIO p2sb region |
| 270 | */ |
| 271 | u32 intel_pinctrl_get_config_reg_addr(struct udevice *dev, uint offset); |
| 272 | |
| 273 | /** |
| 274 | * intel_pinctrl_get_config_reg() - Get the value of a GPIO register |
| 275 | * |
| 276 | * @dev: Pinctrl device |
| 277 | * @offset: GPIO offset within this device |
| 278 | * @return register value within the GPIO p2sb region |
| 279 | */ |
| 280 | u32 intel_pinctrl_get_config_reg(struct udevice *dev, uint offset); |
| 281 | |
| 282 | /** |
| 283 | * intel_pinctrl_get_pad() - Get pad information for a pad |
| 284 | * |
| 285 | * This is used by the GPIO controller to find the pinctrl used by a pad. |
| 286 | * |
| 287 | * @pad: Pad to check |
| 288 | * @devp: Returns pinctrl device containing that pad |
| 289 | * @offsetp: Returns offset of pad within that pinctrl device |
| 290 | */ |
| 291 | int intel_pinctrl_get_pad(uint pad, struct udevice **devp, uint *offsetp); |
| 292 | |
| 293 | /** |
| 294 | * intel_pinctrl_get_acpi_pin() - Get the ACPI pin for a pinctrl pin |
| 295 | * |
| 296 | * Maps a pinctrl pin (in terms of its offset within the pins controlled by that |
| 297 | * pinctrl) to an ACPI GPIO pin-table entry. |
| 298 | * |
| 299 | * @dev: Pinctrl device to check |
| 300 | * @offset: Offset of pin within that device (0 = first) |
| 301 | * @return associated ACPI GPIO pin-table entry, or standard pin number if the |
| 302 | * ACPI pad base is not set |
| 303 | */ |
| 304 | int intel_pinctrl_get_acpi_pin(struct udevice *dev, uint offset); |
| 305 | |
| 306 | #endif |