aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--arch/arm/mach-s3c2410/Kconfig19
-rw-r--r--arch/arm/mach-s3c2410/Makefile1
-rw-r--r--arch/arm/mach-s3c2410/include/mach/gta01.h67
-rw-r--r--arch/arm/mach-s3c2410/mach-gta01.c997
-rw-r--r--drivers/input/misc/Kconfig7
-rw-r--r--drivers/input/misc/Makefile1
-rw-r--r--drivers/input/misc/pcf50606-input.c138
-rw-r--r--drivers/mfd/Kconfig23
-rw-r--r--drivers/mfd/Makefile5
-rw-r--r--drivers/mfd/pcf50606-adc.c278
-rw-r--r--drivers/mfd/pcf50606-core.c676
-rw-r--r--drivers/mfd/pcf50606-gpo.c119
-rw-r--r--drivers/power/Kconfig6
-rw-r--r--drivers/power/Makefile1
-rw-r--r--drivers/power/pcf50606-charger.c243
-rw-r--r--drivers/regulator/Kconfig6
-rw-r--r--drivers/regulator/Makefile1
-rw-r--r--drivers/regulator/pcf50606-regulator.c384
-rw-r--r--drivers/rtc/Kconfig7
-rw-r--r--drivers/rtc/Makefile1
-rw-r--r--drivers/rtc/rtc-pcf50606.c339
-rw-r--r--drivers/watchdog/Kconfig7
-rw-r--r--drivers/watchdog/Makefile1
-rw-r--r--drivers/watchdog/pcf50606_wdt.c216
-rw-r--r--include/linux/mfd/pcf50606/adc.h72
-rw-r--r--include/linux/mfd/pcf50606/core.h172
-rw-r--r--include/linux/mfd/pcf50606/gpo.h42
-rw-r--r--include/linux/mfd/pcf50606/mbc.h52
-rw-r--r--include/linux/mfd/pcf50606/pmic.h73
29 files changed, 3954 insertions, 0 deletions
diff --git a/arch/arm/mach-s3c2410/Kconfig b/arch/arm/mach-s3c2410/Kconfig
index 41bb65d5b91..d336ac42289 100644
--- a/arch/arm/mach-s3c2410/Kconfig
+++ b/arch/arm/mach-s3c2410/Kconfig
@@ -139,4 +139,23 @@ config MACH_QT2410
help
Say Y here if you are using the Armzone QT2410
+config MACH_NEO1973_GTA01
+ bool "FIC Neo1973 GSM Phone (GTA01 Hardware)"
+ select CPU_S3C2410
+ select MACH_NEO1973
+ select S3C_DEV_USB_HOST
+ select MFD_PCF50606
+ select INPUT_PCF50606_PMU
+ select PCF50606_ADC
+ select PCF50606_GPIO
+ select RTC_DRV_PCF50606
+ select REGULATOR_PCF50606
+ select CHARGER_PCF50606
+ select PCF50606_WATCHDOG
+ select POWER_SUPPLY
+ select BATTERY_GTA01
+ select S3C24XX_ADC
+ help
+ Say Y here if you are using the FIC Neo1973 GSM Phone
+
endmenu
diff --git a/arch/arm/mach-s3c2410/Makefile b/arch/arm/mach-s3c2410/Makefile
index fca02f82711..ed3939d2cf7 100644
--- a/arch/arm/mach-s3c2410/Makefile
+++ b/arch/arm/mach-s3c2410/Makefile
@@ -37,3 +37,4 @@ obj-$(CONFIG_SIMTEC_NOR) += nor-simtec.o
# machine additions
obj-$(CONFIG_MACH_BAST_IDE) += bast-ide.o
+obj-$(CONFIG_MACH_NEO1973_GTA01) += mach-gta01.o
diff --git a/arch/arm/mach-s3c2410/include/mach/gta01.h b/arch/arm/mach-s3c2410/include/mach/gta01.h
new file mode 100644
index 00000000000..673a1161105
--- /dev/null
+++ b/arch/arm/mach-s3c2410/include/mach/gta01.h
@@ -0,0 +1,67 @@
+#ifndef _GTA01_H
+#define _GTA01_H
+
+#include <mach/regs-gpio.h>
+#include <mach/irqs.h>
+
+/* Different hardware revisions, passed in ATAG_REVISION by u-boot */
+#define GTA01v3_SYSTEM_REV 0x00000130
+#define GTA01v4_SYSTEM_REV 0x00000140
+#define GTA01Bv2_SYSTEM_REV 0x00000220
+#define GTA01Bv3_SYSTEM_REV 0x00000230
+#define GTA01Bv4_SYSTEM_REV 0x00000240
+
+/* !!!!!!!!!!! */
+#define S3C_SYSTEM_REV_ATAG GTA01Bv2_SYSTEM_REV
+
+/* Backlight */
+
+/* Definitions common to all revisions */
+#define GTA01_GPIO_BACKLIGHT S3C2410_GPB(0)
+#define GTA01_GPIO_GPS_PWRON S3C2410_GPB(1)
+#define GTA01_GPIO_MODEM_RST S3C2410_GPB(6)
+#define GTA01_GPIO_MODEM_ON S3C2410_GPB(7)
+#define GTA01_GPIO_LCD_RESET S3C2410_GPC(6)
+#define GTA01_GPIO_PMU_IRQ S3C2410_GPG(8)
+#define GTA01_GPIO_JACK_INSERT S3C2410_GPF(4)
+#define GTA01_GPIO_nSD_DETECT S3C2410_GPF(5)
+#define GTA01_GPIO_AUX_KEY S3C2410_GPF(6)
+#define GTA01_GPIO_HOLD_KEY S3C2410_GPF(7)
+
+#define GTA01_IRQ_MODEM IRQ_EINT1
+#define GTA01_IRQ_JACK_INSERT IRQ_EINT4
+#define GTA01_IRQ_nSD_DETECT IRQ_EINT5
+#define GTA01_IRQ_AUX_KEY IRQ_EINT6
+
+/* GTA01v3 */
+#define GTA01v3_GPIO_nGSM_EN S3C2410_GPG(9)
+
+/* GTA01v4 */
+#define GTA01_GPIO_MODEM_DNLOAD S3C2410_GPG(0)
+
+/* GTA01Bv2 */
+#define GTA01Bv2_GPIO_nGSM_EN S3C2410_GPF(2)
+#define GTA01Bv2_GPIO_VIBRATOR_ON S3C2410_GPB(10)
+#define GTA01Bv2_IRQ_PCF50606 IRQ_EINT16
+
+/* GTA01Bv3 */
+#define GTA01_GPIO_GPS_EN_3V3 S3C2410_GPG(9)
+
+#define GTA01_GPIO_SDMMC_ON S3C2410_GPB(2)
+#define GTA01_GPIO_BT_EN S3C2410_GPB(5)
+#define GTA01_GPIO_USB_PULLUP S3C2410_GPB(9)
+
+#define GTA01_GPIO_GPS_EN_2V8 S3C2410_GPG(9)
+#define GTA01_GPIO_GPS_EN_3V S3C2410_GPG(10)
+#define GTA01_GPIO_GPS_RESET S3C2410_GPC(0)
+
+/* GTA01Bv4 */
+#define GTA01Bv4_GPIO_nNAND_WP S3C2410_GPA(16)
+#define GTA01Bv4_GPIO_VIBRATOR_ON S3C2410_GPB(3)
+#define GTA01Bv4_GPIO_PMU_IRQ S3C2410_GPG(1)
+
+#define GTA01Bv4_IRQ_PCF50606 IRQ_EINT9
+
+extern struct pcf50606 *gta01_pcf;
+
+#endif /* _GTA01_H */
diff --git a/arch/arm/mach-s3c2410/mach-gta01.c b/arch/arm/mach-s3c2410/mach-gta01.c
new file mode 100644
index 00000000000..1602f06d05c
--- /dev/null
+++ b/arch/arm/mach-s3c2410/mach-gta01.c
@@ -0,0 +1,997 @@
+/*
+ * linux/arch/arm/mach-s3c2410/mach-gta01.c
+ *
+ * S3C2410 Machine Support for the FIC Neo1973 GTA01
+ *
+ * Copyright (C) 2006-2007 by Openmoko, Inc.
+ * Author: Harald Welte <laforge@openmoko.org>
+ * Copyright (C) 2009, Lars-Peter Clausen <lars@metafoo.de>
+ * All rights reserved.
+ *
+ * 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/kernel.h>
+#include <linux/types.h>
+#include <linux/interrupt.h>
+#include <linux/init.h>
+#include <linux/workqueue.h>
+#include <linux/platform_device.h>
+#include <linux/i2c.h>
+#include <linux/serial_core.h>
+#include <linux/mmc/mmc.h>
+#include <linux/mmc/host.h>
+#include <linux/gta01_battery.h>
+
+#include <linux/mtd/mtd.h>
+#include <linux/mtd/nand.h>
+#include <linux/mtd/nand_ecc.h>
+#include <linux/mtd/partitions.h>
+
+#include <linux/mmc/host.h>
+
+#include <linux/mfd/pcf50606/core.h>
+#include <linux/mfd/pcf50606/pmic.h>
+#include <linux/mfd/pcf50606/mbc.h>
+#include <linux/mfd/pcf50606/adc.h>
+
+/*#include <linux/gta01_battery.h>*/
+
+#include <linux/regulator/machine.h>
+#include <linux/regulator/consumer.h>
+
+
+#include <asm/mach/arch.h>
+#include <asm/mach/map.h>
+#include <asm/mach/irq.h>
+
+#include <mach/hardware.h>
+#include <mach/io.h>
+#include <asm/mach-types.h>
+
+#include <mach/regs-gpio.h>
+#include <mach/gpio-fns.h>
+#include <mach/fb.h>
+
+#include <linux/spi/spi.h>
+#include <linux/spi/spi_gpio.h>
+
+#include <mach/gta01.h>
+
+#include <plat/regs-serial.h>
+#include <plat/nand.h>
+#include <plat/devs.h>
+#include <plat/cpu.h>
+#include <plat/pm.h>
+#include <plat/udc.h>
+#include <plat/iic.h>
+#include <plat/mci.h>
+#include <plat/usb-control.h>
+/*#include <mach/neo1973-pm-gsm.h>*/
+
+#include <linux/jbt6k74.h>
+
+#include <linux/input.h>
+#include <linux/gpio_keys.h>
+
+#include <linux/pwm_backlight.h>
+#include <linux/leds_pwm.h>
+
+#include <linux/gpio.h>
+
+/*
+#include <../drivers/input/touchscreen/ts_filter_chain.h>
+#ifdef CONFIG_TOUCHSCREEN_FILTER
+#include <../drivers/input/touchscreen/ts_filter_linear.h>
+#include <../drivers/input/touchscreen/ts_filter_mean.h>
+#include <../drivers/input/touchscreen/ts_filter_median.h>
+#include <../drivers/input/touchscreen/ts_filter_group.h>
+#endif
+*/
+
+static struct map_desc gta01_iodesc[] __initdata = {
+ {
+ .virtual = 0xe0000000,
+ .pfn = __phys_to_pfn(S3C2410_CS3+0x01000000),
+ .length = SZ_1M,
+ .type = MT_DEVICE
+ },
+};
+
+#define UCON S3C2410_UCON_DEFAULT
+#define ULCON S3C2410_LCON_CS8 | S3C2410_LCON_PNONE | S3C2410_LCON_STOPB
+#define UFCON S3C2410_UFCON_RXTRIG8 | S3C2410_UFCON_FIFOMODE
+/* UFCON for the gta01 sets the FIFO trigger level at 4, not 8 */
+#define UFCON_GTA01_PORT0 S3C2410_UFCON_FIFOMODE
+
+static struct s3c2410_uartcfg gta01_uartcfgs[] = {
+ [0] = {
+ .hwport = 0,
+ .flags = 0,
+ .ucon = UCON,
+ .ulcon = ULCON,
+ .ufcon = UFCON_GTA01_PORT0,
+ },
+ [1] = {
+ .hwport = 1,
+ .flags = 0,
+ .ucon = UCON,
+ .ulcon = ULCON,
+ .ufcon = UFCON,
+ },
+};
+
+/* TODO */
+static void gta01_pmu_event_callback(struct pcf50606 *pcf, int irq)
+{
+ /*TODO : Handle ACD here */
+}
+#if 0
+/* FIXME : Goes away when ACD is handled above */
+static int pmu_callback(struct device *dev, unsigned int feature,
+ enum pmu_event event)
+{
+ switch (feature) {
+ case PCF50606_FEAT_ACD:
+ switch (event) {
+ case PMU_EVT_INSERT:
+ pcf50606_charge_fast(pcf50606_global, 1);
+ break;
+ case PMU_EVT_REMOVE:
+ pcf50606_charge_fast(pcf50606_global, 0);
+ break;
+ default:
+ break;
+ }
+ break;
+ default:
+ break;
+ }
+
+ return 0;
+}
+#endif
+struct pcf50606 *gta01_pcf;
+
+static struct platform_device gta01_pm_gsm_dev = {
+ .name = "neo1973-pm-gsm",
+};
+
+static struct platform_device gta01_pm_bt_dev = {
+ .name = "neo1973-pm-bt",
+};
+static struct platform_device gta01_pm_gps_dev = {
+ .name = "neo1973-pm-gps",
+};
+
+static struct regulator_consumer_supply ioreg_consumers[] = {
+ {
+ .dev = &gta01_pm_gps_dev.dev,
+ .supply = "GPS_2V8",
+ },
+};
+
+static struct regulator_consumer_supply d1reg_consumers[] = {
+ {
+ .dev = &gta01_pm_gps_dev.dev,
+ .supply = "GPS_3V",
+ },
+ {
+ .dev = &gta01_pm_bt_dev.dev,
+ .supply = "BT_3V1",
+ },
+};
+
+static struct regulator_consumer_supply dcd_consumers[] = {
+ {
+ .dev = &gta01_pm_gps_dev.dev,
+ .supply = "GPS_3V3",
+ },
+ {
+ .dev = &gta01_pm_gps_dev.dev,
+ .supply = "GPS_1V5",
+ },
+};
+
+static struct regulator_consumer_supply d2reg_consumers[] = {
+ {
+ .dev = &gta01_pm_gps_dev.dev,
+ .supply = "GPS_2V5",
+ },
+ {
+ .dev = &s3c_device_sdi.dev,
+ .supply = "SD_3V3",
+ },
+};
+
+#if 0
+/* This will come with 2.6.32. Don't forget to uncomment it then. */
+static struct regulator_consumer_supply lpreg_consumers[] = {
+ REGULATOR_SUPPLY("VDC", "jbt6k74"),
+ REGULATOR_SUPPLY("VDDIO", "jbt6k74"),
+};
+#else
+static struct regulator_consumer_supply lpreg_consumers[] = {
+ { .supply = "VDC", },
+ { .supply = "VDDIO", },
+};
+#endif
+
+static int gta01_bat_get_charging_status(void)
+{
+ struct pcf50606 *pcf = gta01_pcf;
+ u8 mbcc1, chgmod;
+
+ mbcc1 = pcf50606_reg_read(pcf, PCF50606_REG_MBCC1);
+ chgmod = mbcc1 & PCF50606_MBCC1_CHGMOD_MASK;
+
+ if (chgmod == PCF50606_MBCC1_CHGMOD_IDLE)
+ return 0;
+ else
+ return 1;
+}
+
+static int gta01_bat_get_voltage(void)
+{
+ struct pcf50606 *pcf = gta01_pcf;
+ u16 adc, mv = 0;
+
+ adc = pcf50606_adc_sync_read(pcf, PCF50606_ADCMUX_BATVOLT_RES);
+ mv = (adc * 6000) / 1024;
+
+ return mv * 1000;
+}
+
+static int gta01_bat_get_current(void)
+{
+ struct pcf50606 *pcf = gta01_pcf;
+ u16 adc_battvolt, adc_adcin1;
+ s32 res;
+
+ adc_battvolt = pcf50606_adc_sync_read(pcf, PCF50606_ADCMUX_BATVOLT_SUBTR);
+ adc_adcin1 = pcf50606_adc_sync_read(pcf, PCF50606_ADCMUX_ADCIN1_SUBTR);
+ res = (adc_battvolt - adc_adcin1) * 2400;
+
+ /*rsense is 220 milli */
+ return (res * 1000) / (220 * 1024) * 1000;
+}
+
+static struct gta01_bat_platform_data gta01_bat_pdata = {
+ .get_charging_status = gta01_bat_get_charging_status,
+ .get_voltage = gta01_bat_get_voltage,
+ .get_current = gta01_bat_get_current,
+};
+
+static struct platform_device gta01_bat = {
+ .name = "gta01_battery",
+ .id = -1,
+ .dev = {
+ .platform_data = &gta01_bat_pdata,
+ }
+};
+
+static void gta01_pcf_probe_done(struct pcf50606 *pcf)
+{
+ gta01_pcf = pcf;
+ gta01_bat.dev.parent = pcf->dev;
+ platform_device_register(&gta01_bat);
+}
+
+static int gps_registered_regulators = 0;
+
+static void gta01_pmu_regulator_registered(struct pcf50606 *pcf, int id)
+{
+ switch(id) {
+ case PCF50606_REGULATOR_D1REG:
+ platform_device_register(&gta01_pm_bt_dev);
+ gps_registered_regulators++;
+ break;
+ case PCF50606_REGULATOR_D2REG:
+ gps_registered_regulators++;
+ break;
+ case PCF50606_REGULATOR_IOREG:
+ case PCF50606_REGULATOR_DCD:
+ gps_registered_regulators++;
+ break;
+ }
+
+ /* All GPS related regulators registered ? */
+/* if (gps_registered_regulators == 4)
+ platform_device_register(&gta01_pm_gps_dev);*/
+}
+
+static struct pcf50606_platform_data gta01_pcf_pdata = {
+ .resumers = {
+ [0] = PCF50606_INT1_ALARM |
+ PCF50606_INT1_ONKEYF |
+ PCF50606_INT1_EXTONR,
+ [1] = PCF50606_INT2_CHGWD10S |
+ PCF50606_INT2_CHGPROT |
+ PCF50606_INT2_CHGERR,
+ [2] = PCF50606_INT3_LOWBAT |
+ PCF50606_INT3_HIGHTMP |
+ PCF50606_INT3_ACDINS,
+ },
+ .mbc_event_callback = gta01_pmu_event_callback,
+ .reg_init_data = {
+ /* BT, GPS */
+ [PCF50606_REGULATOR_D1REG] = {
+ .constraints = {
+ .min_uV = 3000000,
+ .max_uV = 3150000,
+ .valid_modes_mask = REGULATOR_MODE_NORMAL,
+ .apply_uV = 1,
+ },
+ .num_consumer_supplies = ARRAY_SIZE(d1reg_consumers),
+ .consumer_supplies = d1reg_consumers,
+ },
+ /* GPS */
+ [PCF50606_REGULATOR_D2REG] = {
+ .constraints = {
+ .min_uV = 1650000,
+ .max_uV = 3300000,
+ .valid_modes_mask = REGULATOR_MODE_NORMAL,
+ .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE,
+ .apply_uV = 1,
+ },
+ .num_consumer_supplies = ARRAY_SIZE(d2reg_consumers),
+ .consumer_supplies = d2reg_consumers,
+
+ },
+ /* RTC/Standby */
+ [PCF50606_REGULATOR_D3REG] = {
+ .constraints = {
+ .min_uV = 1800000,
+ .max_uV = 2100000,
+ .valid_modes_mask = REGULATOR_MODE_NORMAL,
+ .always_on = 1,
+ .state_mem = {
+ .enabled = 1,
+ },
+ },
+ .num_consumer_supplies = 0,
+ },
+ /* GPS */
+ [PCF50606_REGULATOR_DCD] = {
+ .constraints = {
+ .min_uV = 1500000,
+ .max_uV = 1500000,
+ .valid_modes_mask = REGULATOR_MODE_NORMAL,
+ .apply_uV = 1,
+ },
+ .num_consumer_supplies = ARRAY_SIZE(dcd_consumers),
+ .consumer_supplies = dcd_consumers,
+ },
+
+ /* S3C2410 Memory and IO, Vibrator, RAM, NAND, AMP, SD Card */
+ [PCF50606_REGULATOR_DCDE] = {
+ .constraints = {
+ .min_uV = 3300000,
+ .max_uV = 3300000,
+ .valid_modes_mask = REGULATOR_MODE_NORMAL,
+ .apply_uV = 1,
+ .always_on = 1,
+ .state_mem = {
+ .enabled = 1,
+ },
+ },
+ .num_consumer_supplies = 0,
+ },
+ /* SoC */
+ [PCF50606_REGULATOR_DCUD] = {
+ .constraints = {
+ .min_uV = 2100000,
+ .max_uV = 2100000,
+ .valid_modes_mask = REGULATOR_MODE_NORMAL,
+ .apply_uV = 1,
+ .always_on = 1,
+ .state_mem = {
+ .enabled = 1,
+ },
+ },
+ .num_consumer_supplies = 0,
+ },
+ /* Codec, GPS */
+ [PCF50606_REGULATOR_IOREG] = {
+ .constraints = {
+ .min_uV = 3300000,
+ .max_uV = 3300000,
+ .valid_modes_mask = REGULATOR_MODE_NORMAL,
+ .apply_uV = 1,
+ .always_on = 1,
+ },
+ .num_consumer_supplies = ARRAY_SIZE(ioreg_consumers),
+ .consumer_supplies = ioreg_consumers,
+
+ },
+ /* LCM */
+ [PCF50606_REGULATOR_LPREG] = {
+ .constraints = {
+ .min_uV = 3300000,
+ .max_uV = 3300000,
+ .valid_modes_mask = REGULATOR_MODE_NORMAL,
+ .apply_uV = 1,
+ },
+ .num_consumer_supplies = ARRAY_SIZE(lpreg_consumers),
+ .consumer_supplies = lpreg_consumers,
+ },
+ },
+ .probe_done = gta01_pcf_probe_done,
+ .regulator_registered = gta01_pmu_regulator_registered,
+};
+
+static void cfg_pmu_vrail(struct regulator_init_data *vrail,
+ unsigned int suspend_on, unsigned int min,
+ unsigned int max)
+{
+ vrail->constraints.state_mem.enabled = suspend_on;
+ vrail->constraints.min_uV = min;
+ vrail->constraints.max_uV = max;
+ vrail->constraints.apply_uV = 1;
+}
+
+static void mangle_pmu_pdata_by_system_rev(void)
+{
+ struct regulator_init_data *reg_init_data;
+
+ reg_init_data = gta01_pcf_pdata.reg_init_data;
+
+ switch (S3C_SYSTEM_REV_ATAG) {
+ case GTA01Bv4_SYSTEM_REV:
+
+ /* FIXME : gta01_pcf_pdata.used_features |= PCF50606_FEAT_ACD; */
+ break;
+ case GTA01Bv3_SYSTEM_REV:
+ case GTA01Bv2_SYSTEM_REV:
+ reg_init_data[PCF50606_REGULATOR_D3REG].constraints.state_mem.enabled = 1;
+ break;
+ case GTA01v4_SYSTEM_REV:
+ cfg_pmu_vrail(&reg_init_data[PCF50606_REGULATOR_DCUD],
+ 1, 18000000, 1800000);
+ cfg_pmu_vrail(&reg_init_data[PCF50606_REGULATOR_D1REG],
+ 0, 3000000, 3000000);
+ cfg_pmu_vrail(&reg_init_data[PCF50606_REGULATOR_D3REG],
+ 0, 2800000, 2800000);
+ cfg_pmu_vrail(&reg_init_data[PCF50606_REGULATOR_DCD],
+ 0, 3500000, 3500000);
+ break;
+ case GTA01v3_SYSTEM_REV:
+ cfg_pmu_vrail(&reg_init_data[PCF50606_REGULATOR_D1REG],
+ 0, 3000000, 3000000);
+ cfg_pmu_vrail(&reg_init_data[PCF50606_REGULATOR_D2REG],
+ 0, 3300000, 3300000);
+ cfg_pmu_vrail(&reg_init_data[PCF50606_REGULATOR_D3REG],
+ 0, 3300000, 3300000);
+ cfg_pmu_vrail(&reg_init_data[PCF50606_REGULATOR_DCD],
+ 0, 3300000, 3300000);
+ cfg_pmu_vrail(&reg_init_data[PCF50606_REGULATOR_DCUD],
+ 1, 1800000, 1800000);
+ cfg_pmu_vrail(&reg_init_data[PCF50606_REGULATOR_IOREG],
+ 0, 2800000, 2800000);
+ break;
+ }
+}
+
+static void gta01_power_off(void)
+{/*
+ pcf50606_reg_write(gta01_pcf, PCF50606_REG_OOCC1,
+ PCF50606_OOCC1_GOSTDBY);*/
+}
+
+/* LCD driver info */
+
+/* Configuration for 480x640 toppoly TD028TTEC1.
+ * Do not mark this as __initdata or it will break! */
+static struct s3c2410fb_display gta01_displays[] = {
+ {
+ .type = S3C2410_LCDCON1_TFT,
+ .width = 43,
+ .height = 58,
+ .xres = 480,
+ .yres = 640,
+ .bpp = 16,
+
+ .pixclock = 40000, /* HCLK/4 */
+ .left_margin = 104,
+ .right_margin = 8,
+ .hsync_len = 8,
+ .upper_margin = 2,
+ .lower_margin = 16,
+ .vsync_len = 2,
+ .lcdcon5 = S3C2410_LCDCON5_FRM565 |
+ S3C2410_LCDCON5_INVVCLK |
+ S3C2410_LCDCON5_INVVLINE |
+ S3C2410_LCDCON5_INVVFRAME |
+ S3C2410_LCDCON5_PWREN |
+ S3C2410_LCDCON5_HWSWP,
+ },
+ {
+ .type = S3C2410_LCDCON1_TFT,
+ .width = 43,
+ .height = 58,
+ .xres = 480,
+ .yres = 640,
+ .bpp = 32,
+
+ .pixclock = 40000, /* HCLK/4 */
+ .left_margin = 104,
+ .right_margin = 8,
+ .hsync_len = 8,
+ .upper_margin = 2,
+ .lower_margin = 16,
+ .vsync_len = 2,
+ .lcdcon5 = S3C2410_LCDCON5_FRM565 |
+ S3C2410_LCDCON5_INVVCLK |
+ S3C2410_LCDCON5_INVVLINE |
+ S3C2410_LCDCON5_INVVFRAME |
+ S3C2410_LCDCON5_PWREN |
+ S3C2410_LCDCON5_HWSWP,
+ },
+ {
+ .type = S3C2410_LCDCON1_TFT,
+ .width = 43,
+ .height = 58,
+ .xres = 240,
+ .yres = 320,
+ .bpp = 16,
+
+ .pixclock = 40000, /* HCLK/4 */
+ .left_margin = 104,
+ .right_margin = 8,
+ .hsync_len = 8,
+ .upper_margin = 2,
+ .lower_margin = 16,
+ .vsync_len = 2,
+ .lcdcon5 = S3C2410_LCDCON5_FRM565 |
+ S3C2410_LCDCON5_INVVCLK |
+ S3C2410_LCDCON5_INVVLINE |
+ S3C2410_LCDCON5_INVVFRAME |
+ S3C2410_LCDCON5_PWREN |
+ S3C2410_LCDCON5_HWSWP,
+ },
+};
+
+static struct s3c2410fb_mach_info gta01_lcd_cfg __initdata = {
+ .displays = gta01_displays,
+ .num_displays = ARRAY_SIZE(gta01_displays),
+ .default_display = 0,
+
+ .lpcsel = ((0xCE6) & ~7) | 1<<4,
+};
+
+static struct s3c2410_nand_set gta01_nand_sets[] = {
+ [0] = {
+ .name = "neo1973-nand",
+ .nr_chips = 1,
+/* .flags = S3C2410_NAND_BBT,*/
+ },
+};
+
+static struct s3c2410_platform_nand gta01_nand_info = {
+ .tacls = 20,
+ .twrph0 = 60,
+ .twrph1 = 20,
+ .nr_sets = ARRAY_SIZE(gta01_nand_sets),
+ .sets = gta01_nand_sets,
+};
+
+/* MMC */
+
+static void gta01_mmc_set_power(unsigned char power_mode, unsigned short vdd)
+{
+ printk(KERN_DEBUG "mmc_set_power(power_mode=%u, vdd=%u)\n",
+ power_mode, vdd);
+
+ switch (power_mode) {
+ case MMC_POWER_OFF:
+ gpio_set_value(GTA01_GPIO_SDMMC_ON, 1);
+ break;
+ case MMC_POWER_UP:
+ gpio_set_value(GTA01_GPIO_SDMMC_ON, 0);
+ break;
+ }
+}
+
+static struct s3c24xx_mci_pdata gta01_mmc_cfg = {
+ .gpio_detect = GTA01_GPIO_nSD_DETECT,
+ .set_power = &gta01_mmc_set_power,
+ .ocr_avail = MMC_VDD_32_33,
+};
+
+/* UDC */
+
+static void gta01_udc_command(enum s3c2410_udc_cmd_e cmd)
+{
+ printk("udc command: %d\n", cmd);
+ switch (cmd) {
+ case S3C2410_UDC_P_ENABLE:
+ gpio_set_value(GTA01_GPIO_USB_PULLUP, 1);
+ break;
+ case S3C2410_UDC_P_DISABLE:
+ gpio_set_value(GTA01_GPIO_USB_PULLUP, 0);
+ break;
+ default:
+ break;
+ }
+}
+
+/* use a work queue, since I2C API inherently schedules
+ * and we get called in hardirq context from UDC driver */
+
+struct vbus_draw {
+ struct work_struct work;
+ int ma;
+};
+static struct vbus_draw gta01_udc_vbus_drawer;
+
+static void __gta01_udc_vbus_draw(struct work_struct *work)
+{
+ /*
+ * This is a fix to work around boot-time ordering problems if the
+ * s3c2410_udc is initialized before the pcf50606 driver has defined
+ * pcf50606_global
+ */
+ if (!gta01_pcf)
+ return;
+#if 0
+ if (gta01_udc_vbus_drawer.ma >= 500) {
+ /* enable fast charge */
+ printk(KERN_DEBUG "udc: enabling fast charge\n");
+ pcf50606_charge_fast(gta01_pcf, 1);
+ } else {
+ /* disable fast charge */
+ printk(KERN_DEBUG "udc: disabling fast charge\n");
+ pcf50606_charge_fast(gta01_pcf, 0);
+ }
+#endif
+}
+
+static void gta01_udc_vbus_draw(unsigned int ma)
+{
+ gta01_udc_vbus_drawer.ma = ma;
+ schedule_work(&gta01_udc_vbus_drawer.work);
+}
+
+static struct s3c2410_udc_mach_info gta01_udc_cfg = {
+ .vbus_draw = gta01_udc_vbus_draw,
+ .udc_command = gta01_udc_command,
+};
+
+/* Touchscreen configuration. */
+
+#if 0
+
+#ifdef CONFIG_TOUCHSCREEN_FILTER
+const static struct ts_filter_group_configuration gta01_ts_group = {
+ .length = 12,
+ .close_enough = 10,
+ .threshold = 6, /* At least half of the points in a group. */
+ .attempts = 10,
+};
+
+const static struct ts_filter_median_configuration gta01_ts_median = {
+ .extent = 20,
+ .decimation_below = 3,
+ .decimation_threshold = 8 * 3,
+ .decimation_above = 4,
+};
+
+const static struct ts_filter_mean_configuration gta01_ts_mean = {
+ .length = 4,
+};
+
+const static struct ts_filter_linear_configuration gta01_ts_linear = {
+ .constants = {1, 0, 0, 0, 1, 0, 1}, /* Don't modify coords. */
+ .coord0 = 0,
+ .coord1 = 1,
+};
+#endif
+
+const static struct ts_filter_chain_configuration gta01_filter_configuration[] =
+{
+#ifdef CONFIG_TOUCHSCREEN_FILTER
+ {&ts_filter_group_api, &gta01_ts_group.config},
+ {&ts_filter_median_api, &gta01_ts_median.config},
+ {&ts_filter_mean_api, &gta01_ts_mean.config},
+ {&ts_filter_linear_api, &gta01_ts_linear.config},
+#endif
+ {NULL, NULL},
+};
+
+const static struct s3c2410_ts_mach_info gta01_ts_cfg = {
+ .delay = 10000,
+ .presc = 0xff, /* slow as we can go */
+ .filter_config = gta01_filter_configuration,
+};
+#endif
+
+/* SPI / Display */
+
+const struct jbt6k74_platform_data gta01_jbt6k74_pdata = {
+ .gpio_reset = GTA01_GPIO_LCD_RESET,
+};
+
+static struct spi_board_info gta01_spi_board_info[] = {
+ {
+ .modalias = "jbt6k74",
+ .platform_data = &gta01_jbt6k74_pdata,
+ .controller_data = (void*)S3C2410_GPG(3),
+ .max_speed_hz = 10 * 1000 * 1000,
+ .bus_num = 1,
+ },
+};
+
+static struct spi_gpio_platform_data spigpio_platform_data = {
+ .sck = S3C2410_GPG(7),
+ .mosi = S3C2410_GPG(6),
+ .miso = S3C2410_GPG(5),
+ .num_chipselect = 1,
+};
+
+static struct platform_device gta01_lcm_spigpio_device = {
+ .name = "spi_gpio",
+ .id = 1,
+ .dev = {
+ .platform_data = &spigpio_platform_data,
+ },
+};
+
+/* Backlight */
+
+static struct platform_pwm_backlight_data gta01_bl_pdata = {
+ .max_brightness = 0xff,
+ .dft_brightness = 0xff,
+ .pwm_period_ns = 5000000, /* TODO: Tweak this */
+ .pwm_id = 0,
+};
+
+static struct platform_device gta01_bl_device = {
+ .name = "pwm-backlight",
+ .id = -1,
+ .dev = {
+ .platform_data = &gta01_bl_pdata,
+ .parent = &s3c_device_timer[0].dev,
+ },
+};
+
+/* Vibrator */
+static struct led_pwm gta01_vibrator = {
+ .name = "gta01::vibrator",
+ .max_brightness = 0xff,
+ .pwm_period_ns = 500000, /* TODO: Tweak this */
+ .pwm_id = 3,
+};
+
+static struct led_pwm_platform_data gta01_vibrator_pdata = {
+ .num_leds = 1,
+ .leds = &gta01_vibrator,
+};
+
+static struct platform_device gta01_vibrator_device_bv4 = {
+ .name = "leds_pwm",
+ .id = -1,
+ .dev = {
+ .platform_data = &gta01_vibrator_pdata,
+ .parent = &s3c_device_timer[3].dev,
+ }
+};
+
+static struct gpio_led gta01_vibrator_bv2 = {
+ .name = "gta01::vibrator",
+ .gpio = GTA01Bv2_GPIO_VIBRATOR_ON,
+ .default_state = LEDS_GPIO_DEFSTATE_OFF,
+};
+
+static struct gpio_led_platform_data gta01_vibrator_pdata_bv2 = {
+ .num_leds = 1,
+ .leds = &gta01_vibrator_bv2,
+};
+
+static struct platform_device gta01_vibrator_device_bv2 = {
+ .name = "leds-gpio",
+ .id = -1,
+ .dev = {
+ .platform_data = &gta01_vibrator_pdata_bv2,
+ }
+};
+
+static struct platform_device *gta01_vibrator_device = &gta01_vibrator_device_bv4;
+/* Buttons */
+
+static struct gpio_keys_button gta01_buttons[] = {
+ {
+ .gpio = GTA01_GPIO_AUX_KEY,
+ .code = KEY_PHONE,
+ .desc = "Aux",
+ .type = EV_KEY,
+ .debounce_interval = 100,
+ },
+ {
+ .gpio = GTA01_GPIO_HOLD_KEY,
+ .code = KEY_PAUSE,
+ .desc = "Hold",
+ .type = EV_KEY,
+ .debounce_interval = 100,
+ },
+};
+
+static struct gpio_keys_platform_data gta01_buttons_pdata = {
+ .buttons = gta01_buttons,
+ .nbuttons = ARRAY_SIZE(gta01_buttons),
+};
+
+static struct platform_device gta01_buttons_device = {
+ .name = "gpio-keys",
+ .id = -1,
+ .dev = {
+ .platform_data = &gta01_buttons_pdata,
+ },
+};
+
+/* USB */
+
+static struct s3c2410_hcd_info gta01_usb_info = {
+ .port[0] = {
+ .flags = S3C_HCDFLG_USED,
+ },
+ .port[1] = {
+ .flags = 0,
+ },
+};
+
+static struct platform_device *gta01_devices[] __initdata = {
+ &s3c_device_usb,
+ &s3c_device_lcd,
+ &s3c_device_wdt,
+ &s3c_device_i2c0,
+ &s3c_device_iis,
+ &s3c_device_sdi,
+ &s3c_device_usbgadget,
+ &s3c_device_nand,
+ &s3c_device_adc,
+/* &s3c_device_ts,*/
+ &s3c_device_timer[0],
+ &s3c_device_timer[3],
+ &gta01_bl_device,
+ &gta01_buttons_device,
+ &gta01_pm_gsm_dev,
+};
+
+static struct platform_device *gta01_pmu_child_devices[] = {
+ &gta01_lcm_spigpio_device,
+};
+
+static void __init gta01_map_io(void)
+{
+ s3c24xx_init_io(gta01_iodesc, ARRAY_SIZE(gta01_iodesc));
+ s3c24xx_init_clocks(12*1000*1000);
+ s3c24xx_init_uarts(gta01_uartcfgs, ARRAY_SIZE(gta01_uartcfgs));
+}
+
+static irqreturn_t gta01_modem_irq(int irq, void *param)
+{
+ printk(KERN_DEBUG "GSM wakeup interrupt (IRQ %d)\n", irq);
+/* gta_gsm_interrupts++;*/
+ return IRQ_HANDLED;
+}
+
+static struct i2c_board_info gta01_i2c_devs[] __initdata = {
+ {
+ I2C_BOARD_INFO("pcf50606", 0x08),
+ .irq = GTA01Bv4_IRQ_PCF50606,
+ .platform_data = &gta01_pcf_pdata,
+ },
+ {
+ I2C_BOARD_INFO("lm4857", 0x7c),
+ },
+ {
+ I2C_BOARD_INFO("wm8753", 0x1a),
+ },
+};
+
+static int __init gta01_init_gpio(void)
+{
+ int ret;
+
+ ret = gpio_request(GTA01_GPIO_USB_PULLUP, "udc pullup");
+
+ ret = gpio_direction_output(GTA01_GPIO_USB_PULLUP, 0);
+
+ ret = gpio_request(GTA01_GPIO_SDMMC_ON, "SD/MMC power");
+
+ ret = gpio_direction_output(GTA01_GPIO_SDMMC_ON, 1);
+
+ s3c2410_gpio_cfgpin(GTA01_GPIO_BACKLIGHT, S3C2410_GPB0_TOUT0);
+ if (S3C_SYSTEM_REV_ATAG == GTA01Bv4_SYSTEM_REV)
+ s3c2410_gpio_cfgpin(GTA01Bv4_GPIO_VIBRATOR_ON, S3C2410_GPB3_TOUT3);
+
+ return ret;
+}
+
+static void __init gta01_machine_init(void)
+{
+ int rc;
+
+ gta01_init_gpio();
+
+ if (S3C_SYSTEM_REV_ATAG != GTA01Bv4_SYSTEM_REV) {
+ gta01_vibrator_device = &gta01_vibrator_device_bv2;
+ gta01_i2c_devs[0].irq = GTA01Bv2_IRQ_PCF50606;
+ }
+
+ s3c_device_usb.dev.platform_data = &gta01_usb_info;
+ s3c_device_nand.dev.platform_data = &gta01_nand_info;
+ s3c_device_sdi.dev.platform_data = &gta01_mmc_cfg;
+
+ s3c24xx_fb_set_platdata(&gta01_lcd_cfg);
+
+ INIT_WORK(&gta01_udc_vbus_drawer.work, __gta01_udc_vbus_draw);
+ s3c24xx_udc_set_platdata(&gta01_udc_cfg);
+ s3c_i2c0_set_platdata(NULL);
+
+/* set_s3c2410ts_info(&gta01_ts_cfg);*/
+
+#if 0
+ switch (S3C_SYSTEM_REV_ATAG) {
+ case GTA01v3_SYSTEM_REV:
+ case GTA01v4_SYSTEM_REV:
+ /* just use the default (GTA01_IRQ_PCF50606) */
+ break;
+ case GTA01Bv2_SYSTEM_REV:
+ case GTA01Bv3_SYSTEM_REV:
+ /* just use the default (GTA01_IRQ_PCF50606) */
+ gta01_led_resources[0].start =
+ gta01_led_resources[0].end = GTA01Bv2_GPIO_VIBRATOR_ON;
+ break;
+ case GTA01Bv4_SYSTEM_REV:
+ gta01_i2c_devs[0].irq = GTA01Bv4_IRQ_PCF50606;
+ gta01_led_resources[0].start =
+ gta01_led_resources[0].end = GTA01Bv4_GPIO_VIBRATOR_ON;
+ break;
+ }
+#endif
+ mangle_pmu_pdata_by_system_rev();
+
+ i2c_register_board_info(0, gta01_i2c_devs, ARRAY_SIZE(gta01_i2c_devs));
+ spi_register_board_info(gta01_spi_board_info,
+ ARRAY_SIZE(gta01_spi_board_info));
+
+ platform_add_devices(gta01_devices, ARRAY_SIZE(gta01_devices));
+/* platform_add_devices(gta01_vibrator_device, 1);*/
+
+ s3c_pm_init();
+
+ set_irq_type(GTA01_IRQ_MODEM, IRQ_TYPE_EDGE_RISING);
+ rc = request_irq(GTA01_IRQ_MODEM, gta01_modem_irq, IRQF_DISABLED,
+ "modem", NULL);
+ enable_irq_wake(GTA01_IRQ_MODEM);
+
+ printk(KERN_DEBUG "Enabled GSM wakeup IRQ %d (rc=%d)\n",
+ GTA01_IRQ_MODEM, rc);
+
+ pm_power_off = &gta01_power_off;
+}
+
+MACHINE_START(NEO1973_GTA01, "GTA01")
+ .phys_io = S3C2410_PA_UART,
+ .io_pg_offst = (((u32)S3C24XX_VA_UART) >> 18) & 0xfffc,
+ .boot_params = S3C2410_SDRAM_PA + 0x100,
+ .map_io = gta01_map_io,
+ .init_irq = s3c24xx_init_irq,
+ .init_machine = gta01_machine_init,
+ .timer = &s3c24xx_timer,
+MACHINE_END
diff --git a/drivers/input/misc/Kconfig b/drivers/input/misc/Kconfig
index 1acfa3a05aa..558b73f0100 100644
--- a/drivers/input/misc/Kconfig
+++ b/drivers/input/misc/Kconfig
@@ -237,6 +237,13 @@ config INPUT_PCF50633_PMU
Say Y to include support for delivering PMU events via input
layer on NXP PCF50633.
+config INPUT_PCF50606_PMU
+ tristate "PCF50606 PMU events"
+ depends on MFD_PCF50606
+ help
+ Say Y to include support for delivering PMU events via input
+ layer on NXP PCF50606.
+
config INPUT_GPIO_ROTARY_ENCODER
tristate "Rotary encoders connected to GPIO pins"
depends on GPIOLIB && GENERIC_GPIO
diff --git a/drivers/input/misc/Makefile b/drivers/input/misc/Makefile
index 0d979fd4cd5..730857b6674 100644
--- a/drivers/input/misc/Makefile
+++ b/drivers/input/misc/Makefile
@@ -16,6 +16,7 @@ obj-$(CONFIG_INPUT_IXP4XX_BEEPER) += ixp4xx-beeper.o
obj-$(CONFIG_INPUT_KEYSPAN_REMOTE) += keyspan_remote.o
obj-$(CONFIG_INPUT_M68K_BEEP) += m68kspkr.o
obj-$(CONFIG_INPUT_PCF50633_PMU) += pcf50633-input.o
+obj-$(CONFIG_INPUT_PCF50606_PMU) += pcf50606-input.o
obj-$(CONFIG_INPUT_PCSPKR) += pcspkr.o
obj-$(CONFIG_INPUT_POWERMATE) += powermate.o
obj-$(CONFIG_INPUT_RB532_BUTTON) += rb532_button.o
diff --git a/drivers/input/misc/pcf50606-input.c b/drivers/input/misc/pcf50606-input.c
new file mode 100644
index 00000000000..da78fb92fbc
--- /dev/null
+++ b/drivers/input/misc/pcf50606-input.c
@@ -0,0 +1,138 @@
+/* Philips PCF50606 Input Driver
+ *
+ * (C) 2006-2008 by Openmoko, Inc.
+ * Author: Balaji Rao <balajirrao@openmoko.org>
+ * All rights reserved.
+ *
+ * Broken down from monstrous PCF50606 driver mainly by
+ * Harald Welte, Matt Hsu, Andy Green and Werner Almesberger
+ *
+ * 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.
+ *
+ */
+
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/init.h>
+#include <linux/device.h>
+#include <linux/platform_device.h>
+#include <linux/input.h>
+
+#include <linux/mfd/pcf50606/core.h>
+
+#define PCF50606_OOCS_ONKEY 0x01
+#define PCF50606_OOCS_EXTON 0x02
+
+#define PCF50606_OOCC2_ONKEYDB_NONE 0x00
+#define PCF50606_OOCC2_ONKEYDB_14ms 0x01
+#define PCF50606_OOCC2_ONKEYDB_62ms 0x02
+#define PCF50606_OOCC2_ONKEYDB_500ms 0x03
+#define PCF50606_OOCC2_EXTONDB_NONE 0x00
+#define PCF50606_OOCC2_EXTONDB_14ms 0x04
+#define PCF50606_OOCC2_EXTONDB_62ms 0x08
+#define PCF50606_OOCC2_EXTONDB_500ms 0x0c
+
+#define PCF50606_REG_OOCS 0x01
+
+struct pcf50606_input {
+ struct pcf50606 *pcf;
+ struct input_dev *input_dev;
+};
+
+static void
+pcf50606_input_irq(int irq, void *data)
+{
+ struct pcf50606_input *input;
+ int onkey_released;
+
+ input = data;
+ onkey_released = pcf50606_reg_read(input->pcf, PCF50606_REG_OOCS) &
+ PCF50606_OOCS_ONKEY;
+
+ if (irq == PCF50606_IRQ_ONKEYF && !onkey_released)
+ input_report_key(input->input_dev, KEY_POWER, 1);
+ else if (irq == PCF50606_IRQ_ONKEYR && onkey_released)
+ input_report_key(input->input_dev, KEY_POWER, 0);
+
+ input_sync(input->input_dev);
+}
+
+static int __devinit pcf50606_input_probe(struct platform_device *pdev)
+{
+ struct pcf50606_input *input;
+ struct input_dev *input_dev;
+ int ret;
+
+ input = kzalloc(sizeof(*input), GFP_KERNEL);
+ if (!input)
+ return -ENOMEM;
+
+ input_dev = input_allocate_device();
+ if (!input_dev) {
+ kfree(input);
+ return -ENOMEM;
+ }
+
+ platform_set_drvdata(pdev, input);
+ input->pcf = dev_to_pcf50606(pdev->dev.parent);
+ input->input_dev = input_dev;
+
+ input_dev->name = "PCF50606 PMU events";
+ input_dev->id.bustype = BUS_I2C;
+ input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_PWR);
+ set_bit(KEY_POWER, input_dev->keybit);
+
+ ret = input_register_device(input_dev);
+ if (ret) {
+ input_free_device(input_dev);
+ kfree(input);
+ return ret;
+ }
+ pcf50606_register_irq(input->pcf, PCF50606_IRQ_ONKEYR,
+ pcf50606_input_irq, input);
+ pcf50606_register_irq(input->pcf, PCF50606_IRQ_ONKEYF,
+ pcf50606_input_irq, input);
+
+ return 0;
+}
+
+static int __devexit pcf50606_input_remove(struct platform_device *pdev)
+{
+ struct pcf50606_input *input = platform_get_drvdata(pdev);
+
+ input_unregister_device(input->input_dev);
+ pcf50606_free_irq(input->pcf, PCF50606_IRQ_ONKEYR);
+ pcf50606_free_irq(input->pcf, PCF50606_IRQ_ONKEYF);
+
+ kfree(input);
+
+ return 0;
+}
+
+static struct platform_driver pcf50606_input_driver = {
+ .driver = {
+ .name = "pcf50606-input",
+ },
+ .probe = pcf50606_input_probe,
+ .remove = __devexit_p(pcf50606_input_remove),
+};
+
+static int __init pcf50606_input_init(void)
+{
+ return platform_driver_register(&pcf50606_input_driver);
+}
+module_init(pcf50606_input_init);
+
+static void __exit pcf50606_input_exit(void)
+{
+ platform_driver_unregister(&pcf50606_input_driver);
+}
+module_exit(pcf50606_input_exit);
+
+MODULE_AUTHOR("Balaji Rao <balajirrao@openmoko.org>");
+MODULE_DESCRIPTION("PCF50606 input driver");
+MODULE_LICENSE("GPL");
+MODULE_ALIAS("platform:pcf50606-input");
diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig
index cc1f6edc916..dfd63bcaee6 100644
--- a/drivers/mfd/Kconfig
+++ b/drivers/mfd/Kconfig
@@ -263,6 +263,29 @@ config EZX_PCAP
This enables the PCAP ASIC present on EZX Phones. This is
needed for MMC, TouchScreen, Sound, USB, etc..
+config MFD_PCF50606
+ tristate "Support for NXP PCF50606"
+ depends on I2C
+ help
+ Say yes here if you have NXP PCF50606 chip on your board.
+ This core driver provides register access and IRQ handling
+ facilities, and registers devices for the various functions
+ so that function-specific drivers can bind to them.
+
+config PCF50606_ADC
+ tristate "Support for NXP PCF50606 ADC"
+ depends on MFD_PCF50606
+ help
+ Say yes here if you want to include support for ADC in the
+ NXP PCF50606 chip.
+
+config PCF50606_GPO
+ tristate "Support for NXP PCF50606 GPO"
+ depends on MFD_PCF50606
+ help
+ Say yes here if you want to include support GPO for pins on
+ the PCF50606 chip.
+
source "drivers/mfd/glamo/Kconfig"
endmenu
diff --git a/drivers/mfd/Makefile b/drivers/mfd/Makefile
index b72486106f9..21d26b3a0ad 100644
--- a/drivers/mfd/Makefile
+++ b/drivers/mfd/Makefile
@@ -45,3 +45,8 @@ obj-$(CONFIG_MFD_PCF50633) += pcf50633-core.o
obj-$(CONFIG_PCF50633_ADC) += pcf50633-adc.o
obj-$(CONFIG_PCF50633_GPIO) += pcf50633-gpio.o
obj-$(CONFIG_AB3100_CORE) += ab3100-core.o
+
+obj-$(CONFIG_MFD_PCF50606) += pcf50606-core.o
+obj-$(CONFIG_PCF50606_ADC) += pcf50606-adc.o
+obj-$(CONFIG_PCF50606_GPO) += pcf50606-gpo.o
+
diff --git a/drivers/mfd/pcf50606-adc.c b/drivers/mfd/pcf50606-adc.c
new file mode 100644
index 00000000000..47210a9cce8
--- /dev/null
+++ b/drivers/mfd/pcf50606-adc.c
@@ -0,0 +1,278 @@
+/* Philips PCF50606 ADC Driver
+ *
+ * (C) 2006-2008 by Openmoko, Inc.
+ * Author: Balaji Rao <balajirrao@openmoko.org>
+ * All rights reserved.
+ *
+ * Broken down from monstrous PCF50606 driver mainly by
+ * Harald Welte, Andy Green, Werner Almesberger and Matt Hsu
+ *
+ * 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.
+ *
+ * NOTE: This driver does not yet support subtractive ADC mode, which means
+ * you can do only one measurement per read request.
+ */
+
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/init.h>
+#include <linux/device.h>
+#include <linux/platform_device.h>
+#include <linux/completion.h>
+
+#include <linux/mfd/pcf50606/core.h>
+#include <linux/mfd/pcf50606/adc.h>
+
+struct pcf50606_adc_request {
+ int mux;
+ int result;
+ void (*callback)(struct pcf50606 *, void *, int);
+ void *callback_param;
+
+ /* Used in case of sync requests */
+ struct completion completion;
+
+};
+
+#define PCF50606_MAX_ADC_FIFO_DEPTH 8
+
+struct pcf50606_adc {
+ struct pcf50606 *pcf;
+
+ /* Private stuff */
+ struct pcf50606_adc_request *queue[PCF50606_MAX_ADC_FIFO_DEPTH];
+ int queue_head;
+ int queue_tail;
+ struct mutex queue_mutex;
+};
+
+static inline struct pcf50606_adc *__to_adc(struct pcf50606 *pcf)
+{
+ return platform_get_drvdata(pcf->adc_pdev);
+}
+
+static void adc_setup(struct pcf50606 *pcf, int channel)
+{
+ channel &= PCF50606_ADCC2_ADCMUX_MASK;
+
+ /* start ADC conversion of selected channel */
+ pcf50606_reg_write(pcf, PCF50606_REG_ADCC2, channel |
+ PCF50606_ADCC2_ADCSTART | PCF50606_ADCC2_RES_10BIT);
+
+}
+
+static void trigger_next_adc_job_if_any(struct pcf50606 *pcf)
+{
+ struct pcf50606_adc *adc = __to_adc(pcf);
+ int head, tail;
+
+ mutex_lock(&adc->queue_mutex);
+
+ head = adc->queue_head;
+ tail = adc->queue_tail;
+
+ if (!adc->queue[head])
+ goto out;
+
+ adc_setup(pcf, adc->queue[head]->mux);
+out:
+ mutex_unlock(&adc->queue_mutex);
+}
+
+static int
+adc_enqueue_request(struct pcf50606 *pcf, struct pcf50606_adc_request *req)
+{
+ struct pcf50606_adc *adc = __to_adc(pcf);
+ int head, tail;
+
+ mutex_lock(&adc->queue_mutex);
+ head = adc->queue_head;
+ tail = adc->queue_tail;
+
+ if (adc->queue[tail]) {
+ mutex_unlock(&adc->queue_mutex);
+ return -EBUSY;
+ }
+
+ adc->queue[tail] = req;
+
+ adc->queue_tail =
+ (tail + 1) & (PCF50606_MAX_ADC_FIFO_DEPTH - 1);
+
+ mutex_unlock(&adc->queue_mutex);
+
+ trigger_next_adc_job_if_any(pcf);
+
+ return 0;
+}
+
+static void
+pcf50606_adc_sync_read_callback(struct pcf50606 *pcf, void *param, int result)
+{
+ struct pcf50606_adc_request *req;
+
+ /*We know here that the passed param is an adc_request object */
+ req = (struct pcf50606_adc_request *)param;
+
+ req->result = result;
+ complete(&req->completion);
+}
+
+int pcf50606_adc_sync_read(struct pcf50606 *pcf, int mux)
+{
+
+ struct pcf50606_adc_request *req;
+ int result;
+
+ /* req is freed when the result is ready, in irq handler*/
+ req = kzalloc(sizeof(*req), GFP_KERNEL);
+ if (!req)
+ return -ENOMEM;
+
+ req->mux = mux;
+ req->callback = pcf50606_adc_sync_read_callback;
+ req->callback_param = req;
+ init_completion(&req->completion);
+
+ adc_enqueue_request(pcf, req);
+
+ if (wait_for_completion_timeout(&req->completion, 5 * HZ) == 5 * HZ) {
+ dev_err(pcf->dev, "ADC read timed out \n");
+ }
+
+ result = req->result;
+
+ return result;
+}
+EXPORT_SYMBOL_GPL(pcf50606_adc_sync_read);
+
+int pcf50606_adc_async_read(struct pcf50606 *pcf, int mux,
+ void (*callback)(struct pcf50606 *, void *, int),
+ void *callback_param)
+{
+ struct pcf50606_adc_request *req;
+
+ /* req is freed when the result is ready, in pcf50606_work*/
+ req = kmalloc(sizeof(*req), GFP_KERNEL);
+ if (!req)
+ return -ENOMEM;
+
+ req->mux = mux;
+ req->callback = callback;
+ req->callback_param = callback_param;
+
+ adc_enqueue_request(pcf, req);
+
+ return 0;
+}
+EXPORT_SYMBOL_GPL(pcf50606_adc_async_read);
+
+static int adc_result(struct pcf50606 *pcf)
+{
+ u16 ret = (pcf50606_reg_read(pcf, PCF50606_REG_ADCS1) << 2) |
+ (pcf50606_reg_read(pcf, PCF50606_REG_ADCS2) & 0x03);
+
+ dev_dbg(pcf->dev, "adc result = %d\n", ret);
+
+ return ret;
+}
+
+static void pcf50606_adc_irq(int irq, void *data)
+{
+ struct pcf50606_adc *adc = data;
+ struct pcf50606 *pcf = adc->pcf;
+ struct pcf50606_adc_request *req;
+ int head;
+
+ mutex_lock(&adc->queue_mutex);
+ head = adc->queue_head;
+
+ req = adc->queue[head];
+ if (WARN_ON(!req)) {
+ dev_err(pcf->dev, "pcf50606-adc irq: ADC queue empty!\n");
+ mutex_unlock(&adc->queue_mutex);
+ return;
+ }
+
+ adc->queue[head] = NULL;
+ adc->queue_head = (head + 1) &
+ (PCF50606_MAX_ADC_FIFO_DEPTH - 1);
+
+ mutex_unlock(&adc->queue_mutex);
+
+ req->callback(pcf, req->callback_param, adc_result(pcf));
+ kfree(req);
+
+ trigger_next_adc_job_if_any(pcf);
+}
+
+static int __devinit pcf50606_adc_probe(struct platform_device *pdev)
+{
+ struct pcf50606_adc *adc;
+
+ adc = kzalloc(sizeof(*adc), GFP_KERNEL);
+ if (!adc)
+ return -ENOMEM;
+
+ adc->pcf = dev_to_pcf50606(pdev->dev.parent);
+ platform_set_drvdata(pdev, adc);
+
+ pcf50606_register_irq(adc->pcf, PCF50606_IRQ_ADCRDY,
+ pcf50606_adc_irq, adc);
+
+ mutex_init(&adc->queue_mutex);
+
+ return 0;
+}
+
+static int __devexit pcf50606_adc_remove(struct platform_device *pdev)
+{
+ struct pcf50606_adc *adc = platform_get_drvdata(pdev);
+ int i, head;
+
+ pcf50606_free_irq(adc->pcf, PCF50606_IRQ_ADCRDY);
+
+ mutex_lock(&adc->queue_mutex);
+ head = adc->queue_head;
+
+ if (WARN_ON(adc->queue[head]))
+ dev_err(adc->pcf->dev,
+ "adc driver removed with request pending\n");
+
+ for (i = 0; i < PCF50606_MAX_ADC_FIFO_DEPTH; i++)
+ kfree(adc->queue[i]);
+
+ mutex_unlock(&adc->queue_mutex);
+ kfree(adc);
+
+ return 0;
+}
+
+struct platform_driver pcf50606_adc_driver = {
+ .driver = {
+ .name = "pcf50606-adc",
+ },
+ .probe = pcf50606_adc_probe,
+ .remove = __devexit_p(pcf50606_adc_remove),
+};
+
+static int __init pcf50606_adc_init(void)
+{
+ return platform_driver_register(&pcf50606_adc_driver);
+}
+module_init(pcf50606_adc_init);
+
+static void __exit pcf50606_adc_exit(void)
+{
+ platform_driver_unregister(&pcf50606_adc_driver);
+}
+module_exit(pcf50606_adc_exit);
+
+MODULE_AUTHOR("Balaji Rao <balajirrao@openmoko.org>");
+MODULE_DESCRIPTION("PCF50606 adc driver");
+MODULE_LICENSE("GPL");
+MODULE_ALIAS("platform:pcf50606-adc");
+
diff --git a/drivers/mfd/pcf50606-core.c b/drivers/mfd/pcf50606-core.c
new file mode 100644
index 00000000000..741a432586a
--- /dev/null
+++ b/drivers/mfd/pcf50606-core.c
@@ -0,0 +1,676 @@
+/* Philips PCF50606 Power Management Unit (PMU) driver
+ *
+ * (C) 2006-2008 by Openmoko, Inc.
+ * Author: Harald Welte <laforge@openmoko.org>
+ * Matt Hsu <matt@openmoko.org>
+ * All rights reserved.
+ *
+ * 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.
+ *
+ */
+#include <linux/kernel.h>
+#include <linux/device.h>
+#include <linux/sysfs.h>
+#include <linux/device.h>
+#include <linux/module.h>
+#include <linux/types.h>
+#include <linux/interrupt.h>
+#include <linux/workqueue.h>
+#include <linux/platform_device.h>
+#include <linux/i2c.h>
+#include <linux/irq.h>
+#include <linux/device.h>
+#include <linux/module.h>
+
+#include <linux/mfd/pcf50606/core.h>
+
+static int __pcf50606_read(struct pcf50606 *pcf, u8 reg, int num, u8 *data)
+{
+ int ret;
+
+ ret = i2c_smbus_read_i2c_block_data(pcf->i2c_client, reg,
+ num, data);
+ if (ret < 0)
+ dev_err(pcf->dev, "Error reading %d regs at %d\n", num, reg);
+
+ return ret;
+}
+
+static int __pcf50606_write(struct pcf50606 *pcf, u8 reg, int num, u8 *data)
+{
+ int ret;
+
+ ret = i2c_smbus_write_i2c_block_data(pcf->i2c_client, reg,
+ num, data);
+ if (ret < 0)
+ dev_err(pcf->dev, "Error writing %d regs at %d\n", num, reg);
+
+ return ret;
+
+}
+
+/* Read a block of upto 32 regs */
+int pcf50606_read_block(struct pcf50606 *pcf, u8 reg,
+ int nr_regs, u8 *data)
+{
+ int ret;
+
+ mutex_lock(&pcf->lock);
+ ret = __pcf50606_read(pcf, reg, nr_regs, data);
+ mutex_unlock(&pcf->lock);
+
+ return ret;
+}
+EXPORT_SYMBOL_GPL(pcf50606_read_block);
+
+/* Write a block of upto 32 regs */
+int pcf50606_write_block(struct pcf50606 *pcf , u8 reg,
+ int nr_regs, u8 *data)
+{
+ int ret;
+
+ mutex_lock(&pcf->lock);
+ ret = __pcf50606_write(pcf, reg, nr_regs, data);
+ mutex_unlock(&pcf->lock);
+
+ return ret;
+}
+EXPORT_SYMBOL_GPL(pcf50606_write_block);
+
+u8 pcf50606_reg_read(struct pcf50606 *pcf, u8 reg)
+{
+ u8 val;
+
+ mutex_lock(&pcf->lock);
+ __pcf50606_read(pcf, reg, 1, &val);
+ mutex_unlock(&pcf->lock);
+
+ return val;
+}
+EXPORT_SYMBOL_GPL(pcf50606_reg_read);
+
+int pcf50606_reg_write(struct pcf50606 *pcf, u8 reg, u8 val)
+{
+ int ret;
+
+ mutex_lock(&pcf->lock);
+ ret = __pcf50606_write(pcf, reg, 1, &val);
+ mutex_unlock(&pcf->lock);
+
+ return ret;
+}
+EXPORT_SYMBOL_GPL(pcf50606_reg_write);
+
+int pcf50606_reg_set_bit_mask(struct pcf50606 *pcf, u8 reg, u8 mask, u8 val)
+{
+ int ret;
+ u8 tmp;
+
+ val &= mask;
+
+ mutex_lock(&pcf->lock);
+ ret = __pcf50606_read(pcf, reg, 1, &tmp);
+ if (ret < 0)
+ goto out;
+
+ tmp &= ~mask;
+ tmp |= val;
+ ret = __pcf50606_write(pcf, reg, 1, &tmp);
+
+out:
+ mutex_unlock(&pcf->lock);
+
+ return ret;
+}
+EXPORT_SYMBOL_GPL(pcf50606_reg_set_bit_mask);
+
+int pcf50606_reg_clear_bits(struct pcf50606 *pcf, u8 reg, u8 val)
+{
+ int ret;
+ u8 tmp;
+
+ mutex_lock(&pcf->lock);
+ ret = __pcf50606_read(pcf, reg, 1, &tmp);
+ if (ret < 0)
+ goto out;
+
+ tmp &= ~val;
+ ret = __pcf50606_write(pcf, reg, 1, &tmp);
+
+out:
+ mutex_unlock(&pcf->lock);
+
+ return ret;
+}
+EXPORT_SYMBOL_GPL(pcf50606_reg_clear_bits);
+
+/* sysfs attributes */
+static ssize_t show_dump_regs(struct device *dev, struct device_attribute *attr,
+ char *buf)
+{
+ struct pcf50606 *pcf = dev_get_drvdata(dev);
+ u8 dump[16];
+ int n, n1, idx = 0;
+ char *buf1 = buf;
+ static u8 address_no_read[] = { /* must be ascending */
+ PCF50606_REG_INT1,
+ PCF50606_REG_INT2,
+ PCF50606_REG_INT3,
+ 0 /* terminator */
+ };
+
+ for (n = 0; n < 256; n += sizeof(dump)) {
+ for (n1 = 0; n1 < sizeof(dump); n1++)
+ if (n == address_no_read[idx]) {
+ idx++;
+ dump[n1] = 0x00;
+ } else
+ dump[n1] = pcf50606_reg_read(pcf, n + n1);
+
+ hex_dump_to_buffer(dump, sizeof(dump), 16, 1, buf1, 128, 0);
+ buf1 += strlen(buf1);
+ *buf1++ = '\n';
+ *buf1 = '\0';
+ }
+
+ return buf1 - buf;
+}
+static DEVICE_ATTR(dump_regs, 0400, show_dump_regs, NULL);
+
+static ssize_t show_resume_reason(struct device *dev,
+ struct device_attribute *attr, char *buf)
+{
+ struct pcf50606 *pcf = dev_get_drvdata(dev);
+ int n;
+
+ n = sprintf(buf, "%02x%02x%02x\n",
+ pcf->resume_reason[0],
+ pcf->resume_reason[1],
+ pcf->resume_reason[2]);
+
+ return n;
+}
+static DEVICE_ATTR(resume_reason, 0400, show_resume_reason, NULL);
+
+static struct attribute *pcf_sysfs_entries[] = {
+ &dev_attr_dump_regs.attr,
+ &dev_attr_resume_reason.attr,
+ NULL,
+};
+
+static struct attribute_group pcf_attr_group = {
+ .name = NULL, /* put in device directory */
+ .attrs = pcf_sysfs_entries,
+};
+
+int pcf50606_register_irq(struct pcf50606 *pcf, int irq,
+ void (*handler) (int, void *), void *data)
+{
+ if (irq < 0 || irq > PCF50606_NUM_IRQ || !handler)
+ return -EINVAL;
+
+ if (WARN_ON(pcf->irq_handler[irq].handler))
+ return -EBUSY;
+
+ mutex_lock(&pcf->lock);
+ pcf->irq_handler[irq].handler = handler;
+ pcf->irq_handler[irq].data = data;
+ mutex_unlock(&pcf->lock);
+
+ return 0;
+}
+EXPORT_SYMBOL_GPL(pcf50606_register_irq);
+
+int pcf50606_free_irq(struct pcf50606 *pcf, int irq)
+{
+ if (irq < 0 || irq > PCF50606_NUM_IRQ)
+ return -EINVAL;
+
+ mutex_lock(&pcf->lock);
+ pcf->irq_handler[irq].handler = NULL;
+ mutex_unlock(&pcf->lock);
+
+ return 0;
+}
+EXPORT_SYMBOL_GPL(pcf50606_free_irq);
+
+static int __pcf50606_irq_mask_set(struct pcf50606 *pcf, int irq, u8 mask)
+{
+ u8 reg, bits, tmp;
+ int ret = 0, idx;
+
+ idx = irq >> 3;
+ reg = PCF50606_REG_INT1M + idx;
+ bits = 1 << (irq & 0x07);
+
+ mutex_lock(&pcf->lock);
+
+ if (mask) {
+ ret = __pcf50606_read(pcf, reg, 1, &tmp);
+ if (ret < 0)
+ goto out;
+
+ tmp |= bits;
+
+ ret = __pcf50606_write(pcf, reg, 1, &tmp);
+ if (ret < 0)
+ goto out;
+
+ pcf->mask_regs[idx] &= ~bits;
+ pcf->mask_regs[idx] |= bits;
+ } else {
+ ret = __pcf50606_read(pcf, reg, 1, &tmp);
+ if (ret < 0)
+ goto out;
+
+ tmp &= ~bits;
+
+ ret = __pcf50606_write(pcf, reg, 1, &tmp);
+ if (ret < 0)
+ goto out;
+
+ pcf->mask_regs[idx] &= ~bits;
+ }
+out:
+ mutex_unlock(&pcf->lock);
+
+ return ret;
+}
+
+int pcf50606_irq_mask(struct pcf50606 *pcf, int irq)
+{
+ dev_dbg(pcf->dev, "Masking IRQ %d\n", irq);
+
+ return __pcf50606_irq_mask_set(pcf, irq, 1);
+}
+EXPORT_SYMBOL_GPL(pcf50606_irq_mask);
+
+int pcf50606_irq_unmask(struct pcf50606 *pcf, int irq)
+{
+ dev_dbg(pcf->dev, "Unmasking IRQ %d\n", irq);
+
+ return __pcf50606_irq_mask_set(pcf, irq, 0);
+}
+EXPORT_SYMBOL_GPL(pcf50606_irq_unmask);
+
+int pcf50606_irq_mask_get(struct pcf50606 *pcf, int irq)
+{
+ u8 reg, bits;
+
+ reg = (irq / 8);
+ bits = (1 << (irq % 8));
+
+ return pcf->mask_regs[reg] & bits;
+}
+EXPORT_SYMBOL_GPL(pcf50606_irq_mask_get);
+
+static void pcf50606_irq_call_handler(struct pcf50606 *pcf,
+ int irq)
+{
+ if (pcf->irq_handler[irq].handler)
+ pcf->irq_handler[irq].handler(irq, pcf->irq_handler[irq].data);
+}
+
+#define PCF50606_ONKEY1S_TIMEOUT 8
+
+#define PCF50606_REG_MBCS1 0x2c
+
+static void pcf50606_irq_worker(struct work_struct *work)
+{
+ struct pcf50606 *pcf;
+ int ret, i, j;
+ u8 pcf_int[3], chgstat;
+
+ pcf = container_of(work, struct pcf50606, irq_work);
+
+ /* Read the 3 INT regs in one transaction */
+ ret = pcf50606_read_block(pcf, PCF50606_REG_INT1,
+ ARRAY_SIZE(pcf_int), pcf_int);
+ if (ret != ARRAY_SIZE(pcf_int)) {
+ dev_err(pcf->dev, "Error reading INT registers\n");
+
+ /*
+ * If this doesn't ACK the interrupt to the chip, we'll be
+ * called once again as we're level triggered.
+ */
+ goto out;
+ }
+
+ /* We immediately read the charger status. We thus make sure
+ * only of CHGINS/CHGRM interrupt handlers are called */
+ if (pcf_int[1] & (PCF50606_INT2_CHGINS | PCF50606_INT2_CHGRM)) {
+ chgstat = pcf50606_reg_read(pcf, PCF50606_REG_MBCS1);
+ if (chgstat & (0x1 << 4))
+ pcf_int[1] &= ~(1 << PCF50606_INT2_CHGRM);
+ else
+ pcf_int[1] &= ~(1 << PCF50606_INT2_CHGINS);
+ }
+
+ dev_dbg(pcf->dev, "INT1=0x%02x INT2=0x%02x INT3=0x%02x\n",
+ pcf_int[0], pcf_int[1], pcf_int[2]);
+
+ /* Some revisions of the chip don't have a 8s standby mode on
+ * ONKEY1S press. We try to manually do it in such cases. */
+ if (pcf_int[0] & PCF50606_INT1_SECOND && pcf->onkey1s_held) {
+ dev_info(pcf->dev, "ONKEY1S held for %d secs\n",
+ pcf->onkey1s_held);
+ if (pcf->onkey1s_held++ == PCF50606_ONKEY1S_TIMEOUT)
+ if (pcf->pdata->force_shutdown)
+ pcf->pdata->force_shutdown(pcf);
+ }
+
+ if (pcf_int[0] & PCF50606_INT1_ONKEY1S) {
+ dev_info(pcf->dev, "ONKEY1S held\n");
+ pcf->onkey1s_held = 1 ;
+
+ /* Unmask IRQ_SECOND */
+ pcf50606_reg_clear_bits(pcf, PCF50606_REG_INT1M,
+ PCF50606_INT1_SECOND);
+
+ /* Unmask IRQ_ONKEYF */
+ pcf50606_reg_clear_bits(pcf, PCF50606_REG_INT1M,
+ PCF50606_INT1_ONKEYF);
+ }
+
+ if ((pcf_int[0] & PCF50606_INT1_ONKEYR) && pcf->onkey1s_held) {
+ pcf->onkey1s_held = 0;
+
+ /* Mask SECOND and ONKEYF interrupts */
+ if (pcf->mask_regs[0] & PCF50606_INT1_SECOND)
+ pcf50606_reg_set_bit_mask(pcf,
+ PCF50606_REG_INT1M,
+ PCF50606_INT1_SECOND,
+ PCF50606_INT1_SECOND);
+
+ if (pcf->mask_regs[0] & PCF50606_INT1_ONKEYF)
+ pcf50606_reg_set_bit_mask(pcf,
+ PCF50606_REG_INT1M,
+ PCF50606_INT1_ONKEYF,
+ PCF50606_INT1_ONKEYF);
+ }
+
+ /* Have we just resumed ? */
+ if (pcf->is_suspended) {
+
+ pcf->is_suspended = 0;
+
+ /* Set the resume reason filtering out non resumers */
+ for (i = 0; i < ARRAY_SIZE(pcf_int); i++)
+ pcf->resume_reason[i] = pcf_int[i] &
+ pcf->pdata->resumers[i];
+
+ /* Make sure we don't pass on ONKEY events to
+ * userspace now */
+ pcf_int[1] &= ~(PCF50606_INT1_ONKEYR | PCF50606_INT1_ONKEYF);
+ }
+
+ for (i = 0; i < ARRAY_SIZE(pcf_int); i++) {
+ /* Unset masked interrupts */
+ pcf_int[i] &= ~pcf->mask_regs[i];
+
+ for (j = 0; j < 8 ; j++)
+ if (pcf_int[i] & (1 << j))
+ pcf50606_irq_call_handler(pcf, (i * 8) + j);
+ }
+
+out:
+ put_device(pcf->dev);
+ enable_irq(pcf->irq);
+}
+
+static irqreturn_t pcf50606_irq(int irq, void *data)
+{
+ struct pcf50606 *pcf = data;
+
+ get_device(pcf->dev);
+ disable_irq_nosync(pcf->irq);
+ schedule_work(&pcf->irq_work);
+
+ return IRQ_HANDLED;
+}
+
+static void
+pcf50606_client_dev_register(struct pcf50606 *pcf, const char *name,
+ struct platform_device **pdev)
+{
+ int ret;
+
+ *pdev = platform_device_alloc(name, -1);
+ if (!*pdev) {
+ dev_err(pcf->dev, "Falied to allocate %s\n", name);
+ return;
+ }
+
+ (*pdev)->dev.parent = pcf->dev;
+
+ ret = platform_device_add(*pdev);
+ if (ret) {
+ dev_err(pcf->dev, "Failed to register %s: %d\n", name, ret);
+ platform_device_put(*pdev);
+ *pdev = NULL;
+ }
+}
+
+#ifdef CONFIG_PM
+static int pcf50606_suspend(struct i2c_client *client, pm_message_t state)
+{
+ struct pcf50606 *pcf;
+ int ret, i;
+ u8 res[3];
+
+ pcf = i2c_get_clientdata(client);
+
+ /* Make sure our interrupt handlers are not called
+ * henceforth */
+ disable_irq(pcf->irq);
+
+ /* Make sure that any running IRQ worker has quit */
+ cancel_work_sync(&pcf->irq_work);
+
+ /* Save the masks */
+ ret = pcf50606_read_block(pcf, PCF50606_REG_INT1M,
+ ARRAY_SIZE(pcf->suspend_irq_masks),
+ pcf->suspend_irq_masks);
+ if (ret < 0) {
+ dev_err(pcf->dev, "error saving irq masks\n");
+ goto out;
+ }
+
+ /* Write wakeup irq masks */
+ for (i = 0; i < ARRAY_SIZE(res); i++)
+ res[i] = ~pcf->pdata->resumers[i];
+
+ ret = pcf50606_write_block(pcf, PCF50606_REG_INT1M,
+ ARRAY_SIZE(res), &res[0]);
+ if (ret < 0) {
+ dev_err(pcf->dev, "error writing wakeup irq masks\n");
+ goto out;
+ }
+
+ pcf->is_suspended = 1;
+
+out:
+ return ret;
+}
+
+static int pcf50606_resume(struct i2c_client *client)
+{
+ struct pcf50606 *pcf;
+ int ret;
+
+ pcf = i2c_get_clientdata(client);
+
+ /* Write the saved mask registers */
+ ret = pcf50606_write_block(pcf, PCF50606_REG_INT1M,
+ ARRAY_SIZE(pcf->suspend_irq_masks),
+ pcf->suspend_irq_masks);
+ if (ret < 0)
+ dev_err(pcf->dev, "Error restoring saved suspend masks\n");
+
+ get_device(pcf->dev);
+
+ /*
+ * Clear any pending interrupts and set resume reason if any.
+ * This will leave with enable_irq()
+ */
+ pcf50606_irq_worker(&pcf->irq_work);
+
+ return 0;
+}
+#else
+#define pcf50606_suspend NULL
+#define pcf50606_resume NULL
+#endif
+
+static int pcf50606_probe(struct i2c_client *client,
+ const struct i2c_device_id *ids)
+{
+ struct pcf50606 *pcf;
+ struct pcf50606_platform_data *pdata = client->dev.platform_data;
+ int i, ret;
+ int version, variant;
+
+ if (!client->irq) {
+ dev_err(&client->dev, "Missing IRQ\n");
+ return -ENOENT;
+ }
+
+ pcf = kzalloc(sizeof(*pcf), GFP_KERNEL);
+ if (!pcf)
+ return -ENOMEM;
+
+ pcf->pdata = pdata;
+
+ mutex_init(&pcf->lock);
+
+ i2c_set_clientdata(client, pcf);
+ pcf->dev = &client->dev;
+ pcf->i2c_client = client;
+ pcf->irq = client->irq;
+
+ INIT_WORK(&pcf->irq_work, pcf50606_irq_worker);
+
+ version = pcf50606_reg_read(pcf, 0);
+ variant = pcf50606_reg_read(pcf, 1);
+ if (version < 0 || variant < 0) {
+ dev_err(pcf->dev, "Unable to probe pcf50606\n");
+ ret = -ENODEV;
+ goto err;
+ }
+
+ dev_info(pcf->dev, "Probed device version %d variant %d\n",
+ version, variant);
+ /* Enable all inteerupts except RTC SECOND */
+ pcf->mask_regs[0] = 0x40;
+ pcf50606_reg_write(pcf, PCF50606_REG_INT1M, pcf->mask_regs[0]);
+ pcf50606_reg_write(pcf, PCF50606_REG_INT2M, 0x00);
+ pcf50606_reg_write(pcf, PCF50606_REG_INT3M, 0x00);
+
+ ret = request_irq(client->irq, pcf50606_irq,
+ IRQF_TRIGGER_LOW, "pcf50606", pcf);
+
+ if (ret) {
+ dev_err(pcf->dev, "Failed to request IRQ %d\n", ret);
+ goto err;
+ }
+
+ pcf50606_client_dev_register(pcf, "pcf50606-input",
+ &pcf->input_pdev);
+ pcf50606_client_dev_register(pcf, "pcf50606-rtc",
+ &pcf->rtc_pdev);
+ pcf50606_client_dev_register(pcf, "pcf50606-mbc",
+ &pcf->mbc_pdev);
+ pcf50606_client_dev_register(pcf, "pcf50606-adc",
+ &pcf->adc_pdev);
+ pcf50606_client_dev_register(pcf, "pcf50606-wdt",
+ &pcf->wdt_pdev);
+ for (i = 0; i < PCF50606_NUM_REGULATORS; i++) {
+ struct platform_device *pdev;
+
+ pdev = platform_device_alloc("pcf50606-regltr", i);
+ if (!pdev) {
+ dev_err(pcf->dev, "Cannot create regulator %d\n", i);
+ continue;
+ }
+
+ pdev->dev.parent = pcf->dev;
+ platform_device_add_data(pdev, &pdata->reg_init_data[i],
+ sizeof(pdata->reg_init_data[i]));
+ pcf->regulator_pdev[i] = pdev;
+
+ platform_device_add(pdev);
+ }
+
+ if (enable_irq_wake(client->irq) < 0)
+ dev_info(pcf->dev, "IRQ %u cannot be enabled as wake-up source"
+ "in this hardware revision\n", client->irq);
+
+ ret = sysfs_create_group(&client->dev.kobj, &pcf_attr_group);
+ if (ret)
+ dev_info(pcf->dev, "error creating sysfs entries\n");
+
+ if (pdata->probe_done)
+ pdata->probe_done(pcf);
+
+ return 0;
+
+err:
+ i2c_set_clientdata(client, NULL);
+ kfree(pcf);
+ return ret;
+}
+
+static int pcf50606_remove(struct i2c_client *client)
+{
+ struct pcf50606 *pcf = i2c_get_clientdata(client);
+ int i;
+
+ free_irq(pcf->irq, pcf);
+
+ platform_device_unregister(pcf->input_pdev);
+ platform_device_unregister(pcf->rtc_pdev);
+ platform_device_unregister(pcf->mbc_pdev);
+ platform_device_unregister(pcf->adc_pdev);
+
+ for (i = 0; i < PCF50606_NUM_REGULATORS; i++)
+ platform_device_unregister(pcf->regulator_pdev[i]);
+
+ kfree(pcf);
+
+ return 0;
+}
+
+static struct i2c_device_id pcf50606_id_table[] = {
+ {"pcf50606", 0x08},
+};
+
+static struct i2c_driver pcf50606_driver = {
+ .driver = {
+ .name = "pcf50606",
+ },
+ .id_table = pcf50606_id_table,
+ .probe = pcf50606_probe,
+ .remove = pcf50606_remove,
+ .suspend = pcf50606_suspend,
+ .resume = pcf50606_resume,
+};
+
+static int __init pcf50606_init(void)
+{
+ return i2c_add_driver(&pcf50606_driver);
+}
+
+static void pcf50606_exit(void)
+{
+ i2c_del_driver(&pcf50606_driver);
+}
+
+MODULE_DESCRIPTION("I2C chip driver for NXP PCF50606 PMU");
+MODULE_AUTHOR("Harald Welte <laforge@openmoko.org>");
+MODULE_LICENSE("GPL");
+
+module_init(pcf50606_init);
+module_exit(pcf50606_exit);
diff --git a/drivers/mfd/pcf50606-gpo.c b/drivers/mfd/pcf50606-gpo.c
new file mode 100644
index 00000000000..3510f8b48e9
--- /dev/null
+++ b/drivers/mfd/pcf50606-gpo.c
@@ -0,0 +1,119 @@
+/* Philips PCF50606 GPO Driver
+ *
+ * (C) 2006-2008 by Openmoko, Inc.
+ * Author: Balaji Rao <balajirrao@openmoko.org>
+ * All rights reserved.
+ *
+ * Broken down from monstrous PCF50606 driver mainly by
+ * Harald Welte, Andy Green Werner Almesberger and Matt Hsu
+ *
+ * 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.
+ */
+
+#include <linux/kernel.h>
+
+#include <linux/mfd/pcf50606/core.h>
+#include <linux/mfd/pcf50606/gpo.h>
+
+void pcf50606_gpo_set_active(struct pcf50606 *pcf, int gpo, int val)
+{
+ u8 reg, value, mask;
+
+ reg = gpo;
+ value = val;
+ mask = 0x07;
+
+ if (gpo == PCF50606_GPO2) {
+ value = val << 4;
+ mask = 0x07 << 4;
+ }
+ pcf50606_reg_set_bit_mask(pcf, reg, mask, value);
+}
+EXPORT_SYMBOL_GPL(pcf50606_gpo_set_active);
+
+int pcf50606_gpo_get_active(struct pcf50606 *pcf, int gpo)
+{
+ u8 reg, value, shift = 0;
+
+ reg = gpo;
+ if (gpo == PCF50606_GPO2)
+ shift = 4;
+
+ value = pcf50606_reg_read(pcf, reg);
+
+ return (value >> shift) & 0x07;
+}
+EXPORT_SYMBOL_GPL(pcf50606_gpo_get_active);
+
+void pcf50606_gpo_set_standby(struct pcf50606 *pcf, int gpo, int val)
+{
+ u8 reg;
+
+ if (gpo == PCF50606_GPO1 || gpo == PCF50606_GPO2) {
+ dev_err(pcf->dev, "Can't set standby settings for GPO[12]n");
+ return;
+ }
+
+ reg = gpo;
+
+ pcf50606_reg_set_bit_mask(pcf, gpo, 0x07 << 3, val);
+}
+EXPORT_SYMBOL_GPL(pcf50606_gpo_set_standby);
+
+int pcf50606_gpo_get_standby(struct pcf50606 *pcf, int gpo)
+{
+ u8 reg, value;
+
+ if (gpo == PCF50606_GPO1 || gpo == PCF50606_GPO2) {
+ dev_err(pcf->dev, "Can't get standby settings for GPO[12]n");
+ return -EINVAL;
+ }
+
+ reg = gpo;
+ value = pcf50606_reg_read(pcf, reg);
+
+ return (value >> 3) & 0x07;
+}
+EXPORT_SYMBOL_GPL(pcf50606_gpo_get_standby);
+
+void pcf50606_gpo_invert_set(struct pcf50606 *pcf, int gpo, int invert)
+{
+ u8 reg, value, mask;
+
+ reg = gpo;
+ value = !!invert << 6;
+ mask = 0x01 << 6;
+
+ if (gpo == PCF50606_GPO1) {
+ mask = 0x01 << 4;
+ value = !!invert << 4;
+ }
+ else if (gpo == PCF50606_GPO2) {
+ mask = 0x01 << 7;
+ value = !!invert << 7;
+ }
+
+ pcf50606_reg_set_bit_mask(pcf, reg, mask, value);
+}
+EXPORT_SYMBOL_GPL(pcf50606_gpo_invert_set);
+
+int pcf50606_gpo_invert_get(struct pcf50606 *pcf, int gpo)
+{
+ u8 reg, value, shift;
+
+ reg = gpo;
+ shift = 6;
+
+ if (gpo == PCF50606_GPO1)
+ shift = 4;
+ else if (gpo == PCF50606_GPO2)
+ shift = 7;
+
+ value = pcf50606_reg_read(pcf, reg);
+
+ return (value >> shift) & 0x01;
+}
+EXPORT_SYMBOL_GPL(pcf50606_gpo_invert_get);
diff --git a/drivers/power/Kconfig b/drivers/power/Kconfig
index 2acfcd12e48..f5ac0976d5f 100644
--- a/drivers/power/Kconfig
+++ b/drivers/power/Kconfig
@@ -114,5 +114,11 @@ config HDQ_GPIO_BITBANG
Say Y to enable supoort for generic gpio based HDQ bitbang driver.
This can not be built as a module.
+config CHARGER_PCF50606
+ tristate "Support for NXP PCF50606 MBC"
+ depends on MFD_PCF50606
+ help
+ Say Y to include support for NXP PCF50606 Battery Charger.
+
endif # POWER_SUPPLY
diff --git a/drivers/power/Makefile b/drivers/power/Makefile
index 027ee9fdbcd..6dc969dcce0 100644
--- a/drivers/power/Makefile
+++ b/drivers/power/Makefile
@@ -28,6 +28,7 @@ obj-$(CONFIG_BATTERY_BQ27x00) += bq27x00_battery.o
obj-$(CONFIG_BATTERY_DA9030) += da9030_battery.o
obj-$(CONFIG_BATTERY_MAX17040) += max17040_battery.o
obj-$(CONFIG_CHARGER_PCF50633) += pcf50633-charger.o
+obj-$(CONFIG_CHARGER_PCF50606) += pcf50606-charger.o
obj-$(CONFIG_BATTERY_BQ27000_HDQ) += bq27000_battery.o
obj-$(CONFIG_HDQ_GPIO_BITBANG) += hdq.o
diff --git a/drivers/power/pcf50606-charger.c b/drivers/power/pcf50606-charger.c
new file mode 100644
index 00000000000..f90c5ed25b3
--- /dev/null
+++ b/drivers/power/pcf50606-charger.c
@@ -0,0 +1,243 @@
+/* NXP PCF50606 Main Battery Charger Driver
+ *
+ * (C) 2006-2008 by Openmoko, Inc.
+ * Author: Balaji Rao <balajirrao@openmoko.org>
+ * All rights reserved.
+ *
+ * Broken down from monstrous PCF50606 driver mainly by
+ * Harald Welte, Andy Green and Werner Almesberger
+ *
+ * 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.
+ *
+ */
+
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/init.h>
+#include <linux/types.h>
+#include <linux/device.h>
+#include <linux/sysfs.h>
+#include <linux/platform_device.h>
+#include <linux/power_supply.h>
+
+#include <linux/mfd/pcf50606/core.h>
+#include <linux/mfd/pcf50606/mbc.h>
+
+struct pcf50606_mbc {
+ struct pcf50606 *pcf;
+
+ int charger_online;
+ struct power_supply charger;
+};
+
+void pcf50606_charge_fast(struct pcf50606 *pcf, int on)
+{
+ struct pcf50606_mbc *mbc = platform_get_drvdata(pcf->mbc_pdev);
+
+ /*
+ * This is a fix to work around boot-time ordering problems if
+ * the s3c2410_udc is initialized before the pcf50606 mbc is
+ * ready.
+ */
+ if (!mbc)
+ return;
+
+ if (on) {
+ pcf50606_reg_set_bit_mask(pcf, PCF50606_REG_MBCC1,
+ PCF50606_MBCC1_AUTOFST,
+ PCF50606_MBCC1_AUTOFST);\
+ mbc->charger_online = 1;
+ } else {
+ /* disable automatic fast-charge */
+ pcf50606_reg_clear_bits(pcf, PCF50606_REG_MBCC1,
+ PCF50606_MBCC1_AUTOFST);
+ /* switch to idle mode to abort existing charge process */
+ pcf50606_reg_set_bit_mask(pcf, PCF50606_REG_MBCC1,
+ PCF50606_MBCC1_CHGMOD_MASK,
+ PCF50606_MBCC1_CHGMOD_IDLE);
+ mbc->charger_online = 0;
+ }
+}
+EXPORT_SYMBOL_GPL(pcf50606_charge_fast);
+
+static ssize_t
+show_chgmode(struct device *dev, struct device_attribute *attr, char *buf)
+{
+ struct pcf50606_mbc *mbc = dev_get_drvdata(dev);
+
+ u8 mbcc1 = pcf50606_reg_read(mbc->pcf, PCF50606_REG_MBCC1);
+ u8 chgmod = (mbcc1 & PCF50606_MBCC1_CHGMOD_MASK);
+
+ return sprintf(buf, "%d\n", chgmod);
+}
+
+static ssize_t set_chgmode(struct device *dev, struct device_attribute *attr,
+ const char *buf, size_t count)
+{
+ struct pcf50606_mbc *mbc = dev_get_drvdata(dev);
+ u_int8_t mbcc1 = pcf50606_reg_read(mbc->pcf, PCF50606_REG_MBCC1);
+
+ mbcc1 &= ~PCF50606_MBCC1_CHGMOD_MASK;
+
+ if (!strcmp(buf, "qualification"))
+ mbcc1 |= PCF50606_MBCC1_CHGMOD_QUAL;
+ else if (!strcmp(buf, "pre"))
+ mbcc1 |= PCF50606_MBCC1_CHGMOD_PRE;
+ else if (!strcmp(buf, "trickle"))
+ mbcc1 |= PCF50606_MBCC1_CHGMOD_TRICKLE;
+ else if (!strcmp(buf, "fast_cccv"))
+ mbcc1 |= PCF50606_MBCC1_CHGMOD_FAST_CCCV;
+ /* We don't allow the other fast modes for security reasons */
+ else if (!strcmp(buf, "idle"))
+ mbcc1 |= PCF50606_MBCC1_CHGMOD_IDLE;
+ else
+ return -EINVAL;
+
+ pcf50606_reg_write(mbc->pcf, PCF50606_REG_MBCC1, mbcc1);
+
+ return count;
+}
+
+static DEVICE_ATTR(chgmode, S_IRUGO, show_chgmode, set_chgmode);
+
+
+static struct attribute *pcf50606_mbc_sysfs_entries[] = {
+ &dev_attr_chgmode.attr,
+ NULL,
+};
+
+static struct attribute_group mbc_attr_group = {
+ .name = NULL, /* put in device directory */
+ .attrs = pcf50606_mbc_sysfs_entries,
+};
+
+static void
+pcf50606_mbc_irq_handler(int irq, void *data)
+{
+ struct pcf50606_mbc *mbc = data;
+
+ power_supply_changed(&mbc->charger);
+
+ if (mbc->pcf->pdata->mbc_event_callback)
+ mbc->pcf->pdata->mbc_event_callback(mbc->pcf, irq);
+}
+
+static int charger_get_property(struct power_supply *psy,
+ enum power_supply_property psp,
+ union power_supply_propval *val)
+{
+ struct pcf50606_mbc *mbc = container_of(psy, struct pcf50606_mbc, charger);
+ int ret = 0;
+
+ switch (psp) {
+ case POWER_SUPPLY_PROP_ONLINE:
+ val->intval = mbc->charger_online;
+ break;
+ default:
+ ret = -EINVAL;
+ break;
+ }
+ return ret;
+}
+
+static enum power_supply_property power_props[] = {
+ POWER_SUPPLY_PROP_ONLINE,
+};
+
+static const u8 mbc_irq_handlers[] = {
+ PCF50606_IRQ_CHGINS,
+ PCF50606_IRQ_CHGRM,
+ PCF50606_IRQ_CHGFOK,
+ PCF50606_IRQ_CHGERR,
+ PCF50606_IRQ_CHGFRDY,
+ PCF50606_IRQ_CHGPROT,
+};
+
+static int __devinit pcf50606_mbc_probe(struct platform_device *pdev)
+{
+ struct pcf50606_mbc *mbc;
+ int ret;
+ int i;
+ u8 oocs;
+
+ mbc = kzalloc(sizeof(*mbc), GFP_KERNEL);
+ if (!mbc)
+ return -ENOMEM;
+
+ platform_set_drvdata(pdev, mbc);
+ mbc->pcf = dev_to_pcf50606(pdev->dev.parent);
+
+ /* Set up IRQ handlers */
+ for (i = 0; i < ARRAY_SIZE(mbc_irq_handlers); i++)
+ pcf50606_register_irq(mbc->pcf, mbc_irq_handlers[i],
+ pcf50606_mbc_irq_handler, mbc);
+
+ mbc->charger.name = "charger";
+ mbc->charger.type = POWER_SUPPLY_TYPE_MAINS;
+ mbc->charger.properties = power_props;
+ mbc->charger.num_properties = ARRAY_SIZE(power_props);
+ mbc->charger.get_property = &charger_get_property;
+ mbc->charger.supplied_to = mbc->pcf->pdata->batteries;
+ mbc->charger.num_supplicants = mbc->pcf->pdata->num_batteries;
+
+ ret = power_supply_register(&pdev->dev, &mbc->charger);
+ if (ret) {
+ dev_err(mbc->pcf->dev, "failed to register charger\n");
+ kfree(mbc);
+ return ret;
+ }
+
+ ret = sysfs_create_group(&pdev->dev.kobj, &mbc_attr_group);
+ if (ret)
+ dev_err(mbc->pcf->dev, "failed to create sysfs entries\n");
+
+ oocs = pcf50606_reg_read(mbc->pcf, PCF50606_REG_OOCS);
+ if (oocs & PCF50606_OOCS_CHGOK)
+ pcf50606_mbc_irq_handler(PCF50606_IRQ_CHGINS, mbc);
+
+ return 0;
+}
+
+static int __devexit pcf50606_mbc_remove(struct platform_device *pdev)
+{
+ struct pcf50606_mbc *mbc = platform_get_drvdata(pdev);
+ int i;
+
+ /* Remove IRQ handlers */
+ for (i = 0; i < ARRAY_SIZE(mbc_irq_handlers); i++)
+ pcf50606_free_irq(mbc->pcf, mbc_irq_handlers[i]);
+
+ power_supply_unregister(&mbc->charger);
+
+ kfree(mbc);
+
+ return 0;
+}
+
+static struct platform_driver pcf50606_mbc_driver = {
+ .driver = {
+ .name = "pcf50606-mbc",
+ },
+ .probe = pcf50606_mbc_probe,
+ .remove = __devexit_p(pcf50606_mbc_remove),
+};
+
+static int __init pcf50606_mbc_init(void)
+{
+ return platform_driver_register(&pcf50606_mbc_driver);
+}
+module_init(pcf50606_mbc_init);
+
+static void __exit pcf50606_mbc_exit(void)
+{
+ platform_driver_unregister(&pcf50606_mbc_driver);
+}
+module_exit(pcf50606_mbc_exit);
+
+MODULE_AUTHOR("Balaji Rao <balajirrao@openmoko.org>");
+MODULE_DESCRIPTION("PCF50606 mbc driver");
+MODULE_LICENSE("GPL");
+MODULE_ALIAS("platform:pcf50606-mbc");
diff --git a/drivers/regulator/Kconfig b/drivers/regulator/Kconfig
index f4317798e47..29f34a4de25 100644
--- a/drivers/regulator/Kconfig
+++ b/drivers/regulator/Kconfig
@@ -117,4 +117,10 @@ config REGULATOR_LP3971
Say Y here to support the voltage regulators and convertors
on National Semiconductors LP3971 PMIC
+config REGULATOR_PCF50606
+ bool "PCF50606 regulator driver"
+ depends on MFD_PCF50606
+ help
+ Say Y here to support the voltage regulators and convertors
+ on PCF50606
endif
diff --git a/drivers/regulator/Makefile b/drivers/regulator/Makefile
index 4d762c4cccf..ac5b42ae95c 100644
--- a/drivers/regulator/Makefile
+++ b/drivers/regulator/Makefile
@@ -16,5 +16,6 @@ obj-$(CONFIG_REGULATOR_WM8350) += wm8350-regulator.o
obj-$(CONFIG_REGULATOR_WM8400) += wm8400-regulator.o
obj-$(CONFIG_REGULATOR_DA903X) += da903x.o
obj-$(CONFIG_REGULATOR_PCF50633) += pcf50633-regulator.o
+obj-$(CONFIG_REGULATOR_PCF50606) += pcf50606-regulator.o
ccflags-$(CONFIG_REGULATOR_DEBUG) += -DDEBUG
diff --git a/drivers/regulator/pcf50606-regulator.c b/drivers/regulator/pcf50606-regulator.c
new file mode 100644
index 00000000000..667614c06f4
--- /dev/null
+++ b/drivers/regulator/pcf50606-regulator.c
@@ -0,0 +1,384 @@
+/* NXP PCF50606 PMIC Driver
+ *
+ * (C) 2006-2008 by Openmoko, Inc.
+ * Author: Balaji Rao <balajirrao@openmoko.org>
+ * All rights reserved.
+ *
+ * Broken down from monstrous PCF50606 driver mainly by
+ * Harald Welte and Andy Green and Werner Almesberger
+ *
+ * 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.
+ *
+ */
+
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/init.h>
+#include <linux/device.h>
+#include <linux/err.h>
+#include <linux/platform_device.h>
+
+#include <linux/mfd/pcf50606/core.h>
+#include <linux/mfd/pcf50606/pmic.h>
+
+#define PCF50606_REGULATOR(_name, _id) \
+ { \
+ .name = _name, \
+ .id = _id, \
+ .ops = &pcf50606_regulator_ops, \
+ .type = REGULATOR_VOLTAGE, \
+ .owner = THIS_MODULE, \
+ }
+
+static const u8 pcf50606_regulator_registers[PCF50606_NUM_REGULATORS] = {
+ [PCF50606_REGULATOR_DCD] = PCF50606_REG_DCDC1,
+ [PCF50606_REGULATOR_DCDE] = PCF50606_REG_DCDEC1,
+ [PCF50606_REGULATOR_DCUD] = PCF50606_REG_DCUDC1,
+ [PCF50606_REGULATOR_D1REG] = PCF50606_REG_D1REGC1,
+ [PCF50606_REGULATOR_D2REG] = PCF50606_REG_D2REGC1,
+ [PCF50606_REGULATOR_D3REG] = PCF50606_REG_D3REGC1,
+ [PCF50606_REGULATOR_LPREG] = PCF50606_REG_LPREGC1,
+ [PCF50606_REGULATOR_IOREG] = PCF50606_REG_IOREGC,
+};
+
+static u8 dcudc_voltage(unsigned int millivolts)
+{
+ if (millivolts < 900)
+ return 0;
+ if (millivolts > 5500)
+ return 0x1f;
+ if (millivolts <= 3300) {
+ millivolts -= 900;
+ return millivolts/300;
+ }
+ if (millivolts < 4000)
+ return 0x0f;
+ else {
+ millivolts -= 4000;
+ return millivolts/100;
+ }
+}
+
+static unsigned int dcudc_2voltage(u8 bits)
+{
+ bits &= 0x1f;
+ if (bits < 0x08)
+ return 900 + bits * 300;
+ else if (bits < 0x10)
+ return 3300;
+ else
+ return 4000 + bits * 100;
+}
+
+static u8 dcdec_voltage(unsigned int millivolts)
+{
+ if (millivolts < 900)
+ return 0;
+ else if (millivolts > 3300)
+ return 0x0f;
+
+ millivolts -= 900;
+ return millivolts/300;
+}
+
+static unsigned int dcdec_2voltage(u8 bits)
+{
+ bits &= 0x0f;
+ return 900 + bits*300;
+}
+
+static u8 dcdc_voltage(unsigned int millivolts)
+{
+ if (millivolts < 900)
+ return 0;
+ else if (millivolts > 3600)
+ return 0x1f;
+
+ if (millivolts < 1500) {
+ millivolts -= 900;
+ return millivolts/25;
+ } else {
+ millivolts -= 1500;
+ return 0x18 + millivolts/300;
+ }
+}
+
+static unsigned int dcdc_2voltage(u8 bits)
+{
+ bits &= 0x1f;
+ if ((bits & 0x18) == 0x18)
+ return 1500 + ((bits & 0x7) * 300);
+ else
+ return 900 + (bits * 25);
+}
+
+static u8 dx_voltage(unsigned int millivolts)
+{
+ if (millivolts < 900)
+ return 0;
+ else if (millivolts > 3300)
+ return 0x18;
+
+ millivolts -= 900;
+ return millivolts/100;
+}
+
+static unsigned int dx_2voltage(u8 bits)
+{
+ bits &= 0x1f;
+ return 900 + (bits * 100);
+}
+
+static int pcf50606_regulator_set_voltage(struct regulator_dev *rdev,
+ int min_uV, int max_uV)
+{
+ struct pcf50606 *pcf;
+ int regulator_id, millivolts, rc;
+ u8 volt_bits, regnr;
+
+ pcf = rdev_get_drvdata(rdev);
+
+ regulator_id = rdev_get_id(rdev);
+ if (regulator_id >= PCF50606_NUM_REGULATORS)
+ return -EINVAL;
+
+ millivolts = min_uV / 1000;
+
+ switch (regulator_id) {
+ case PCF50606_REGULATOR_DCD:
+ volt_bits = dcdc_voltage(millivolts);
+ rc = pcf50606_reg_set_bit_mask(pcf, PCF50606_REG_DCDC1, 0x1f,
+ volt_bits);
+ break;
+ case PCF50606_REGULATOR_DCDE:
+ volt_bits = dcdec_voltage(millivolts);
+ rc = pcf50606_reg_set_bit_mask(pcf, PCF50606_REG_DCDEC1, 0x0f,
+ volt_bits);
+ break;
+ case PCF50606_REGULATOR_DCUD:
+ volt_bits = dcudc_voltage(millivolts);
+ rc = pcf50606_reg_set_bit_mask(pcf, PCF50606_REG_DCUDC1, 0x1f,
+ volt_bits);
+ break;
+ case PCF50606_REGULATOR_D1REG:
+ case PCF50606_REGULATOR_D2REG:
+ case PCF50606_REGULATOR_D3REG:
+ regnr = PCF50606_REG_D1REGC1 +
+ (regulator_id - PCF50606_REGULATOR_D1REG);
+ volt_bits = dx_voltage(millivolts);
+ rc = pcf50606_reg_set_bit_mask(pcf, regnr, 0x1f, volt_bits);
+ break;
+ case PCF50606_REGULATOR_LPREG:
+ volt_bits = dx_voltage(millivolts);
+ rc = pcf50606_reg_set_bit_mask(pcf, PCF50606_REG_LPREGC1, 0x1f,
+ volt_bits);
+ break;
+ case PCF50606_REGULATOR_IOREG:
+ if (millivolts < 1800)
+ return -EINVAL;
+ volt_bits = dx_voltage(millivolts);
+ rc = pcf50606_reg_set_bit_mask(pcf, PCF50606_REG_IOREGC, 0x1f,
+ volt_bits);
+ break;
+ default:
+ return -EINVAL;
+ }
+
+ return rc;
+}
+
+static int pcf50606_regulator_get_voltage(struct regulator_dev *rdev)
+{
+ struct pcf50606 *pcf;
+ u8 volt_bits, regnr;
+ int rc = 0, regulator_id;
+
+
+ pcf = rdev_get_drvdata(rdev);
+
+ regulator_id = rdev_get_id(rdev);
+ if (regulator_id >= PCF50606_NUM_REGULATORS)
+ return -EINVAL;
+
+ switch (regulator_id) {
+ case PCF50606_REGULATOR_DCD:
+ volt_bits = pcf50606_reg_read(pcf, PCF50606_REG_DCDC1) & 0x1f;
+ rc = dcdc_2voltage(volt_bits);
+ break;
+ case PCF50606_REGULATOR_DCDE:
+ volt_bits = pcf50606_reg_read(pcf, PCF50606_REG_DCDEC1) & 0x0f;
+ rc = dcdec_2voltage(volt_bits);
+ break;
+ case PCF50606_REGULATOR_DCUD:
+ volt_bits = pcf50606_reg_read(pcf, PCF50606_REG_DCUDC1) & 0x1f;
+ rc = dcudc_2voltage(volt_bits);
+ break;
+ case PCF50606_REGULATOR_D1REG:
+ case PCF50606_REGULATOR_D2REG:
+ case PCF50606_REGULATOR_D3REG:
+ regnr = PCF50606_REG_D1REGC1 + (regulator_id - PCF50606_REGULATOR_D1REG);
+ volt_bits = pcf50606_reg_read(pcf, regnr) & 0x1f;
+ if (volt_bits > 0x18)
+ volt_bits = 0x18;
+ rc = dx_2voltage(volt_bits);
+ break;
+ case PCF50606_REGULATOR_LPREG:
+ volt_bits = pcf50606_reg_read(pcf, PCF50606_REG_LPREGC1) & 0x1f;
+ if (volt_bits > 0x18)
+ volt_bits = 0x18;
+ rc = dx_2voltage(volt_bits);
+ break;
+ case PCF50606_REGULATOR_IOREG:
+ volt_bits = pcf50606_reg_read(pcf, PCF50606_REG_IOREGC) & 0x1f;
+ if (volt_bits > 0x18)
+ volt_bits = 0x18;
+ rc = dx_2voltage(volt_bits);
+ break;
+ default:
+ return -EINVAL;
+ }
+
+ return rc * 1000;
+
+}
+
+static int pcf50606_regulator_enable(struct regulator_dev *rdev)
+{
+ struct pcf50606 *pcf = rdev_get_drvdata(rdev);
+ int regulator_id;
+ u8 regnr;
+
+ regulator_id = rdev_get_id(rdev);
+ if (regulator_id >= PCF50606_NUM_REGULATORS)
+ return -EINVAL;
+
+ regnr = pcf50606_regulator_registers[regulator_id];
+
+ return pcf50606_reg_set_bit_mask(pcf, regnr, 0xe0, 0xe0);
+}
+
+static int pcf50606_regulator_disable(struct regulator_dev *rdev)
+{
+ struct pcf50606 *pcf = rdev_get_drvdata(rdev);
+ int regulator_id;
+ u8 regnr;
+
+ regulator_id = rdev_get_id(rdev);
+ if (regulator_id >= PCF50606_NUM_REGULATORS)
+ return -EINVAL;
+
+ /* IOREG cannot be powered off since it powers the PMU I2C */
+ if (regulator_id == PCF50606_REGULATOR_IOREG)
+ return -EINVAL;
+
+ regnr = pcf50606_regulator_registers[regulator_id];
+
+ return pcf50606_reg_set_bit_mask(pcf, regnr, 0xe0, 0);
+}
+
+static int pcf50606_regulator_is_enabled(struct regulator_dev *rdev)
+{
+ struct pcf50606 *pcf = rdev_get_drvdata(rdev);
+ int regulator_id = rdev_get_id(rdev);
+ u8 regnr, val;
+
+ regulator_id = rdev_get_id(rdev);
+ if (regulator_id >= PCF50606_NUM_REGULATORS)
+ return -EINVAL;
+
+ /* the *ENA register is always one after the *OUT register */
+ regnr = pcf50606_regulator_registers[regulator_id];
+ val = (pcf50606_reg_read(pcf, regnr) & 0xe0) >> 5;
+
+ /* PWREN1 = 1, PWREN2 = 1, see table 16 of datasheet */
+ if (val == 0 || val == 5)
+ return 0;
+
+ return 1;
+}
+
+static struct regulator_ops pcf50606_regulator_ops = {
+ .set_voltage = pcf50606_regulator_set_voltage,
+ .get_voltage = pcf50606_regulator_get_voltage,
+ .enable = pcf50606_regulator_enable,
+ .disable = pcf50606_regulator_disable,
+ .is_enabled = pcf50606_regulator_is_enabled,
+};
+
+static struct regulator_desc regulators[] = {
+ [PCF50606_REGULATOR_DCD] =
+ PCF50606_REGULATOR("dcd", PCF50606_REGULATOR_DCD),
+ [PCF50606_REGULATOR_DCDE] =
+ PCF50606_REGULATOR("dcde", PCF50606_REGULATOR_DCDE),
+ [PCF50606_REGULATOR_DCUD] =
+ PCF50606_REGULATOR("dcud", PCF50606_REGULATOR_DCUD),
+ [PCF50606_REGULATOR_D1REG] =
+ PCF50606_REGULATOR("d1reg", PCF50606_REGULATOR_D1REG),
+ [PCF50606_REGULATOR_D2REG] =
+ PCF50606_REGULATOR("d2reg", PCF50606_REGULATOR_D2REG),
+ [PCF50606_REGULATOR_D3REG] =
+ PCF50606_REGULATOR("d3reg", PCF50606_REGULATOR_D3REG),
+ [PCF50606_REGULATOR_LPREG] =
+ PCF50606_REGULATOR("lpreg", PCF50606_REGULATOR_LPREG),
+ [PCF50606_REGULATOR_IOREG] =
+ PCF50606_REGULATOR("ioreg", PCF50606_REGULATOR_IOREG),
+};
+
+static int __devinit pcf50606_regulator_probe(struct platform_device *pdev)
+{
+ struct regulator_dev *rdev;
+ struct pcf50606 *pcf;
+
+ /* Already set by core driver */
+ pcf = dev_to_pcf50606(pdev->dev.parent);
+
+ rdev = regulator_register(&regulators[pdev->id], &pdev->dev,
+ pdev->dev.platform_data, pcf);
+ if (IS_ERR(rdev))
+ return PTR_ERR(rdev);
+
+ platform_set_drvdata(pdev, rdev);
+
+ if (pcf->pdata->regulator_registered)
+ pcf->pdata->regulator_registered(pcf, pdev->id);
+
+ return 0;
+}
+
+static int __devexit pcf50606_regulator_remove(struct platform_device *pdev)
+{
+ struct regulator_dev *rdev = platform_get_drvdata(pdev);
+
+ platform_set_drvdata(pdev, NULL);
+ regulator_unregister(rdev);
+
+ return 0;
+}
+
+static struct platform_driver pcf50606_regulator_driver = {
+ .driver = {
+ .name = "pcf50606-regltr",
+ },
+ .probe = pcf50606_regulator_probe,
+ .remove = __devexit_p(pcf50606_regulator_remove),
+};
+
+static int __init pcf50606_regulator_init(void)
+{
+ return platform_driver_register(&pcf50606_regulator_driver);
+}
+module_init(pcf50606_regulator_init);
+
+static void __exit pcf50606_regulator_exit(void)
+{
+ platform_driver_unregister(&pcf50606_regulator_driver);
+}
+module_exit(pcf50606_regulator_exit);
+
+MODULE_AUTHOR("Balaji Rao <balajirrao@openmoko.org>");
+MODULE_DESCRIPTION("PCF50606 regulator driver");
+MODULE_LICENSE("GPL");
+MODULE_ALIAS("platform:pcf50606-regulator");
diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig
index 81adbdbd504..7e0a1a4763e 100644
--- a/drivers/rtc/Kconfig
+++ b/drivers/rtc/Kconfig
@@ -535,6 +535,13 @@ config RTC_DRV_PCF50633
If you say yes here you get support for the RTC subsystem of the
NXP PCF50633 used in embedded systems.
+config RTC_DRV_PCF50606
+ depends on MFD_PCF50606
+ tristate "NXP PCF50606 RTC"
+ help
+ If you say yes here you get support for the RTC subsystem of the
+ NXP PCF50606 used in embedded systems.
+
comment "on-CPU RTC drivers"
config RTC_DRV_OMAP
diff --git a/drivers/rtc/Makefile b/drivers/rtc/Makefile
index 3c0f2b2ac92..8082cbfcfa5 100644
--- a/drivers/rtc/Makefile
+++ b/drivers/rtc/Makefile
@@ -77,4 +77,5 @@ obj-$(CONFIG_RTC_DRV_VR41XX) += rtc-vr41xx.o
obj-$(CONFIG_RTC_DRV_WM8350) += rtc-wm8350.o
obj-$(CONFIG_RTC_DRV_X1205) += rtc-x1205.o
obj-$(CONFIG_RTC_DRV_PCF50633) += rtc-pcf50633.o
+obj-$(CONFIG_RTC_DRV_PCF50606) += rtc-pcf50606.o
obj-$(CONFIG_RTC_DRV_PS3) += rtc-ps3.o
diff --git a/drivers/rtc/rtc-pcf50606.c b/drivers/rtc/rtc-pcf50606.c
new file mode 100644
index 00000000000..01ce1b9e48f
--- /dev/null
+++ b/drivers/rtc/rtc-pcf50606.c
@@ -0,0 +1,339 @@
+/* NXP PCF50606 RTC Driver
+ *
+ * (C) 2006-2008 by Openmoko, Inc.
+ * Author: Balaji Rao <balajirrao@openmoko.org>
+ * All rights reserved.
+ *
+ * Broken down from monstrous PCF50606 driver mainly by
+ * Harald Welte, Andy Green and Werner Almesberger
+ *
+ * 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.
+ *
+ */
+
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/init.h>
+#include <linux/device.h>
+#include <linux/platform_device.h>
+#include <linux/rtc.h>
+#include <linux/bcd.h>
+#include <linux/err.h>
+
+#include <linux/mfd/pcf50606/core.h>
+
+#define PCF50606_REG_RTCSC 0x0a /* Second */
+#define PCF50606_REG_RTCMN 0x0b /* Minute */
+#define PCF50606_REG_RTCHR 0x0c /* Hour */
+#define PCF50606_REG_RTCWD 0x0d /* Weekday */
+#define PCF50606_REG_RTCDT 0x0e /* Day */
+#define PCF50606_REG_RTCMT 0x0f /* Month */
+#define PCF50606_REG_RTCYR 0x10 /* Year */
+#define PCF50606_REG_RTCSCA 0x11 /* Alarm Second */
+#define PCF50606_REG_RTCMNA 0x12 /* Alarm Minute */
+#define PCF50606_REG_RTCHRA 0x13 /* Alarm Hour */
+#define PCF50606_REG_RTCWDA 0x14 /* Alarm Weekday */
+#define PCF50606_REG_RTCDTA 0x15 /* Alarm Day */
+#define PCF50606_REG_RTCMTA 0x16 /* Alarm Month */
+#define PCF50606_REG_RTCYRA 0x17 /* Alarm Year */
+
+enum pcf50606_time_indexes {
+ PCF50606_TI_SEC,
+ PCF50606_TI_MIN,
+ PCF50606_TI_HOUR,
+ PCF50606_TI_WKDAY,
+ PCF50606_TI_DAY,
+ PCF50606_TI_MONTH,
+ PCF50606_TI_YEAR,
+ PCF50606_TI_EXTENT /* always last */
+};
+
+struct pcf50606_time {
+ u_int8_t time[PCF50606_TI_EXTENT];
+};
+
+struct pcf50606_rtc {
+ int alarm_enabled;
+ int second_enabled;
+ int alarm_pending;
+
+ struct pcf50606 *pcf;
+ struct rtc_device *rtc_dev;
+};
+
+static void pcf2rtc_time(struct rtc_time *rtc, struct pcf50606_time *pcf)
+{
+ rtc->tm_sec = bcd2bin(pcf->time[PCF50606_TI_SEC]);
+ rtc->tm_min = bcd2bin(pcf->time[PCF50606_TI_MIN]);
+ rtc->tm_hour = bcd2bin(pcf->time[PCF50606_TI_HOUR]);
+ rtc->tm_wday = bcd2bin(pcf->time[PCF50606_TI_WKDAY]);
+ rtc->tm_mday = bcd2bin(pcf->time[PCF50606_TI_DAY]);
+ rtc->tm_mon = bcd2bin(pcf->time[PCF50606_TI_MONTH]) - 1;
+ rtc->tm_year = bcd2bin(pcf->time[PCF50606_TI_YEAR]) + 100;
+}
+
+static void rtc2pcf_time(struct pcf50606_time *pcf, struct rtc_time *rtc)
+{
+ pcf->time[PCF50606_TI_SEC] = bin2bcd(rtc->tm_sec);
+ pcf->time[PCF50606_TI_MIN] = bin2bcd(rtc->tm_min);
+ pcf->time[PCF50606_TI_HOUR] = bin2bcd(rtc->tm_hour);
+ pcf->time[PCF50606_TI_WKDAY] = bin2bcd(rtc->tm_wday);
+ pcf->time[PCF50606_TI_DAY] = bin2bcd(rtc->tm_mday);
+ pcf->time[PCF50606_TI_MONTH] = bin2bcd(rtc->tm_mon + 1);
+ pcf->time[PCF50606_TI_YEAR] = bin2bcd(rtc->tm_year % 100);
+}
+
+static int
+pcf50606_rtc_ioctl(struct device *dev, unsigned int cmd, unsigned long arg)
+{
+ struct pcf50606_rtc *rtc = dev_get_drvdata(dev);
+
+ switch (cmd) {
+ case RTC_AIE_OFF:
+ rtc->alarm_enabled = 0;
+ pcf50606_irq_mask(rtc->pcf, PCF50606_IRQ_ALARM);
+ return 0;
+ case RTC_AIE_ON:
+ rtc->alarm_enabled = 1;
+ pcf50606_irq_unmask(rtc->pcf, PCF50606_IRQ_ALARM);
+ return 0;
+ case RTC_UIE_OFF:
+ rtc->second_enabled = 0;
+ pcf50606_irq_mask(rtc->pcf, PCF50606_IRQ_SECOND);
+ return 0;
+ case RTC_UIE_ON:
+ rtc->second_enabled = 1;
+ pcf50606_irq_unmask(rtc->pcf, PCF50606_IRQ_SECOND);
+ return 0;
+ }
+
+ return -ENOIOCTLCMD;
+}
+
+static int pcf50606_rtc_read_time(struct device *dev, struct rtc_time *tm)
+{
+ struct pcf50606_rtc *rtc;
+ struct pcf50606_time pcf_tm;
+ int ret;
+
+ rtc = dev_get_drvdata(dev);
+
+ ret = pcf50606_read_block(rtc->pcf, PCF50606_REG_RTCSC,
+ PCF50606_TI_EXTENT,
+ &pcf_tm.time[0]);
+ if (ret != PCF50606_TI_EXTENT) {
+ dev_err(dev, "Failed to read time\n");
+ return -EIO;
+ }
+
+ dev_dbg(dev, "PCF_TIME: %02x.%02x.%02x %02x:%02x:%02x\n",
+ pcf_tm.time[PCF50606_TI_DAY],
+ pcf_tm.time[PCF50606_TI_MONTH],
+ pcf_tm.time[PCF50606_TI_YEAR],
+ pcf_tm.time[PCF50606_TI_HOUR],
+ pcf_tm.time[PCF50606_TI_MIN],
+ pcf_tm.time[PCF50606_TI_SEC]);
+
+ pcf2rtc_time(tm, &pcf_tm);
+
+ dev_dbg(dev, "RTC_TIME: %u.%u.%u %u:%u:%u\n",
+ tm->tm_mday, tm->tm_mon, tm->tm_year,
+ tm->tm_hour, tm->tm_min, tm->tm_sec);
+
+ return rtc_valid_tm(tm);
+}
+
+static int pcf50606_rtc_set_time(struct device *dev, struct rtc_time *tm)
+{
+ struct pcf50606_rtc *rtc;
+ struct pcf50606_time pcf_tm;
+ int second_masked, alarm_masked, ret = 0;
+
+ rtc = dev_get_drvdata(dev);
+
+ dev_dbg(dev, "RTC_TIME: %u.%u.%u %u:%u:%u\n",
+ tm->tm_mday, tm->tm_mon, tm->tm_year,
+ tm->tm_hour, tm->tm_min, tm->tm_sec);
+
+ rtc2pcf_time(&pcf_tm, tm);
+
+ dev_dbg(dev, "PCF_TIME: %02x.%02x.%02x %02x:%02x:%02x\n",
+ pcf_tm.time[PCF50606_TI_DAY],
+ pcf_tm.time[PCF50606_TI_MONTH],
+ pcf_tm.time[PCF50606_TI_YEAR],
+ pcf_tm.time[PCF50606_TI_HOUR],
+ pcf_tm.time[PCF50606_TI_MIN],
+ pcf_tm.time[PCF50606_TI_SEC]);
+
+
+ second_masked = pcf50606_irq_mask_get(rtc->pcf, PCF50606_IRQ_SECOND);
+ alarm_masked = pcf50606_irq_mask_get(rtc->pcf, PCF50606_IRQ_ALARM);
+
+ if (!second_masked)
+ pcf50606_irq_mask(rtc->pcf, PCF50606_IRQ_SECOND);
+ if (!alarm_masked)
+ pcf50606_irq_mask(rtc->pcf, PCF50606_IRQ_ALARM);
+
+ /* Returns 0 on success */
+ ret = pcf50606_write_block(rtc->pcf, PCF50606_REG_RTCSC,
+ PCF50606_TI_EXTENT,
+ &pcf_tm.time[0]);
+
+ if (!second_masked)
+ pcf50606_irq_unmask(rtc->pcf, PCF50606_IRQ_SECOND);
+ if (!alarm_masked)
+ pcf50606_irq_unmask(rtc->pcf, PCF50606_IRQ_ALARM);
+
+ return ret;
+}
+
+static int pcf50606_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm)
+{
+ struct pcf50606_rtc *rtc;
+ struct pcf50606_time pcf_tm;
+ int ret = 0;
+
+ rtc = dev_get_drvdata(dev);
+
+ alrm->enabled = rtc->alarm_enabled;
+ alrm->pending = rtc->alarm_pending;
+
+ ret = pcf50606_read_block(rtc->pcf, PCF50606_REG_RTCSCA,
+ PCF50606_TI_EXTENT, &pcf_tm.time[0]);
+ if (ret != PCF50606_TI_EXTENT) {
+ dev_err(dev, "Failed to read time\n");
+ return -EIO;
+ }
+
+ pcf2rtc_time(&alrm->time, &pcf_tm);
+
+ return rtc_valid_tm(&alrm->time);
+}
+
+static int pcf50606_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm)
+{
+ struct pcf50606_rtc *rtc;
+ struct pcf50606_time pcf_tm;
+ int alarm_masked, ret = 0;
+
+ rtc = dev_get_drvdata(dev);
+
+ rtc2pcf_time(&pcf_tm, &alrm->time);
+
+ /* do like mktime does and ignore tm_wday */
+ pcf_tm.time[PCF50606_TI_WKDAY] = 7;
+
+ alarm_masked = pcf50606_irq_mask_get(rtc->pcf, PCF50606_IRQ_ALARM);
+
+ /* disable alarm interrupt */
+ if (!alarm_masked)
+ pcf50606_irq_mask(rtc->pcf, PCF50606_IRQ_ALARM);
+
+ /* Returns 0 on success */
+ ret = pcf50606_write_block(rtc->pcf, PCF50606_REG_RTCSCA,
+ PCF50606_TI_EXTENT, &pcf_tm.time[0]);
+
+ if (!alrm->enabled)
+ rtc->alarm_pending = 0;
+
+ if (!alarm_masked || alrm->enabled)
+ pcf50606_irq_unmask(rtc->pcf, PCF50606_IRQ_ALARM);
+ rtc->alarm_enabled = alrm->enabled;
+
+ return ret;
+}
+
+static struct rtc_class_ops pcf50606_rtc_ops = {
+ .ioctl = pcf50606_rtc_ioctl,
+ .read_time = pcf50606_rtc_read_time,
+ .set_time = pcf50606_rtc_set_time,
+ .read_alarm = pcf50606_rtc_read_alarm,
+ .set_alarm = pcf50606_rtc_set_alarm,
+};
+
+static void pcf50606_rtc_irq(int irq, void *data)
+{
+ struct pcf50606_rtc *rtc = data;
+
+ switch (irq) {
+ case PCF50606_IRQ_ALARM:
+ rtc_update_irq(rtc->rtc_dev, 1, RTC_AF | RTC_IRQF);
+ rtc->alarm_pending = 1;
+ break;
+ case PCF50606_IRQ_SECOND:
+ rtc_update_irq(rtc->rtc_dev, 1, RTC_UF | RTC_IRQF);
+ break;
+ }
+}
+
+static int __devinit pcf50606_rtc_probe(struct platform_device *pdev)
+{
+ struct pcf50606_rtc *rtc;
+
+ rtc = kzalloc(sizeof(*rtc), GFP_KERNEL);
+ if (!rtc)
+ return -ENOMEM;
+
+ rtc->pcf = dev_to_pcf50606(pdev->dev.parent);
+ platform_set_drvdata(pdev, rtc);
+ rtc->rtc_dev = rtc_device_register("pcf50606-rtc", &pdev->dev,
+ &pcf50606_rtc_ops, THIS_MODULE);
+
+ if (IS_ERR(rtc->rtc_dev)) {
+ kfree(rtc);
+ return PTR_ERR(rtc->rtc_dev);
+ }
+
+ pcf50606_register_irq(rtc->pcf, PCF50606_IRQ_ALARM,
+ pcf50606_rtc_irq, rtc);
+ pcf50606_register_irq(rtc->pcf, PCF50606_IRQ_SECOND,
+ pcf50606_rtc_irq, rtc);
+
+ return 0;
+}
+
+
+static int __devexit pcf50606_rtc_remove(struct platform_device *pdev)
+{
+ struct pcf50606_rtc *rtc;
+
+ rtc = platform_get_drvdata(pdev);
+
+ pcf50606_free_irq(rtc->pcf, PCF50606_IRQ_ALARM);
+ pcf50606_free_irq(rtc->pcf, PCF50606_IRQ_SECOND);
+
+ rtc_device_unregister(rtc->rtc_dev);
+
+ kfree(rtc);
+
+ return 0;
+}
+
+
+static struct platform_driver pcf50606_rtc_driver = {
+ .driver = {
+ .name = "pcf50606-rtc",
+ },
+ .probe = pcf50606_rtc_probe,
+ .remove = __devexit_p(pcf50606_rtc_remove),
+};
+
+static int __init pcf50606_rtc_init(void)
+{
+ return platform_driver_register(&pcf50606_rtc_driver);
+}
+module_init(pcf50606_rtc_init);
+
+static void __exit pcf50606_rtc_exit(void)
+{
+ platform_driver_unregister(&pcf50606_rtc_driver);
+}
+module_exit(pcf50606_rtc_exit);
+
+MODULE_DESCRIPTION("PCF50606 RTC driver");
+MODULE_AUTHOR("Balaji Rao <balajirrao@openmoko.org>");
+MODULE_LICENSE("GPL");
+
diff --git a/drivers/watchdog/Kconfig b/drivers/watchdog/Kconfig
index b1ccc04f3c9..618cc10acc6 100644
--- a/drivers/watchdog/Kconfig
+++ b/drivers/watchdog/Kconfig
@@ -154,6 +154,13 @@ config S3C2410_WATCHDOG
The driver can be built as a module by choosing M, and will
be called s3c2410_wdt
+config PCF50606_WATCHDOG
+ depends on MFD_PCF50606
+ tristate "Philips PCF50606 watchdog"
+ help
+ If you say yes here you get support for the Philips PCF50606
+ PMU's watchdog.
+
config SA1100_WATCHDOG
tristate "SA1100/PXA2xx watchdog"
depends on ARCH_SA1100 || ARCH_PXA
diff --git a/drivers/watchdog/Makefile b/drivers/watchdog/Makefile
index 3d774294a2b..638e1c1d743 100644
--- a/drivers/watchdog/Makefile
+++ b/drivers/watchdog/Makefile
@@ -35,6 +35,7 @@ obj-$(CONFIG_IXP2000_WATCHDOG) += ixp2000_wdt.o
obj-$(CONFIG_IXP4XX_WATCHDOG) += ixp4xx_wdt.o
obj-$(CONFIG_KS8695_WATCHDOG) += ks8695_wdt.o
obj-$(CONFIG_S3C2410_WATCHDOG) += s3c2410_wdt.o
+obj-$(CONFIG_PCF50606_WATCHDOG) += pcf50606_wdt.o
obj-$(CONFIG_SA1100_WATCHDOG) += sa1100_wdt.o
obj-$(CONFIG_MPCORE_WATCHDOG) += mpcore_wdt.o
obj-$(CONFIG_EP93XX_WATCHDOG) += ep93xx_wdt.o
diff --git a/drivers/watchdog/pcf50606_wdt.c b/drivers/watchdog/pcf50606_wdt.c
new file mode 100644
index 00000000000..6a53c664b21
--- /dev/null
+++ b/drivers/watchdog/pcf50606_wdt.c
@@ -0,0 +1,216 @@
+/* Philips PCF50606 Watchdog Timer Driver
+ *
+ * (C) 2006-2008 by Openmoko, Inc.
+ * Author: Balaji Rao <balajirrao@openmoko.org>
+ * All rights reserved.
+ *
+ * Broken down from monstrous PCF50606 driver mainly by
+ * Harald Welte, Matt Hsu, Andy Green and Werner Almesberger
+ *
+ * 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.
+ */
+
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/init.h>
+#include <linux/device.h>
+#include <linux/rtc.h>
+#include <linux/bcd.h>
+#include <linux/err.h>
+#include <linux/miscdevice.h>
+#include <linux/watchdog.h>
+#include <linux/platform_device.h>
+
+#include <linux/mfd/pcf50606/core.h>
+
+static struct pcf50606 *pcf = NULL;
+static unsigned long wdt_status;
+
+#define WDT_IN_USE 0
+#define WDT_OK_TO_CLOSE 1
+#define WDT_REGION_INITED 2
+#define WDT_DEVICE_INITED 3
+
+static int allow_close;
+#define CLOSE_STATE_NOT 0x0000
+#define CLOSE_STATE_ALLOW 0x2342
+
+#define PCF50606_REG_OOCC1 0x08
+#define PCF50606_REG_OOCS 0x01
+
+#define PCF50606_OOCS_WDTEXP 0x80
+#define PCF50606_OOCC1_WDTRST 0x08
+
+static void pcf50606_wdt_start(void)
+{
+ pcf50606_reg_set_bit_mask(pcf, PCF50606_REG_OOCC1, PCF50606_OOCC1_WDTRST,
+ PCF50606_OOCC1_WDTRST);
+}
+
+static void pcf50606_wdt_stop(void)
+{
+ pcf50606_reg_clear_bits(pcf, PCF50606_REG_OOCS, PCF50606_OOCS_WDTEXP);
+}
+
+static void pcf50606_wdt_keepalive(void)
+{
+ pcf50606_wdt_start();
+}
+
+static int pcf50606_wdt_open(struct inode *inode, struct file *file)
+{
+ if (test_and_set_bit(WDT_IN_USE, &wdt_status))
+ return -EBUSY;
+
+ pcf50606_wdt_start();
+
+ return nonseekable_open(inode, file);
+}
+
+static int pcf50606_wdt_release(struct inode *inode, struct file *file)
+{
+ if (allow_close == CLOSE_STATE_ALLOW)
+ pcf50606_wdt_stop();
+ else {
+ printk(KERN_CRIT "Unexpected close, not stopping watchdog!\n");
+ pcf50606_wdt_keepalive();
+ }
+
+ allow_close = CLOSE_STATE_NOT;
+ clear_bit(WDT_IN_USE, &wdt_status);
+
+ return 0;
+}
+
+static ssize_t pcf50606_wdt_write(struct file *file, const char __user *data,
+ size_t len, loff_t *ppos)
+{
+ if (len) {
+ size_t i;
+
+ for (i = 0; i != len; i++) {
+ char c;
+ if (get_user(c, data + i))
+ return -EFAULT;
+ if (c == 'V')
+ allow_close = CLOSE_STATE_ALLOW;
+ }
+ pcf50606_wdt_keepalive();
+ }
+
+ return len;
+}
+
+static struct watchdog_info pcf50606_wdt_ident = {
+ .options = WDIOF_MAGICCLOSE,
+ .firmware_version = 0,
+ .identity = "PCF50606 Watchdog",
+};
+
+static int pcf50606_wdt_ioctl(struct inode *inode, struct file *file,
+ unsigned int cmd, unsigned long arg)
+{
+ void __user *argp = (void __user *)arg;
+ int __user *p = argp;
+
+ switch (cmd) {
+ case WDIOC_GETSUPPORT:
+ return copy_to_user(argp, &pcf50606_wdt_ident,
+ sizeof(pcf50606_wdt_ident)) ? -EFAULT : 0;
+ break;
+ case WDIOC_GETSTATUS:
+ case WDIOC_GETBOOTSTATUS:
+ return put_user(0, p);
+ case WDIOC_KEEPALIVE:
+ pcf50606_wdt_keepalive();
+ return 0;
+ case WDIOC_GETTIMEOUT:
+ return put_user(8, p);
+ default:
+ return -ENOIOCTLCMD;
+ }
+}
+
+static struct file_operations pcf50606_wdt_fops = {
+ .owner = THIS_MODULE,
+ .llseek = no_llseek,
+ .write = &pcf50606_wdt_write,
+ .ioctl = &pcf50606_wdt_ioctl,
+ .open = &pcf50606_wdt_open,
+ .release = &pcf50606_wdt_release,
+};
+
+static struct miscdevice pcf50606_wdt_miscdev = {
+ .minor = WATCHDOG_MINOR,
+ .name = "watchdog",
+ .fops = &pcf50606_wdt_fops,
+};
+
+static void pcf50606_wdt_irq(int irq, void *unused)
+{
+ pcf50606_reg_set_bit_mask(pcf, PCF50606_REG_OOCC1,
+ PCF50606_OOCC1_WDTRST,
+ PCF50606_OOCC1_WDTRST);
+}
+
+int __init pcf50606_wdt_probe(struct platform_device *pdev)
+{
+ int err;
+
+ if (pcf) {
+ dev_err(pcf->dev, "Only one instance of WDT supported\n");
+ return -ENODEV;
+ }
+
+ pcf = dev_to_pcf50606(pdev->dev.parent);
+
+ err = misc_register(&pcf50606_wdt_miscdev);
+ if (err) {
+ dev_err(&pdev->dev, "cannot register miscdev on "
+ "minor=%d (%d)\n", WATCHDOG_MINOR, err);
+ return err;
+ }
+ set_bit(WDT_DEVICE_INITED, &wdt_status);
+
+ pcf50606_register_irq(pcf, PCF50606_IRQ_CHGWD10S, pcf50606_wdt_irq, NULL);
+
+ return 0;
+}
+
+static int __devexit pcf50606_wdt_remove(struct platform_device *pdev)
+{
+ pcf50606_free_irq(pcf, PCF50606_IRQ_CHGWD10S);
+ misc_deregister(&pcf50606_wdt_miscdev);
+ pcf = NULL;
+
+ return 0;
+}
+
+struct platform_driver pcf50606_wdt_driver = {
+ .driver = {
+ .name = "pcf50606-wdt",
+ },
+ .probe = pcf50606_wdt_probe,
+ .remove = __devexit_p(pcf50606_wdt_remove),
+};
+
+static int __init pcf50606_wdt_init(void)
+{
+ return platform_driver_register(&pcf50606_wdt_driver);
+}
+module_init(pcf50606_wdt_init);
+
+static void __exit pcf50606_wdt_exit(void)
+{
+ platform_driver_unregister(&pcf50606_wdt_driver);
+}
+module_exit(pcf50606_wdt_exit);
+
+MODULE_AUTHOR("Balaji Rao <balajirrao@openmoko.org>");
+MODULE_DESCRIPTION("PCF50606 wdt driver");
+MODULE_LICENSE("GPL");
+MODULE_ALIAS("platform:pcf50606-wdt");
+
diff --git a/include/linux/mfd/pcf50606/adc.h b/include/linux/mfd/pcf50606/adc.h
new file mode 100644
index 00000000000..fd4840300dd
--- /dev/null
+++ b/include/linux/mfd/pcf50606/adc.h
@@ -0,0 +1,72 @@
+/*
+ * adc.h -- Driver for NXP PCF50606 ADC
+ *
+ * (C) 2006-2008 by Openmoko, Inc.
+ * All rights reserved.
+ *
+ * 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.
+ */
+
+#ifndef __LINUX_MFD_PCF50606_ADC_H
+#define __LINUX_MFD_PCF50606_ADC_H
+
+#include <linux/mfd/pcf50633/core.h>
+#include <linux/platform_device.h>
+
+/* ADC Registers */
+#define PCF50606_REG_ADCC1 0x2e
+#define PCF50606_REG_ADCC2 0x2f
+#define PCF50606_REG_ADCS1 0x30
+#define PCF50606_REG_ADCS2 0x31
+#define PCF50606_REG_ADCS3 0x32
+
+#define PCF50606_ADCC1_TSCMODACT 0x01
+#define PCF50606_ADCC1_TSCMODSTB 0x02
+#define PCF50606_ADCC1_TRATSET 0x04
+#define PCF50606_ADCC1_NTCSWAPE 0x08
+#define PCF50606_ADCC1_NTCSWAOFF 0x10
+#define PCF50606_ADCC1_EXTSYNCBREAK 0x20
+ /* reserved */
+#define PCF50606_ADCC1_TSCINT 0x80
+
+#define PCF50606_ADCC2_ADCSTART 0x01
+ /* see enum pcf50606_adcc2_adcmux */
+#define PCF50606_ADCC2_SYNC_NONE 0x00
+#define PCF50606_ADCC2_SYNC_TXON 0x20
+#define PCF50606_ADCC2_SYNC_PWREN1 0x40
+#define PCF50606_ADCC2_SYNC_PWREN2 0x60
+#define PCF50606_ADCC2_RES_10BIT 0x00
+#define PCF50606_ADCC2_RES_8BIT 0x80
+
+#define PCF50606_ADCC2_ADCMUX_MASK (0xf << 1)
+
+#define ADCMUX_SHIFT 1
+#define PCF50606_ADCMUX_BATVOLT_RES (0x0 << ADCMUX_SHIFT)
+#define PCF50606_ADCMUX_BATVOLT_SUBTR (0x1 << ADCMUX_SHIFT)
+#define PCF50606_ADCMUX_ADCIN1_RES (0x2 << ADCMUX_SHIFT)
+#define PCF50606_ADCMUX_ADCIN1_SUBTR (0x3 << ADCMUX_SHIFT)
+#define PCF50606_ADCMUX_BATTEMP (0x4 << ADCMUX_SHIFT)
+#define PCF50606_ADCMUX_ADCIN2 (0x5 << ADCMUX_SHIFT)
+#define PCF50606_ADCMUX_ADCIN3 (0x6 << ADCMUX_SHIFT)
+#define PCF50606_ADCMUX_ADCIN3_RATIO (0x7 << ADCMUX_SHIFT)
+#define PCF50606_ADCMUX_XPOS (0x8 << ADCMUX_SHIFT)
+#define PCF50606_ADCMUX_YPOS (0x9 << ADCMUX_SHIFT)
+#define PCF50606_ADCMUX_P1 (0xa << ADCMUX_SHIFT)
+#define PCF50606_ADCMUX_P2 (0xb << ADCMUX_SHIFT)
+#define PCF50606_ADCMUX_BATVOLT_ADCIN1 (0xc << ADCMUX_SHIFT)
+#define PCF50606_ADCMUX_XY_SEQUENCE (0xe << ADCMUX_SHIFT)
+#define PCF50606_P1_P2_RESISTANCE (0xf << ADCMUX_SHIFT)
+
+#define PCF50606_ADCS2_ADCRDY 0x80
+
+extern int
+pcf50606_adc_async_read(struct pcf50606 *pcf, int mux,
+ void (*callback)(struct pcf50606 *, void *, int),
+ void *callback_param);
+extern int
+pcf50606_adc_sync_read(struct pcf50606 *pcf, int mux);
+
+#endif /* __LINUX_PCF50606_ADC_H */
diff --git a/include/linux/mfd/pcf50606/core.h b/include/linux/mfd/pcf50606/core.h
new file mode 100644
index 00000000000..e036e07064c
--- /dev/null
+++ b/include/linux/mfd/pcf50606/core.h
@@ -0,0 +1,172 @@
+/*
+ * core.h -- Core driver for NXP PCF50606
+ *
+ * (C) 2006-2008 by Openmoko, Inc.
+ * All rights reserved.
+ *
+ * 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.
+ */
+
+#ifndef __LINUX_MFD_PCF50606_CORE_H
+#define __LINUX_MFD_PCF50606_CORE_H
+
+#include <linux/i2c.h>
+#include <linux/workqueue.h>
+#include <linux/regulator/driver.h>
+#include <linux/regulator/machine.h>
+#include <linux/power_supply.h>
+
+struct pcf50606;
+
+#define PCF50606_NUM_REGULATORS 8
+
+struct pcf50606_platform_data {
+ struct regulator_init_data reg_init_data[PCF50606_NUM_REGULATORS];
+
+ char **batteries;
+ int num_batteries;
+
+ /* Callbacks */
+ void (*probe_done)(struct pcf50606 *);
+ void (*mbc_event_callback)(struct pcf50606 *, int);
+ void (*regulator_registered)(struct pcf50606 *, int);
+ void (*force_shutdown)(struct pcf50606 *);
+
+ u8 resumers[3];
+};
+
+struct pcf50606_irq {
+ void (*handler)(int, void *);
+ void *data;
+};
+
+int pcf50606_register_irq(struct pcf50606 *pcf, int irq,
+ void (*handler) (int, void *), void *data);
+int pcf50606_free_irq(struct pcf50606 *pcf, int irq);
+
+int pcf50606_irq_mask(struct pcf50606 *pcf, int irq);
+int pcf50606_irq_unmask(struct pcf50606 *pcf, int irq);
+int pcf50606_irq_mask_get(struct pcf50606 *pcf, int irq);
+
+int pcf50606_read_block(struct pcf50606 *, u8 reg,
+ int nr_regs, u8 *data);
+int pcf50606_write_block(struct pcf50606 *pcf, u8 reg,
+ int nr_regs, u8 *data);
+u8 pcf50606_reg_read(struct pcf50606 *, u8 reg);
+int pcf50606_reg_write(struct pcf50606 *pcf, u8 reg, u8 val);
+
+int pcf50606_reg_set_bit_mask(struct pcf50606 *pcf, u8 reg, u8 mask, u8 val);
+int pcf50606_reg_clear_bits(struct pcf50606 *pcf, u8 reg, u8 bits);
+
+/* Interrupt registers */
+
+#define PCF50606_REG_INT1 0x02
+#define PCF50606_REG_INT2 0x03
+#define PCF50606_REG_INT3 0x04
+
+#define PCF50606_REG_INT1M 0x05
+#define PCF50606_REG_INT2M 0x06
+#define PCF50606_REG_INT3M 0x07
+
+enum {
+ /* Chip IRQs */
+ PCF50606_IRQ_ONKEYR,
+ PCF50606_IRQ_ONKEYF,
+ PCF50606_IRQ_ONKEY1S,
+ PCF50606_IRQ_EXTONR,
+ PCF50606_IRQ_EXTONF,
+ PCF50606_IRQ_RESERVED_1,
+ PCF50606_IRQ_SECOND,
+ PCF50606_IRQ_ALARM,
+ PCF50606_IRQ_CHGINS,
+ PCF50606_IRQ_CHGRM,
+ PCF50606_IRQ_CHGFOK,
+ PCF50606_IRQ_CHGERR,
+ PCF50606_IRQ_CHGFRDY,
+ PCF50606_IRQ_CHGPROT,
+ PCF50606_IRQ_CHGWD10S,
+ PCF50606_IRQ_CHGWDEXP,
+ PCF50606_IRQ_ADCRDY,
+ PCF50606_IRQ_ACDINS,
+ PCF50606_IRQ_ACDREM,
+ PCF50606_IRQ_TSCPRES,
+ PCF50606_IRQ_RESERVED_2,
+ PCF50606_IRQ_RESERVED_3,
+ PCF50606_IRQ_LOWBAT,
+ PCF50606_IRQ_HIGHTMP,
+
+ /* Always last */
+ PCF50606_NUM_IRQ,
+};
+
+struct pcf50606 {
+ struct device *dev;
+ struct i2c_client *i2c_client;
+
+ struct pcf50606_platform_data *pdata;
+ int irq;
+ struct pcf50606_irq irq_handler[PCF50606_NUM_IRQ];
+ struct work_struct irq_work;
+ struct mutex lock;
+
+ u8 mask_regs[3];
+
+ u8 suspend_irq_masks[3];
+ u8 resume_reason[3];
+ int is_suspended;
+
+ int onkey1s_held;
+
+ struct platform_device *rtc_pdev;
+ struct platform_device *mbc_pdev;
+ struct platform_device *adc_pdev;
+ struct platform_device *input_pdev;
+ struct platform_device *wdt_pdev;
+ struct platform_device *regulator_pdev[PCF50606_NUM_REGULATORS];
+};
+
+enum pcf50606_reg_int1 {
+ PCF50606_INT1_ONKEYR = 0x01, /* ONKEY rising edge */
+ PCF50606_INT1_ONKEYF = 0x02, /* ONKEY falling edge */
+ PCF50606_INT1_ONKEY1S = 0x04, /* OMKEY at least 1sec low */
+ PCF50606_INT1_EXTONR = 0x08, /* EXTON rising edge */
+ PCF50606_INT1_EXTONF = 0x10, /* EXTON falling edge */
+ PCF50606_INT1_SECOND = 0x40, /* RTC periodic second interrupt */
+ PCF50606_INT1_ALARM = 0x80, /* RTC alarm time is reached */
+};
+
+enum pcf50606_reg_int2 {
+ PCF50606_INT2_CHGINS = 0x01, /* Charger inserted */
+ PCF50606_INT2_CHGRM = 0x02, /* Charger removed */
+ PCF50606_INT2_CHGFOK = 0x04, /* Fast charging OK */
+ PCF50606_INT2_CHGERR = 0x08, /* Error in charging mode */
+ PCF50606_INT2_CHGFRDY = 0x10, /* Fast charge completed */
+ PCF50606_INT2_CHGPROT = 0x20, /* Charging protection interrupt */
+ PCF50606_INT2_CHGWD10S = 0x40, /* Charger watchdig expires in 10s */
+ PCF50606_INT2_CHGWDEXP = 0x80, /* Charger watchdog expires */
+};
+
+enum pcf50606_reg_int3 {
+ PCF50606_INT3_ADCRDY = 0x01, /* ADC conversion finished */
+ PCF50606_INT3_ACDINS = 0x02, /* Accessory inserted */
+ PCF50606_INT3_ACDREM = 0x04, /* Accessory removed */
+ PCF50606_INT3_TSCPRES = 0x08, /* Touch screen pressed */
+ PCF50606_INT3_LOWBAT = 0x40, /* Low battery voltage */
+ PCF50606_INT3_HIGHTMP = 0x80, /* High temperature */
+};
+
+/* Misc regs */
+
+#define PCF50606_REG_OOCC1 0x08
+#define PCF50606_OOCC1_GOSTDBY 0x01
+
+static inline struct pcf50606 *dev_to_pcf50606(struct device *dev)
+{
+ return dev_get_drvdata(dev);
+}
+
+#endif
+
diff --git a/include/linux/mfd/pcf50606/gpo.h b/include/linux/mfd/pcf50606/gpo.h
new file mode 100644
index 00000000000..081b127d754
--- /dev/null
+++ b/include/linux/mfd/pcf50606/gpo.h
@@ -0,0 +1,42 @@
+/*
+ * gpo.h -- GPO driver for NXP PCF50606
+ *
+ * (C) 2006-2008 by Openmoko, Inc.
+ * All rights reserved.
+ *
+ * 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.
+ */
+
+#ifndef __LINUX_MFD_PCF50606_GPO_H
+#define __LINUX_MFD_PCF50606_GPO_H
+
+#include <linux/mfd/pcf50633/core.h>
+
+#define PCF50606_REG_GPOC1 0x38
+#define PCF50606_REG_GPOC2 0x39
+#define PCF50606_REG_GPOC3 0x3a
+#define PCF50606_REG_GPOC4 0x3b
+#define PCF50606_REG_GPOC5 0x3c
+
+#define PCF50606_GPO1 PCF50606_REG_GPOC1
+#define PCF50606_GPO2 PCF50606_REG_GPOC1
+#define PCF50606_GPOOD1 PCF50606_REG_GPOC2
+#define PCF50606_GPOOD2 PCF50606_REG_GPOC3
+#define PCF50606_GPOOD3 PCF50606_REG_GPOC4
+#define PCF50606_GPOOD4 PCF50606_REG_GPOC5
+
+#define PCF50606_GPOCFG_GPOSEL_MASK 0x07
+
+void pcf50606_gpo_set_active(struct pcf50606 *pcf, int gpo, int value);
+int pcf50606_gpo_get_active(struct pcf50606 *pcf, int gpo);
+void pcf50606_gpo_set_standby(struct pcf50606 *pcf, int gpo, int value);
+int pcf50606_gpo_get_standby(struct pcf50606 *pcf, int gpo);
+
+void pcf50606_gpo_invert_set(struct pcf50606 *, int gpo, int invert);
+int pcf50606_gpo_invert_get(struct pcf50606 *pcf, int gpo);
+
+#endif /* __LINUX_MFD_PCF50606_GPIO_H */
+
diff --git a/include/linux/mfd/pcf50606/mbc.h b/include/linux/mfd/pcf50606/mbc.h
new file mode 100644
index 00000000000..b793d703a64
--- /dev/null
+++ b/include/linux/mfd/pcf50606/mbc.h
@@ -0,0 +1,52 @@
+/*
+ * mbc.h -- Driver for NXP PCF50606 Main Battery Charger
+ *
+ * (C) 2006-2008 by Openmoko, Inc.
+ * All rights reserved.
+ *
+ * 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.
+ */
+
+#ifndef __LINUX_MFD_PCF50606_MBC_H
+#define __LINUX_MFD_PCF50606_MBC_H
+
+#include <linux/mfd/pcf50606/core.h>
+#include <linux/platform_device.h>
+
+#define PCF50606_REG_OOCS 0x01
+
+/* Charger OK */
+#define PCF50606_OOCS_CHGOK 0x20
+
+#define PCF50606_REG_MBCC1 0x29
+#define PCF50606_REG_MBCC2 0x2a
+#define PCF50606_REG_MBCC3 0x2b
+#define PCF50606_REG_MBCS1 0x2c
+
+#define PCF50606_MBCC1_CHGAPE 0x01
+#define PCF50606_MBCC1_AUTOFST 0x02
+#define PCF50606_MBCC1_CHGMOD_MASK 0x1c
+#define PCF50606_MBCC1_CHGMOD_QUAL 0x00
+#define PCF50606_MBCC1_CHGMOD_PRE 0x04
+#define PCF50606_MBCC1_CHGMOD_TRICKLE 0x08
+#define PCF50606_MBCC1_CHGMOD_FAST_CCCV 0x0c
+#define PCF50606_MBCC1_CHGMOD_FAST_NOCC 0x10
+#define PCF50606_MBCC1_CHGMOD_FAST_NOCV 0x14
+#define PCF50606_MBCC1_CHGMOD_FAST_SW 0x18
+#define PCF50606_MBCC1_CHGMOD_IDLE 0x1c
+#define PCF50606_MBCC1_DETMOD_LOWCHG 0x20
+#define PCF50606_MBCC1_DETMOD_WDRST 0x40
+
+#define PCF50606_MBCC1_CHGMOD_SHIFT 2
+
+/* Charger status */
+#define PCF50606_MBC_CHARGER_ONLINE 0x01
+#define PCF50606_MBC_CHARGER_ACTIVE 0x02
+
+void pcf50606_charge_fast(struct pcf50606 *pcf, int on);
+
+#endif
+
diff --git a/include/linux/mfd/pcf50606/pmic.h b/include/linux/mfd/pcf50606/pmic.h
new file mode 100644
index 00000000000..1bcfe39025b
--- /dev/null
+++ b/include/linux/mfd/pcf50606/pmic.h
@@ -0,0 +1,73 @@
+#ifndef __LINUX_MFD_PCF50606_PMIC_H
+#define __LINUX_MFD_PCF50606_PMIC_H
+
+#define PCF50606_REG_DCDC1 0x1b
+#define PCF50606_REG_DCDC2 0x1c
+#define PCF50606_REG_DCDC3 0x1d
+#define PCF50606_REG_DCDC4 0x1e
+#define PCF50606_REG_DCDEC1 0x1f
+#define PCF50606_REG_DCDEC2 0x20
+#define PCF50606_REG_DCUDC1 0x21
+#define PCF50606_REG_DCUDC2 0x22
+#define PCF50606_REG_IOREGC 0x23
+#define PCF50606_REG_D1REGC1 0x24
+#define PCF50606_REG_D2REGC1 0x25
+#define PCF50606_REG_D3REGC1 0x26
+#define PCF50606_REG_LPREGC1 0x27
+#define PCF50606_REG_LPREGC2 0x28
+
+/* used by PSSC, PWROKM, PWROKS, */
+enum pcf50606_regu {
+ PCF50606_REGU_DCD = 0x01, /* DCD in phase 2 */
+ PCF50606_REGU_DCDE = 0x02, /* DCDE in phase 2 */
+ PCF50606_REGU_DCUD = 0x04, /* DCDU in phase 2 */
+ PCF50606_REGU_IO = 0x08, /* IO in phase 2 */
+ PCF50606_REGU_D1 = 0x10, /* D1 in phase 2 */
+ PCF50606_REGU_D2 = 0x20, /* D2 in phase 2 */
+ PCF50606_REGU_D3 = 0x40, /* D3 in phase 2 */
+ PCF50606_REGU_LP = 0x80, /* LP in phase 2 */
+};
+
+enum pcf50606_reg_dcdc4 {
+ PCF50606_DCDC4_MODE_AUTO = 0x00,
+ PCF50606_DCDC4_MODE_PWM = 0x01,
+ PCF50606_DCDC4_MODE_PCF = 0x02,
+ PCF50606_DCDC4_OFF_FLOAT = 0x00,
+ PCF50606_DCDC4_OFF_BYPASS = 0x04,
+ PCF50606_DCDC4_OFF_PULLDOWN = 0x08,
+ PCF50606_DCDC4_CURLIM_500mA = 0x00,
+ PCF50606_DCDC4_CURLIM_750mA = 0x10,
+ PCF50606_DCDC4_CURLIM_1000mA = 0x20,
+ PCF50606_DCDC4_CURLIM_1250mA = 0x30,
+ PCF50606_DCDC4_TOGGLE = 0x40,
+ PCF50606_DCDC4_REGSEL_DCDC2 = 0x80,
+};
+
+enum pcf50606_reg_dcdec2 {
+ PCF50606_DCDEC2_MODE_AUTO = 0x00,
+ PCF50606_DCDEC2_MODE_PWM = 0x01,
+ PCF50606_DCDEC2_MODE_PCF = 0x02,
+ PCF50606_DCDEC2_OFF_FLOAT = 0x00,
+ PCF50606_DCDEC2_OFF_BYPASS = 0x04,
+};
+
+enum pcf50606_reg_dcudc2 {
+ PCF50606_DCUDC2_MODE_AUTO = 0x00,
+ PCF50606_DCUDC2_MODE_PWM = 0x01,
+ PCF50606_DCUDC2_MODE_PCF = 0x02,
+ PCF50606_DCUDC2_OFF_FLOAT = 0x00,
+ PCF50606_DCUDC2_OFF_BYPASS = 0x04,
+};
+
+enum pcf50606_regulator_id {
+ PCF50606_REGULATOR_DCD,
+ PCF50606_REGULATOR_DCDE,
+ PCF50606_REGULATOR_DCUD,
+ PCF50606_REGULATOR_D1REG,
+ PCF50606_REGULATOR_D2REG,
+ PCF50606_REGULATOR_D3REG,
+ PCF50606_REGULATOR_LPREG,
+ PCF50606_REGULATOR_IOREG,
+};
+
+#endif