Bill Richardson | eece432 | 2012-10-20 11:44:34 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2012 The Chromium OS Authors. |
Wolfgang Denk | d79de1d | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 3 | * SPDX-License-Identifier: GPL-2.0+ |
Bill Richardson | eece432 | 2012-10-20 11:44:34 +0000 | [diff] [blame] | 4 | */ |
| 5 | |
| 6 | /* |
| 7 | * This is a GPIO driver for Intel ICH6 and later. The x86 GPIOs are accessed |
| 8 | * through the PCI bus. Each PCI device has 256 bytes of configuration space, |
| 9 | * consisting of a standard header and a device-specific set of registers. PCI |
| 10 | * bus 0, device 31, function 0 gives us access to the chipset GPIOs (among |
| 11 | * other things). Within the PCI configuration space, the GPIOBASE register |
| 12 | * tells us where in the device's I/O region we can find more registers to |
| 13 | * actually access the GPIOs. |
| 14 | * |
| 15 | * PCI bus/device/function 0:1f:0 => PCI config registers |
| 16 | * PCI config register "GPIOBASE" |
| 17 | * PCI I/O space + [GPIOBASE] => start of GPIO registers |
| 18 | * GPIO registers => gpio pin function, direction, value |
Bill Richardson | 50a5ebe | 2012-10-20 11:44:36 +0000 | [diff] [blame] | 19 | * |
| 20 | * |
| 21 | * Danger Will Robinson! Bank 0 (GPIOs 0-31) seems to be fairly stable. Most |
| 22 | * ICH versions have more, but the decoding the matrix that describes them is |
| 23 | * absurdly complex and constantly changing. We'll provide Bank 1 and Bank 2, |
| 24 | * but they will ONLY work for certain unspecified chipsets because the offset |
| 25 | * from GPIOBASE changes randomly. Even then, many GPIOs are unimplemented or |
| 26 | * reserved or subject to arcane restrictions. |
Bill Richardson | eece432 | 2012-10-20 11:44:34 +0000 | [diff] [blame] | 27 | */ |
| 28 | |
| 29 | #include <common.h> |
Simon Glass | 2b4071b | 2014-10-10 07:49:18 -0600 | [diff] [blame] | 30 | #include <dm.h> |
| 31 | #include <errno.h> |
| 32 | #include <fdtdec.h> |
Bill Richardson | eece432 | 2012-10-20 11:44:34 +0000 | [diff] [blame] | 33 | #include <pci.h> |
| 34 | #include <asm/gpio.h> |
| 35 | #include <asm/io.h> |
Simon Glass | 60af017 | 2014-11-12 22:42:24 -0700 | [diff] [blame] | 36 | #include <asm/pci.h> |
| 37 | #ifdef CONFIG_X86_RESET_VECTOR |
| 38 | #include <asm/arch/pch.h> |
| 39 | #define SUPPORT_GPIO_SETUP |
| 40 | #endif |
Bill Richardson | eece432 | 2012-10-20 11:44:34 +0000 | [diff] [blame] | 41 | |
Simon Glass | 2b4071b | 2014-10-10 07:49:18 -0600 | [diff] [blame] | 42 | #define GPIO_PER_BANK 32 |
| 43 | |
Bill Richardson | eece432 | 2012-10-20 11:44:34 +0000 | [diff] [blame] | 44 | /* Where in config space is the register that points to the GPIO registers? */ |
| 45 | #define PCI_CFG_GPIOBASE 0x48 |
| 46 | |
Simon Glass | 2b4071b | 2014-10-10 07:49:18 -0600 | [diff] [blame] | 47 | struct ich6_bank_priv { |
| 48 | /* These are I/O addresses */ |
| 49 | uint32_t use_sel; |
| 50 | uint32_t io_sel; |
| 51 | uint32_t lvl; |
Bill Richardson | 50a5ebe | 2012-10-20 11:44:36 +0000 | [diff] [blame] | 52 | }; |
| 53 | |
Simon Glass | 60af017 | 2014-11-12 22:42:24 -0700 | [diff] [blame] | 54 | #ifdef SUPPORT_GPIO_SETUP |
| 55 | static void setup_pch_gpios(const struct pch_gpio_map *gpio) |
| 56 | { |
| 57 | u16 gpiobase = pci_read_config16(PCH_LPC_DEV, GPIO_BASE) & 0xfffc; |
| 58 | |
| 59 | /* GPIO Set 1 */ |
| 60 | if (gpio->set1.level) |
| 61 | outl(*((u32 *)gpio->set1.level), gpiobase + GP_LVL); |
| 62 | if (gpio->set1.mode) |
| 63 | outl(*((u32 *)gpio->set1.mode), gpiobase + GPIO_USE_SEL); |
| 64 | if (gpio->set1.direction) |
| 65 | outl(*((u32 *)gpio->set1.direction), gpiobase + GP_IO_SEL); |
| 66 | if (gpio->set1.reset) |
| 67 | outl(*((u32 *)gpio->set1.reset), gpiobase + GP_RST_SEL1); |
| 68 | if (gpio->set1.invert) |
| 69 | outl(*((u32 *)gpio->set1.invert), gpiobase + GPI_INV); |
| 70 | if (gpio->set1.blink) |
| 71 | outl(*((u32 *)gpio->set1.blink), gpiobase + GPO_BLINK); |
| 72 | |
| 73 | /* GPIO Set 2 */ |
| 74 | if (gpio->set2.level) |
| 75 | outl(*((u32 *)gpio->set2.level), gpiobase + GP_LVL2); |
| 76 | if (gpio->set2.mode) |
| 77 | outl(*((u32 *)gpio->set2.mode), gpiobase + GPIO_USE_SEL2); |
| 78 | if (gpio->set2.direction) |
| 79 | outl(*((u32 *)gpio->set2.direction), gpiobase + GP_IO_SEL2); |
| 80 | if (gpio->set2.reset) |
| 81 | outl(*((u32 *)gpio->set2.reset), gpiobase + GP_RST_SEL2); |
| 82 | |
| 83 | /* GPIO Set 3 */ |
| 84 | if (gpio->set3.level) |
| 85 | outl(*((u32 *)gpio->set3.level), gpiobase + GP_LVL3); |
| 86 | if (gpio->set3.mode) |
| 87 | outl(*((u32 *)gpio->set3.mode), gpiobase + GPIO_USE_SEL3); |
| 88 | if (gpio->set3.direction) |
| 89 | outl(*((u32 *)gpio->set3.direction), gpiobase + GP_IO_SEL3); |
| 90 | if (gpio->set3.reset) |
| 91 | outl(*((u32 *)gpio->set3.reset), gpiobase + GP_RST_SEL3); |
| 92 | } |
| 93 | |
| 94 | /* TODO: Move this to device tree, or platform data */ |
| 95 | void ich_gpio_set_gpio_map(const struct pch_gpio_map *map) |
| 96 | { |
| 97 | gd->arch.gpio_map = map; |
| 98 | } |
| 99 | #endif /* SUPPORT_GPIO_SETUP */ |
| 100 | |
Simon Glass | 2b4071b | 2014-10-10 07:49:18 -0600 | [diff] [blame] | 101 | static int gpio_ich6_ofdata_to_platdata(struct udevice *dev) |
Bill Richardson | 50a5ebe | 2012-10-20 11:44:36 +0000 | [diff] [blame] | 102 | { |
Simon Glass | 2b4071b | 2014-10-10 07:49:18 -0600 | [diff] [blame] | 103 | struct ich6_bank_platdata *plat = dev_get_platdata(dev); |
| 104 | pci_dev_t pci_dev; /* handle for 0:1f:0 */ |
Bill Richardson | eece432 | 2012-10-20 11:44:34 +0000 | [diff] [blame] | 105 | u8 tmpbyte; |
| 106 | u16 tmpword; |
| 107 | u32 tmplong; |
Simon Glass | 2b4071b | 2014-10-10 07:49:18 -0600 | [diff] [blame] | 108 | u32 gpiobase; |
| 109 | int offset; |
Bill Richardson | eece432 | 2012-10-20 11:44:34 +0000 | [diff] [blame] | 110 | |
| 111 | /* Where should it be? */ |
Simon Glass | 2b4071b | 2014-10-10 07:49:18 -0600 | [diff] [blame] | 112 | pci_dev = PCI_BDF(0, 0x1f, 0); |
Bill Richardson | eece432 | 2012-10-20 11:44:34 +0000 | [diff] [blame] | 113 | |
| 114 | /* Is the device present? */ |
Simon Glass | 60af017 | 2014-11-12 22:42:24 -0700 | [diff] [blame] | 115 | tmpword = pci_read_config16(pci_dev, PCI_VENDOR_ID); |
Bill Richardson | eece432 | 2012-10-20 11:44:34 +0000 | [diff] [blame] | 116 | if (tmpword != PCI_VENDOR_ID_INTEL) { |
| 117 | debug("%s: wrong VendorID\n", __func__); |
Simon Glass | 2b4071b | 2014-10-10 07:49:18 -0600 | [diff] [blame] | 118 | return -ENODEV; |
Bill Richardson | eece432 | 2012-10-20 11:44:34 +0000 | [diff] [blame] | 119 | } |
Bill Richardson | 50a5ebe | 2012-10-20 11:44:36 +0000 | [diff] [blame] | 120 | |
Simon Glass | 60af017 | 2014-11-12 22:42:24 -0700 | [diff] [blame] | 121 | tmpword = pci_read_config16(pci_dev, PCI_DEVICE_ID); |
Bill Richardson | 50a5ebe | 2012-10-20 11:44:36 +0000 | [diff] [blame] | 122 | debug("Found %04x:%04x\n", PCI_VENDOR_ID_INTEL, tmpword); |
Bill Richardson | eece432 | 2012-10-20 11:44:34 +0000 | [diff] [blame] | 123 | /* |
Bill Richardson | 50a5ebe | 2012-10-20 11:44:36 +0000 | [diff] [blame] | 124 | * We'd like to validate the Device ID too, but pretty much any |
Bill Richardson | eece432 | 2012-10-20 11:44:34 +0000 | [diff] [blame] | 125 | * value is either a) correct with slight differences, or b) |
Bill Richardson | 50a5ebe | 2012-10-20 11:44:36 +0000 | [diff] [blame] | 126 | * correct but undocumented. We'll have to check a bunch of other |
| 127 | * things instead... |
Bill Richardson | eece432 | 2012-10-20 11:44:34 +0000 | [diff] [blame] | 128 | */ |
| 129 | |
| 130 | /* I/O should already be enabled (it's a RO bit). */ |
Simon Glass | 60af017 | 2014-11-12 22:42:24 -0700 | [diff] [blame] | 131 | tmpword = pci_read_config16(pci_dev, PCI_COMMAND); |
Bill Richardson | eece432 | 2012-10-20 11:44:34 +0000 | [diff] [blame] | 132 | if (!(tmpword & PCI_COMMAND_IO)) { |
| 133 | debug("%s: device IO not enabled\n", __func__); |
Simon Glass | 2b4071b | 2014-10-10 07:49:18 -0600 | [diff] [blame] | 134 | return -ENODEV; |
Bill Richardson | eece432 | 2012-10-20 11:44:34 +0000 | [diff] [blame] | 135 | } |
| 136 | |
| 137 | /* Header Type must be normal (bits 6-0 only; see spec.) */ |
Simon Glass | 60af017 | 2014-11-12 22:42:24 -0700 | [diff] [blame] | 138 | tmpbyte = pci_read_config8(pci_dev, PCI_HEADER_TYPE); |
Bill Richardson | eece432 | 2012-10-20 11:44:34 +0000 | [diff] [blame] | 139 | if ((tmpbyte & 0x7f) != PCI_HEADER_TYPE_NORMAL) { |
| 140 | debug("%s: invalid Header type\n", __func__); |
Simon Glass | 2b4071b | 2014-10-10 07:49:18 -0600 | [diff] [blame] | 141 | return -ENODEV; |
Bill Richardson | eece432 | 2012-10-20 11:44:34 +0000 | [diff] [blame] | 142 | } |
| 143 | |
| 144 | /* Base Class must be a bridge device */ |
Simon Glass | 60af017 | 2014-11-12 22:42:24 -0700 | [diff] [blame] | 145 | tmpbyte = pci_read_config8(pci_dev, PCI_CLASS_CODE); |
Bill Richardson | eece432 | 2012-10-20 11:44:34 +0000 | [diff] [blame] | 146 | if (tmpbyte != PCI_CLASS_CODE_BRIDGE) { |
| 147 | debug("%s: invalid class\n", __func__); |
Simon Glass | 2b4071b | 2014-10-10 07:49:18 -0600 | [diff] [blame] | 148 | return -ENODEV; |
Bill Richardson | eece432 | 2012-10-20 11:44:34 +0000 | [diff] [blame] | 149 | } |
| 150 | /* Sub Class must be ISA */ |
Simon Glass | 60af017 | 2014-11-12 22:42:24 -0700 | [diff] [blame] | 151 | tmpbyte = pci_read_config8(pci_dev, PCI_CLASS_SUB_CODE); |
Bill Richardson | eece432 | 2012-10-20 11:44:34 +0000 | [diff] [blame] | 152 | if (tmpbyte != PCI_CLASS_SUB_CODE_BRIDGE_ISA) { |
| 153 | debug("%s: invalid subclass\n", __func__); |
Simon Glass | 2b4071b | 2014-10-10 07:49:18 -0600 | [diff] [blame] | 154 | return -ENODEV; |
Bill Richardson | eece432 | 2012-10-20 11:44:34 +0000 | [diff] [blame] | 155 | } |
| 156 | |
| 157 | /* Programming Interface must be 0x00 (no others exist) */ |
Simon Glass | 60af017 | 2014-11-12 22:42:24 -0700 | [diff] [blame] | 158 | tmpbyte = pci_read_config8(pci_dev, PCI_CLASS_PROG); |
Bill Richardson | eece432 | 2012-10-20 11:44:34 +0000 | [diff] [blame] | 159 | if (tmpbyte != 0x00) { |
| 160 | debug("%s: invalid interface type\n", __func__); |
Simon Glass | 2b4071b | 2014-10-10 07:49:18 -0600 | [diff] [blame] | 161 | return -ENODEV; |
Bill Richardson | eece432 | 2012-10-20 11:44:34 +0000 | [diff] [blame] | 162 | } |
| 163 | |
| 164 | /* |
| 165 | * GPIOBASE moved to its current offset with ICH6, but prior to |
| 166 | * that it was unused (or undocumented). Check that it looks |
| 167 | * okay: not all ones or zeros, and mapped to I/O space (bit 0). |
| 168 | */ |
Simon Glass | 60af017 | 2014-11-12 22:42:24 -0700 | [diff] [blame] | 169 | tmplong = pci_read_config32(pci_dev, PCI_CFG_GPIOBASE); |
Bill Richardson | eece432 | 2012-10-20 11:44:34 +0000 | [diff] [blame] | 170 | if (tmplong == 0x00000000 || tmplong == 0xffffffff || |
| 171 | !(tmplong & 0x00000001)) { |
| 172 | debug("%s: unexpected GPIOBASE value\n", __func__); |
Simon Glass | 2b4071b | 2014-10-10 07:49:18 -0600 | [diff] [blame] | 173 | return -ENODEV; |
Bill Richardson | eece432 | 2012-10-20 11:44:34 +0000 | [diff] [blame] | 174 | } |
| 175 | |
| 176 | /* |
| 177 | * Okay, I guess we're looking at the right device. The actual |
| 178 | * GPIO registers are in the PCI device's I/O space, starting |
| 179 | * at the offset that we just read. Bit 0 indicates that it's |
| 180 | * an I/O address, not a memory address, so mask that off. |
| 181 | */ |
| 182 | gpiobase = tmplong & 0xfffffffe; |
Simon Glass | 2b4071b | 2014-10-10 07:49:18 -0600 | [diff] [blame] | 183 | offset = fdtdec_get_int(gd->fdt_blob, dev->of_offset, "reg", -1); |
| 184 | if (offset == -1) { |
| 185 | debug("%s: Invalid register offset %d\n", __func__, offset); |
| 186 | return -EINVAL; |
| 187 | } |
| 188 | plat->base_addr = gpiobase + offset; |
| 189 | plat->bank_name = fdt_getprop(gd->fdt_blob, dev->of_offset, |
| 190 | "bank-name", NULL); |
Bill Richardson | eece432 | 2012-10-20 11:44:34 +0000 | [diff] [blame] | 191 | |
Bill Richardson | eece432 | 2012-10-20 11:44:34 +0000 | [diff] [blame] | 192 | return 0; |
| 193 | } |
| 194 | |
Simon Glass | 60af017 | 2014-11-12 22:42:24 -0700 | [diff] [blame] | 195 | static int ich6_gpio_probe(struct udevice *dev) |
Bill Richardson | eece432 | 2012-10-20 11:44:34 +0000 | [diff] [blame] | 196 | { |
Simon Glass | 2b4071b | 2014-10-10 07:49:18 -0600 | [diff] [blame] | 197 | struct ich6_bank_platdata *plat = dev_get_platdata(dev); |
| 198 | struct gpio_dev_priv *uc_priv = dev->uclass_priv; |
| 199 | struct ich6_bank_priv *bank = dev_get_priv(dev); |
Bill Richardson | eece432 | 2012-10-20 11:44:34 +0000 | [diff] [blame] | 200 | |
Simon Glass | 60af017 | 2014-11-12 22:42:24 -0700 | [diff] [blame] | 201 | #ifdef SUPPORT_GPIO_SETUP |
| 202 | if (gd->arch.gpio_map) { |
| 203 | setup_pch_gpios(gd->arch.gpio_map); |
| 204 | gd->arch.gpio_map = NULL; |
| 205 | } |
| 206 | #endif |
Simon Glass | 2b4071b | 2014-10-10 07:49:18 -0600 | [diff] [blame] | 207 | uc_priv->gpio_count = GPIO_PER_BANK; |
| 208 | uc_priv->bank_name = plat->bank_name; |
| 209 | bank->use_sel = plat->base_addr; |
| 210 | bank->io_sel = plat->base_addr + 4; |
| 211 | bank->lvl = plat->base_addr + 8; |
Bill Richardson | eece432 | 2012-10-20 11:44:34 +0000 | [diff] [blame] | 212 | |
Simon Glass | 2b4071b | 2014-10-10 07:49:18 -0600 | [diff] [blame] | 213 | return 0; |
| 214 | } |
| 215 | |
Simon Glass | 60af017 | 2014-11-12 22:42:24 -0700 | [diff] [blame] | 216 | static int ich6_gpio_request(struct udevice *dev, unsigned offset, |
| 217 | const char *label) |
Simon Glass | 2b4071b | 2014-10-10 07:49:18 -0600 | [diff] [blame] | 218 | { |
| 219 | struct ich6_bank_priv *bank = dev_get_priv(dev); |
| 220 | u32 tmplong; |
Bill Richardson | eece432 | 2012-10-20 11:44:34 +0000 | [diff] [blame] | 221 | |
| 222 | /* |
| 223 | * Make sure that the GPIO pin we want isn't already in use for some |
| 224 | * built-in hardware function. We have to check this for every |
| 225 | * requested pin. |
| 226 | */ |
Simon Glass | 2b4071b | 2014-10-10 07:49:18 -0600 | [diff] [blame] | 227 | tmplong = inl(bank->use_sel); |
| 228 | if (!(tmplong & (1UL << offset))) { |
Bill Richardson | 50a5ebe | 2012-10-20 11:44:36 +0000 | [diff] [blame] | 229 | debug("%s: gpio %d is reserved for internal use\n", __func__, |
Simon Glass | 2b4071b | 2014-10-10 07:49:18 -0600 | [diff] [blame] | 230 | offset); |
| 231 | return -EPERM; |
Bill Richardson | eece432 | 2012-10-20 11:44:34 +0000 | [diff] [blame] | 232 | } |
| 233 | |
Bill Richardson | eece432 | 2012-10-20 11:44:34 +0000 | [diff] [blame] | 234 | return 0; |
| 235 | } |
| 236 | |
Simon Glass | 2b4071b | 2014-10-10 07:49:18 -0600 | [diff] [blame] | 237 | static int ich6_gpio_direction_input(struct udevice *dev, unsigned offset) |
Bill Richardson | eece432 | 2012-10-20 11:44:34 +0000 | [diff] [blame] | 238 | { |
Simon Glass | 2b4071b | 2014-10-10 07:49:18 -0600 | [diff] [blame] | 239 | struct ich6_bank_priv *bank = dev_get_priv(dev); |
Bill Richardson | eece432 | 2012-10-20 11:44:34 +0000 | [diff] [blame] | 240 | u32 tmplong; |
Bill Richardson | 50a5ebe | 2012-10-20 11:44:36 +0000 | [diff] [blame] | 241 | |
Simon Glass | 2b4071b | 2014-10-10 07:49:18 -0600 | [diff] [blame] | 242 | tmplong = inl(bank->io_sel); |
| 243 | tmplong |= (1UL << offset); |
| 244 | outl(bank->io_sel, tmplong); |
Bill Richardson | eece432 | 2012-10-20 11:44:34 +0000 | [diff] [blame] | 245 | return 0; |
| 246 | } |
| 247 | |
Simon Glass | 2b4071b | 2014-10-10 07:49:18 -0600 | [diff] [blame] | 248 | static int ich6_gpio_direction_output(struct udevice *dev, unsigned offset, |
| 249 | int value) |
Bill Richardson | eece432 | 2012-10-20 11:44:34 +0000 | [diff] [blame] | 250 | { |
Simon Glass | 2b4071b | 2014-10-10 07:49:18 -0600 | [diff] [blame] | 251 | struct ich6_bank_priv *bank = dev_get_priv(dev); |
Bill Richardson | eece432 | 2012-10-20 11:44:34 +0000 | [diff] [blame] | 252 | u32 tmplong; |
| 253 | |
Axel Lin | 6df0e9e | 2014-12-07 12:48:27 +0800 | [diff] [blame] | 254 | gpio_set_value(offset, value); |
| 255 | |
Simon Glass | 2b4071b | 2014-10-10 07:49:18 -0600 | [diff] [blame] | 256 | tmplong = inl(bank->io_sel); |
| 257 | tmplong &= ~(1UL << offset); |
| 258 | outl(bank->io_sel, tmplong); |
Bill Richardson | eece432 | 2012-10-20 11:44:34 +0000 | [diff] [blame] | 259 | return 0; |
| 260 | } |
| 261 | |
Simon Glass | 2b4071b | 2014-10-10 07:49:18 -0600 | [diff] [blame] | 262 | static int ich6_gpio_get_value(struct udevice *dev, unsigned offset) |
| 263 | |
Bill Richardson | eece432 | 2012-10-20 11:44:34 +0000 | [diff] [blame] | 264 | { |
Simon Glass | 2b4071b | 2014-10-10 07:49:18 -0600 | [diff] [blame] | 265 | struct ich6_bank_priv *bank = dev_get_priv(dev); |
Bill Richardson | eece432 | 2012-10-20 11:44:34 +0000 | [diff] [blame] | 266 | u32 tmplong; |
Bill Richardson | 50a5ebe | 2012-10-20 11:44:36 +0000 | [diff] [blame] | 267 | int r; |
Bill Richardson | eece432 | 2012-10-20 11:44:34 +0000 | [diff] [blame] | 268 | |
Simon Glass | 2b4071b | 2014-10-10 07:49:18 -0600 | [diff] [blame] | 269 | tmplong = inl(bank->lvl); |
| 270 | r = (tmplong & (1UL << offset)) ? 1 : 0; |
Bill Richardson | 50a5ebe | 2012-10-20 11:44:36 +0000 | [diff] [blame] | 271 | return r; |
Bill Richardson | eece432 | 2012-10-20 11:44:34 +0000 | [diff] [blame] | 272 | } |
| 273 | |
Simon Glass | 2b4071b | 2014-10-10 07:49:18 -0600 | [diff] [blame] | 274 | static int ich6_gpio_set_value(struct udevice *dev, unsigned offset, |
| 275 | int value) |
Bill Richardson | eece432 | 2012-10-20 11:44:34 +0000 | [diff] [blame] | 276 | { |
Simon Glass | 2b4071b | 2014-10-10 07:49:18 -0600 | [diff] [blame] | 277 | struct ich6_bank_priv *bank = dev_get_priv(dev); |
Bill Richardson | eece432 | 2012-10-20 11:44:34 +0000 | [diff] [blame] | 278 | u32 tmplong; |
| 279 | |
Simon Glass | 2b4071b | 2014-10-10 07:49:18 -0600 | [diff] [blame] | 280 | tmplong = inl(bank->lvl); |
Bill Richardson | eece432 | 2012-10-20 11:44:34 +0000 | [diff] [blame] | 281 | if (value) |
Simon Glass | 2b4071b | 2014-10-10 07:49:18 -0600 | [diff] [blame] | 282 | tmplong |= (1UL << offset); |
Bill Richardson | eece432 | 2012-10-20 11:44:34 +0000 | [diff] [blame] | 283 | else |
Simon Glass | 2b4071b | 2014-10-10 07:49:18 -0600 | [diff] [blame] | 284 | tmplong &= ~(1UL << offset); |
| 285 | outl(bank->lvl, tmplong); |
Bill Richardson | eece432 | 2012-10-20 11:44:34 +0000 | [diff] [blame] | 286 | return 0; |
| 287 | } |
Simon Glass | 2b4071b | 2014-10-10 07:49:18 -0600 | [diff] [blame] | 288 | |
| 289 | static int ich6_gpio_get_function(struct udevice *dev, unsigned offset) |
| 290 | { |
| 291 | struct ich6_bank_priv *bank = dev_get_priv(dev); |
| 292 | u32 mask = 1UL << offset; |
| 293 | |
| 294 | if (!(inl(bank->use_sel) & mask)) |
| 295 | return GPIOF_FUNC; |
| 296 | if (inl(bank->io_sel) & mask) |
| 297 | return GPIOF_INPUT; |
| 298 | else |
| 299 | return GPIOF_OUTPUT; |
| 300 | } |
| 301 | |
| 302 | static const struct dm_gpio_ops gpio_ich6_ops = { |
| 303 | .request = ich6_gpio_request, |
| 304 | .direction_input = ich6_gpio_direction_input, |
| 305 | .direction_output = ich6_gpio_direction_output, |
| 306 | .get_value = ich6_gpio_get_value, |
| 307 | .set_value = ich6_gpio_set_value, |
| 308 | .get_function = ich6_gpio_get_function, |
| 309 | }; |
| 310 | |
| 311 | static const struct udevice_id intel_ich6_gpio_ids[] = { |
| 312 | { .compatible = "intel,ich6-gpio" }, |
| 313 | { } |
| 314 | }; |
| 315 | |
| 316 | U_BOOT_DRIVER(gpio_ich6) = { |
| 317 | .name = "gpio_ich6", |
| 318 | .id = UCLASS_GPIO, |
| 319 | .of_match = intel_ich6_gpio_ids, |
| 320 | .ops = &gpio_ich6_ops, |
| 321 | .ofdata_to_platdata = gpio_ich6_ofdata_to_platdata, |
| 322 | .probe = ich6_gpio_probe, |
| 323 | .priv_auto_alloc_size = sizeof(struct ich6_bank_priv), |
| 324 | .platdata_auto_alloc_size = sizeof(struct ich6_bank_platdata), |
| 325 | }; |