blob: 364f56c3991db804d16f08466b3fd9579aae89f3 [file] [log] [blame]
Mathias Nymana5d811b2013-06-18 14:33:02 +03001/*
2 * Pinctrl GPIO driver for Intel Baytrail
3 * Copyright (c) 2012-2013, Intel Corporation.
4 *
5 * Author: Mathias Nyman <mathias.nyman@linux.intel.com>
6 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms and conditions of the GNU General Public License,
9 * version 2, as published by the Free Software Foundation.
10 *
11 * This program is distributed in the hope it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 * more details.
Mathias Nymana5d811b2013-06-18 14:33:02 +030015 */
16
17#include <linux/kernel.h>
18#include <linux/module.h>
19#include <linux/init.h>
20#include <linux/types.h>
21#include <linux/bitops.h>
22#include <linux/interrupt.h>
Linus Walleijbf9a5c92015-12-08 00:03:44 +010023#include <linux/gpio/driver.h>
Mathias Nymana5d811b2013-06-18 14:33:02 +030024#include <linux/acpi.h>
Mathias Nymana5d811b2013-06-18 14:33:02 +030025#include <linux/platform_device.h>
26#include <linux/seq_file.h>
27#include <linux/io.h>
28#include <linux/pm_runtime.h>
29#include <linux/pinctrl/pinctrl.h>
30
31/* memory mapped register offsets */
32#define BYT_CONF0_REG 0x000
33#define BYT_CONF1_REG 0x004
34#define BYT_VAL_REG 0x008
35#define BYT_DFT_REG 0x00c
36#define BYT_INT_STAT_REG 0x800
37
38/* BYT_CONF0_REG register bits */
Mika Westerberg3ff95882014-05-16 12:18:29 +030039#define BYT_IODEN BIT(31)
Eric Ernstff998352014-06-12 11:06:20 -070040#define BYT_DIRECT_IRQ_EN BIT(27)
Mathias Nymana5d811b2013-06-18 14:33:02 +030041#define BYT_TRIG_NEG BIT(26)
42#define BYT_TRIG_POS BIT(25)
43#define BYT_TRIG_LVL BIT(24)
Mika Westerberg3ff95882014-05-16 12:18:29 +030044#define BYT_PULL_STR_SHIFT 9
45#define BYT_PULL_STR_MASK (3 << BYT_PULL_STR_SHIFT)
46#define BYT_PULL_STR_2K (0 << BYT_PULL_STR_SHIFT)
47#define BYT_PULL_STR_10K (1 << BYT_PULL_STR_SHIFT)
48#define BYT_PULL_STR_20K (2 << BYT_PULL_STR_SHIFT)
49#define BYT_PULL_STR_40K (3 << BYT_PULL_STR_SHIFT)
50#define BYT_PULL_ASSIGN_SHIFT 7
51#define BYT_PULL_ASSIGN_MASK (3 << BYT_PULL_ASSIGN_SHIFT)
52#define BYT_PULL_ASSIGN_UP (1 << BYT_PULL_ASSIGN_SHIFT)
53#define BYT_PULL_ASSIGN_DOWN (2 << BYT_PULL_ASSIGN_SHIFT)
Mathias Nymana5d811b2013-06-18 14:33:02 +030054#define BYT_PIN_MUX 0x07
55
56/* BYT_VAL_REG register bits */
57#define BYT_INPUT_EN BIT(2) /* 0: input enabled (active low)*/
58#define BYT_OUTPUT_EN BIT(1) /* 0: output enabled (active low)*/
59#define BYT_LEVEL BIT(0)
60
61#define BYT_DIR_MASK (BIT(1) | BIT(2))
62#define BYT_TRIG_MASK (BIT(26) | BIT(25) | BIT(24))
63
Mika Westerbergfcc18de2015-02-23 14:53:13 +020064#define BYT_CONF0_RESTORE_MASK (BYT_DIRECT_IRQ_EN | BYT_TRIG_MASK | \
65 BYT_PIN_MUX)
66#define BYT_VAL_RESTORE_MASK (BYT_DIR_MASK | BYT_LEVEL)
67
Mathias Nymana5d811b2013-06-18 14:33:02 +030068#define BYT_NGPIO_SCORE 102
69#define BYT_NGPIO_NCORE 28
70#define BYT_NGPIO_SUS 44
71
Chew, Kean Ho42bd0072014-03-06 21:59:49 +080072#define BYT_SCORE_ACPI_UID "1"
73#define BYT_NCORE_ACPI_UID "2"
74#define BYT_SUS_ACPI_UID "3"
75
Cristina Ciocanc8f5c4c2016-04-01 14:00:02 +030076struct byt_gpio_pin_context {
77 u32 conf0;
78 u32 val;
79};
Mathias Nymana5d811b2013-06-18 14:33:02 +030080
Cristina Ciocanc8f5c4c2016-04-01 14:00:02 +030081struct byt_simple_func_mux {
82 const char *name;
83 unsigned short func;
84};
85
86struct byt_mixed_func_mux {
87 const char *name;
88 const unsigned short *func_values;
89};
90
91struct byt_pingroup {
92 const char *name;
93 const unsigned int *pins;
94 size_t npins;
95 unsigned short has_simple_funcs;
96 union {
97 const struct byt_simple_func_mux *simple_funcs;
98 const struct byt_mixed_func_mux *mixed_funcs;
99 };
100 size_t nfuncs;
101};
102
103struct byt_function {
104 const char *name;
105 const char * const *groups;
106 size_t ngroups;
107};
108
109struct byt_community {
110 unsigned int pin_base;
111 size_t npins;
112 const unsigned int *pad_map;
113 void __iomem *reg_base;
114};
115
116#define SIMPLE_FUNC(n, f) \
117 { \
118 .name = (n), \
119 .func = (f), \
120 }
121#define MIXED_FUNC(n, f) \
122 { \
123 .name = (n), \
124 .func_values = (f), \
125 }
126
127#define PIN_GROUP_SIMPLE(n, p, f) \
128 { \
129 .name = (n), \
130 .pins = (p), \
131 .npins = ARRAY_SIZE((p)), \
132 .has_simple_funcs = 1, \
133 .simple_funcs = (f), \
134 .nfuncs = ARRAY_SIZE((f)), \
135 }
136#define PIN_GROUP_MIXED(n, p, f) \
137 { \
138 .name = (n), \
139 .pins = (p), \
140 .npins = ARRAY_SIZE((p)), \
141 .has_simple_funcs = 0, \
142 .mixed_funcs = (f), \
143 .nfuncs = ARRAY_SIZE((f)), \
144 }
145
146#define FUNCTION(n, g) \
147 { \
148 .name = (n), \
149 .groups = (g), \
150 .ngroups = ARRAY_SIZE((g)), \
151 }
152
153#define COMMUNITY(p, n, map) \
154 { \
155 .pin_base = (p), \
156 .npins = (n), \
157 .pad_map = (map),\
158 }
159
160struct byt_pinctrl_soc_data {
161 const char *uid;
162 const struct pinctrl_pin_desc *pins;
163 size_t npins;
164 const struct byt_pingroup *groups;
165 size_t ngroups;
166 const struct byt_function *functions;
167 size_t nfunctions;
168 const struct byt_community *communities;
169 size_t ncommunities;
170};
171
172/* SCORE pins, aka GPIOC_<pin_no> or GPIO_S0_SC[<pin_no>] */
173static const struct pinctrl_pin_desc byt_score_pins[] = {
174 PINCTRL_PIN(0, "SATA_GP0"),
175 PINCTRL_PIN(1, "SATA_GP1"),
176 PINCTRL_PIN(2, "SATA_LED#"),
177 PINCTRL_PIN(3, "PCIE_CLKREQ0"),
178 PINCTRL_PIN(4, "PCIE_CLKREQ1"),
179 PINCTRL_PIN(5, "PCIE_CLKREQ2"),
180 PINCTRL_PIN(6, "PCIE_CLKREQ3"),
181 PINCTRL_PIN(7, "SD3_WP"),
182 PINCTRL_PIN(8, "HDA_RST"),
183 PINCTRL_PIN(9, "HDA_SYNC"),
184 PINCTRL_PIN(10, "HDA_CLK"),
185 PINCTRL_PIN(11, "HDA_SDO"),
186 PINCTRL_PIN(12, "HDA_SDI0"),
187 PINCTRL_PIN(13, "HDA_SDI1"),
188 PINCTRL_PIN(14, "GPIO_S0_SC14"),
189 PINCTRL_PIN(15, "GPIO_S0_SC15"),
190 PINCTRL_PIN(16, "MMC1_CLK"),
191 PINCTRL_PIN(17, "MMC1_D0"),
192 PINCTRL_PIN(18, "MMC1_D1"),
193 PINCTRL_PIN(19, "MMC1_D2"),
194 PINCTRL_PIN(20, "MMC1_D3"),
195 PINCTRL_PIN(21, "MMC1_D4"),
196 PINCTRL_PIN(22, "MMC1_D5"),
197 PINCTRL_PIN(23, "MMC1_D6"),
198 PINCTRL_PIN(24, "MMC1_D7"),
199 PINCTRL_PIN(25, "MMC1_CMD"),
200 PINCTRL_PIN(26, "MMC1_RST"),
201 PINCTRL_PIN(27, "SD2_CLK"),
202 PINCTRL_PIN(28, "SD2_D0"),
203 PINCTRL_PIN(29, "SD2_D1"),
204 PINCTRL_PIN(30, "SD2_D2"),
205 PINCTRL_PIN(31, "SD2_D3_CD"),
206 PINCTRL_PIN(32, "SD2_CMD"),
207 PINCTRL_PIN(33, "SD3_CLK"),
208 PINCTRL_PIN(34, "SD3_D0"),
209 PINCTRL_PIN(35, "SD3_D1"),
210 PINCTRL_PIN(36, "SD3_D2"),
211 PINCTRL_PIN(37, "SD3_D3"),
212 PINCTRL_PIN(38, "SD3_CD"),
213 PINCTRL_PIN(39, "SD3_CMD"),
214 PINCTRL_PIN(40, "SD3_1P8EN"),
215 PINCTRL_PIN(41, "SD3_PWREN#"),
216 PINCTRL_PIN(42, "ILB_LPC_AD0"),
217 PINCTRL_PIN(43, "ILB_LPC_AD1"),
218 PINCTRL_PIN(44, "ILB_LPC_AD2"),
219 PINCTRL_PIN(45, "ILB_LPC_AD3"),
220 PINCTRL_PIN(46, "ILB_LPC_FRAME"),
221 PINCTRL_PIN(47, "ILB_LPC_CLK0"),
222 PINCTRL_PIN(48, "ILB_LPC_CLK1"),
223 PINCTRL_PIN(49, "ILB_LPC_CLKRUN"),
224 PINCTRL_PIN(50, "ILB_LPC_SERIRQ"),
225 PINCTRL_PIN(51, "PCU_SMB_DATA"),
226 PINCTRL_PIN(52, "PCU_SMB_CLK"),
227 PINCTRL_PIN(53, "PCU_SMB_ALERT"),
228 PINCTRL_PIN(54, "ILB_8254_SPKR"),
229 PINCTRL_PIN(55, "GPIO_S0_SC55"),
230 PINCTRL_PIN(56, "GPIO_S0_SC56"),
231 PINCTRL_PIN(57, "GPIO_S0_SC57"),
232 PINCTRL_PIN(58, "GPIO_S0_SC58"),
233 PINCTRL_PIN(59, "GPIO_S0_SC59"),
234 PINCTRL_PIN(60, "GPIO_S0_SC60"),
235 PINCTRL_PIN(61, "GPIO_S0_SC61"),
236 PINCTRL_PIN(62, "LPE_I2S2_CLK"),
237 PINCTRL_PIN(63, "LPE_I2S2_FRM"),
238 PINCTRL_PIN(64, "LPE_I2S2_DATAIN"),
239 PINCTRL_PIN(65, "LPE_I2S2_DATAOUT"),
240 PINCTRL_PIN(66, "SIO_SPI_CS"),
241 PINCTRL_PIN(67, "SIO_SPI_MISO"),
242 PINCTRL_PIN(68, "SIO_SPI_MOSI"),
243 PINCTRL_PIN(69, "SIO_SPI_CLK"),
244 PINCTRL_PIN(70, "SIO_UART1_RXD"),
245 PINCTRL_PIN(71, "SIO_UART1_TXD"),
246 PINCTRL_PIN(72, "SIO_UART1_RTS"),
247 PINCTRL_PIN(73, "SIO_UART1_CTS"),
248 PINCTRL_PIN(74, "SIO_UART2_RXD"),
249 PINCTRL_PIN(75, "SIO_UART2_TXD"),
250 PINCTRL_PIN(76, "SIO_UART2_RTS"),
251 PINCTRL_PIN(77, "SIO_UART2_CTS"),
252 PINCTRL_PIN(78, "SIO_I2C0_DATA"),
253 PINCTRL_PIN(79, "SIO_I2C0_CLK"),
254 PINCTRL_PIN(80, "SIO_I2C1_DATA"),
255 PINCTRL_PIN(81, "SIO_I2C1_CLK"),
256 PINCTRL_PIN(82, "SIO_I2C2_DATA"),
257 PINCTRL_PIN(83, "SIO_I2C2_CLK"),
258 PINCTRL_PIN(84, "SIO_I2C3_DATA"),
259 PINCTRL_PIN(85, "SIO_I2C3_CLK"),
260 PINCTRL_PIN(86, "SIO_I2C4_DATA"),
261 PINCTRL_PIN(87, "SIO_I2C4_CLK"),
262 PINCTRL_PIN(88, "SIO_I2C5_DATA"),
263 PINCTRL_PIN(89, "SIO_I2C5_CLK"),
264 PINCTRL_PIN(90, "SIO_I2C6_DATA"),
265 PINCTRL_PIN(91, "SIO_I2C6_CLK"),
266 PINCTRL_PIN(92, "GPIO_S0_SC92"),
267 PINCTRL_PIN(93, "GPIO_S0_SC93"),
268 PINCTRL_PIN(94, "SIO_PWM0"),
269 PINCTRL_PIN(95, "SIO_PWM1"),
270 PINCTRL_PIN(96, "PMC_PLT_CLK0"),
271 PINCTRL_PIN(97, "PMC_PLT_CLK1"),
272 PINCTRL_PIN(98, "PMC_PLT_CLK2"),
273 PINCTRL_PIN(99, "PMC_PLT_CLK3"),
274 PINCTRL_PIN(100, "PMC_PLT_CLK4"),
275 PINCTRL_PIN(101, "PMC_PLT_CLK5"),
276};
Mathias Nymana5d811b2013-06-18 14:33:02 +0300277
278static unsigned const score_pins[BYT_NGPIO_SCORE] = {
279 85, 89, 93, 96, 99, 102, 98, 101, 34, 37,
280 36, 38, 39, 35, 40, 84, 62, 61, 64, 59,
281 54, 56, 60, 55, 63, 57, 51, 50, 53, 47,
282 52, 49, 48, 43, 46, 41, 45, 42, 58, 44,
283 95, 105, 70, 68, 67, 66, 69, 71, 65, 72,
284 86, 90, 88, 92, 103, 77, 79, 83, 78, 81,
285 80, 82, 13, 12, 15, 14, 17, 18, 19, 16,
286 2, 1, 0, 4, 6, 7, 9, 8, 33, 32,
287 31, 30, 29, 27, 25, 28, 26, 23, 21, 20,
288 24, 22, 5, 3, 10, 11, 106, 87, 91, 104,
289 97, 100,
290};
291
Cristina Ciocanc8f5c4c2016-04-01 14:00:02 +0300292static const unsigned int byt_score_pins_map[BYT_NGPIO_SCORE] = {
293 85, 89, 93, 96, 99, 102, 98, 101, 34, 37,
294 36, 38, 39, 35, 40, 84, 62, 61, 64, 59,
295 54, 56, 60, 55, 63, 57, 51, 50, 53, 47,
296 52, 49, 48, 43, 46, 41, 45, 42, 58, 44,
297 95, 105, 70, 68, 67, 66, 69, 71, 65, 72,
298 86, 90, 88, 92, 103, 77, 79, 83, 78, 81,
299 80, 82, 13, 12, 15, 14, 17, 18, 19, 16,
300 2, 1, 0, 4, 6, 7, 9, 8, 33, 32,
301 31, 30, 29, 27, 25, 28, 26, 23, 21, 20,
302 24, 22, 5, 3, 10, 11, 106, 87, 91, 104,
303 97, 100,
Mathias Nymana5d811b2013-06-18 14:33:02 +0300304};
305
Cristina Ciocanc8f5c4c2016-04-01 14:00:02 +0300306/* SCORE groups */
307static const unsigned int byt_score_uart1_pins[] = { 70, 71, 72, 73 };
308static const unsigned int byt_score_uart2_pins[] = { 74, 75, 76, 77 };
309static const struct byt_simple_func_mux byt_score_uart_mux[] = {
310 SIMPLE_FUNC("uart", 1),
311};
312
313static const unsigned int byt_score_pwm0_pins[] = { 94 };
314static const unsigned int byt_score_pwm1_pins[] = { 95 };
315static const struct byt_simple_func_mux byt_score_pwm_mux[] = {
316 SIMPLE_FUNC("pwm", 1),
317};
318
319static const unsigned int byt_score_sio_spi_pins[] = { 66, 67, 68, 69 };
320static const struct byt_simple_func_mux byt_score_spi_mux[] = {
321 SIMPLE_FUNC("spi", 1),
322};
323
324static const unsigned int byt_score_i2c5_pins[] = { 88, 89 };
325static const unsigned int byt_score_i2c6_pins[] = { 90, 91 };
326static const unsigned int byt_score_i2c4_pins[] = { 86, 87 };
327static const unsigned int byt_score_i2c3_pins[] = { 84, 85 };
328static const unsigned int byt_score_i2c2_pins[] = { 82, 83 };
329static const unsigned int byt_score_i2c1_pins[] = { 80, 81 };
330static const unsigned int byt_score_i2c0_pins[] = { 78, 79 };
331static const struct byt_simple_func_mux byt_score_i2c_mux[] = {
332 SIMPLE_FUNC("i2c", 1),
333};
334
335static const unsigned int byt_score_ssp0_pins[] = { 8, 9, 10, 11 };
336static const unsigned int byt_score_ssp1_pins[] = { 12, 13, 14, 15 };
337static const unsigned int byt_score_ssp2_pins[] = { 62, 63, 64, 65 };
338static const struct byt_simple_func_mux byt_score_ssp_mux[] = {
339 SIMPLE_FUNC("ssp", 1),
340};
341
342static const unsigned int byt_score_sdcard_pins[] = {
343 7, 33, 34, 35, 36, 37, 38, 39, 40, 41,
344};
345static const unsigned short byt_score_sdcard_mux_values[] = {
346 2, 1, 1, 1, 1, 1, 1, 1, 1, 1,
347};
348static const struct byt_mixed_func_mux byt_score_sdcard_mux[] = {
349 MIXED_FUNC("sdcard", byt_score_sdcard_mux_values),
350};
351
352static const unsigned int byt_score_sdio_pins[] = { 27, 28, 29, 30, 31, 32 };
353static const struct byt_simple_func_mux byt_score_sdio_mux[] = {
354 SIMPLE_FUNC("sdio", 1),
355};
356
357static const unsigned int byt_score_emmc_pins[] = {
358 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26,
359};
360static const struct byt_simple_func_mux byt_score_emmc_mux[] = {
361 SIMPLE_FUNC("emmc", 1),
362};
363
364static const unsigned int byt_score_ilb_lpc_pins[] = {
365 42, 43, 44, 45, 46, 47, 48, 49, 50,
366};
367static const struct byt_simple_func_mux byt_score_lpc_mux[] = {
368 SIMPLE_FUNC("lpc", 1),
369};
370
371static const unsigned int byt_score_sata_pins[] = { 0, 1, 2 };
372static const struct byt_simple_func_mux byt_score_sata_mux[] = {
373 SIMPLE_FUNC("sata", 1),
374};
375
376static const unsigned int byt_score_plt_clk0_pins[] = { 96 };
377static const unsigned int byt_score_plt_clk1_pins[] = { 97 };
378static const unsigned int byt_score_plt_clk2_pins[] = { 98 };
379static const unsigned int byt_score_plt_clk4_pins[] = { 99 };
380static const unsigned int byt_score_plt_clk5_pins[] = { 100 };
381static const unsigned int byt_score_plt_clk3_pins[] = { 101 };
382static const struct byt_simple_func_mux byt_score_plt_clk_mux[] = {
383 SIMPLE_FUNC("plt_clk", 1),
384};
385
386static const unsigned int byt_score_smbus_pins[] = { 51, 52, 53 };
387static const struct byt_simple_func_mux byt_score_smbus_mux[] = {
388 SIMPLE_FUNC("smbus", 1),
389};
390
391static const struct byt_pingroup byt_score_groups[] = {
392 PIN_GROUP_SIMPLE("uart1_grp",
393 byt_score_uart1_pins, byt_score_uart_mux),
394 PIN_GROUP_SIMPLE("uart2_grp",
395 byt_score_uart2_pins, byt_score_uart_mux),
396 PIN_GROUP_SIMPLE("pwm0_grp",
397 byt_score_pwm0_pins, byt_score_pwm_mux),
398 PIN_GROUP_SIMPLE("pwm1_grp",
399 byt_score_pwm1_pins, byt_score_pwm_mux),
400 PIN_GROUP_SIMPLE("ssp2_grp",
401 byt_score_ssp2_pins, byt_score_pwm_mux),
402 PIN_GROUP_SIMPLE("sio_spi_grp",
403 byt_score_sio_spi_pins, byt_score_spi_mux),
404 PIN_GROUP_SIMPLE("i2c5_grp",
405 byt_score_i2c5_pins, byt_score_i2c_mux),
406 PIN_GROUP_SIMPLE("i2c6_grp",
407 byt_score_i2c6_pins, byt_score_i2c_mux),
408 PIN_GROUP_SIMPLE("i2c4_grp",
409 byt_score_i2c4_pins, byt_score_i2c_mux),
410 PIN_GROUP_SIMPLE("i2c3_grp",
411 byt_score_i2c3_pins, byt_score_i2c_mux),
412 PIN_GROUP_SIMPLE("i2c2_grp",
413 byt_score_i2c2_pins, byt_score_i2c_mux),
414 PIN_GROUP_SIMPLE("i2c1_grp",
415 byt_score_i2c1_pins, byt_score_i2c_mux),
416 PIN_GROUP_SIMPLE("i2c0_grp",
417 byt_score_i2c0_pins, byt_score_i2c_mux),
418 PIN_GROUP_SIMPLE("ssp0_grp",
419 byt_score_ssp0_pins, byt_score_ssp_mux),
420 PIN_GROUP_SIMPLE("ssp1_grp",
421 byt_score_ssp1_pins, byt_score_ssp_mux),
422 PIN_GROUP_MIXED("sdcard_grp",
423 byt_score_sdcard_pins, byt_score_sdcard_mux),
424 PIN_GROUP_SIMPLE("sdio_grp",
425 byt_score_sdio_pins, byt_score_sdio_mux),
426 PIN_GROUP_SIMPLE("emmc_grp",
427 byt_score_emmc_pins, byt_score_emmc_mux),
428 PIN_GROUP_SIMPLE("lpc_grp",
429 byt_score_ilb_lpc_pins, byt_score_lpc_mux),
430 PIN_GROUP_SIMPLE("sata_grp",
431 byt_score_sata_pins, byt_score_sata_mux),
432 PIN_GROUP_SIMPLE("plt_clk0_grp",
433 byt_score_plt_clk0_pins, byt_score_plt_clk_mux),
434 PIN_GROUP_SIMPLE("plt_clk1_grp",
435 byt_score_plt_clk1_pins, byt_score_plt_clk_mux),
436 PIN_GROUP_SIMPLE("plt_clk2_grp",
437 byt_score_plt_clk2_pins, byt_score_plt_clk_mux),
438 PIN_GROUP_SIMPLE("plt_clk3_grp",
439 byt_score_plt_clk3_pins, byt_score_plt_clk_mux),
440 PIN_GROUP_SIMPLE("plt_clk4_grp",
441 byt_score_plt_clk4_pins, byt_score_plt_clk_mux),
442 PIN_GROUP_SIMPLE("plt_clk5_grp",
443 byt_score_plt_clk5_pins, byt_score_plt_clk_mux),
444 PIN_GROUP_SIMPLE("smbus_grp",
445 byt_score_smbus_pins, byt_score_smbus_mux),
446};
447
448static const char * const byt_score_uart_groups[] = {
449 "uart1_grp", "uart2_grp",
450};
451static const char * const byt_score_pwm_groups[] = {
452 "pwm0_grp", "pwm1_grp",
453};
454static const char * const byt_score_ssp_groups[] = {
455 "ssp0_grp", "ssp1_grp", "ssp2_grp",
456};
457static const char * const byt_score_spi_groups[] = { "sio_spi_grp" };
458static const char * const byt_score_i2c_groups[] = {
459 "i2c0_grp", "i2c1_grp", "i2c2_grp", "i2c3_grp", "i2c4_grp", "i2c5_grp",
460 "i2c6_grp",
461};
462static const char * const byt_score_sdcard_groups[] = { "sdcard_grp" };
463static const char * const byt_score_sdio_groups[] = { "sdio_grp" };
464static const char * const byt_score_emmc_groups[] = { "emmc_grp" };
465static const char * const byt_score_lpc_groups[] = { "lpc_grp" };
466static const char * const byt_score_sata_groups[] = { "sata_grp" };
467static const char * const byt_score_plt_clk_groups[] = {
468 "plt_clk0_grp", "plt_clk1_grp", "plt_clk2_grp", "plt_clk3_grp",
469 "plt_clk4_grp", "plt_clk5_grp",
470};
471static const char * const byt_score_smbus_groups[] = { "smbus_grp" };
472static const char * const byt_score_gpio_groups[] = {
473 "uart1_grp", "uart2_grp", "pwm0_grp", "pwm1_grp", "ssp0_grp",
474 "ssp1_grp", "ssp2_grp", "sio_spi_grp", "i2c0_grp", "i2c1_grp",
475 "i2c2_grp", "i2c3_grp", "i2c4_grp", "i2c5_grp", "i2c6_grp",
476 "sdcard_grp", "sdio_grp", "emmc_grp", "lpc_grp", "sata_grp",
477 "plt_clk0_grp", "plt_clk1_grp", "plt_clk2_grp", "plt_clk3_grp",
478 "plt_clk4_grp", "plt_clk5_grp", "smbus_grp",
479
480};
481
482static const struct byt_function byt_score_functions[] = {
483 FUNCTION("uart", byt_score_uart_groups),
484 FUNCTION("pwm", byt_score_pwm_groups),
485 FUNCTION("ssp", byt_score_ssp_groups),
486 FUNCTION("spi", byt_score_spi_groups),
487 FUNCTION("i2c", byt_score_i2c_groups),
488 FUNCTION("sdcard", byt_score_sdcard_groups),
489 FUNCTION("sdio", byt_score_sdio_groups),
490 FUNCTION("emmc", byt_score_emmc_groups),
491 FUNCTION("lpc", byt_score_lpc_groups),
492 FUNCTION("sata", byt_score_sata_groups),
493 FUNCTION("plt_clk", byt_score_plt_clk_groups),
494 FUNCTION("smbus", byt_score_smbus_groups),
495 FUNCTION("gpio", byt_score_gpio_groups),
496};
497
498static const struct byt_community byt_score_communities[] = {
499 COMMUNITY(0, BYT_NGPIO_SCORE, byt_score_pins_map),
500};
501
502static const struct byt_pinctrl_soc_data byt_score_soc_data = {
503 .uid = BYT_SCORE_ACPI_UID,
504 .pins = byt_score_pins,
505 .npins = ARRAY_SIZE(byt_score_pins),
506 .groups = byt_score_groups,
507 .ngroups = ARRAY_SIZE(byt_score_groups),
508 .functions = byt_score_functions,
509 .nfunctions = ARRAY_SIZE(byt_score_functions),
510 .communities = byt_score_communities,
511 .ncommunities = ARRAY_SIZE(byt_score_communities),
512};
513
514/* SUS pins, aka GPIOS_<pin_no> or GPIO_S5[<pin_no>] */
515static const struct pinctrl_pin_desc byt_sus_pins[] = {
516 PINCTRL_PIN(0, "GPIO_S50"),
517 PINCTRL_PIN(1, "GPIO_S51"),
518 PINCTRL_PIN(2, "GPIO_S52"),
519 PINCTRL_PIN(3, "GPIO_S53"),
520 PINCTRL_PIN(4, "GPIO_S54"),
521 PINCTRL_PIN(5, "GPIO_S55"),
522 PINCTRL_PIN(6, "GPIO_S56"),
523 PINCTRL_PIN(7, "GPIO_S57"),
524 PINCTRL_PIN(8, "GPIO_S58"),
525 PINCTRL_PIN(9, "GPIO_S59"),
526 PINCTRL_PIN(10, "GPIO_S510"),
527 PINCTRL_PIN(11, "PMC_SUSPWRDNACK"),
528 PINCTRL_PIN(12, "PMC_SUSCLK0"),
529 PINCTRL_PIN(13, "GPIO_S513"),
530 PINCTRL_PIN(14, "USB_ULPI_RST"),
531 PINCTRL_PIN(15, "PMC_WAKE_PCIE0#"),
532 PINCTRL_PIN(16, "PMC_PWRBTN"),
533 PINCTRL_PIN(17, "GPIO_S517"),
534 PINCTRL_PIN(18, "PMC_SUS_STAT"),
535 PINCTRL_PIN(19, "USB_OC0"),
536 PINCTRL_PIN(20, "USB_OC1"),
537 PINCTRL_PIN(21, "PCU_SPI_CS1"),
538 PINCTRL_PIN(22, "GPIO_S522"),
539 PINCTRL_PIN(23, "GPIO_S523"),
540 PINCTRL_PIN(24, "GPIO_S524"),
541 PINCTRL_PIN(25, "GPIO_S525"),
542 PINCTRL_PIN(26, "GPIO_S526"),
543 PINCTRL_PIN(27, "GPIO_S527"),
544 PINCTRL_PIN(28, "GPIO_S528"),
545 PINCTRL_PIN(29, "GPIO_S529"),
546 PINCTRL_PIN(30, "GPIO_S530"),
547 PINCTRL_PIN(31, "USB_ULPI_CLK"),
548 PINCTRL_PIN(32, "USB_ULPI_DATA0"),
549 PINCTRL_PIN(33, "USB_ULPI_DATA1"),
550 PINCTRL_PIN(34, "USB_ULPI_DATA2"),
551 PINCTRL_PIN(35, "USB_ULPI_DATA3"),
552 PINCTRL_PIN(36, "USB_ULPI_DATA4"),
553 PINCTRL_PIN(37, "USB_ULPI_DATA5"),
554 PINCTRL_PIN(38, "USB_ULPI_DATA6"),
555 PINCTRL_PIN(39, "USB_ULPI_DATA7"),
556 PINCTRL_PIN(40, "USB_ULPI_DIR"),
557 PINCTRL_PIN(41, "USB_ULPI_NXT"),
558 PINCTRL_PIN(42, "USB_ULPI_STP"),
559 PINCTRL_PIN(43, "USB_ULPI_REFCLK"),
560};
561
562static const unsigned int sus_pins[BYT_NGPIO_SUS] = {
Mathias Nymana5d811b2013-06-18 14:33:02 +0300563 29, 33, 30, 31, 32, 34, 36, 35, 38, 37,
564 18, 7, 11, 20, 17, 1, 8, 10, 19, 12,
565 0, 2, 23, 39, 28, 27, 22, 21, 24, 25,
566 26, 51, 56, 54, 49, 55, 48, 57, 50, 58,
567 52, 53, 59, 40,
568};
569
Cristina Ciocanc8f5c4c2016-04-01 14:00:02 +0300570static const unsigned int byt_sus_pins_map[BYT_NGPIO_SUS] = {
571 29, 33, 30, 31, 32, 34, 36, 35, 38, 37,
572 18, 7, 11, 20, 17, 1, 8, 10, 19, 12,
573 0, 2, 23, 39, 28, 27, 22, 21, 24, 25,
574 26, 51, 56, 54, 49, 55, 48, 57, 50, 58,
575 52, 53, 59, 40,
576};
577
578static const unsigned int byt_sus_usb_over_current_pins[] = { 19, 20 };
579static const struct byt_simple_func_mux byt_sus_usb_oc_mux[] = {
580 SIMPLE_FUNC("usb", 0),
581 SIMPLE_FUNC("gpio", 1),
582};
583
584static const unsigned int byt_sus_usb_ulpi_pins[] = {
585 14, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43,
586};
587static const unsigned short byt_sus_usb_ulpi_mode_values[] = {
588 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
589};
590static const unsigned short byt_sus_usb_ulpi_gpio_mode_values[] = {
591 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
592};
593static const struct byt_mixed_func_mux byt_sus_usb_ulpi_mux[] = {
594 MIXED_FUNC("usb", byt_sus_usb_ulpi_mode_values),
595 MIXED_FUNC("gpio", byt_sus_usb_ulpi_gpio_mode_values),
596};
597
598static const unsigned int byt_sus_pcu_spi_pins[] = { 21 };
599static const struct byt_simple_func_mux byt_sus_pcu_spi_mux[] = {
600 SIMPLE_FUNC("spi", 0),
601 SIMPLE_FUNC("gpio", 1),
602};
603
604static const struct byt_pingroup byt_sus_groups[] = {
605 PIN_GROUP_SIMPLE("usb_oc_grp",
606 byt_sus_usb_over_current_pins, byt_sus_usb_oc_mux),
607 PIN_GROUP_MIXED("usb_ulpi_grp",
608 byt_sus_usb_ulpi_pins, byt_sus_usb_ulpi_mux),
609 PIN_GROUP_SIMPLE("pcu_spi_grp",
610 byt_sus_pcu_spi_pins, byt_sus_pcu_spi_mux),
611};
612
613static const char * const byt_sus_usb_groups[] = {
614 "usb_oc_grp", "usb_ulpi_grp",
615};
616static const char * const byt_sus_spi_groups[] = { "pcu_spi_grp" };
617static const char * const byt_sus_gpio_groups[] = {
618 "usb_oc_grp", "usb_ulpi_grp", "pcu_spi_grp",
619};
620
621static const struct byt_function byt_sus_functions[] = {
622 FUNCTION("usb", byt_sus_usb_groups),
623 FUNCTION("spi", byt_sus_spi_groups),
624 FUNCTION("gpio", byt_sus_gpio_groups),
625};
626
627static const struct byt_community byt_sus_communities[] = {
628 COMMUNITY(0, BYT_NGPIO_SUS, byt_sus_pins_map),
629};
630
631static const struct byt_pinctrl_soc_data byt_sus_soc_data = {
632 .uid = BYT_SUS_ACPI_UID,
633 .pins = byt_sus_pins,
634 .npins = ARRAY_SIZE(byt_sus_pins),
635 .groups = byt_sus_groups,
636 .ngroups = ARRAY_SIZE(byt_sus_groups),
637 .functions = byt_sus_functions,
638 .nfunctions = ARRAY_SIZE(byt_sus_functions),
639 .communities = byt_sus_communities,
640 .ncommunities = ARRAY_SIZE(byt_sus_communities),
641};
642
643static const struct pinctrl_pin_desc byt_ncore_pins[] = {
644 PINCTRL_PIN(0, "GPIO_NCORE0"),
645 PINCTRL_PIN(1, "GPIO_NCORE1"),
646 PINCTRL_PIN(2, "GPIO_NCORE2"),
647 PINCTRL_PIN(3, "GPIO_NCORE3"),
648 PINCTRL_PIN(4, "GPIO_NCORE4"),
649 PINCTRL_PIN(5, "GPIO_NCORE5"),
650 PINCTRL_PIN(6, "GPIO_NCORE6"),
651 PINCTRL_PIN(7, "GPIO_NCORE7"),
652 PINCTRL_PIN(8, "GPIO_NCORE8"),
653 PINCTRL_PIN(9, "GPIO_NCORE9"),
654 PINCTRL_PIN(10, "GPIO_NCORE10"),
655 PINCTRL_PIN(11, "GPIO_NCORE11"),
656 PINCTRL_PIN(12, "GPIO_NCORE12"),
657 PINCTRL_PIN(13, "GPIO_NCORE13"),
658 PINCTRL_PIN(14, "GPIO_NCORE14"),
659 PINCTRL_PIN(15, "GPIO_NCORE15"),
660 PINCTRL_PIN(16, "GPIO_NCORE16"),
661 PINCTRL_PIN(17, "GPIO_NCORE17"),
662 PINCTRL_PIN(18, "GPIO_NCORE18"),
663 PINCTRL_PIN(19, "GPIO_NCORE19"),
664 PINCTRL_PIN(20, "GPIO_NCORE20"),
665 PINCTRL_PIN(21, "GPIO_NCORE21"),
666 PINCTRL_PIN(22, "GPIO_NCORE22"),
667 PINCTRL_PIN(23, "GPIO_NCORE23"),
668 PINCTRL_PIN(24, "GPIO_NCORE24"),
669 PINCTRL_PIN(25, "GPIO_NCORE25"),
670 PINCTRL_PIN(26, "GPIO_NCORE26"),
671 PINCTRL_PIN(27, "GPIO_NCORE27"),
672};
673
674static unsigned const byt_ncore_pins_map[BYT_NGPIO_NCORE] = {
675 19, 18, 17, 20, 21, 22, 24, 25, 23, 16,
676 14, 15, 12, 26, 27, 1, 4, 8, 11, 0,
677 3, 6, 10, 13, 2, 5, 9, 7,
678};
679
680static const struct byt_community byt_ncore_communities[] = {
681 COMMUNITY(0, BYT_NGPIO_NCORE, byt_ncore_pins_map),
682};
683
684static const struct byt_pinctrl_soc_data byt_ncore_soc_data = {
685 .uid = BYT_NCORE_ACPI_UID,
686 .pins = byt_ncore_pins,
687 .npins = ARRAY_SIZE(byt_ncore_pins),
688 .communities = byt_ncore_communities,
689 .ncommunities = ARRAY_SIZE(byt_ncore_communities),
690};
691
692static unsigned const ncore_pins[BYT_NGPIO_NCORE] = {
693 19, 18, 17, 20, 21, 22, 24, 25, 23, 16,
694 14, 15, 12, 26, 27, 1, 4, 8, 11, 0,
695 3, 6, 10, 13, 2, 5, 9, 7,
696};
697
Mathias Nymana5d811b2013-06-18 14:33:02 +0300698static struct pinctrl_gpio_range byt_ranges[] = {
699 {
Chew, Kean Ho42bd0072014-03-06 21:59:49 +0800700 .name = BYT_SCORE_ACPI_UID, /* match with acpi _UID in probe */
Mathias Nymana5d811b2013-06-18 14:33:02 +0300701 .npins = BYT_NGPIO_SCORE,
702 .pins = score_pins,
703 },
704 {
Chew, Kean Ho42bd0072014-03-06 21:59:49 +0800705 .name = BYT_NCORE_ACPI_UID,
Mathias Nymana5d811b2013-06-18 14:33:02 +0300706 .npins = BYT_NGPIO_NCORE,
707 .pins = ncore_pins,
708 },
709 {
Chew, Kean Ho42bd0072014-03-06 21:59:49 +0800710 .name = BYT_SUS_ACPI_UID,
Mathias Nymana5d811b2013-06-18 14:33:02 +0300711 .npins = BYT_NGPIO_SUS,
712 .pins = sus_pins,
713 },
714 {
715 },
716};
717
718struct byt_gpio {
719 struct gpio_chip chip;
Mathias Nymana5d811b2013-06-18 14:33:02 +0300720 struct platform_device *pdev;
Mika Westerberg78e1c892015-08-17 16:03:17 +0300721 raw_spinlock_t lock;
Mathias Nymana5d811b2013-06-18 14:33:02 +0300722 void __iomem *reg_base;
723 struct pinctrl_gpio_range *range;
Mika Westerbergfcc18de2015-02-23 14:53:13 +0200724 struct byt_gpio_pin_context *saved_context;
Mathias Nymana5d811b2013-06-18 14:33:02 +0300725};
726
Cristina Ciocanc8f5c4c2016-04-01 14:00:02 +0300727static const struct byt_pinctrl_soc_data *byt_soc_data[] = {
728 &byt_score_soc_data,
729 &byt_sus_soc_data,
730 &byt_ncore_soc_data,
731 NULL,
732};
733
Mathias Nymana5d811b2013-06-18 14:33:02 +0300734static void __iomem *byt_gpio_reg(struct gpio_chip *chip, unsigned offset,
735 int reg)
736{
Linus Walleijbf9a5c92015-12-08 00:03:44 +0100737 struct byt_gpio *vg = gpiochip_get_data(chip);
Mathias Nymana5d811b2013-06-18 14:33:02 +0300738 u32 reg_offset;
Mathias Nymana5d811b2013-06-18 14:33:02 +0300739
740 if (reg == BYT_INT_STAT_REG)
741 reg_offset = (offset / 32) * 4;
742 else
743 reg_offset = vg->range->pins[offset] * 16;
744
Andy Shevchenko9c5b6552013-07-10 14:55:38 +0300745 return vg->reg_base + reg_offset + reg;
Mathias Nymana5d811b2013-06-18 14:33:02 +0300746}
747
Mika Westerberg95f09722015-02-23 14:53:11 +0200748static void byt_gpio_clear_triggering(struct byt_gpio *vg, unsigned offset)
749{
750 void __iomem *reg = byt_gpio_reg(&vg->chip, offset, BYT_CONF0_REG);
751 unsigned long flags;
752 u32 value;
753
Mika Westerberg78e1c892015-08-17 16:03:17 +0300754 raw_spin_lock_irqsave(&vg->lock, flags);
Mika Westerberg95f09722015-02-23 14:53:11 +0200755 value = readl(reg);
756 value &= ~(BYT_TRIG_POS | BYT_TRIG_NEG | BYT_TRIG_LVL);
757 writel(value, reg);
Mika Westerberg78e1c892015-08-17 16:03:17 +0300758 raw_spin_unlock_irqrestore(&vg->lock, flags);
Mika Westerberg95f09722015-02-23 14:53:11 +0200759}
760
Mika Westerbergf8323b62015-02-23 14:53:10 +0200761static u32 byt_get_gpio_mux(struct byt_gpio *vg, unsigned offset)
Chew, Kean Ho42bd0072014-03-06 21:59:49 +0800762{
763 /* SCORE pin 92-93 */
764 if (!strcmp(vg->range->name, BYT_SCORE_ACPI_UID) &&
765 offset >= 92 && offset <= 93)
Mika Westerbergf8323b62015-02-23 14:53:10 +0200766 return 1;
Chew, Kean Ho42bd0072014-03-06 21:59:49 +0800767
768 /* SUS pin 11-21 */
769 if (!strcmp(vg->range->name, BYT_SUS_ACPI_UID) &&
770 offset >= 11 && offset <= 21)
Mika Westerbergf8323b62015-02-23 14:53:10 +0200771 return 1;
Chew, Kean Ho42bd0072014-03-06 21:59:49 +0800772
Mika Westerbergf8323b62015-02-23 14:53:10 +0200773 return 0;
Chew, Kean Ho42bd0072014-03-06 21:59:49 +0800774}
775
Mathias Nymana5d811b2013-06-18 14:33:02 +0300776static int byt_gpio_request(struct gpio_chip *chip, unsigned offset)
777{
Linus Walleijbf9a5c92015-12-08 00:03:44 +0100778 struct byt_gpio *vg = gpiochip_get_data(chip);
Chew, Kean Ho42bd0072014-03-06 21:59:49 +0800779 void __iomem *reg = byt_gpio_reg(chip, offset, BYT_CONF0_REG);
Mika Westerbergf8323b62015-02-23 14:53:10 +0200780 u32 value, gpio_mux;
Mika Westerberg39ce8152015-08-04 15:03:14 +0300781 unsigned long flags;
782
Mika Westerberg78e1c892015-08-17 16:03:17 +0300783 raw_spin_lock_irqsave(&vg->lock, flags);
Chew, Kean Ho42bd0072014-03-06 21:59:49 +0800784
785 /*
786 * In most cases, func pin mux 000 means GPIO function.
787 * But, some pins may have func pin mux 001 represents
Mika Westerbergf8323b62015-02-23 14:53:10 +0200788 * GPIO function.
789 *
790 * Because there are devices out there where some pins were not
791 * configured correctly we allow changing the mux value from
792 * request (but print out warning about that).
Chew, Kean Ho42bd0072014-03-06 21:59:49 +0800793 */
794 value = readl(reg) & BYT_PIN_MUX;
Mika Westerbergf8323b62015-02-23 14:53:10 +0200795 gpio_mux = byt_get_gpio_mux(vg, offset);
796 if (WARN_ON(gpio_mux != value)) {
Mika Westerbergf8323b62015-02-23 14:53:10 +0200797 value = readl(reg) & ~BYT_PIN_MUX;
798 value |= gpio_mux;
799 writel(value, reg);
Mika Westerbergf8323b62015-02-23 14:53:10 +0200800
801 dev_warn(&vg->pdev->dev,
802 "pin %u forcibly re-configured as GPIO\n", offset);
Chew, Kean Ho42bd0072014-03-06 21:59:49 +0800803 }
Mathias Nymana5d811b2013-06-18 14:33:02 +0300804
Mika Westerberg78e1c892015-08-17 16:03:17 +0300805 raw_spin_unlock_irqrestore(&vg->lock, flags);
Mika Westerberg39ce8152015-08-04 15:03:14 +0300806
Mathias Nymana5d811b2013-06-18 14:33:02 +0300807 pm_runtime_get(&vg->pdev->dev);
808
809 return 0;
810}
811
812static void byt_gpio_free(struct gpio_chip *chip, unsigned offset)
813{
Linus Walleijbf9a5c92015-12-08 00:03:44 +0100814 struct byt_gpio *vg = gpiochip_get_data(chip);
Mathias Nymana5d811b2013-06-18 14:33:02 +0300815
Mika Westerberg95f09722015-02-23 14:53:11 +0200816 byt_gpio_clear_triggering(vg, offset);
Mathias Nymana5d811b2013-06-18 14:33:02 +0300817 pm_runtime_put(&vg->pdev->dev);
818}
819
820static int byt_irq_type(struct irq_data *d, unsigned type)
821{
Linus Walleijbf9a5c92015-12-08 00:03:44 +0100822 struct byt_gpio *vg = gpiochip_get_data(irq_data_get_irq_chip_data(d));
Mathias Nymana5d811b2013-06-18 14:33:02 +0300823 u32 offset = irqd_to_hwirq(d);
824 u32 value;
825 unsigned long flags;
826 void __iomem *reg = byt_gpio_reg(&vg->chip, offset, BYT_CONF0_REG);
827
828 if (offset >= vg->chip.ngpio)
829 return -EINVAL;
830
Mika Westerberg78e1c892015-08-17 16:03:17 +0300831 raw_spin_lock_irqsave(&vg->lock, flags);
Mathias Nymana5d811b2013-06-18 14:33:02 +0300832 value = readl(reg);
833
Loic Poulain3a71c052014-09-26 16:14:51 +0200834 WARN(value & BYT_DIRECT_IRQ_EN,
835 "Bad pad config for io mode, force direct_irq_en bit clearing");
836
Mathias Nymana5d811b2013-06-18 14:33:02 +0300837 /* For level trigges the BYT_TRIG_POS and BYT_TRIG_NEG bits
838 * are used to indicate high and low level triggering
839 */
Loic Poulain3a71c052014-09-26 16:14:51 +0200840 value &= ~(BYT_DIRECT_IRQ_EN | BYT_TRIG_POS | BYT_TRIG_NEG |
841 BYT_TRIG_LVL);
Mathias Nymana5d811b2013-06-18 14:33:02 +0300842
Mathias Nymana5d811b2013-06-18 14:33:02 +0300843 writel(value, reg);
844
Mika Westerberg31e43292015-02-23 14:53:12 +0200845 if (type & IRQ_TYPE_EDGE_BOTH)
Thomas Gleixnerf3a085b2015-06-23 15:52:44 +0200846 irq_set_handler_locked(d, handle_edge_irq);
Mika Westerberg31e43292015-02-23 14:53:12 +0200847 else if (type & IRQ_TYPE_LEVEL_MASK)
Thomas Gleixnerf3a085b2015-06-23 15:52:44 +0200848 irq_set_handler_locked(d, handle_level_irq);
Mika Westerberg31e43292015-02-23 14:53:12 +0200849
Mika Westerberg78e1c892015-08-17 16:03:17 +0300850 raw_spin_unlock_irqrestore(&vg->lock, flags);
Mathias Nymana5d811b2013-06-18 14:33:02 +0300851
852 return 0;
853}
854
855static int byt_gpio_get(struct gpio_chip *chip, unsigned offset)
856{
857 void __iomem *reg = byt_gpio_reg(chip, offset, BYT_VAL_REG);
Linus Walleijbf9a5c92015-12-08 00:03:44 +0100858 struct byt_gpio *vg = gpiochip_get_data(chip);
Mika Westerberg39ce8152015-08-04 15:03:14 +0300859 unsigned long flags;
860 u32 val;
861
Mika Westerberg78e1c892015-08-17 16:03:17 +0300862 raw_spin_lock_irqsave(&vg->lock, flags);
Mika Westerberg39ce8152015-08-04 15:03:14 +0300863 val = readl(reg);
Mika Westerberg78e1c892015-08-17 16:03:17 +0300864 raw_spin_unlock_irqrestore(&vg->lock, flags);
Mika Westerberg39ce8152015-08-04 15:03:14 +0300865
Linus Walleij3bde8772015-12-21 16:17:20 +0100866 return !!(val & BYT_LEVEL);
Mathias Nymana5d811b2013-06-18 14:33:02 +0300867}
868
869static void byt_gpio_set(struct gpio_chip *chip, unsigned offset, int value)
870{
Linus Walleijbf9a5c92015-12-08 00:03:44 +0100871 struct byt_gpio *vg = gpiochip_get_data(chip);
Mathias Nymana5d811b2013-06-18 14:33:02 +0300872 void __iomem *reg = byt_gpio_reg(chip, offset, BYT_VAL_REG);
873 unsigned long flags;
874 u32 old_val;
875
Mika Westerberg78e1c892015-08-17 16:03:17 +0300876 raw_spin_lock_irqsave(&vg->lock, flags);
Mathias Nymana5d811b2013-06-18 14:33:02 +0300877
878 old_val = readl(reg);
879
880 if (value)
881 writel(old_val | BYT_LEVEL, reg);
882 else
883 writel(old_val & ~BYT_LEVEL, reg);
884
Mika Westerberg78e1c892015-08-17 16:03:17 +0300885 raw_spin_unlock_irqrestore(&vg->lock, flags);
Mathias Nymana5d811b2013-06-18 14:33:02 +0300886}
887
888static int byt_gpio_direction_input(struct gpio_chip *chip, unsigned offset)
889{
Linus Walleijbf9a5c92015-12-08 00:03:44 +0100890 struct byt_gpio *vg = gpiochip_get_data(chip);
Mathias Nymana5d811b2013-06-18 14:33:02 +0300891 void __iomem *reg = byt_gpio_reg(chip, offset, BYT_VAL_REG);
892 unsigned long flags;
893 u32 value;
894
Mika Westerberg78e1c892015-08-17 16:03:17 +0300895 raw_spin_lock_irqsave(&vg->lock, flags);
Mathias Nymana5d811b2013-06-18 14:33:02 +0300896
897 value = readl(reg) | BYT_DIR_MASK;
Andy Shevchenko496940c2013-07-10 14:55:40 +0300898 value &= ~BYT_INPUT_EN; /* active low */
Mathias Nymana5d811b2013-06-18 14:33:02 +0300899 writel(value, reg);
900
Mika Westerberg78e1c892015-08-17 16:03:17 +0300901 raw_spin_unlock_irqrestore(&vg->lock, flags);
Mathias Nymana5d811b2013-06-18 14:33:02 +0300902
903 return 0;
904}
905
906static int byt_gpio_direction_output(struct gpio_chip *chip,
907 unsigned gpio, int value)
908{
Linus Walleijbf9a5c92015-12-08 00:03:44 +0100909 struct byt_gpio *vg = gpiochip_get_data(chip);
Eric Ernstff998352014-06-12 11:06:20 -0700910 void __iomem *conf_reg = byt_gpio_reg(chip, gpio, BYT_CONF0_REG);
Mathias Nymana5d811b2013-06-18 14:33:02 +0300911 void __iomem *reg = byt_gpio_reg(chip, gpio, BYT_VAL_REG);
912 unsigned long flags;
913 u32 reg_val;
914
Mika Westerberg78e1c892015-08-17 16:03:17 +0300915 raw_spin_lock_irqsave(&vg->lock, flags);
Mathias Nymana5d811b2013-06-18 14:33:02 +0300916
Eric Ernstff998352014-06-12 11:06:20 -0700917 /*
918 * Before making any direction modifications, do a check if gpio
919 * is set for direct IRQ. On baytrail, setting GPIO to output does
920 * not make sense, so let's at least warn the caller before they shoot
921 * themselves in the foot.
922 */
923 WARN(readl(conf_reg) & BYT_DIRECT_IRQ_EN,
924 "Potential Error: Setting GPIO with direct_irq_en to output");
925
Andy Shevchenko496940c2013-07-10 14:55:40 +0300926 reg_val = readl(reg) | BYT_DIR_MASK;
David Cohend90c3382014-10-14 10:54:37 -0700927 reg_val &= ~(BYT_OUTPUT_EN | BYT_INPUT_EN);
Andy Shevchenko496940c2013-07-10 14:55:40 +0300928
929 if (value)
930 writel(reg_val | BYT_LEVEL, reg);
931 else
932 writel(reg_val & ~BYT_LEVEL, reg);
Mathias Nymana5d811b2013-06-18 14:33:02 +0300933
Mika Westerberg78e1c892015-08-17 16:03:17 +0300934 raw_spin_unlock_irqrestore(&vg->lock, flags);
Mathias Nymana5d811b2013-06-18 14:33:02 +0300935
936 return 0;
937}
938
939static void byt_gpio_dbg_show(struct seq_file *s, struct gpio_chip *chip)
940{
Linus Walleijbf9a5c92015-12-08 00:03:44 +0100941 struct byt_gpio *vg = gpiochip_get_data(chip);
Mathias Nymana5d811b2013-06-18 14:33:02 +0300942 int i;
Mathias Nymana5d811b2013-06-18 14:33:02 +0300943 u32 conf0, val, offs;
944
Mathias Nymana5d811b2013-06-18 14:33:02 +0300945 for (i = 0; i < vg->chip.ngpio; i++) {
Mika Westerberg3ff95882014-05-16 12:18:29 +0300946 const char *pull_str = NULL;
947 const char *pull = NULL;
Mika Westerberg78e1c892015-08-17 16:03:17 +0300948 unsigned long flags;
Mathias Nymana4d8d6d2013-11-22 14:01:23 +0200949 const char *label;
Mathias Nymana5d811b2013-06-18 14:33:02 +0300950 offs = vg->range->pins[i] * 16;
Mika Westerberg78e1c892015-08-17 16:03:17 +0300951
952 raw_spin_lock_irqsave(&vg->lock, flags);
Mathias Nymana5d811b2013-06-18 14:33:02 +0300953 conf0 = readl(vg->reg_base + offs + BYT_CONF0_REG);
954 val = readl(vg->reg_base + offs + BYT_VAL_REG);
Mika Westerberg78e1c892015-08-17 16:03:17 +0300955 raw_spin_unlock_irqrestore(&vg->lock, flags);
Mathias Nymana5d811b2013-06-18 14:33:02 +0300956
Mathias Nymana4d8d6d2013-11-22 14:01:23 +0200957 label = gpiochip_is_requested(chip, i);
958 if (!label)
959 label = "Unrequested";
960
Mika Westerberg3ff95882014-05-16 12:18:29 +0300961 switch (conf0 & BYT_PULL_ASSIGN_MASK) {
962 case BYT_PULL_ASSIGN_UP:
963 pull = "up";
964 break;
965 case BYT_PULL_ASSIGN_DOWN:
966 pull = "down";
967 break;
968 }
969
970 switch (conf0 & BYT_PULL_STR_MASK) {
971 case BYT_PULL_STR_2K:
972 pull_str = "2k";
973 break;
974 case BYT_PULL_STR_10K:
975 pull_str = "10k";
976 break;
977 case BYT_PULL_STR_20K:
978 pull_str = "20k";
979 break;
980 case BYT_PULL_STR_40K:
981 pull_str = "40k";
982 break;
983 }
984
Mathias Nymana5d811b2013-06-18 14:33:02 +0300985 seq_printf(s,
Mika Westerberg3ff95882014-05-16 12:18:29 +0300986 " gpio-%-3d (%-20.20s) %s %s %s pad-%-3d offset:0x%03x mux:%d %s%s%s",
Mathias Nymana5d811b2013-06-18 14:33:02 +0300987 i,
Mathias Nymana4d8d6d2013-11-22 14:01:23 +0200988 label,
Mathias Nymana5d811b2013-06-18 14:33:02 +0300989 val & BYT_INPUT_EN ? " " : "in",
990 val & BYT_OUTPUT_EN ? " " : "out",
991 val & BYT_LEVEL ? "hi" : "lo",
992 vg->range->pins[i], offs,
993 conf0 & 0x7,
Mika Westerberg3ff95882014-05-16 12:18:29 +0300994 conf0 & BYT_TRIG_NEG ? " fall" : " ",
995 conf0 & BYT_TRIG_POS ? " rise" : " ",
996 conf0 & BYT_TRIG_LVL ? " level" : " ");
997
998 if (pull && pull_str)
999 seq_printf(s, " %-4s %-3s", pull, pull_str);
1000 else
1001 seq_puts(s, " ");
1002
1003 if (conf0 & BYT_IODEN)
1004 seq_puts(s, " open-drain");
1005
1006 seq_puts(s, "\n");
Mathias Nymana5d811b2013-06-18 14:33:02 +03001007 }
Mathias Nymana5d811b2013-06-18 14:33:02 +03001008}
1009
Thomas Gleixnerbd0b9ac2015-09-14 10:42:37 +02001010static void byt_gpio_irq_handler(struct irq_desc *desc)
Mathias Nymana5d811b2013-06-18 14:33:02 +03001011{
1012 struct irq_data *data = irq_desc_get_irq_data(desc);
Linus Walleijbf9a5c92015-12-08 00:03:44 +01001013 struct byt_gpio *vg = gpiochip_get_data(irq_desc_get_handler_data(desc));
Mathias Nymana5d811b2013-06-18 14:33:02 +03001014 struct irq_chip *chip = irq_data_get_irq_chip(data);
Mika Westerberg31e43292015-02-23 14:53:12 +02001015 u32 base, pin;
Mathias Nymana5d811b2013-06-18 14:33:02 +03001016 void __iomem *reg;
Mika Westerberg31e43292015-02-23 14:53:12 +02001017 unsigned long pending;
Mathias Nymana5d811b2013-06-18 14:33:02 +03001018 unsigned virq;
Mathias Nymana5d811b2013-06-18 14:33:02 +03001019
1020 /* check from GPIO controller which pin triggered the interrupt */
1021 for (base = 0; base < vg->chip.ngpio; base += 32) {
Mathias Nymana5d811b2013-06-18 14:33:02 +03001022 reg = byt_gpio_reg(&vg->chip, base, BYT_INT_STAT_REG);
Mika Westerberg31e43292015-02-23 14:53:12 +02001023 pending = readl(reg);
1024 for_each_set_bit(pin, &pending, 32) {
Mika Westerberge1ee5c52014-07-25 09:54:47 +03001025 virq = irq_find_mapping(vg->chip.irqdomain, base + pin);
Mathias Nymana5d811b2013-06-18 14:33:02 +03001026 generic_handle_irq(virq);
Mathias Nymana5d811b2013-06-18 14:33:02 +03001027 }
1028 }
1029 chip->irq_eoi(data);
1030}
1031
Mika Westerberg31e43292015-02-23 14:53:12 +02001032static void byt_irq_ack(struct irq_data *d)
1033{
1034 struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
Linus Walleijbf9a5c92015-12-08 00:03:44 +01001035 struct byt_gpio *vg = gpiochip_get_data(gc);
Mika Westerberg31e43292015-02-23 14:53:12 +02001036 unsigned offset = irqd_to_hwirq(d);
1037 void __iomem *reg;
1038
Mika Westerberg78e1c892015-08-17 16:03:17 +03001039 raw_spin_lock(&vg->lock);
Mika Westerberg31e43292015-02-23 14:53:12 +02001040 reg = byt_gpio_reg(&vg->chip, offset, BYT_INT_STAT_REG);
1041 writel(BIT(offset % 32), reg);
Mika Westerberg78e1c892015-08-17 16:03:17 +03001042 raw_spin_unlock(&vg->lock);
Mika Westerberg31e43292015-02-23 14:53:12 +02001043}
1044
Mathias Nymana5d811b2013-06-18 14:33:02 +03001045static void byt_irq_unmask(struct irq_data *d)
1046{
Mika Westerberg31e43292015-02-23 14:53:12 +02001047 struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
Linus Walleijbf9a5c92015-12-08 00:03:44 +01001048 struct byt_gpio *vg = gpiochip_get_data(gc);
Mika Westerberg31e43292015-02-23 14:53:12 +02001049 unsigned offset = irqd_to_hwirq(d);
1050 unsigned long flags;
1051 void __iomem *reg;
1052 u32 value;
1053
Mika Westerberg31e43292015-02-23 14:53:12 +02001054 reg = byt_gpio_reg(&vg->chip, offset, BYT_CONF0_REG);
Mika Westerberg78e1c892015-08-17 16:03:17 +03001055
1056 raw_spin_lock_irqsave(&vg->lock, flags);
Mika Westerberg31e43292015-02-23 14:53:12 +02001057 value = readl(reg);
1058
1059 switch (irqd_get_trigger_type(d)) {
1060 case IRQ_TYPE_LEVEL_HIGH:
1061 value |= BYT_TRIG_LVL;
1062 case IRQ_TYPE_EDGE_RISING:
1063 value |= BYT_TRIG_POS;
1064 break;
1065 case IRQ_TYPE_LEVEL_LOW:
1066 value |= BYT_TRIG_LVL;
1067 case IRQ_TYPE_EDGE_FALLING:
1068 value |= BYT_TRIG_NEG;
1069 break;
1070 case IRQ_TYPE_EDGE_BOTH:
1071 value |= (BYT_TRIG_NEG | BYT_TRIG_POS);
1072 break;
1073 }
1074
1075 writel(value, reg);
1076
Mika Westerberg78e1c892015-08-17 16:03:17 +03001077 raw_spin_unlock_irqrestore(&vg->lock, flags);
Mathias Nymana5d811b2013-06-18 14:33:02 +03001078}
1079
1080static void byt_irq_mask(struct irq_data *d)
1081{
Mika Westerberg31e43292015-02-23 14:53:12 +02001082 struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
Linus Walleijbf9a5c92015-12-08 00:03:44 +01001083 struct byt_gpio *vg = gpiochip_get_data(gc);
Mika Westerberg31e43292015-02-23 14:53:12 +02001084
1085 byt_gpio_clear_triggering(vg, irqd_to_hwirq(d));
Mathias Nymana5d811b2013-06-18 14:33:02 +03001086}
1087
1088static struct irq_chip byt_irqchip = {
1089 .name = "BYT-GPIO",
Mika Westerberg31e43292015-02-23 14:53:12 +02001090 .irq_ack = byt_irq_ack,
Mathias Nymana5d811b2013-06-18 14:33:02 +03001091 .irq_mask = byt_irq_mask,
1092 .irq_unmask = byt_irq_unmask,
1093 .irq_set_type = byt_irq_type,
Mathias Nyman41939e62014-08-11 16:51:55 +03001094 .flags = IRQCHIP_SKIP_SET_WAKE,
Mathias Nymana5d811b2013-06-18 14:33:02 +03001095};
1096
1097static void byt_gpio_irq_init_hw(struct byt_gpio *vg)
1098{
1099 void __iomem *reg;
1100 u32 base, value;
Mika Westerberg95f09722015-02-23 14:53:11 +02001101 int i;
1102
1103 /*
1104 * Clear interrupt triggers for all pins that are GPIOs and
1105 * do not use direct IRQ mode. This will prevent spurious
1106 * interrupts from misconfigured pins.
1107 */
1108 for (i = 0; i < vg->chip.ngpio; i++) {
1109 value = readl(byt_gpio_reg(&vg->chip, i, BYT_CONF0_REG));
1110 if ((value & BYT_PIN_MUX) == byt_get_gpio_mux(vg, i) &&
1111 !(value & BYT_DIRECT_IRQ_EN)) {
1112 byt_gpio_clear_triggering(vg, i);
1113 dev_dbg(&vg->pdev->dev, "disabling GPIO %d\n", i);
1114 }
1115 }
Mathias Nymana5d811b2013-06-18 14:33:02 +03001116
1117 /* clear interrupt status trigger registers */
1118 for (base = 0; base < vg->chip.ngpio; base += 32) {
1119 reg = byt_gpio_reg(&vg->chip, base, BYT_INT_STAT_REG);
1120 writel(0xffffffff, reg);
1121 /* make sure trigger bits are cleared, if not then a pin
1122 might be misconfigured in bios */
1123 value = readl(reg);
1124 if (value)
1125 dev_err(&vg->pdev->dev,
1126 "GPIO interrupt error, pins misconfigured\n");
1127 }
1128}
1129
Mathias Nymana5d811b2013-06-18 14:33:02 +03001130static int byt_gpio_probe(struct platform_device *pdev)
1131{
1132 struct byt_gpio *vg;
1133 struct gpio_chip *gc;
1134 struct resource *mem_rc, *irq_rc;
1135 struct device *dev = &pdev->dev;
1136 struct acpi_device *acpi_dev;
1137 struct pinctrl_gpio_range *range;
1138 acpi_handle handle = ACPI_HANDLE(dev);
Mathias Nymana5d811b2013-06-18 14:33:02 +03001139 int ret;
1140
1141 if (acpi_bus_get_device(handle, &acpi_dev))
1142 return -ENODEV;
1143
1144 vg = devm_kzalloc(dev, sizeof(struct byt_gpio), GFP_KERNEL);
1145 if (!vg) {
1146 dev_err(&pdev->dev, "can't allocate byt_gpio chip data\n");
1147 return -ENOMEM;
1148 }
1149
1150 for (range = byt_ranges; range->name; range++) {
1151 if (!strcmp(acpi_dev->pnp.unique_id, range->name)) {
1152 vg->chip.ngpio = range->npins;
1153 vg->range = range;
1154 break;
1155 }
1156 }
1157
1158 if (!vg->chip.ngpio || !vg->range)
1159 return -ENODEV;
1160
1161 vg->pdev = pdev;
1162 platform_set_drvdata(pdev, vg);
1163
1164 mem_rc = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1165 vg->reg_base = devm_ioremap_resource(dev, mem_rc);
1166 if (IS_ERR(vg->reg_base))
1167 return PTR_ERR(vg->reg_base);
1168
Mika Westerberg78e1c892015-08-17 16:03:17 +03001169 raw_spin_lock_init(&vg->lock);
Mathias Nymana5d811b2013-06-18 14:33:02 +03001170
1171 gc = &vg->chip;
1172 gc->label = dev_name(&pdev->dev);
1173 gc->owner = THIS_MODULE;
1174 gc->request = byt_gpio_request;
1175 gc->free = byt_gpio_free;
1176 gc->direction_input = byt_gpio_direction_input;
1177 gc->direction_output = byt_gpio_direction_output;
1178 gc->get = byt_gpio_get;
1179 gc->set = byt_gpio_set;
1180 gc->dbg_show = byt_gpio_dbg_show;
1181 gc->base = -1;
Linus Walleij9fb1f392013-12-04 14:42:46 +01001182 gc->can_sleep = false;
Linus Walleij58383c782015-11-04 09:56:26 +01001183 gc->parent = dev;
Mathias Nymana5d811b2013-06-18 14:33:02 +03001184
Mika Westerbergfcc18de2015-02-23 14:53:13 +02001185#ifdef CONFIG_PM_SLEEP
1186 vg->saved_context = devm_kcalloc(&pdev->dev, gc->ngpio,
1187 sizeof(*vg->saved_context), GFP_KERNEL);
1188#endif
1189
Linus Walleijbf9a5c92015-12-08 00:03:44 +01001190 ret = gpiochip_add_data(gc, vg);
Jin Yao605a7bc2014-05-15 18:28:47 +03001191 if (ret) {
1192 dev_err(&pdev->dev, "failed adding byt-gpio chip\n");
1193 return ret;
1194 }
1195
Mika Westerberge1ee5c52014-07-25 09:54:47 +03001196 /* set up interrupts */
1197 irq_rc = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
1198 if (irq_rc && irq_rc->start) {
1199 byt_gpio_irq_init_hw(vg);
1200 ret = gpiochip_irqchip_add(gc, &byt_irqchip, 0,
1201 handle_simple_irq, IRQ_TYPE_NONE);
1202 if (ret) {
1203 dev_err(dev, "failed to add irqchip\n");
1204 gpiochip_remove(gc);
1205 return ret;
1206 }
1207
1208 gpiochip_set_chained_irqchip(gc, &byt_irqchip,
1209 (unsigned)irq_rc->start,
1210 byt_gpio_irq_handler);
1211 }
1212
Mathias Nymana5d811b2013-06-18 14:33:02 +03001213 pm_runtime_enable(dev);
1214
1215 return 0;
1216}
1217
Mika Westerbergfcc18de2015-02-23 14:53:13 +02001218#ifdef CONFIG_PM_SLEEP
1219static int byt_gpio_suspend(struct device *dev)
1220{
1221 struct platform_device *pdev = to_platform_device(dev);
1222 struct byt_gpio *vg = platform_get_drvdata(pdev);
1223 int i;
1224
1225 for (i = 0; i < vg->chip.ngpio; i++) {
1226 void __iomem *reg;
1227 u32 value;
1228
1229 reg = byt_gpio_reg(&vg->chip, i, BYT_CONF0_REG);
1230 value = readl(reg) & BYT_CONF0_RESTORE_MASK;
1231 vg->saved_context[i].conf0 = value;
1232
1233 reg = byt_gpio_reg(&vg->chip, i, BYT_VAL_REG);
1234 value = readl(reg) & BYT_VAL_RESTORE_MASK;
1235 vg->saved_context[i].val = value;
1236 }
1237
1238 return 0;
1239}
1240
1241static int byt_gpio_resume(struct device *dev)
1242{
1243 struct platform_device *pdev = to_platform_device(dev);
1244 struct byt_gpio *vg = platform_get_drvdata(pdev);
1245 int i;
1246
1247 for (i = 0; i < vg->chip.ngpio; i++) {
1248 void __iomem *reg;
1249 u32 value;
1250
1251 reg = byt_gpio_reg(&vg->chip, i, BYT_CONF0_REG);
1252 value = readl(reg);
1253 if ((value & BYT_CONF0_RESTORE_MASK) !=
1254 vg->saved_context[i].conf0) {
1255 value &= ~BYT_CONF0_RESTORE_MASK;
1256 value |= vg->saved_context[i].conf0;
1257 writel(value, reg);
1258 dev_info(dev, "restored pin %d conf0 %#08x", i, value);
1259 }
1260
1261 reg = byt_gpio_reg(&vg->chip, i, BYT_VAL_REG);
1262 value = readl(reg);
1263 if ((value & BYT_VAL_RESTORE_MASK) !=
1264 vg->saved_context[i].val) {
1265 u32 v;
1266
1267 v = value & ~BYT_VAL_RESTORE_MASK;
1268 v |= vg->saved_context[i].val;
1269 if (v != value) {
1270 writel(v, reg);
1271 dev_dbg(dev, "restored pin %d val %#08x\n",
1272 i, v);
1273 }
1274 }
1275 }
1276
1277 return 0;
1278}
1279#endif
1280
Mika Westerbergec879f12015-10-13 17:51:26 +03001281#ifdef CONFIG_PM
Mathias Nymana5d811b2013-06-18 14:33:02 +03001282static int byt_gpio_runtime_suspend(struct device *dev)
1283{
1284 return 0;
1285}
1286
1287static int byt_gpio_runtime_resume(struct device *dev)
1288{
1289 return 0;
1290}
Mika Westerbergec879f12015-10-13 17:51:26 +03001291#endif
Mathias Nymana5d811b2013-06-18 14:33:02 +03001292
1293static const struct dev_pm_ops byt_gpio_pm_ops = {
Mika Westerbergfcc18de2015-02-23 14:53:13 +02001294 SET_LATE_SYSTEM_SLEEP_PM_OPS(byt_gpio_suspend, byt_gpio_resume)
1295 SET_RUNTIME_PM_OPS(byt_gpio_runtime_suspend, byt_gpio_runtime_resume,
1296 NULL)
Mathias Nymana5d811b2013-06-18 14:33:02 +03001297};
1298
1299static const struct acpi_device_id byt_gpio_acpi_match[] = {
Cristina Ciocanc8f5c4c2016-04-01 14:00:02 +03001300 { "INT33B2", (kernel_ulong_t)byt_soc_data },
1301 { "INT33FC", (kernel_ulong_t)byt_soc_data },
Mathias Nymana5d811b2013-06-18 14:33:02 +03001302 { }
1303};
1304MODULE_DEVICE_TABLE(acpi, byt_gpio_acpi_match);
1305
1306static int byt_gpio_remove(struct platform_device *pdev)
1307{
1308 struct byt_gpio *vg = platform_get_drvdata(pdev);
Andy Shevchenkoec243322013-07-10 14:55:36 +03001309
Mathias Nymana5d811b2013-06-18 14:33:02 +03001310 pm_runtime_disable(&pdev->dev);
abdoulaye bertheb4e7c552014-07-12 22:30:13 +02001311 gpiochip_remove(&vg->chip);
Mathias Nymana5d811b2013-06-18 14:33:02 +03001312
1313 return 0;
1314}
1315
1316static struct platform_driver byt_gpio_driver = {
1317 .probe = byt_gpio_probe,
1318 .remove = byt_gpio_remove,
1319 .driver = {
1320 .name = "byt_gpio",
Mathias Nymana5d811b2013-06-18 14:33:02 +03001321 .pm = &byt_gpio_pm_ops,
1322 .acpi_match_table = ACPI_PTR(byt_gpio_acpi_match),
1323 },
1324};
1325
1326static int __init byt_gpio_init(void)
1327{
1328 return platform_driver_register(&byt_gpio_driver);
1329}
Mathias Nymana5d811b2013-06-18 14:33:02 +03001330subsys_initcall(byt_gpio_init);
Felipe Balbi9067bbe2014-10-13 15:50:08 -05001331
1332static void __exit byt_gpio_exit(void)
1333{
1334 platform_driver_unregister(&byt_gpio_driver);
1335}
1336module_exit(byt_gpio_exit);