Blame view

drivers/gpio/gpio-wcove.c 12.6 KB
fd30b72ea   Andy Shevchenko   gpio: wcove: Conv...
1
  // SPDX-License-Identifier: GPL-2.0
0ba19cfc2   Bin Gao   gpio: Add Intel W...
2
3
4
5
6
7
  /*
   * Intel Whiskey Cove PMIC GPIO Driver
   *
   * This driver is written based on gpio-crystalcove.c
   *
   * Copyright (C) 2016 Intel Corporation. All rights reserved.
0ba19cfc2   Bin Gao   gpio: Add Intel W...
8
9
10
   */
  
  #include <linux/bitops.h>
0ba19cfc2   Bin Gao   gpio: Add Intel W...
11
  #include <linux/gpio/driver.h>
39684807d   Andy Shevchenko   gpio: wcove: Sort...
12
  #include <linux/interrupt.h>
0ba19cfc2   Bin Gao   gpio: Add Intel W...
13
  #include <linux/mfd/intel_soc_pmic.h>
39684807d   Andy Shevchenko   gpio: wcove: Sort...
14
  #include <linux/module.h>
0ba19cfc2   Bin Gao   gpio: Add Intel W...
15
16
17
18
19
20
  #include <linux/platform_device.h>
  #include <linux/regmap.h>
  #include <linux/seq_file.h>
  
  /*
   * Whiskey Cove PMIC has 13 physical GPIO pins divided into 3 banks:
cb19c7f3e   Andy Shevchenko   gpio: wcove: Fix ...
21
22
23
   * Bank 0: Pin  0 - 6
   * Bank 1: Pin  7 - 10
   * Bank 2: Pin 11 - 12
0ba19cfc2   Bin Gao   gpio: Add Intel W...
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
   * Each pin has one output control register and one input control register.
   */
  #define BANK0_NR_PINS		7
  #define BANK1_NR_PINS		4
  #define BANK2_NR_PINS		2
  #define WCOVE_GPIO_NUM		(BANK0_NR_PINS + BANK1_NR_PINS + BANK2_NR_PINS)
  #define WCOVE_VGPIO_NUM		94
  /* GPIO output control registers (one per pin): 0x4e44 - 0x4e50 */
  #define GPIO_OUT_CTRL_BASE	0x4e44
  /* GPIO input control registers (one per pin): 0x4e51 - 0x4e5d */
  #define GPIO_IN_CTRL_BASE	0x4e51
  
  /*
   * GPIO interrupts are organized in two groups:
   * Group 0: Bank 0 pins (Pin 0 - 6)
   * Group 1: Bank 1 and Bank 2 pins (Pin 7 - 12)
   * Each group has two registers (one bit per pin): status and mask.
   */
  #define GROUP0_NR_IRQS		7
  #define GROUP1_NR_IRQS		6
  #define IRQ_MASK_BASE		0x4e19
  #define IRQ_STATUS_BASE		0x4e0b
881ebd229   Kuppuswamy Sathyanarayanan   gpio: gpio-wcove:...
46
47
  #define GPIO_IRQ0_MASK		GENMASK(6, 0)
  #define GPIO_IRQ1_MASK		GENMASK(5, 0)
0ba19cfc2   Bin Gao   gpio: Add Intel W...
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
  #define UPDATE_IRQ_TYPE		BIT(0)
  #define UPDATE_IRQ_MASK		BIT(1)
  
  #define CTLI_INTCNT_DIS		(0 << 1)
  #define CTLI_INTCNT_NE		(1 << 1)
  #define CTLI_INTCNT_PE		(2 << 1)
  #define CTLI_INTCNT_BE		(3 << 1)
  
  #define CTLO_DIR_IN		(0 << 5)
  #define CTLO_DIR_OUT		(1 << 5)
  
  #define CTLO_DRV_MASK		(1 << 4)
  #define CTLO_DRV_OD		(0 << 4)
  #define CTLO_DRV_CMOS		(1 << 4)
  
  #define CTLO_DRV_REN		(1 << 3)
  
  #define CTLO_RVAL_2KDOWN	(0 << 1)
  #define CTLO_RVAL_2KUP		(1 << 1)
  #define CTLO_RVAL_50KDOWN	(2 << 1)
  #define CTLO_RVAL_50KUP		(3 << 1)
cb19c7f3e   Andy Shevchenko   gpio: wcove: Fix ...
69
70
  #define CTLO_INPUT_SET		(CTLO_DRV_CMOS | CTLO_DRV_REN | CTLO_RVAL_2KUP)
  #define CTLO_OUTPUT_SET		(CTLO_DIR_OUT | CTLO_INPUT_SET)
0ba19cfc2   Bin Gao   gpio: Add Intel W...
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
  
  enum ctrl_register {
  	CTRL_IN,
  	CTRL_OUT,
  };
  
  /*
   * struct wcove_gpio - Whiskey Cove GPIO controller
   * @buslock: for bus lock/sync and unlock.
   * @chip: the abstract gpio_chip structure.
   * @dev: the gpio device
   * @regmap: the regmap from the parent device.
   * @regmap_irq_chip: the regmap of the gpio irq chip.
   * @update: pending IRQ setting update, to be written to the chip upon unlock.
   * @intcnt: the Interrupt Detect value to be written.
   * @set_irq_mask: true if the IRQ mask needs to be set, false to clear.
   */
  struct wcove_gpio {
  	struct mutex buslock;
  	struct gpio_chip chip;
  	struct device *dev;
  	struct regmap *regmap;
  	struct regmap_irq_chip_data *regmap_irq_chip;
  	int update;
  	int intcnt;
  	bool set_irq_mask;
  };
282db906e   Andy Shevchenko   gpio: wcove: Allo...
98
  static inline int to_reg(int gpio, enum ctrl_register reg_type)
0ba19cfc2   Bin Gao   gpio: Add Intel W...
99
100
  {
  	unsigned int reg;
0ba19cfc2   Bin Gao   gpio: Add Intel W...
101

3a02dc974   Kuppuswamy Sathyanarayanan   gpio: gpio-wcove:...
102
103
  	if (gpio >= WCOVE_GPIO_NUM)
  		return -EOPNOTSUPP;
0ba19cfc2   Bin Gao   gpio: Add Intel W...
104
105
  
  	if (reg_type == CTRL_IN)
3a02dc974   Kuppuswamy Sathyanarayanan   gpio: gpio-wcove:...
106
  		reg = GPIO_IN_CTRL_BASE + gpio;
0ba19cfc2   Bin Gao   gpio: Add Intel W...
107
  	else
3a02dc974   Kuppuswamy Sathyanarayanan   gpio: gpio-wcove:...
108
  		reg = GPIO_OUT_CTRL_BASE + gpio;
0ba19cfc2   Bin Gao   gpio: Add Intel W...
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
  
  	return reg;
  }
  
  static void wcove_update_irq_mask(struct wcove_gpio *wg, int gpio)
  {
  	unsigned int reg, mask;
  
  	if (gpio < GROUP0_NR_IRQS) {
  		reg = IRQ_MASK_BASE;
  		mask = BIT(gpio % GROUP0_NR_IRQS);
  	} else {
  		reg = IRQ_MASK_BASE + 1;
  		mask = BIT((gpio - GROUP0_NR_IRQS) % GROUP1_NR_IRQS);
  	}
  
  	if (wg->set_irq_mask)
  		regmap_update_bits(wg->regmap, reg, mask, mask);
  	else
  		regmap_update_bits(wg->regmap, reg, mask, 0);
  }
  
  static void wcove_update_irq_ctrl(struct wcove_gpio *wg, int gpio)
  {
3a02dc974   Kuppuswamy Sathyanarayanan   gpio: gpio-wcove:...
133
134
135
136
  	int reg = to_reg(gpio, CTRL_IN);
  
  	if (reg < 0)
  		return;
0ba19cfc2   Bin Gao   gpio: Add Intel W...
137
138
139
140
141
142
143
  
  	regmap_update_bits(wg->regmap, reg, CTLI_INTCNT_BE, wg->intcnt);
  }
  
  static int wcove_gpio_dir_in(struct gpio_chip *chip, unsigned int gpio)
  {
  	struct wcove_gpio *wg = gpiochip_get_data(chip);
3a02dc974   Kuppuswamy Sathyanarayanan   gpio: gpio-wcove:...
144
145
146
147
  	int reg = to_reg(gpio, CTRL_OUT);
  
  	if (reg < 0)
  		return 0;
0ba19cfc2   Bin Gao   gpio: Add Intel W...
148

3a02dc974   Kuppuswamy Sathyanarayanan   gpio: gpio-wcove:...
149
  	return regmap_write(wg->regmap, reg, CTLO_INPUT_SET);
0ba19cfc2   Bin Gao   gpio: Add Intel W...
150
151
152
153
154
155
  }
  
  static int wcove_gpio_dir_out(struct gpio_chip *chip, unsigned int gpio,
  				    int value)
  {
  	struct wcove_gpio *wg = gpiochip_get_data(chip);
3a02dc974   Kuppuswamy Sathyanarayanan   gpio: gpio-wcove:...
156
  	int reg = to_reg(gpio, CTRL_OUT);
0ba19cfc2   Bin Gao   gpio: Add Intel W...
157

3a02dc974   Kuppuswamy Sathyanarayanan   gpio: gpio-wcove:...
158
159
160
161
  	if (reg < 0)
  		return 0;
  
  	return regmap_write(wg->regmap, reg, CTLO_OUTPUT_SET | value);
0ba19cfc2   Bin Gao   gpio: Add Intel W...
162
  }
7d9e59ce7   Bin Gao   gpio: wcove-gpio:...
163
164
165
166
  static int wcove_gpio_get_direction(struct gpio_chip *chip, unsigned int gpio)
  {
  	struct wcove_gpio *wg = gpiochip_get_data(chip);
  	unsigned int val;
3a02dc974   Kuppuswamy Sathyanarayanan   gpio: gpio-wcove:...
167
168
169
  	int ret, reg = to_reg(gpio, CTRL_OUT);
  
  	if (reg < 0)
e42615ec2   Matti Vaittinen   gpio: Use new GPI...
170
  		return GPIO_LINE_DIRECTION_OUT;
7d9e59ce7   Bin Gao   gpio: wcove-gpio:...
171

3a02dc974   Kuppuswamy Sathyanarayanan   gpio: gpio-wcove:...
172
  	ret = regmap_read(wg->regmap, reg, &val);
7d9e59ce7   Bin Gao   gpio: wcove-gpio:...
173
174
  	if (ret)
  		return ret;
e42615ec2   Matti Vaittinen   gpio: Use new GPI...
175
176
177
178
  	if (val & CTLO_DIR_OUT)
  		return GPIO_LINE_DIRECTION_OUT;
  
  	return GPIO_LINE_DIRECTION_IN;
7d9e59ce7   Bin Gao   gpio: wcove-gpio:...
179
  }
0ba19cfc2   Bin Gao   gpio: Add Intel W...
180
181
182
183
  static int wcove_gpio_get(struct gpio_chip *chip, unsigned int gpio)
  {
  	struct wcove_gpio *wg = gpiochip_get_data(chip);
  	unsigned int val;
3a02dc974   Kuppuswamy Sathyanarayanan   gpio: gpio-wcove:...
184
185
186
187
  	int ret, reg = to_reg(gpio, CTRL_IN);
  
  	if (reg < 0)
  		return 0;
0ba19cfc2   Bin Gao   gpio: Add Intel W...
188

3a02dc974   Kuppuswamy Sathyanarayanan   gpio: gpio-wcove:...
189
  	ret = regmap_read(wg->regmap, reg, &val);
0ba19cfc2   Bin Gao   gpio: Add Intel W...
190
191
192
193
194
  	if (ret)
  		return ret;
  
  	return val & 0x1;
  }
cb19c7f3e   Andy Shevchenko   gpio: wcove: Fix ...
195
  static void wcove_gpio_set(struct gpio_chip *chip, unsigned int gpio, int value)
0ba19cfc2   Bin Gao   gpio: Add Intel W...
196
197
  {
  	struct wcove_gpio *wg = gpiochip_get_data(chip);
3a02dc974   Kuppuswamy Sathyanarayanan   gpio: gpio-wcove:...
198
199
200
201
  	int reg = to_reg(gpio, CTRL_OUT);
  
  	if (reg < 0)
  		return;
0ba19cfc2   Bin Gao   gpio: Add Intel W...
202
203
  
  	if (value)
3a02dc974   Kuppuswamy Sathyanarayanan   gpio: gpio-wcove:...
204
  		regmap_update_bits(wg->regmap, reg, 1, 1);
0ba19cfc2   Bin Gao   gpio: Add Intel W...
205
  	else
3a02dc974   Kuppuswamy Sathyanarayanan   gpio: gpio-wcove:...
206
  		regmap_update_bits(wg->regmap, reg, 1, 0);
0ba19cfc2   Bin Gao   gpio: Add Intel W...
207
  }
2956b5d94   Mika Westerberg   pinctrl / gpio: I...
208
209
  static int wcove_gpio_set_config(struct gpio_chip *chip, unsigned int gpio,
  				 unsigned long config)
0ba19cfc2   Bin Gao   gpio: Add Intel W...
210
211
  {
  	struct wcove_gpio *wg = gpiochip_get_data(chip);
3a02dc974   Kuppuswamy Sathyanarayanan   gpio: gpio-wcove:...
212
213
214
215
  	int reg = to_reg(gpio, CTRL_OUT);
  
  	if (reg < 0)
  		return 0;
0ba19cfc2   Bin Gao   gpio: Add Intel W...
216

2956b5d94   Mika Westerberg   pinctrl / gpio: I...
217
218
  	switch (pinconf_to_config_param(config)) {
  	case PIN_CONFIG_DRIVE_OPEN_DRAIN:
3a02dc974   Kuppuswamy Sathyanarayanan   gpio: gpio-wcove:...
219
220
  		return regmap_update_bits(wg->regmap, reg, CTLO_DRV_MASK,
  					  CTLO_DRV_OD);
2956b5d94   Mika Westerberg   pinctrl / gpio: I...
221
  	case PIN_CONFIG_DRIVE_PUSH_PULL:
3a02dc974   Kuppuswamy Sathyanarayanan   gpio: gpio-wcove:...
222
223
  		return regmap_update_bits(wg->regmap, reg, CTLO_DRV_MASK,
  					  CTLO_DRV_CMOS);
0ba19cfc2   Bin Gao   gpio: Add Intel W...
224
225
226
227
228
229
230
231
232
233
234
  	default:
  		break;
  	}
  
  	return -ENOTSUPP;
  }
  
  static int wcove_irq_type(struct irq_data *data, unsigned int type)
  {
  	struct gpio_chip *chip = irq_data_get_irq_chip_data(data);
  	struct wcove_gpio *wg = gpiochip_get_data(chip);
3a02dc974   Kuppuswamy Sathyanarayanan   gpio: gpio-wcove:...
235
236
  	if (data->hwirq >= WCOVE_GPIO_NUM)
  		return 0;
0ba19cfc2   Bin Gao   gpio: Add Intel W...
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
  	switch (type) {
  	case IRQ_TYPE_NONE:
  		wg->intcnt = CTLI_INTCNT_DIS;
  		break;
  	case IRQ_TYPE_EDGE_BOTH:
  		wg->intcnt = CTLI_INTCNT_BE;
  		break;
  	case IRQ_TYPE_EDGE_RISING:
  		wg->intcnt = CTLI_INTCNT_PE;
  		break;
  	case IRQ_TYPE_EDGE_FALLING:
  		wg->intcnt = CTLI_INTCNT_NE;
  		break;
  	default:
  		return -EINVAL;
  	}
  
  	wg->update |= UPDATE_IRQ_TYPE;
  
  	return 0;
  }
  
  static void wcove_bus_lock(struct irq_data *data)
  {
  	struct gpio_chip *chip = irq_data_get_irq_chip_data(data);
  	struct wcove_gpio *wg = gpiochip_get_data(chip);
  
  	mutex_lock(&wg->buslock);
  }
  
  static void wcove_bus_sync_unlock(struct irq_data *data)
  {
  	struct gpio_chip *chip = irq_data_get_irq_chip_data(data);
  	struct wcove_gpio *wg = gpiochip_get_data(chip);
  	int gpio = data->hwirq;
  
  	if (wg->update & UPDATE_IRQ_TYPE)
  		wcove_update_irq_ctrl(wg, gpio);
  	if (wg->update & UPDATE_IRQ_MASK)
  		wcove_update_irq_mask(wg, gpio);
  	wg->update = 0;
  
  	mutex_unlock(&wg->buslock);
  }
  
  static void wcove_irq_unmask(struct irq_data *data)
  {
  	struct gpio_chip *chip = irq_data_get_irq_chip_data(data);
  	struct wcove_gpio *wg = gpiochip_get_data(chip);
3a02dc974   Kuppuswamy Sathyanarayanan   gpio: gpio-wcove:...
286
287
  	if (data->hwirq >= WCOVE_GPIO_NUM)
  		return;
0ba19cfc2   Bin Gao   gpio: Add Intel W...
288
289
290
291
292
293
294
295
  	wg->set_irq_mask = false;
  	wg->update |= UPDATE_IRQ_MASK;
  }
  
  static void wcove_irq_mask(struct irq_data *data)
  {
  	struct gpio_chip *chip = irq_data_get_irq_chip_data(data);
  	struct wcove_gpio *wg = gpiochip_get_data(chip);
3a02dc974   Kuppuswamy Sathyanarayanan   gpio: gpio-wcove:...
296
297
  	if (data->hwirq >= WCOVE_GPIO_NUM)
  		return;
0ba19cfc2   Bin Gao   gpio: Add Intel W...
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
  	wg->set_irq_mask = true;
  	wg->update |= UPDATE_IRQ_MASK;
  }
  
  static struct irq_chip wcove_irqchip = {
  	.name			= "Whiskey Cove",
  	.irq_mask		= wcove_irq_mask,
  	.irq_unmask		= wcove_irq_unmask,
  	.irq_set_type		= wcove_irq_type,
  	.irq_bus_lock		= wcove_bus_lock,
  	.irq_bus_sync_unlock	= wcove_bus_sync_unlock,
  };
  
  static irqreturn_t wcove_gpio_irq_handler(int irq, void *data)
  {
  	struct wcove_gpio *wg = (struct wcove_gpio *)data;
  	unsigned int pending, virq, gpio, mask, offset;
  	u8 p[2];
  
  	if (regmap_bulk_read(wg->regmap, IRQ_STATUS_BASE, p, 2)) {
  		dev_err(wg->dev, "Failed to read irq status register
  ");
  		return IRQ_NONE;
  	}
881ebd229   Kuppuswamy Sathyanarayanan   gpio: gpio-wcove:...
322
  	pending = (p[0] & GPIO_IRQ0_MASK) | ((p[1] & GPIO_IRQ1_MASK) << 7);
0ba19cfc2   Bin Gao   gpio: Add Intel W...
323
324
325
326
327
328
329
  	if (!pending)
  		return IRQ_NONE;
  
  	/* Iterate until no interrupt is pending */
  	while (pending) {
  		/* One iteration is for all pending bits */
  		for_each_set_bit(gpio, (const unsigned long *)&pending,
7c2d176fe   Kuppuswamy Sathyanarayanan   gpio: gpio-wcove:...
330
  						 WCOVE_GPIO_NUM) {
0ba19cfc2   Bin Gao   gpio: Add Intel W...
331
332
333
  			offset = (gpio > GROUP0_NR_IRQS) ? 1 : 0;
  			mask = (offset == 1) ? BIT(gpio - GROUP0_NR_IRQS) :
  								BIT(gpio);
f0fbe7bce   Thierry Reding   gpio: Move irqdom...
334
  			virq = irq_find_mapping(wg->chip.irq.domain, gpio);
0ba19cfc2   Bin Gao   gpio: Add Intel W...
335
336
337
338
339
340
341
342
343
344
345
  			handle_nested_irq(virq);
  			regmap_update_bits(wg->regmap, IRQ_STATUS_BASE + offset,
  								mask, mask);
  		}
  
  		/* Next iteration */
  		if (regmap_bulk_read(wg->regmap, IRQ_STATUS_BASE, p, 2)) {
  			dev_err(wg->dev, "Failed to read irq status
  ");
  			break;
  		}
881ebd229   Kuppuswamy Sathyanarayanan   gpio: gpio-wcove:...
346
  		pending = (p[0] & GPIO_IRQ0_MASK) | ((p[1] & GPIO_IRQ1_MASK) << 7);
0ba19cfc2   Bin Gao   gpio: Add Intel W...
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
  	}
  
  	return IRQ_HANDLED;
  }
  
  static void wcove_gpio_dbg_show(struct seq_file *s,
  				      struct gpio_chip *chip)
  {
  	unsigned int ctlo, ctli, irq_mask, irq_status;
  	struct wcove_gpio *wg = gpiochip_get_data(chip);
  	int gpio, offset, group, ret = 0;
  
  	for (gpio = 0; gpio < WCOVE_GPIO_NUM; gpio++) {
  		group = gpio < GROUP0_NR_IRQS ? 0 : 1;
  		ret += regmap_read(wg->regmap, to_reg(gpio, CTRL_OUT), &ctlo);
  		ret += regmap_read(wg->regmap, to_reg(gpio, CTRL_IN), &ctli);
  		ret += regmap_read(wg->regmap, IRQ_MASK_BASE + group,
  							&irq_mask);
  		ret += regmap_read(wg->regmap, IRQ_STATUS_BASE + group,
  							&irq_status);
  		if (ret) {
  			pr_err("Failed to read registers: ctrl out/in or irq status/mask
  ");
  			break;
  		}
  
  		offset = gpio % 8;
  		seq_printf(s, " gpio-%-2d %s %s %s %s ctlo=%2x,%s %s
  ",
  			   gpio, ctlo & CTLO_DIR_OUT ? "out" : "in ",
  			   ctli & 0x1 ? "hi" : "lo",
  			   ctli & CTLI_INTCNT_NE ? "fall" : "    ",
  			   ctli & CTLI_INTCNT_PE ? "rise" : "    ",
  			   ctlo,
  			   irq_mask & BIT(offset) ? "mask  " : "unmask",
  			   irq_status & BIT(offset) ? "pending" : "       ");
  	}
  }
  
  static int wcove_gpio_probe(struct platform_device *pdev)
  {
  	struct intel_soc_pmic *pmic;
  	struct wcove_gpio *wg;
  	int virq, ret, irq;
  	struct device *dev;
22f61d4e6   Linus Walleij   gpio: wcove: Use ...
392
  	struct gpio_irq_chip *girq;
0ba19cfc2   Bin Gao   gpio: Add Intel W...
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
  
  	/*
  	 * This gpio platform device is created by a mfd device (see
  	 * drivers/mfd/intel_soc_pmic_bxtwc.c for details). Information
  	 * shared by all sub-devices created by the mfd device, the regmap
  	 * pointer for instance, is stored as driver data of the mfd device
  	 * driver.
  	 */
  	pmic = dev_get_drvdata(pdev->dev.parent);
  	if (!pmic)
  		return -ENODEV;
  
  	irq = platform_get_irq(pdev, 0);
  	if (irq < 0)
  		return irq;
  
  	dev = &pdev->dev;
  
  	wg = devm_kzalloc(dev, sizeof(*wg), GFP_KERNEL);
  	if (!wg)
  		return -ENOMEM;
a1d28c599   Kuppuswamy Sathyanarayanan   mfd: intel_soc_pm...
414
  	wg->regmap_irq_chip = pmic->irq_chip_data;
0ba19cfc2   Bin Gao   gpio: Add Intel W...
415
416
417
418
419
420
421
  
  	platform_set_drvdata(pdev, wg);
  
  	mutex_init(&wg->buslock);
  	wg->chip.label = KBUILD_MODNAME;
  	wg->chip.direction_input = wcove_gpio_dir_in;
  	wg->chip.direction_output = wcove_gpio_dir_out;
7d9e59ce7   Bin Gao   gpio: wcove-gpio:...
422
  	wg->chip.get_direction = wcove_gpio_get_direction;
0ba19cfc2   Bin Gao   gpio: Add Intel W...
423
424
  	wg->chip.get = wcove_gpio_get;
  	wg->chip.set = wcove_gpio_set;
2956b5d94   Mika Westerberg   pinctrl / gpio: I...
425
  	wg->chip.set_config = wcove_gpio_set_config,
0ba19cfc2   Bin Gao   gpio: Add Intel W...
426
427
428
429
430
431
432
  	wg->chip.base = -1;
  	wg->chip.ngpio = WCOVE_VGPIO_NUM;
  	wg->chip.can_sleep = true;
  	wg->chip.parent = pdev->dev.parent;
  	wg->chip.dbg_show = wcove_gpio_dbg_show;
  	wg->dev = dev;
  	wg->regmap = pmic->regmap;
0ba19cfc2   Bin Gao   gpio: Add Intel W...
433
434
435
436
437
438
  	virq = regmap_irq_get_virq(wg->regmap_irq_chip, irq);
  	if (virq < 0) {
  		dev_err(dev, "Failed to get virq by irq %d
  ", irq);
  		return virq;
  	}
22f61d4e6   Linus Walleij   gpio: wcove: Use ...
439
440
441
442
443
444
445
446
447
  	girq = &wg->chip.irq;
  	girq->chip = &wcove_irqchip;
  	/* This will let us handle the parent IRQ in the driver */
  	girq->parent_handler = NULL;
  	girq->num_parents = 0;
  	girq->parents = NULL;
  	girq->default_type = IRQ_TYPE_NONE;
  	girq->handler = handle_simple_irq;
  	girq->threaded = true;
22cc42207   Andy Shevchenko   gpio: wcove: Requ...
448
449
450
451
452
453
454
  	ret = devm_request_threaded_irq(dev, virq, NULL, wcove_gpio_irq_handler,
  					IRQF_ONESHOT, pdev->name, wg);
  	if (ret) {
  		dev_err(dev, "Failed to request irq %d
  ", virq);
  		return ret;
  	}
22f61d4e6   Linus Walleij   gpio: wcove: Use ...
455
456
457
458
459
460
  	ret = devm_gpiochip_add_data(dev, &wg->chip, wg);
  	if (ret) {
  		dev_err(dev, "Failed to add gpiochip: %d
  ", ret);
  		return ret;
  	}
35ca3f616   Linus Walleij   gpio: set explici...
461

a1d28c599   Kuppuswamy Sathyanarayanan   mfd: intel_soc_pm...
462
463
464
465
466
467
468
469
470
471
472
  	/* Enable GPIO0 interrupts */
  	ret = regmap_update_bits(wg->regmap, IRQ_MASK_BASE, GPIO_IRQ0_MASK,
  				 0x00);
  	if (ret)
  		return ret;
  
  	/* Enable GPIO1 interrupts */
  	ret = regmap_update_bits(wg->regmap, IRQ_MASK_BASE + 1, GPIO_IRQ1_MASK,
  				 0x00);
  	if (ret)
  		return ret;
0ba19cfc2   Bin Gao   gpio: Add Intel W...
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
  	return 0;
  }
  
  /*
   * Whiskey Cove PMIC itself is a analog device(but with digital control
   * interface) providing power management support for other devices in
   * the accompanied SoC, so we have no .pm for Whiskey Cove GPIO driver.
   */
  static struct platform_driver wcove_gpio_driver = {
  	.driver = {
  		.name = "bxt_wcove_gpio",
  	},
  	.probe = wcove_gpio_probe,
  };
  
  module_platform_driver(wcove_gpio_driver);
  
  MODULE_AUTHOR("Ajay Thomas <ajay.thomas.david.rajamanickam@intel.com>");
  MODULE_AUTHOR("Bin Gao <bin.gao@intel.com>");
  MODULE_DESCRIPTION("Intel Whiskey Cove GPIO Driver");
  MODULE_LICENSE("GPL v2");
  MODULE_ALIAS("platform:bxt_wcove_gpio");