blob: c14176d4a77bf7734fe4074554f11ddfcd882d4b [file] [log] [blame]
Simon Glass0a6f3332019-12-08 17:32:08 -07001// 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
9#define LOG_CATEGORY UCLASS_GPIO
10
11#include <common.h>
12#include <dm.h>
13#include <dt-structs.h>
Simon Glassf7ae49f2020-05-10 11:40:05 -060014#include <log.h>
Simon Glass0a6f3332019-12-08 17:32:08 -070015#include <p2sb.h>
16#include <asm/intel_pinctrl.h>
17#include <asm-generic/gpio.h>
18#include <asm/intel_pinctrl_defs.h>
19
20/**
21 * struct apl_gpio_platdata - platform data for each device
22 *
23 * @dtplat: of-platdata data from C struct
24 */
25struct apl_gpio_platdata {
26#if CONFIG_IS_ENABLED(OF_PLATDATA)
27 /* Put this first since driver model will copy the data here */
28 struct dtd_intel_apl_pinctrl dtplat;
29#endif
30};
31
32static const struct reset_mapping rst_map[] = {
33 { .logical = PAD_CFG0_LOGICAL_RESET_PWROK, .chipset = 0U << 30 },
34 { .logical = PAD_CFG0_LOGICAL_RESET_DEEP, .chipset = 1U << 30 },
35 { .logical = PAD_CFG0_LOGICAL_RESET_PLTRST, .chipset = 2U << 30 },
36};
37
38/* Groups for each community */
39static const struct pad_group apl_community_n_groups[] = {
40 INTEL_GPP(N_OFFSET, N_OFFSET, GPIO_31), /* NORTH 0 */
41 INTEL_GPP(N_OFFSET, GPIO_32, JTAG_TRST_B), /* NORTH 1 */
42 INTEL_GPP(N_OFFSET, JTAG_TMS, SVID0_CLK), /* NORTH 2 */
43};
44
45static const struct pad_group apl_community_w_groups[] = {
46 INTEL_GPP(W_OFFSET, W_OFFSET, OSC_CLK_OUT_1), /* WEST 0 */
47 INTEL_GPP(W_OFFSET, OSC_CLK_OUT_2, SUSPWRDNACK),/* WEST 1 */
48};
49
50static const struct pad_group apl_community_sw_groups[] = {
51 INTEL_GPP(SW_OFFSET, SW_OFFSET, SMB_ALERTB), /* SOUTHWEST 0 */
52 INTEL_GPP(SW_OFFSET, SMB_CLK, LPC_FRAMEB), /* SOUTHWEST 1 */
53};
54
55static const struct pad_group apl_community_nw_groups[] = {
56 INTEL_GPP(NW_OFFSET, NW_OFFSET, PROCHOT_B), /* NORTHWEST 0 */
57 INTEL_GPP(NW_OFFSET, PMIC_I2C_SCL, GPIO_106), /* NORTHWEST 1 */
58 INTEL_GPP(NW_OFFSET, GPIO_109, GPIO_123), /* NORTHWEST 2 */
59};
60
61/* TODO(sjg@chromium.org): Consider moving this to device tree */
62static const struct pad_community apl_gpio_communities[] = {
63 {
64 .port = PID_GPIO_N,
65 .first_pad = N_OFFSET,
66 .last_pad = SVID0_CLK,
67 .num_gpi_regs = NUM_N_GPI_REGS,
68 .gpi_status_offset = NUM_NW_GPI_REGS + NUM_W_GPI_REGS
69 + NUM_SW_GPI_REGS,
70 .pad_cfg_base = PAD_CFG_BASE,
71 .host_own_reg_0 = HOSTSW_OWN_REG_0,
72 .gpi_int_sts_reg_0 = GPI_INT_STS_0,
73 .gpi_int_en_reg_0 = GPI_INT_EN_0,
74 .gpi_smi_sts_reg_0 = GPI_SMI_STS_0,
75 .gpi_smi_en_reg_0 = GPI_SMI_EN_0,
76 .max_pads_per_group = GPIO_MAX_NUM_PER_GROUP,
77 .name = "GPIO_GPE_N",
78 .acpi_path = "\\_SB.GPO0",
79 .reset_map = rst_map,
80 .num_reset_vals = ARRAY_SIZE(rst_map),
81 .groups = apl_community_n_groups,
82 .num_groups = ARRAY_SIZE(apl_community_n_groups),
83 }, {
84 .port = PID_GPIO_NW,
85 .first_pad = NW_OFFSET,
86 .last_pad = GPIO_123,
87 .num_gpi_regs = NUM_NW_GPI_REGS,
88 .gpi_status_offset = NUM_W_GPI_REGS + NUM_SW_GPI_REGS,
89 .pad_cfg_base = PAD_CFG_BASE,
90 .host_own_reg_0 = HOSTSW_OWN_REG_0,
91 .gpi_int_sts_reg_0 = GPI_INT_STS_0,
92 .gpi_int_en_reg_0 = GPI_INT_EN_0,
93 .gpi_smi_sts_reg_0 = GPI_SMI_STS_0,
94 .gpi_smi_en_reg_0 = GPI_SMI_EN_0,
95 .max_pads_per_group = GPIO_MAX_NUM_PER_GROUP,
96 .name = "GPIO_GPE_NW",
97 .acpi_path = "\\_SB.GPO1",
98 .reset_map = rst_map,
99 .num_reset_vals = ARRAY_SIZE(rst_map),
100 .groups = apl_community_nw_groups,
101 .num_groups = ARRAY_SIZE(apl_community_nw_groups),
102 }, {
103 .port = PID_GPIO_W,
104 .first_pad = W_OFFSET,
105 .last_pad = SUSPWRDNACK,
106 .num_gpi_regs = NUM_W_GPI_REGS,
107 .gpi_status_offset = NUM_SW_GPI_REGS,
108 .pad_cfg_base = PAD_CFG_BASE,
109 .host_own_reg_0 = HOSTSW_OWN_REG_0,
110 .gpi_int_sts_reg_0 = GPI_INT_STS_0,
111 .gpi_int_en_reg_0 = GPI_INT_EN_0,
112 .gpi_smi_sts_reg_0 = GPI_SMI_STS_0,
113 .gpi_smi_en_reg_0 = GPI_SMI_EN_0,
114 .max_pads_per_group = GPIO_MAX_NUM_PER_GROUP,
115 .name = "GPIO_GPE_W",
116 .acpi_path = "\\_SB.GPO2",
117 .reset_map = rst_map,
118 .num_reset_vals = ARRAY_SIZE(rst_map),
119 .groups = apl_community_w_groups,
120 .num_groups = ARRAY_SIZE(apl_community_w_groups),
121 }, {
122 .port = PID_GPIO_SW,
123 .first_pad = SW_OFFSET,
124 .last_pad = LPC_FRAMEB,
125 .num_gpi_regs = NUM_SW_GPI_REGS,
126 .gpi_status_offset = 0,
127 .pad_cfg_base = PAD_CFG_BASE,
128 .host_own_reg_0 = HOSTSW_OWN_REG_0,
129 .gpi_int_sts_reg_0 = GPI_INT_STS_0,
130 .gpi_int_en_reg_0 = GPI_INT_EN_0,
131 .gpi_smi_sts_reg_0 = GPI_SMI_STS_0,
132 .gpi_smi_en_reg_0 = GPI_SMI_EN_0,
133 .max_pads_per_group = GPIO_MAX_NUM_PER_GROUP,
134 .name = "GPIO_GPE_SW",
135 .acpi_path = "\\_SB.GPO3",
136 .reset_map = rst_map,
137 .num_reset_vals = ARRAY_SIZE(rst_map),
138 .groups = apl_community_sw_groups,
139 .num_groups = ARRAY_SIZE(apl_community_sw_groups),
140 },
141};
142
143static int apl_pinctrl_ofdata_to_platdata(struct udevice *dev)
144{
145 struct p2sb_child_platdata *pplat;
146 const struct pad_community *comm = NULL;
147 int i;
148
149#if CONFIG_IS_ENABLED(OF_PLATDATA)
150 struct apl_gpio_platdata *plat = dev_get_platdata(dev);
151 int ret;
152
153 /*
154 * It would be nice to do this in the bind() method, but with
155 * of-platdata binding happens in the order that DM finds things in the
156 * linker list (i.e. alphabetical order by driver name). So the GPIO
157 * device may well be bound before its parent (p2sb), and this call
158 * will fail if p2sb is not bound yet.
159 *
160 * TODO(sjg@chromium.org): Add a parent pointer to child devices in dtoc
161 */
162 ret = p2sb_set_port_id(dev, plat->dtplat.intel_p2sb_port_id);
163 if (ret)
164 return log_msg_ret("Could not set port id", ret);
165#endif
166 /* Attach this device to its community structure */
167 pplat = dev_get_parent_platdata(dev);
168 for (i = 0; i < ARRAY_SIZE(apl_gpio_communities); i++) {
169 if (apl_gpio_communities[i].port == pplat->pid)
170 comm = &apl_gpio_communities[i];
171 }
172
173 return intel_pinctrl_ofdata_to_platdata(dev, comm, 2);
174}
175
176static const struct udevice_id apl_gpio_ids[] = {
177 { .compatible = "intel,apl-pinctrl"},
178 { }
179};
180
181U_BOOT_DRIVER(apl_pinctrl_drv) = {
182 .name = "intel_apl_pinctrl",
183 .id = UCLASS_PINCTRL,
184 .of_match = apl_gpio_ids,
185 .probe = intel_pinctrl_probe,
186 .ops = &intel_pinctrl_ops,
187#if !CONFIG_IS_ENABLED(OF_PLATDATA)
188 .bind = dm_scan_fdt_dev,
189#endif
190 .ofdata_to_platdata = apl_pinctrl_ofdata_to_platdata,
191 .priv_auto_alloc_size = sizeof(struct intel_pinctrl_priv),
192 .platdata_auto_alloc_size = sizeof(struct apl_gpio_platdata),
193};