4 * Copyright (c) 2014,2015 AMD Corporation.
5 * Authors: Ken Xue <Ken.Xue@amd.com>
6 * Wu, Jeff <Jeff.Wu@amd.com>
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms and conditions of the GNU General Public License,
10 * version 2, as published by the Free Software Foundation.
13 #include <linux/err.h>
14 #include <linux/bug.h>
15 #include <linux/kernel.h>
16 #include <linux/module.h>
17 #include <linux/spinlock.h>
18 #include <linux/compiler.h>
19 #include <linux/types.h>
20 #include <linux/errno.h>
21 #include <linux/log2.h>
23 #include <linux/gpio.h>
24 #include <linux/slab.h>
25 #include <linux/platform_device.h>
26 #include <linux/mutex.h>
27 #include <linux/acpi.h>
28 #include <linux/seq_file.h>
29 #include <linux/interrupt.h>
30 #include <linux/list.h>
31 #include <linux/bitops.h>
32 #include <linux/pinctrl/pinconf.h>
33 #include <linux/pinctrl/pinconf-generic.h>
35 #include "pinctrl-utils.h"
36 #include "pinctrl-amd.h"
38 static int amd_gpio_direction_input(struct gpio_chip *gc, unsigned offset)
42 struct amd_gpio *gpio_dev = gpiochip_get_data(gc);
44 spin_lock_irqsave(&gpio_dev->lock, flags);
45 pin_reg = readl(gpio_dev->base + offset * 4);
47 * Suppose BIOS or Bootloader sets specific debounce for the
48 * GPIO. if not, set debounce to be 2.75ms and remove glitch.
50 if ((pin_reg & DB_TMR_OUT_MASK) == 0) {
52 pin_reg |= BIT(DB_TMR_OUT_UNIT_OFF);
53 pin_reg |= DB_TYPE_REMOVE_GLITCH << DB_CNTRL_OFF;
54 pin_reg &= ~BIT(DB_TMR_LARGE_OFF);
57 pin_reg &= ~BIT(OUTPUT_ENABLE_OFF);
58 writel(pin_reg, gpio_dev->base + offset * 4);
59 spin_unlock_irqrestore(&gpio_dev->lock, flags);
64 static int amd_gpio_direction_output(struct gpio_chip *gc, unsigned offset,
69 struct amd_gpio *gpio_dev = gpiochip_get_data(gc);
71 spin_lock_irqsave(&gpio_dev->lock, flags);
72 pin_reg = readl(gpio_dev->base + offset * 4);
73 pin_reg |= BIT(OUTPUT_ENABLE_OFF);
75 pin_reg |= BIT(OUTPUT_VALUE_OFF);
77 pin_reg &= ~BIT(OUTPUT_VALUE_OFF);
78 writel(pin_reg, gpio_dev->base + offset * 4);
79 spin_unlock_irqrestore(&gpio_dev->lock, flags);
84 static int amd_gpio_get_value(struct gpio_chip *gc, unsigned offset)
88 struct amd_gpio *gpio_dev = gpiochip_get_data(gc);
90 spin_lock_irqsave(&gpio_dev->lock, flags);
91 pin_reg = readl(gpio_dev->base + offset * 4);
92 spin_unlock_irqrestore(&gpio_dev->lock, flags);
94 return !!(pin_reg & BIT(PIN_STS_OFF));
97 static void amd_gpio_set_value(struct gpio_chip *gc, unsigned offset, int value)
101 struct amd_gpio *gpio_dev = gpiochip_get_data(gc);
103 spin_lock_irqsave(&gpio_dev->lock, flags);
104 pin_reg = readl(gpio_dev->base + offset * 4);
106 pin_reg |= BIT(OUTPUT_VALUE_OFF);
108 pin_reg &= ~BIT(OUTPUT_VALUE_OFF);
109 writel(pin_reg, gpio_dev->base + offset * 4);
110 spin_unlock_irqrestore(&gpio_dev->lock, flags);
113 static int amd_gpio_set_debounce(struct gpio_chip *gc, unsigned offset,
120 struct amd_gpio *gpio_dev = gpiochip_get_data(gc);
122 spin_lock_irqsave(&gpio_dev->lock, flags);
123 pin_reg = readl(gpio_dev->base + offset * 4);
126 pin_reg |= DB_TYPE_REMOVE_GLITCH << DB_CNTRL_OFF;
127 pin_reg &= ~DB_TMR_OUT_MASK;
129 Debounce Debounce Timer Max
130 TmrLarge TmrOutUnit Unit Debounce
132 0 0 61 usec (2 RtcClk) 976 usec
133 0 1 244 usec (8 RtcClk) 3.9 msec
134 1 0 15.6 msec (512 RtcClk) 250 msec
135 1 1 62.5 msec (2048 RtcClk) 1 sec
140 pin_reg &= ~BIT(DB_TMR_OUT_UNIT_OFF);
141 pin_reg &= ~BIT(DB_TMR_LARGE_OFF);
142 } else if (debounce < 976) {
143 time = debounce / 61;
144 pin_reg |= time & DB_TMR_OUT_MASK;
145 pin_reg &= ~BIT(DB_TMR_OUT_UNIT_OFF);
146 pin_reg &= ~BIT(DB_TMR_LARGE_OFF);
147 } else if (debounce < 3900) {
148 time = debounce / 244;
149 pin_reg |= time & DB_TMR_OUT_MASK;
150 pin_reg |= BIT(DB_TMR_OUT_UNIT_OFF);
151 pin_reg &= ~BIT(DB_TMR_LARGE_OFF);
152 } else if (debounce < 250000) {
153 time = debounce / 15600;
154 pin_reg |= time & DB_TMR_OUT_MASK;
155 pin_reg &= ~BIT(DB_TMR_OUT_UNIT_OFF);
156 pin_reg |= BIT(DB_TMR_LARGE_OFF);
157 } else if (debounce < 1000000) {
158 time = debounce / 62500;
159 pin_reg |= time & DB_TMR_OUT_MASK;
160 pin_reg |= BIT(DB_TMR_OUT_UNIT_OFF);
161 pin_reg |= BIT(DB_TMR_LARGE_OFF);
163 pin_reg &= ~DB_CNTRl_MASK;
167 pin_reg &= ~BIT(DB_TMR_OUT_UNIT_OFF);
168 pin_reg &= ~BIT(DB_TMR_LARGE_OFF);
169 pin_reg &= ~DB_TMR_OUT_MASK;
170 pin_reg &= ~DB_CNTRl_MASK;
172 writel(pin_reg, gpio_dev->base + offset * 4);
173 spin_unlock_irqrestore(&gpio_dev->lock, flags);
178 #ifdef CONFIG_DEBUG_FS
179 static void amd_gpio_dbg_show(struct seq_file *s, struct gpio_chip *gc)
183 unsigned int bank, i, pin_num;
184 struct amd_gpio *gpio_dev = gpiochip_get_data(gc);
188 char *interrupt_enable;
189 char *interrupt_mask;
195 char *pull_up_enable;
196 char *pull_down_enable;
200 for (bank = 0; bank < AMD_GPIO_TOTAL_BANKS; bank++) {
201 seq_printf(s, "GPIO bank%d\t", bank);
206 pin_num = AMD_GPIO_PINS_BANK0;
210 pin_num = AMD_GPIO_PINS_BANK1 + i;
214 pin_num = AMD_GPIO_PINS_BANK2 + i;
218 for (; i < pin_num; i++) {
219 seq_printf(s, "pin%d\t", i);
220 spin_lock_irqsave(&gpio_dev->lock, flags);
221 pin_reg = readl(gpio_dev->base + i * 4);
222 spin_unlock_irqrestore(&gpio_dev->lock, flags);
224 if (pin_reg & BIT(INTERRUPT_ENABLE_OFF)) {
225 interrupt_enable = "interrupt is enabled|";
227 if (!(pin_reg & BIT(ACTIVE_LEVEL_OFF))
228 && !(pin_reg & BIT(ACTIVE_LEVEL_OFF+1)))
229 active_level = "Active low|";
230 else if (pin_reg & BIT(ACTIVE_LEVEL_OFF)
231 && !(pin_reg & BIT(ACTIVE_LEVEL_OFF+1)))
232 active_level = "Active high|";
233 else if (!(pin_reg & BIT(ACTIVE_LEVEL_OFF))
234 && pin_reg & BIT(ACTIVE_LEVEL_OFF+1))
235 active_level = "Active on both|";
237 active_level = "Unknow Active level|";
239 if (pin_reg & BIT(LEVEL_TRIG_OFF))
240 level_trig = "Level trigger|";
242 level_trig = "Edge trigger|";
246 "interrupt is disabled|";
251 if (pin_reg & BIT(INTERRUPT_MASK_OFF))
253 "interrupt is unmasked|";
256 "interrupt is masked|";
258 if (pin_reg & BIT(WAKE_CNTRL_OFF))
259 wake_cntrl0 = "enable wakeup in S0i3 state|";
261 wake_cntrl0 = "disable wakeup in S0i3 state|";
263 if (pin_reg & BIT(WAKE_CNTRL_OFF))
264 wake_cntrl1 = "enable wakeup in S3 state|";
266 wake_cntrl1 = "disable wakeup in S3 state|";
268 if (pin_reg & BIT(WAKE_CNTRL_OFF))
269 wake_cntrl2 = "enable wakeup in S4/S5 state|";
271 wake_cntrl2 = "disable wakeup in S4/S5 state|";
273 if (pin_reg & BIT(PULL_UP_ENABLE_OFF)) {
274 pull_up_enable = "pull-up is enabled|";
275 if (pin_reg & BIT(PULL_UP_SEL_OFF))
276 pull_up_sel = "8k pull-up|";
278 pull_up_sel = "4k pull-up|";
280 pull_up_enable = "pull-up is disabled|";
284 if (pin_reg & BIT(PULL_DOWN_ENABLE_OFF))
285 pull_down_enable = "pull-down is enabled|";
287 pull_down_enable = "Pull-down is disabled|";
289 if (pin_reg & BIT(OUTPUT_ENABLE_OFF)) {
291 output_enable = "output is enabled|";
292 if (pin_reg & BIT(OUTPUT_VALUE_OFF))
293 output_value = "output is high|";
295 output_value = "output is low|";
297 output_enable = "output is disabled|";
300 if (pin_reg & BIT(PIN_STS_OFF))
301 pin_sts = "input is high|";
303 pin_sts = "input is low|";
306 seq_printf(s, "%s %s %s %s %s %s\n"
307 " %s %s %s %s %s %s %s 0x%x\n",
308 level_trig, active_level, interrupt_enable,
309 interrupt_mask, wake_cntrl0, wake_cntrl1,
310 wake_cntrl2, pin_sts, pull_up_sel,
311 pull_up_enable, pull_down_enable,
312 output_value, output_enable, pin_reg);
317 #define amd_gpio_dbg_show NULL
320 static void amd_gpio_irq_enable(struct irq_data *d)
324 struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
325 struct amd_gpio *gpio_dev = gpiochip_get_data(gc);
327 spin_lock_irqsave(&gpio_dev->lock, flags);
328 pin_reg = readl(gpio_dev->base + (d->hwirq)*4);
330 Suppose BIOS or Bootloader sets specific debounce for the
331 GPIO. if not, set debounce to be 2.75ms.
333 if ((pin_reg & DB_TMR_OUT_MASK) == 0) {
335 pin_reg |= BIT(DB_TMR_OUT_UNIT_OFF);
336 pin_reg &= ~BIT(DB_TMR_LARGE_OFF);
338 pin_reg |= BIT(INTERRUPT_ENABLE_OFF);
339 pin_reg |= BIT(INTERRUPT_MASK_OFF);
340 writel(pin_reg, gpio_dev->base + (d->hwirq)*4);
341 spin_unlock_irqrestore(&gpio_dev->lock, flags);
344 static void amd_gpio_irq_disable(struct irq_data *d)
348 struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
349 struct amd_gpio *gpio_dev = gpiochip_get_data(gc);
351 spin_lock_irqsave(&gpio_dev->lock, flags);
352 pin_reg = readl(gpio_dev->base + (d->hwirq)*4);
353 pin_reg &= ~BIT(INTERRUPT_ENABLE_OFF);
354 pin_reg &= ~BIT(INTERRUPT_MASK_OFF);
355 writel(pin_reg, gpio_dev->base + (d->hwirq)*4);
356 spin_unlock_irqrestore(&gpio_dev->lock, flags);
359 static void amd_gpio_irq_mask(struct irq_data *d)
363 struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
364 struct amd_gpio *gpio_dev = gpiochip_get_data(gc);
366 spin_lock_irqsave(&gpio_dev->lock, flags);
367 pin_reg = readl(gpio_dev->base + (d->hwirq)*4);
368 pin_reg &= ~BIT(INTERRUPT_MASK_OFF);
369 writel(pin_reg, gpio_dev->base + (d->hwirq)*4);
370 spin_unlock_irqrestore(&gpio_dev->lock, flags);
373 static void amd_gpio_irq_unmask(struct irq_data *d)
377 struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
378 struct amd_gpio *gpio_dev = gpiochip_get_data(gc);
380 spin_lock_irqsave(&gpio_dev->lock, flags);
381 pin_reg = readl(gpio_dev->base + (d->hwirq)*4);
382 pin_reg |= BIT(INTERRUPT_MASK_OFF);
383 writel(pin_reg, gpio_dev->base + (d->hwirq)*4);
384 spin_unlock_irqrestore(&gpio_dev->lock, flags);
387 static void amd_gpio_irq_eoi(struct irq_data *d)
391 struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
392 struct amd_gpio *gpio_dev = gpiochip_get_data(gc);
394 spin_lock_irqsave(&gpio_dev->lock, flags);
395 reg = readl(gpio_dev->base + WAKE_INT_MASTER_REG);
397 writel(reg, gpio_dev->base + WAKE_INT_MASTER_REG);
398 spin_unlock_irqrestore(&gpio_dev->lock, flags);
401 static int amd_gpio_irq_set_type(struct irq_data *d, unsigned int type)
406 struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
407 struct amd_gpio *gpio_dev = gpiochip_get_data(gc);
409 spin_lock_irqsave(&gpio_dev->lock, flags);
410 pin_reg = readl(gpio_dev->base + (d->hwirq)*4);
412 switch (type & IRQ_TYPE_SENSE_MASK) {
413 case IRQ_TYPE_EDGE_RISING:
414 pin_reg &= ~BIT(LEVEL_TRIG_OFF);
415 pin_reg &= ~(ACTIVE_LEVEL_MASK << ACTIVE_LEVEL_OFF);
416 pin_reg |= ACTIVE_HIGH << ACTIVE_LEVEL_OFF;
417 pin_reg |= DB_TYPE_REMOVE_GLITCH << DB_CNTRL_OFF;
418 irq_set_handler_locked(d, handle_edge_irq);
421 case IRQ_TYPE_EDGE_FALLING:
422 pin_reg &= ~BIT(LEVEL_TRIG_OFF);
423 pin_reg &= ~(ACTIVE_LEVEL_MASK << ACTIVE_LEVEL_OFF);
424 pin_reg |= ACTIVE_LOW << ACTIVE_LEVEL_OFF;
425 pin_reg |= DB_TYPE_REMOVE_GLITCH << DB_CNTRL_OFF;
426 irq_set_handler_locked(d, handle_edge_irq);
429 case IRQ_TYPE_EDGE_BOTH:
430 pin_reg &= ~BIT(LEVEL_TRIG_OFF);
431 pin_reg &= ~(ACTIVE_LEVEL_MASK << ACTIVE_LEVEL_OFF);
432 pin_reg |= BOTH_EADGE << ACTIVE_LEVEL_OFF;
433 pin_reg |= DB_TYPE_REMOVE_GLITCH << DB_CNTRL_OFF;
434 irq_set_handler_locked(d, handle_edge_irq);
437 case IRQ_TYPE_LEVEL_HIGH:
438 pin_reg |= LEVEL_TRIGGER << LEVEL_TRIG_OFF;
439 pin_reg &= ~(ACTIVE_LEVEL_MASK << ACTIVE_LEVEL_OFF);
440 pin_reg |= ACTIVE_HIGH << ACTIVE_LEVEL_OFF;
441 pin_reg &= ~(DB_CNTRl_MASK << DB_CNTRL_OFF);
442 pin_reg |= DB_TYPE_PRESERVE_LOW_GLITCH << DB_CNTRL_OFF;
443 irq_set_handler_locked(d, handle_level_irq);
446 case IRQ_TYPE_LEVEL_LOW:
447 pin_reg |= LEVEL_TRIGGER << LEVEL_TRIG_OFF;
448 pin_reg &= ~(ACTIVE_LEVEL_MASK << ACTIVE_LEVEL_OFF);
449 pin_reg |= ACTIVE_LOW << ACTIVE_LEVEL_OFF;
450 pin_reg &= ~(DB_CNTRl_MASK << DB_CNTRL_OFF);
451 pin_reg |= DB_TYPE_PRESERVE_HIGH_GLITCH << DB_CNTRL_OFF;
452 irq_set_handler_locked(d, handle_level_irq);
459 dev_err(&gpio_dev->pdev->dev, "Invalid type value\n");
463 pin_reg |= CLR_INTR_STAT << INTERRUPT_STS_OFF;
464 writel(pin_reg, gpio_dev->base + (d->hwirq)*4);
465 spin_unlock_irqrestore(&gpio_dev->lock, flags);
470 static void amd_irq_ack(struct irq_data *d)
473 * based on HW design,there is no need to ack HW
474 * before handle current irq. But this routine is
475 * necessary for handle_edge_irq
479 static struct irq_chip amd_gpio_irqchip = {
481 .irq_ack = amd_irq_ack,
482 .irq_enable = amd_gpio_irq_enable,
483 .irq_disable = amd_gpio_irq_disable,
484 .irq_mask = amd_gpio_irq_mask,
485 .irq_unmask = amd_gpio_irq_unmask,
486 .irq_eoi = amd_gpio_irq_eoi,
487 .irq_set_type = amd_gpio_irq_set_type,
490 static void amd_gpio_irq_handler(struct irq_desc *desc)
500 struct irq_chip *chip = irq_desc_get_chip(desc);
501 struct gpio_chip *gc = irq_desc_get_handler_data(desc);
502 struct amd_gpio *gpio_dev = gpiochip_get_data(gc);
504 chained_irq_enter(chip, desc);
505 /*enable GPIO interrupt again*/
506 spin_lock_irqsave(&gpio_dev->lock, flags);
507 reg = readl(gpio_dev->base + WAKE_INT_STATUS_REG1);
511 reg = readl(gpio_dev->base + WAKE_INT_STATUS_REG0);
513 spin_unlock_irqrestore(&gpio_dev->lock, flags);
516 * first 46 bits indicates interrupt status.
517 * one bit represents four interrupt sources.
519 for (off = 0; off < 46 ; off++) {
520 if (reg64 & BIT(off)) {
521 for (i = 0; i < 4; i++) {
522 pin_reg = readl(gpio_dev->base +
524 if ((pin_reg & BIT(INTERRUPT_STS_OFF)) ||
525 (pin_reg & BIT(WAKE_STS_OFF))) {
526 irq = irq_find_mapping(gc->irqdomain,
528 generic_handle_irq(irq);
531 + (off * 4 + i) * 4);
539 handle_bad_irq(desc);
541 spin_lock_irqsave(&gpio_dev->lock, flags);
542 reg = readl(gpio_dev->base + WAKE_INT_MASTER_REG);
544 writel(reg, gpio_dev->base + WAKE_INT_MASTER_REG);
545 spin_unlock_irqrestore(&gpio_dev->lock, flags);
547 chained_irq_exit(chip, desc);
550 static int amd_get_groups_count(struct pinctrl_dev *pctldev)
552 struct amd_gpio *gpio_dev = pinctrl_dev_get_drvdata(pctldev);
554 return gpio_dev->ngroups;
557 static const char *amd_get_group_name(struct pinctrl_dev *pctldev,
560 struct amd_gpio *gpio_dev = pinctrl_dev_get_drvdata(pctldev);
562 return gpio_dev->groups[group].name;
565 static int amd_get_group_pins(struct pinctrl_dev *pctldev,
567 const unsigned **pins,
570 struct amd_gpio *gpio_dev = pinctrl_dev_get_drvdata(pctldev);
572 *pins = gpio_dev->groups[group].pins;
573 *num_pins = gpio_dev->groups[group].npins;
577 static const struct pinctrl_ops amd_pinctrl_ops = {
578 .get_groups_count = amd_get_groups_count,
579 .get_group_name = amd_get_group_name,
580 .get_group_pins = amd_get_group_pins,
582 .dt_node_to_map = pinconf_generic_dt_node_to_map_group,
583 .dt_free_map = pinctrl_utils_free_map,
587 static int amd_pinconf_get(struct pinctrl_dev *pctldev,
589 unsigned long *config)
594 struct amd_gpio *gpio_dev = pinctrl_dev_get_drvdata(pctldev);
595 enum pin_config_param param = pinconf_to_config_param(*config);
597 spin_lock_irqsave(&gpio_dev->lock, flags);
598 pin_reg = readl(gpio_dev->base + pin*4);
599 spin_unlock_irqrestore(&gpio_dev->lock, flags);
601 case PIN_CONFIG_INPUT_DEBOUNCE:
602 arg = pin_reg & DB_TMR_OUT_MASK;
605 case PIN_CONFIG_BIAS_PULL_DOWN:
606 arg = (pin_reg >> PULL_DOWN_ENABLE_OFF) & BIT(0);
609 case PIN_CONFIG_BIAS_PULL_UP:
610 arg = (pin_reg >> PULL_UP_SEL_OFF) & (BIT(0) | BIT(1));
613 case PIN_CONFIG_DRIVE_STRENGTH:
614 arg = (pin_reg >> DRV_STRENGTH_SEL_OFF) & DRV_STRENGTH_SEL_MASK;
618 dev_err(&gpio_dev->pdev->dev, "Invalid config param %04x\n",
623 *config = pinconf_to_config_packed(param, arg);
628 static int amd_pinconf_set(struct pinctrl_dev *pctldev, unsigned int pin,
629 unsigned long *configs, unsigned num_configs)
636 enum pin_config_param param;
637 struct amd_gpio *gpio_dev = pinctrl_dev_get_drvdata(pctldev);
639 spin_lock_irqsave(&gpio_dev->lock, flags);
640 for (i = 0; i < num_configs; i++) {
641 param = pinconf_to_config_param(configs[i]);
642 arg = pinconf_to_config_argument(configs[i]);
643 pin_reg = readl(gpio_dev->base + pin*4);
646 case PIN_CONFIG_INPUT_DEBOUNCE:
647 pin_reg &= ~DB_TMR_OUT_MASK;
648 pin_reg |= arg & DB_TMR_OUT_MASK;
651 case PIN_CONFIG_BIAS_PULL_DOWN:
652 pin_reg &= ~BIT(PULL_DOWN_ENABLE_OFF);
653 pin_reg |= (arg & BIT(0)) << PULL_DOWN_ENABLE_OFF;
656 case PIN_CONFIG_BIAS_PULL_UP:
657 pin_reg &= ~BIT(PULL_UP_SEL_OFF);
658 pin_reg |= (arg & BIT(0)) << PULL_UP_SEL_OFF;
659 pin_reg &= ~BIT(PULL_UP_ENABLE_OFF);
660 pin_reg |= ((arg>>1) & BIT(0)) << PULL_UP_ENABLE_OFF;
663 case PIN_CONFIG_DRIVE_STRENGTH:
664 pin_reg &= ~(DRV_STRENGTH_SEL_MASK
665 << DRV_STRENGTH_SEL_OFF);
666 pin_reg |= (arg & DRV_STRENGTH_SEL_MASK)
667 << DRV_STRENGTH_SEL_OFF;
671 dev_err(&gpio_dev->pdev->dev,
672 "Invalid config param %04x\n", param);
676 writel(pin_reg, gpio_dev->base + pin*4);
678 spin_unlock_irqrestore(&gpio_dev->lock, flags);
683 static int amd_pinconf_group_get(struct pinctrl_dev *pctldev,
685 unsigned long *config)
687 const unsigned *pins;
691 ret = amd_get_group_pins(pctldev, group, &pins, &npins);
695 if (amd_pinconf_get(pctldev, pins[0], config))
701 static int amd_pinconf_group_set(struct pinctrl_dev *pctldev,
702 unsigned group, unsigned long *configs,
703 unsigned num_configs)
705 const unsigned *pins;
709 ret = amd_get_group_pins(pctldev, group, &pins, &npins);
712 for (i = 0; i < npins; i++) {
713 if (amd_pinconf_set(pctldev, pins[i], configs, num_configs))
719 static const struct pinconf_ops amd_pinconf_ops = {
720 .pin_config_get = amd_pinconf_get,
721 .pin_config_set = amd_pinconf_set,
722 .pin_config_group_get = amd_pinconf_group_get,
723 .pin_config_group_set = amd_pinconf_group_set,
726 static struct pinctrl_desc amd_pinctrl_desc = {
728 .npins = ARRAY_SIZE(kerncz_pins),
729 .pctlops = &amd_pinctrl_ops,
730 .confops = &amd_pinconf_ops,
731 .owner = THIS_MODULE,
734 static int amd_gpio_probe(struct platform_device *pdev)
738 struct resource *res;
739 struct amd_gpio *gpio_dev;
741 gpio_dev = devm_kzalloc(&pdev->dev,
742 sizeof(struct amd_gpio), GFP_KERNEL);
746 spin_lock_init(&gpio_dev->lock);
748 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
750 dev_err(&pdev->dev, "Failed to get gpio io resource.\n");
754 gpio_dev->base = devm_ioremap_nocache(&pdev->dev, res->start,
759 irq_base = platform_get_irq(pdev, 0);
761 dev_err(&pdev->dev, "Failed to get gpio IRQ.\n");
765 gpio_dev->pdev = pdev;
766 gpio_dev->gc.direction_input = amd_gpio_direction_input;
767 gpio_dev->gc.direction_output = amd_gpio_direction_output;
768 gpio_dev->gc.get = amd_gpio_get_value;
769 gpio_dev->gc.set = amd_gpio_set_value;
770 gpio_dev->gc.set_debounce = amd_gpio_set_debounce;
771 gpio_dev->gc.dbg_show = amd_gpio_dbg_show;
773 gpio_dev->gc.base = 0;
774 gpio_dev->gc.label = pdev->name;
775 gpio_dev->gc.owner = THIS_MODULE;
776 gpio_dev->gc.parent = &pdev->dev;
777 gpio_dev->gc.ngpio = TOTAL_NUMBER_OF_PINS;
778 #if defined(CONFIG_OF_GPIO)
779 gpio_dev->gc.of_node = pdev->dev.of_node;
782 gpio_dev->groups = kerncz_groups;
783 gpio_dev->ngroups = ARRAY_SIZE(kerncz_groups);
785 amd_pinctrl_desc.name = dev_name(&pdev->dev);
786 gpio_dev->pctrl = devm_pinctrl_register(&pdev->dev, &amd_pinctrl_desc,
788 if (IS_ERR(gpio_dev->pctrl)) {
789 dev_err(&pdev->dev, "Couldn't register pinctrl driver\n");
790 return PTR_ERR(gpio_dev->pctrl);
793 ret = gpiochip_add_data(&gpio_dev->gc, gpio_dev);
797 ret = gpiochip_add_pin_range(&gpio_dev->gc, dev_name(&pdev->dev),
798 0, 0, TOTAL_NUMBER_OF_PINS);
800 dev_err(&pdev->dev, "Failed to add pin range\n");
804 ret = gpiochip_irqchip_add(&gpio_dev->gc,
810 dev_err(&pdev->dev, "could not add irqchip\n");
815 gpiochip_set_chained_irqchip(&gpio_dev->gc,
818 amd_gpio_irq_handler);
820 platform_set_drvdata(pdev, gpio_dev);
822 dev_dbg(&pdev->dev, "amd gpio driver loaded\n");
826 gpiochip_remove(&gpio_dev->gc);
831 static int amd_gpio_remove(struct platform_device *pdev)
833 struct amd_gpio *gpio_dev;
835 gpio_dev = platform_get_drvdata(pdev);
837 gpiochip_remove(&gpio_dev->gc);
842 static const struct acpi_device_id amd_gpio_acpi_match[] = {
847 MODULE_DEVICE_TABLE(acpi, amd_gpio_acpi_match);
849 static struct platform_driver amd_gpio_driver = {
852 .acpi_match_table = ACPI_PTR(amd_gpio_acpi_match),
854 .probe = amd_gpio_probe,
855 .remove = amd_gpio_remove,
858 module_platform_driver(amd_gpio_driver);
860 MODULE_LICENSE("GPL v2");
861 MODULE_AUTHOR("Ken Xue <Ken.Xue@amd.com>, Jeff Wu <Jeff.Wu@amd.com>");
862 MODULE_DESCRIPTION("AMD GPIO pinctrl driver");