blob: 978eddd89ea2aaefab9c9369a6d15fdf6ee1053a [file] [log] [blame]
Andy Shevchenko875a92b2018-06-29 15:36:34 +03001// SPDX-License-Identifier: GPL-2.0
Mika Westerberg6e08d6b2014-11-03 13:01:33 +02002/*
3 * Cherryview/Braswell pinctrl driver
4 *
Andy Shevchenko293428f2020-06-09 21:24:49 +03005 * Copyright (C) 2014, 2020 Intel Corporation
Mika Westerberg6e08d6b2014-11-03 13:01:33 +02006 * Author: Mika Westerberg <mika.westerberg@linux.intel.com>
7 *
8 * This driver is based on the original Cherryview GPIO driver by
9 * Ning Li <ning.li@intel.com>
10 * Alan Cox <alan@linux.intel.com>
Mika Westerberg6e08d6b2014-11-03 13:01:33 +020011 */
12
Andy Shevchenko994f8862018-09-04 14:26:25 +030013#include <linux/acpi.h>
Mika Westerberg70365022017-04-10 13:16:33 +030014#include <linux/dmi.h>
Andy Shevchenko994f8862018-09-04 14:26:25 +030015#include <linux/gpio/driver.h>
Mika Westerberg6e08d6b2014-11-03 13:01:33 +020016#include <linux/kernel.h>
17#include <linux/module.h>
Andy Shevchenko994f8862018-09-04 14:26:25 +030018#include <linux/platform_device.h>
Mika Westerberg6e08d6b2014-11-03 13:01:33 +020019#include <linux/types.h>
Andy Shevchenko994f8862018-09-04 14:26:25 +030020
Mika Westerberg6e08d6b2014-11-03 13:01:33 +020021#include <linux/pinctrl/pinctrl.h>
22#include <linux/pinctrl/pinmux.h>
23#include <linux/pinctrl/pinconf.h>
24#include <linux/pinctrl/pinconf-generic.h>
Mika Westerberg6e08d6b2014-11-03 13:01:33 +020025
Andy Shevchenko5458b7c2018-09-04 14:26:21 +030026#include "pinctrl-intel.h"
27
Mika Westerberg6e08d6b2014-11-03 13:01:33 +020028#define CHV_INTSTAT 0x300
29#define CHV_INTMASK 0x380
30
31#define FAMILY_PAD_REGS_OFF 0x4400
32#define FAMILY_PAD_REGS_SIZE 0x400
33#define MAX_FAMILY_PAD_GPIO_NO 15
34#define GPIO_REGS_SIZE 8
35
36#define CHV_PADCTRL0 0x000
37#define CHV_PADCTRL0_INTSEL_SHIFT 28
Andy Shevchenko5707dd72020-04-01 20:35:02 +030038#define CHV_PADCTRL0_INTSEL_MASK GENMASK(31, 28)
Mika Westerberg6e08d6b2014-11-03 13:01:33 +020039#define CHV_PADCTRL0_TERM_UP BIT(23)
40#define CHV_PADCTRL0_TERM_SHIFT 20
Andy Shevchenko5707dd72020-04-01 20:35:02 +030041#define CHV_PADCTRL0_TERM_MASK GENMASK(22, 20)
Mika Westerberg6e08d6b2014-11-03 13:01:33 +020042#define CHV_PADCTRL0_TERM_20K 1
43#define CHV_PADCTRL0_TERM_5K 2
44#define CHV_PADCTRL0_TERM_1K 4
45#define CHV_PADCTRL0_PMODE_SHIFT 16
Andy Shevchenko5707dd72020-04-01 20:35:02 +030046#define CHV_PADCTRL0_PMODE_MASK GENMASK(19, 16)
Mika Westerberg6e08d6b2014-11-03 13:01:33 +020047#define CHV_PADCTRL0_GPIOEN BIT(15)
48#define CHV_PADCTRL0_GPIOCFG_SHIFT 8
Andy Shevchenko5707dd72020-04-01 20:35:02 +030049#define CHV_PADCTRL0_GPIOCFG_MASK GENMASK(10, 8)
Mika Westerberg6e08d6b2014-11-03 13:01:33 +020050#define CHV_PADCTRL0_GPIOCFG_GPIO 0
51#define CHV_PADCTRL0_GPIOCFG_GPO 1
52#define CHV_PADCTRL0_GPIOCFG_GPI 2
53#define CHV_PADCTRL0_GPIOCFG_HIZ 3
54#define CHV_PADCTRL0_GPIOTXSTATE BIT(1)
55#define CHV_PADCTRL0_GPIORXSTATE BIT(0)
56
57#define CHV_PADCTRL1 0x004
58#define CHV_PADCTRL1_CFGLOCK BIT(31)
59#define CHV_PADCTRL1_INVRXTX_SHIFT 4
Andy Shevchenko5707dd72020-04-01 20:35:02 +030060#define CHV_PADCTRL1_INVRXTX_MASK GENMASK(7, 4)
Hans de Goedea0bf06d2020-09-04 19:21:41 +020061#define CHV_PADCTRL1_INVRXTX_TXDATA BIT(7)
Andy Shevchenko5707dd72020-04-01 20:35:02 +030062#define CHV_PADCTRL1_INVRXTX_RXDATA BIT(6)
63#define CHV_PADCTRL1_INVRXTX_TXENABLE BIT(5)
Mika Westerberg6e08d6b2014-11-03 13:01:33 +020064#define CHV_PADCTRL1_ODEN BIT(3)
Andy Shevchenko5707dd72020-04-01 20:35:02 +030065#define CHV_PADCTRL1_INTWAKECFG_MASK GENMASK(2, 0)
Mika Westerberg6e08d6b2014-11-03 13:01:33 +020066#define CHV_PADCTRL1_INTWAKECFG_FALLING 1
67#define CHV_PADCTRL1_INTWAKECFG_RISING 2
68#define CHV_PADCTRL1_INTWAKECFG_BOTH 3
69#define CHV_PADCTRL1_INTWAKECFG_LEVEL 4
70
Andy Shevchenko293428f2020-06-09 21:24:49 +030071struct intel_pad_context {
Mika Westerberg9eb457b2014-12-04 12:32:50 +020072 u32 padctrl0;
73 u32 padctrl1;
74};
75
Hans de Goedebdfbef22021-11-18 11:56:48 +010076#define CHV_INVALID_HWIRQ ((unsigned int)INVALID_HWIRQ)
77
Mika Westerberg6e08d6b2014-11-03 13:01:33 +020078/**
Andy Shevchenko8a828572020-07-27 19:12:15 +030079 * struct intel_community_context - community context for Cherryview
80 * @intr_lines: Mapping between 16 HW interrupt wires and GPIO offset (in GPIO number space)
81 * @saved_intmask: Interrupt mask saved for system sleep
82 */
83struct intel_community_context {
84 unsigned int intr_lines[16];
85 u32 saved_intmask;
86};
87
Andy Shevchenko36ad7b22020-04-01 20:35:01 +030088#define PINMODE_INVERT_OE BIT(15)
Mika Westerberg6e08d6b2014-11-03 13:01:33 +020089
Andy Shevchenko36ad7b22020-04-01 20:35:01 +030090#define PINMODE(m, i) ((m) | ((i) * PINMODE_INVERT_OE))
Mika Westerberg6e08d6b2014-11-03 13:01:33 +020091
Andy Shevchenko293428f2020-06-09 21:24:49 +030092#define CHV_GPP(start, end) \
Mika Westerberg6e08d6b2014-11-03 13:01:33 +020093 { \
94 .base = (start), \
Andy Shevchenko36ad7b22020-04-01 20:35:01 +030095 .size = (end) - (start) + 1, \
Mika Westerberg6e08d6b2014-11-03 13:01:33 +020096 }
97
Andy Shevchenko293428f2020-06-09 21:24:49 +030098#define CHV_COMMUNITY(g, i, a) \
99 { \
100 .gpps = (g), \
101 .ngpps = ARRAY_SIZE(g), \
102 .nirqs = (i), \
103 .acpi_space_id = (a), \
104 }
105
Mika Westerberg6e08d6b2014-11-03 13:01:33 +0200106static const struct pinctrl_pin_desc southwest_pins[] = {
107 PINCTRL_PIN(0, "FST_SPI_D2"),
108 PINCTRL_PIN(1, "FST_SPI_D0"),
109 PINCTRL_PIN(2, "FST_SPI_CLK"),
110 PINCTRL_PIN(3, "FST_SPI_D3"),
111 PINCTRL_PIN(4, "FST_SPI_CS1_B"),
112 PINCTRL_PIN(5, "FST_SPI_D1"),
113 PINCTRL_PIN(6, "FST_SPI_CS0_B"),
114 PINCTRL_PIN(7, "FST_SPI_CS2_B"),
115
116 PINCTRL_PIN(15, "UART1_RTS_B"),
117 PINCTRL_PIN(16, "UART1_RXD"),
118 PINCTRL_PIN(17, "UART2_RXD"),
119 PINCTRL_PIN(18, "UART1_CTS_B"),
120 PINCTRL_PIN(19, "UART2_RTS_B"),
121 PINCTRL_PIN(20, "UART1_TXD"),
122 PINCTRL_PIN(21, "UART2_TXD"),
123 PINCTRL_PIN(22, "UART2_CTS_B"),
124
125 PINCTRL_PIN(30, "MF_HDA_CLK"),
126 PINCTRL_PIN(31, "MF_HDA_RSTB"),
127 PINCTRL_PIN(32, "MF_HDA_SDIO"),
128 PINCTRL_PIN(33, "MF_HDA_SDO"),
129 PINCTRL_PIN(34, "MF_HDA_DOCKRSTB"),
130 PINCTRL_PIN(35, "MF_HDA_SYNC"),
131 PINCTRL_PIN(36, "MF_HDA_SDI1"),
132 PINCTRL_PIN(37, "MF_HDA_DOCKENB"),
133
134 PINCTRL_PIN(45, "I2C5_SDA"),
135 PINCTRL_PIN(46, "I2C4_SDA"),
136 PINCTRL_PIN(47, "I2C6_SDA"),
137 PINCTRL_PIN(48, "I2C5_SCL"),
138 PINCTRL_PIN(49, "I2C_NFC_SDA"),
139 PINCTRL_PIN(50, "I2C4_SCL"),
140 PINCTRL_PIN(51, "I2C6_SCL"),
141 PINCTRL_PIN(52, "I2C_NFC_SCL"),
142
143 PINCTRL_PIN(60, "I2C1_SDA"),
144 PINCTRL_PIN(61, "I2C0_SDA"),
145 PINCTRL_PIN(62, "I2C2_SDA"),
146 PINCTRL_PIN(63, "I2C1_SCL"),
147 PINCTRL_PIN(64, "I2C3_SDA"),
148 PINCTRL_PIN(65, "I2C0_SCL"),
149 PINCTRL_PIN(66, "I2C2_SCL"),
150 PINCTRL_PIN(67, "I2C3_SCL"),
151
152 PINCTRL_PIN(75, "SATA_GP0"),
153 PINCTRL_PIN(76, "SATA_GP1"),
154 PINCTRL_PIN(77, "SATA_LEDN"),
155 PINCTRL_PIN(78, "SATA_GP2"),
156 PINCTRL_PIN(79, "MF_SMB_ALERTB"),
157 PINCTRL_PIN(80, "SATA_GP3"),
158 PINCTRL_PIN(81, "MF_SMB_CLK"),
159 PINCTRL_PIN(82, "MF_SMB_DATA"),
160
161 PINCTRL_PIN(90, "PCIE_CLKREQ0B"),
162 PINCTRL_PIN(91, "PCIE_CLKREQ1B"),
163 PINCTRL_PIN(92, "GP_SSP_2_CLK"),
164 PINCTRL_PIN(93, "PCIE_CLKREQ2B"),
165 PINCTRL_PIN(94, "GP_SSP_2_RXD"),
166 PINCTRL_PIN(95, "PCIE_CLKREQ3B"),
167 PINCTRL_PIN(96, "GP_SSP_2_FS"),
168 PINCTRL_PIN(97, "GP_SSP_2_TXD"),
169};
170
Mika Westerberg6e08d6b2014-11-03 13:01:33 +0200171static const unsigned southwest_uart0_pins[] = { 16, 20 };
172static const unsigned southwest_uart1_pins[] = { 15, 16, 18, 20 };
173static const unsigned southwest_uart2_pins[] = { 17, 19, 21, 22 };
174static const unsigned southwest_i2c0_pins[] = { 61, 65 };
175static const unsigned southwest_hda_pins[] = { 30, 31, 32, 33, 34, 35, 36, 37 };
176static const unsigned southwest_lpe_pins[] = {
177 30, 31, 32, 33, 34, 35, 36, 37, 92, 94, 96, 97,
178};
179static const unsigned southwest_i2c1_pins[] = { 60, 63 };
180static const unsigned southwest_i2c2_pins[] = { 62, 66 };
181static const unsigned southwest_i2c3_pins[] = { 64, 67 };
182static const unsigned southwest_i2c4_pins[] = { 46, 50 };
183static const unsigned southwest_i2c5_pins[] = { 45, 48 };
184static const unsigned southwest_i2c6_pins[] = { 47, 51 };
185static const unsigned southwest_i2c_nfc_pins[] = { 49, 52 };
Mika Westerberg6e08d6b2014-11-03 13:01:33 +0200186static const unsigned southwest_spi3_pins[] = { 76, 79, 80, 81, 82 };
187
Andy Shevchenko36ad7b22020-04-01 20:35:01 +0300188/* Some of LPE I2S TXD pins need to have OE inversion set */
189static const unsigned int southwest_lpe_altfuncs[] = {
190 PINMODE(1, 1), PINMODE(1, 0), PINMODE(1, 0), PINMODE(1, 0), /* 30, 31, 32, 33 */
191 PINMODE(1, 1), PINMODE(1, 0), PINMODE(1, 0), PINMODE(1, 0), /* 34, 35, 36, 37 */
192 PINMODE(1, 0), PINMODE(1, 0), PINMODE(1, 0), PINMODE(1, 1), /* 92, 94, 96, 97 */
Mika Westerberg6e08d6b2014-11-03 13:01:33 +0200193};
194
195/*
196 * Two spi3 chipselects are available in different mode than the main spi3
Andy Shevchenko36ad7b22020-04-01 20:35:01 +0300197 * functionality, which is using mode 2.
Mika Westerberg6e08d6b2014-11-03 13:01:33 +0200198 */
Andy Shevchenko36ad7b22020-04-01 20:35:01 +0300199static const unsigned int southwest_spi3_altfuncs[] = {
200 PINMODE(3, 0), PINMODE(2, 0), PINMODE(3, 0), PINMODE(2, 0), /* 76, 79, 80, 81 */
201 PINMODE(2, 0), /* 82 */
Mika Westerberg6e08d6b2014-11-03 13:01:33 +0200202};
203
Andy Shevchenko36ad7b22020-04-01 20:35:01 +0300204static const struct intel_pingroup southwest_groups[] = {
205 PIN_GROUP("uart0_grp", southwest_uart0_pins, PINMODE(2, 0)),
206 PIN_GROUP("uart1_grp", southwest_uart1_pins, PINMODE(1, 0)),
207 PIN_GROUP("uart2_grp", southwest_uart2_pins, PINMODE(1, 0)),
208 PIN_GROUP("hda_grp", southwest_hda_pins, PINMODE(2, 0)),
209 PIN_GROUP("i2c0_grp", southwest_i2c0_pins, PINMODE(1, 1)),
210 PIN_GROUP("i2c1_grp", southwest_i2c1_pins, PINMODE(1, 1)),
211 PIN_GROUP("i2c2_grp", southwest_i2c2_pins, PINMODE(1, 1)),
212 PIN_GROUP("i2c3_grp", southwest_i2c3_pins, PINMODE(1, 1)),
213 PIN_GROUP("i2c4_grp", southwest_i2c4_pins, PINMODE(1, 1)),
214 PIN_GROUP("i2c5_grp", southwest_i2c5_pins, PINMODE(1, 1)),
215 PIN_GROUP("i2c6_grp", southwest_i2c6_pins, PINMODE(1, 1)),
216 PIN_GROUP("i2c_nfc_grp", southwest_i2c_nfc_pins, PINMODE(2, 1)),
217 PIN_GROUP("lpe_grp", southwest_lpe_pins, southwest_lpe_altfuncs),
218 PIN_GROUP("spi3_grp", southwest_spi3_pins, southwest_spi3_altfuncs),
Mika Westerberg6e08d6b2014-11-03 13:01:33 +0200219};
220
221static const char * const southwest_uart0_groups[] = { "uart0_grp" };
222static const char * const southwest_uart1_groups[] = { "uart1_grp" };
223static const char * const southwest_uart2_groups[] = { "uart2_grp" };
224static const char * const southwest_hda_groups[] = { "hda_grp" };
225static const char * const southwest_lpe_groups[] = { "lpe_grp" };
226static const char * const southwest_i2c0_groups[] = { "i2c0_grp" };
227static const char * const southwest_i2c1_groups[] = { "i2c1_grp" };
228static const char * const southwest_i2c2_groups[] = { "i2c2_grp" };
229static const char * const southwest_i2c3_groups[] = { "i2c3_grp" };
230static const char * const southwest_i2c4_groups[] = { "i2c4_grp" };
231static const char * const southwest_i2c5_groups[] = { "i2c5_grp" };
232static const char * const southwest_i2c6_groups[] = { "i2c6_grp" };
233static const char * const southwest_i2c_nfc_groups[] = { "i2c_nfc_grp" };
234static const char * const southwest_spi3_groups[] = { "spi3_grp" };
235
236/*
237 * Only do pinmuxing for certain LPSS devices for now. Rest of the pins are
238 * enabled only as GPIOs.
239 */
Andy Shevchenko5458b7c2018-09-04 14:26:21 +0300240static const struct intel_function southwest_functions[] = {
Mika Westerberg6e08d6b2014-11-03 13:01:33 +0200241 FUNCTION("uart0", southwest_uart0_groups),
242 FUNCTION("uart1", southwest_uart1_groups),
243 FUNCTION("uart2", southwest_uart2_groups),
244 FUNCTION("hda", southwest_hda_groups),
245 FUNCTION("lpe", southwest_lpe_groups),
246 FUNCTION("i2c0", southwest_i2c0_groups),
247 FUNCTION("i2c1", southwest_i2c1_groups),
248 FUNCTION("i2c2", southwest_i2c2_groups),
249 FUNCTION("i2c3", southwest_i2c3_groups),
250 FUNCTION("i2c4", southwest_i2c4_groups),
251 FUNCTION("i2c5", southwest_i2c5_groups),
252 FUNCTION("i2c6", southwest_i2c6_groups),
253 FUNCTION("i2c_nfc", southwest_i2c_nfc_groups),
254 FUNCTION("spi3", southwest_spi3_groups),
255};
256
Andy Shevchenko36ad7b22020-04-01 20:35:01 +0300257static const struct intel_padgroup southwest_gpps[] = {
258 CHV_GPP(0, 7),
259 CHV_GPP(15, 22),
260 CHV_GPP(30, 37),
261 CHV_GPP(45, 52),
262 CHV_GPP(60, 67),
263 CHV_GPP(75, 82),
264 CHV_GPP(90, 97),
Mika Westerberg6e08d6b2014-11-03 13:01:33 +0200265};
266
Andy Shevchenko293428f2020-06-09 21:24:49 +0300267/*
268 * Southwest community can generate GPIO interrupts only for the first 8
269 * interrupts. The upper half (8-15) can only be used to trigger GPEs.
270 */
271static const struct intel_community southwest_communities[] = {
272 CHV_COMMUNITY(southwest_gpps, 8, 0x91),
273};
274
275static const struct intel_pinctrl_soc_data southwest_soc_data = {
Mika Westerberg6e08d6b2014-11-03 13:01:33 +0200276 .uid = "1",
277 .pins = southwest_pins,
278 .npins = ARRAY_SIZE(southwest_pins),
279 .groups = southwest_groups,
280 .ngroups = ARRAY_SIZE(southwest_groups),
281 .functions = southwest_functions,
282 .nfunctions = ARRAY_SIZE(southwest_functions),
Andy Shevchenko293428f2020-06-09 21:24:49 +0300283 .communities = southwest_communities,
284 .ncommunities = ARRAY_SIZE(southwest_communities),
Mika Westerberg6e08d6b2014-11-03 13:01:33 +0200285};
286
287static const struct pinctrl_pin_desc north_pins[] = {
288 PINCTRL_PIN(0, "GPIO_DFX_0"),
289 PINCTRL_PIN(1, "GPIO_DFX_3"),
290 PINCTRL_PIN(2, "GPIO_DFX_7"),
291 PINCTRL_PIN(3, "GPIO_DFX_1"),
292 PINCTRL_PIN(4, "GPIO_DFX_5"),
293 PINCTRL_PIN(5, "GPIO_DFX_4"),
294 PINCTRL_PIN(6, "GPIO_DFX_8"),
295 PINCTRL_PIN(7, "GPIO_DFX_2"),
296 PINCTRL_PIN(8, "GPIO_DFX_6"),
297
298 PINCTRL_PIN(15, "GPIO_SUS0"),
299 PINCTRL_PIN(16, "SEC_GPIO_SUS10"),
300 PINCTRL_PIN(17, "GPIO_SUS3"),
301 PINCTRL_PIN(18, "GPIO_SUS7"),
302 PINCTRL_PIN(19, "GPIO_SUS1"),
303 PINCTRL_PIN(20, "GPIO_SUS5"),
304 PINCTRL_PIN(21, "SEC_GPIO_SUS11"),
305 PINCTRL_PIN(22, "GPIO_SUS4"),
306 PINCTRL_PIN(23, "SEC_GPIO_SUS8"),
307 PINCTRL_PIN(24, "GPIO_SUS2"),
308 PINCTRL_PIN(25, "GPIO_SUS6"),
309 PINCTRL_PIN(26, "CX_PREQ_B"),
310 PINCTRL_PIN(27, "SEC_GPIO_SUS9"),
311
312 PINCTRL_PIN(30, "TRST_B"),
313 PINCTRL_PIN(31, "TCK"),
314 PINCTRL_PIN(32, "PROCHOT_B"),
315 PINCTRL_PIN(33, "SVIDO_DATA"),
316 PINCTRL_PIN(34, "TMS"),
317 PINCTRL_PIN(35, "CX_PRDY_B_2"),
318 PINCTRL_PIN(36, "TDO_2"),
319 PINCTRL_PIN(37, "CX_PRDY_B"),
320 PINCTRL_PIN(38, "SVIDO_ALERT_B"),
321 PINCTRL_PIN(39, "TDO"),
322 PINCTRL_PIN(40, "SVIDO_CLK"),
323 PINCTRL_PIN(41, "TDI"),
324
325 PINCTRL_PIN(45, "GP_CAMERASB_05"),
326 PINCTRL_PIN(46, "GP_CAMERASB_02"),
327 PINCTRL_PIN(47, "GP_CAMERASB_08"),
328 PINCTRL_PIN(48, "GP_CAMERASB_00"),
329 PINCTRL_PIN(49, "GP_CAMERASB_06"),
330 PINCTRL_PIN(50, "GP_CAMERASB_10"),
331 PINCTRL_PIN(51, "GP_CAMERASB_03"),
332 PINCTRL_PIN(52, "GP_CAMERASB_09"),
333 PINCTRL_PIN(53, "GP_CAMERASB_01"),
334 PINCTRL_PIN(54, "GP_CAMERASB_07"),
335 PINCTRL_PIN(55, "GP_CAMERASB_11"),
336 PINCTRL_PIN(56, "GP_CAMERASB_04"),
337
338 PINCTRL_PIN(60, "PANEL0_BKLTEN"),
339 PINCTRL_PIN(61, "HV_DDI0_HPD"),
340 PINCTRL_PIN(62, "HV_DDI2_DDC_SDA"),
341 PINCTRL_PIN(63, "PANEL1_BKLTCTL"),
342 PINCTRL_PIN(64, "HV_DDI1_HPD"),
343 PINCTRL_PIN(65, "PANEL0_BKLTCTL"),
344 PINCTRL_PIN(66, "HV_DDI0_DDC_SDA"),
345 PINCTRL_PIN(67, "HV_DDI2_DDC_SCL"),
346 PINCTRL_PIN(68, "HV_DDI2_HPD"),
347 PINCTRL_PIN(69, "PANEL1_VDDEN"),
348 PINCTRL_PIN(70, "PANEL1_BKLTEN"),
349 PINCTRL_PIN(71, "HV_DDI0_DDC_SCL"),
350 PINCTRL_PIN(72, "PANEL0_VDDEN"),
351};
352
Andy Shevchenko36ad7b22020-04-01 20:35:01 +0300353static const struct intel_padgroup north_gpps[] = {
354 CHV_GPP(0, 8),
355 CHV_GPP(15, 27),
356 CHV_GPP(30, 41),
357 CHV_GPP(45, 56),
358 CHV_GPP(60, 72),
Mika Westerberg6e08d6b2014-11-03 13:01:33 +0200359};
360
Andy Shevchenko293428f2020-06-09 21:24:49 +0300361/*
362 * North community can generate GPIO interrupts only for the first 8
363 * interrupts. The upper half (8-15) can only be used to trigger GPEs.
364 */
365static const struct intel_community north_communities[] = {
366 CHV_COMMUNITY(north_gpps, 8, 0x92),
367};
368
369static const struct intel_pinctrl_soc_data north_soc_data = {
Mika Westerberg6e08d6b2014-11-03 13:01:33 +0200370 .uid = "2",
371 .pins = north_pins,
372 .npins = ARRAY_SIZE(north_pins),
Andy Shevchenko293428f2020-06-09 21:24:49 +0300373 .communities = north_communities,
374 .ncommunities = ARRAY_SIZE(north_communities),
Mika Westerberg6e08d6b2014-11-03 13:01:33 +0200375};
376
377static const struct pinctrl_pin_desc east_pins[] = {
378 PINCTRL_PIN(0, "PMU_SLP_S3_B"),
379 PINCTRL_PIN(1, "PMU_BATLOW_B"),
380 PINCTRL_PIN(2, "SUS_STAT_B"),
381 PINCTRL_PIN(3, "PMU_SLP_S0IX_B"),
382 PINCTRL_PIN(4, "PMU_AC_PRESENT"),
383 PINCTRL_PIN(5, "PMU_PLTRST_B"),
384 PINCTRL_PIN(6, "PMU_SUSCLK"),
385 PINCTRL_PIN(7, "PMU_SLP_LAN_B"),
386 PINCTRL_PIN(8, "PMU_PWRBTN_B"),
387 PINCTRL_PIN(9, "PMU_SLP_S4_B"),
388 PINCTRL_PIN(10, "PMU_WAKE_B"),
389 PINCTRL_PIN(11, "PMU_WAKE_LAN_B"),
390
391 PINCTRL_PIN(15, "MF_ISH_GPIO_3"),
392 PINCTRL_PIN(16, "MF_ISH_GPIO_7"),
393 PINCTRL_PIN(17, "MF_ISH_I2C1_SCL"),
394 PINCTRL_PIN(18, "MF_ISH_GPIO_1"),
395 PINCTRL_PIN(19, "MF_ISH_GPIO_5"),
396 PINCTRL_PIN(20, "MF_ISH_GPIO_9"),
397 PINCTRL_PIN(21, "MF_ISH_GPIO_0"),
398 PINCTRL_PIN(22, "MF_ISH_GPIO_4"),
399 PINCTRL_PIN(23, "MF_ISH_GPIO_8"),
400 PINCTRL_PIN(24, "MF_ISH_GPIO_2"),
401 PINCTRL_PIN(25, "MF_ISH_GPIO_6"),
402 PINCTRL_PIN(26, "MF_ISH_I2C1_SDA"),
403};
404
Andy Shevchenko36ad7b22020-04-01 20:35:01 +0300405static const struct intel_padgroup east_gpps[] = {
406 CHV_GPP(0, 11),
407 CHV_GPP(15, 26),
Mika Westerberg6e08d6b2014-11-03 13:01:33 +0200408};
409
Andy Shevchenko293428f2020-06-09 21:24:49 +0300410static const struct intel_community east_communities[] = {
411 CHV_COMMUNITY(east_gpps, 16, 0x93),
412};
413
414static const struct intel_pinctrl_soc_data east_soc_data = {
Mika Westerberg6e08d6b2014-11-03 13:01:33 +0200415 .uid = "3",
416 .pins = east_pins,
417 .npins = ARRAY_SIZE(east_pins),
Andy Shevchenko293428f2020-06-09 21:24:49 +0300418 .communities = east_communities,
419 .ncommunities = ARRAY_SIZE(east_communities),
Mika Westerberg6e08d6b2014-11-03 13:01:33 +0200420};
421
422static const struct pinctrl_pin_desc southeast_pins[] = {
423 PINCTRL_PIN(0, "MF_PLT_CLK0"),
424 PINCTRL_PIN(1, "PWM1"),
425 PINCTRL_PIN(2, "MF_PLT_CLK1"),
426 PINCTRL_PIN(3, "MF_PLT_CLK4"),
427 PINCTRL_PIN(4, "MF_PLT_CLK3"),
428 PINCTRL_PIN(5, "PWM0"),
429 PINCTRL_PIN(6, "MF_PLT_CLK5"),
430 PINCTRL_PIN(7, "MF_PLT_CLK2"),
431
432 PINCTRL_PIN(15, "SDMMC2_D3_CD_B"),
433 PINCTRL_PIN(16, "SDMMC1_CLK"),
434 PINCTRL_PIN(17, "SDMMC1_D0"),
435 PINCTRL_PIN(18, "SDMMC2_D1"),
436 PINCTRL_PIN(19, "SDMMC2_CLK"),
437 PINCTRL_PIN(20, "SDMMC1_D2"),
438 PINCTRL_PIN(21, "SDMMC2_D2"),
439 PINCTRL_PIN(22, "SDMMC2_CMD"),
440 PINCTRL_PIN(23, "SDMMC1_CMD"),
441 PINCTRL_PIN(24, "SDMMC1_D1"),
442 PINCTRL_PIN(25, "SDMMC2_D0"),
443 PINCTRL_PIN(26, "SDMMC1_D3_CD_B"),
444
445 PINCTRL_PIN(30, "SDMMC3_D1"),
446 PINCTRL_PIN(31, "SDMMC3_CLK"),
447 PINCTRL_PIN(32, "SDMMC3_D3"),
448 PINCTRL_PIN(33, "SDMMC3_D2"),
449 PINCTRL_PIN(34, "SDMMC3_CMD"),
450 PINCTRL_PIN(35, "SDMMC3_D0"),
451
452 PINCTRL_PIN(45, "MF_LPC_AD2"),
453 PINCTRL_PIN(46, "LPC_CLKRUNB"),
454 PINCTRL_PIN(47, "MF_LPC_AD0"),
455 PINCTRL_PIN(48, "LPC_FRAMEB"),
456 PINCTRL_PIN(49, "MF_LPC_CLKOUT1"),
457 PINCTRL_PIN(50, "MF_LPC_AD3"),
458 PINCTRL_PIN(51, "MF_LPC_CLKOUT0"),
459 PINCTRL_PIN(52, "MF_LPC_AD1"),
460
461 PINCTRL_PIN(60, "SPI1_MISO"),
462 PINCTRL_PIN(61, "SPI1_CSO_B"),
463 PINCTRL_PIN(62, "SPI1_CLK"),
464 PINCTRL_PIN(63, "MMC1_D6"),
465 PINCTRL_PIN(64, "SPI1_MOSI"),
466 PINCTRL_PIN(65, "MMC1_D5"),
467 PINCTRL_PIN(66, "SPI1_CS1_B"),
468 PINCTRL_PIN(67, "MMC1_D4_SD_WE"),
469 PINCTRL_PIN(68, "MMC1_D7"),
470 PINCTRL_PIN(69, "MMC1_RCLK"),
471
472 PINCTRL_PIN(75, "USB_OC1_B"),
473 PINCTRL_PIN(76, "PMU_RESETBUTTON_B"),
474 PINCTRL_PIN(77, "GPIO_ALERT"),
475 PINCTRL_PIN(78, "SDMMC3_PWR_EN_B"),
476 PINCTRL_PIN(79, "ILB_SERIRQ"),
477 PINCTRL_PIN(80, "USB_OC0_B"),
478 PINCTRL_PIN(81, "SDMMC3_CD_B"),
479 PINCTRL_PIN(82, "SPKR"),
480 PINCTRL_PIN(83, "SUSPWRDNACK"),
481 PINCTRL_PIN(84, "SPARE_PIN"),
482 PINCTRL_PIN(85, "SDMMC3_1P8_EN"),
483};
484
485static const unsigned southeast_pwm0_pins[] = { 5 };
486static const unsigned southeast_pwm1_pins[] = { 1 };
487static const unsigned southeast_sdmmc1_pins[] = {
488 16, 17, 20, 23, 24, 26, 63, 65, 67, 68, 69,
489};
490static const unsigned southeast_sdmmc2_pins[] = { 15, 18, 19, 21, 22, 25 };
491static const unsigned southeast_sdmmc3_pins[] = {
492 30, 31, 32, 33, 34, 35, 78, 81, 85,
493};
494static const unsigned southeast_spi1_pins[] = { 60, 61, 62, 64, 66 };
495static const unsigned southeast_spi2_pins[] = { 2, 3, 4, 6, 7 };
496
Andy Shevchenko36ad7b22020-04-01 20:35:01 +0300497static const struct intel_pingroup southeast_groups[] = {
498 PIN_GROUP("pwm0_grp", southeast_pwm0_pins, PINMODE(1, 0)),
499 PIN_GROUP("pwm1_grp", southeast_pwm1_pins, PINMODE(1, 0)),
500 PIN_GROUP("sdmmc1_grp", southeast_sdmmc1_pins, PINMODE(1, 0)),
501 PIN_GROUP("sdmmc2_grp", southeast_sdmmc2_pins, PINMODE(1, 0)),
502 PIN_GROUP("sdmmc3_grp", southeast_sdmmc3_pins, PINMODE(1, 0)),
503 PIN_GROUP("spi1_grp", southeast_spi1_pins, PINMODE(1, 0)),
504 PIN_GROUP("spi2_grp", southeast_spi2_pins, PINMODE(4, 0)),
Mika Westerberg6e08d6b2014-11-03 13:01:33 +0200505};
506
507static const char * const southeast_pwm0_groups[] = { "pwm0_grp" };
508static const char * const southeast_pwm1_groups[] = { "pwm1_grp" };
509static const char * const southeast_sdmmc1_groups[] = { "sdmmc1_grp" };
510static const char * const southeast_sdmmc2_groups[] = { "sdmmc2_grp" };
511static const char * const southeast_sdmmc3_groups[] = { "sdmmc3_grp" };
512static const char * const southeast_spi1_groups[] = { "spi1_grp" };
513static const char * const southeast_spi2_groups[] = { "spi2_grp" };
514
Andy Shevchenko5458b7c2018-09-04 14:26:21 +0300515static const struct intel_function southeast_functions[] = {
Mika Westerberg6e08d6b2014-11-03 13:01:33 +0200516 FUNCTION("pwm0", southeast_pwm0_groups),
517 FUNCTION("pwm1", southeast_pwm1_groups),
518 FUNCTION("sdmmc1", southeast_sdmmc1_groups),
519 FUNCTION("sdmmc2", southeast_sdmmc2_groups),
520 FUNCTION("sdmmc3", southeast_sdmmc3_groups),
521 FUNCTION("spi1", southeast_spi1_groups),
522 FUNCTION("spi2", southeast_spi2_groups),
523};
524
Andy Shevchenko36ad7b22020-04-01 20:35:01 +0300525static const struct intel_padgroup southeast_gpps[] = {
526 CHV_GPP(0, 7),
527 CHV_GPP(15, 26),
528 CHV_GPP(30, 35),
529 CHV_GPP(45, 52),
530 CHV_GPP(60, 69),
531 CHV_GPP(75, 85),
Mika Westerberg6e08d6b2014-11-03 13:01:33 +0200532};
533
Andy Shevchenko293428f2020-06-09 21:24:49 +0300534static const struct intel_community southeast_communities[] = {
535 CHV_COMMUNITY(southeast_gpps, 16, 0x94),
536};
537
538static const struct intel_pinctrl_soc_data southeast_soc_data = {
Mika Westerberg6e08d6b2014-11-03 13:01:33 +0200539 .uid = "4",
540 .pins = southeast_pins,
541 .npins = ARRAY_SIZE(southeast_pins),
542 .groups = southeast_groups,
543 .ngroups = ARRAY_SIZE(southeast_groups),
544 .functions = southeast_functions,
545 .nfunctions = ARRAY_SIZE(southeast_functions),
Andy Shevchenko293428f2020-06-09 21:24:49 +0300546 .communities = southeast_communities,
547 .ncommunities = ARRAY_SIZE(southeast_communities),
Mika Westerberg6e08d6b2014-11-03 13:01:33 +0200548};
549
Andy Shevchenko293428f2020-06-09 21:24:49 +0300550static const struct intel_pinctrl_soc_data *chv_soc_data[] = {
551 &southwest_soc_data,
552 &north_soc_data,
553 &east_soc_data,
554 &southeast_soc_data,
555 NULL
Mika Westerberg6e08d6b2014-11-03 13:01:33 +0200556};
557
Dan O'Donovan0bd50d7192016-06-10 13:23:34 +0100558/*
559 * Lock to serialize register accesses
560 *
561 * Due to a silicon issue, a shared lock must be used to prevent
562 * concurrent accesses across the 4 GPIO controllers.
563 *
564 * See Intel Atom Z8000 Processor Series Specification Update (Rev. 005),
565 * errata #CHT34, for further information.
566 */
567static DEFINE_RAW_SPINLOCK(chv_lock);
568
Andy Shevchenko3ea2e2c2020-07-27 19:12:16 +0300569static u32 chv_pctrl_readl(struct intel_pinctrl *pctrl, unsigned int offset)
Andy Shevchenko99fd6512020-06-09 21:24:45 +0300570{
Andy Shevchenko293428f2020-06-09 21:24:49 +0300571 const struct intel_community *community = &pctrl->communities[0];
572
573 return readl(community->regs + offset);
Andy Shevchenko99fd6512020-06-09 21:24:45 +0300574}
575
Andy Shevchenko3ea2e2c2020-07-27 19:12:16 +0300576static void chv_pctrl_writel(struct intel_pinctrl *pctrl, unsigned int offset, u32 value)
Andy Shevchenko99fd6512020-06-09 21:24:45 +0300577{
Andy Shevchenko293428f2020-06-09 21:24:49 +0300578 const struct intel_community *community = &pctrl->communities[0];
579 void __iomem *reg = community->regs + offset;
Andy Shevchenko99fd6512020-06-09 21:24:45 +0300580
581 /* Write and simple read back to confirm the bus transferring done */
582 writel(value, reg);
583 readl(reg);
584}
585
Andy Shevchenko3ea2e2c2020-07-27 19:12:16 +0300586static void __iomem *chv_padreg(struct intel_pinctrl *pctrl, unsigned int offset,
Andy Shevchenko4e737af2018-09-26 17:50:28 +0300587 unsigned int reg)
Mika Westerberg6e08d6b2014-11-03 13:01:33 +0200588{
Andy Shevchenko293428f2020-06-09 21:24:49 +0300589 const struct intel_community *community = &pctrl->communities[0];
Andy Shevchenko4e737af2018-09-26 17:50:28 +0300590 unsigned int family_no = offset / MAX_FAMILY_PAD_GPIO_NO;
591 unsigned int pad_no = offset % MAX_FAMILY_PAD_GPIO_NO;
Mika Westerberg6e08d6b2014-11-03 13:01:33 +0200592
Andy Shevchenko293428f2020-06-09 21:24:49 +0300593 offset = FAMILY_PAD_REGS_SIZE * family_no + GPIO_REGS_SIZE * pad_no;
Mika Westerberg6e08d6b2014-11-03 13:01:33 +0200594
Andy Shevchenko293428f2020-06-09 21:24:49 +0300595 return community->pad_regs + offset + reg;
Mika Westerberg6e08d6b2014-11-03 13:01:33 +0200596}
597
Andy Shevchenko3ea2e2c2020-07-27 19:12:16 +0300598static u32 chv_readl(struct intel_pinctrl *pctrl, unsigned int pin, unsigned int offset)
Andy Shevchenko4e7293e2020-06-09 21:24:44 +0300599{
600 return readl(chv_padreg(pctrl, pin, offset));
601}
602
Andy Shevchenko3ea2e2c2020-07-27 19:12:16 +0300603static void chv_writel(struct intel_pinctrl *pctrl, unsigned int pin, unsigned int offset, u32 value)
Mika Westerberg6e08d6b2014-11-03 13:01:33 +0200604{
Andy Shevchenkobfc8a4b2020-06-09 21:24:46 +0300605 void __iomem *reg = chv_padreg(pctrl, pin, offset);
606
607 /* Write and simple read back to confirm the bus transferring done */
Mika Westerberg6e08d6b2014-11-03 13:01:33 +0200608 writel(value, reg);
Mika Westerberg6e08d6b2014-11-03 13:01:33 +0200609 readl(reg);
610}
611
612/* When Pad Cfg is locked, driver can only change GPIOTXState or GPIORXState */
Andy Shevchenko3ea2e2c2020-07-27 19:12:16 +0300613static bool chv_pad_locked(struct intel_pinctrl *pctrl, unsigned int offset)
Mika Westerberg6e08d6b2014-11-03 13:01:33 +0200614{
Andy Shevchenko4e7293e2020-06-09 21:24:44 +0300615 return chv_readl(pctrl, offset, CHV_PADCTRL1) & CHV_PADCTRL1_CFGLOCK;
Mika Westerberg6e08d6b2014-11-03 13:01:33 +0200616}
617
618static int chv_get_groups_count(struct pinctrl_dev *pctldev)
619{
Andy Shevchenko3ea2e2c2020-07-27 19:12:16 +0300620 struct intel_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev);
Mika Westerberg6e08d6b2014-11-03 13:01:33 +0200621
Andy Shevchenko293428f2020-06-09 21:24:49 +0300622 return pctrl->soc->ngroups;
Mika Westerberg6e08d6b2014-11-03 13:01:33 +0200623}
624
625static const char *chv_get_group_name(struct pinctrl_dev *pctldev,
Andy Shevchenko4e737af2018-09-26 17:50:28 +0300626 unsigned int group)
Mika Westerberg6e08d6b2014-11-03 13:01:33 +0200627{
Andy Shevchenko3ea2e2c2020-07-27 19:12:16 +0300628 struct intel_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev);
Mika Westerberg6e08d6b2014-11-03 13:01:33 +0200629
Andy Shevchenko293428f2020-06-09 21:24:49 +0300630 return pctrl->soc->groups[group].name;
Mika Westerberg6e08d6b2014-11-03 13:01:33 +0200631}
632
Andy Shevchenko4e737af2018-09-26 17:50:28 +0300633static int chv_get_group_pins(struct pinctrl_dev *pctldev, unsigned int group,
634 const unsigned int **pins, unsigned int *npins)
Mika Westerberg6e08d6b2014-11-03 13:01:33 +0200635{
Andy Shevchenko3ea2e2c2020-07-27 19:12:16 +0300636 struct intel_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev);
Mika Westerberg6e08d6b2014-11-03 13:01:33 +0200637
Andy Shevchenko293428f2020-06-09 21:24:49 +0300638 *pins = pctrl->soc->groups[group].pins;
639 *npins = pctrl->soc->groups[group].npins;
Mika Westerberg6e08d6b2014-11-03 13:01:33 +0200640 return 0;
641}
642
643static void chv_pin_dbg_show(struct pinctrl_dev *pctldev, struct seq_file *s,
Andy Shevchenko4e737af2018-09-26 17:50:28 +0300644 unsigned int offset)
Mika Westerberg6e08d6b2014-11-03 13:01:33 +0200645{
Andy Shevchenko3ea2e2c2020-07-27 19:12:16 +0300646 struct intel_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev);
Mika Westerberg6e08d6b2014-11-03 13:01:33 +0200647 unsigned long flags;
648 u32 ctrl0, ctrl1;
649 bool locked;
650
Dan O'Donovan0bd50d7192016-06-10 13:23:34 +0100651 raw_spin_lock_irqsave(&chv_lock, flags);
Mika Westerberg6e08d6b2014-11-03 13:01:33 +0200652
Andy Shevchenko4e7293e2020-06-09 21:24:44 +0300653 ctrl0 = chv_readl(pctrl, offset, CHV_PADCTRL0);
654 ctrl1 = chv_readl(pctrl, offset, CHV_PADCTRL1);
Mika Westerberg6e08d6b2014-11-03 13:01:33 +0200655 locked = chv_pad_locked(pctrl, offset);
656
Dan O'Donovan0bd50d7192016-06-10 13:23:34 +0100657 raw_spin_unlock_irqrestore(&chv_lock, flags);
Mika Westerberg6e08d6b2014-11-03 13:01:33 +0200658
659 if (ctrl0 & CHV_PADCTRL0_GPIOEN) {
660 seq_puts(s, "GPIO ");
661 } else {
662 u32 mode;
663
664 mode = ctrl0 & CHV_PADCTRL0_PMODE_MASK;
665 mode >>= CHV_PADCTRL0_PMODE_SHIFT;
666
667 seq_printf(s, "mode %d ", mode);
668 }
669
Mika Westerberg684373e2016-10-31 16:57:34 +0200670 seq_printf(s, "0x%08x 0x%08x", ctrl0, ctrl1);
Mika Westerberg6e08d6b2014-11-03 13:01:33 +0200671
672 if (locked)
673 seq_puts(s, " [LOCKED]");
674}
675
676static const struct pinctrl_ops chv_pinctrl_ops = {
677 .get_groups_count = chv_get_groups_count,
678 .get_group_name = chv_get_group_name,
679 .get_group_pins = chv_get_group_pins,
680 .pin_dbg_show = chv_pin_dbg_show,
681};
682
683static int chv_get_functions_count(struct pinctrl_dev *pctldev)
684{
Andy Shevchenko3ea2e2c2020-07-27 19:12:16 +0300685 struct intel_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev);
Mika Westerberg6e08d6b2014-11-03 13:01:33 +0200686
Andy Shevchenko293428f2020-06-09 21:24:49 +0300687 return pctrl->soc->nfunctions;
Mika Westerberg6e08d6b2014-11-03 13:01:33 +0200688}
689
690static const char *chv_get_function_name(struct pinctrl_dev *pctldev,
Andy Shevchenko4e737af2018-09-26 17:50:28 +0300691 unsigned int function)
Mika Westerberg6e08d6b2014-11-03 13:01:33 +0200692{
Andy Shevchenko3ea2e2c2020-07-27 19:12:16 +0300693 struct intel_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev);
Mika Westerberg6e08d6b2014-11-03 13:01:33 +0200694
Andy Shevchenko293428f2020-06-09 21:24:49 +0300695 return pctrl->soc->functions[function].name;
Mika Westerberg6e08d6b2014-11-03 13:01:33 +0200696}
697
698static int chv_get_function_groups(struct pinctrl_dev *pctldev,
Andy Shevchenko4e737af2018-09-26 17:50:28 +0300699 unsigned int function,
Mika Westerberg6e08d6b2014-11-03 13:01:33 +0200700 const char * const **groups,
Andy Shevchenko4e737af2018-09-26 17:50:28 +0300701 unsigned int * const ngroups)
Mika Westerberg6e08d6b2014-11-03 13:01:33 +0200702{
Andy Shevchenko3ea2e2c2020-07-27 19:12:16 +0300703 struct intel_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev);
Mika Westerberg6e08d6b2014-11-03 13:01:33 +0200704
Andy Shevchenko293428f2020-06-09 21:24:49 +0300705 *groups = pctrl->soc->functions[function].groups;
706 *ngroups = pctrl->soc->functions[function].ngroups;
Mika Westerberg6e08d6b2014-11-03 13:01:33 +0200707 return 0;
708}
709
Andy Shevchenko4e737af2018-09-26 17:50:28 +0300710static int chv_pinmux_set_mux(struct pinctrl_dev *pctldev,
711 unsigned int function, unsigned int group)
Mika Westerberg6e08d6b2014-11-03 13:01:33 +0200712{
Andy Shevchenko3ea2e2c2020-07-27 19:12:16 +0300713 struct intel_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev);
Andy Shevchenko36ad7b22020-04-01 20:35:01 +0300714 const struct intel_pingroup *grp;
Mika Westerberg6e08d6b2014-11-03 13:01:33 +0200715 unsigned long flags;
716 int i;
717
Andy Shevchenko293428f2020-06-09 21:24:49 +0300718 grp = &pctrl->soc->groups[group];
Mika Westerberg6e08d6b2014-11-03 13:01:33 +0200719
Dan O'Donovan0bd50d7192016-06-10 13:23:34 +0100720 raw_spin_lock_irqsave(&chv_lock, flags);
Mika Westerberg6e08d6b2014-11-03 13:01:33 +0200721
722 /* Check first that the pad is not locked */
723 for (i = 0; i < grp->npins; i++) {
724 if (chv_pad_locked(pctrl, grp->pins[i])) {
725 dev_warn(pctrl->dev, "unable to set mode for locked pin %u\n",
726 grp->pins[i]);
Dan O'Donovan0bd50d7192016-06-10 13:23:34 +0100727 raw_spin_unlock_irqrestore(&chv_lock, flags);
Mika Westerberg6e08d6b2014-11-03 13:01:33 +0200728 return -EBUSY;
729 }
730 }
731
732 for (i = 0; i < grp->npins; i++) {
Mika Westerberg6e08d6b2014-11-03 13:01:33 +0200733 int pin = grp->pins[i];
Andy Shevchenko36ad7b22020-04-01 20:35:01 +0300734 unsigned int mode;
735 bool invert_oe;
Mika Westerberg6e08d6b2014-11-03 13:01:33 +0200736 u32 value;
737
738 /* Check if there is pin-specific config */
Andy Shevchenko36ad7b22020-04-01 20:35:01 +0300739 if (grp->modes)
740 mode = grp->modes[i];
741 else
742 mode = grp->mode;
Mika Westerberg6e08d6b2014-11-03 13:01:33 +0200743
Andy Shevchenko36ad7b22020-04-01 20:35:01 +0300744 /* Extract OE inversion */
745 invert_oe = mode & PINMODE_INVERT_OE;
746 mode &= ~PINMODE_INVERT_OE;
Mika Westerberg6e08d6b2014-11-03 13:01:33 +0200747
Andy Shevchenko4e7293e2020-06-09 21:24:44 +0300748 value = chv_readl(pctrl, pin, CHV_PADCTRL0);
Mika Westerberg6e08d6b2014-11-03 13:01:33 +0200749 /* Disable GPIO mode */
750 value &= ~CHV_PADCTRL0_GPIOEN;
751 /* Set to desired mode */
752 value &= ~CHV_PADCTRL0_PMODE_MASK;
Andy Shevchenko36ad7b22020-04-01 20:35:01 +0300753 value |= mode << CHV_PADCTRL0_PMODE_SHIFT;
Andy Shevchenkobfc8a4b2020-06-09 21:24:46 +0300754 chv_writel(pctrl, pin, CHV_PADCTRL0, value);
Mika Westerberg6e08d6b2014-11-03 13:01:33 +0200755
756 /* Update for invert_oe */
Andy Shevchenko4e7293e2020-06-09 21:24:44 +0300757 value = chv_readl(pctrl, pin, CHV_PADCTRL1) & ~CHV_PADCTRL1_INVRXTX_MASK;
Andy Shevchenko36ad7b22020-04-01 20:35:01 +0300758 if (invert_oe)
Mika Westerberg6e08d6b2014-11-03 13:01:33 +0200759 value |= CHV_PADCTRL1_INVRXTX_TXENABLE;
Andy Shevchenkobfc8a4b2020-06-09 21:24:46 +0300760 chv_writel(pctrl, pin, CHV_PADCTRL1, value);
Mika Westerberg6e08d6b2014-11-03 13:01:33 +0200761
762 dev_dbg(pctrl->dev, "configured pin %u mode %u OE %sinverted\n",
Andy Shevchenko36ad7b22020-04-01 20:35:01 +0300763 pin, mode, invert_oe ? "" : "not ");
Mika Westerberg6e08d6b2014-11-03 13:01:33 +0200764 }
765
Dan O'Donovan0bd50d7192016-06-10 13:23:34 +0100766 raw_spin_unlock_irqrestore(&chv_lock, flags);
Mika Westerberg6e08d6b2014-11-03 13:01:33 +0200767
768 return 0;
769}
770
Andy Shevchenko3ea2e2c2020-07-27 19:12:16 +0300771static void chv_gpio_clear_triggering(struct intel_pinctrl *pctrl,
Hans de Goedeb6fb6e12018-12-04 20:42:46 +0100772 unsigned int offset)
773{
Hans de Goedea0bf06d2020-09-04 19:21:41 +0200774 u32 invrxtx_mask = CHV_PADCTRL1_INVRXTX_MASK;
Hans de Goedeb6fb6e12018-12-04 20:42:46 +0100775 u32 value;
776
Hans de Goedea0bf06d2020-09-04 19:21:41 +0200777 /*
778 * One some devices the GPIO should output the inverted value from what
779 * device-drivers / ACPI code expects (inverted external buffer?). The
780 * BIOS makes this work by setting the CHV_PADCTRL1_INVRXTX_TXDATA flag,
781 * preserve this flag if the pin is already setup as GPIO.
782 */
783 value = chv_readl(pctrl, offset, CHV_PADCTRL0);
784 if (value & CHV_PADCTRL0_GPIOEN)
785 invrxtx_mask &= ~CHV_PADCTRL1_INVRXTX_TXDATA;
786
Andy Shevchenko4e7293e2020-06-09 21:24:44 +0300787 value = chv_readl(pctrl, offset, CHV_PADCTRL1);
Hans de Goedeb6fb6e12018-12-04 20:42:46 +0100788 value &= ~CHV_PADCTRL1_INTWAKECFG_MASK;
Hans de Goedea0bf06d2020-09-04 19:21:41 +0200789 value &= ~invrxtx_mask;
Andy Shevchenkobfc8a4b2020-06-09 21:24:46 +0300790 chv_writel(pctrl, offset, CHV_PADCTRL1, value);
Hans de Goedeb6fb6e12018-12-04 20:42:46 +0100791}
792
Mika Westerberg6e08d6b2014-11-03 13:01:33 +0200793static int chv_gpio_request_enable(struct pinctrl_dev *pctldev,
794 struct pinctrl_gpio_range *range,
Andy Shevchenko4e737af2018-09-26 17:50:28 +0300795 unsigned int offset)
Mika Westerberg6e08d6b2014-11-03 13:01:33 +0200796{
Andy Shevchenko3ea2e2c2020-07-27 19:12:16 +0300797 struct intel_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev);
Mika Westerberg6e08d6b2014-11-03 13:01:33 +0200798 unsigned long flags;
Mika Westerberg6e08d6b2014-11-03 13:01:33 +0200799 u32 value;
800
Dan O'Donovan0bd50d7192016-06-10 13:23:34 +0100801 raw_spin_lock_irqsave(&chv_lock, flags);
Mika Westerberg6e08d6b2014-11-03 13:01:33 +0200802
803 if (chv_pad_locked(pctrl, offset)) {
Andy Shevchenko4e7293e2020-06-09 21:24:44 +0300804 value = chv_readl(pctrl, offset, CHV_PADCTRL0);
Mika Westerberg6e08d6b2014-11-03 13:01:33 +0200805 if (!(value & CHV_PADCTRL0_GPIOEN)) {
806 /* Locked so cannot enable */
Dan O'Donovan0bd50d7192016-06-10 13:23:34 +0100807 raw_spin_unlock_irqrestore(&chv_lock, flags);
Mika Westerberg6e08d6b2014-11-03 13:01:33 +0200808 return -EBUSY;
809 }
810 } else {
Andy Shevchenko8a828572020-07-27 19:12:15 +0300811 struct intel_community_context *cctx = &pctrl->context.communities[0];
Mika Westerberg6e08d6b2014-11-03 13:01:33 +0200812 int i;
813
814 /* Reset the interrupt mapping */
Andy Shevchenko8a828572020-07-27 19:12:15 +0300815 for (i = 0; i < ARRAY_SIZE(cctx->intr_lines); i++) {
816 if (cctx->intr_lines[i] == offset) {
Hans de Goedebdfbef22021-11-18 11:56:48 +0100817 cctx->intr_lines[i] = CHV_INVALID_HWIRQ;
Mika Westerberg6e08d6b2014-11-03 13:01:33 +0200818 break;
819 }
820 }
821
822 /* Disable interrupt generation */
Hans de Goedeb6fb6e12018-12-04 20:42:46 +0100823 chv_gpio_clear_triggering(pctrl, offset);
Mika Westerberg6e08d6b2014-11-03 13:01:33 +0200824
Andy Shevchenko4e7293e2020-06-09 21:24:44 +0300825 value = chv_readl(pctrl, offset, CHV_PADCTRL0);
Mika Westerberg2479c732015-01-29 12:44:48 +0200826
827 /*
828 * If the pin is in HiZ mode (both TX and RX buffers are
829 * disabled) we turn it to be input now.
830 */
831 if ((value & CHV_PADCTRL0_GPIOCFG_MASK) ==
832 (CHV_PADCTRL0_GPIOCFG_HIZ << CHV_PADCTRL0_GPIOCFG_SHIFT)) {
833 value &= ~CHV_PADCTRL0_GPIOCFG_MASK;
Andy Shevchenkobfc8a4b2020-06-09 21:24:46 +0300834 value |= CHV_PADCTRL0_GPIOCFG_GPI << CHV_PADCTRL0_GPIOCFG_SHIFT;
Mika Westerberg2479c732015-01-29 12:44:48 +0200835 }
836
837 /* Switch to a GPIO mode */
838 value |= CHV_PADCTRL0_GPIOEN;
Andy Shevchenkobfc8a4b2020-06-09 21:24:46 +0300839 chv_writel(pctrl, offset, CHV_PADCTRL0, value);
Mika Westerberg6e08d6b2014-11-03 13:01:33 +0200840 }
841
Dan O'Donovan0bd50d7192016-06-10 13:23:34 +0100842 raw_spin_unlock_irqrestore(&chv_lock, flags);
Mika Westerberg6e08d6b2014-11-03 13:01:33 +0200843
844 return 0;
845}
846
847static void chv_gpio_disable_free(struct pinctrl_dev *pctldev,
848 struct pinctrl_gpio_range *range,
Andy Shevchenko4e737af2018-09-26 17:50:28 +0300849 unsigned int offset)
Mika Westerberg6e08d6b2014-11-03 13:01:33 +0200850{
Andy Shevchenko3ea2e2c2020-07-27 19:12:16 +0300851 struct intel_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev);
Mika Westerberg6e08d6b2014-11-03 13:01:33 +0200852 unsigned long flags;
Mika Westerberg6e08d6b2014-11-03 13:01:33 +0200853
Dan O'Donovan0bd50d7192016-06-10 13:23:34 +0100854 raw_spin_lock_irqsave(&chv_lock, flags);
Mika Westerberg6e08d6b2014-11-03 13:01:33 +0200855
Hans de Goede1adde322018-12-04 20:42:47 +0100856 if (!chv_pad_locked(pctrl, offset))
857 chv_gpio_clear_triggering(pctrl, offset);
Mika Westerberg6e08d6b2014-11-03 13:01:33 +0200858
Dan O'Donovan0bd50d7192016-06-10 13:23:34 +0100859 raw_spin_unlock_irqrestore(&chv_lock, flags);
Mika Westerberg6e08d6b2014-11-03 13:01:33 +0200860}
861
862static int chv_gpio_set_direction(struct pinctrl_dev *pctldev,
863 struct pinctrl_gpio_range *range,
Andy Shevchenko4e737af2018-09-26 17:50:28 +0300864 unsigned int offset, bool input)
Mika Westerberg6e08d6b2014-11-03 13:01:33 +0200865{
Andy Shevchenko3ea2e2c2020-07-27 19:12:16 +0300866 struct intel_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev);
Mika Westerberg6e08d6b2014-11-03 13:01:33 +0200867 unsigned long flags;
868 u32 ctrl0;
869
Dan O'Donovan0bd50d7192016-06-10 13:23:34 +0100870 raw_spin_lock_irqsave(&chv_lock, flags);
Mika Westerberg6e08d6b2014-11-03 13:01:33 +0200871
Andy Shevchenko4e7293e2020-06-09 21:24:44 +0300872 ctrl0 = chv_readl(pctrl, offset, CHV_PADCTRL0) & ~CHV_PADCTRL0_GPIOCFG_MASK;
Mika Westerberg6e08d6b2014-11-03 13:01:33 +0200873 if (input)
874 ctrl0 |= CHV_PADCTRL0_GPIOCFG_GPI << CHV_PADCTRL0_GPIOCFG_SHIFT;
875 else
876 ctrl0 |= CHV_PADCTRL0_GPIOCFG_GPO << CHV_PADCTRL0_GPIOCFG_SHIFT;
Andy Shevchenkobfc8a4b2020-06-09 21:24:46 +0300877 chv_writel(pctrl, offset, CHV_PADCTRL0, ctrl0);
Mika Westerberg6e08d6b2014-11-03 13:01:33 +0200878
Dan O'Donovan0bd50d7192016-06-10 13:23:34 +0100879 raw_spin_unlock_irqrestore(&chv_lock, flags);
Mika Westerberg6e08d6b2014-11-03 13:01:33 +0200880
881 return 0;
882}
883
884static const struct pinmux_ops chv_pinmux_ops = {
885 .get_functions_count = chv_get_functions_count,
886 .get_function_name = chv_get_function_name,
887 .get_function_groups = chv_get_function_groups,
888 .set_mux = chv_pinmux_set_mux,
889 .gpio_request_enable = chv_gpio_request_enable,
890 .gpio_disable_free = chv_gpio_disable_free,
891 .gpio_set_direction = chv_gpio_set_direction,
892};
893
Andy Shevchenko4e737af2018-09-26 17:50:28 +0300894static int chv_config_get(struct pinctrl_dev *pctldev, unsigned int pin,
Mika Westerberg6e08d6b2014-11-03 13:01:33 +0200895 unsigned long *config)
896{
Andy Shevchenko3ea2e2c2020-07-27 19:12:16 +0300897 struct intel_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev);
Mika Westerberg6e08d6b2014-11-03 13:01:33 +0200898 enum pin_config_param param = pinconf_to_config_param(*config);
899 unsigned long flags;
900 u32 ctrl0, ctrl1;
901 u16 arg = 0;
902 u32 term;
903
Dan O'Donovan0bd50d7192016-06-10 13:23:34 +0100904 raw_spin_lock_irqsave(&chv_lock, flags);
Andy Shevchenko4e7293e2020-06-09 21:24:44 +0300905 ctrl0 = chv_readl(pctrl, pin, CHV_PADCTRL0);
906 ctrl1 = chv_readl(pctrl, pin, CHV_PADCTRL1);
Dan O'Donovan0bd50d7192016-06-10 13:23:34 +0100907 raw_spin_unlock_irqrestore(&chv_lock, flags);
Mika Westerberg6e08d6b2014-11-03 13:01:33 +0200908
909 term = (ctrl0 & CHV_PADCTRL0_TERM_MASK) >> CHV_PADCTRL0_TERM_SHIFT;
910
911 switch (param) {
912 case PIN_CONFIG_BIAS_DISABLE:
913 if (term)
914 return -EINVAL;
915 break;
916
917 case PIN_CONFIG_BIAS_PULL_UP:
918 if (!(ctrl0 & CHV_PADCTRL0_TERM_UP))
919 return -EINVAL;
920
921 switch (term) {
922 case CHV_PADCTRL0_TERM_20K:
923 arg = 20000;
924 break;
925 case CHV_PADCTRL0_TERM_5K:
926 arg = 5000;
927 break;
928 case CHV_PADCTRL0_TERM_1K:
929 arg = 1000;
930 break;
931 }
932
933 break;
934
935 case PIN_CONFIG_BIAS_PULL_DOWN:
936 if (!term || (ctrl0 & CHV_PADCTRL0_TERM_UP))
937 return -EINVAL;
938
939 switch (term) {
940 case CHV_PADCTRL0_TERM_20K:
941 arg = 20000;
942 break;
943 case CHV_PADCTRL0_TERM_5K:
944 arg = 5000;
945 break;
946 }
947
948 break;
949
950 case PIN_CONFIG_DRIVE_OPEN_DRAIN:
951 if (!(ctrl1 & CHV_PADCTRL1_ODEN))
952 return -EINVAL;
953 break;
954
955 case PIN_CONFIG_BIAS_HIGH_IMPEDANCE: {
956 u32 cfg;
957
958 cfg = ctrl0 & CHV_PADCTRL0_GPIOCFG_MASK;
959 cfg >>= CHV_PADCTRL0_GPIOCFG_SHIFT;
960 if (cfg != CHV_PADCTRL0_GPIOCFG_HIZ)
961 return -EINVAL;
962
963 break;
964 }
965
966 default:
967 return -ENOTSUPP;
968 }
969
970 *config = pinconf_to_config_packed(param, arg);
971 return 0;
972}
973
Andy Shevchenko3ea2e2c2020-07-27 19:12:16 +0300974static int chv_config_set_pull(struct intel_pinctrl *pctrl, unsigned int pin,
Mika Westerberg58957d22017-01-23 15:34:32 +0300975 enum pin_config_param param, u32 arg)
Mika Westerberg6e08d6b2014-11-03 13:01:33 +0200976{
Mika Westerberg6e08d6b2014-11-03 13:01:33 +0200977 unsigned long flags;
978 u32 ctrl0, pull;
979
Dan O'Donovan0bd50d7192016-06-10 13:23:34 +0100980 raw_spin_lock_irqsave(&chv_lock, flags);
Andy Shevchenko4e7293e2020-06-09 21:24:44 +0300981 ctrl0 = chv_readl(pctrl, pin, CHV_PADCTRL0);
Mika Westerberg6e08d6b2014-11-03 13:01:33 +0200982
983 switch (param) {
984 case PIN_CONFIG_BIAS_DISABLE:
985 ctrl0 &= ~(CHV_PADCTRL0_TERM_MASK | CHV_PADCTRL0_TERM_UP);
986 break;
987
988 case PIN_CONFIG_BIAS_PULL_UP:
989 ctrl0 &= ~(CHV_PADCTRL0_TERM_MASK | CHV_PADCTRL0_TERM_UP);
990
991 switch (arg) {
992 case 1000:
993 /* For 1k there is only pull up */
994 pull = CHV_PADCTRL0_TERM_1K << CHV_PADCTRL0_TERM_SHIFT;
995 break;
996 case 5000:
997 pull = CHV_PADCTRL0_TERM_5K << CHV_PADCTRL0_TERM_SHIFT;
998 break;
999 case 20000:
1000 pull = CHV_PADCTRL0_TERM_20K << CHV_PADCTRL0_TERM_SHIFT;
1001 break;
1002 default:
Dan O'Donovan0bd50d7192016-06-10 13:23:34 +01001003 raw_spin_unlock_irqrestore(&chv_lock, flags);
Mika Westerberg6e08d6b2014-11-03 13:01:33 +02001004 return -EINVAL;
1005 }
1006
1007 ctrl0 |= CHV_PADCTRL0_TERM_UP | pull;
1008 break;
1009
1010 case PIN_CONFIG_BIAS_PULL_DOWN:
1011 ctrl0 &= ~(CHV_PADCTRL0_TERM_MASK | CHV_PADCTRL0_TERM_UP);
1012
1013 switch (arg) {
1014 case 5000:
1015 pull = CHV_PADCTRL0_TERM_5K << CHV_PADCTRL0_TERM_SHIFT;
1016 break;
1017 case 20000:
1018 pull = CHV_PADCTRL0_TERM_20K << CHV_PADCTRL0_TERM_SHIFT;
1019 break;
1020 default:
Dan O'Donovan0bd50d7192016-06-10 13:23:34 +01001021 raw_spin_unlock_irqrestore(&chv_lock, flags);
Mika Westerberg6e08d6b2014-11-03 13:01:33 +02001022 return -EINVAL;
1023 }
1024
1025 ctrl0 |= pull;
1026 break;
1027
1028 default:
Dan O'Donovan0bd50d7192016-06-10 13:23:34 +01001029 raw_spin_unlock_irqrestore(&chv_lock, flags);
Mika Westerberg6e08d6b2014-11-03 13:01:33 +02001030 return -EINVAL;
1031 }
1032
Andy Shevchenkobfc8a4b2020-06-09 21:24:46 +03001033 chv_writel(pctrl, pin, CHV_PADCTRL0, ctrl0);
Dan O'Donovan0bd50d7192016-06-10 13:23:34 +01001034 raw_spin_unlock_irqrestore(&chv_lock, flags);
Mika Westerberg6e08d6b2014-11-03 13:01:33 +02001035
1036 return 0;
1037}
1038
Andy Shevchenko3ea2e2c2020-07-27 19:12:16 +03001039static int chv_config_set_oden(struct intel_pinctrl *pctrl, unsigned int pin,
Dan O'Donovanccdf81d2016-06-10 13:23:35 +01001040 bool enable)
1041{
Dan O'Donovanccdf81d2016-06-10 13:23:35 +01001042 unsigned long flags;
1043 u32 ctrl1;
1044
1045 raw_spin_lock_irqsave(&chv_lock, flags);
Andy Shevchenko4e7293e2020-06-09 21:24:44 +03001046 ctrl1 = chv_readl(pctrl, pin, CHV_PADCTRL1);
Dan O'Donovanccdf81d2016-06-10 13:23:35 +01001047
1048 if (enable)
1049 ctrl1 |= CHV_PADCTRL1_ODEN;
1050 else
1051 ctrl1 &= ~CHV_PADCTRL1_ODEN;
1052
Andy Shevchenkobfc8a4b2020-06-09 21:24:46 +03001053 chv_writel(pctrl, pin, CHV_PADCTRL1, ctrl1);
Dan O'Donovanccdf81d2016-06-10 13:23:35 +01001054 raw_spin_unlock_irqrestore(&chv_lock, flags);
1055
1056 return 0;
1057}
1058
Andy Shevchenko4e737af2018-09-26 17:50:28 +03001059static int chv_config_set(struct pinctrl_dev *pctldev, unsigned int pin,
1060 unsigned long *configs, unsigned int nconfigs)
Mika Westerberg6e08d6b2014-11-03 13:01:33 +02001061{
Andy Shevchenko3ea2e2c2020-07-27 19:12:16 +03001062 struct intel_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev);
Mika Westerberg6e08d6b2014-11-03 13:01:33 +02001063 enum pin_config_param param;
1064 int i, ret;
Mika Westerberg58957d22017-01-23 15:34:32 +03001065 u32 arg;
Mika Westerberg6e08d6b2014-11-03 13:01:33 +02001066
1067 if (chv_pad_locked(pctrl, pin))
1068 return -EBUSY;
1069
1070 for (i = 0; i < nconfigs; i++) {
1071 param = pinconf_to_config_param(configs[i]);
1072 arg = pinconf_to_config_argument(configs[i]);
1073
1074 switch (param) {
1075 case PIN_CONFIG_BIAS_DISABLE:
1076 case PIN_CONFIG_BIAS_PULL_UP:
1077 case PIN_CONFIG_BIAS_PULL_DOWN:
1078 ret = chv_config_set_pull(pctrl, pin, param, arg);
1079 if (ret)
1080 return ret;
1081 break;
1082
Dan O'Donovanccdf81d2016-06-10 13:23:35 +01001083 case PIN_CONFIG_DRIVE_PUSH_PULL:
1084 ret = chv_config_set_oden(pctrl, pin, false);
1085 if (ret)
1086 return ret;
1087 break;
1088
1089 case PIN_CONFIG_DRIVE_OPEN_DRAIN:
1090 ret = chv_config_set_oden(pctrl, pin, true);
1091 if (ret)
1092 return ret;
1093 break;
1094
Mika Westerberg6e08d6b2014-11-03 13:01:33 +02001095 default:
1096 return -ENOTSUPP;
1097 }
1098
1099 dev_dbg(pctrl->dev, "pin %d set config %d arg %u\n", pin,
1100 param, arg);
1101 }
1102
1103 return 0;
1104}
1105
Dan O'Donovan77401d72016-06-10 13:23:36 +01001106static int chv_config_group_get(struct pinctrl_dev *pctldev,
1107 unsigned int group,
1108 unsigned long *config)
1109{
1110 const unsigned int *pins;
1111 unsigned int npins;
1112 int ret;
1113
1114 ret = chv_get_group_pins(pctldev, group, &pins, &npins);
1115 if (ret)
1116 return ret;
1117
1118 ret = chv_config_get(pctldev, pins[0], config);
1119 if (ret)
1120 return ret;
1121
1122 return 0;
1123}
1124
1125static int chv_config_group_set(struct pinctrl_dev *pctldev,
1126 unsigned int group, unsigned long *configs,
1127 unsigned int num_configs)
1128{
1129 const unsigned int *pins;
1130 unsigned int npins;
1131 int i, ret;
1132
1133 ret = chv_get_group_pins(pctldev, group, &pins, &npins);
1134 if (ret)
1135 return ret;
1136
1137 for (i = 0; i < npins; i++) {
1138 ret = chv_config_set(pctldev, pins[i], configs, num_configs);
1139 if (ret)
1140 return ret;
1141 }
1142
1143 return 0;
1144}
1145
Mika Westerberg6e08d6b2014-11-03 13:01:33 +02001146static const struct pinconf_ops chv_pinconf_ops = {
1147 .is_generic = true,
1148 .pin_config_set = chv_config_set,
1149 .pin_config_get = chv_config_get,
Dan O'Donovan77401d72016-06-10 13:23:36 +01001150 .pin_config_group_get = chv_config_group_get,
1151 .pin_config_group_set = chv_config_group_set,
Mika Westerberg6e08d6b2014-11-03 13:01:33 +02001152};
1153
1154static struct pinctrl_desc chv_pinctrl_desc = {
1155 .pctlops = &chv_pinctrl_ops,
1156 .pmxops = &chv_pinmux_ops,
1157 .confops = &chv_pinconf_ops,
1158 .owner = THIS_MODULE,
1159};
1160
Andy Shevchenko4e737af2018-09-26 17:50:28 +03001161static int chv_gpio_get(struct gpio_chip *chip, unsigned int offset)
Mika Westerberg6e08d6b2014-11-03 13:01:33 +02001162{
Andy Shevchenko3ea2e2c2020-07-27 19:12:16 +03001163 struct intel_pinctrl *pctrl = gpiochip_get_data(chip);
Mika Westerberg4585b002015-08-03 12:46:38 +03001164 unsigned long flags;
Mika Westerberg6e08d6b2014-11-03 13:01:33 +02001165 u32 ctrl0, cfg;
1166
Dan O'Donovan0bd50d7192016-06-10 13:23:34 +01001167 raw_spin_lock_irqsave(&chv_lock, flags);
Andy Shevchenko4e7293e2020-06-09 21:24:44 +03001168 ctrl0 = chv_readl(pctrl, offset, CHV_PADCTRL0);
Dan O'Donovan0bd50d7192016-06-10 13:23:34 +01001169 raw_spin_unlock_irqrestore(&chv_lock, flags);
Mika Westerberg6e08d6b2014-11-03 13:01:33 +02001170
1171 cfg = ctrl0 & CHV_PADCTRL0_GPIOCFG_MASK;
1172 cfg >>= CHV_PADCTRL0_GPIOCFG_SHIFT;
1173
1174 if (cfg == CHV_PADCTRL0_GPIOCFG_GPO)
1175 return !!(ctrl0 & CHV_PADCTRL0_GPIOTXSTATE);
1176 return !!(ctrl0 & CHV_PADCTRL0_GPIORXSTATE);
1177}
1178
Andy Shevchenko4e737af2018-09-26 17:50:28 +03001179static void chv_gpio_set(struct gpio_chip *chip, unsigned int offset, int value)
Mika Westerberg6e08d6b2014-11-03 13:01:33 +02001180{
Andy Shevchenko3ea2e2c2020-07-27 19:12:16 +03001181 struct intel_pinctrl *pctrl = gpiochip_get_data(chip);
Mika Westerberg6e08d6b2014-11-03 13:01:33 +02001182 unsigned long flags;
Mika Westerberg6e08d6b2014-11-03 13:01:33 +02001183 u32 ctrl0;
1184
Dan O'Donovan0bd50d7192016-06-10 13:23:34 +01001185 raw_spin_lock_irqsave(&chv_lock, flags);
Mika Westerberg6e08d6b2014-11-03 13:01:33 +02001186
Andy Shevchenko4e7293e2020-06-09 21:24:44 +03001187 ctrl0 = chv_readl(pctrl, offset, CHV_PADCTRL0);
Mika Westerberg6e08d6b2014-11-03 13:01:33 +02001188
1189 if (value)
1190 ctrl0 |= CHV_PADCTRL0_GPIOTXSTATE;
1191 else
1192 ctrl0 &= ~CHV_PADCTRL0_GPIOTXSTATE;
1193
Andy Shevchenkobfc8a4b2020-06-09 21:24:46 +03001194 chv_writel(pctrl, offset, CHV_PADCTRL0, ctrl0);
Mika Westerberg6e08d6b2014-11-03 13:01:33 +02001195
Dan O'Donovan0bd50d7192016-06-10 13:23:34 +01001196 raw_spin_unlock_irqrestore(&chv_lock, flags);
Mika Westerberg6e08d6b2014-11-03 13:01:33 +02001197}
1198
Andy Shevchenko4e737af2018-09-26 17:50:28 +03001199static int chv_gpio_get_direction(struct gpio_chip *chip, unsigned int offset)
Mika Westerberg6e08d6b2014-11-03 13:01:33 +02001200{
Andy Shevchenko3ea2e2c2020-07-27 19:12:16 +03001201 struct intel_pinctrl *pctrl = gpiochip_get_data(chip);
Mika Westerberg6e08d6b2014-11-03 13:01:33 +02001202 u32 ctrl0, direction;
Mika Westerberg4585b002015-08-03 12:46:38 +03001203 unsigned long flags;
Mika Westerberg6e08d6b2014-11-03 13:01:33 +02001204
Dan O'Donovan0bd50d7192016-06-10 13:23:34 +01001205 raw_spin_lock_irqsave(&chv_lock, flags);
Andy Shevchenko4e7293e2020-06-09 21:24:44 +03001206 ctrl0 = chv_readl(pctrl, offset, CHV_PADCTRL0);
Dan O'Donovan0bd50d7192016-06-10 13:23:34 +01001207 raw_spin_unlock_irqrestore(&chv_lock, flags);
Mika Westerberg6e08d6b2014-11-03 13:01:33 +02001208
1209 direction = ctrl0 & CHV_PADCTRL0_GPIOCFG_MASK;
1210 direction >>= CHV_PADCTRL0_GPIOCFG_SHIFT;
1211
Matti Vaittinen90a1eb12019-12-12 08:35:19 +02001212 if (direction == CHV_PADCTRL0_GPIOCFG_GPO)
1213 return GPIO_LINE_DIRECTION_OUT;
1214
1215 return GPIO_LINE_DIRECTION_IN;
Mika Westerberg6e08d6b2014-11-03 13:01:33 +02001216}
1217
Andy Shevchenko4e737af2018-09-26 17:50:28 +03001218static int chv_gpio_direction_input(struct gpio_chip *chip, unsigned int offset)
Mika Westerberg6e08d6b2014-11-03 13:01:33 +02001219{
1220 return pinctrl_gpio_direction_input(chip->base + offset);
1221}
1222
Andy Shevchenko4e737af2018-09-26 17:50:28 +03001223static int chv_gpio_direction_output(struct gpio_chip *chip, unsigned int offset,
Mika Westerberg6e08d6b2014-11-03 13:01:33 +02001224 int value)
1225{
qipeng.zha549e7832015-03-03 18:13:22 +08001226 chv_gpio_set(chip, offset, value);
Mika Westerberg6e08d6b2014-11-03 13:01:33 +02001227 return pinctrl_gpio_direction_output(chip->base + offset);
1228}
1229
1230static const struct gpio_chip chv_gpio_chip = {
1231 .owner = THIS_MODULE,
Jonas Gorski98c85d52015-10-11 17:34:19 +02001232 .request = gpiochip_generic_request,
1233 .free = gpiochip_generic_free,
Mika Westerberg6e08d6b2014-11-03 13:01:33 +02001234 .get_direction = chv_gpio_get_direction,
1235 .direction_input = chv_gpio_direction_input,
1236 .direction_output = chv_gpio_direction_output,
1237 .get = chv_gpio_get,
1238 .set = chv_gpio_set,
1239};
1240
1241static void chv_gpio_irq_ack(struct irq_data *d)
1242{
1243 struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
Andy Shevchenko3ea2e2c2020-07-27 19:12:16 +03001244 struct intel_pinctrl *pctrl = gpiochip_get_data(gc);
Mika Westerberg03c47492017-11-27 16:54:42 +03001245 int pin = irqd_to_hwirq(d);
Mika Westerberg6e08d6b2014-11-03 13:01:33 +02001246 u32 intr_line;
1247
Dan O'Donovan0bd50d7192016-06-10 13:23:34 +01001248 raw_spin_lock(&chv_lock);
Mika Westerberg6e08d6b2014-11-03 13:01:33 +02001249
Andy Shevchenko4e7293e2020-06-09 21:24:44 +03001250 intr_line = chv_readl(pctrl, pin, CHV_PADCTRL0);
Mika Westerberg6e08d6b2014-11-03 13:01:33 +02001251 intr_line &= CHV_PADCTRL0_INTSEL_MASK;
1252 intr_line >>= CHV_PADCTRL0_INTSEL_SHIFT;
Andy Shevchenko99fd6512020-06-09 21:24:45 +03001253 chv_pctrl_writel(pctrl, CHV_INTSTAT, BIT(intr_line));
Mika Westerberg6e08d6b2014-11-03 13:01:33 +02001254
Dan O'Donovan0bd50d7192016-06-10 13:23:34 +01001255 raw_spin_unlock(&chv_lock);
Mika Westerberg6e08d6b2014-11-03 13:01:33 +02001256}
1257
1258static void chv_gpio_irq_mask_unmask(struct irq_data *d, bool mask)
1259{
1260 struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
Andy Shevchenko3ea2e2c2020-07-27 19:12:16 +03001261 struct intel_pinctrl *pctrl = gpiochip_get_data(gc);
Mika Westerberg03c47492017-11-27 16:54:42 +03001262 int pin = irqd_to_hwirq(d);
Mika Westerberg6e08d6b2014-11-03 13:01:33 +02001263 u32 value, intr_line;
1264 unsigned long flags;
1265
Dan O'Donovan0bd50d7192016-06-10 13:23:34 +01001266 raw_spin_lock_irqsave(&chv_lock, flags);
Mika Westerberg6e08d6b2014-11-03 13:01:33 +02001267
Andy Shevchenko4e7293e2020-06-09 21:24:44 +03001268 intr_line = chv_readl(pctrl, pin, CHV_PADCTRL0);
Mika Westerberg6e08d6b2014-11-03 13:01:33 +02001269 intr_line &= CHV_PADCTRL0_INTSEL_MASK;
1270 intr_line >>= CHV_PADCTRL0_INTSEL_SHIFT;
1271
Andy Shevchenko99fd6512020-06-09 21:24:45 +03001272 value = chv_pctrl_readl(pctrl, CHV_INTMASK);
Mika Westerberg6e08d6b2014-11-03 13:01:33 +02001273 if (mask)
1274 value &= ~BIT(intr_line);
1275 else
1276 value |= BIT(intr_line);
Andy Shevchenko99fd6512020-06-09 21:24:45 +03001277 chv_pctrl_writel(pctrl, CHV_INTMASK, value);
Mika Westerberg6e08d6b2014-11-03 13:01:33 +02001278
Dan O'Donovan0bd50d7192016-06-10 13:23:34 +01001279 raw_spin_unlock_irqrestore(&chv_lock, flags);
Mika Westerberg6e08d6b2014-11-03 13:01:33 +02001280}
1281
1282static void chv_gpio_irq_mask(struct irq_data *d)
1283{
1284 chv_gpio_irq_mask_unmask(d, true);
1285}
1286
1287static void chv_gpio_irq_unmask(struct irq_data *d)
1288{
1289 chv_gpio_irq_mask_unmask(d, false);
1290}
1291
Mika Westerberge6c906d2015-05-12 13:35:37 +03001292static unsigned chv_gpio_irq_startup(struct irq_data *d)
1293{
1294 /*
1295 * Check if the interrupt has been requested with 0 as triggering
1296 * type. In that case it is assumed that the current values
1297 * programmed to the hardware are used (e.g BIOS configured
1298 * defaults).
1299 *
1300 * In that case ->irq_set_type() will never be called so we need to
1301 * read back the values from hardware now, set correct flow handler
1302 * and update mappings before the interrupt is being used.
1303 */
1304 if (irqd_get_trigger_type(d) == IRQ_TYPE_NONE) {
1305 struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
Andy Shevchenko3ea2e2c2020-07-27 19:12:16 +03001306 struct intel_pinctrl *pctrl = gpiochip_get_data(gc);
Andy Shevchenko8a828572020-07-27 19:12:15 +03001307 struct intel_community_context *cctx = &pctrl->context.communities[0];
Andy Shevchenko4e737af2018-09-26 17:50:28 +03001308 unsigned int pin = irqd_to_hwirq(d);
Mika Westerberge6c906d2015-05-12 13:35:37 +03001309 irq_flow_handler_t handler;
1310 unsigned long flags;
1311 u32 intsel, value;
1312
Dan O'Donovan0bd50d7192016-06-10 13:23:34 +01001313 raw_spin_lock_irqsave(&chv_lock, flags);
Andy Shevchenko4e7293e2020-06-09 21:24:44 +03001314 intsel = chv_readl(pctrl, pin, CHV_PADCTRL0);
Mika Westerberge6c906d2015-05-12 13:35:37 +03001315 intsel &= CHV_PADCTRL0_INTSEL_MASK;
1316 intsel >>= CHV_PADCTRL0_INTSEL_SHIFT;
1317
Andy Shevchenko4e7293e2020-06-09 21:24:44 +03001318 value = chv_readl(pctrl, pin, CHV_PADCTRL1);
Mika Westerberge6c906d2015-05-12 13:35:37 +03001319 if (value & CHV_PADCTRL1_INTWAKECFG_LEVEL)
1320 handler = handle_level_irq;
1321 else
1322 handler = handle_edge_irq;
1323
Hans de Goedebdfbef22021-11-18 11:56:48 +01001324 if (cctx->intr_lines[intsel] == CHV_INVALID_HWIRQ) {
Thomas Gleixnera4e3f782015-06-23 15:52:44 +02001325 irq_set_handler_locked(d, handler);
Andy Shevchenko8a828572020-07-27 19:12:15 +03001326 cctx->intr_lines[intsel] = pin;
Mika Westerberge6c906d2015-05-12 13:35:37 +03001327 }
Dan O'Donovan0bd50d7192016-06-10 13:23:34 +01001328 raw_spin_unlock_irqrestore(&chv_lock, flags);
Mika Westerberge6c906d2015-05-12 13:35:37 +03001329 }
1330
1331 chv_gpio_irq_unmask(d);
1332 return 0;
1333}
1334
Andy Shevchenko4e737af2018-09-26 17:50:28 +03001335static int chv_gpio_irq_type(struct irq_data *d, unsigned int type)
Mika Westerberg6e08d6b2014-11-03 13:01:33 +02001336{
1337 struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
Andy Shevchenko3ea2e2c2020-07-27 19:12:16 +03001338 struct intel_pinctrl *pctrl = gpiochip_get_data(gc);
Andy Shevchenko8a828572020-07-27 19:12:15 +03001339 struct intel_community_context *cctx = &pctrl->context.communities[0];
Andy Shevchenko4e737af2018-09-26 17:50:28 +03001340 unsigned int pin = irqd_to_hwirq(d);
Mika Westerberg6e08d6b2014-11-03 13:01:33 +02001341 unsigned long flags;
1342 u32 value;
1343
Dan O'Donovan0bd50d7192016-06-10 13:23:34 +01001344 raw_spin_lock_irqsave(&chv_lock, flags);
Mika Westerberg6e08d6b2014-11-03 13:01:33 +02001345
1346 /*
1347 * Pins which can be used as shared interrupt are configured in
1348 * BIOS. Driver trusts BIOS configurations and assigns different
1349 * handler according to the irq type.
1350 *
1351 * Driver needs to save the mapping between each pin and
1352 * its interrupt line.
1353 * 1. If the pin cfg is locked in BIOS:
1354 * Trust BIOS has programmed IntWakeCfg bits correctly,
1355 * driver just needs to save the mapping.
1356 * 2. If the pin cfg is not locked in BIOS:
1357 * Driver programs the IntWakeCfg bits and save the mapping.
1358 */
1359 if (!chv_pad_locked(pctrl, pin)) {
Andy Shevchenko4e7293e2020-06-09 21:24:44 +03001360 value = chv_readl(pctrl, pin, CHV_PADCTRL1);
Mika Westerberg6e08d6b2014-11-03 13:01:33 +02001361 value &= ~CHV_PADCTRL1_INTWAKECFG_MASK;
1362 value &= ~CHV_PADCTRL1_INVRXTX_MASK;
1363
1364 if (type & IRQ_TYPE_EDGE_BOTH) {
1365 if ((type & IRQ_TYPE_EDGE_BOTH) == IRQ_TYPE_EDGE_BOTH)
1366 value |= CHV_PADCTRL1_INTWAKECFG_BOTH;
1367 else if (type & IRQ_TYPE_EDGE_RISING)
1368 value |= CHV_PADCTRL1_INTWAKECFG_RISING;
1369 else if (type & IRQ_TYPE_EDGE_FALLING)
1370 value |= CHV_PADCTRL1_INTWAKECFG_FALLING;
1371 } else if (type & IRQ_TYPE_LEVEL_MASK) {
1372 value |= CHV_PADCTRL1_INTWAKECFG_LEVEL;
1373 if (type & IRQ_TYPE_LEVEL_LOW)
1374 value |= CHV_PADCTRL1_INVRXTX_RXDATA;
1375 }
1376
Andy Shevchenkobfc8a4b2020-06-09 21:24:46 +03001377 chv_writel(pctrl, pin, CHV_PADCTRL1, value);
Mika Westerberg6e08d6b2014-11-03 13:01:33 +02001378 }
1379
Andy Shevchenko4e7293e2020-06-09 21:24:44 +03001380 value = chv_readl(pctrl, pin, CHV_PADCTRL0);
Mika Westerberg6e08d6b2014-11-03 13:01:33 +02001381 value &= CHV_PADCTRL0_INTSEL_MASK;
1382 value >>= CHV_PADCTRL0_INTSEL_SHIFT;
1383
Andy Shevchenko8a828572020-07-27 19:12:15 +03001384 cctx->intr_lines[value] = pin;
Mika Westerberg6e08d6b2014-11-03 13:01:33 +02001385
1386 if (type & IRQ_TYPE_EDGE_BOTH)
Thomas Gleixnera4e3f782015-06-23 15:52:44 +02001387 irq_set_handler_locked(d, handle_edge_irq);
Mika Westerberg6e08d6b2014-11-03 13:01:33 +02001388 else if (type & IRQ_TYPE_LEVEL_MASK)
Thomas Gleixnera4e3f782015-06-23 15:52:44 +02001389 irq_set_handler_locked(d, handle_level_irq);
Mika Westerberg6e08d6b2014-11-03 13:01:33 +02001390
Dan O'Donovan0bd50d7192016-06-10 13:23:34 +01001391 raw_spin_unlock_irqrestore(&chv_lock, flags);
Mika Westerberg6e08d6b2014-11-03 13:01:33 +02001392
1393 return 0;
1394}
1395
Thomas Gleixnerbd0b9ac2015-09-14 10:42:37 +02001396static void chv_gpio_irq_handler(struct irq_desc *desc)
Mika Westerberg6e08d6b2014-11-03 13:01:33 +02001397{
1398 struct gpio_chip *gc = irq_desc_get_handler_data(desc);
Andy Shevchenko3ea2e2c2020-07-27 19:12:16 +03001399 struct intel_pinctrl *pctrl = gpiochip_get_data(gc);
Andy Shevchenko293428f2020-06-09 21:24:49 +03001400 const struct intel_community *community = &pctrl->communities[0];
Andy Shevchenko8a828572020-07-27 19:12:15 +03001401 struct intel_community_context *cctx = &pctrl->context.communities[0];
Jiang Liu5663bb22015-06-04 12:13:16 +08001402 struct irq_chip *chip = irq_desc_get_chip(desc);
Mika Westerberg6e08d6b2014-11-03 13:01:33 +02001403 unsigned long pending;
Grace Kao3dbf1ee2020-04-17 12:11:54 +08001404 unsigned long flags;
Mika Westerberg6e08d6b2014-11-03 13:01:33 +02001405 u32 intr_line;
1406
1407 chained_irq_enter(chip, desc);
1408
Grace Kao3dbf1ee2020-04-17 12:11:54 +08001409 raw_spin_lock_irqsave(&chv_lock, flags);
Andy Shevchenko99fd6512020-06-09 21:24:45 +03001410 pending = chv_pctrl_readl(pctrl, CHV_INTSTAT);
Grace Kao3dbf1ee2020-04-17 12:11:54 +08001411 raw_spin_unlock_irqrestore(&chv_lock, flags);
1412
Andy Shevchenko293428f2020-06-09 21:24:49 +03001413 for_each_set_bit(intr_line, &pending, community->nirqs) {
Marc Zyngiera9cb09b2021-05-04 17:42:18 +01001414 unsigned int offset;
Mika Westerberg6e08d6b2014-11-03 13:01:33 +02001415
Andy Shevchenko8a828572020-07-27 19:12:15 +03001416 offset = cctx->intr_lines[intr_line];
Hans de Goedebdfbef22021-11-18 11:56:48 +01001417 if (offset == CHV_INVALID_HWIRQ) {
1418 dev_err(pctrl->dev, "interrupt on unused interrupt line %u\n",
1419 intr_line);
1420 continue;
1421 }
1422
Marc Zyngiera9cb09b2021-05-04 17:42:18 +01001423 generic_handle_domain_irq(gc->irq.domain, offset);
Mika Westerberg6e08d6b2014-11-03 13:01:33 +02001424 }
1425
1426 chained_irq_exit(chip, desc);
1427}
1428
Mika Westerberg70365022017-04-10 13:16:33 +03001429/*
1430 * Certain machines seem to hardcode Linux IRQ numbers in their ACPI
1431 * tables. Since we leave GPIOs that are not capable of generating
1432 * interrupts out of the irqdomain the numbering will be different and
1433 * cause devices using the hardcoded IRQ numbers fail. In order not to
1434 * break such machines we will only mask pins from irqdomain if the machine
1435 * is not listed below.
1436 */
1437static const struct dmi_system_id chv_no_valid_mask[] = {
Mika Westerberg2a8209f2017-05-17 13:25:14 +03001438 /* See https://bugzilla.kernel.org/show_bug.cgi?id=194945 */
Mika Westerberg70365022017-04-10 13:16:33 +03001439 {
Mika Westerberg2a8209f2017-05-17 13:25:14 +03001440 .ident = "Intel_Strago based Chromebooks (All models)",
Mika Westerberg70365022017-04-10 13:16:33 +03001441 .matches = {
1442 DMI_MATCH(DMI_SYS_VENDOR, "GOOGLE"),
Mika Westerberg2a8209f2017-05-17 13:25:14 +03001443 DMI_MATCH(DMI_PRODUCT_FAMILY, "Intel_Strago"),
1444 },
1445 },
1446 {
Andy Shevchenko2d80bd32017-07-04 15:58:39 +03001447 .ident = "HP Chromebook 11 G5 (Setzer)",
1448 .matches = {
1449 DMI_MATCH(DMI_SYS_VENDOR, "HP"),
1450 DMI_MATCH(DMI_PRODUCT_NAME, "Setzer"),
1451 },
1452 },
1453 {
Mika Westerberg2a8209f2017-05-17 13:25:14 +03001454 .ident = "Acer Chromebook R11 (Cyan)",
1455 .matches = {
1456 DMI_MATCH(DMI_SYS_VENDOR, "GOOGLE"),
1457 DMI_MATCH(DMI_PRODUCT_NAME, "Cyan"),
1458 },
1459 },
1460 {
1461 .ident = "Samsung Chromebook 3 (Celes)",
1462 .matches = {
1463 DMI_MATCH(DMI_SYS_VENDOR, "GOOGLE"),
1464 DMI_MATCH(DMI_PRODUCT_NAME, "Celes"),
Mika Westerberg70365022017-04-10 13:16:33 +03001465 },
Wei Yongjuna9de0802017-04-25 06:22:05 +00001466 },
1467 {}
Mika Westerberg70365022017-04-10 13:16:33 +03001468};
1469
Linus Walleij5fbe5b52019-09-04 16:01:04 +02001470static void chv_init_irq_valid_mask(struct gpio_chip *chip,
1471 unsigned long *valid_mask,
1472 unsigned int ngpios)
1473{
Andy Shevchenko3ea2e2c2020-07-27 19:12:16 +03001474 struct intel_pinctrl *pctrl = gpiochip_get_data(chip);
Andy Shevchenko293428f2020-06-09 21:24:49 +03001475 const struct intel_community *community = &pctrl->communities[0];
Linus Walleij5fbe5b52019-09-04 16:01:04 +02001476 int i;
1477
1478 /* Do not add GPIOs that can only generate GPEs to the IRQ domain */
Andy Shevchenko293428f2020-06-09 21:24:49 +03001479 for (i = 0; i < pctrl->soc->npins; i++) {
Linus Walleij5fbe5b52019-09-04 16:01:04 +02001480 const struct pinctrl_pin_desc *desc;
1481 u32 intsel;
1482
Andy Shevchenko293428f2020-06-09 21:24:49 +03001483 desc = &pctrl->soc->pins[i];
Linus Walleij5fbe5b52019-09-04 16:01:04 +02001484
Andy Shevchenko4e7293e2020-06-09 21:24:44 +03001485 intsel = chv_readl(pctrl, desc->number, CHV_PADCTRL0);
Linus Walleij5fbe5b52019-09-04 16:01:04 +02001486 intsel &= CHV_PADCTRL0_INTSEL_MASK;
1487 intsel >>= CHV_PADCTRL0_INTSEL_SHIFT;
1488
1489 if (intsel >= community->nirqs)
Hans de Goede37398982019-10-18 11:08:42 +02001490 clear_bit(desc->number, valid_mask);
Linus Walleij5fbe5b52019-09-04 16:01:04 +02001491 }
1492}
1493
Hans de Goede82d9beb2019-11-14 11:08:02 +01001494static int chv_gpio_irq_init_hw(struct gpio_chip *chip)
1495{
Andy Shevchenko3ea2e2c2020-07-27 19:12:16 +03001496 struct intel_pinctrl *pctrl = gpiochip_get_data(chip);
Andy Shevchenko293428f2020-06-09 21:24:49 +03001497 const struct intel_community *community = &pctrl->communities[0];
Hans de Goede82d9beb2019-11-14 11:08:02 +01001498
1499 /*
1500 * The same set of machines in chv_no_valid_mask[] have incorrectly
1501 * configured GPIOs that generate spurious interrupts so we use
1502 * this same list to apply another quirk for them.
1503 *
1504 * See also https://bugzilla.kernel.org/show_bug.cgi?id=197953.
1505 */
1506 if (!pctrl->chip.irq.init_valid_mask) {
1507 /*
1508 * Mask all interrupts the community is able to generate
1509 * but leave the ones that can only generate GPEs unmasked.
1510 */
Andy Shevchenko293428f2020-06-09 21:24:49 +03001511 chv_pctrl_writel(pctrl, CHV_INTMASK, GENMASK(31, community->nirqs));
Hans de Goede82d9beb2019-11-14 11:08:02 +01001512 }
1513
1514 /* Clear all interrupts */
Andy Shevchenko99fd6512020-06-09 21:24:45 +03001515 chv_pctrl_writel(pctrl, CHV_INTSTAT, 0xffff);
Hans de Goede82d9beb2019-11-14 11:08:02 +01001516
1517 return 0;
1518}
1519
Hans de Goedebd906332019-11-14 11:08:03 +01001520static int chv_gpio_add_pin_ranges(struct gpio_chip *chip)
1521{
Andy Shevchenko3ea2e2c2020-07-27 19:12:16 +03001522 struct intel_pinctrl *pctrl = gpiochip_get_data(chip);
Andy Shevchenko293428f2020-06-09 21:24:49 +03001523 const struct intel_community *community = &pctrl->communities[0];
Andy Shevchenko36ad7b22020-04-01 20:35:01 +03001524 const struct intel_padgroup *gpp;
Hans de Goedebd906332019-11-14 11:08:03 +01001525 int ret, i;
1526
Andy Shevchenko36ad7b22020-04-01 20:35:01 +03001527 for (i = 0; i < community->ngpps; i++) {
1528 gpp = &community->gpps[i];
Hans de Goedebd906332019-11-14 11:08:03 +01001529 ret = gpiochip_add_pin_range(chip, dev_name(pctrl->dev),
Andy Shevchenko36ad7b22020-04-01 20:35:01 +03001530 gpp->base, gpp->base,
1531 gpp->size);
Hans de Goedebd906332019-11-14 11:08:03 +01001532 if (ret) {
1533 dev_err(pctrl->dev, "failed to add GPIO pin range\n");
1534 return ret;
1535 }
1536 }
1537
1538 return 0;
1539}
1540
Andy Shevchenko3ea2e2c2020-07-27 19:12:16 +03001541static int chv_gpio_probe(struct intel_pinctrl *pctrl, int irq)
Mika Westerberg6e08d6b2014-11-03 13:01:33 +02001542{
Andy Shevchenko293428f2020-06-09 21:24:49 +03001543 const struct intel_community *community = &pctrl->communities[0];
Andy Shevchenko36ad7b22020-04-01 20:35:01 +03001544 const struct intel_padgroup *gpp;
Mika Westerberg6e08d6b2014-11-03 13:01:33 +02001545 struct gpio_chip *chip = &pctrl->chip;
Mika Westerberg70365022017-04-10 13:16:33 +03001546 bool need_valid_mask = !dmi_check_system(chv_no_valid_mask);
Mika Westerberg03c47492017-11-27 16:54:42 +03001547 int ret, i, irq_base;
Mika Westerberg6e08d6b2014-11-03 13:01:33 +02001548
1549 *chip = chv_gpio_chip;
1550
Andy Shevchenko293428f2020-06-09 21:24:49 +03001551 chip->ngpio = pctrl->soc->pins[pctrl->soc->npins - 1].number + 1;
Mika Westerberg6e08d6b2014-11-03 13:01:33 +02001552 chip->label = dev_name(pctrl->dev);
Hans de Goedebd906332019-11-14 11:08:03 +01001553 chip->add_pin_ranges = chv_gpio_add_pin_ranges;
Linus Walleij58383c782015-11-04 09:56:26 +01001554 chip->parent = pctrl->dev;
Mika Westerberg6e08d6b2014-11-03 13:01:33 +02001555 chip->base = -1;
1556
Hans de Goedeb9a19bdb2019-11-14 11:08:04 +01001557 pctrl->irq = irq;
Andy Shevchenkoe58e1772019-10-24 16:34:41 +03001558 pctrl->irqchip.name = "chv-gpio";
1559 pctrl->irqchip.irq_startup = chv_gpio_irq_startup;
1560 pctrl->irqchip.irq_ack = chv_gpio_irq_ack;
1561 pctrl->irqchip.irq_mask = chv_gpio_irq_mask;
1562 pctrl->irqchip.irq_unmask = chv_gpio_irq_unmask;
1563 pctrl->irqchip.irq_set_type = chv_gpio_irq_type;
1564 pctrl->irqchip.flags = IRQCHIP_SKIP_SET_WAKE;
1565
Hans de Goedeb9a19bdb2019-11-14 11:08:04 +01001566 chip->irq.chip = &pctrl->irqchip;
1567 chip->irq.init_hw = chv_gpio_irq_init_hw;
1568 chip->irq.parent_handler = chv_gpio_irq_handler;
1569 chip->irq.num_parents = 1;
1570 chip->irq.parents = &pctrl->irq;
1571 chip->irq.default_type = IRQ_TYPE_NONE;
1572 chip->irq.handler = handle_bad_irq;
1573 if (need_valid_mask) {
1574 chip->irq.init_valid_mask = chv_init_irq_valid_mask;
1575 } else {
1576 irq_base = devm_irq_alloc_descs(pctrl->dev, -1, 0,
Andy Shevchenko293428f2020-06-09 21:24:49 +03001577 pctrl->soc->npins, NUMA_NO_NODE);
Hans de Goedeb9a19bdb2019-11-14 11:08:04 +01001578 if (irq_base < 0) {
1579 dev_err(pctrl->dev, "Failed to allocate IRQ numbers\n");
1580 return irq_base;
1581 }
1582 }
1583
1584 ret = devm_gpiochip_add_data(pctrl->dev, chip, pctrl);
Mika Westerberg6e08d6b2014-11-03 13:01:33 +02001585 if (ret) {
Hans de Goedeb9a19bdb2019-11-14 11:08:04 +01001586 dev_err(pctrl->dev, "Failed to register gpiochip\n");
Mika Westerbergd1073412016-09-20 15:15:23 +03001587 return ret;
Mika Westerberg6e08d6b2014-11-03 13:01:33 +02001588 }
1589
Mika Westerberg83b9dc12018-04-25 13:32:11 +03001590 if (!need_valid_mask) {
Andy Shevchenko36ad7b22020-04-01 20:35:01 +03001591 for (i = 0; i < community->ngpps; i++) {
1592 gpp = &community->gpps[i];
Mika Westerberg83b9dc12018-04-25 13:32:11 +03001593
1594 irq_domain_associate_many(chip->irq.domain, irq_base,
Andy Shevchenko36ad7b22020-04-01 20:35:01 +03001595 gpp->base, gpp->size);
1596 irq_base += gpp->size;
Mika Westerberg83b9dc12018-04-25 13:32:11 +03001597 }
1598 }
1599
Mika Westerberg6e08d6b2014-11-03 13:01:33 +02001600 return 0;
Mika Westerberg6e08d6b2014-11-03 13:01:33 +02001601}
1602
Hans de Goedea0b02852017-03-23 14:23:25 +01001603static acpi_status chv_pinctrl_mmio_access_handler(u32 function,
1604 acpi_physical_address address, u32 bits, u64 *value,
1605 void *handler_context, void *region_context)
1606{
Andy Shevchenko3ea2e2c2020-07-27 19:12:16 +03001607 struct intel_pinctrl *pctrl = region_context;
Hans de Goedea0b02852017-03-23 14:23:25 +01001608 unsigned long flags;
1609 acpi_status ret = AE_OK;
1610
1611 raw_spin_lock_irqsave(&chv_lock, flags);
1612
1613 if (function == ACPI_WRITE)
Andy Shevchenko99fd6512020-06-09 21:24:45 +03001614 chv_pctrl_writel(pctrl, address, *value);
Hans de Goedea0b02852017-03-23 14:23:25 +01001615 else if (function == ACPI_READ)
Andy Shevchenko99fd6512020-06-09 21:24:45 +03001616 *value = chv_pctrl_readl(pctrl, address);
Hans de Goedea0b02852017-03-23 14:23:25 +01001617 else
1618 ret = AE_BAD_PARAMETER;
1619
1620 raw_spin_unlock_irqrestore(&chv_lock, flags);
1621
1622 return ret;
1623}
1624
Mika Westerberg6e08d6b2014-11-03 13:01:33 +02001625static int chv_pinctrl_probe(struct platform_device *pdev)
1626{
Andy Shevchenko10c857f2020-07-29 14:57:08 +03001627 const struct intel_pinctrl_soc_data *soc_data;
Hans de Goedebdfbef22021-11-18 11:56:48 +01001628 struct intel_community_context *cctx;
Andy Shevchenko293428f2020-06-09 21:24:49 +03001629 struct intel_community *community;
1630 struct device *dev = &pdev->dev;
Andy Shevchenko10c857f2020-07-29 14:57:08 +03001631 struct acpi_device *adev = ACPI_COMPANION(dev);
Andy Shevchenko3ea2e2c2020-07-27 19:12:16 +03001632 struct intel_pinctrl *pctrl;
Hans de Goedea0b02852017-03-23 14:23:25 +01001633 acpi_status status;
Hans de Goedebdfbef22021-11-18 11:56:48 +01001634 unsigned int i;
Andy Shevchenko10c857f2020-07-29 14:57:08 +03001635 int ret, irq;
Mika Westerberg6e08d6b2014-11-03 13:01:33 +02001636
Andy Shevchenko10c857f2020-07-29 14:57:08 +03001637 soc_data = intel_pinctrl_get_soc_data(pdev);
1638 if (IS_ERR(soc_data))
1639 return PTR_ERR(soc_data);
Andy Shevchenko293428f2020-06-09 21:24:49 +03001640
1641 pctrl = devm_kzalloc(dev, sizeof(*pctrl), GFP_KERNEL);
Mika Westerberg6e08d6b2014-11-03 13:01:33 +02001642 if (!pctrl)
1643 return -ENOMEM;
1644
Andy Shevchenko359164fa2020-07-29 15:02:30 +03001645 pctrl->dev = dev;
Andy Shevchenko293428f2020-06-09 21:24:49 +03001646 pctrl->soc = soc_data;
1647
1648 pctrl->ncommunities = pctrl->soc->ncommunities;
1649 pctrl->communities = devm_kmemdup(dev, pctrl->soc->communities,
1650 pctrl->ncommunities * sizeof(*pctrl->communities),
1651 GFP_KERNEL);
1652 if (!pctrl->communities)
1653 return -ENOMEM;
1654
1655 community = &pctrl->communities[0];
1656 community->regs = devm_platform_ioremap_resource(pdev, 0);
1657 if (IS_ERR(community->regs))
1658 return PTR_ERR(community->regs);
1659
1660 community->pad_regs = community->regs + FAMILY_PAD_REGS_OFF;
Mika Westerberg6e08d6b2014-11-03 13:01:33 +02001661
Mika Westerberg9eb457b2014-12-04 12:32:50 +02001662#ifdef CONFIG_PM_SLEEP
Andy Shevchenko293428f2020-06-09 21:24:49 +03001663 pctrl->context.pads = devm_kcalloc(dev, pctrl->soc->npins,
1664 sizeof(*pctrl->context.pads),
1665 GFP_KERNEL);
1666 if (!pctrl->context.pads)
Mika Westerberg9eb457b2014-12-04 12:32:50 +02001667 return -ENOMEM;
1668#endif
1669
Andy Shevchenko8a828572020-07-27 19:12:15 +03001670 pctrl->context.communities = devm_kcalloc(dev, pctrl->soc->ncommunities,
1671 sizeof(*pctrl->context.communities),
1672 GFP_KERNEL);
1673 if (!pctrl->context.communities)
1674 return -ENOMEM;
1675
Hans de Goedebdfbef22021-11-18 11:56:48 +01001676 cctx = &pctrl->context.communities[0];
1677 for (i = 0; i < ARRAY_SIZE(cctx->intr_lines); i++)
1678 cctx->intr_lines[i] = CHV_INVALID_HWIRQ;
1679
Mika Westerberg6e08d6b2014-11-03 13:01:33 +02001680 irq = platform_get_irq(pdev, 0);
Stephen Boyd57afe3e2019-07-30 11:15:34 -07001681 if (irq < 0)
Mika Westerberg6e08d6b2014-11-03 13:01:33 +02001682 return irq;
Mika Westerberg6e08d6b2014-11-03 13:01:33 +02001683
1684 pctrl->pctldesc = chv_pinctrl_desc;
Andy Shevchenko359164fa2020-07-29 15:02:30 +03001685 pctrl->pctldesc.name = dev_name(dev);
Andy Shevchenko293428f2020-06-09 21:24:49 +03001686 pctrl->pctldesc.pins = pctrl->soc->pins;
1687 pctrl->pctldesc.npins = pctrl->soc->npins;
Mika Westerberg6e08d6b2014-11-03 13:01:33 +02001688
Andy Shevchenko359164fa2020-07-29 15:02:30 +03001689 pctrl->pctldev = devm_pinctrl_register(dev, &pctrl->pctldesc, pctrl);
Masahiro Yamada323de9e2015-06-09 13:01:16 +09001690 if (IS_ERR(pctrl->pctldev)) {
Andy Shevchenko359164fa2020-07-29 15:02:30 +03001691 dev_err(dev, "failed to register pinctrl driver\n");
Masahiro Yamada323de9e2015-06-09 13:01:16 +09001692 return PTR_ERR(pctrl->pctldev);
Mika Westerberg6e08d6b2014-11-03 13:01:33 +02001693 }
1694
1695 ret = chv_gpio_probe(pctrl, irq);
Laxman Dewangan7cf061fa2016-02-24 14:44:07 +05301696 if (ret)
Mika Westerberg6e08d6b2014-11-03 13:01:33 +02001697 return ret;
Mika Westerberg6e08d6b2014-11-03 13:01:33 +02001698
Hans de Goedea0b02852017-03-23 14:23:25 +01001699 status = acpi_install_address_space_handler(adev->handle,
Andy Shevchenko293428f2020-06-09 21:24:49 +03001700 community->acpi_space_id,
Hans de Goedea0b02852017-03-23 14:23:25 +01001701 chv_pinctrl_mmio_access_handler,
1702 NULL, pctrl);
1703 if (ACPI_FAILURE(status))
Andy Shevchenko359164fa2020-07-29 15:02:30 +03001704 dev_err(dev, "failed to install ACPI addr space handler\n");
Hans de Goedea0b02852017-03-23 14:23:25 +01001705
Mika Westerberg6e08d6b2014-11-03 13:01:33 +02001706 platform_set_drvdata(pdev, pctrl);
1707
1708 return 0;
1709}
1710
Hans de Goedea0b02852017-03-23 14:23:25 +01001711static int chv_pinctrl_remove(struct platform_device *pdev)
1712{
Andy Shevchenko3ea2e2c2020-07-27 19:12:16 +03001713 struct intel_pinctrl *pctrl = platform_get_drvdata(pdev);
Andy Shevchenko293428f2020-06-09 21:24:49 +03001714 const struct intel_community *community = &pctrl->communities[0];
Hans de Goedea0b02852017-03-23 14:23:25 +01001715
1716 acpi_remove_address_space_handler(ACPI_COMPANION(&pdev->dev),
Andy Shevchenko293428f2020-06-09 21:24:49 +03001717 community->acpi_space_id,
Hans de Goedea0b02852017-03-23 14:23:25 +01001718 chv_pinctrl_mmio_access_handler);
1719
1720 return 0;
1721}
1722
Mika Westerberg9eb457b2014-12-04 12:32:50 +02001723#ifdef CONFIG_PM_SLEEP
Mika Westerbergd2cdf5dc2016-10-31 16:57:33 +02001724static int chv_pinctrl_suspend_noirq(struct device *dev)
Mika Westerberg9eb457b2014-12-04 12:32:50 +02001725{
Andy Shevchenko3ea2e2c2020-07-27 19:12:16 +03001726 struct intel_pinctrl *pctrl = dev_get_drvdata(dev);
Andy Shevchenko8a828572020-07-27 19:12:15 +03001727 struct intel_community_context *cctx = &pctrl->context.communities[0];
Mika Westerberg56211122016-10-31 16:57:32 +02001728 unsigned long flags;
Mika Westerberg9eb457b2014-12-04 12:32:50 +02001729 int i;
1730
Mika Westerberg56211122016-10-31 16:57:32 +02001731 raw_spin_lock_irqsave(&chv_lock, flags);
1732
Andy Shevchenko8a828572020-07-27 19:12:15 +03001733 cctx->saved_intmask = chv_pctrl_readl(pctrl, CHV_INTMASK);
Mika Westerberg9eb457b2014-12-04 12:32:50 +02001734
Andy Shevchenko293428f2020-06-09 21:24:49 +03001735 for (i = 0; i < pctrl->soc->npins; i++) {
Mika Westerberg9eb457b2014-12-04 12:32:50 +02001736 const struct pinctrl_pin_desc *desc;
Andy Shevchenko293428f2020-06-09 21:24:49 +03001737 struct intel_pad_context *ctx = &pctrl->context.pads[i];
Mika Westerberg9eb457b2014-12-04 12:32:50 +02001738
Andy Shevchenko293428f2020-06-09 21:24:49 +03001739 desc = &pctrl->soc->pins[i];
Mika Westerberg9eb457b2014-12-04 12:32:50 +02001740 if (chv_pad_locked(pctrl, desc->number))
1741 continue;
1742
Andy Shevchenko4e7293e2020-06-09 21:24:44 +03001743 ctx->padctrl0 = chv_readl(pctrl, desc->number, CHV_PADCTRL0);
1744 ctx->padctrl0 &= ~CHV_PADCTRL0_GPIORXSTATE;
Mika Westerberg9eb457b2014-12-04 12:32:50 +02001745
Andy Shevchenko4e7293e2020-06-09 21:24:44 +03001746 ctx->padctrl1 = chv_readl(pctrl, desc->number, CHV_PADCTRL1);
Mika Westerberg9eb457b2014-12-04 12:32:50 +02001747 }
1748
Mika Westerberg56211122016-10-31 16:57:32 +02001749 raw_spin_unlock_irqrestore(&chv_lock, flags);
1750
Mika Westerberg9eb457b2014-12-04 12:32:50 +02001751 return 0;
1752}
1753
Mika Westerbergd2cdf5dc2016-10-31 16:57:33 +02001754static int chv_pinctrl_resume_noirq(struct device *dev)
Mika Westerberg9eb457b2014-12-04 12:32:50 +02001755{
Andy Shevchenko3ea2e2c2020-07-27 19:12:16 +03001756 struct intel_pinctrl *pctrl = dev_get_drvdata(dev);
Andy Shevchenko8a828572020-07-27 19:12:15 +03001757 struct intel_community_context *cctx = &pctrl->context.communities[0];
Mika Westerberg56211122016-10-31 16:57:32 +02001758 unsigned long flags;
Mika Westerberg9eb457b2014-12-04 12:32:50 +02001759 int i;
1760
Mika Westerberg56211122016-10-31 16:57:32 +02001761 raw_spin_lock_irqsave(&chv_lock, flags);
1762
Mika Westerberg9eb457b2014-12-04 12:32:50 +02001763 /*
1764 * Mask all interrupts before restoring per-pin configuration
1765 * registers because we don't know in which state BIOS left them
1766 * upon exiting suspend.
1767 */
Andy Shevchenko99fd6512020-06-09 21:24:45 +03001768 chv_pctrl_writel(pctrl, CHV_INTMASK, 0x0000);
Mika Westerberg9eb457b2014-12-04 12:32:50 +02001769
Andy Shevchenko293428f2020-06-09 21:24:49 +03001770 for (i = 0; i < pctrl->soc->npins; i++) {
Mika Westerberg9eb457b2014-12-04 12:32:50 +02001771 const struct pinctrl_pin_desc *desc;
Andy Shevchenko293428f2020-06-09 21:24:49 +03001772 struct intel_pad_context *ctx = &pctrl->context.pads[i];
Mika Westerberg9eb457b2014-12-04 12:32:50 +02001773 u32 val;
1774
Andy Shevchenko293428f2020-06-09 21:24:49 +03001775 desc = &pctrl->soc->pins[i];
Mika Westerberg9eb457b2014-12-04 12:32:50 +02001776 if (chv_pad_locked(pctrl, desc->number))
1777 continue;
1778
Mika Westerberg9eb457b2014-12-04 12:32:50 +02001779 /* Only restore if our saved state differs from the current */
Andy Shevchenko4e7293e2020-06-09 21:24:44 +03001780 val = chv_readl(pctrl, desc->number, CHV_PADCTRL0);
1781 val &= ~CHV_PADCTRL0_GPIORXSTATE;
Mika Westerberg9eb457b2014-12-04 12:32:50 +02001782 if (ctx->padctrl0 != val) {
Andy Shevchenkobfc8a4b2020-06-09 21:24:46 +03001783 chv_writel(pctrl, desc->number, CHV_PADCTRL0, ctx->padctrl0);
Mika Westerberg9eb457b2014-12-04 12:32:50 +02001784 dev_dbg(pctrl->dev, "restored pin %2u ctrl0 0x%08x\n",
Andy Shevchenko4e7293e2020-06-09 21:24:44 +03001785 desc->number, chv_readl(pctrl, desc->number, CHV_PADCTRL0));
Mika Westerberg9eb457b2014-12-04 12:32:50 +02001786 }
1787
Andy Shevchenko4e7293e2020-06-09 21:24:44 +03001788 val = chv_readl(pctrl, desc->number, CHV_PADCTRL1);
Mika Westerberg9eb457b2014-12-04 12:32:50 +02001789 if (ctx->padctrl1 != val) {
Andy Shevchenkobfc8a4b2020-06-09 21:24:46 +03001790 chv_writel(pctrl, desc->number, CHV_PADCTRL1, ctx->padctrl1);
Mika Westerberg9eb457b2014-12-04 12:32:50 +02001791 dev_dbg(pctrl->dev, "restored pin %2u ctrl1 0x%08x\n",
Andy Shevchenko4e7293e2020-06-09 21:24:44 +03001792 desc->number, chv_readl(pctrl, desc->number, CHV_PADCTRL1));
Mika Westerberg9eb457b2014-12-04 12:32:50 +02001793 }
1794 }
1795
1796 /*
1797 * Now that all pins are restored to known state, we can restore
1798 * the interrupt mask register as well.
1799 */
Andy Shevchenko99fd6512020-06-09 21:24:45 +03001800 chv_pctrl_writel(pctrl, CHV_INTSTAT, 0xffff);
Andy Shevchenko8a828572020-07-27 19:12:15 +03001801 chv_pctrl_writel(pctrl, CHV_INTMASK, cctx->saved_intmask);
Mika Westerberg9eb457b2014-12-04 12:32:50 +02001802
Mika Westerberg56211122016-10-31 16:57:32 +02001803 raw_spin_unlock_irqrestore(&chv_lock, flags);
1804
Mika Westerberg9eb457b2014-12-04 12:32:50 +02001805 return 0;
1806}
1807#endif
1808
1809static const struct dev_pm_ops chv_pinctrl_pm_ops = {
Mika Westerbergd2cdf5dc2016-10-31 16:57:33 +02001810 SET_NOIRQ_SYSTEM_SLEEP_PM_OPS(chv_pinctrl_suspend_noirq,
1811 chv_pinctrl_resume_noirq)
Mika Westerberg9eb457b2014-12-04 12:32:50 +02001812};
1813
Mika Westerberg6e08d6b2014-11-03 13:01:33 +02001814static const struct acpi_device_id chv_pinctrl_acpi_match[] = {
Andy Shevchenko293428f2020-06-09 21:24:49 +03001815 { "INT33FF", (kernel_ulong_t)chv_soc_data },
Mika Westerberg6e08d6b2014-11-03 13:01:33 +02001816 { }
1817};
1818MODULE_DEVICE_TABLE(acpi, chv_pinctrl_acpi_match);
1819
1820static struct platform_driver chv_pinctrl_driver = {
1821 .probe = chv_pinctrl_probe,
Hans de Goedea0b02852017-03-23 14:23:25 +01001822 .remove = chv_pinctrl_remove,
Mika Westerberg6e08d6b2014-11-03 13:01:33 +02001823 .driver = {
1824 .name = "cherryview-pinctrl",
Mika Westerberg9eb457b2014-12-04 12:32:50 +02001825 .pm = &chv_pinctrl_pm_ops,
Mika Westerberg6e08d6b2014-11-03 13:01:33 +02001826 .acpi_match_table = chv_pinctrl_acpi_match,
1827 },
1828};
1829
1830static int __init chv_pinctrl_init(void)
1831{
1832 return platform_driver_register(&chv_pinctrl_driver);
1833}
1834subsys_initcall(chv_pinctrl_init);
1835
1836static void __exit chv_pinctrl_exit(void)
1837{
1838 platform_driver_unregister(&chv_pinctrl_driver);
1839}
1840module_exit(chv_pinctrl_exit);
1841
1842MODULE_AUTHOR("Mika Westerberg <mika.westerberg@linux.intel.com>");
1843MODULE_DESCRIPTION("Intel Cherryview/Braswell pinctrl driver");
1844MODULE_LICENSE("GPL v2");