blob: 3f6b34febbf11249cf2a30e400647038f4a66f33 [file] [log] [blame]
Ken Xuedbad75d2015-03-10 15:02:19 +08001/*
2 * GPIO driver for AMD
3 *
4 * Copyright (c) 2014,2015 AMD Corporation.
5 * Authors: Ken Xue <Ken.Xue@amd.com>
6 * Wu, Jeff <Jeff.Wu@amd.com>
7 *
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.
Shyam Sundar S Kadd7bfc2017-05-03 11:59:11 +053011 *
12 * Contact Information: Nehal Shah <Nehal-bakulchandra.Shah@amd.com>
13 * Shyam Sundar S K <Shyam-sundar.S-k@amd.com>
14 *
Ken Xuedbad75d2015-03-10 15:02:19 +080015 */
16
17#include <linux/err.h>
18#include <linux/bug.h>
19#include <linux/kernel.h>
20#include <linux/module.h>
21#include <linux/spinlock.h>
22#include <linux/compiler.h>
23#include <linux/types.h>
24#include <linux/errno.h>
25#include <linux/log2.h>
26#include <linux/io.h>
27#include <linux/gpio.h>
28#include <linux/slab.h>
29#include <linux/platform_device.h>
30#include <linux/mutex.h>
31#include <linux/acpi.h>
32#include <linux/seq_file.h>
33#include <linux/interrupt.h>
34#include <linux/list.h>
35#include <linux/bitops.h>
Ken Xuedbad75d2015-03-10 15:02:19 +080036#include <linux/pinctrl/pinconf.h>
37#include <linux/pinctrl/pinconf-generic.h>
38
Daniel Drake79d2c8b2017-09-11 14:11:56 +080039#include "core.h"
Ken Xuedbad75d2015-03-10 15:02:19 +080040#include "pinctrl-utils.h"
41#include "pinctrl-amd.h"
42
Ken Xuedbad75d2015-03-10 15:02:19 +080043static int amd_gpio_direction_input(struct gpio_chip *gc, unsigned offset)
44{
45 unsigned long flags;
46 u32 pin_reg;
Linus Walleij04d36722015-12-08 09:21:38 +010047 struct amd_gpio *gpio_dev = gpiochip_get_data(gc);
Ken Xuedbad75d2015-03-10 15:02:19 +080048
Julia Cartwright229710f2017-03-09 10:22:04 -060049 raw_spin_lock_irqsave(&gpio_dev->lock, flags);
Ken Xuedbad75d2015-03-10 15:02:19 +080050 pin_reg = readl(gpio_dev->base + offset * 4);
Ken Xuedbad75d2015-03-10 15:02:19 +080051 pin_reg &= ~BIT(OUTPUT_ENABLE_OFF);
52 writel(pin_reg, gpio_dev->base + offset * 4);
Julia Cartwright229710f2017-03-09 10:22:04 -060053 raw_spin_unlock_irqrestore(&gpio_dev->lock, flags);
Ken Xuedbad75d2015-03-10 15:02:19 +080054
55 return 0;
56}
57
58static int amd_gpio_direction_output(struct gpio_chip *gc, unsigned offset,
59 int value)
60{
61 u32 pin_reg;
62 unsigned long flags;
Linus Walleij04d36722015-12-08 09:21:38 +010063 struct amd_gpio *gpio_dev = gpiochip_get_data(gc);
Ken Xuedbad75d2015-03-10 15:02:19 +080064
Julia Cartwright229710f2017-03-09 10:22:04 -060065 raw_spin_lock_irqsave(&gpio_dev->lock, flags);
Ken Xuedbad75d2015-03-10 15:02:19 +080066 pin_reg = readl(gpio_dev->base + offset * 4);
67 pin_reg |= BIT(OUTPUT_ENABLE_OFF);
68 if (value)
69 pin_reg |= BIT(OUTPUT_VALUE_OFF);
70 else
71 pin_reg &= ~BIT(OUTPUT_VALUE_OFF);
72 writel(pin_reg, gpio_dev->base + offset * 4);
Julia Cartwright229710f2017-03-09 10:22:04 -060073 raw_spin_unlock_irqrestore(&gpio_dev->lock, flags);
Ken Xuedbad75d2015-03-10 15:02:19 +080074
75 return 0;
76}
77
78static int amd_gpio_get_value(struct gpio_chip *gc, unsigned offset)
79{
80 u32 pin_reg;
81 unsigned long flags;
Linus Walleij04d36722015-12-08 09:21:38 +010082 struct amd_gpio *gpio_dev = gpiochip_get_data(gc);
Ken Xuedbad75d2015-03-10 15:02:19 +080083
Julia Cartwright229710f2017-03-09 10:22:04 -060084 raw_spin_lock_irqsave(&gpio_dev->lock, flags);
Ken Xuedbad75d2015-03-10 15:02:19 +080085 pin_reg = readl(gpio_dev->base + offset * 4);
Julia Cartwright229710f2017-03-09 10:22:04 -060086 raw_spin_unlock_irqrestore(&gpio_dev->lock, flags);
Ken Xuedbad75d2015-03-10 15:02:19 +080087
88 return !!(pin_reg & BIT(PIN_STS_OFF));
89}
90
91static void amd_gpio_set_value(struct gpio_chip *gc, unsigned offset, int value)
92{
93 u32 pin_reg;
94 unsigned long flags;
Linus Walleij04d36722015-12-08 09:21:38 +010095 struct amd_gpio *gpio_dev = gpiochip_get_data(gc);
Ken Xuedbad75d2015-03-10 15:02:19 +080096
Julia Cartwright229710f2017-03-09 10:22:04 -060097 raw_spin_lock_irqsave(&gpio_dev->lock, flags);
Ken Xuedbad75d2015-03-10 15:02:19 +080098 pin_reg = readl(gpio_dev->base + offset * 4);
99 if (value)
100 pin_reg |= BIT(OUTPUT_VALUE_OFF);
101 else
102 pin_reg &= ~BIT(OUTPUT_VALUE_OFF);
103 writel(pin_reg, gpio_dev->base + offset * 4);
Julia Cartwright229710f2017-03-09 10:22:04 -0600104 raw_spin_unlock_irqrestore(&gpio_dev->lock, flags);
Ken Xuedbad75d2015-03-10 15:02:19 +0800105}
106
107static int amd_gpio_set_debounce(struct gpio_chip *gc, unsigned offset,
108 unsigned debounce)
109{
Ken Xuedbad75d2015-03-10 15:02:19 +0800110 u32 time;
Ken Xue25a853d2015-03-27 17:44:26 +0800111 u32 pin_reg;
112 int ret = 0;
Ken Xuedbad75d2015-03-10 15:02:19 +0800113 unsigned long flags;
Linus Walleij04d36722015-12-08 09:21:38 +0100114 struct amd_gpio *gpio_dev = gpiochip_get_data(gc);
Ken Xuedbad75d2015-03-10 15:02:19 +0800115
Julia Cartwright229710f2017-03-09 10:22:04 -0600116 raw_spin_lock_irqsave(&gpio_dev->lock, flags);
Ken Xuedbad75d2015-03-10 15:02:19 +0800117 pin_reg = readl(gpio_dev->base + offset * 4);
118
119 if (debounce) {
120 pin_reg |= DB_TYPE_REMOVE_GLITCH << DB_CNTRL_OFF;
121 pin_reg &= ~DB_TMR_OUT_MASK;
122 /*
123 Debounce Debounce Timer Max
124 TmrLarge TmrOutUnit Unit Debounce
125 Time
126 0 0 61 usec (2 RtcClk) 976 usec
127 0 1 244 usec (8 RtcClk) 3.9 msec
128 1 0 15.6 msec (512 RtcClk) 250 msec
129 1 1 62.5 msec (2048 RtcClk) 1 sec
130 */
131
132 if (debounce < 61) {
133 pin_reg |= 1;
134 pin_reg &= ~BIT(DB_TMR_OUT_UNIT_OFF);
135 pin_reg &= ~BIT(DB_TMR_LARGE_OFF);
136 } else if (debounce < 976) {
137 time = debounce / 61;
138 pin_reg |= time & DB_TMR_OUT_MASK;
139 pin_reg &= ~BIT(DB_TMR_OUT_UNIT_OFF);
140 pin_reg &= ~BIT(DB_TMR_LARGE_OFF);
141 } else if (debounce < 3900) {
142 time = debounce / 244;
143 pin_reg |= time & DB_TMR_OUT_MASK;
144 pin_reg |= BIT(DB_TMR_OUT_UNIT_OFF);
145 pin_reg &= ~BIT(DB_TMR_LARGE_OFF);
146 } else if (debounce < 250000) {
147 time = debounce / 15600;
148 pin_reg |= time & DB_TMR_OUT_MASK;
149 pin_reg &= ~BIT(DB_TMR_OUT_UNIT_OFF);
150 pin_reg |= BIT(DB_TMR_LARGE_OFF);
151 } else if (debounce < 1000000) {
152 time = debounce / 62500;
153 pin_reg |= time & DB_TMR_OUT_MASK;
154 pin_reg |= BIT(DB_TMR_OUT_UNIT_OFF);
155 pin_reg |= BIT(DB_TMR_LARGE_OFF);
156 } else {
157 pin_reg &= ~DB_CNTRl_MASK;
Ken Xue25a853d2015-03-27 17:44:26 +0800158 ret = -EINVAL;
Ken Xuedbad75d2015-03-10 15:02:19 +0800159 }
160 } else {
161 pin_reg &= ~BIT(DB_TMR_OUT_UNIT_OFF);
162 pin_reg &= ~BIT(DB_TMR_LARGE_OFF);
163 pin_reg &= ~DB_TMR_OUT_MASK;
164 pin_reg &= ~DB_CNTRl_MASK;
165 }
166 writel(pin_reg, gpio_dev->base + offset * 4);
Julia Cartwright229710f2017-03-09 10:22:04 -0600167 raw_spin_unlock_irqrestore(&gpio_dev->lock, flags);
Ken Xuedbad75d2015-03-10 15:02:19 +0800168
Ken Xue25a853d2015-03-27 17:44:26 +0800169 return ret;
Ken Xuedbad75d2015-03-10 15:02:19 +0800170}
171
Mika Westerberg2956b5d2017-01-23 15:34:34 +0300172static int amd_gpio_set_config(struct gpio_chip *gc, unsigned offset,
173 unsigned long config)
174{
175 u32 debounce;
176
177 if (pinconf_to_config_param(config) != PIN_CONFIG_INPUT_DEBOUNCE)
178 return -ENOTSUPP;
179
180 debounce = pinconf_to_config_argument(config);
181 return amd_gpio_set_debounce(gc, offset, debounce);
182}
183
Ken Xuedbad75d2015-03-10 15:02:19 +0800184#ifdef CONFIG_DEBUG_FS
185static void amd_gpio_dbg_show(struct seq_file *s, struct gpio_chip *gc)
186{
187 u32 pin_reg;
188 unsigned long flags;
189 unsigned int bank, i, pin_num;
Linus Walleij04d36722015-12-08 09:21:38 +0100190 struct amd_gpio *gpio_dev = gpiochip_get_data(gc);
Ken Xuedbad75d2015-03-10 15:02:19 +0800191
192 char *level_trig;
193 char *active_level;
194 char *interrupt_enable;
195 char *interrupt_mask;
196 char *wake_cntrl0;
197 char *wake_cntrl1;
198 char *wake_cntrl2;
199 char *pin_sts;
200 char *pull_up_sel;
201 char *pull_up_enable;
202 char *pull_down_enable;
203 char *output_value;
204 char *output_enable;
205
Shah, Nehal-bakulchandra3bfd4432016-12-06 12:17:48 +0530206 for (bank = 0; bank < gpio_dev->hwbank_num; bank++) {
Ken Xuedbad75d2015-03-10 15:02:19 +0800207 seq_printf(s, "GPIO bank%d\t", bank);
208
209 switch (bank) {
210 case 0:
211 i = 0;
212 pin_num = AMD_GPIO_PINS_BANK0;
213 break;
214 case 1:
215 i = 64;
216 pin_num = AMD_GPIO_PINS_BANK1 + i;
217 break;
218 case 2:
219 i = 128;
220 pin_num = AMD_GPIO_PINS_BANK2 + i;
221 break;
Shah, Nehal-bakulchandra3bfd4432016-12-06 12:17:48 +0530222 case 3:
223 i = 192;
224 pin_num = AMD_GPIO_PINS_BANK3 + i;
225 break;
Linus Walleij6ac4c1a2017-01-03 09:18:58 +0100226 default:
227 /* Illegal bank number, ignore */
228 continue;
Ken Xuedbad75d2015-03-10 15:02:19 +0800229 }
Ken Xuedbad75d2015-03-10 15:02:19 +0800230 for (; i < pin_num; i++) {
231 seq_printf(s, "pin%d\t", i);
Julia Cartwright229710f2017-03-09 10:22:04 -0600232 raw_spin_lock_irqsave(&gpio_dev->lock, flags);
Ken Xuedbad75d2015-03-10 15:02:19 +0800233 pin_reg = readl(gpio_dev->base + i * 4);
Julia Cartwright229710f2017-03-09 10:22:04 -0600234 raw_spin_unlock_irqrestore(&gpio_dev->lock, flags);
Ken Xuedbad75d2015-03-10 15:02:19 +0800235
236 if (pin_reg & BIT(INTERRUPT_ENABLE_OFF)) {
237 interrupt_enable = "interrupt is enabled|";
238
Dan Carpenter3775dac2017-01-07 09:32:15 +0300239 if (!(pin_reg & BIT(ACTIVE_LEVEL_OFF)) &&
240 !(pin_reg & BIT(ACTIVE_LEVEL_OFF + 1)))
Ken Xuedbad75d2015-03-10 15:02:19 +0800241 active_level = "Active low|";
Dan Carpenter3775dac2017-01-07 09:32:15 +0300242 else if (pin_reg & BIT(ACTIVE_LEVEL_OFF) &&
243 !(pin_reg & BIT(ACTIVE_LEVEL_OFF + 1)))
Ken Xuedbad75d2015-03-10 15:02:19 +0800244 active_level = "Active high|";
Dan Carpenter3775dac2017-01-07 09:32:15 +0300245 else if (!(pin_reg & BIT(ACTIVE_LEVEL_OFF)) &&
246 pin_reg & BIT(ACTIVE_LEVEL_OFF + 1))
Ken Xuedbad75d2015-03-10 15:02:19 +0800247 active_level = "Active on both|";
248 else
Masanari Iida0a951602016-11-23 22:44:47 +0900249 active_level = "Unknown Active level|";
Ken Xuedbad75d2015-03-10 15:02:19 +0800250
251 if (pin_reg & BIT(LEVEL_TRIG_OFF))
252 level_trig = "Level trigger|";
253 else
254 level_trig = "Edge trigger|";
255
256 } else {
257 interrupt_enable =
258 "interrupt is disabled|";
259 active_level = " ";
260 level_trig = " ";
261 }
262
263 if (pin_reg & BIT(INTERRUPT_MASK_OFF))
264 interrupt_mask =
265 "interrupt is unmasked|";
266 else
267 interrupt_mask =
268 "interrupt is masked|";
269
Shah, Nehal-bakulchandra3bfd4432016-12-06 12:17:48 +0530270 if (pin_reg & BIT(WAKE_CNTRL_OFF_S0I3))
Ken Xuedbad75d2015-03-10 15:02:19 +0800271 wake_cntrl0 = "enable wakeup in S0i3 state|";
272 else
273 wake_cntrl0 = "disable wakeup in S0i3 state|";
274
Shah, Nehal-bakulchandra3bfd4432016-12-06 12:17:48 +0530275 if (pin_reg & BIT(WAKE_CNTRL_OFF_S3))
Ken Xuedbad75d2015-03-10 15:02:19 +0800276 wake_cntrl1 = "enable wakeup in S3 state|";
277 else
278 wake_cntrl1 = "disable wakeup in S3 state|";
279
Shah, Nehal-bakulchandra3bfd4432016-12-06 12:17:48 +0530280 if (pin_reg & BIT(WAKE_CNTRL_OFF_S4))
Ken Xuedbad75d2015-03-10 15:02:19 +0800281 wake_cntrl2 = "enable wakeup in S4/S5 state|";
282 else
283 wake_cntrl2 = "disable wakeup in S4/S5 state|";
284
285 if (pin_reg & BIT(PULL_UP_ENABLE_OFF)) {
286 pull_up_enable = "pull-up is enabled|";
287 if (pin_reg & BIT(PULL_UP_SEL_OFF))
288 pull_up_sel = "8k pull-up|";
289 else
290 pull_up_sel = "4k pull-up|";
291 } else {
292 pull_up_enable = "pull-up is disabled|";
293 pull_up_sel = " ";
294 }
295
296 if (pin_reg & BIT(PULL_DOWN_ENABLE_OFF))
297 pull_down_enable = "pull-down is enabled|";
298 else
299 pull_down_enable = "Pull-down is disabled|";
300
301 if (pin_reg & BIT(OUTPUT_ENABLE_OFF)) {
302 pin_sts = " ";
303 output_enable = "output is enabled|";
304 if (pin_reg & BIT(OUTPUT_VALUE_OFF))
305 output_value = "output is high|";
306 else
307 output_value = "output is low|";
308 } else {
309 output_enable = "output is disabled|";
310 output_value = " ";
311
312 if (pin_reg & BIT(PIN_STS_OFF))
313 pin_sts = "input is high|";
314 else
315 pin_sts = "input is low|";
316 }
317
318 seq_printf(s, "%s %s %s %s %s %s\n"
319 " %s %s %s %s %s %s %s 0x%x\n",
320 level_trig, active_level, interrupt_enable,
321 interrupt_mask, wake_cntrl0, wake_cntrl1,
322 wake_cntrl2, pin_sts, pull_up_sel,
323 pull_up_enable, pull_down_enable,
324 output_value, output_enable, pin_reg);
325 }
326 }
327}
328#else
329#define amd_gpio_dbg_show NULL
330#endif
331
332static void amd_gpio_irq_enable(struct irq_data *d)
333{
334 u32 pin_reg;
335 unsigned long flags;
336 struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
Linus Walleij04d36722015-12-08 09:21:38 +0100337 struct amd_gpio *gpio_dev = gpiochip_get_data(gc);
Ken Xuedbad75d2015-03-10 15:02:19 +0800338
Julia Cartwright229710f2017-03-09 10:22:04 -0600339 raw_spin_lock_irqsave(&gpio_dev->lock, flags);
Ken Xuedbad75d2015-03-10 15:02:19 +0800340 pin_reg = readl(gpio_dev->base + (d->hwirq)*4);
Ken Xuedbad75d2015-03-10 15:02:19 +0800341 pin_reg |= BIT(INTERRUPT_ENABLE_OFF);
342 pin_reg |= BIT(INTERRUPT_MASK_OFF);
343 writel(pin_reg, gpio_dev->base + (d->hwirq)*4);
Julia Cartwright229710f2017-03-09 10:22:04 -0600344 raw_spin_unlock_irqrestore(&gpio_dev->lock, flags);
Ken Xuedbad75d2015-03-10 15:02:19 +0800345}
346
347static void amd_gpio_irq_disable(struct irq_data *d)
348{
349 u32 pin_reg;
350 unsigned long flags;
351 struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
Linus Walleij04d36722015-12-08 09:21:38 +0100352 struct amd_gpio *gpio_dev = gpiochip_get_data(gc);
Ken Xuedbad75d2015-03-10 15:02:19 +0800353
Julia Cartwright229710f2017-03-09 10:22:04 -0600354 raw_spin_lock_irqsave(&gpio_dev->lock, flags);
Ken Xuedbad75d2015-03-10 15:02:19 +0800355 pin_reg = readl(gpio_dev->base + (d->hwirq)*4);
356 pin_reg &= ~BIT(INTERRUPT_ENABLE_OFF);
357 pin_reg &= ~BIT(INTERRUPT_MASK_OFF);
358 writel(pin_reg, gpio_dev->base + (d->hwirq)*4);
Julia Cartwright229710f2017-03-09 10:22:04 -0600359 raw_spin_unlock_irqrestore(&gpio_dev->lock, flags);
Ken Xuedbad75d2015-03-10 15:02:19 +0800360}
361
362static void amd_gpio_irq_mask(struct irq_data *d)
363{
364 u32 pin_reg;
365 unsigned long flags;
366 struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
Linus Walleij04d36722015-12-08 09:21:38 +0100367 struct amd_gpio *gpio_dev = gpiochip_get_data(gc);
Ken Xuedbad75d2015-03-10 15:02:19 +0800368
Julia Cartwright229710f2017-03-09 10:22:04 -0600369 raw_spin_lock_irqsave(&gpio_dev->lock, flags);
Ken Xuedbad75d2015-03-10 15:02:19 +0800370 pin_reg = readl(gpio_dev->base + (d->hwirq)*4);
371 pin_reg &= ~BIT(INTERRUPT_MASK_OFF);
372 writel(pin_reg, gpio_dev->base + (d->hwirq)*4);
Julia Cartwright229710f2017-03-09 10:22:04 -0600373 raw_spin_unlock_irqrestore(&gpio_dev->lock, flags);
Ken Xuedbad75d2015-03-10 15:02:19 +0800374}
375
376static void amd_gpio_irq_unmask(struct irq_data *d)
377{
378 u32 pin_reg;
379 unsigned long flags;
380 struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
Linus Walleij04d36722015-12-08 09:21:38 +0100381 struct amd_gpio *gpio_dev = gpiochip_get_data(gc);
Ken Xuedbad75d2015-03-10 15:02:19 +0800382
Julia Cartwright229710f2017-03-09 10:22:04 -0600383 raw_spin_lock_irqsave(&gpio_dev->lock, flags);
Ken Xuedbad75d2015-03-10 15:02:19 +0800384 pin_reg = readl(gpio_dev->base + (d->hwirq)*4);
385 pin_reg |= BIT(INTERRUPT_MASK_OFF);
386 writel(pin_reg, gpio_dev->base + (d->hwirq)*4);
Julia Cartwright229710f2017-03-09 10:22:04 -0600387 raw_spin_unlock_irqrestore(&gpio_dev->lock, flags);
Ken Xuedbad75d2015-03-10 15:02:19 +0800388}
389
390static void amd_gpio_irq_eoi(struct irq_data *d)
391{
392 u32 reg;
393 unsigned long flags;
394 struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
Linus Walleij04d36722015-12-08 09:21:38 +0100395 struct amd_gpio *gpio_dev = gpiochip_get_data(gc);
Ken Xuedbad75d2015-03-10 15:02:19 +0800396
Julia Cartwright229710f2017-03-09 10:22:04 -0600397 raw_spin_lock_irqsave(&gpio_dev->lock, flags);
Ken Xuedbad75d2015-03-10 15:02:19 +0800398 reg = readl(gpio_dev->base + WAKE_INT_MASTER_REG);
399 reg |= EOI_MASK;
400 writel(reg, gpio_dev->base + WAKE_INT_MASTER_REG);
Julia Cartwright229710f2017-03-09 10:22:04 -0600401 raw_spin_unlock_irqrestore(&gpio_dev->lock, flags);
Ken Xuedbad75d2015-03-10 15:02:19 +0800402}
403
404static int amd_gpio_irq_set_type(struct irq_data *d, unsigned int type)
405{
406 int ret = 0;
407 u32 pin_reg;
Shyam Sundar S K2983f292016-12-08 17:31:14 +0530408 unsigned long flags, irq_flags;
Ken Xuedbad75d2015-03-10 15:02:19 +0800409 struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
Linus Walleij04d36722015-12-08 09:21:38 +0100410 struct amd_gpio *gpio_dev = gpiochip_get_data(gc);
Ken Xuedbad75d2015-03-10 15:02:19 +0800411
Julia Cartwright229710f2017-03-09 10:22:04 -0600412 raw_spin_lock_irqsave(&gpio_dev->lock, flags);
Ken Xuedbad75d2015-03-10 15:02:19 +0800413 pin_reg = readl(gpio_dev->base + (d->hwirq)*4);
414
Shyam Sundar S K2983f292016-12-08 17:31:14 +0530415 /* Ignore the settings coming from the client and
416 * read the values from the ACPI tables
417 * while setting the trigger type
Agrawal, Nitesh-kumar499c7192016-08-31 08:50:49 +0000418 */
Agrawal, Nitesh-kumar499c7192016-08-31 08:50:49 +0000419
Shyam Sundar S K2983f292016-12-08 17:31:14 +0530420 irq_flags = irq_get_trigger_type(d->irq);
421 if (irq_flags != IRQ_TYPE_NONE)
422 type = irq_flags;
Agrawal, Nitesh-kumar499c7192016-08-31 08:50:49 +0000423
Ken Xuedbad75d2015-03-10 15:02:19 +0800424 switch (type & IRQ_TYPE_SENSE_MASK) {
425 case IRQ_TYPE_EDGE_RISING:
426 pin_reg &= ~BIT(LEVEL_TRIG_OFF);
427 pin_reg &= ~(ACTIVE_LEVEL_MASK << ACTIVE_LEVEL_OFF);
428 pin_reg |= ACTIVE_HIGH << ACTIVE_LEVEL_OFF;
429 pin_reg |= DB_TYPE_REMOVE_GLITCH << DB_CNTRL_OFF;
Thomas Gleixner9d829312015-06-23 15:52:47 +0200430 irq_set_handler_locked(d, handle_edge_irq);
Ken Xuedbad75d2015-03-10 15:02:19 +0800431 break;
432
433 case IRQ_TYPE_EDGE_FALLING:
434 pin_reg &= ~BIT(LEVEL_TRIG_OFF);
435 pin_reg &= ~(ACTIVE_LEVEL_MASK << ACTIVE_LEVEL_OFF);
436 pin_reg |= ACTIVE_LOW << ACTIVE_LEVEL_OFF;
437 pin_reg |= DB_TYPE_REMOVE_GLITCH << DB_CNTRL_OFF;
Thomas Gleixner9d829312015-06-23 15:52:47 +0200438 irq_set_handler_locked(d, handle_edge_irq);
Ken Xuedbad75d2015-03-10 15:02:19 +0800439 break;
440
441 case IRQ_TYPE_EDGE_BOTH:
442 pin_reg &= ~BIT(LEVEL_TRIG_OFF);
443 pin_reg &= ~(ACTIVE_LEVEL_MASK << ACTIVE_LEVEL_OFF);
444 pin_reg |= BOTH_EADGE << ACTIVE_LEVEL_OFF;
445 pin_reg |= DB_TYPE_REMOVE_GLITCH << DB_CNTRL_OFF;
Thomas Gleixner9d829312015-06-23 15:52:47 +0200446 irq_set_handler_locked(d, handle_edge_irq);
Ken Xuedbad75d2015-03-10 15:02:19 +0800447 break;
448
449 case IRQ_TYPE_LEVEL_HIGH:
450 pin_reg |= LEVEL_TRIGGER << LEVEL_TRIG_OFF;
451 pin_reg &= ~(ACTIVE_LEVEL_MASK << ACTIVE_LEVEL_OFF);
452 pin_reg |= ACTIVE_HIGH << ACTIVE_LEVEL_OFF;
453 pin_reg &= ~(DB_CNTRl_MASK << DB_CNTRL_OFF);
454 pin_reg |= DB_TYPE_PRESERVE_LOW_GLITCH << DB_CNTRL_OFF;
Thomas Gleixner9d829312015-06-23 15:52:47 +0200455 irq_set_handler_locked(d, handle_level_irq);
Ken Xuedbad75d2015-03-10 15:02:19 +0800456 break;
457
458 case IRQ_TYPE_LEVEL_LOW:
459 pin_reg |= LEVEL_TRIGGER << LEVEL_TRIG_OFF;
460 pin_reg &= ~(ACTIVE_LEVEL_MASK << ACTIVE_LEVEL_OFF);
461 pin_reg |= ACTIVE_LOW << ACTIVE_LEVEL_OFF;
462 pin_reg &= ~(DB_CNTRl_MASK << DB_CNTRL_OFF);
463 pin_reg |= DB_TYPE_PRESERVE_HIGH_GLITCH << DB_CNTRL_OFF;
Thomas Gleixner9d829312015-06-23 15:52:47 +0200464 irq_set_handler_locked(d, handle_level_irq);
Ken Xuedbad75d2015-03-10 15:02:19 +0800465 break;
466
467 case IRQ_TYPE_NONE:
468 break;
469
470 default:
471 dev_err(&gpio_dev->pdev->dev, "Invalid type value\n");
472 ret = -EINVAL;
Ken Xuedbad75d2015-03-10 15:02:19 +0800473 }
474
475 pin_reg |= CLR_INTR_STAT << INTERRUPT_STS_OFF;
476 writel(pin_reg, gpio_dev->base + (d->hwirq)*4);
Julia Cartwright229710f2017-03-09 10:22:04 -0600477 raw_spin_unlock_irqrestore(&gpio_dev->lock, flags);
Ken Xuedbad75d2015-03-10 15:02:19 +0800478
Ken Xuedbad75d2015-03-10 15:02:19 +0800479 return ret;
480}
481
482static void amd_irq_ack(struct irq_data *d)
483{
484 /*
485 * based on HW design,there is no need to ack HW
486 * before handle current irq. But this routine is
487 * necessary for handle_edge_irq
488 */
489}
490
491static struct irq_chip amd_gpio_irqchip = {
492 .name = "amd_gpio",
493 .irq_ack = amd_irq_ack,
494 .irq_enable = amd_gpio_irq_enable,
495 .irq_disable = amd_gpio_irq_disable,
496 .irq_mask = amd_gpio_irq_mask,
497 .irq_unmask = amd_gpio_irq_unmask,
498 .irq_eoi = amd_gpio_irq_eoi,
499 .irq_set_type = amd_gpio_irq_set_type,
Shah, Nehal-bakulchandra3bfd4432016-12-06 12:17:48 +0530500 .flags = IRQCHIP_SKIP_SET_WAKE,
Ken Xuedbad75d2015-03-10 15:02:19 +0800501};
502
Thomas Gleixnerba714a92017-05-23 23:23:32 +0200503#define PIN_IRQ_PENDING (BIT(INTERRUPT_STS_OFF) | BIT(WAKE_STS_OFF))
504
505static irqreturn_t amd_gpio_irq_handler(int irq, void *dev_id)
Ken Xuedbad75d2015-03-10 15:02:19 +0800506{
Thomas Gleixnerba714a92017-05-23 23:23:32 +0200507 struct amd_gpio *gpio_dev = dev_id;
508 struct gpio_chip *gc = &gpio_dev->gc;
509 irqreturn_t ret = IRQ_NONE;
510 unsigned int i, irqnr;
Ken Xuedbad75d2015-03-10 15:02:19 +0800511 unsigned long flags;
Thomas Gleixnerba714a92017-05-23 23:23:32 +0200512 u32 *regs, regval;
513 u64 status, mask;
Ken Xuedbad75d2015-03-10 15:02:19 +0800514
Thomas Gleixnerba714a92017-05-23 23:23:32 +0200515 /* Read the wake status */
Julia Cartwright229710f2017-03-09 10:22:04 -0600516 raw_spin_lock_irqsave(&gpio_dev->lock, flags);
Thomas Gleixnerba714a92017-05-23 23:23:32 +0200517 status = readl(gpio_dev->base + WAKE_INT_STATUS_REG1);
518 status <<= 32;
519 status |= readl(gpio_dev->base + WAKE_INT_STATUS_REG0);
Julia Cartwright229710f2017-03-09 10:22:04 -0600520 raw_spin_unlock_irqrestore(&gpio_dev->lock, flags);
Ken Xuedbad75d2015-03-10 15:02:19 +0800521
Thomas Gleixnerba714a92017-05-23 23:23:32 +0200522 /* Bit 0-45 contain the relevant status bits */
523 status &= (1ULL << 46) - 1;
524 regs = gpio_dev->base;
525 for (mask = 1, irqnr = 0; status; mask <<= 1, regs += 4, irqnr += 4) {
526 if (!(status & mask))
527 continue;
528 status &= ~mask;
529
530 /* Each status bit covers four pins */
531 for (i = 0; i < 4; i++) {
532 regval = readl(regs + i);
533 if (!(regval & PIN_IRQ_PENDING))
534 continue;
535 irq = irq_find_mapping(gc->irqdomain, irqnr + i);
536 generic_handle_irq(irq);
537 /* Clear interrupt */
538 writel(regval, regs + i);
539 ret = IRQ_HANDLED;
Ken Xuedbad75d2015-03-10 15:02:19 +0800540 }
541 }
542
Thomas Gleixnerba714a92017-05-23 23:23:32 +0200543 /* Signal EOI to the GPIO unit */
Julia Cartwright229710f2017-03-09 10:22:04 -0600544 raw_spin_lock_irqsave(&gpio_dev->lock, flags);
Thomas Gleixnerba714a92017-05-23 23:23:32 +0200545 regval = readl(gpio_dev->base + WAKE_INT_MASTER_REG);
546 regval |= EOI_MASK;
547 writel(regval, gpio_dev->base + WAKE_INT_MASTER_REG);
Julia Cartwright229710f2017-03-09 10:22:04 -0600548 raw_spin_unlock_irqrestore(&gpio_dev->lock, flags);
Ken Xuedbad75d2015-03-10 15:02:19 +0800549
Thomas Gleixnerba714a92017-05-23 23:23:32 +0200550 return ret;
Ken Xuedbad75d2015-03-10 15:02:19 +0800551}
552
553static int amd_get_groups_count(struct pinctrl_dev *pctldev)
554{
555 struct amd_gpio *gpio_dev = pinctrl_dev_get_drvdata(pctldev);
556
557 return gpio_dev->ngroups;
558}
559
560static const char *amd_get_group_name(struct pinctrl_dev *pctldev,
561 unsigned group)
562{
563 struct amd_gpio *gpio_dev = pinctrl_dev_get_drvdata(pctldev);
564
565 return gpio_dev->groups[group].name;
566}
567
568static int amd_get_group_pins(struct pinctrl_dev *pctldev,
569 unsigned group,
570 const unsigned **pins,
571 unsigned *num_pins)
572{
573 struct amd_gpio *gpio_dev = pinctrl_dev_get_drvdata(pctldev);
574
575 *pins = gpio_dev->groups[group].pins;
576 *num_pins = gpio_dev->groups[group].npins;
577 return 0;
578}
579
580static const struct pinctrl_ops amd_pinctrl_ops = {
581 .get_groups_count = amd_get_groups_count,
582 .get_group_name = amd_get_group_name,
583 .get_group_pins = amd_get_group_pins,
584#ifdef CONFIG_OF
585 .dt_node_to_map = pinconf_generic_dt_node_to_map_group,
Irina Tirdead32f7fd2016-03-31 14:44:42 +0300586 .dt_free_map = pinctrl_utils_free_map,
Ken Xuedbad75d2015-03-10 15:02:19 +0800587#endif
588};
589
590static int amd_pinconf_get(struct pinctrl_dev *pctldev,
591 unsigned int pin,
592 unsigned long *config)
593{
594 u32 pin_reg;
595 unsigned arg;
596 unsigned long flags;
597 struct amd_gpio *gpio_dev = pinctrl_dev_get_drvdata(pctldev);
598 enum pin_config_param param = pinconf_to_config_param(*config);
599
Julia Cartwright229710f2017-03-09 10:22:04 -0600600 raw_spin_lock_irqsave(&gpio_dev->lock, flags);
Ken Xuedbad75d2015-03-10 15:02:19 +0800601 pin_reg = readl(gpio_dev->base + pin*4);
Julia Cartwright229710f2017-03-09 10:22:04 -0600602 raw_spin_unlock_irqrestore(&gpio_dev->lock, flags);
Ken Xuedbad75d2015-03-10 15:02:19 +0800603 switch (param) {
604 case PIN_CONFIG_INPUT_DEBOUNCE:
605 arg = pin_reg & DB_TMR_OUT_MASK;
606 break;
607
608 case PIN_CONFIG_BIAS_PULL_DOWN:
609 arg = (pin_reg >> PULL_DOWN_ENABLE_OFF) & BIT(0);
610 break;
611
612 case PIN_CONFIG_BIAS_PULL_UP:
613 arg = (pin_reg >> PULL_UP_SEL_OFF) & (BIT(0) | BIT(1));
614 break;
615
616 case PIN_CONFIG_DRIVE_STRENGTH:
617 arg = (pin_reg >> DRV_STRENGTH_SEL_OFF) & DRV_STRENGTH_SEL_MASK;
618 break;
619
620 default:
621 dev_err(&gpio_dev->pdev->dev, "Invalid config param %04x\n",
622 param);
623 return -ENOTSUPP;
624 }
625
626 *config = pinconf_to_config_packed(param, arg);
627
628 return 0;
629}
630
631static int amd_pinconf_set(struct pinctrl_dev *pctldev, unsigned int pin,
632 unsigned long *configs, unsigned num_configs)
633{
634 int i;
Ken Xuedbad75d2015-03-10 15:02:19 +0800635 u32 arg;
Ken Xue25a853d2015-03-27 17:44:26 +0800636 int ret = 0;
637 u32 pin_reg;
Ken Xuedbad75d2015-03-10 15:02:19 +0800638 unsigned long flags;
639 enum pin_config_param param;
640 struct amd_gpio *gpio_dev = pinctrl_dev_get_drvdata(pctldev);
641
Julia Cartwright229710f2017-03-09 10:22:04 -0600642 raw_spin_lock_irqsave(&gpio_dev->lock, flags);
Ken Xuedbad75d2015-03-10 15:02:19 +0800643 for (i = 0; i < num_configs; i++) {
644 param = pinconf_to_config_param(configs[i]);
645 arg = pinconf_to_config_argument(configs[i]);
646 pin_reg = readl(gpio_dev->base + pin*4);
647
648 switch (param) {
649 case PIN_CONFIG_INPUT_DEBOUNCE:
650 pin_reg &= ~DB_TMR_OUT_MASK;
651 pin_reg |= arg & DB_TMR_OUT_MASK;
652 break;
653
654 case PIN_CONFIG_BIAS_PULL_DOWN:
655 pin_reg &= ~BIT(PULL_DOWN_ENABLE_OFF);
656 pin_reg |= (arg & BIT(0)) << PULL_DOWN_ENABLE_OFF;
657 break;
658
659 case PIN_CONFIG_BIAS_PULL_UP:
660 pin_reg &= ~BIT(PULL_UP_SEL_OFF);
661 pin_reg |= (arg & BIT(0)) << PULL_UP_SEL_OFF;
662 pin_reg &= ~BIT(PULL_UP_ENABLE_OFF);
663 pin_reg |= ((arg>>1) & BIT(0)) << PULL_UP_ENABLE_OFF;
664 break;
665
666 case PIN_CONFIG_DRIVE_STRENGTH:
667 pin_reg &= ~(DRV_STRENGTH_SEL_MASK
668 << DRV_STRENGTH_SEL_OFF);
669 pin_reg |= (arg & DRV_STRENGTH_SEL_MASK)
670 << DRV_STRENGTH_SEL_OFF;
671 break;
672
673 default:
674 dev_err(&gpio_dev->pdev->dev,
675 "Invalid config param %04x\n", param);
Ken Xue25a853d2015-03-27 17:44:26 +0800676 ret = -ENOTSUPP;
Ken Xuedbad75d2015-03-10 15:02:19 +0800677 }
678
679 writel(pin_reg, gpio_dev->base + pin*4);
680 }
Julia Cartwright229710f2017-03-09 10:22:04 -0600681 raw_spin_unlock_irqrestore(&gpio_dev->lock, flags);
Ken Xuedbad75d2015-03-10 15:02:19 +0800682
Ken Xue25a853d2015-03-27 17:44:26 +0800683 return ret;
Ken Xuedbad75d2015-03-10 15:02:19 +0800684}
685
686static int amd_pinconf_group_get(struct pinctrl_dev *pctldev,
687 unsigned int group,
688 unsigned long *config)
689{
690 const unsigned *pins;
691 unsigned npins;
692 int ret;
693
694 ret = amd_get_group_pins(pctldev, group, &pins, &npins);
695 if (ret)
696 return ret;
697
698 if (amd_pinconf_get(pctldev, pins[0], config))
699 return -ENOTSUPP;
700
701 return 0;
702}
703
704static int amd_pinconf_group_set(struct pinctrl_dev *pctldev,
705 unsigned group, unsigned long *configs,
706 unsigned num_configs)
707{
708 const unsigned *pins;
709 unsigned npins;
710 int i, ret;
711
712 ret = amd_get_group_pins(pctldev, group, &pins, &npins);
713 if (ret)
714 return ret;
715 for (i = 0; i < npins; i++) {
716 if (amd_pinconf_set(pctldev, pins[i], configs, num_configs))
717 return -ENOTSUPP;
718 }
719 return 0;
720}
721
722static const struct pinconf_ops amd_pinconf_ops = {
723 .pin_config_get = amd_pinconf_get,
724 .pin_config_set = amd_pinconf_set,
725 .pin_config_group_get = amd_pinconf_group_get,
726 .pin_config_group_set = amd_pinconf_group_set,
727};
728
Daniel Drake79d2c8b2017-09-11 14:11:56 +0800729#ifdef CONFIG_PM_SLEEP
730static bool amd_gpio_should_save(struct amd_gpio *gpio_dev, unsigned int pin)
731{
732 const struct pin_desc *pd = pin_desc_get(gpio_dev->pctrl, pin);
733
734 if (!pd)
735 return false;
736
737 /*
738 * Only restore the pin if it is actually in use by the kernel (or
739 * by userspace).
740 */
741 if (pd->mux_owner || pd->gpio_owner ||
742 gpiochip_line_is_irq(&gpio_dev->gc, pin))
743 return true;
744
745 return false;
746}
747
748int amd_gpio_suspend(struct device *dev)
749{
750 struct platform_device *pdev = to_platform_device(dev);
751 struct amd_gpio *gpio_dev = platform_get_drvdata(pdev);
752 struct pinctrl_desc *desc = gpio_dev->pctrl->desc;
753 int i;
754
755 for (i = 0; i < desc->npins; i++) {
756 int pin = desc->pins[i].number;
757
758 if (!amd_gpio_should_save(gpio_dev, pin))
759 continue;
760
761 gpio_dev->saved_regs[i] = readl(gpio_dev->base + pin*4);
762 }
763
764 return 0;
765}
766
767int amd_gpio_resume(struct device *dev)
768{
769 struct platform_device *pdev = to_platform_device(dev);
770 struct amd_gpio *gpio_dev = platform_get_drvdata(pdev);
771 struct pinctrl_desc *desc = gpio_dev->pctrl->desc;
772 int i;
773
774 for (i = 0; i < desc->npins; i++) {
775 int pin = desc->pins[i].number;
776
777 if (!amd_gpio_should_save(gpio_dev, pin))
778 continue;
779
780 writel(gpio_dev->saved_regs[i], gpio_dev->base + pin*4);
781 }
782
783 return 0;
784}
785
786static const struct dev_pm_ops amd_gpio_pm_ops = {
787 SET_LATE_SYSTEM_SLEEP_PM_OPS(amd_gpio_suspend,
788 amd_gpio_resume)
789};
790#endif
791
Ken Xuedbad75d2015-03-10 15:02:19 +0800792static struct pinctrl_desc amd_pinctrl_desc = {
793 .pins = kerncz_pins,
794 .npins = ARRAY_SIZE(kerncz_pins),
795 .pctlops = &amd_pinctrl_ops,
796 .confops = &amd_pinconf_ops,
797 .owner = THIS_MODULE,
798};
799
800static int amd_gpio_probe(struct platform_device *pdev)
801{
802 int ret = 0;
Ken Xue25a853d2015-03-27 17:44:26 +0800803 int irq_base;
Ken Xuedbad75d2015-03-10 15:02:19 +0800804 struct resource *res;
805 struct amd_gpio *gpio_dev;
806
807 gpio_dev = devm_kzalloc(&pdev->dev,
808 sizeof(struct amd_gpio), GFP_KERNEL);
809 if (!gpio_dev)
810 return -ENOMEM;
811
Julia Cartwright229710f2017-03-09 10:22:04 -0600812 raw_spin_lock_init(&gpio_dev->lock);
Ken Xuedbad75d2015-03-10 15:02:19 +0800813
814 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
815 if (!res) {
816 dev_err(&pdev->dev, "Failed to get gpio io resource.\n");
817 return -EINVAL;
818 }
819
820 gpio_dev->base = devm_ioremap_nocache(&pdev->dev, res->start,
821 resource_size(res));
Wei Yongjun424a6c62016-02-06 22:56:36 +0800822 if (!gpio_dev->base)
823 return -ENOMEM;
Ken Xuedbad75d2015-03-10 15:02:19 +0800824
825 irq_base = platform_get_irq(pdev, 0);
826 if (irq_base < 0) {
Gustavo A. R. Silva2e6424ab2017-08-09 11:09:33 -0500827 dev_err(&pdev->dev, "Failed to get gpio IRQ: %d\n", irq_base);
828 return irq_base;
Ken Xuedbad75d2015-03-10 15:02:19 +0800829 }
830
Daniel Drake79d2c8b2017-09-11 14:11:56 +0800831#ifdef CONFIG_PM_SLEEP
832 gpio_dev->saved_regs = devm_kcalloc(&pdev->dev, amd_pinctrl_desc.npins,
833 sizeof(*gpio_dev->saved_regs),
834 GFP_KERNEL);
835 if (!gpio_dev->saved_regs)
836 return -ENOMEM;
837#endif
838
Ken Xuedbad75d2015-03-10 15:02:19 +0800839 gpio_dev->pdev = pdev;
840 gpio_dev->gc.direction_input = amd_gpio_direction_input;
841 gpio_dev->gc.direction_output = amd_gpio_direction_output;
842 gpio_dev->gc.get = amd_gpio_get_value;
843 gpio_dev->gc.set = amd_gpio_set_value;
Mika Westerberg2956b5d2017-01-23 15:34:34 +0300844 gpio_dev->gc.set_config = amd_gpio_set_config;
Ken Xuedbad75d2015-03-10 15:02:19 +0800845 gpio_dev->gc.dbg_show = amd_gpio_dbg_show;
846
Shah, Nehal-bakulchandra3bfd4432016-12-06 12:17:48 +0530847 gpio_dev->gc.base = -1;
Ken Xuedbad75d2015-03-10 15:02:19 +0800848 gpio_dev->gc.label = pdev->name;
849 gpio_dev->gc.owner = THIS_MODULE;
Linus Walleij58383c782015-11-04 09:56:26 +0100850 gpio_dev->gc.parent = &pdev->dev;
Shah, Nehal-bakulchandra3bfd4432016-12-06 12:17:48 +0530851 gpio_dev->gc.ngpio = resource_size(res) / 4;
Ken Xuedbad75d2015-03-10 15:02:19 +0800852#if defined(CONFIG_OF_GPIO)
853 gpio_dev->gc.of_node = pdev->dev.of_node;
854#endif
855
Shah, Nehal-bakulchandra3bfd4432016-12-06 12:17:48 +0530856 gpio_dev->hwbank_num = gpio_dev->gc.ngpio / 64;
Ken Xuedbad75d2015-03-10 15:02:19 +0800857 gpio_dev->groups = kerncz_groups;
858 gpio_dev->ngroups = ARRAY_SIZE(kerncz_groups);
859
860 amd_pinctrl_desc.name = dev_name(&pdev->dev);
Laxman Dewangan251e22a2016-02-24 14:44:07 +0530861 gpio_dev->pctrl = devm_pinctrl_register(&pdev->dev, &amd_pinctrl_desc,
862 gpio_dev);
Masahiro Yamada323de9e2015-06-09 13:01:16 +0900863 if (IS_ERR(gpio_dev->pctrl)) {
Ken Xuedbad75d2015-03-10 15:02:19 +0800864 dev_err(&pdev->dev, "Couldn't register pinctrl driver\n");
Masahiro Yamada323de9e2015-06-09 13:01:16 +0900865 return PTR_ERR(gpio_dev->pctrl);
Ken Xuedbad75d2015-03-10 15:02:19 +0800866 }
867
Linus Walleij04d36722015-12-08 09:21:38 +0100868 ret = gpiochip_add_data(&gpio_dev->gc, gpio_dev);
Ken Xuedbad75d2015-03-10 15:02:19 +0800869 if (ret)
Laxman Dewangan251e22a2016-02-24 14:44:07 +0530870 return ret;
Ken Xuedbad75d2015-03-10 15:02:19 +0800871
872 ret = gpiochip_add_pin_range(&gpio_dev->gc, dev_name(&pdev->dev),
Shah, Nehal-bakulchandra3bfd4432016-12-06 12:17:48 +0530873 0, 0, gpio_dev->gc.ngpio);
Ken Xuedbad75d2015-03-10 15:02:19 +0800874 if (ret) {
875 dev_err(&pdev->dev, "Failed to add pin range\n");
876 goto out2;
877 }
878
879 ret = gpiochip_irqchip_add(&gpio_dev->gc,
880 &amd_gpio_irqchip,
881 0,
882 handle_simple_irq,
883 IRQ_TYPE_NONE);
884 if (ret) {
885 dev_err(&pdev->dev, "could not add irqchip\n");
886 ret = -ENODEV;
887 goto out2;
888 }
889
Thomas Gleixnerba714a92017-05-23 23:23:32 +0200890 ret = devm_request_irq(&pdev->dev, irq_base, amd_gpio_irq_handler, 0,
891 KBUILD_MODNAME, gpio_dev);
892 if (ret)
893 goto out2;
894
Ken Xuedbad75d2015-03-10 15:02:19 +0800895 platform_set_drvdata(pdev, gpio_dev);
896
897 dev_dbg(&pdev->dev, "amd gpio driver loaded\n");
898 return ret;
899
900out2:
901 gpiochip_remove(&gpio_dev->gc);
902
Ken Xuedbad75d2015-03-10 15:02:19 +0800903 return ret;
904}
905
906static int amd_gpio_remove(struct platform_device *pdev)
907{
908 struct amd_gpio *gpio_dev;
909
910 gpio_dev = platform_get_drvdata(pdev);
911
912 gpiochip_remove(&gpio_dev->gc);
Ken Xuedbad75d2015-03-10 15:02:19 +0800913
914 return 0;
915}
916
917static const struct acpi_device_id amd_gpio_acpi_match[] = {
918 { "AMD0030", 0 },
Wang Hongcheng42a44402016-03-11 10:58:42 +0800919 { "AMDI0030", 0},
Ken Xuedbad75d2015-03-10 15:02:19 +0800920 { },
921};
922MODULE_DEVICE_TABLE(acpi, amd_gpio_acpi_match);
923
924static struct platform_driver amd_gpio_driver = {
925 .driver = {
926 .name = "amd_gpio",
Ken Xuedbad75d2015-03-10 15:02:19 +0800927 .acpi_match_table = ACPI_PTR(amd_gpio_acpi_match),
Daniel Drake79d2c8b2017-09-11 14:11:56 +0800928#ifdef CONFIG_PM_SLEEP
929 .pm = &amd_gpio_pm_ops,
930#endif
Ken Xuedbad75d2015-03-10 15:02:19 +0800931 },
932 .probe = amd_gpio_probe,
933 .remove = amd_gpio_remove,
934};
935
936module_platform_driver(amd_gpio_driver);
937
938MODULE_LICENSE("GPL v2");
939MODULE_AUTHOR("Ken Xue <Ken.Xue@amd.com>, Jeff Wu <Jeff.Wu@amd.com>");
940MODULE_DESCRIPTION("AMD GPIO pinctrl driver");