Grant Likely | c103de2 | 2011-06-04 18:38:28 -0600 | [diff] [blame] | 1 | /* |
David Cohen | a0bbf03 | 2014-01-17 07:30:01 -0800 | [diff] [blame] | 2 | * Intel MID GPIO driver |
Grant Likely | c103de2 | 2011-06-04 18:38:28 -0600 | [diff] [blame] | 3 | * |
David Cohen | a0bbf03 | 2014-01-17 07:30:01 -0800 | [diff] [blame] | 4 | * Copyright (c) 2008-2014 Intel Corporation. |
Alek Du | 8bf0261 | 2009-09-22 16:46:36 -0700 | [diff] [blame] | 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License version 2 as |
| 8 | * published by the Free Software Foundation. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
Alek Du | 8bf0261 | 2009-09-22 16:46:36 -0700 | [diff] [blame] | 14 | */ |
| 15 | |
| 16 | /* Supports: |
| 17 | * Moorestown platform Langwell chip. |
Alek Du | 8081c84 | 2010-05-26 14:42:25 -0700 | [diff] [blame] | 18 | * Medfield platform Penwell chip. |
David Cohen | f89a768 | 2013-10-04 13:01:42 -0700 | [diff] [blame] | 19 | * Clovertrail platform Cloverview chip. |
| 20 | * Merrifield platform Tangier chip. |
Alek Du | 8bf0261 | 2009-09-22 16:46:36 -0700 | [diff] [blame] | 21 | */ |
| 22 | |
| 23 | #include <linux/module.h> |
| 24 | #include <linux/pci.h> |
Alan Cox | 72b4379 | 2010-10-27 15:33:23 -0700 | [diff] [blame] | 25 | #include <linux/platform_device.h> |
Alek Du | 8bf0261 | 2009-09-22 16:46:36 -0700 | [diff] [blame] | 26 | #include <linux/kernel.h> |
| 27 | #include <linux/delay.h> |
| 28 | #include <linux/stddef.h> |
| 29 | #include <linux/interrupt.h> |
| 30 | #include <linux/init.h> |
Alek Du | 8bf0261 | 2009-09-22 16:46:36 -0700 | [diff] [blame] | 31 | #include <linux/io.h> |
Linus Walleij | 3f7dbfd | 2014-05-29 16:55:55 +0200 | [diff] [blame] | 32 | #include <linux/gpio/driver.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 33 | #include <linux/slab.h> |
Kristen Carlson Accardi | 7812803 | 2011-05-10 14:23:45 +0100 | [diff] [blame] | 34 | #include <linux/pm_runtime.h> |
Alek Du | 8bf0261 | 2009-09-22 16:46:36 -0700 | [diff] [blame] | 35 | |
David Cohen | f89a768 | 2013-10-04 13:01:42 -0700 | [diff] [blame] | 36 | #define INTEL_MID_IRQ_TYPE_EDGE (1 << 0) |
| 37 | #define INTEL_MID_IRQ_TYPE_LEVEL (1 << 1) |
David Cohen | d56d6b3 | 2013-10-04 13:01:40 -0700 | [diff] [blame] | 38 | |
Alek Du | 8081c84 | 2010-05-26 14:42:25 -0700 | [diff] [blame] | 39 | /* |
| 40 | * Langwell chip has 64 pins and thus there are 2 32bit registers to control |
| 41 | * each feature, while Penwell chip has 96 pins for each block, and need 3 32bit |
| 42 | * registers to control them, so we only define the order here instead of a |
| 43 | * structure, to get a bit offset for a pin (use GPDR as an example): |
| 44 | * |
| 45 | * nreg = ngpio / 32; |
| 46 | * reg = offset / 32; |
| 47 | * bit = offset % 32; |
| 48 | * reg_addr = reg_base + GPDR * nreg * 4 + reg * 4; |
| 49 | * |
| 50 | * so the bit of reg_addr is to control pin offset's GPDR feature |
| 51 | */ |
| 52 | |
| 53 | enum GPIO_REG { |
| 54 | GPLR = 0, /* pin level read-only */ |
| 55 | GPDR, /* pin direction */ |
| 56 | GPSR, /* pin set */ |
| 57 | GPCR, /* pin clear */ |
| 58 | GRER, /* rising edge detect */ |
| 59 | GFER, /* falling edge detect */ |
| 60 | GEDR, /* edge detect result */ |
Adrian Hunter | 8c0f7b1 | 2011-10-03 14:36:07 +0300 | [diff] [blame] | 61 | GAFR, /* alt function */ |
Alek Du | 8bf0261 | 2009-09-22 16:46:36 -0700 | [diff] [blame] | 62 | }; |
| 63 | |
David Cohen | f89a768 | 2013-10-04 13:01:42 -0700 | [diff] [blame] | 64 | /* intel_mid gpio driver data */ |
| 65 | struct intel_mid_gpio_ddata { |
David Cohen | d56d6b3 | 2013-10-04 13:01:40 -0700 | [diff] [blame] | 66 | u16 ngpio; /* number of gpio pins */ |
| 67 | u32 gplr_offset; /* offset of first GPLR register from base */ |
| 68 | u32 flis_base; /* base address of FLIS registers */ |
| 69 | u32 flis_len; /* length of FLIS registers */ |
| 70 | u32 (*get_flis_offset)(int gpio); |
| 71 | u32 chip_irq_type; /* chip interrupt type */ |
| 72 | }; |
| 73 | |
David Cohen | f89a768 | 2013-10-04 13:01:42 -0700 | [diff] [blame] | 74 | struct intel_mid_gpio { |
Alek Du | 8bf0261 | 2009-09-22 16:46:36 -0700 | [diff] [blame] | 75 | struct gpio_chip chip; |
Andy Shevchenko | 64c8cbc | 2013-05-22 13:20:11 +0300 | [diff] [blame] | 76 | void __iomem *reg_base; |
Alek Du | 8bf0261 | 2009-09-22 16:46:36 -0700 | [diff] [blame] | 77 | spinlock_t lock; |
Kristen Carlson Accardi | 7812803 | 2011-05-10 14:23:45 +0100 | [diff] [blame] | 78 | struct pci_dev *pdev; |
Alek Du | 8bf0261 | 2009-09-22 16:46:36 -0700 | [diff] [blame] | 79 | }; |
| 80 | |
Alek Du | 8081c84 | 2010-05-26 14:42:25 -0700 | [diff] [blame] | 81 | static void __iomem *gpio_reg(struct gpio_chip *chip, unsigned offset, |
Andy Shevchenko | 611a485 | 2013-05-22 13:20:14 +0300 | [diff] [blame] | 82 | enum GPIO_REG reg_type) |
Alek Du | 8bf0261 | 2009-09-22 16:46:36 -0700 | [diff] [blame] | 83 | { |
Linus Walleij | 5c77c02 | 2015-12-06 10:55:28 +0100 | [diff] [blame] | 84 | struct intel_mid_gpio *priv = gpiochip_get_data(chip); |
Alek Du | 8081c84 | 2010-05-26 14:42:25 -0700 | [diff] [blame] | 85 | unsigned nreg = chip->ngpio / 32; |
Alek Du | 8bf0261 | 2009-09-22 16:46:36 -0700 | [diff] [blame] | 86 | u8 reg = offset / 32; |
Alek Du | 8bf0261 | 2009-09-22 16:46:36 -0700 | [diff] [blame] | 87 | |
David Cohen | f89a768 | 2013-10-04 13:01:42 -0700 | [diff] [blame] | 88 | return priv->reg_base + reg_type * nreg * 4 + reg * 4; |
Alek Du | 8081c84 | 2010-05-26 14:42:25 -0700 | [diff] [blame] | 89 | } |
| 90 | |
Adrian Hunter | 8c0f7b1 | 2011-10-03 14:36:07 +0300 | [diff] [blame] | 91 | static void __iomem *gpio_reg_2bit(struct gpio_chip *chip, unsigned offset, |
| 92 | enum GPIO_REG reg_type) |
| 93 | { |
Linus Walleij | 5c77c02 | 2015-12-06 10:55:28 +0100 | [diff] [blame] | 94 | struct intel_mid_gpio *priv = gpiochip_get_data(chip); |
Adrian Hunter | 8c0f7b1 | 2011-10-03 14:36:07 +0300 | [diff] [blame] | 95 | unsigned nreg = chip->ngpio / 32; |
| 96 | u8 reg = offset / 16; |
Adrian Hunter | 8c0f7b1 | 2011-10-03 14:36:07 +0300 | [diff] [blame] | 97 | |
David Cohen | f89a768 | 2013-10-04 13:01:42 -0700 | [diff] [blame] | 98 | return priv->reg_base + reg_type * nreg * 4 + reg * 4; |
Adrian Hunter | 8c0f7b1 | 2011-10-03 14:36:07 +0300 | [diff] [blame] | 99 | } |
| 100 | |
David Cohen | f89a768 | 2013-10-04 13:01:42 -0700 | [diff] [blame] | 101 | static int intel_gpio_request(struct gpio_chip *chip, unsigned offset) |
Adrian Hunter | 8c0f7b1 | 2011-10-03 14:36:07 +0300 | [diff] [blame] | 102 | { |
| 103 | void __iomem *gafr = gpio_reg_2bit(chip, offset, GAFR); |
| 104 | u32 value = readl(gafr); |
| 105 | int shift = (offset % 16) << 1, af = (value >> shift) & 3; |
| 106 | |
| 107 | if (af) { |
| 108 | value &= ~(3 << shift); |
| 109 | writel(value, gafr); |
| 110 | } |
| 111 | return 0; |
| 112 | } |
| 113 | |
David Cohen | f89a768 | 2013-10-04 13:01:42 -0700 | [diff] [blame] | 114 | static int intel_gpio_get(struct gpio_chip *chip, unsigned offset) |
Alek Du | 8081c84 | 2010-05-26 14:42:25 -0700 | [diff] [blame] | 115 | { |
| 116 | void __iomem *gplr = gpio_reg(chip, offset, GPLR); |
| 117 | |
Linus Walleij | 4c628f3 | 2015-12-21 11:00:56 +0100 | [diff] [blame] | 118 | return !!(readl(gplr) & BIT(offset % 32)); |
Alek Du | 8bf0261 | 2009-09-22 16:46:36 -0700 | [diff] [blame] | 119 | } |
| 120 | |
David Cohen | f89a768 | 2013-10-04 13:01:42 -0700 | [diff] [blame] | 121 | static void intel_gpio_set(struct gpio_chip *chip, unsigned offset, int value) |
Alek Du | 8bf0261 | 2009-09-22 16:46:36 -0700 | [diff] [blame] | 122 | { |
Alek Du | 8bf0261 | 2009-09-22 16:46:36 -0700 | [diff] [blame] | 123 | void __iomem *gpsr, *gpcr; |
| 124 | |
| 125 | if (value) { |
Alek Du | 8081c84 | 2010-05-26 14:42:25 -0700 | [diff] [blame] | 126 | gpsr = gpio_reg(chip, offset, GPSR); |
Alek Du | 8bf0261 | 2009-09-22 16:46:36 -0700 | [diff] [blame] | 127 | writel(BIT(offset % 32), gpsr); |
| 128 | } else { |
Alek Du | 8081c84 | 2010-05-26 14:42:25 -0700 | [diff] [blame] | 129 | gpcr = gpio_reg(chip, offset, GPCR); |
Alek Du | 8bf0261 | 2009-09-22 16:46:36 -0700 | [diff] [blame] | 130 | writel(BIT(offset % 32), gpcr); |
| 131 | } |
| 132 | } |
| 133 | |
David Cohen | f89a768 | 2013-10-04 13:01:42 -0700 | [diff] [blame] | 134 | static int intel_gpio_direction_input(struct gpio_chip *chip, unsigned offset) |
Alek Du | 8bf0261 | 2009-09-22 16:46:36 -0700 | [diff] [blame] | 135 | { |
Linus Walleij | 5c77c02 | 2015-12-06 10:55:28 +0100 | [diff] [blame] | 136 | struct intel_mid_gpio *priv = gpiochip_get_data(chip); |
Alek Du | 8081c84 | 2010-05-26 14:42:25 -0700 | [diff] [blame] | 137 | void __iomem *gpdr = gpio_reg(chip, offset, GPDR); |
Alek Du | 8bf0261 | 2009-09-22 16:46:36 -0700 | [diff] [blame] | 138 | u32 value; |
| 139 | unsigned long flags; |
Alek Du | 8bf0261 | 2009-09-22 16:46:36 -0700 | [diff] [blame] | 140 | |
David Cohen | f89a768 | 2013-10-04 13:01:42 -0700 | [diff] [blame] | 141 | if (priv->pdev) |
| 142 | pm_runtime_get(&priv->pdev->dev); |
Kristen Carlson Accardi | 7812803 | 2011-05-10 14:23:45 +0100 | [diff] [blame] | 143 | |
David Cohen | f89a768 | 2013-10-04 13:01:42 -0700 | [diff] [blame] | 144 | spin_lock_irqsave(&priv->lock, flags); |
Alek Du | 8bf0261 | 2009-09-22 16:46:36 -0700 | [diff] [blame] | 145 | value = readl(gpdr); |
| 146 | value &= ~BIT(offset % 32); |
| 147 | writel(value, gpdr); |
David Cohen | f89a768 | 2013-10-04 13:01:42 -0700 | [diff] [blame] | 148 | spin_unlock_irqrestore(&priv->lock, flags); |
Kristen Carlson Accardi | 7812803 | 2011-05-10 14:23:45 +0100 | [diff] [blame] | 149 | |
David Cohen | f89a768 | 2013-10-04 13:01:42 -0700 | [diff] [blame] | 150 | if (priv->pdev) |
| 151 | pm_runtime_put(&priv->pdev->dev); |
Kristen Carlson Accardi | 7812803 | 2011-05-10 14:23:45 +0100 | [diff] [blame] | 152 | |
Alek Du | 8bf0261 | 2009-09-22 16:46:36 -0700 | [diff] [blame] | 153 | return 0; |
| 154 | } |
| 155 | |
David Cohen | f89a768 | 2013-10-04 13:01:42 -0700 | [diff] [blame] | 156 | static int intel_gpio_direction_output(struct gpio_chip *chip, |
Alek Du | 8bf0261 | 2009-09-22 16:46:36 -0700 | [diff] [blame] | 157 | unsigned offset, int value) |
| 158 | { |
Linus Walleij | 5c77c02 | 2015-12-06 10:55:28 +0100 | [diff] [blame] | 159 | struct intel_mid_gpio *priv = gpiochip_get_data(chip); |
Alek Du | 8081c84 | 2010-05-26 14:42:25 -0700 | [diff] [blame] | 160 | void __iomem *gpdr = gpio_reg(chip, offset, GPDR); |
Alek Du | 8bf0261 | 2009-09-22 16:46:36 -0700 | [diff] [blame] | 161 | unsigned long flags; |
Alek Du | 8bf0261 | 2009-09-22 16:46:36 -0700 | [diff] [blame] | 162 | |
David Cohen | f89a768 | 2013-10-04 13:01:42 -0700 | [diff] [blame] | 163 | intel_gpio_set(chip, offset, value); |
Kristen Carlson Accardi | 7812803 | 2011-05-10 14:23:45 +0100 | [diff] [blame] | 164 | |
David Cohen | f89a768 | 2013-10-04 13:01:42 -0700 | [diff] [blame] | 165 | if (priv->pdev) |
| 166 | pm_runtime_get(&priv->pdev->dev); |
Kristen Carlson Accardi | 7812803 | 2011-05-10 14:23:45 +0100 | [diff] [blame] | 167 | |
David Cohen | f89a768 | 2013-10-04 13:01:42 -0700 | [diff] [blame] | 168 | spin_lock_irqsave(&priv->lock, flags); |
Alek Du | 8bf0261 | 2009-09-22 16:46:36 -0700 | [diff] [blame] | 169 | value = readl(gpdr); |
Justin P. Mattock | 6eab04a | 2011-04-08 19:49:08 -0700 | [diff] [blame] | 170 | value |= BIT(offset % 32); |
Alek Du | 8bf0261 | 2009-09-22 16:46:36 -0700 | [diff] [blame] | 171 | writel(value, gpdr); |
David Cohen | f89a768 | 2013-10-04 13:01:42 -0700 | [diff] [blame] | 172 | spin_unlock_irqrestore(&priv->lock, flags); |
Kristen Carlson Accardi | 7812803 | 2011-05-10 14:23:45 +0100 | [diff] [blame] | 173 | |
David Cohen | f89a768 | 2013-10-04 13:01:42 -0700 | [diff] [blame] | 174 | if (priv->pdev) |
| 175 | pm_runtime_put(&priv->pdev->dev); |
Kristen Carlson Accardi | 7812803 | 2011-05-10 14:23:45 +0100 | [diff] [blame] | 176 | |
Alek Du | 8bf0261 | 2009-09-22 16:46:36 -0700 | [diff] [blame] | 177 | return 0; |
| 178 | } |
| 179 | |
David Cohen | f89a768 | 2013-10-04 13:01:42 -0700 | [diff] [blame] | 180 | static int intel_mid_irq_type(struct irq_data *d, unsigned type) |
Alek Du | 8bf0261 | 2009-09-22 16:46:36 -0700 | [diff] [blame] | 181 | { |
Linus Walleij | 3f7dbfd | 2014-05-29 16:55:55 +0200 | [diff] [blame] | 182 | struct gpio_chip *gc = irq_data_get_irq_chip_data(d); |
Linus Walleij | 5c77c02 | 2015-12-06 10:55:28 +0100 | [diff] [blame] | 183 | struct intel_mid_gpio *priv = gpiochip_get_data(gc); |
Mika Westerberg | 465f2bd | 2012-05-02 11:15:50 +0300 | [diff] [blame] | 184 | u32 gpio = irqd_to_hwirq(d); |
Alek Du | 8bf0261 | 2009-09-22 16:46:36 -0700 | [diff] [blame] | 185 | unsigned long flags; |
| 186 | u32 value; |
David Cohen | f89a768 | 2013-10-04 13:01:42 -0700 | [diff] [blame] | 187 | void __iomem *grer = gpio_reg(&priv->chip, gpio, GRER); |
| 188 | void __iomem *gfer = gpio_reg(&priv->chip, gpio, GFER); |
Alek Du | 8bf0261 | 2009-09-22 16:46:36 -0700 | [diff] [blame] | 189 | |
David Cohen | f89a768 | 2013-10-04 13:01:42 -0700 | [diff] [blame] | 190 | if (gpio >= priv->chip.ngpio) |
Alek Du | 8bf0261 | 2009-09-22 16:46:36 -0700 | [diff] [blame] | 191 | return -EINVAL; |
Kristen Carlson Accardi | 7812803 | 2011-05-10 14:23:45 +0100 | [diff] [blame] | 192 | |
David Cohen | f89a768 | 2013-10-04 13:01:42 -0700 | [diff] [blame] | 193 | if (priv->pdev) |
| 194 | pm_runtime_get(&priv->pdev->dev); |
Kristen Carlson Accardi | 7812803 | 2011-05-10 14:23:45 +0100 | [diff] [blame] | 195 | |
David Cohen | f89a768 | 2013-10-04 13:01:42 -0700 | [diff] [blame] | 196 | spin_lock_irqsave(&priv->lock, flags); |
Alek Du | 8bf0261 | 2009-09-22 16:46:36 -0700 | [diff] [blame] | 197 | if (type & IRQ_TYPE_EDGE_RISING) |
| 198 | value = readl(grer) | BIT(gpio % 32); |
| 199 | else |
| 200 | value = readl(grer) & (~BIT(gpio % 32)); |
| 201 | writel(value, grer); |
| 202 | |
| 203 | if (type & IRQ_TYPE_EDGE_FALLING) |
| 204 | value = readl(gfer) | BIT(gpio % 32); |
| 205 | else |
| 206 | value = readl(gfer) & (~BIT(gpio % 32)); |
| 207 | writel(value, gfer); |
David Cohen | f89a768 | 2013-10-04 13:01:42 -0700 | [diff] [blame] | 208 | spin_unlock_irqrestore(&priv->lock, flags); |
Alek Du | 8bf0261 | 2009-09-22 16:46:36 -0700 | [diff] [blame] | 209 | |
David Cohen | f89a768 | 2013-10-04 13:01:42 -0700 | [diff] [blame] | 210 | if (priv->pdev) |
| 211 | pm_runtime_put(&priv->pdev->dev); |
Kristen Carlson Accardi | 7812803 | 2011-05-10 14:23:45 +0100 | [diff] [blame] | 212 | |
Alek Du | 8bf0261 | 2009-09-22 16:46:36 -0700 | [diff] [blame] | 213 | return 0; |
Andrew Morton | fd0574c | 2010-10-27 15:33:22 -0700 | [diff] [blame] | 214 | } |
Alek Du | 8bf0261 | 2009-09-22 16:46:36 -0700 | [diff] [blame] | 215 | |
David Cohen | f89a768 | 2013-10-04 13:01:42 -0700 | [diff] [blame] | 216 | static void intel_mid_irq_unmask(struct irq_data *d) |
Alek Du | 8bf0261 | 2009-09-22 16:46:36 -0700 | [diff] [blame] | 217 | { |
Andrew Morton | fd0574c | 2010-10-27 15:33:22 -0700 | [diff] [blame] | 218 | } |
Alek Du | 8bf0261 | 2009-09-22 16:46:36 -0700 | [diff] [blame] | 219 | |
David Cohen | f89a768 | 2013-10-04 13:01:42 -0700 | [diff] [blame] | 220 | static void intel_mid_irq_mask(struct irq_data *d) |
Alek Du | 8bf0261 | 2009-09-22 16:46:36 -0700 | [diff] [blame] | 221 | { |
Andrew Morton | fd0574c | 2010-10-27 15:33:22 -0700 | [diff] [blame] | 222 | } |
Alek Du | 8bf0261 | 2009-09-22 16:46:36 -0700 | [diff] [blame] | 223 | |
David Cohen | f89a768 | 2013-10-04 13:01:42 -0700 | [diff] [blame] | 224 | static struct irq_chip intel_mid_irqchip = { |
| 225 | .name = "INTEL_MID-GPIO", |
| 226 | .irq_mask = intel_mid_irq_mask, |
| 227 | .irq_unmask = intel_mid_irq_unmask, |
| 228 | .irq_set_type = intel_mid_irq_type, |
Alek Du | 8bf0261 | 2009-09-22 16:46:36 -0700 | [diff] [blame] | 229 | }; |
| 230 | |
David Cohen | f89a768 | 2013-10-04 13:01:42 -0700 | [diff] [blame] | 231 | static const struct intel_mid_gpio_ddata gpio_lincroft = { |
David Cohen | d56d6b3 | 2013-10-04 13:01:40 -0700 | [diff] [blame] | 232 | .ngpio = 64, |
| 233 | }; |
| 234 | |
David Cohen | f89a768 | 2013-10-04 13:01:42 -0700 | [diff] [blame] | 235 | static const struct intel_mid_gpio_ddata gpio_penwell_aon = { |
David Cohen | d56d6b3 | 2013-10-04 13:01:40 -0700 | [diff] [blame] | 236 | .ngpio = 96, |
David Cohen | f89a768 | 2013-10-04 13:01:42 -0700 | [diff] [blame] | 237 | .chip_irq_type = INTEL_MID_IRQ_TYPE_EDGE, |
David Cohen | d56d6b3 | 2013-10-04 13:01:40 -0700 | [diff] [blame] | 238 | }; |
| 239 | |
David Cohen | f89a768 | 2013-10-04 13:01:42 -0700 | [diff] [blame] | 240 | static const struct intel_mid_gpio_ddata gpio_penwell_core = { |
David Cohen | d56d6b3 | 2013-10-04 13:01:40 -0700 | [diff] [blame] | 241 | .ngpio = 96, |
David Cohen | f89a768 | 2013-10-04 13:01:42 -0700 | [diff] [blame] | 242 | .chip_irq_type = INTEL_MID_IRQ_TYPE_EDGE, |
David Cohen | d56d6b3 | 2013-10-04 13:01:40 -0700 | [diff] [blame] | 243 | }; |
| 244 | |
David Cohen | f89a768 | 2013-10-04 13:01:42 -0700 | [diff] [blame] | 245 | static const struct intel_mid_gpio_ddata gpio_cloverview_aon = { |
David Cohen | d56d6b3 | 2013-10-04 13:01:40 -0700 | [diff] [blame] | 246 | .ngpio = 96, |
David Cohen | f89a768 | 2013-10-04 13:01:42 -0700 | [diff] [blame] | 247 | .chip_irq_type = INTEL_MID_IRQ_TYPE_EDGE | INTEL_MID_IRQ_TYPE_LEVEL, |
David Cohen | d56d6b3 | 2013-10-04 13:01:40 -0700 | [diff] [blame] | 248 | }; |
| 249 | |
David Cohen | f89a768 | 2013-10-04 13:01:42 -0700 | [diff] [blame] | 250 | static const struct intel_mid_gpio_ddata gpio_cloverview_core = { |
David Cohen | d56d6b3 | 2013-10-04 13:01:40 -0700 | [diff] [blame] | 251 | .ngpio = 96, |
David Cohen | f89a768 | 2013-10-04 13:01:42 -0700 | [diff] [blame] | 252 | .chip_irq_type = INTEL_MID_IRQ_TYPE_EDGE, |
David Cohen | d56d6b3 | 2013-10-04 13:01:40 -0700 | [diff] [blame] | 253 | }; |
| 254 | |
David Cohen | f89a768 | 2013-10-04 13:01:42 -0700 | [diff] [blame] | 255 | static const struct intel_mid_gpio_ddata gpio_tangier = { |
David Cohen | d56d6b3 | 2013-10-04 13:01:40 -0700 | [diff] [blame] | 256 | .ngpio = 192, |
| 257 | .gplr_offset = 4, |
| 258 | .flis_base = 0xff0c0000, |
| 259 | .flis_len = 0x8000, |
| 260 | .get_flis_offset = NULL, |
David Cohen | f89a768 | 2013-10-04 13:01:42 -0700 | [diff] [blame] | 261 | .chip_irq_type = INTEL_MID_IRQ_TYPE_EDGE, |
David Cohen | d56d6b3 | 2013-10-04 13:01:40 -0700 | [diff] [blame] | 262 | }; |
| 263 | |
Jingoo Han | 14f4a88 | 2013-12-03 08:08:45 +0900 | [diff] [blame] | 264 | static const struct pci_device_id intel_gpio_ids[] = { |
David Cohen | d56d6b3 | 2013-10-04 13:01:40 -0700 | [diff] [blame] | 265 | { |
| 266 | /* Lincroft */ |
| 267 | PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x080f), |
| 268 | .driver_data = (kernel_ulong_t)&gpio_lincroft, |
| 269 | }, |
| 270 | { |
| 271 | /* Penwell AON */ |
| 272 | PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x081f), |
| 273 | .driver_data = (kernel_ulong_t)&gpio_penwell_aon, |
| 274 | }, |
| 275 | { |
| 276 | /* Penwell Core */ |
| 277 | PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x081a), |
| 278 | .driver_data = (kernel_ulong_t)&gpio_penwell_core, |
| 279 | }, |
| 280 | { |
| 281 | /* Cloverview Aon */ |
| 282 | PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x08eb), |
| 283 | .driver_data = (kernel_ulong_t)&gpio_cloverview_aon, |
| 284 | }, |
| 285 | { |
| 286 | /* Cloverview Core */ |
| 287 | PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x08f7), |
| 288 | .driver_data = (kernel_ulong_t)&gpio_cloverview_core, |
| 289 | }, |
| 290 | { |
| 291 | /* Tangier */ |
| 292 | PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x1199), |
| 293 | .driver_data = (kernel_ulong_t)&gpio_tangier, |
| 294 | }, |
| 295 | { 0 } |
Alek Du | 8bf0261 | 2009-09-22 16:46:36 -0700 | [diff] [blame] | 296 | }; |
David Cohen | f89a768 | 2013-10-04 13:01:42 -0700 | [diff] [blame] | 297 | MODULE_DEVICE_TABLE(pci, intel_gpio_ids); |
Alek Du | 8bf0261 | 2009-09-22 16:46:36 -0700 | [diff] [blame] | 298 | |
Thomas Gleixner | bd0b9ac | 2015-09-14 10:42:37 +0200 | [diff] [blame] | 299 | static void intel_mid_irq_handler(struct irq_desc *desc) |
Alek Du | 8bf0261 | 2009-09-22 16:46:36 -0700 | [diff] [blame] | 300 | { |
Linus Walleij | 3f7dbfd | 2014-05-29 16:55:55 +0200 | [diff] [blame] | 301 | struct gpio_chip *gc = irq_desc_get_handler_data(desc); |
Linus Walleij | 5c77c02 | 2015-12-06 10:55:28 +0100 | [diff] [blame] | 302 | struct intel_mid_gpio *priv = gpiochip_get_data(gc); |
Thomas Gleixner | 20e2aa9 | 2011-03-17 19:32:49 +0000 | [diff] [blame] | 303 | struct irq_data *data = irq_desc_get_irq_data(desc); |
Thomas Gleixner | 20e2aa9 | 2011-03-17 19:32:49 +0000 | [diff] [blame] | 304 | struct irq_chip *chip = irq_data_get_irq_chip(data); |
Thomas Gleixner | 84bead6 | 2011-03-17 19:32:58 +0000 | [diff] [blame] | 305 | u32 base, gpio, mask; |
Thomas Gleixner | 732063b | 2011-03-17 19:32:55 +0000 | [diff] [blame] | 306 | unsigned long pending; |
Alek Du | 8bf0261 | 2009-09-22 16:46:36 -0700 | [diff] [blame] | 307 | void __iomem *gedr; |
Alek Du | 8bf0261 | 2009-09-22 16:46:36 -0700 | [diff] [blame] | 308 | |
| 309 | /* check GPIO controller to check which pin triggered the interrupt */ |
David Cohen | f89a768 | 2013-10-04 13:01:42 -0700 | [diff] [blame] | 310 | for (base = 0; base < priv->chip.ngpio; base += 32) { |
| 311 | gedr = gpio_reg(&priv->chip, base, GEDR); |
Mika Westerberg | c8f925b | 2012-05-10 13:01:22 +0300 | [diff] [blame] | 312 | while ((pending = readl(gedr))) { |
Mathias Nyman | 2345b20 | 2011-07-08 10:02:18 +0100 | [diff] [blame] | 313 | gpio = __ffs(pending); |
Thomas Gleixner | 84bead6 | 2011-03-17 19:32:58 +0000 | [diff] [blame] | 314 | mask = BIT(gpio); |
Thomas Gleixner | 84bead6 | 2011-03-17 19:32:58 +0000 | [diff] [blame] | 315 | /* Clear before handling so we can't lose an edge */ |
| 316 | writel(mask, gedr); |
Linus Walleij | 3f7dbfd | 2014-05-29 16:55:55 +0200 | [diff] [blame] | 317 | generic_handle_irq(irq_find_mapping(gc->irqdomain, |
Mika Westerberg | 465f2bd | 2012-05-02 11:15:50 +0300 | [diff] [blame] | 318 | base + gpio)); |
Thomas Gleixner | 732063b | 2011-03-17 19:32:55 +0000 | [diff] [blame] | 319 | } |
Alek Du | 8bf0261 | 2009-09-22 16:46:36 -0700 | [diff] [blame] | 320 | } |
Feng Tang | 0766d20 | 2011-01-25 15:07:15 -0800 | [diff] [blame] | 321 | |
Thomas Gleixner | 20e2aa9 | 2011-03-17 19:32:49 +0000 | [diff] [blame] | 322 | chip->irq_eoi(data); |
Alek Du | 8bf0261 | 2009-09-22 16:46:36 -0700 | [diff] [blame] | 323 | } |
| 324 | |
David Cohen | f89a768 | 2013-10-04 13:01:42 -0700 | [diff] [blame] | 325 | static void intel_mid_irq_init_hw(struct intel_mid_gpio *priv) |
Mika Westerberg | f5f9311 | 2012-04-05 12:15:17 +0300 | [diff] [blame] | 326 | { |
| 327 | void __iomem *reg; |
| 328 | unsigned base; |
| 329 | |
David Cohen | f89a768 | 2013-10-04 13:01:42 -0700 | [diff] [blame] | 330 | for (base = 0; base < priv->chip.ngpio; base += 32) { |
Mika Westerberg | f5f9311 | 2012-04-05 12:15:17 +0300 | [diff] [blame] | 331 | /* Clear the rising-edge detect register */ |
David Cohen | f89a768 | 2013-10-04 13:01:42 -0700 | [diff] [blame] | 332 | reg = gpio_reg(&priv->chip, base, GRER); |
Mika Westerberg | f5f9311 | 2012-04-05 12:15:17 +0300 | [diff] [blame] | 333 | writel(0, reg); |
| 334 | /* Clear the falling-edge detect register */ |
David Cohen | f89a768 | 2013-10-04 13:01:42 -0700 | [diff] [blame] | 335 | reg = gpio_reg(&priv->chip, base, GFER); |
Mika Westerberg | f5f9311 | 2012-04-05 12:15:17 +0300 | [diff] [blame] | 336 | writel(0, reg); |
| 337 | /* Clear the edge detect status register */ |
David Cohen | f89a768 | 2013-10-04 13:01:42 -0700 | [diff] [blame] | 338 | reg = gpio_reg(&priv->chip, base, GEDR); |
Mika Westerberg | f5f9311 | 2012-04-05 12:15:17 +0300 | [diff] [blame] | 339 | writel(~0, reg); |
| 340 | } |
| 341 | } |
| 342 | |
David Cohen | f89a768 | 2013-10-04 13:01:42 -0700 | [diff] [blame] | 343 | static int intel_gpio_runtime_idle(struct device *dev) |
Kristen Carlson Accardi | 7812803 | 2011-05-10 14:23:45 +0100 | [diff] [blame] | 344 | { |
xinhui.pan | 84a3457 | 2014-01-31 13:08:01 -0800 | [diff] [blame] | 345 | int err = pm_schedule_suspend(dev, 500); |
| 346 | return err ?: -EBUSY; |
Kristen Carlson Accardi | 7812803 | 2011-05-10 14:23:45 +0100 | [diff] [blame] | 347 | } |
| 348 | |
David Cohen | f89a768 | 2013-10-04 13:01:42 -0700 | [diff] [blame] | 349 | static const struct dev_pm_ops intel_gpio_pm_ops = { |
| 350 | SET_RUNTIME_PM_OPS(NULL, NULL, intel_gpio_runtime_idle) |
Kristen Carlson Accardi | 7812803 | 2011-05-10 14:23:45 +0100 | [diff] [blame] | 351 | }; |
| 352 | |
David Cohen | f89a768 | 2013-10-04 13:01:42 -0700 | [diff] [blame] | 353 | static int intel_gpio_probe(struct pci_dev *pdev, |
Andy Shevchenko | 64c8cbc | 2013-05-22 13:20:11 +0300 | [diff] [blame] | 354 | const struct pci_device_id *id) |
Alek Du | 8bf0261 | 2009-09-22 16:46:36 -0700 | [diff] [blame] | 355 | { |
Andy Shevchenko | 64c8cbc | 2013-05-22 13:20:11 +0300 | [diff] [blame] | 356 | void __iomem *base; |
David Cohen | f89a768 | 2013-10-04 13:01:42 -0700 | [diff] [blame] | 357 | struct intel_mid_gpio *priv; |
Alek Du | 8bf0261 | 2009-09-22 16:46:36 -0700 | [diff] [blame] | 358 | u32 gpio_base; |
David Cohen | 2519f9a | 2013-05-06 16:11:03 -0700 | [diff] [blame] | 359 | u32 irq_base; |
Julia Lawall | d6a2b7b | 2012-08-05 11:52:34 +0200 | [diff] [blame] | 360 | int retval; |
David Cohen | f89a768 | 2013-10-04 13:01:42 -0700 | [diff] [blame] | 361 | struct intel_mid_gpio_ddata *ddata = |
| 362 | (struct intel_mid_gpio_ddata *)id->driver_data; |
Alek Du | 8bf0261 | 2009-09-22 16:46:36 -0700 | [diff] [blame] | 363 | |
Andy Shevchenko | 786e07e | 2013-05-22 13:20:12 +0300 | [diff] [blame] | 364 | retval = pcim_enable_device(pdev); |
Alek Du | 8bf0261 | 2009-09-22 16:46:36 -0700 | [diff] [blame] | 365 | if (retval) |
Mika Westerberg | 8302c74 | 2012-04-05 12:15:15 +0300 | [diff] [blame] | 366 | return retval; |
Alek Du | 8bf0261 | 2009-09-22 16:46:36 -0700 | [diff] [blame] | 367 | |
Andy Shevchenko | 786e07e | 2013-05-22 13:20:12 +0300 | [diff] [blame] | 368 | retval = pcim_iomap_regions(pdev, 1 << 0 | 1 << 1, pci_name(pdev)); |
Alek Du | 8bf0261 | 2009-09-22 16:46:36 -0700 | [diff] [blame] | 369 | if (retval) { |
Andy Shevchenko | 786e07e | 2013-05-22 13:20:12 +0300 | [diff] [blame] | 370 | dev_err(&pdev->dev, "I/O memory mapping error\n"); |
| 371 | return retval; |
Alek Du | 8bf0261 | 2009-09-22 16:46:36 -0700 | [diff] [blame] | 372 | } |
Andy Shevchenko | 786e07e | 2013-05-22 13:20:12 +0300 | [diff] [blame] | 373 | |
| 374 | base = pcim_iomap_table(pdev)[1]; |
Andy Shevchenko | 64c8cbc | 2013-05-22 13:20:11 +0300 | [diff] [blame] | 375 | |
| 376 | irq_base = readl(base); |
| 377 | gpio_base = readl(sizeof(u32) + base); |
| 378 | |
Alek Du | 8bf0261 | 2009-09-22 16:46:36 -0700 | [diff] [blame] | 379 | /* release the IO mapping, since we already get the info from bar1 */ |
Andy Shevchenko | 786e07e | 2013-05-22 13:20:12 +0300 | [diff] [blame] | 380 | pcim_iounmap_regions(pdev, 1 << 1); |
Alek Du | 8bf0261 | 2009-09-22 16:46:36 -0700 | [diff] [blame] | 381 | |
David Cohen | f89a768 | 2013-10-04 13:01:42 -0700 | [diff] [blame] | 382 | priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); |
| 383 | if (!priv) { |
Andy Shevchenko | 8aca119 | 2013-05-22 13:20:13 +0300 | [diff] [blame] | 384 | dev_err(&pdev->dev, "can't allocate chip data\n"); |
Andy Shevchenko | 786e07e | 2013-05-22 13:20:12 +0300 | [diff] [blame] | 385 | return -ENOMEM; |
Alek Du | 8bf0261 | 2009-09-22 16:46:36 -0700 | [diff] [blame] | 386 | } |
Mika Westerberg | b3e35af | 2012-04-05 12:15:16 +0300 | [diff] [blame] | 387 | |
David Cohen | f89a768 | 2013-10-04 13:01:42 -0700 | [diff] [blame] | 388 | priv->reg_base = pcim_iomap_table(pdev)[0]; |
| 389 | priv->chip.label = dev_name(&pdev->dev); |
Linus Walleij | 58383c78 | 2015-11-04 09:56:26 +0100 | [diff] [blame] | 390 | priv->chip.parent = &pdev->dev; |
David Cohen | f89a768 | 2013-10-04 13:01:42 -0700 | [diff] [blame] | 391 | priv->chip.request = intel_gpio_request; |
| 392 | priv->chip.direction_input = intel_gpio_direction_input; |
| 393 | priv->chip.direction_output = intel_gpio_direction_output; |
| 394 | priv->chip.get = intel_gpio_get; |
| 395 | priv->chip.set = intel_gpio_set; |
David Cohen | f89a768 | 2013-10-04 13:01:42 -0700 | [diff] [blame] | 396 | priv->chip.base = gpio_base; |
| 397 | priv->chip.ngpio = ddata->ngpio; |
Linus Walleij | 9fb1f39 | 2013-12-04 14:42:46 +0100 | [diff] [blame] | 398 | priv->chip.can_sleep = false; |
David Cohen | f89a768 | 2013-10-04 13:01:42 -0700 | [diff] [blame] | 399 | priv->pdev = pdev; |
David Cohen | 2519f9a | 2013-05-06 16:11:03 -0700 | [diff] [blame] | 400 | |
David Cohen | f89a768 | 2013-10-04 13:01:42 -0700 | [diff] [blame] | 401 | spin_lock_init(&priv->lock); |
Andy Shevchenko | aeb168f | 2013-05-22 13:20:10 +0300 | [diff] [blame] | 402 | |
David Cohen | f89a768 | 2013-10-04 13:01:42 -0700 | [diff] [blame] | 403 | pci_set_drvdata(pdev, priv); |
Linus Walleij | 5c77c02 | 2015-12-06 10:55:28 +0100 | [diff] [blame] | 404 | retval = gpiochip_add_data(&priv->chip, priv); |
Alek Du | 8bf0261 | 2009-09-22 16:46:36 -0700 | [diff] [blame] | 405 | if (retval) { |
Andy Shevchenko | 8aca119 | 2013-05-22 13:20:13 +0300 | [diff] [blame] | 406 | dev_err(&pdev->dev, "gpiochip_add error %d\n", retval); |
Andy Shevchenko | 786e07e | 2013-05-22 13:20:12 +0300 | [diff] [blame] | 407 | return retval; |
Alek Du | 8bf0261 | 2009-09-22 16:46:36 -0700 | [diff] [blame] | 408 | } |
Mika Westerberg | f5f9311 | 2012-04-05 12:15:17 +0300 | [diff] [blame] | 409 | |
Linus Walleij | 3f7dbfd | 2014-05-29 16:55:55 +0200 | [diff] [blame] | 410 | retval = gpiochip_irqchip_add(&priv->chip, |
| 411 | &intel_mid_irqchip, |
| 412 | irq_base, |
| 413 | handle_simple_irq, |
| 414 | IRQ_TYPE_NONE); |
| 415 | if (retval) { |
| 416 | dev_err(&pdev->dev, |
| 417 | "could not connect irqchip to gpiochip\n"); |
| 418 | return retval; |
| 419 | } |
| 420 | |
David Cohen | f89a768 | 2013-10-04 13:01:42 -0700 | [diff] [blame] | 421 | intel_mid_irq_init_hw(priv); |
Mika Westerberg | f5f9311 | 2012-04-05 12:15:17 +0300 | [diff] [blame] | 422 | |
Linus Walleij | 3f7dbfd | 2014-05-29 16:55:55 +0200 | [diff] [blame] | 423 | gpiochip_set_chained_irqchip(&priv->chip, |
| 424 | &intel_mid_irqchip, |
| 425 | pdev->irq, |
| 426 | intel_mid_irq_handler); |
Alek Du | 8bf0261 | 2009-09-22 16:46:36 -0700 | [diff] [blame] | 427 | |
Kristen Carlson Accardi | 7812803 | 2011-05-10 14:23:45 +0100 | [diff] [blame] | 428 | pm_runtime_put_noidle(&pdev->dev); |
| 429 | pm_runtime_allow(&pdev->dev); |
| 430 | |
Mika Westerberg | 8302c74 | 2012-04-05 12:15:15 +0300 | [diff] [blame] | 431 | return 0; |
Alek Du | 8bf0261 | 2009-09-22 16:46:36 -0700 | [diff] [blame] | 432 | } |
| 433 | |
David Cohen | f89a768 | 2013-10-04 13:01:42 -0700 | [diff] [blame] | 434 | static struct pci_driver intel_gpio_driver = { |
| 435 | .name = "intel_mid_gpio", |
| 436 | .id_table = intel_gpio_ids, |
| 437 | .probe = intel_gpio_probe, |
Kristen Carlson Accardi | 7812803 | 2011-05-10 14:23:45 +0100 | [diff] [blame] | 438 | .driver = { |
David Cohen | f89a768 | 2013-10-04 13:01:42 -0700 | [diff] [blame] | 439 | .pm = &intel_gpio_pm_ops, |
Kristen Carlson Accardi | 7812803 | 2011-05-10 14:23:45 +0100 | [diff] [blame] | 440 | }, |
Alek Du | 8bf0261 | 2009-09-22 16:46:36 -0700 | [diff] [blame] | 441 | }; |
| 442 | |
David Cohen | f89a768 | 2013-10-04 13:01:42 -0700 | [diff] [blame] | 443 | static int __init intel_gpio_init(void) |
Alek Du | 8bf0261 | 2009-09-22 16:46:36 -0700 | [diff] [blame] | 444 | { |
David Cohen | f89a768 | 2013-10-04 13:01:42 -0700 | [diff] [blame] | 445 | return pci_register_driver(&intel_gpio_driver); |
Alek Du | 8bf0261 | 2009-09-22 16:46:36 -0700 | [diff] [blame] | 446 | } |
| 447 | |
David Cohen | f89a768 | 2013-10-04 13:01:42 -0700 | [diff] [blame] | 448 | device_initcall(intel_gpio_init); |