OSDN Git Service

pinctrl: amd: Use amd_pinconf_set() for all config options
[tomoyo/tomoyo-test1.git] / drivers / pinctrl / pinctrl-amd.c
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3  * GPIO driver for AMD
4  *
5  * Copyright (c) 2014,2015 AMD Corporation.
6  * Authors: Ken Xue <Ken.Xue@amd.com>
7  *      Wu, Jeff <Jeff.Wu@amd.com>
8  *
9  */
10
11 #include <linux/err.h>
12 #include <linux/bug.h>
13 #include <linux/kernel.h>
14 #include <linux/module.h>
15 #include <linux/spinlock.h>
16 #include <linux/compiler.h>
17 #include <linux/types.h>
18 #include <linux/errno.h>
19 #include <linux/log2.h>
20 #include <linux/io.h>
21 #include <linux/gpio/driver.h>
22 #include <linux/slab.h>
23 #include <linux/platform_device.h>
24 #include <linux/mutex.h>
25 #include <linux/acpi.h>
26 #include <linux/seq_file.h>
27 #include <linux/interrupt.h>
28 #include <linux/list.h>
29 #include <linux/bitops.h>
30 #include <linux/pinctrl/pinconf.h>
31 #include <linux/pinctrl/pinconf-generic.h>
32 #include <linux/pinctrl/pinmux.h>
33 #include <linux/suspend.h>
34
35 #include "core.h"
36 #include "pinctrl-utils.h"
37 #include "pinctrl-amd.h"
38
39 static int amd_gpio_get_direction(struct gpio_chip *gc, unsigned offset)
40 {
41         unsigned long flags;
42         u32 pin_reg;
43         struct amd_gpio *gpio_dev = gpiochip_get_data(gc);
44
45         raw_spin_lock_irqsave(&gpio_dev->lock, flags);
46         pin_reg = readl(gpio_dev->base + offset * 4);
47         raw_spin_unlock_irqrestore(&gpio_dev->lock, flags);
48
49         if (pin_reg & BIT(OUTPUT_ENABLE_OFF))
50                 return GPIO_LINE_DIRECTION_OUT;
51
52         return GPIO_LINE_DIRECTION_IN;
53 }
54
55 static int amd_gpio_direction_input(struct gpio_chip *gc, unsigned offset)
56 {
57         unsigned long flags;
58         u32 pin_reg;
59         struct amd_gpio *gpio_dev = gpiochip_get_data(gc);
60
61         raw_spin_lock_irqsave(&gpio_dev->lock, flags);
62         pin_reg = readl(gpio_dev->base + offset * 4);
63         pin_reg &= ~BIT(OUTPUT_ENABLE_OFF);
64         writel(pin_reg, gpio_dev->base + offset * 4);
65         raw_spin_unlock_irqrestore(&gpio_dev->lock, flags);
66
67         return 0;
68 }
69
70 static int amd_gpio_direction_output(struct gpio_chip *gc, unsigned offset,
71                 int value)
72 {
73         u32 pin_reg;
74         unsigned long flags;
75         struct amd_gpio *gpio_dev = gpiochip_get_data(gc);
76
77         raw_spin_lock_irqsave(&gpio_dev->lock, flags);
78         pin_reg = readl(gpio_dev->base + offset * 4);
79         pin_reg |= BIT(OUTPUT_ENABLE_OFF);
80         if (value)
81                 pin_reg |= BIT(OUTPUT_VALUE_OFF);
82         else
83                 pin_reg &= ~BIT(OUTPUT_VALUE_OFF);
84         writel(pin_reg, gpio_dev->base + offset * 4);
85         raw_spin_unlock_irqrestore(&gpio_dev->lock, flags);
86
87         return 0;
88 }
89
90 static int amd_gpio_get_value(struct gpio_chip *gc, unsigned offset)
91 {
92         u32 pin_reg;
93         unsigned long flags;
94         struct amd_gpio *gpio_dev = gpiochip_get_data(gc);
95
96         raw_spin_lock_irqsave(&gpio_dev->lock, flags);
97         pin_reg = readl(gpio_dev->base + offset * 4);
98         raw_spin_unlock_irqrestore(&gpio_dev->lock, flags);
99
100         return !!(pin_reg & BIT(PIN_STS_OFF));
101 }
102
103 static void amd_gpio_set_value(struct gpio_chip *gc, unsigned offset, int value)
104 {
105         u32 pin_reg;
106         unsigned long flags;
107         struct amd_gpio *gpio_dev = gpiochip_get_data(gc);
108
109         raw_spin_lock_irqsave(&gpio_dev->lock, flags);
110         pin_reg = readl(gpio_dev->base + offset * 4);
111         if (value)
112                 pin_reg |= BIT(OUTPUT_VALUE_OFF);
113         else
114                 pin_reg &= ~BIT(OUTPUT_VALUE_OFF);
115         writel(pin_reg, gpio_dev->base + offset * 4);
116         raw_spin_unlock_irqrestore(&gpio_dev->lock, flags);
117 }
118
119 static int amd_gpio_set_debounce(struct gpio_chip *gc, unsigned offset,
120                 unsigned debounce)
121 {
122         u32 time;
123         u32 pin_reg;
124         int ret = 0;
125         unsigned long flags;
126         struct amd_gpio *gpio_dev = gpiochip_get_data(gc);
127
128         raw_spin_lock_irqsave(&gpio_dev->lock, flags);
129
130         /* Use special handling for Pin0 debounce */
131         if (offset == 0) {
132                 pin_reg = readl(gpio_dev->base + WAKE_INT_MASTER_REG);
133                 if (pin_reg & INTERNAL_GPIO0_DEBOUNCE)
134                         debounce = 0;
135         }
136
137         pin_reg = readl(gpio_dev->base + offset * 4);
138
139         if (debounce) {
140                 pin_reg |= DB_TYPE_REMOVE_GLITCH << DB_CNTRL_OFF;
141                 pin_reg &= ~DB_TMR_OUT_MASK;
142                 /*
143                 Debounce        Debounce        Timer   Max
144                 TmrLarge        TmrOutUnit      Unit    Debounce
145                                                         Time
146                 0       0       61 usec (2 RtcClk)      976 usec
147                 0       1       244 usec (8 RtcClk)     3.9 msec
148                 1       0       15.6 msec (512 RtcClk)  250 msec
149                 1       1       62.5 msec (2048 RtcClk) 1 sec
150                 */
151
152                 if (debounce < 61) {
153                         pin_reg |= 1;
154                         pin_reg &= ~BIT(DB_TMR_OUT_UNIT_OFF);
155                         pin_reg &= ~BIT(DB_TMR_LARGE_OFF);
156                 } else if (debounce < 976) {
157                         time = debounce / 61;
158                         pin_reg |= time & DB_TMR_OUT_MASK;
159                         pin_reg &= ~BIT(DB_TMR_OUT_UNIT_OFF);
160                         pin_reg &= ~BIT(DB_TMR_LARGE_OFF);
161                 } else if (debounce < 3900) {
162                         time = debounce / 244;
163                         pin_reg |= time & DB_TMR_OUT_MASK;
164                         pin_reg |= BIT(DB_TMR_OUT_UNIT_OFF);
165                         pin_reg &= ~BIT(DB_TMR_LARGE_OFF);
166                 } else if (debounce < 250000) {
167                         time = debounce / 15625;
168                         pin_reg |= time & DB_TMR_OUT_MASK;
169                         pin_reg &= ~BIT(DB_TMR_OUT_UNIT_OFF);
170                         pin_reg |= BIT(DB_TMR_LARGE_OFF);
171                 } else if (debounce < 1000000) {
172                         time = debounce / 62500;
173                         pin_reg |= time & DB_TMR_OUT_MASK;
174                         pin_reg |= BIT(DB_TMR_OUT_UNIT_OFF);
175                         pin_reg |= BIT(DB_TMR_LARGE_OFF);
176                 } else {
177                         pin_reg &= ~(DB_CNTRl_MASK << DB_CNTRL_OFF);
178                         ret = -EINVAL;
179                 }
180         } else {
181                 pin_reg &= ~BIT(DB_TMR_OUT_UNIT_OFF);
182                 pin_reg &= ~BIT(DB_TMR_LARGE_OFF);
183                 pin_reg &= ~DB_TMR_OUT_MASK;
184                 pin_reg &= ~(DB_CNTRl_MASK << DB_CNTRL_OFF);
185         }
186         writel(pin_reg, gpio_dev->base + offset * 4);
187         raw_spin_unlock_irqrestore(&gpio_dev->lock, flags);
188
189         return ret;
190 }
191
192 #ifdef CONFIG_DEBUG_FS
193 static void amd_gpio_dbg_show(struct seq_file *s, struct gpio_chip *gc)
194 {
195         u32 pin_reg;
196         u32 db_cntrl;
197         unsigned long flags;
198         unsigned int bank, i, pin_num;
199         struct amd_gpio *gpio_dev = gpiochip_get_data(gc);
200
201         bool tmr_out_unit;
202         bool tmr_large;
203
204         char *level_trig;
205         char *active_level;
206         char *interrupt_mask;
207         char *wake_cntrl0;
208         char *wake_cntrl1;
209         char *wake_cntrl2;
210         char *pin_sts;
211         char *interrupt_sts;
212         char *wake_sts;
213         char *pull_up_sel;
214         char *orientation;
215         char debounce_value[40];
216         char *debounce_enable;
217         char *wake_cntrlz;
218
219         seq_printf(s, "WAKE_INT_MASTER_REG: 0x%08x\n", readl(gpio_dev->base + WAKE_INT_MASTER_REG));
220         for (bank = 0; bank < gpio_dev->hwbank_num; bank++) {
221                 unsigned int time = 0;
222                 unsigned int unit = 0;
223
224                 switch (bank) {
225                 case 0:
226                         i = 0;
227                         pin_num = AMD_GPIO_PINS_BANK0;
228                         break;
229                 case 1:
230                         i = 64;
231                         pin_num = AMD_GPIO_PINS_BANK1 + i;
232                         break;
233                 case 2:
234                         i = 128;
235                         pin_num = AMD_GPIO_PINS_BANK2 + i;
236                         break;
237                 case 3:
238                         i = 192;
239                         pin_num = AMD_GPIO_PINS_BANK3 + i;
240                         break;
241                 default:
242                         /* Illegal bank number, ignore */
243                         continue;
244                 }
245                 seq_printf(s, "GPIO bank%d\n", bank);
246                 seq_puts(s, "gpio\t  int|active|trigger|S0i3| S3|S4/S5| Z|wake|pull|  orient|       debounce|reg\n");
247                 for (; i < pin_num; i++) {
248                         seq_printf(s, "#%d\t", i);
249                         raw_spin_lock_irqsave(&gpio_dev->lock, flags);
250                         pin_reg = readl(gpio_dev->base + i * 4);
251                         raw_spin_unlock_irqrestore(&gpio_dev->lock, flags);
252
253                         if (pin_reg & BIT(INTERRUPT_ENABLE_OFF)) {
254                                 u8 level = (pin_reg >> ACTIVE_LEVEL_OFF) &
255                                                 ACTIVE_LEVEL_MASK;
256
257                                 if (level == ACTIVE_LEVEL_HIGH)
258                                         active_level = "↑";
259                                 else if (level == ACTIVE_LEVEL_LOW)
260                                         active_level = "↓";
261                                 else if (!(pin_reg & BIT(LEVEL_TRIG_OFF)) &&
262                                          level == ACTIVE_LEVEL_BOTH)
263                                         active_level = "b";
264                                 else
265                                         active_level = "?";
266
267                                 if (pin_reg & BIT(LEVEL_TRIG_OFF))
268                                         level_trig = "level";
269                                 else
270                                         level_trig = " edge";
271
272                                 if (pin_reg & BIT(INTERRUPT_MASK_OFF))
273                                         interrupt_mask = "😛";
274                                 else
275                                         interrupt_mask = "😷";
276
277                                 if (pin_reg & BIT(INTERRUPT_STS_OFF))
278                                         interrupt_sts = "🔥";
279                                 else
280                                         interrupt_sts = "  ";
281
282                                 seq_printf(s, "%s %s|     %s|  %s|",
283                                    interrupt_sts,
284                                    interrupt_mask,
285                                    active_level,
286                                    level_trig);
287                         } else
288                                 seq_puts(s, "    ∅|      |       |");
289
290                         if (pin_reg & BIT(WAKE_CNTRL_OFF_S0I3))
291                                 wake_cntrl0 = "⏰";
292                         else
293                                 wake_cntrl0 = "  ";
294                         seq_printf(s, "  %s| ", wake_cntrl0);
295
296                         if (pin_reg & BIT(WAKE_CNTRL_OFF_S3))
297                                 wake_cntrl1 = "⏰";
298                         else
299                                 wake_cntrl1 = "  ";
300                         seq_printf(s, "%s|", wake_cntrl1);
301
302                         if (pin_reg & BIT(WAKE_CNTRL_OFF_S4))
303                                 wake_cntrl2 = "⏰";
304                         else
305                                 wake_cntrl2 = "  ";
306                         seq_printf(s, "   %s|", wake_cntrl2);
307
308                         if (pin_reg & BIT(WAKECNTRL_Z_OFF))
309                                 wake_cntrlz = "⏰";
310                         else
311                                 wake_cntrlz = "  ";
312                         seq_printf(s, "%s|", wake_cntrlz);
313
314                         if (pin_reg & BIT(WAKE_STS_OFF))
315                                 wake_sts = "🔥";
316                         else
317                                 wake_sts = " ";
318                         seq_printf(s, "   %s|", wake_sts);
319
320                         if (pin_reg & BIT(PULL_UP_ENABLE_OFF)) {
321                                 if (pin_reg & BIT(PULL_UP_SEL_OFF))
322                                         pull_up_sel = "8k";
323                                 else
324                                         pull_up_sel = "4k";
325                                 seq_printf(s, "%s ↑|",
326                                            pull_up_sel);
327                         } else if (pin_reg & BIT(PULL_DOWN_ENABLE_OFF)) {
328                                 seq_puts(s, "   ↓|");
329                         } else  {
330                                 seq_puts(s, "    |");
331                         }
332
333                         if (pin_reg & BIT(OUTPUT_ENABLE_OFF)) {
334                                 pin_sts = "output";
335                                 if (pin_reg & BIT(OUTPUT_VALUE_OFF))
336                                         orientation = "↑";
337                                 else
338                                         orientation = "↓";
339                         } else {
340                                 pin_sts = "input ";
341                                 if (pin_reg & BIT(PIN_STS_OFF))
342                                         orientation = "↑";
343                                 else
344                                         orientation = "↓";
345                         }
346                         seq_printf(s, "%s %s|", pin_sts, orientation);
347
348                         db_cntrl = (DB_CNTRl_MASK << DB_CNTRL_OFF) & pin_reg;
349                         if (db_cntrl) {
350                                 tmr_out_unit = pin_reg & BIT(DB_TMR_OUT_UNIT_OFF);
351                                 tmr_large = pin_reg & BIT(DB_TMR_LARGE_OFF);
352                                 time = pin_reg & DB_TMR_OUT_MASK;
353                                 if (tmr_large) {
354                                         if (tmr_out_unit)
355                                                 unit = 62500;
356                                         else
357                                                 unit = 15625;
358                                 } else {
359                                         if (tmr_out_unit)
360                                                 unit = 244;
361                                         else
362                                                 unit = 61;
363                                 }
364                                 if ((DB_TYPE_REMOVE_GLITCH << DB_CNTRL_OFF) == db_cntrl)
365                                         debounce_enable = "b";
366                                 else if ((DB_TYPE_PRESERVE_LOW_GLITCH << DB_CNTRL_OFF) == db_cntrl)
367                                         debounce_enable = "↓";
368                                 else
369                                         debounce_enable = "↑";
370                                 snprintf(debounce_value, sizeof(debounce_value), "%06u", time * unit);
371                                 seq_printf(s, "%s (🕑 %sus)|", debounce_enable, debounce_value);
372                         } else {
373                                 seq_puts(s, "               |");
374                         }
375                         seq_printf(s, "0x%x\n", pin_reg);
376                 }
377         }
378 }
379 #else
380 #define amd_gpio_dbg_show NULL
381 #endif
382
383 static void amd_gpio_irq_enable(struct irq_data *d)
384 {
385         u32 pin_reg;
386         unsigned long flags;
387         struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
388         struct amd_gpio *gpio_dev = gpiochip_get_data(gc);
389
390         gpiochip_enable_irq(gc, d->hwirq);
391
392         raw_spin_lock_irqsave(&gpio_dev->lock, flags);
393         pin_reg = readl(gpio_dev->base + (d->hwirq)*4);
394         pin_reg |= BIT(INTERRUPT_ENABLE_OFF);
395         pin_reg |= BIT(INTERRUPT_MASK_OFF);
396         writel(pin_reg, gpio_dev->base + (d->hwirq)*4);
397         raw_spin_unlock_irqrestore(&gpio_dev->lock, flags);
398 }
399
400 static void amd_gpio_irq_disable(struct irq_data *d)
401 {
402         u32 pin_reg;
403         unsigned long flags;
404         struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
405         struct amd_gpio *gpio_dev = gpiochip_get_data(gc);
406
407         raw_spin_lock_irqsave(&gpio_dev->lock, flags);
408         pin_reg = readl(gpio_dev->base + (d->hwirq)*4);
409         pin_reg &= ~BIT(INTERRUPT_ENABLE_OFF);
410         pin_reg &= ~BIT(INTERRUPT_MASK_OFF);
411         writel(pin_reg, gpio_dev->base + (d->hwirq)*4);
412         raw_spin_unlock_irqrestore(&gpio_dev->lock, flags);
413
414         gpiochip_disable_irq(gc, d->hwirq);
415 }
416
417 static void amd_gpio_irq_mask(struct irq_data *d)
418 {
419         u32 pin_reg;
420         unsigned long flags;
421         struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
422         struct amd_gpio *gpio_dev = gpiochip_get_data(gc);
423
424         raw_spin_lock_irqsave(&gpio_dev->lock, flags);
425         pin_reg = readl(gpio_dev->base + (d->hwirq)*4);
426         pin_reg &= ~BIT(INTERRUPT_MASK_OFF);
427         writel(pin_reg, gpio_dev->base + (d->hwirq)*4);
428         raw_spin_unlock_irqrestore(&gpio_dev->lock, flags);
429 }
430
431 static void amd_gpio_irq_unmask(struct irq_data *d)
432 {
433         u32 pin_reg;
434         unsigned long flags;
435         struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
436         struct amd_gpio *gpio_dev = gpiochip_get_data(gc);
437
438         raw_spin_lock_irqsave(&gpio_dev->lock, flags);
439         pin_reg = readl(gpio_dev->base + (d->hwirq)*4);
440         pin_reg |= BIT(INTERRUPT_MASK_OFF);
441         writel(pin_reg, gpio_dev->base + (d->hwirq)*4);
442         raw_spin_unlock_irqrestore(&gpio_dev->lock, flags);
443 }
444
445 static int amd_gpio_irq_set_wake(struct irq_data *d, unsigned int on)
446 {
447         u32 pin_reg;
448         unsigned long flags;
449         struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
450         struct amd_gpio *gpio_dev = gpiochip_get_data(gc);
451         u32 wake_mask = BIT(WAKE_CNTRL_OFF_S0I3) | BIT(WAKE_CNTRL_OFF_S3);
452         int err;
453
454         raw_spin_lock_irqsave(&gpio_dev->lock, flags);
455         pin_reg = readl(gpio_dev->base + (d->hwirq)*4);
456
457         if (on)
458                 pin_reg |= wake_mask;
459         else
460                 pin_reg &= ~wake_mask;
461
462         writel(pin_reg, gpio_dev->base + (d->hwirq)*4);
463         raw_spin_unlock_irqrestore(&gpio_dev->lock, flags);
464
465         if (on)
466                 err = enable_irq_wake(gpio_dev->irq);
467         else
468                 err = disable_irq_wake(gpio_dev->irq);
469
470         if (err)
471                 dev_err(&gpio_dev->pdev->dev, "failed to %s wake-up interrupt\n",
472                         on ? "enable" : "disable");
473
474         return 0;
475 }
476
477 static void amd_gpio_irq_eoi(struct irq_data *d)
478 {
479         u32 reg;
480         unsigned long flags;
481         struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
482         struct amd_gpio *gpio_dev = gpiochip_get_data(gc);
483
484         raw_spin_lock_irqsave(&gpio_dev->lock, flags);
485         reg = readl(gpio_dev->base + WAKE_INT_MASTER_REG);
486         reg |= EOI_MASK;
487         writel(reg, gpio_dev->base + WAKE_INT_MASTER_REG);
488         raw_spin_unlock_irqrestore(&gpio_dev->lock, flags);
489 }
490
491 static int amd_gpio_irq_set_type(struct irq_data *d, unsigned int type)
492 {
493         int ret = 0;
494         u32 pin_reg, pin_reg_irq_en, mask;
495         unsigned long flags;
496         struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
497         struct amd_gpio *gpio_dev = gpiochip_get_data(gc);
498
499         raw_spin_lock_irqsave(&gpio_dev->lock, flags);
500         pin_reg = readl(gpio_dev->base + (d->hwirq)*4);
501
502         switch (type & IRQ_TYPE_SENSE_MASK) {
503         case IRQ_TYPE_EDGE_RISING:
504                 pin_reg &= ~BIT(LEVEL_TRIG_OFF);
505                 pin_reg &= ~(ACTIVE_LEVEL_MASK << ACTIVE_LEVEL_OFF);
506                 pin_reg |= ACTIVE_HIGH << ACTIVE_LEVEL_OFF;
507                 irq_set_handler_locked(d, handle_edge_irq);
508                 break;
509
510         case IRQ_TYPE_EDGE_FALLING:
511                 pin_reg &= ~BIT(LEVEL_TRIG_OFF);
512                 pin_reg &= ~(ACTIVE_LEVEL_MASK << ACTIVE_LEVEL_OFF);
513                 pin_reg |= ACTIVE_LOW << ACTIVE_LEVEL_OFF;
514                 irq_set_handler_locked(d, handle_edge_irq);
515                 break;
516
517         case IRQ_TYPE_EDGE_BOTH:
518                 pin_reg &= ~BIT(LEVEL_TRIG_OFF);
519                 pin_reg &= ~(ACTIVE_LEVEL_MASK << ACTIVE_LEVEL_OFF);
520                 pin_reg |= BOTH_EADGE << ACTIVE_LEVEL_OFF;
521                 irq_set_handler_locked(d, handle_edge_irq);
522                 break;
523
524         case IRQ_TYPE_LEVEL_HIGH:
525                 pin_reg |= LEVEL_TRIGGER << LEVEL_TRIG_OFF;
526                 pin_reg &= ~(ACTIVE_LEVEL_MASK << ACTIVE_LEVEL_OFF);
527                 pin_reg |= ACTIVE_HIGH << ACTIVE_LEVEL_OFF;
528                 irq_set_handler_locked(d, handle_level_irq);
529                 break;
530
531         case IRQ_TYPE_LEVEL_LOW:
532                 pin_reg |= LEVEL_TRIGGER << LEVEL_TRIG_OFF;
533                 pin_reg &= ~(ACTIVE_LEVEL_MASK << ACTIVE_LEVEL_OFF);
534                 pin_reg |= ACTIVE_LOW << ACTIVE_LEVEL_OFF;
535                 irq_set_handler_locked(d, handle_level_irq);
536                 break;
537
538         case IRQ_TYPE_NONE:
539                 break;
540
541         default:
542                 dev_err(&gpio_dev->pdev->dev, "Invalid type value\n");
543                 ret = -EINVAL;
544         }
545
546         pin_reg |= CLR_INTR_STAT << INTERRUPT_STS_OFF;
547         /*
548          * If WAKE_INT_MASTER_REG.MaskStsEn is set, a software write to the
549          * debounce registers of any GPIO will block wake/interrupt status
550          * generation for *all* GPIOs for a length of time that depends on
551          * WAKE_INT_MASTER_REG.MaskStsLength[11:0].  During this period the
552          * INTERRUPT_ENABLE bit will read as 0.
553          *
554          * We temporarily enable irq for the GPIO whose configuration is
555          * changing, and then wait for it to read back as 1 to know when
556          * debounce has settled and then disable the irq again.
557          * We do this polling with the spinlock held to ensure other GPIO
558          * access routines do not read an incorrect value for the irq enable
559          * bit of other GPIOs.  We keep the GPIO masked while polling to avoid
560          * spurious irqs, and disable the irq again after polling.
561          */
562         mask = BIT(INTERRUPT_ENABLE_OFF);
563         pin_reg_irq_en = pin_reg;
564         pin_reg_irq_en |= mask;
565         pin_reg_irq_en &= ~BIT(INTERRUPT_MASK_OFF);
566         writel(pin_reg_irq_en, gpio_dev->base + (d->hwirq)*4);
567         while ((readl(gpio_dev->base + (d->hwirq)*4) & mask) != mask)
568                 continue;
569         writel(pin_reg, gpio_dev->base + (d->hwirq)*4);
570         raw_spin_unlock_irqrestore(&gpio_dev->lock, flags);
571
572         return ret;
573 }
574
575 static void amd_irq_ack(struct irq_data *d)
576 {
577         /*
578          * based on HW design,there is no need to ack HW
579          * before handle current irq. But this routine is
580          * necessary for handle_edge_irq
581         */
582 }
583
584 static const struct irq_chip amd_gpio_irqchip = {
585         .name         = "amd_gpio",
586         .irq_ack      = amd_irq_ack,
587         .irq_enable   = amd_gpio_irq_enable,
588         .irq_disable  = amd_gpio_irq_disable,
589         .irq_mask     = amd_gpio_irq_mask,
590         .irq_unmask   = amd_gpio_irq_unmask,
591         .irq_set_wake = amd_gpio_irq_set_wake,
592         .irq_eoi      = amd_gpio_irq_eoi,
593         .irq_set_type = amd_gpio_irq_set_type,
594         /*
595          * We need to set IRQCHIP_ENABLE_WAKEUP_ON_SUSPEND so that a wake event
596          * also generates an IRQ. We need the IRQ so the irq_handler can clear
597          * the wake event. Otherwise the wake event will never clear and
598          * prevent the system from suspending.
599          */
600         .flags        = IRQCHIP_ENABLE_WAKEUP_ON_SUSPEND | IRQCHIP_IMMUTABLE,
601         GPIOCHIP_IRQ_RESOURCE_HELPERS,
602 };
603
604 #define PIN_IRQ_PENDING (BIT(INTERRUPT_STS_OFF) | BIT(WAKE_STS_OFF))
605
606 static bool do_amd_gpio_irq_handler(int irq, void *dev_id)
607 {
608         struct amd_gpio *gpio_dev = dev_id;
609         struct gpio_chip *gc = &gpio_dev->gc;
610         unsigned int i, irqnr;
611         unsigned long flags;
612         u32 __iomem *regs;
613         bool ret = false;
614         u32  regval;
615         u64 status, mask;
616
617         /* Read the wake status */
618         raw_spin_lock_irqsave(&gpio_dev->lock, flags);
619         status = readl(gpio_dev->base + WAKE_INT_STATUS_REG1);
620         status <<= 32;
621         status |= readl(gpio_dev->base + WAKE_INT_STATUS_REG0);
622         raw_spin_unlock_irqrestore(&gpio_dev->lock, flags);
623
624         /* Bit 0-45 contain the relevant status bits */
625         status &= (1ULL << 46) - 1;
626         regs = gpio_dev->base;
627         for (mask = 1, irqnr = 0; status; mask <<= 1, regs += 4, irqnr += 4) {
628                 if (!(status & mask))
629                         continue;
630                 status &= ~mask;
631
632                 /* Each status bit covers four pins */
633                 for (i = 0; i < 4; i++) {
634                         regval = readl(regs + i);
635
636                         if (regval & PIN_IRQ_PENDING)
637                                 pm_pr_dbg("GPIO %d is active: 0x%x",
638                                           irqnr + i, regval);
639
640                         /* caused wake on resume context for shared IRQ */
641                         if (irq < 0 && (regval & BIT(WAKE_STS_OFF)))
642                                 return true;
643
644                         if (!(regval & PIN_IRQ_PENDING) ||
645                             !(regval & BIT(INTERRUPT_MASK_OFF)))
646                                 continue;
647                         generic_handle_domain_irq_safe(gc->irq.domain, irqnr + i);
648
649                         /* Clear interrupt.
650                          * We must read the pin register again, in case the
651                          * value was changed while executing
652                          * generic_handle_domain_irq() above.
653                          * If the line is not an irq, disable it in order to
654                          * avoid a system hang caused by an interrupt storm.
655                          */
656                         raw_spin_lock_irqsave(&gpio_dev->lock, flags);
657                         regval = readl(regs + i);
658                         if (!gpiochip_line_is_irq(gc, irqnr + i)) {
659                                 regval &= ~BIT(INTERRUPT_MASK_OFF);
660                                 dev_dbg(&gpio_dev->pdev->dev,
661                                         "Disabling spurious GPIO IRQ %d\n",
662                                         irqnr + i);
663                         } else {
664                                 ret = true;
665                         }
666                         writel(regval, regs + i);
667                         raw_spin_unlock_irqrestore(&gpio_dev->lock, flags);
668                 }
669         }
670         /* did not cause wake on resume context for shared IRQ */
671         if (irq < 0)
672                 return false;
673
674         /* Signal EOI to the GPIO unit */
675         raw_spin_lock_irqsave(&gpio_dev->lock, flags);
676         regval = readl(gpio_dev->base + WAKE_INT_MASTER_REG);
677         regval |= EOI_MASK;
678         writel(regval, gpio_dev->base + WAKE_INT_MASTER_REG);
679         raw_spin_unlock_irqrestore(&gpio_dev->lock, flags);
680
681         return ret;
682 }
683
684 static irqreturn_t amd_gpio_irq_handler(int irq, void *dev_id)
685 {
686         return IRQ_RETVAL(do_amd_gpio_irq_handler(irq, dev_id));
687 }
688
689 static bool __maybe_unused amd_gpio_check_wake(void *dev_id)
690 {
691         return do_amd_gpio_irq_handler(-1, dev_id);
692 }
693
694 static int amd_get_groups_count(struct pinctrl_dev *pctldev)
695 {
696         struct amd_gpio *gpio_dev = pinctrl_dev_get_drvdata(pctldev);
697
698         return gpio_dev->ngroups;
699 }
700
701 static const char *amd_get_group_name(struct pinctrl_dev *pctldev,
702                                       unsigned group)
703 {
704         struct amd_gpio *gpio_dev = pinctrl_dev_get_drvdata(pctldev);
705
706         return gpio_dev->groups[group].name;
707 }
708
709 static int amd_get_group_pins(struct pinctrl_dev *pctldev,
710                               unsigned group,
711                               const unsigned **pins,
712                               unsigned *num_pins)
713 {
714         struct amd_gpio *gpio_dev = pinctrl_dev_get_drvdata(pctldev);
715
716         *pins = gpio_dev->groups[group].pins;
717         *num_pins = gpio_dev->groups[group].npins;
718         return 0;
719 }
720
721 static const struct pinctrl_ops amd_pinctrl_ops = {
722         .get_groups_count       = amd_get_groups_count,
723         .get_group_name         = amd_get_group_name,
724         .get_group_pins         = amd_get_group_pins,
725 #ifdef CONFIG_OF
726         .dt_node_to_map         = pinconf_generic_dt_node_to_map_group,
727         .dt_free_map            = pinctrl_utils_free_map,
728 #endif
729 };
730
731 static int amd_pinconf_get(struct pinctrl_dev *pctldev,
732                           unsigned int pin,
733                           unsigned long *config)
734 {
735         u32 pin_reg;
736         unsigned arg;
737         unsigned long flags;
738         struct amd_gpio *gpio_dev = pinctrl_dev_get_drvdata(pctldev);
739         enum pin_config_param param = pinconf_to_config_param(*config);
740
741         raw_spin_lock_irqsave(&gpio_dev->lock, flags);
742         pin_reg = readl(gpio_dev->base + pin*4);
743         raw_spin_unlock_irqrestore(&gpio_dev->lock, flags);
744         switch (param) {
745         case PIN_CONFIG_INPUT_DEBOUNCE:
746                 arg = pin_reg & DB_TMR_OUT_MASK;
747                 break;
748
749         case PIN_CONFIG_BIAS_PULL_DOWN:
750                 arg = (pin_reg >> PULL_DOWN_ENABLE_OFF) & BIT(0);
751                 break;
752
753         case PIN_CONFIG_BIAS_PULL_UP:
754                 arg = (pin_reg >> PULL_UP_SEL_OFF) & (BIT(0) | BIT(1));
755                 break;
756
757         case PIN_CONFIG_DRIVE_STRENGTH:
758                 arg = (pin_reg >> DRV_STRENGTH_SEL_OFF) & DRV_STRENGTH_SEL_MASK;
759                 break;
760
761         default:
762                 dev_err(&gpio_dev->pdev->dev, "Invalid config param %04x\n",
763                         param);
764                 return -ENOTSUPP;
765         }
766
767         *config = pinconf_to_config_packed(param, arg);
768
769         return 0;
770 }
771
772 static int amd_pinconf_set(struct pinctrl_dev *pctldev, unsigned int pin,
773                            unsigned long *configs, unsigned int num_configs)
774 {
775         int i;
776         u32 arg;
777         int ret = 0;
778         u32 pin_reg;
779         unsigned long flags;
780         enum pin_config_param param;
781         struct amd_gpio *gpio_dev = pinctrl_dev_get_drvdata(pctldev);
782
783         raw_spin_lock_irqsave(&gpio_dev->lock, flags);
784         for (i = 0; i < num_configs; i++) {
785                 param = pinconf_to_config_param(configs[i]);
786                 arg = pinconf_to_config_argument(configs[i]);
787                 pin_reg = readl(gpio_dev->base + pin*4);
788
789                 switch (param) {
790                 case PIN_CONFIG_INPUT_DEBOUNCE:
791                         pin_reg &= ~DB_TMR_OUT_MASK;
792                         pin_reg |= arg & DB_TMR_OUT_MASK;
793                         break;
794
795                 case PIN_CONFIG_BIAS_PULL_DOWN:
796                         pin_reg &= ~BIT(PULL_DOWN_ENABLE_OFF);
797                         pin_reg |= (arg & BIT(0)) << PULL_DOWN_ENABLE_OFF;
798                         break;
799
800                 case PIN_CONFIG_BIAS_PULL_UP:
801                         pin_reg &= ~BIT(PULL_UP_SEL_OFF);
802                         pin_reg |= (arg & BIT(0)) << PULL_UP_SEL_OFF;
803                         pin_reg &= ~BIT(PULL_UP_ENABLE_OFF);
804                         pin_reg |= ((arg>>1) & BIT(0)) << PULL_UP_ENABLE_OFF;
805                         break;
806
807                 case PIN_CONFIG_DRIVE_STRENGTH:
808                         pin_reg &= ~(DRV_STRENGTH_SEL_MASK
809                                         << DRV_STRENGTH_SEL_OFF);
810                         pin_reg |= (arg & DRV_STRENGTH_SEL_MASK)
811                                         << DRV_STRENGTH_SEL_OFF;
812                         break;
813
814                 default:
815                         dev_err(&gpio_dev->pdev->dev,
816                                 "Invalid config param %04x\n", param);
817                         ret = -ENOTSUPP;
818                 }
819
820                 writel(pin_reg, gpio_dev->base + pin*4);
821         }
822         raw_spin_unlock_irqrestore(&gpio_dev->lock, flags);
823
824         return ret;
825 }
826
827 static int amd_pinconf_group_get(struct pinctrl_dev *pctldev,
828                                 unsigned int group,
829                                 unsigned long *config)
830 {
831         const unsigned *pins;
832         unsigned npins;
833         int ret;
834
835         ret = amd_get_group_pins(pctldev, group, &pins, &npins);
836         if (ret)
837                 return ret;
838
839         if (amd_pinconf_get(pctldev, pins[0], config))
840                         return -ENOTSUPP;
841
842         return 0;
843 }
844
845 static int amd_pinconf_group_set(struct pinctrl_dev *pctldev,
846                                 unsigned group, unsigned long *configs,
847                                 unsigned num_configs)
848 {
849         const unsigned *pins;
850         unsigned npins;
851         int i, ret;
852
853         ret = amd_get_group_pins(pctldev, group, &pins, &npins);
854         if (ret)
855                 return ret;
856         for (i = 0; i < npins; i++) {
857                 if (amd_pinconf_set(pctldev, pins[i], configs, num_configs))
858                         return -ENOTSUPP;
859         }
860         return 0;
861 }
862
863 static int amd_gpio_set_config(struct gpio_chip *gc, unsigned int pin,
864                                unsigned long config)
865 {
866         struct amd_gpio *gpio_dev = gpiochip_get_data(gc);
867
868         if (pinconf_to_config_param(config) == PIN_CONFIG_INPUT_DEBOUNCE) {
869                 u32 debounce = pinconf_to_config_argument(config);
870
871                 return amd_gpio_set_debounce(gc, pin, debounce);
872         }
873
874         return amd_pinconf_set(gpio_dev->pctrl, pin, &config, 1);
875 }
876
877 static const struct pinconf_ops amd_pinconf_ops = {
878         .pin_config_get         = amd_pinconf_get,
879         .pin_config_set         = amd_pinconf_set,
880         .pin_config_group_get = amd_pinconf_group_get,
881         .pin_config_group_set = amd_pinconf_group_set,
882 };
883
884 #ifdef CONFIG_PM_SLEEP
885 static bool amd_gpio_should_save(struct amd_gpio *gpio_dev, unsigned int pin)
886 {
887         const struct pin_desc *pd = pin_desc_get(gpio_dev->pctrl, pin);
888
889         if (!pd)
890                 return false;
891
892         /*
893          * Only restore the pin if it is actually in use by the kernel (or
894          * by userspace).
895          */
896         if (pd->mux_owner || pd->gpio_owner ||
897             gpiochip_line_is_irq(&gpio_dev->gc, pin))
898                 return true;
899
900         return false;
901 }
902
903 static int amd_gpio_suspend(struct device *dev)
904 {
905         struct amd_gpio *gpio_dev = dev_get_drvdata(dev);
906         struct pinctrl_desc *desc = gpio_dev->pctrl->desc;
907         unsigned long flags;
908         int i;
909
910         for (i = 0; i < desc->npins; i++) {
911                 int pin = desc->pins[i].number;
912
913                 if (!amd_gpio_should_save(gpio_dev, pin))
914                         continue;
915
916                 raw_spin_lock_irqsave(&gpio_dev->lock, flags);
917                 gpio_dev->saved_regs[i] = readl(gpio_dev->base + pin * 4) & ~PIN_IRQ_PENDING;
918                 raw_spin_unlock_irqrestore(&gpio_dev->lock, flags);
919         }
920
921         return 0;
922 }
923
924 static int amd_gpio_resume(struct device *dev)
925 {
926         struct amd_gpio *gpio_dev = dev_get_drvdata(dev);
927         struct pinctrl_desc *desc = gpio_dev->pctrl->desc;
928         unsigned long flags;
929         int i;
930
931         for (i = 0; i < desc->npins; i++) {
932                 int pin = desc->pins[i].number;
933
934                 if (!amd_gpio_should_save(gpio_dev, pin))
935                         continue;
936
937                 raw_spin_lock_irqsave(&gpio_dev->lock, flags);
938                 gpio_dev->saved_regs[i] |= readl(gpio_dev->base + pin * 4) & PIN_IRQ_PENDING;
939                 writel(gpio_dev->saved_regs[i], gpio_dev->base + pin * 4);
940                 raw_spin_unlock_irqrestore(&gpio_dev->lock, flags);
941         }
942
943         return 0;
944 }
945
946 static const struct dev_pm_ops amd_gpio_pm_ops = {
947         SET_LATE_SYSTEM_SLEEP_PM_OPS(amd_gpio_suspend,
948                                      amd_gpio_resume)
949 };
950 #endif
951
952 static int amd_get_functions_count(struct pinctrl_dev *pctldev)
953 {
954         return ARRAY_SIZE(pmx_functions);
955 }
956
957 static const char *amd_get_fname(struct pinctrl_dev *pctrldev, unsigned int selector)
958 {
959         return pmx_functions[selector].name;
960 }
961
962 static int amd_get_groups(struct pinctrl_dev *pctrldev, unsigned int selector,
963                           const char * const **groups,
964                           unsigned int * const num_groups)
965 {
966         struct amd_gpio *gpio_dev = pinctrl_dev_get_drvdata(pctrldev);
967
968         if (!gpio_dev->iomux_base) {
969                 dev_err(&gpio_dev->pdev->dev, "iomux function %d group not supported\n", selector);
970                 return -EINVAL;
971         }
972
973         *groups = pmx_functions[selector].groups;
974         *num_groups = pmx_functions[selector].ngroups;
975         return 0;
976 }
977
978 static int amd_set_mux(struct pinctrl_dev *pctrldev, unsigned int function, unsigned int group)
979 {
980         struct amd_gpio *gpio_dev = pinctrl_dev_get_drvdata(pctrldev);
981         struct device *dev = &gpio_dev->pdev->dev;
982         struct pin_desc *pd;
983         int ind, index;
984
985         if (!gpio_dev->iomux_base)
986                 return -EINVAL;
987
988         for (index = 0; index < NSELECTS; index++) {
989                 if (strcmp(gpio_dev->groups[group].name,  pmx_functions[function].groups[index]))
990                         continue;
991
992                 if (readb(gpio_dev->iomux_base + pmx_functions[function].index) ==
993                                 FUNCTION_INVALID) {
994                         dev_err(dev, "IOMUX_GPIO 0x%x not present or supported\n",
995                                 pmx_functions[function].index);
996                         return -EINVAL;
997                 }
998
999                 writeb(index, gpio_dev->iomux_base + pmx_functions[function].index);
1000
1001                 if (index != (readb(gpio_dev->iomux_base + pmx_functions[function].index) &
1002                                         FUNCTION_MASK)) {
1003                         dev_err(dev, "IOMUX_GPIO 0x%x not present or supported\n",
1004                                 pmx_functions[function].index);
1005                         return -EINVAL;
1006                 }
1007
1008                 for (ind = 0; ind < gpio_dev->groups[group].npins; ind++) {
1009                         if (strncmp(gpio_dev->groups[group].name, "IMX_F", strlen("IMX_F")))
1010                                 continue;
1011
1012                         pd = pin_desc_get(gpio_dev->pctrl, gpio_dev->groups[group].pins[ind]);
1013                         pd->mux_owner = gpio_dev->groups[group].name;
1014                 }
1015                 break;
1016         }
1017
1018         return 0;
1019 }
1020
1021 static const struct pinmux_ops amd_pmxops = {
1022         .get_functions_count = amd_get_functions_count,
1023         .get_function_name = amd_get_fname,
1024         .get_function_groups = amd_get_groups,
1025         .set_mux = amd_set_mux,
1026 };
1027
1028 static struct pinctrl_desc amd_pinctrl_desc = {
1029         .pins   = kerncz_pins,
1030         .npins = ARRAY_SIZE(kerncz_pins),
1031         .pctlops = &amd_pinctrl_ops,
1032         .pmxops = &amd_pmxops,
1033         .confops = &amd_pinconf_ops,
1034         .owner = THIS_MODULE,
1035 };
1036
1037 static void amd_get_iomux_res(struct amd_gpio *gpio_dev)
1038 {
1039         struct pinctrl_desc *desc = &amd_pinctrl_desc;
1040         struct device *dev = &gpio_dev->pdev->dev;
1041         int index;
1042
1043         index = device_property_match_string(dev, "pinctrl-resource-names",  "iomux");
1044         if (index < 0) {
1045                 dev_dbg(dev, "iomux not supported\n");
1046                 goto out_no_pinmux;
1047         }
1048
1049         gpio_dev->iomux_base = devm_platform_ioremap_resource(gpio_dev->pdev, index);
1050         if (IS_ERR(gpio_dev->iomux_base)) {
1051                 dev_dbg(dev, "iomux not supported %d io resource\n", index);
1052                 goto out_no_pinmux;
1053         }
1054
1055         return;
1056
1057 out_no_pinmux:
1058         desc->pmxops = NULL;
1059 }
1060
1061 static int amd_gpio_probe(struct platform_device *pdev)
1062 {
1063         int ret = 0;
1064         struct resource *res;
1065         struct amd_gpio *gpio_dev;
1066         struct gpio_irq_chip *girq;
1067
1068         gpio_dev = devm_kzalloc(&pdev->dev,
1069                                 sizeof(struct amd_gpio), GFP_KERNEL);
1070         if (!gpio_dev)
1071                 return -ENOMEM;
1072
1073         raw_spin_lock_init(&gpio_dev->lock);
1074
1075         gpio_dev->base = devm_platform_get_and_ioremap_resource(pdev, 0, &res);
1076         if (IS_ERR(gpio_dev->base)) {
1077                 dev_err(&pdev->dev, "Failed to get gpio io resource.\n");
1078                 return PTR_ERR(gpio_dev->base);
1079         }
1080
1081         gpio_dev->irq = platform_get_irq(pdev, 0);
1082         if (gpio_dev->irq < 0)
1083                 return gpio_dev->irq;
1084
1085 #ifdef CONFIG_PM_SLEEP
1086         gpio_dev->saved_regs = devm_kcalloc(&pdev->dev, amd_pinctrl_desc.npins,
1087                                             sizeof(*gpio_dev->saved_regs),
1088                                             GFP_KERNEL);
1089         if (!gpio_dev->saved_regs)
1090                 return -ENOMEM;
1091 #endif
1092
1093         gpio_dev->pdev = pdev;
1094         gpio_dev->gc.get_direction      = amd_gpio_get_direction;
1095         gpio_dev->gc.direction_input    = amd_gpio_direction_input;
1096         gpio_dev->gc.direction_output   = amd_gpio_direction_output;
1097         gpio_dev->gc.get                        = amd_gpio_get_value;
1098         gpio_dev->gc.set                        = amd_gpio_set_value;
1099         gpio_dev->gc.set_config         = amd_gpio_set_config;
1100         gpio_dev->gc.dbg_show           = amd_gpio_dbg_show;
1101
1102         gpio_dev->gc.base               = -1;
1103         gpio_dev->gc.label                      = pdev->name;
1104         gpio_dev->gc.owner                      = THIS_MODULE;
1105         gpio_dev->gc.parent                     = &pdev->dev;
1106         gpio_dev->gc.ngpio                      = resource_size(res) / 4;
1107
1108         gpio_dev->hwbank_num = gpio_dev->gc.ngpio / 64;
1109         gpio_dev->groups = kerncz_groups;
1110         gpio_dev->ngroups = ARRAY_SIZE(kerncz_groups);
1111
1112         amd_pinctrl_desc.name = dev_name(&pdev->dev);
1113         amd_get_iomux_res(gpio_dev);
1114         gpio_dev->pctrl = devm_pinctrl_register(&pdev->dev, &amd_pinctrl_desc,
1115                                                 gpio_dev);
1116         if (IS_ERR(gpio_dev->pctrl)) {
1117                 dev_err(&pdev->dev, "Couldn't register pinctrl driver\n");
1118                 return PTR_ERR(gpio_dev->pctrl);
1119         }
1120
1121         girq = &gpio_dev->gc.irq;
1122         gpio_irq_chip_set_chip(girq, &amd_gpio_irqchip);
1123         /* This will let us handle the parent IRQ in the driver */
1124         girq->parent_handler = NULL;
1125         girq->num_parents = 0;
1126         girq->parents = NULL;
1127         girq->default_type = IRQ_TYPE_NONE;
1128         girq->handler = handle_simple_irq;
1129
1130         ret = gpiochip_add_data(&gpio_dev->gc, gpio_dev);
1131         if (ret)
1132                 return ret;
1133
1134         ret = gpiochip_add_pin_range(&gpio_dev->gc, dev_name(&pdev->dev),
1135                                 0, 0, gpio_dev->gc.ngpio);
1136         if (ret) {
1137                 dev_err(&pdev->dev, "Failed to add pin range\n");
1138                 goto out2;
1139         }
1140
1141         ret = devm_request_irq(&pdev->dev, gpio_dev->irq, amd_gpio_irq_handler,
1142                                IRQF_SHARED, KBUILD_MODNAME, gpio_dev);
1143         if (ret)
1144                 goto out2;
1145
1146         platform_set_drvdata(pdev, gpio_dev);
1147         acpi_register_wakeup_handler(gpio_dev->irq, amd_gpio_check_wake, gpio_dev);
1148
1149         dev_dbg(&pdev->dev, "amd gpio driver loaded\n");
1150         return ret;
1151
1152 out2:
1153         gpiochip_remove(&gpio_dev->gc);
1154
1155         return ret;
1156 }
1157
1158 static int amd_gpio_remove(struct platform_device *pdev)
1159 {
1160         struct amd_gpio *gpio_dev;
1161
1162         gpio_dev = platform_get_drvdata(pdev);
1163
1164         gpiochip_remove(&gpio_dev->gc);
1165         acpi_unregister_wakeup_handler(amd_gpio_check_wake, gpio_dev);
1166
1167         return 0;
1168 }
1169
1170 #ifdef CONFIG_ACPI
1171 static const struct acpi_device_id amd_gpio_acpi_match[] = {
1172         { "AMD0030", 0 },
1173         { "AMDI0030", 0},
1174         { "AMDI0031", 0},
1175         { },
1176 };
1177 MODULE_DEVICE_TABLE(acpi, amd_gpio_acpi_match);
1178 #endif
1179
1180 static struct platform_driver amd_gpio_driver = {
1181         .driver         = {
1182                 .name   = "amd_gpio",
1183                 .acpi_match_table = ACPI_PTR(amd_gpio_acpi_match),
1184 #ifdef CONFIG_PM_SLEEP
1185                 .pm     = &amd_gpio_pm_ops,
1186 #endif
1187         },
1188         .probe          = amd_gpio_probe,
1189         .remove         = amd_gpio_remove,
1190 };
1191
1192 module_platform_driver(amd_gpio_driver);
1193
1194 MODULE_AUTHOR("Ken Xue <Ken.Xue@amd.com>, Jeff Wu <Jeff.Wu@amd.com>");
1195 MODULE_DESCRIPTION("AMD GPIO pinctrl driver");