aboutsummaryrefslogtreecommitdiff
path: root/drivers/mfd/pcf50633-gpio.c
diff options
context:
space:
mode:
authorAndy Green <andy@openmoko.com>2008-11-21 16:40:58 +0000
committerAndy Green <andy@openmoko.com>2008-11-21 16:40:58 +0000
commit4a922dc8ab2915b61ff6adfe8e0a01069893b52b (patch)
tree6909728173fc18e8a88eaa9aa46eaebffbcabd93 /drivers/mfd/pcf50633-gpio.c
parenta7e6827348e9e85466c9ab6488769bf862e9fd0b (diff)
MERGE-via-balaji-tracking-balaji-updates
Signed-off-by: Andy Green <andy@openmoko.com>
Diffstat (limited to 'drivers/mfd/pcf50633-gpio.c')
-rw-r--r--drivers/mfd/pcf50633-gpio.c109
1 files changed, 73 insertions, 36 deletions
diff --git a/drivers/mfd/pcf50633-gpio.c b/drivers/mfd/pcf50633-gpio.c
index f71acbd6dbc..a5b978c4e3c 100644
--- a/drivers/mfd/pcf50633-gpio.c
+++ b/drivers/mfd/pcf50633-gpio.c
@@ -1,62 +1,99 @@
+/* Philips PCF50633 GPIO Driver
+ *
+ * (C) 2006-2008 by Openmoko, Inc.
+ * Author: Balaji Rao <balajirrao@openmoko.org>
+ * All rights reserved.
+ *
+ * Broken down from monstrous PCF50633 driver mainly by
+ * Harald Welte and Andy Green
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ */
+
#include <linux/mfd/pcf50633/core.h>
#include <linux/mfd/pcf50633/gpio.h>
+#include <linux/mfd/pcf50633/pmic.h>
-void pcf50633_gpio_set(struct pcf50633 *pcf, int gpio, int on)
+void pcf50633_gpio_set(struct pcf50633 *pcf, int gpio, int val)
{
- u8 reg = gpio - PCF50633_GPIO1 + PCF50633_REG_GPIO1CFG;
+ u8 reg;
+
+ reg = gpio - PCF50633_GPIO1 + PCF50633_REG_GPIO1CFG;
- if (on)
- pcf50633_reg_set_bit_mask(pcf, reg, 0x0f, 0x07);
- else
- pcf50633_reg_set_bit_mask(pcf, reg, 0x0f, 0x00);
+ pcf50633_reg_set_bit_mask(pcf, reg, 0x07, val);
}
EXPORT_SYMBOL_GPL(pcf50633_gpio_set);
int pcf50633_gpio_get(struct pcf50633 *pcf, int gpio)
{
- u8 reg = gpio - PCF50633_GPIO1 + PCF50633_REG_GPIO1CFG;
- u8 val = pcf50633_reg_read(pcf, reg) & 0x0f;
+ u8 reg, val;
- if (val == PCF50633_GPOCFG_GPOSEL_1 ||
- val == (PCF50633_GPOCFG_GPOSEL_0|PCF50633_GPOCFG_GPOSEL_INVERSE))
- return 1;
+ reg = gpio - PCF50633_GPIO1 + PCF50633_REG_GPIO1CFG;
+ val = pcf50633_reg_read(pcf, reg);
- return 0;
+ return val;
}
EXPORT_SYMBOL_GPL(pcf50633_gpio_get);
-int __init pcf50633_gpio_probe(struct platform_device *pdev)
+void pcf50633_gpio_invert_set(struct pcf50633 *pcf, int gpio, int invert)
{
- return 0;
+ u8 val, reg;
+
+ reg = gpio - PCF50633_GPIO1 + PCF50633_REG_GPIO1CFG;
+ val = !!invert << 3;
+
+ pcf50633_reg_set_bit_mask(pcf, reg, val, val);
}
+EXPORT_SYMBOL_GPL(pcf50633_gpio_invert_set);
-static int __devexit pcf50633_gpio_remove(struct platform_device *pdev)
+int pcf50633_gpio_invert_get(struct pcf50633 *pcf, int gpio)
{
- return 0;
-}
+ u8 reg, val;
-struct platform_driver pcf50633_gpio_driver = {
- .driver = {
- .name = "pcf50633-gpio",
- },
- .probe = pcf50633_gpio_probe,
- .remove = __devexit_p(pcf50633_gpio_remove),
-};
+ reg = gpio - PCF50633_GPIO1 + PCF50633_REG_GPIO1CFG;
+ val = pcf50633_reg_read(pcf, reg);
-static int __init pcf50633_gpio_init(void)
-{
- return platform_driver_register(&pcf50633_gpio_driver);
+ return val & (1 << 3);
}
-module_init(pcf50633_gpio_init);
+EXPORT_SYMBOL_GPL(pcf50633_gpio_invert_get);
+
+static const u8 pcf50633_regulator_registers[PCF50633_NUM_REGULATORS] = {
+ [PCF50633_REGULATOR_AUTO] = PCF50633_REG_AUTOOUT,
+ [PCF50633_REGULATOR_DOWN1] = PCF50633_REG_DOWN1OUT,
+ [PCF50633_REGULATOR_DOWN2] = PCF50633_REG_DOWN2OUT,
+ [PCF50633_REGULATOR_MEMLDO] = PCF50633_REG_MEMLDOOUT,
+ [PCF50633_REGULATOR_LDO1] = PCF50633_REG_LDO1OUT,
+ [PCF50633_REGULATOR_LDO2] = PCF50633_REG_LDO2OUT,
+ [PCF50633_REGULATOR_LDO3] = PCF50633_REG_LDO3OUT,
+ [PCF50633_REGULATOR_LDO4] = PCF50633_REG_LDO4OUT,
+ [PCF50633_REGULATOR_LDO5] = PCF50633_REG_LDO5OUT,
+ [PCF50633_REGULATOR_LDO6] = PCF50633_REG_LDO6OUT,
+ [PCF50633_REGULATOR_HCLDO] = PCF50633_REG_HCLDOOUT,
+};
-static void __exit pcf50633_gpio_exit(void)
+void pcf50633_gpio_power_supply_set(struct pcf50633 *pcf,
+ int gpio, int regulator, int on)
{
- platform_driver_unregister(&pcf50633_gpio_driver);
-}
-module_exit(pcf50633_gpio_exit);
+ u8 reg, val;
-MODULE_AUTHOR("Balaji Rao <balajirrao@openmoko.org>");
-MODULE_DESCRIPTION("PCF50633 gpio driver");
-MODULE_LICENSE("GPL");
-MODULE_ALIAS("platform:pcf50633-gpio");
+ /* the *ENA register is always one after the *OUT register */
+ reg = pcf50633_regulator_registers[regulator] + 1;
+
+ val = (!!on << (gpio - PCF50633_GPIO1));
+ pcf50633_reg_set_bit_mask(pcf, reg, val, val);
+}
+EXPORT_SYMBOL_GPL(pcf50633_gpio_power_supply_set);