diff options
| author | Mathias Nyman <mathias.nyman@linux.intel.com> | 2013-06-18 07:33:02 -0400 |
|---|---|---|
| committer | Linus Walleij <linus.walleij@linaro.org> | 2013-06-18 11:23:40 -0400 |
| commit | a5d811bbf1c6df86cfe23948059ea614554b9f19 (patch) | |
| tree | ba9c651bd4f61303bf7a806ababf5b3f79b9f3d0 /drivers/pinctrl | |
| parent | 1c851fb189152b6572688fda7fc487ade2a4cb8a (diff) | |
pinctrl: add Intel BayTrail GPIO/pinctrl support
Add support for gpio on Intel BayTrail platforms. BayTrail supports 3 banks
of gpios called SCORE, NCORE ans SUS with 102, 28 and 44 gpio pins.
Supports gpio interrupts and ACPI gpio events
Pins may be muxed to alternate function instead of gpio by firmware.
This driver does not touch the pin muxing and expect firmare
to set pin muxing and pullup/down properties properly.
Signed-off-by: Mathias Nyman <mathias.nyman@linux.intel.com>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Diffstat (limited to 'drivers/pinctrl')
| -rw-r--r-- | drivers/pinctrl/Kconfig | 12 | ||||
| -rw-r--r-- | drivers/pinctrl/Makefile | 1 | ||||
| -rw-r--r-- | drivers/pinctrl/pinctrl-baytrail.c | 543 |
3 files changed, 556 insertions, 0 deletions
diff --git a/drivers/pinctrl/Kconfig b/drivers/pinctrl/Kconfig index 269c0406dce4..e01976fb1175 100644 --- a/drivers/pinctrl/Kconfig +++ b/drivers/pinctrl/Kconfig | |||
| @@ -58,6 +58,18 @@ config PINCTRL_AT91 | |||
| 58 | help | 58 | help |
| 59 | Say Y here to enable the at91 pinctrl driver | 59 | Say Y here to enable the at91 pinctrl driver |
| 60 | 60 | ||
| 61 | config PINCTRL_BAYTRAIL | ||
| 62 | bool "Intel Baytrail GPIO pin control" | ||
| 63 | depends on GPIOLIB && ACPI && X86 | ||
| 64 | select IRQ_DOMAIN | ||
| 65 | help | ||
| 66 | driver for memory mapped GPIO functionality on Intel Baytrail | ||
| 67 | platforms. Supports 3 banks with 102, 28 and 44 gpios. | ||
| 68 | Most pins are usually muxed to some other functionality by firmware, | ||
| 69 | so only a small amount is available for gpio use. | ||
| 70 | |||
| 71 | Requires ACPI device enumeration code to set up a platform device. | ||
| 72 | |||
| 61 | config PINCTRL_BCM2835 | 73 | config PINCTRL_BCM2835 |
| 62 | bool | 74 | bool |
| 63 | select PINMUX | 75 | select PINMUX |
diff --git a/drivers/pinctrl/Makefile b/drivers/pinctrl/Makefile index ff38aca65689..9031afddb9ad 100644 --- a/drivers/pinctrl/Makefile +++ b/drivers/pinctrl/Makefile | |||
| @@ -16,6 +16,7 @@ obj-$(CONFIG_PINCTRL_AB9540) += pinctrl-ab9540.o | |||
| 16 | obj-$(CONFIG_PINCTRL_AB8505) += pinctrl-ab8505.o | 16 | obj-$(CONFIG_PINCTRL_AB8505) += pinctrl-ab8505.o |
| 17 | obj-$(CONFIG_PINCTRL_AT91) += pinctrl-at91.o | 17 | obj-$(CONFIG_PINCTRL_AT91) += pinctrl-at91.o |
| 18 | obj-$(CONFIG_PINCTRL_BCM2835) += pinctrl-bcm2835.o | 18 | obj-$(CONFIG_PINCTRL_BCM2835) += pinctrl-bcm2835.o |
| 19 | obj-$(CONFIG_PINCTRL_BAYTRAIL) += pinctrl-baytrail.o | ||
| 19 | obj-$(CONFIG_PINCTRL_IMX) += pinctrl-imx.o | 20 | obj-$(CONFIG_PINCTRL_IMX) += pinctrl-imx.o |
| 20 | obj-$(CONFIG_PINCTRL_IMX35) += pinctrl-imx35.o | 21 | obj-$(CONFIG_PINCTRL_IMX35) += pinctrl-imx35.o |
| 21 | obj-$(CONFIG_PINCTRL_IMX51) += pinctrl-imx51.o | 22 | obj-$(CONFIG_PINCTRL_IMX51) += pinctrl-imx51.o |
diff --git a/drivers/pinctrl/pinctrl-baytrail.c b/drivers/pinctrl/pinctrl-baytrail.c new file mode 100644 index 000000000000..e9d735dcebfb --- /dev/null +++ b/drivers/pinctrl/pinctrl-baytrail.c | |||
| @@ -0,0 +1,543 @@ | |||
| 1 | /* | ||
| 2 | * Pinctrl GPIO driver for Intel Baytrail | ||
| 3 | * Copyright (c) 2012-2013, Intel Corporation. | ||
| 4 | * | ||
| 5 | * Author: Mathias Nyman <mathias.nyman@linux.intel.com> | ||
| 6 | * | ||
| 7 | * This program is free software; you can redistribute it and/or modify it | ||
| 8 | * under the terms and conditions of the GNU General Public License, | ||
| 9 | * version 2, as published by the Free Software Foundation. | ||
| 10 | * | ||
| 11 | * This program is distributed in the hope it will be useful, but WITHOUT | ||
| 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
| 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
| 14 | * more details. | ||
| 15 | * | ||
| 16 | * You should have received a copy of the GNU General Public License along with | ||
| 17 | * this program; if not, write to the Free Software Foundation, Inc., | ||
| 18 | * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. | ||
| 19 | * | ||
| 20 | */ | ||
| 21 | |||
| 22 | #include <linux/kernel.h> | ||
| 23 | #include <linux/module.h> | ||
| 24 | #include <linux/init.h> | ||
| 25 | #include <linux/types.h> | ||
| 26 | #include <linux/bitops.h> | ||
| 27 | #include <linux/interrupt.h> | ||
| 28 | #include <linux/irq.h> | ||
| 29 | #include <linux/gpio.h> | ||
| 30 | #include <linux/irqdomain.h> | ||
| 31 | #include <linux/acpi.h> | ||
| 32 | #include <linux/acpi_gpio.h> | ||
| 33 | #include <linux/platform_device.h> | ||
| 34 | #include <linux/seq_file.h> | ||
| 35 | #include <linux/io.h> | ||
| 36 | #include <linux/pm_runtime.h> | ||
| 37 | #include <linux/pinctrl/pinctrl.h> | ||
| 38 | |||
| 39 | /* memory mapped register offsets */ | ||
| 40 | #define BYT_CONF0_REG 0x000 | ||
| 41 | #define BYT_CONF1_REG 0x004 | ||
| 42 | #define BYT_VAL_REG 0x008 | ||
| 43 | #define BYT_DFT_REG 0x00c | ||
| 44 | #define BYT_INT_STAT_REG 0x800 | ||
| 45 | |||
| 46 | /* BYT_CONF0_REG register bits */ | ||
| 47 | #define BYT_TRIG_NEG BIT(26) | ||
| 48 | #define BYT_TRIG_POS BIT(25) | ||
| 49 | #define BYT_TRIG_LVL BIT(24) | ||
| 50 | #define BYT_PIN_MUX 0x07 | ||
| 51 | |||
| 52 | /* BYT_VAL_REG register bits */ | ||
| 53 | #define BYT_INPUT_EN BIT(2) /* 0: input enabled (active low)*/ | ||
| 54 | #define BYT_OUTPUT_EN BIT(1) /* 0: output enabled (active low)*/ | ||
| 55 | #define BYT_LEVEL BIT(0) | ||
| 56 | |||
| 57 | #define BYT_DIR_MASK (BIT(1) | BIT(2)) | ||
| 58 | #define BYT_TRIG_MASK (BIT(26) | BIT(25) | BIT(24)) | ||
| 59 | |||
| 60 | #define BYT_NGPIO_SCORE 102 | ||
| 61 | #define BYT_NGPIO_NCORE 28 | ||
| 62 | #define BYT_NGPIO_SUS 44 | ||
| 63 | |||
| 64 | /* | ||
| 65 | * Baytrail gpio controller consist of three separate sub-controllers called | ||
| 66 | * SCORE, NCORE and SUS. The sub-controllers are identified by their acpi UID. | ||
| 67 | * | ||
| 68 | * GPIO numbering is _not_ ordered meaning that gpio # 0 in ACPI namespace does | ||
| 69 | * _not_ correspond to the first gpio register at controller's gpio base. | ||
| 70 | * There is no logic or pattern in mapping gpio numbers to registers (pads) so | ||
| 71 | * each sub-controller needs to have its own mapping table | ||
| 72 | */ | ||
| 73 | |||
| 74 | /* score_pins[gpio_nr] = pad_nr */ | ||
| 75 | |||
| 76 | static unsigned const score_pins[BYT_NGPIO_SCORE] = { | ||
| 77 | 85, 89, 93, 96, 99, 102, 98, 101, 34, 37, | ||
| 78 | 36, 38, 39, 35, 40, 84, 62, 61, 64, 59, | ||
| 79 | 54, 56, 60, 55, 63, 57, 51, 50, 53, 47, | ||
| 80 | 52, 49, 48, 43, 46, 41, 45, 42, 58, 44, | ||
| 81 | 95, 105, 70, 68, 67, 66, 69, 71, 65, 72, | ||
| 82 | 86, 90, 88, 92, 103, 77, 79, 83, 78, 81, | ||
| 83 | 80, 82, 13, 12, 15, 14, 17, 18, 19, 16, | ||
| 84 | 2, 1, 0, 4, 6, 7, 9, 8, 33, 32, | ||
| 85 | 31, 30, 29, 27, 25, 28, 26, 23, 21, 20, | ||
| 86 | 24, 22, 5, 3, 10, 11, 106, 87, 91, 104, | ||
| 87 | 97, 100, | ||
| 88 | }; | ||
| 89 | |||
| 90 | static unsigned const ncore_pins[BYT_NGPIO_NCORE] = { | ||
| 91 | 19, 18, 17, 20, 21, 22, 24, 25, 23, 16, | ||
| 92 | 14, 15, 12, 26, 27, 1, 4, 8, 11, 0, | ||
| 93 | 3, 6, 10, 13, 2, 5, 9, 7, | ||
| 94 | }; | ||
| 95 | |||
| 96 | static unsigned const sus_pins[BYT_NGPIO_SUS] = { | ||
| 97 | 29, 33, 30, 31, 32, 34, 36, 35, 38, 37, | ||
| 98 | 18, 7, 11, 20, 17, 1, 8, 10, 19, 12, | ||
| 99 | 0, 2, 23, 39, 28, 27, 22, 21, 24, 25, | ||
| 100 | 26, 51, 56, 54, 49, 55, 48, 57, 50, 58, | ||
| 101 | 52, 53, 59, 40, | ||
| 102 | }; | ||
| 103 | |||
| 104 | static struct pinctrl_gpio_range byt_ranges[] = { | ||
| 105 | { | ||
| 106 | .name = "1", /* match with acpi _UID in probe */ | ||
| 107 | .npins = BYT_NGPIO_SCORE, | ||
| 108 | .pins = score_pins, | ||
| 109 | }, | ||
| 110 | { | ||
| 111 | .name = "2", | ||
| 112 | .npins = BYT_NGPIO_NCORE, | ||
| 113 | .pins = ncore_pins, | ||
| 114 | }, | ||
| 115 | { | ||
| 116 | .name = "3", | ||
| 117 | .npins = BYT_NGPIO_SUS, | ||
| 118 | .pins = sus_pins, | ||
| 119 | }, | ||
| 120 | { | ||
| 121 | }, | ||
| 122 | }; | ||
| 123 | |||
| 124 | struct byt_gpio { | ||
| 125 | struct gpio_chip chip; | ||
| 126 | struct irq_domain *domain; | ||
| 127 | struct platform_device *pdev; | ||
| 128 | spinlock_t lock; | ||
| 129 | void __iomem *reg_base; | ||
| 130 | struct pinctrl_gpio_range *range; | ||
| 131 | }; | ||
| 132 | |||
| 133 | static void __iomem *byt_gpio_reg(struct gpio_chip *chip, unsigned offset, | ||
| 134 | int reg) | ||
| 135 | { | ||
| 136 | struct byt_gpio *vg = container_of(chip, struct byt_gpio, chip); | ||
| 137 | u32 reg_offset; | ||
| 138 | void __iomem *ptr; | ||
| 139 | |||
| 140 | if (reg == BYT_INT_STAT_REG) | ||
| 141 | reg_offset = (offset / 32) * 4; | ||
| 142 | else | ||
| 143 | reg_offset = vg->range->pins[offset] * 16; | ||
| 144 | |||
| 145 | ptr = (void __iomem *) (vg->reg_base + reg_offset + reg); | ||
| 146 | return ptr; | ||
| 147 | } | ||
| 148 | |||
| 149 | static int byt_gpio_request(struct gpio_chip *chip, unsigned offset) | ||
| 150 | { | ||
