diff options
| author | Peter Ujfalusi <peter.ujfalusi@ti.com> | 2012-08-16 08:13:15 -0400 |
|---|---|---|
| committer | Samuel Ortiz <sameo@linux.intel.com> | 2012-09-19 06:21:20 -0400 |
| commit | 70ffd691ffd45e6753eee5b5636df2ff7d2c04c8 (patch) | |
| tree | ba81c17c6778036ca66e218069b32652ff2ffc16 | |
| parent | 5cbe786a6e32e80149f7b29def50b2bf563f6628 (diff) | |
gpio: Add basic support for TWL6040 GPOs
TWL6040 provides GPO lines to be used for controlling external devices.The number
of lines different between versions: twl6040 have 3 GPO while TWL6041 have 1.
Signed-off-by: Sergio Aguirre <saaguirre@ti.com>
Signed-off-by: Peter Ujfalusi <peter.ujfalusi@ti.com>
Acked-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
| -rw-r--r-- | drivers/gpio/Kconfig | 7 | ||||
| -rw-r--r-- | drivers/gpio/Makefile | 1 | ||||
| -rw-r--r-- | drivers/gpio/gpio-twl6040.c | 137 |
3 files changed, 145 insertions, 0 deletions
diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig index b16c8a72a2e2..f74633e0495a 100644 --- a/drivers/gpio/Kconfig +++ b/drivers/gpio/Kconfig | |||
| @@ -402,6 +402,13 @@ config GPIO_TWL4030 | |||
| 402 | Say yes here to access the GPIO signals of various multi-function | 402 | Say yes here to access the GPIO signals of various multi-function |
| 403 | power management chips from Texas Instruments. | 403 | power management chips from Texas Instruments. |
| 404 | 404 | ||
| 405 | config GPIO_TWL6040 | ||
| 406 | tristate "TWL6040 GPO" | ||
| 407 | depends on TWL6040_CORE | ||
| 408 | help | ||
| 409 | Say yes here to access the GPO signals of twl6040 | ||
| 410 | audio chip from Texas Instruments. | ||
| 411 | |||
| 405 | config GPIO_WM831X | 412 | config GPIO_WM831X |
| 406 | tristate "WM831x GPIOs" | 413 | tristate "WM831x GPIOs" |
| 407 | depends on MFD_WM831X | 414 | depends on MFD_WM831X |
diff --git a/drivers/gpio/Makefile b/drivers/gpio/Makefile index 153caceeb053..f857b463af0f 100644 --- a/drivers/gpio/Makefile +++ b/drivers/gpio/Makefile | |||
| @@ -67,6 +67,7 @@ obj-$(CONFIG_GPIO_TPS6586X) += gpio-tps6586x.o | |||
| 67 | obj-$(CONFIG_GPIO_TPS65910) += gpio-tps65910.o | 67 | obj-$(CONFIG_GPIO_TPS65910) += gpio-tps65910.o |
| 68 | obj-$(CONFIG_GPIO_TPS65912) += gpio-tps65912.o | 68 | obj-$(CONFIG_GPIO_TPS65912) += gpio-tps65912.o |
| 69 | obj-$(CONFIG_GPIO_TWL4030) += gpio-twl4030.o | 69 | obj-$(CONFIG_GPIO_TWL4030) += gpio-twl4030.o |
| 70 | obj-$(CONFIG_GPIO_TWL6040) += gpio-twl6040.o | ||
| 70 | obj-$(CONFIG_GPIO_UCB1400) += gpio-ucb1400.o | 71 | obj-$(CONFIG_GPIO_UCB1400) += gpio-ucb1400.o |
| 71 | obj-$(CONFIG_GPIO_VR41XX) += gpio-vr41xx.o | 72 | obj-$(CONFIG_GPIO_VR41XX) += gpio-vr41xx.o |
| 72 | obj-$(CONFIG_GPIO_VX855) += gpio-vx855.o | 73 | obj-$(CONFIG_GPIO_VX855) += gpio-vx855.o |
diff --git a/drivers/gpio/gpio-twl6040.c b/drivers/gpio/gpio-twl6040.c new file mode 100644 index 000000000000..dd58e8b25043 --- /dev/null +++ b/drivers/gpio/gpio-twl6040.c | |||
| @@ -0,0 +1,137 @@ | |||
| 1 | /* | ||
| 2 | * Access to GPOs on TWL6040 chip | ||
| 3 | * | ||
| 4 | * Copyright (C) 2012 Texas Instruments, Inc. | ||
| 5 | * | ||
| 6 | * Authors: | ||
| 7 | * Sergio Aguirre <saaguirre@ti.com> | ||
| 8 | * Peter Ujfalusi <peter.ujfalusi@ti.com> | ||
| 9 | * | ||
| 10 | * This program is free software; you can redistribute it and/or modify | ||
| 11 | * it under the terms of the GNU General Public License as published by | ||
| 12 | * the Free Software Foundation; either version 2 of the License, or | ||
| 13 | * (at your option) any later version. | ||
| 14 | * | ||
| 15 | * This program is distributed in the hope that it will be useful, | ||
| 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 18 | * GNU General Public License for more details. | ||
| 19 | * | ||
| 20 | * You should have received a copy of the GNU General Public License | ||
| 21 | * along with this program; if not, write to the Free Software | ||
| 22 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
| 23 | */ | ||
| 24 | |||
| 25 | #include <linux/module.h> | ||
| 26 | #include <linux/init.h> | ||
| 27 | #include <linux/kthread.h> | ||
| 28 | #include <linux/irq.h> | ||
| 29 | #include <linux/gpio.h> | ||
| 30 | #include <linux/platform_device.h> | ||
| 31 | #include <linux/of.h> | ||
| 32 | |||
| 33 | #include <linux/mfd/twl6040.h> | ||
| 34 | |||
| 35 | static struct gpio_chip twl6040gpo_chip; | ||
| 36 | |||
| 37 | static int twl6040gpo_get(struct gpio_chip *chip, unsigned offset) | ||
| 38 | { | ||
| 39 | struct twl6040 *twl6040 = dev_get_drvdata(chip->dev->parent); | ||
| 40 | int ret = 0; | ||
| 41 | |||
| 42 | ret = twl6040_reg_read(twl6040, TWL6040_REG_GPOCTL); | ||
| 43 | if (ret < 0) | ||
| 44 | return ret; | ||
| 45 | |||
| 46 | return (ret >> offset) & 1; | ||
| 47 | } | ||
| 48 | |||
| 49 | static int twl6040gpo_direction_out(struct gpio_chip *chip, unsigned offset, | ||
| 50 | int value) | ||
| 51 | { | ||
| 52 | /* This only drives GPOs, and can't change direction */ | ||
| 53 | return 0; | ||
| 54 | } | ||
| 55 | |||
| 56 | static void twl6040gpo_set(struct gpio_chip *chip, unsigned offset, int value) | ||
| 57 | { | ||
| 58 | struct twl6040 *twl6040 = dev_get_drvdata(chip->dev->parent); | ||
| 59 | int ret; | ||
| 60 | u8 gpoctl; | ||
| 61 | |||
| 62 | ret = twl6040_reg_read(twl6040, TWL6040_REG_GPOCTL); | ||
| 63 | if (ret < 0) | ||
| 64 | return; | ||
| 65 | |||
| 66 | if (value) | ||
| 67 | gpoctl = ret | (1 << offset); | ||
| 68 | else | ||
| 69 | gpoctl = ret & ~(1 << offset); | ||
| 70 | |||
| 71 | twl6040_reg_write(twl6040, TWL6040_REG_GPOCTL, gpoctl); | ||
| 72 | } | ||
| 73 | |||
| 74 | static struct gpio_chip twl6040gpo_chip = { | ||
| 75 | .label = "twl6040", | ||
| 76 | .owner = THIS_MODULE, | ||
| 77 | .get = twl6040gpo_get, | ||
| 78 | .direction_output = twl6040gpo_direction_out, | ||
| 79 | .set = twl6040gpo_set, | ||
| 80 | .can_sleep = 1, | ||
| 81 | }; | ||
| 82 | |||
| 83 | /*----------------------------------------------------------------------*/ | ||
| 84 | |||
| 85 | static int __devinit gpo_twl6040_probe(struct platform_device *pdev) | ||
| 86 | { | ||
| 87 | struct twl6040_gpo_data *pdata = pdev->dev.platform_data; | ||
| 88 | struct device *twl6040_core_dev = pdev->dev.parent; | ||
| 89 | struct twl6040 *twl6040 = dev_get_drvdata(twl6040_core_dev); | ||
| 90 | int ret; | ||
| 91 | |||
| 92 | if (pdata) | ||
| 93 | twl6040gpo_chip.base = pdata->gpio_base; | ||
| 94 | else | ||
| 95 | twl6040gpo_chip.base = -1; | ||
| 96 | |||
| 97 | if (twl6040_get_revid(twl6040) < TWL6041_REV_ES2_0) | ||
| 98 | twl6040gpo_chip.ngpio = 3; /* twl6040 have 3 GPO */ | ||
| 99 | else | ||
| 100 | twl6040gpo_chip.ngpio = 1; /* twl6041 have 1 GPO */ | ||
| 101 | |||
| 102 | twl6040gpo_chip.dev = &pdev->dev; | ||
| 103 | #ifdef CONFIG_OF_GPIO | ||
| 104 | twl6040gpo_chip.of_node = twl6040_core_dev->of_node; | ||
| 105 | #endif | ||
| 106 | |||
| 107 | ret = gpiochip_add(&twl6040gpo_chip); | ||
| 108 | if (ret < 0) { | ||
| 109 | dev_err(&pdev->dev, "could not register gpiochip, %d\n", ret); | ||
| 110 | twl6040gpo_chip.ngpio = 0; | ||
| 111 | } | ||
| 112 | |||
| 113 | return ret; | ||
| 114 | } | ||
| 115 | |||
| 116 | static int __devexit gpo_twl6040_remove(struct platform_device *pdev) | ||
| 117 | { | ||
| 118 | return gpiochip_remove(&twl6040gpo_chip); | ||
| 119 | } | ||
| 120 | |||
| 121 | /* Note: this hardware lives inside an I2C-based multi-function device. */ | ||
| 122 | MODULE_ALIAS("platform:twl6040-gpo"); | ||
| 123 | |||
| 124 | static struct platform_driver gpo_twl6040_driver = { | ||
| 125 | .driver = { | ||
| 126 | .name = "twl6040-gpo", | ||
| 127 | .owner = THIS_MODULE, | ||
| 128 | }, | ||
| 129 | .probe = gpo_twl6040_probe, | ||
| 130 | .remove = gpo_twl6040_remove, | ||
| 131 | }; | ||
| 132 | |||
| 133 | module_platform_driver(gpo_twl6040_driver); | ||
| 134 | |||
| 135 | MODULE_AUTHOR("Texas Instruments, Inc."); | ||
| 136 | MODULE_DESCRIPTION("GPO interface for TWL6040"); | ||
| 137 | MODULE_LICENSE("GPL"); | ||
