17 #include <linux/module.h>
18 #include <linux/kernel.h>
19 #include <linux/pci.h>
24 #define PCH_EDGE_FALLING 0
25 #define PCH_EDGE_RISING BIT(0)
26 #define PCH_LEVEL_L BIT(1)
27 #define PCH_LEVEL_H (BIT(0) | BIT(1))
28 #define PCH_EDGE_BOTH BIT(2)
29 #define PCH_IM_MASK (BIT(0) | BIT(1) | BIT(2))
31 #define PCH_IRQ_BASE 24
57 static int gpio_pins[] = {
108 static void pch_gpio_set(
struct gpio_chip *
gpio,
unsigned nr,
int val)
117 reg_val |= (1 <<
nr);
119 reg_val &= ~(1 <<
nr);
122 spin_unlock_irqrestore(&chip->
spinlock, flags);
125 static int pch_gpio_get(
struct gpio_chip *
gpio,
unsigned nr)
132 static int pch_gpio_direction_output(
struct gpio_chip *
gpio,
unsigned nr,
141 pm =
ioread32(&chip->
reg->pm) & ((1 << gpio_pins[chip->
ioh]) - 1);
147 reg_val |= (1 <<
nr);
149 reg_val &= ~(1 <<
nr);
151 spin_unlock_irqrestore(&chip->
spinlock, flags);
156 static int pch_gpio_direction_input(
struct gpio_chip *gpio,
unsigned nr)
163 pm =
ioread32(&chip->
reg->pm) & ((1 << gpio_pins[chip->
ioh]) - 1);
166 spin_unlock_irqrestore(&chip->
spinlock, flags);
174 static void pch_gpio_save_reg_conf(
struct pch_gpio *chip)
185 ioread32(&chip->
reg->gpio_use_sel);
191 static void pch_gpio_restore_reg_conf(
struct pch_gpio *chip)
204 &chip->
reg->gpio_use_sel);
207 static int pch_gpio_to_irq(
struct gpio_chip *gpio,
unsigned offset)
213 static void pch_gpio_setup(
struct pch_gpio *chip)
215 struct gpio_chip *gpio = &chip->
gpio;
217 gpio->label = dev_name(chip->
dev);
219 gpio->direction_input = pch_gpio_direction_input;
220 gpio->get = pch_gpio_get;
221 gpio->direction_output = pch_gpio_direction_output;
222 gpio->set = pch_gpio_set;
223 gpio->dbg_show =
NULL;
225 gpio->ngpio = gpio_pins[chip->
ioh];
227 gpio->to_irq = pch_gpio_to_irq;
230 static int pch_irq_type(
struct irq_data *
d,
unsigned int type)
232 struct irq_chip_generic *
gc = irq_data_get_irq_chip_data(d);
233 struct pch_gpio *chip = gc->private;
241 im_reg = &chip->
reg->im0;
244 im_reg = &chip->
reg->im1;
247 dev_dbg(chip->
dev,
"%s:irq=%d type=%d ch=%d pos=%d\n",
248 __func__, irq, type, ch, im_pos);
274 iowrite32(im | (val << (im_pos * 4)), im_reg);
283 spin_unlock_irqrestore(&chip->
spinlock, flags);
287 static void pch_irq_unmask(
struct irq_data *d)
289 struct irq_chip_generic *gc = irq_data_get_irq_chip_data(d);
290 struct pch_gpio *chip = gc->private;
295 static void pch_irq_mask(
struct irq_data *d)
297 struct irq_chip_generic *gc = irq_data_get_irq_chip_data(d);
298 struct pch_gpio *chip = gc->private;
303 static void pch_irq_ack(
struct irq_data *d)
305 struct irq_chip_generic *gc = irq_data_get_irq_chip_data(d);
306 struct pch_gpio *chip = gc->private;
317 for (i = 0; i < gpio_pins[chip->
ioh]; i++) {
318 if (reg_val &
BIT(i)) {
319 dev_dbg(chip->
dev,
"%s:[%d]:irq=%d status=0x%x\n",
320 __func__, i, irq, reg_val);
329 unsigned int irq_start,
unsigned int num)
331 struct irq_chip_generic *gc;
332 struct irq_chip_type *
ct;
339 ct->chip.irq_ack = pch_irq_ack;
340 ct->chip.irq_mask = pch_irq_mask;
341 ct->chip.irq_unmask = pch_irq_unmask;
342 ct->chip.irq_set_type = pch_irq_type;
363 dev_err(&pdev->
dev,
"%s : pci_enable_device FAILED", __func__);
369 dev_err(&pdev->
dev,
"pci_request_regions FAILED-%d", ret);
370 goto err_request_regions;
373 chip->
base = pci_iomap(pdev, 1, 0);
375 dev_err(&pdev->
dev,
"%s : pci_iomap FAILED", __func__);
380 if (pdev->
device == 0x8803)
382 else if (pdev->
device == 0x8014)
384 else if (pdev->
device == 0x8043)
388 pci_set_drvdata(pdev, chip);
390 pch_gpio_setup(chip);
393 dev_err(&pdev->
dev,
"PCH gpio: Failed to register GPIO\n");
394 goto err_gpiochip_add;
399 dev_warn(&pdev->
dev,
"PCH gpio: Failed to get IRQ base num\n");
406 msk = (1 << gpio_pins[chip->
ioh]) - 1;
414 "%s request_irq failed\n", __func__);
415 goto err_request_irq;
418 pch_gpio_alloc_generic_chip(chip, irq_base, gpio_pins[chip->
ioh]);
428 dev_err(&pdev->
dev,
"%s gpiochip_remove failed\n", __func__);
441 dev_err(&pdev->
dev,
"%s Failed returns %d\n", __func__, ret);
448 struct pch_gpio *chip = pci_get_drvdata(pdev);
458 dev_err(&pdev->
dev,
"Failed gpiochip_remove\n");
470 struct pch_gpio *chip = pci_get_drvdata(pdev);
474 pch_gpio_save_reg_conf(chip);
475 spin_unlock_irqrestore(&chip->
spinlock, flags);
479 dev_err(&pdev->
dev,
"pci_save_state Failed-%d\n", ret);
484 ret = pci_enable_wake(pdev,
PCI_D0, 1);
486 dev_err(&pdev->
dev,
"pci_enable_wake Failed -%d\n", ret);
494 struct pch_gpio *chip = pci_get_drvdata(pdev);
497 ret = pci_enable_wake(pdev,
PCI_D0, 0);
502 dev_err(&pdev->
dev,
"pci_enable_device Failed-%d ", ret);
510 pch_gpio_restore_reg_conf(chip);
511 spin_unlock_irqrestore(&chip->
spinlock, flags);
516 #define pch_gpio_suspend NULL
517 #define pch_gpio_resume NULL
520 #define PCI_VENDOR_ID_ROHM 0x10DB
532 .id_table = pch_gpio_pcidev_id,
533 .probe = pch_gpio_probe,