[UPSTREAM 1/1] pcf50633 rewrite to use MFD model
Balaji Rao
balajirrao at openmoko.org
Sun Nov 16 20:34:54 CET 2008
pcf50633 driver rewritten to use the MFD model.
diff --git a/arch/arm/configs/gta02-moredrivers-defconfig b/arch/arm/configs/gta02-moredrivers-defconfig
index 2b292be..99f0e3f 100644
--- a/arch/arm/configs/gta02-moredrivers-defconfig
+++ b/arch/arm/configs/gta02-moredrivers-defconfig
@@ -960,6 +960,7 @@ CONFIG_INPUT_MISC=y
# CONFIG_INPUT_CM109 is not set
CONFIG_INPUT_UINPUT=m
CONFIG_INPUT_LIS302DL=y
+CONFIG_INPUT_PCF50633_PMU=y
#
# Hardware I/O ports
@@ -1193,6 +1194,10 @@ CONFIG_SSB_POSSIBLE=y
# CONFIG_PMIC_DA903X is not set
# CONFIG_MFD_WM8400 is not set
# CONFIG_MFD_WM8350_I2C is not set
+CONFIG_MFD_PCF50633=y
+CONFIG_MFD_PCF50633_ADC=y
+CONFIG_MFD_PCF50633_MBC=y
+CONFIG_MFD_PCF50633_GPIO=y
CONFIG_MFD_GLAMO=y
CONFIG_MFD_GLAMO_FB=y
CONFIG_MFD_GLAMO_SPI_GPIO=y
@@ -1614,6 +1619,7 @@ CONFIG_RTC_INTF_DEV=y
# CONFIG_RTC_DRV_X1205 is not set
# CONFIG_RTC_DRV_PCF8563 is not set
# CONFIG_RTC_DRV_PCF8583 is not set
+CONFIG_RTC_DRV_PCF50633=y
# CONFIG_RTC_DRV_M41T80 is not set
# CONFIG_RTC_DRV_S35390A is not set
# CONFIG_RTC_DRV_FM3130 is not set
diff --git a/arch/arm/mach-s3c2440/Kconfig b/arch/arm/mach-s3c2440/Kconfig
index 8c8864e..af100c1 100644
--- a/arch/arm/mach-s3c2440/Kconfig
+++ b/arch/arm/mach-s3c2440/Kconfig
@@ -86,7 +86,13 @@ config MACH_AT2440EVB
config MACH_NEO1973_GTA02
bool "FIC Neo1973 GSM Phone (GTA02 Hardware)"
select CPU_S3C2442
- select SENSORS_PCF50633
+ select MFD_PCF50633
+ select INPUT_PCF50633_PMU
+ select MFD_PCF50633_ADC
+ select MFD_PCF50633_MBC
+ select MFD_PCF50633_PMIC
+ select MFD_PCF50633_GPIO
+ select REGULATOR_PCF50633
select POWER_SUPPLY
select GTA02_HDQ
select MACH_NEO1973
diff --git a/drivers/input/misc/Kconfig b/drivers/input/misc/Kconfig
index 8aa8bc1..23e3bd0 100644
--- a/drivers/input/misc/Kconfig
+++ b/drivers/input/misc/Kconfig
@@ -229,4 +229,8 @@ config INPUT_LIS302DL
The userspece interface is a 3-axis (X/Y/Z) relative movement
Linux input device, reporting REL_[XYZ] events.
+config INPUT_PCF50633_PMU
+ tristate "PCF50633 PMU events"
+ depends on MFD_PCF50633
+
endif
diff --git a/drivers/input/misc/Makefile b/drivers/input/misc/Makefile
index 75a7a2e..f0ef98e 100644
--- a/drivers/input/misc/Makefile
+++ b/drivers/input/misc/Makefile
@@ -22,4 +22,4 @@ obj-$(CONFIG_INPUT_UINPUT) += uinput.o
obj-$(CONFIG_INPUT_APANEL) += apanel.o
obj-$(CONFIG_INPUT_SGI_BTNS) += sgi_btns.o
obj-$(CONFIG_INPUT_LIS302DL) += lis302dl.o
-
+obj-$(CONFIG_INPUT_PCF50633_PMU) += pcf50633-input.o
diff --git a/drivers/input/misc/pcf50633-input.c b/drivers/input/misc/pcf50633-input.c
new file mode 100644
index 0000000..5423ef3
--- /dev/null
+++ b/drivers/input/misc/pcf50633-input.c
@@ -0,0 +1,106 @@
+#include <linux/input.h>
+
+#include <linux/mfd/pcf50633/core.h>
+#include <linux/mfd/pcf50633/input.h>
+
+static void
+pcf50633_input_irq(struct pcf50633 *pcf, int irq, void *data)
+{
+ struct input_dev *input_dev = pcf->input.input_dev;
+ int onkey_released;
+
+
+ /* We report only one event depending on if the key status */
+ onkey_released = pcf50633_reg_read(pcf, PCF50633_REG_OOCSTAT) &
+ PCF50633_OOCSTAT_ONKEY;
+
+ if (irq == PCF50633_IRQ_ONKEYF && !onkey_released)
+ input_report_key(input_dev, KEY_POWER, 1);
+ else if (irq == PCF50633_IRQ_ONKEYR && onkey_released)
+ input_report_key(input_dev, KEY_POWER, 0);
+
+ /* MBC makes sure that only one of USBINS/USBREM will be called */
+ if (irq == PCF50633_IRQ_USBINS)
+ input_report_key(input_dev, KEY_POWER2, 1);
+ else if (irq == PCF50633_IRQ_USBREM)
+ input_report_key(input_dev, KEY_POWER2, 0);
+
+ input_sync(input_dev);
+}
+
+int __init pcf50633_input_probe(struct platform_device *pdev)
+{
+ struct pcf50633 *pcf;
+ struct input_dev *input_dev;
+ int ret;
+
+ pcf = platform_get_drvdata(pdev);
+
+ input_dev = input_allocate_device();
+ if (!input_dev)
+ return -ENODEV;
+
+ input_dev->name = "GTA02 PMU events";
+ input_dev->phys = "FIXME";
+ input_dev->id.bustype = BUS_I2C;
+
+ input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_PWR);
+ set_bit(KEY_POWER, input_dev->keybit);
+ set_bit(KEY_POWER2, input_dev->keybit);
+
+ ret = input_register_device(input_dev);
+ if (ret)
+ goto out;
+
+ pcf->input.input_dev = input_dev;
+
+ /* Currently we care only about ONKEY and USBINS/USBREM
+ *
+ * USBINS/USBREM are told to us by mbc driver as we can't setup
+ * two handlers for an IRQ
+ */
+ pcf->irq_handler[PCF50633_IRQ_ONKEYR].handler = pcf50633_input_irq;
+
+ pcf->irq_handler[PCF50633_IRQ_ONKEYF].handler = pcf50633_input_irq;
+
+ return 0;
+
+out:
+ input_free_device(input_dev);
+ return ret;
+}
+
+static int __devexit pcf50633_input_remove(struct platform_device *pdev)
+{
+ struct pcf50633 *pcf;
+
+ pcf = platform_get_drvdata(pdev);
+ input_unregister_device(pcf->input.input_dev);
+
+ return 0;
+}
+
+struct platform_driver pcf50633_input_driver = {
+ .driver = {
+ .name = "pcf50633-input",
+ },
+ .probe = pcf50633_input_probe,
+ .remove = __devexit_p(pcf50633_input_remove),
+};
+
+static int __init pcf50633_input_init(void)
+{
+ return platform_driver_register(&pcf50633_input_driver);
+}
+module_init(pcf50633_input_init);
+
+static void __exit pcf50633_input_exit(void)
+{
+ platform_driver_unregister(&pcf50633_input_driver);
+}
+module_exit(pcf50633_input_exit);
+
+MODULE_AUTHOR("Balaji Rao <balajirrao at openmoko.org>");
+MODULE_DESCRIPTION("PCF50633 input driver");
+MODULE_LICENSE("GPL");
+MODULE_ALIAS("platform:pcf50633-input");
diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig
index 10e5b2c..84920f6 100644
--- a/drivers/mfd/Kconfig
+++ b/drivers/mfd/Kconfig
@@ -153,6 +153,22 @@ config MFD_WM8350_I2C
I2C as the control interface. Additional options must be
selected to enable support for the functionality of the chip.
+config MFD_PCF50633
+ tristate "Support for NXP PCF50633"
+ depends on I2C
+
+config MFD_PCF50633_ADC
+ tristate "Support for NXP PCF50633 ADC"
+ depends on MFD_PCF50633
+
+config MFD_PCF50633_MBC
+ tristate "Support for NXP PCF50633 MBC"
+ depends on MFD_PCF50633
+
+config MFD_PCF50633_GPIO
+ tristate "Support for NXP PCF50633 GPIO"
+ depends on MFD_PCF50633
+
source "drivers/mfd/glamo/Kconfig"
endmenu
diff --git a/drivers/mfd/Makefile b/drivers/mfd/Makefile
index b917368..30f1091 100644
--- a/drivers/mfd/Makefile
+++ b/drivers/mfd/Makefile
@@ -32,4 +32,9 @@ obj-$(CONFIG_MCP_UCB1200) += ucb1x00-assabet.o
endif
obj-$(CONFIG_UCB1400_CORE) += ucb1400_core.o
-obj-$(CONFIG_PMIC_DA903X) += da903x.o
\ No newline at end of file
+obj-$(CONFIG_PMIC_DA903X) += da903x.o
+
+obj-$(CONFIG_MFD_PCF50633) += pcf50633-core.o
+obj-$(CONFIG_MFD_PCF50633_ADC) += pcf50633-adc.o
+obj-$(CONFIG_MFD_PCF50633_MBC) += pcf50633-mbc.o
+obj-$(CONFIG_MFD_PCF50633_GPIO) += pcf50633-gpio.o
diff --git a/drivers/mfd/pcf50633-adc.c b/drivers/mfd/pcf50633-adc.c
new file mode 100644
index 0000000..936f7c2
--- /dev/null
+++ b/drivers/mfd/pcf50633-adc.c
@@ -0,0 +1,218 @@
+#include <linux/mfd/pcf50633/core.h>
+#include <linux/mfd/pcf50633/adc.h>
+
+struct pcf50633_adc_request {
+ int mux;
+ int avg;
+ int result;
+ void (*callback)(struct pcf50633 *, void *, int);
+ void *callback_param;
+
+ /* Used in case of sync requests */
+ struct completion completion;
+
+};
+
+static void adc_read_setup(struct pcf50633 *pcf,
+ int channel, int avg)
+{
+ channel &= PCF50633_ADCC1_ADCMUX_MASK;
+
+ /* kill ratiometric, but enable ACCSW biasing */
+ pcf50633_reg_write(pcf, PCF50633_REG_ADCC2, 0x00);
+ pcf50633_reg_write(pcf, PCF50633_REG_ADCC3, 0x01);
+
+ /* start ADC conversion of selected channel */
+ pcf50633_reg_write(pcf, PCF50633_REG_ADCC1, channel | avg |
+ PCF50633_ADCC1_ADCSTART | PCF50633_ADCC1_RES_10BIT);
+
+}
+
+static void trigger_next_adc_job_if_any(struct pcf50633 *pcf)
+{
+ int head, tail;
+
+ mutex_lock(&pcf->adc.queue_mutex);
+
+ head = pcf->adc.queue_head;
+ tail = pcf->adc.queue_tail;
+
+ if (!pcf->adc.queue[head])
+ goto out;
+
+ adc_read_setup(pcf, pcf->adc.queue[head]->mux,
+ pcf->adc.queue[head]->avg);
+out:
+ mutex_unlock(&pcf->adc.queue_mutex);
+}
+
+static int
+adc_enqueue_request(struct pcf50633 *pcf, struct pcf50633_adc_request *req)
+{
+ int head, tail;
+
+ mutex_lock(&pcf->adc.queue_mutex);
+ head = pcf->adc.queue_head;
+ tail = pcf->adc.queue_tail;
+
+ if (pcf->adc.queue[tail]) {
+ mutex_unlock(&pcf->adc.queue_mutex);
+ return -EBUSY;
+ }
+
+ pcf->adc.queue[tail] = req;
+
+ pcf->adc.queue_tail =
+ (tail + 1) & (PCF50633_MAX_ADC_FIFO_DEPTH - 1);
+
+ mutex_unlock(&pcf->adc.queue_mutex);
+
+ trigger_next_adc_job_if_any(pcf);
+
+ return 0;
+}
+
+static void
+pcf50633_adc_sync_read_callback(struct pcf50633 *pcf, void *param, int result)
+{
+ struct pcf50633_adc_request *req;
+
+ /*We know here that the passed param is an adc_request object */
+ req = (struct pcf50633_adc_request *)param;
+
+ req->result = result;
+ complete(&req->completion);
+}
+
+int pcf50633_adc_sync_read(struct pcf50633 *pcf, int mux, int avg)
+{
+
+ struct pcf50633_adc_request *req;
+ int result;
+
+ /* req is freed when the result is ready, in pcf50633_work*/
+ req = kzalloc(sizeof(*req), GFP_KERNEL);
+ if (!req)
+ return -ENOMEM;
+
+ req->mux = mux;
+ req->avg = avg;
+ req->callback = pcf50633_adc_sync_read_callback;
+ req->callback_param = req;
+ init_completion(&req->completion);
+
+ adc_enqueue_request(pcf, req);
+
+ wait_for_completion(&req->completion);
+ result = req->result;
+
+ return result;
+}
+EXPORT_SYMBOL(pcf50633_adc_sync_read);
+
+int pcf50633_adc_async_read(struct pcf50633 *pcf, int mux, int avg,
+ void (*callback)(struct pcf50633 *, void *,int),
+ void *callback_param)
+{
+ struct pcf50633_adc_request *req;
+
+ /* req is freed when the result is ready, in pcf50633_work*/
+ req = kmalloc(sizeof(*req), GFP_KERNEL);
+ if (!req)
+ return -ENOMEM;
+
+ req->mux = mux;
+ req->avg = avg;
+ req->callback = callback;
+ req->callback_param = callback_param;
+
+ adc_enqueue_request(pcf, req);
+
+ return 0;
+}
+EXPORT_SYMBOL(pcf50633_adc_async_read);
+
+static int adc_result(struct pcf50633 *pcf)
+{
+ u16 ret = (pcf50633_reg_read(pcf, PCF50633_REG_ADCS1) << 2) |
+ (pcf50633_reg_read(pcf, PCF50633_REG_ADCS3) &
+ PCF50633_ADCS3_ADCDAT1L_MASK);
+ dev_info(pcf->dev, "adc result = %d\n", ret);
+
+ return ret;
+}
+
+static void pcf50633_adc_irq(struct pcf50633 *pcf, int irq, void *unused)
+{
+ struct pcf50633_adc_request *req;
+ int head;
+
+ mutex_lock(&pcf->adc.queue_mutex);
+ head = pcf->adc.queue_head;
+
+ req = pcf->adc.queue[head];
+ if (!req) {
+ dev_err(pcf->dev, "ADC queue empty\n");
+ mutex_unlock(&pcf->adc.queue_mutex);
+ return;
+ }
+ pcf->adc.queue[head] = NULL;
+ pcf->adc.queue_head = (head + 1) &
+ (PCF50633_MAX_ADC_FIFO_DEPTH - 1);
+
+ mutex_unlock(&pcf->adc.queue_mutex);
+ req->callback(pcf, req->callback_param, adc_result(pcf));
+
+ kfree(req);
+
+ trigger_next_adc_job_if_any(pcf);
+}
+
+int __init pcf50633_adc_probe(struct platform_device *pdev)
+{
+ struct pcf50633 *pcf;
+
+ pcf = platform_get_drvdata(pdev);
+
+ /* Set up IRQ handlers */
+ pcf->irq_handler[PCF50633_IRQ_ADCRDY].handler = pcf50633_adc_irq;
+
+ mutex_init(&pcf->adc.queue_mutex);
+ return 0;
+}
+
+static int __devexit pcf50633_adc_remove(struct platform_device *pdev)
+{
+ struct pcf50633 *pcf;
+
+ pcf = platform_get_drvdata(pdev);
+ pcf->irq_handler[PCF50633_IRQ_ADCRDY].handler = NULL;
+
+ return 0;
+}
+
+struct platform_driver pcf50633_adc_driver = {
+ .driver = {
+ .name = "pcf50633-adc",
+ },
+ .probe = pcf50633_adc_probe,
+ .remove = __devexit_p(pcf50633_adc_remove),
+};
+
+static int __init pcf50633_adc_init(void)
+{
+ return platform_driver_register(&pcf50633_adc_driver);
+}
+module_init(pcf50633_adc_init);
+
+static void __exit pcf50633_adc_exit(void)
+{
+ platform_driver_unregister(&pcf50633_adc_driver);
+}
+module_exit(pcf50633_adc_exit);
+
+MODULE_AUTHOR("Balaji Rao <balajirrao at openmoko.org>");
+MODULE_DESCRIPTION("PCF50633 adc driver");
+MODULE_LICENSE("GPL");
+MODULE_ALIAS("platform:pcf50633-adc");
+
diff --git a/drivers/mfd/pcf50633-core.c b/drivers/mfd/pcf50633-core.c
new file mode 100644
index 0000000..73ef46b
--- /dev/null
+++ b/drivers/mfd/pcf50633-core.c
@@ -0,0 +1,464 @@
+#include <linux/i2c.h>
+#include <linux/irq.h>
+#include <linux/device.h>
+#include <linux/module.h>
+#include <linux/interrupt.h>
+#include <linux/workqueue.h>
+#include <linux/platform_device.h>
+
+#include <linux/mfd/pcf50633/core.h>
+#include <linux/mfd/pcf50633/adc.h>
+#include <linux/mfd/pcf50633/rtc.h>
+#include <linux/mfd/pcf50633/mbc.h>
+#include <linux/mfd/pcf50633/input.h>
+#include <linux/mfd/pcf50633/pmic.h>
+
+/* Read a block of upto 32 regs */
+int pcf50633_read_block(struct pcf50633 *pcf , u8 reg,
+ int nr_regs, u8 *data)
+{
+ return i2c_smbus_read_i2c_block_data(pcf->i2c_client, reg,
+ nr_regs, data);
+}
+EXPORT_SYMBOL(pcf50633_read_block);
+
+/* Write a block of upto 32 regs */
+int pcf50633_write_block(struct pcf50633 *pcf , u8 reg,
+ int nr_regs, u8 *data)
+{
+ return i2c_smbus_write_i2c_block_data(pcf->i2c_client, reg,
+ nr_regs, data);
+}
+EXPORT_SYMBOL(pcf50633_write_block);
+
+u8 pcf50633_reg_read(struct pcf50633 *pcf, u8 reg)
+{
+ return i2c_smbus_read_byte_data(pcf->i2c_client, reg);
+}
+EXPORT_SYMBOL(pcf50633_reg_read);
+
+int pcf50633_reg_write(struct pcf50633 *pcf, u8 reg, u8 val)
+{
+ return i2c_smbus_write_byte_data(pcf->i2c_client, reg, val);
+}
+EXPORT_SYMBOL(pcf50633_reg_write);
+
+int pcf50633_reg_set_bit_mask(struct pcf50633 *pcf, u8 reg, u8 mask, u8 val)
+{
+ int ret;
+ u8 tmp;
+
+ val &= mask;
+
+ mutex_lock(&pcf->io_mutex);
+
+ tmp = pcf50633_reg_read(pcf, reg);
+ tmp &= ~mask;
+ tmp |= val;
+ ret = pcf50633_reg_write(pcf, reg, tmp);
+
+ mutex_unlock(&pcf->io_mutex);
+
+ return ret;
+}
+EXPORT_SYMBOL(pcf50633_reg_set_bit_mask);
+
+int pcf50633_reg_clear_bits(struct pcf50633 *pcf, u8 reg, u8 val)
+{
+ int ret;
+ u8 tmp;
+
+ mutex_lock(&pcf->io_mutex);
+
+ tmp = pcf50633_reg_read(pcf, reg);
+ tmp &= ~val;
+ ret = pcf50633_reg_write(pcf, reg, tmp);
+
+ mutex_unlock(&pcf->io_mutex);
+
+ return ret;
+}
+EXPORT_SYMBOL(pcf50633_reg_clear_bits);
+
+/* sysfs attributes */
+static ssize_t show_dump_regs(struct device *dev, struct device_attribute *attr,
+ char *buf)
+{
+ struct pcf50633 *pcf = dev_get_drvdata(dev);
+ u8 dump[16];
+ int n, n1, idx = 0;
+ char *buf1 = buf;
+ static u8 address_no_read[] = { /* must be ascending */
+ PCF50633_REG_INT1,
+ PCF50633_REG_INT2,
+ PCF50633_REG_INT3,
+ PCF50633_REG_INT4,
+ PCF50633_REG_INT5,
+ 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] = pcf50633_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 struct attribute *pcf_sysfs_entries[] = {
+ &dev_attr_dump_regs,
+ NULL,
+};
+
+static struct attribute_group pcf_attr_group = {
+ .name = NULL, /* put in device directory */
+ .attrs = pcf_sysfs_entries,
+};
+
+
+static int pcf50633_irq_mask_set(struct pcf50633 *pcf, int irq, int mask)
+{
+ int bits, reg;
+ int ret = 0;
+
+ reg = (irq / 8);
+ bits = (1 << (irq % 8));
+
+ if (mask)
+ pcf50633_reg_clear_bits(pcf, reg, bits);
+ else
+ pcf50633_reg_set_bit_mask(pcf, reg, bits, bits);
+
+ if (ret)
+ dev_err(pcf->dev, "Error masking IRQ %d : %d\n", irq, ret);
+
+ return ret;
+}
+
+int pcf50633_irq_mask(struct pcf50633 *pcf ,int irq)
+{
+ return pcf50633_irq_mask_set(pcf, irq, 1);
+}
+EXPORT_SYMBOL(pcf50633_irq_mask);
+
+int pcf50633_irq_unmask(struct pcf50633 *pcf ,int irq)
+{
+ return pcf50633_irq_mask_set(pcf, irq, 0);
+}
+EXPORT_SYMBOL(pcf50633_irq_unmask);
+
+static void pcf50633_irq_call_handler(struct pcf50633 *pcf,
+ int irq)
+{
+ if (pcf->irq_handler[irq].handler)
+ pcf->irq_handler[irq].handler(pcf, irq,
+ pcf->irq_handler[irq].data);
+}
+
+static void pcf50633_irq_worker(struct work_struct *work)
+{
+ struct pcf50633 *pcf;
+ int ret, i, j;
+ u8 pcf_int[5];
+
+ pcf = container_of(work, struct pcf50633, irq_work);
+
+ /*
+ * If we are presently suspending, we are not in a position to deal
+ * with pcf50633 interrupts at all.
+ *
+ * Because we didn't clear the int pending registers, there will be
+ * no edge / interrupt waiting for us when we wake. But it is OK
+ * because at the end of our resume, we call this workqueue pcf50633_reg_set_bit_masktion
+ * gratuitously, clearing the pending register and re-enabling
+ * servicing this interrupt.
+ */
+
+ /* Read the 5 INT regs in one transaction */
+ ret = pcf50633_read_block(pcf, PCF50633_REG_INT1,
+ sizeof(pcf_int), pcf_int);
+ if (ret != sizeof(pcf_int)) {
+ dev_info(pcf->dev, "Error reading INT registers\n");
+
+ /* We don't have an option but to retry. Because if
+ * we don't, there won't be another interrupt edge.
+ */
+ goto reschedule;
+ }
+
+ /*FIXME: Handle resume reason. Why can't we just handle it
+ * during resume ? */
+
+ /* FIXME: Coldplug eliminated. Handled in _probe now */
+
+ /* Mask out SECOND if it's not used */
+ if (!pcf->rtc.second_enabled)
+ pcf_int[0] &= ~PCF50633_INT1_SECOND;
+
+ dev_info(pcf->dev, "INT1=0x%02x INT2=0x%02x INT3=0x%02x "
+ "INT4=0x%02x INT5=0x%02x\n", pcf_int[0],
+ pcf_int[1], pcf_int[2], pcf_int[3], pcf_int[4]);
+
+ for (i = 0; i < 5; i++)
+ for (j = 0; j < 8 ; j++)
+ if (pcf_int[i] & (1 << j))
+ pcf50633_irq_call_handler(pcf, (i * 8) + j);
+
+ put_device(pcf->dev);
+
+ return;
+reschedule:
+ schedule_work(&pcf->irq_work);
+
+ /* Don't put_device here. Will be used when we are rescheduled */
+ return;
+}
+
+static irqreturn_t pcf50633_irq(int irq, void *data)
+{
+ struct pcf50633 *pcf = data;
+
+ get_device(pcf->dev);
+ schedule_work(&pcf->irq_work);
+
+ return IRQ_HANDLED;
+}
+
+static void
+pcf50633_client_dev_register(struct pcf50633 *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;
+ platform_set_drvdata(*pdev, pcf);
+
+ ret = platform_device_add(*pdev);
+ if (ret != 0) {
+ dev_err(pcf->dev, "Failed to register %s: %d\n", name, ret);
+ platform_device_put(*pdev);
+ *pdev = NULL;
+ }
+
+}
+
+#ifdef CONFIG_PM
+static int pcf50633_suspend(struct device *dev, pm_message_t state)
+{
+ struct pcf50633 *pcf;
+ int ret, i;
+ u8 res[5];
+
+ pcf = dev_get_drvdata(dev);
+
+ /* Make sure our interrupt handlers are not called
+ * henceforth */
+ disable_irq(pcf->irq);
+
+ /* Make sure that an IRQ worker has quit */
+ cancel_work_sync(&pcf->irq_work);
+
+ /* We are not going to service any further interrupts until we
+ * resume. If the IRQ worker is still pending in the background,
+ * it will bail when it sees we set suspend state above
+ */
+
+ /* Save the masks */
+ pcf50633_read_block(pcf, PCF50633_REG_INT1M, 5,
+ pcf->suspend_irq_masks);
+
+ /* Set interrupt masks so only those sources we want to wake
+ * us are able to
+ */
+ for (i = 0; i < 5; i++)
+ res[i] = ~pcf->pdata->resumers[i];
+
+ pcf50633_write_block(pcf, PCF50633_REG_INT1M, 5, &res[0]);
+
+ return 0;
+}
+
+static int pcf50633_resume(struct device *dev)
+{
+ struct pcf50633 *pcf;
+
+ pcf = dev_get_drvdata(dev);
+
+ /* Write the saved mask registers */
+ pcf50633_write_block(pcf, PCF50633_REG_INT1M, 5,
+ pcf->suspend_irq_masks);
+
+
+ /* Gratuitous call to PCF work function, in the case that the PCF
+ * interrupt edge was missed during resume. This forces the pending
+ * register clear and lifts the interrupt back high again. In the
+ * case nothing is waiting for service, no harm done.
+ */
+
+ get_device(pcf->dev);
+ pcf50633_irq_worker(&pcf->irq_work);
+
+ enable_irq(pcf->irq);
+
+ return 0;
+}
+#else
+#define pcf50633_suspend NULL
+#define pcf50633_resume NULL
+#endif
+
+static int pcf50633_probe(struct i2c_client *client,
+ const struct i2c_device_id *ids)
+{
+ struct pcf50633 *pcf;
+ struct pcf50633_platform_data *pdata;
+ int i, ret = 0;
+ u8 mbcs1;
+
+ pdata = client->dev.platform_data;
+
+ pcf = kzalloc(sizeof(*pcf), GFP_KERNEL);
+ if (!pcf)
+ return -ENOMEM;
+
+ pcf->pdata = pdata;
+ pdata->pcf = pcf;
+
+ i2c_set_clientdata(client, pcf);
+ pcf->dev = &client->dev;
+ pcf->i2c_client = client;
+
+ mutex_init(&pcf->io_mutex);
+
+ INIT_WORK(&pcf->irq_work, pcf50633_irq_worker);
+
+ /* Enable all inteerupts except RTC SECOND */
+ pcf50633_reg_write(pcf, PCF50633_REG_INT1M, 0x80);
+ pcf50633_reg_write(pcf, PCF50633_REG_INT2M, 0x00);
+ pcf50633_reg_write(pcf, PCF50633_REG_INT3M, 0x80);
+ pcf50633_reg_write(pcf, PCF50633_REG_INT4M, 0x00);
+ pcf50633_reg_write(pcf, PCF50633_REG_INT5M, 0x00);
+
+ pcf50633_client_dev_register(pcf, "pcf50633-input",
+ &pcf->input.pdev);
+ pcf50633_client_dev_register(pcf, "pcf50633-rtc",
+ &pcf->rtc.pdev);
+ pcf50633_client_dev_register(pcf, "pcf50633-mbc",
+ &pcf->mbc.pdev);
+ pcf50633_client_dev_register(pcf, "pcf50633-adc",
+ &pcf->adc.pdev);
+ pcf50633_client_dev_register(pcf, "pcf50633-gpio",
+ &pcf->gpio.pdev);
+ for (i = 0; i < PCF50633_NUM_REGULATORS; i++) {
+ struct platform_device *pdev;
+
+ pdev = platform_device_alloc("pcf50633-regltr", i);
+ if (!pdev) {
+ dev_err(pcf->dev, "Cannot create regulator\n");
+ continue;
+ }
+
+ pdev->dev.parent = pcf->dev;
+ pdev->dev.platform_data = &pdata->reg_init_data[i];
+ pdev->dev.driver_data = pcf;
+ pcf->pmic.pdev[i] = pdev;
+
+ platform_device_add(pdev);
+ }
+
+ pcf->irq = client->irq;
+
+ if (client->irq) {
+ ret = request_irq(client->irq, pcf50633_irq,
+ IRQF_TRIGGER_FALLING, "pcf50633", pcf);
+
+ if (ret) {
+ dev_err(pcf->dev, "Failed to request IRQ %d\n", ret);
+ goto err;
+ }
+ } else {
+ dev_err(pcf->dev, "No IRQ configured\n");
+ goto err;
+ }
+
+ if (enable_irq_wake(client->irq) < 0)
+ dev_err(pcf->dev, "IRQ %u cannot be enabled as wake-up"
+ "source in this hardware revision", client->irq);
+
+ /* Cold Intialization */
+ mbcs1 = pcf50633_reg_read(pcf, PCF50633_REG_MBCS1);
+
+ if (mbcs1 & 0x01)
+ pcf50633_irq_call_handler(pcf, PCF50633_IRQ_USBINS);
+ if (mbcs1 & 0x04)
+ pcf50633_irq_call_handler(pcf, PCF50633_IRQ_ADPINS);
+
+ ret = sysfs_create_group(&client->dev.kobj, &pcf_attr_group);
+ if (ret)
+ dev_err(pcf->dev, "error creating sysfs entries\n");
+
+ return 0;
+
+err:
+ kfree(pcf);
+ return ret;
+}
+
+static int pcf50633_remove(struct i2c_client *client)
+{
+ struct pcf50633 *pcf = i2c_get_clientdata(client);
+
+ free_irq(pcf->irq, pcf);
+ kfree(pcf);
+
+ return 0;
+}
+
+static struct i2c_device_id pcf50633_id_table[] = {
+ {"pcf50633", 0x73},
+};
+
+static struct i2c_driver pcf50633_driver = {
+ .driver = {
+ .name = "pcf50633",
+ .suspend= pcf50633_suspend,
+ .resume = pcf50633_resume,
+ },
+ .id_table = pcf50633_id_table,
+ .probe = pcf50633_probe,
+ .remove = pcf50633_remove,
+};
+
+static int __init pcf50633_init(void)
+{
+ return i2c_add_driver(&pcf50633_driver);
+}
+
+static void pcf50633_exit(void)
+{
+ i2c_del_driver(&pcf50633_driver);
+}
+
+MODULE_DESCRIPTION("I2C chip driver for NXP PCF50633 PMU");
+MODULE_AUTHOR("Harald Welte <laforge at openmoko.org>");
+MODULE_LICENSE("GPL");
+
+module_init(pcf50633_init);
+module_exit(pcf50633_exit);
diff --git a/drivers/mfd/pcf50633-gpio.c b/drivers/mfd/pcf50633-gpio.c
new file mode 100644
index 0000000..f71acbd
--- /dev/null
+++ b/drivers/mfd/pcf50633-gpio.c
@@ -0,0 +1,62 @@
+#include <linux/mfd/pcf50633/core.h>
+#include <linux/mfd/pcf50633/gpio.h>
+
+void pcf50633_gpio_set(struct pcf50633 *pcf, int gpio, int on)
+{
+ u8 reg = gpio - PCF50633_GPIO1 + PCF50633_REG_GPIO1CFG;
+
+ if (on)
+ pcf50633_reg_set_bit_mask(pcf, reg, 0x0f, 0x07);
+ else
+ pcf50633_reg_set_bit_mask(pcf, reg, 0x0f, 0x00);
+}
+EXPORT_SYMBOL_GPL(pcf50633_gpio_set);
+
+int pcf50633_gpio_get(struct pcf50633 *pcf, int gpio)
+{
+ u8 reg = gpio - PCF50633_GPIO1 + PCF50633_REG_GPIO1CFG;
+ u8 val = pcf50633_reg_read(pcf, reg) & 0x0f;
+
+ if (val == PCF50633_GPOCFG_GPOSEL_1 ||
+ val == (PCF50633_GPOCFG_GPOSEL_0|PCF50633_GPOCFG_GPOSEL_INVERSE))
+ return 1;
+
+ return 0;
+}
+EXPORT_SYMBOL_GPL(pcf50633_gpio_get);
+
+int __init pcf50633_gpio_probe(struct platform_device *pdev)
+{
+ return 0;
+}
+
+static int __devexit pcf50633_gpio_remove(struct platform_device *pdev)
+{
+ return 0;
+}
+
+struct platform_driver pcf50633_gpio_driver = {
+ .driver = {
+ .name = "pcf50633-gpio",
+ },
+ .probe = pcf50633_gpio_probe,
+ .remove = __devexit_p(pcf50633_gpio_remove),
+};
+
+static int __init pcf50633_gpio_init(void)
+{
+ return platform_driver_register(&pcf50633_gpio_driver);
+}
+module_init(pcf50633_gpio_init);
+
+static void __exit pcf50633_gpio_exit(void)
+{
+ platform_driver_unregister(&pcf50633_gpio_driver);
+}
+module_exit(pcf50633_gpio_exit);
+
+MODULE_AUTHOR("Balaji Rao <balajirrao at openmoko.org>");
+MODULE_DESCRIPTION("PCF50633 gpio driver");
+MODULE_LICENSE("GPL");
+MODULE_ALIAS("platform:pcf50633-gpio");
+
diff --git a/drivers/mfd/pcf50633-i2c.c b/drivers/mfd/pcf50633-i2c.c
new file mode 100644
index 0000000..7191269
--- /dev/null
+++ b/drivers/mfd/pcf50633-i2c.c
@@ -0,0 +1,3 @@
+
+};
+
diff --git a/drivers/mfd/pcf50633-input.c b/drivers/mfd/pcf50633-input.c
new file mode 100644
index 0000000..6f3223c
--- /dev/null
+++ b/drivers/mfd/pcf50633-input.c
@@ -0,0 +1,105 @@
+#include <linux/input.h>
+
+#include <linux/mfd/pcf50633/core.h>
+#include <linux/mfd/pcf50633/input.h>
+
+static void
+pcf50633_input_irq(struct pcf50633 *pcf, int irq, void *data)
+{
+ struct input_device *input_dev = (struct input_device *)data;
+ int onkey_released;
+
+
+ /* We report only one event depending on if the key status */
+ onkey_released = pcf50633_reg_read(pcf, PCF50633_REG_OOCSTAT) &
+ PCF50633_OOCSTAT_ONKEY;
+
+ if (irq == CF50633_INT2_ONKEYF && !onkey_released)
+ input_report_key(pcf->input_dev, KEY_POWER, 1);
+ else if (irq == CF50633_INT2_ONKEYR && onkey_released)
+ input_report_key(pcf->input_dev, KEY_POWER, 0);
+
+ /* MBC makes sure that only one of USBINS/USBREM will be called */
+ if (irq == CF50633_INT1_USBINS)
+ input_report_key(pcf->input_dev, KEY_POWER2, 1);
+ else if (irq == CF50633_INT1_USBREM)
+ input_report_key(pcf->input_dev, KEY_POWER2, 0);
+
+}
+int __init pcf50633_input_probe(struct platform_device *pdev)
+{
+ struct pcf50633 *pcf;
+ struct input_device *input_dev;
+ int ret;
+
+ pcf = platform_get_drvdata(pdev);
+
+ input_dev = input_allocate_device();
+ if (!input_dev)
+ return -ENODEV;
+
+ input_dev->name = "GTA02 PMU events";
+ input_dev->phys = "FIXME";
+ input_dev->id.bustype = BUS_I2C;
+
+ input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_PWR);
+ set_bit(KEY_POWER, pcf->input_dev->keybit);
+ set_bit(KEY_POWER2, pcf->input_dev->keybit);
+
+ ret = input_register_device(pcf->input_dev);
+ if (ret)
+ goto out;
+
+ pcf->input.input_dev = input_dev;
+
+ /* Currently we care only about ONKEY and USBINS/USBREM
+ *
+ * USBINS/USBREM are told to us by mbc driver as we can't setup
+ * two handlers for an IRQ
+ */
+ pcf->irq_handler[PCF50633_IRQ_ONKEYR].handler = pcf50633_input_irq;
+ pcf->irq_handler[PCF50633_IRQ_ONKEYR].data = input_dev;
+
+ pcf->irq_handler[PCF50633_IRQ_ONKEYF].handler = pcf50633_input_irq;
+ pcf->irq_handler[PCF50633_IRQ_ONKEYF].data = input_dev;
+
+ return 0;
+
+out:
+ input_free_device(input_dev);
+ return ret;
+}
+
+static int __devexit pcf50633_input_remove(struct platform_device *pdev)
+{
+ struct pcf50633 *pcf;
+
+ input_unregister_device(pcf->input.input_dev);
+
+ return 0;
+}
+
+struct platform_driver pcf50633_input_driver = {
+ .driver = {
+ .name = "pcf50633-input",
+ },
+ .probe = pcf50633_input_probe,
+ .remove = __devexit_p(pcf50633_input_remove),
+};
+
+static int __init pcf50633_input_init(void)
+{
+ return platform_driver_register(&pcf50633_input_driver);
+}
+module_init(pcf50633_input_init);
+
+static void __exit pcf50633_input_exit(void)
+{
+ platform_driver_unregister(&pcf50633_input_driver);
+}
+module_exit(pcf50633_input_exit);
+
+MODULE_AUTHOR("Balaji Rao <balajirrao at openmoko.org>");
+MODULE_DESCRIPTION("PCF50633 input driver");
+MODULE_LICENSE("GPL");
+MODULE_ALIAS("platform:pcf50633-input");
diff --git a/drivers/mfd/pcf50633-mbc.c b/drivers/mfd/pcf50633-mbc.c
new file mode 100644
index 0000000..b856234
--- /dev/null
+++ b/drivers/mfd/pcf50633-mbc.c
@@ -0,0 +1,258 @@
+#include <linux/mfd/pcf50633/core.h>
+#include <linux/mfd/pcf50633/mbc.h>
+
+
+/*
+#if CONFIG_INPUT_PCF50633_PMU =
+extern static void pcf50633_input_irq(struct pcf50633 *, int, void *);
+
+static void pcf50633_input_report(struct pcf50633 *pcf, int key)
+{
+ pcf50633_input_irq(pcf, key, NULL);
+}
+#else
+static void pcf50633_input_report(struct pcf50633 *pcf, int key)
+{
+}
+#endif
+*/
+
+/*
+ * Dump regs
+ */
+
+static const char *chgmode_names[] = {
+ [PCF50633_MBCS2_MBC_PLAY] = "play-only",
+ [PCF50633_MBCS2_MBC_USB_PRE] = "pre",
+ [PCF50633_MBCS2_MBC_ADP_PRE] = "pre",
+ [PCF50633_MBCS2_MBC_USB_PRE_WAIT] = "pre-wait",
+ [PCF50633_MBCS2_MBC_ADP_PRE_WAIT] = "pre-wait",
+ [PCF50633_MBCS2_MBC_USB_FAST] = "fast",
+ [PCF50633_MBCS2_MBC_ADP_FAST] = "fast",
+ [PCF50633_MBCS2_MBC_USB_FAST_WAIT] = "fast-wait",
+ [PCF50633_MBCS2_MBC_ADP_FAST_WAIT] = "fast-wait",
+ [PCF50633_MBCS2_MBC_BAT_FULL] = "bat-full",
+};
+
+static ssize_t show_chgmode(struct device *dev, struct device_attribute *attr,
+ char *buf)
+{
+ struct pcf50633 *pcf = dev_get_drvdata(dev);
+
+ u8 mbcs2 = pcf50633_reg_read(pcf, PCF50633_REG_MBCS2);
+ u8 chgmod = (mbcs2 & PCF50633_MBCS2_MBC_MASK);
+
+ return sprintf(buf, "%s %d\n", chgmode_names[chgmod], chgmod);
+}
+static DEVICE_ATTR(chgmode, S_IRUGO | S_IWUSR, show_chgmode, NULL);
+
+static ssize_t show_usblim(struct device *dev, struct device_attribute *attr,
+ char *buf)
+{
+ struct pcf50633 *pcf = dev_get_drvdata(dev);
+ u8 usblim = pcf50633_reg_read(pcf, PCF50633_REG_MBCC7) &
+ PCF50633_MBCC7_USB_MASK;
+ unsigned int ma;
+
+ if (usblim == PCF50633_MBCC7_USB_1000mA)
+ ma = 1000;
+ else if (usblim == PCF50633_MBCC7_USB_500mA)
+ ma = 500;
+ else if (usblim == PCF50633_MBCC7_USB_100mA)
+ ma = 100;
+ else
+ ma = 0;
+
+ return sprintf(buf, "%u\n", ma);
+}
+static DEVICE_ATTR(usb_curlim, S_IRUGO | S_IWUSR, show_usblim, NULL);
+
+void pcf50633_mbc_usb_curlim_set(struct pcf50633 *pcf, int ma);
+
+static ssize_t force_usb_limit_dangerous(struct device *dev,
+ struct device_attribute *attr, const char *buf, size_t count)
+{
+ struct pcf50633 *pcf = dev_get_drvdata(dev);
+ int ma = simple_strtoul(buf, NULL, 10);
+
+ pcf50633_mbc_usb_curlim_set(pcf, ma);
+ return count;
+}
+
+static DEVICE_ATTR(force_usb_limit_dangerous, 0600,
+ NULL, force_usb_limit_dangerous);
+
+static struct attribute *mbc_sysfs_entries[] = {
+ &dev_attr_chgmode.attr,
+ &dev_attr_usb_curlim.attr,
+ &dev_attr_force_usb_limit_dangerous,
+ NULL,
+};
+
+static struct attribute_group mbc_attr_group = {
+ .name = NULL, /* put in device directory */
+ .attrs = mbc_sysfs_entries,
+};
+
+void pcf50633_mbc_usb_curlim_set(struct pcf50633 *pcf, int ma)
+{
+ int ret;
+ u8 bits;
+
+ if (ma >= 1000)
+ bits = PCF50633_MBCC7_USB_1000mA;
+ else if (ma >= 500)
+ bits = PCF50633_MBCC7_USB_500mA;
+ else if (ma >= 100)
+ bits = PCF50633_MBCC7_USB_100mA;
+ else
+ bits = PCF50633_MBCC7_USB_SUSPEND;
+
+ ret = pcf50633_reg_set_bit_mask(pcf, PCF50633_REG_MBCC7,
+ PCF50633_MBCC7_USB_MASK, bits);
+ if (ret)
+ dev_err(pcf->dev, "error setting usb current limit to %d mA\n", ma);
+ else
+ dev_info(pcf->dev, "usb current limit set to %d mA\n", ma);
+}
+EXPORT_SYMBOL(pcf50633_mbc_usb_curlim_set);
+
+/* 3s charging resume poll once battery full signalled */
+#define PCF50633_MBC_CHARGER_POLL (3 * HZ)
+
+static void pcf50633_mbc_charger_worker (struct work_struct *work)
+{
+ struct delayed_work *delayed_work;
+ struct pcf50633 *pcf;
+ struct pcf50633_mbc *mbc;
+ int chgmod;
+
+ printk("CHarger work scheduled\n");
+
+ delayed_work = container_of(work, struct delayed_work, work);
+ mbc = container_of(delayed_work, struct pcf50633_mbc, charger_work);
+ pcf = container_of(mbc, struct pcf50633, mbc);
+
+ chgmod = pcf50633_reg_read(pcf, PCF50633_REG_MBCS2) & 0x0f;
+
+ /* Has charging resumed ? */
+ if (chgmod && (chgmod < 0x0a) && (chgmod != 0x05)) {
+ pcf->mbc.charger_active = 1;
+
+ /* Signal charging resume */
+ pcf->pdata->mbc_event_callback(pcf, PCF50633_IRQ_CHGRESUME);
+ return;
+ }
+ else
+ schedule_delayed_work(&pcf->mbc.charger_work,
+ PCF50633_MBC_CHARGER_POLL);
+}
+
+#define PCF50633_MBC_IRQ_HANDLER pcf50633_mbc_irq_handler
+
+static void PCF50633_MBC_IRQ_HANDLER(struct pcf50633 *pcf, int irq, void *data)
+{
+ struct pcf50633_mbc *mbc;
+
+ mbc = &pcf->mbc;
+ /* FIXME : Handle the case when INS and REM might be
+ * simultaneously set
+ */
+
+ if (irq == PCF50633_IRQ_USBINS || irq == PCF50633_IRQ_ADPINS) {
+ pcf->mbc.charger_active = 1;
+ pcf->mbc.charger_online = 1;
+ } else if (irq == PCF50633_IRQ_USBREM || irq == PCF50633_IRQ_ADPREM) {
+ /* Stop looking for charger resume */
+ cancel_delayed_work_sync(&pcf->mbc.charger_work);
+
+ pcf->mbc.charger_online = 0;
+ pcf->mbc.charger_active = 0;
+ }
+
+ if (irq == PCF50633_IRQ_BATFULL) {
+ /* Poll for charging resume */
+ schedule_delayed_work(&pcf->mbc.charger_work,
+ PCF50633_MBC_CHARGER_POLL);
+
+ pcf->mbc.charger_active = 0;
+ printk("CHarger work scheduling....\n");
+ }
+
+ if (pcf->pdata->mbc_event_callback)
+ pcf->pdata->mbc_event_callback(pcf, irq);
+
+ /* FIXME : Report input events for USBINS and USBREM */
+}
+
+int __init pcf50633_mbc_probe(struct platform_device *pdev)
+{
+ struct pcf50633 *pcf;
+
+ pcf = platform_get_drvdata(pdev);
+
+ /* Set up IRQ handlers */
+ pcf->irq_handler[PCF50633_IRQ_ADPINS].handler =
+ PCF50633_MBC_IRQ_HANDLER;
+ pcf->irq_handler[PCF50633_IRQ_ADPREM].handler =
+ PCF50633_MBC_IRQ_HANDLER;
+ pcf->irq_handler[PCF50633_IRQ_USBINS].handler =
+ PCF50633_MBC_IRQ_HANDLER;
+ pcf->irq_handler[PCF50633_IRQ_USBREM].handler =
+ PCF50633_MBC_IRQ_HANDLER;
+ pcf->irq_handler[PCF50633_IRQ_BATFULL].handler =
+ PCF50633_MBC_IRQ_HANDLER;
+ pcf->irq_handler[PCF50633_IRQ_CHGHALT].handler =
+ PCF50633_MBC_IRQ_HANDLER;
+ pcf->irq_handler[PCF50633_IRQ_THLIMON].handler =
+ PCF50633_MBC_IRQ_HANDLER;
+ pcf->irq_handler[PCF50633_IRQ_THLIMOFF].handler =
+ PCF50633_MBC_IRQ_HANDLER;
+ pcf->irq_handler[PCF50633_IRQ_USBLIMON].handler =
+ PCF50633_MBC_IRQ_HANDLER;
+ pcf->irq_handler[PCF50633_IRQ_USBLIMOFF].handler =
+ PCF50633_MBC_IRQ_HANDLER;
+ pcf->irq_handler[PCF50633_IRQ_LOWSYS].handler =
+ PCF50633_MBC_IRQ_HANDLER;
+ pcf->irq_handler[PCF50633_IRQ_LOWBAT].handler =
+ PCF50633_MBC_IRQ_HANDLER;
+
+ INIT_DELAYED_WORK(&pcf->mbc.charger_work, pcf50633_mbc_charger_worker);
+
+ return sysfs_create_group(&pdev->dev.kobj, &mbc_attr_group);
+}
+
+static int __devexit pcf50633_mbc_remove(struct platform_device *pdev)
+{
+ struct pcf50633 *pcf;
+
+ pcf = platform_get_drvdata(pdev);
+
+ return 0;
+}
+
+struct platform_driver pcf50633_mbc_driver = {
+ .driver = {
+ .name = "pcf50633-mbc",
+ },
+ .probe = pcf50633_mbc_probe,
+ .remove = __devexit_p(pcf50633_mbc_remove),
+};
+
+static int __init pcf50633_mbc_init(void)
+{
+ return platform_driver_register(&pcf50633_mbc_driver);
+}
+module_init(pcf50633_mbc_init);
+
+static void __exit pcf50633_mbc_exit(void)
+{
+ platform_driver_unregister(&pcf50633_mbc_driver);
+}
+module_exit(pcf50633_mbc_exit);
+
+MODULE_AUTHOR("Balaji Rao <balajirrao at openmoko.org>");
+MODULE_DESCRIPTION("PCF50633 mbc driver");
+MODULE_LICENSE("GPL");
+MODULE_ALIAS("platform:pcf50633-mbc");
+
diff --git a/drivers/mfd/pcf50633-template.c b/drivers/mfd/pcf50633-template.c
new file mode 100644
index 0000000..2a13dc7
--- /dev/null
+++ b/drivers/mfd/pcf50633-template.c
@@ -0,0 +1,64 @@
+#include <linux/mfd/pcf50633/core.h>
+#include <linux/mfd/pcf50633/gpio.h>
+
+void pcf50633_gpio_set(struct pcf50633 *pcf, int gpio, int on)
+{
+ u8 reg = gpio - PCF50633_GPIO1 + PCF50633_REG_GPIO1CFG;
+
+ if (on)
+ pcf50633_reg_set_bit_mask(pcf, reg, 0x0f, 0x07);
+ else
+ pcf50633_reg_set_bit_mask(pcf, reg, 0x0f, 0x00);
+}
+EXPORT_SYMBOL_GPL(pcf50633_gpio_set);
+
+int pcf50633_gpio_get(struct pcf50633 *pcf, int gpio);
+{
+ u8 reg = gpio - PCF50633_GPIO1 + PCF50633_REG_GPIO1CFG;
+ u8 val = pcf50633_reg_read(pcf, reg) & 0x0f;
+
+ if (val == PCF50633_GPOCFG_GPOSEL_1 ||
+ val == (PCF50633_GPOCFG_GPOSEL_0|PCF50633_GPOCFG_GPOSEL_INVERSE))
+ return 1;
+
+ return 0;
+}
+EXPORT_SYMBOL_GPL(pcf50633_gpio_get);
+
+int __init pcf50633_gpio_probe(struct platform_device *pdev)
+{
+ return 0;
+}
+
+static int __devexit pcf50633_gpio_remove(struct platform_device *pdev)
+{
+ struct pcf50633 *pcf;
+
+ pcf = platform_get_drvdata(pdev);
+}
+
+struct platform_driver pcf50633_gpio_driver = {
+ .driver = {
+ .name = "pcf50633-gpio",
+ },
+ .probe = pcf50633_gpio_probe,
+ .remove = __devexit_p(pcf50633_gpio_remove),
+};
+
+static int __init pcf50633_gpio_init(void)
+{
+ return platform_driver_register(&pcf50633_gpio_driver);
+}
+module_init(pcf50633_gpio_init);
+
+static void __exit pcf50633_gpio_exit(void)
+{
+ platform_driver_unregister(&pcf50633_gpio_driver);
+}
+module_exit(pcf50633_gpio_exit);
+
+MODULE_AUTHOR("Balaji Rao <balajirrao at openmoko.org>");
+MODULE_DESCRIPTION("PCF50633 gpio driver");
+MODULE_LICENSE("GPL");
+MODULE_ALIAS("platform:pcf50633-gpio");
+
diff --git a/include/linux/mfd/pcf50633/adc.h b/include/linux/mfd/pcf50633/adc.h
new file mode 100644
index 0000000..140830e
--- /dev/null
+++ b/include/linux/mfd/pcf50633/adc.h
@@ -0,0 +1,92 @@
+#ifndef __LINUX_MFD_PCF50633_ADC_H
+#define __LINUX_MFD_PCF50633_ADC_H
+
+#include <linux/platform_device.h>
+
+/* ADC Registers */
+#define PCF50633_REG_ADCC3 0x52
+#define PCF50633_REG_ADCC2 0x53
+#define PCF50633_REG_ADCC1 0x54
+#define PCF50633_REG_ADCS1 0x55
+#define PCF50633_REG_ADCS2 0x56
+#define PCF50633_REG_ADCS3 0x57
+
+#define PCF50633_ADCC1_ADCSTART 0x01
+#define PCF50633_ADCC1_RES_10BIT 0x02
+#define PCF50633_ADCC1_AVERAGE_NO 0x00
+#define PCF50633_ADCC1_AVERAGE_4 0x04
+#define PCF50633_ADCC1_AVERAGE_8 0x08
+#define PCF50633_ADCC1_AVERAGE_16 0x0c
+#define PCF50633_ADCC1_MUX_BATSNS_RES 0x00
+#define PCF50633_ADCC1_MUX_BATSNS_SUBTR 0x10
+#define PCF50633_ADCC1_MUX_ADCIN2_RES 0x20
+#define PCF50633_ADCC1_MUX_ADCIN2_SUBTR 0x30
+#define PCF50633_ADCC1_MUX_BATTEMP 0x60
+#define PCF50633_ADCC1_MUX_ADCIN1 0x70
+#define PCF50633_ADCC1_AVERAGE_MASK 0x0c
+#define PCF50633_ADCC1_ADCMUX_MASK 0xf0
+
+#define PCF50633_ADCC2_RATIO_NONE 0x00
+#define PCF50633_ADCC2_RATIO_BATTEMP 0x01
+#define PCF50633_ADCC2_RATIO_ADCIN1 0x02
+#define PCF50633_ADCC2_RATIO_BOTH 0x03
+#define PCF50633_ADCC2_RATIOSETTL_100US 0x04
+
+#define PCF50633_ADCC3_ACCSW_EN 0x01
+#define PCF50633_ADCC3_NTCSW_EN 0x04
+#define PCF50633_ADCC3_RES_DIV_TWO 0x10
+#define PCF50633_ADCC3_RES_DIV_THREE 0x00
+
+#define PCF50633_ADCS3_REF_NTCSW 0x00
+#define PCF50633_ADCS3_REF_ACCSW 0x10
+#define PCF50633_ADCS3_REF_2V0 0x20
+#define PCF50633_ADCS3_REF_VISA 0x30
+#define PCF50633_ADCS3_REF_2V0_2 0x70
+#define PCF50633_ADCS3_ADCRDY 0x80
+
+#define PCF50633_ADCS3_ADCDAT1L_MASK 0x03
+#define PCF50633_ADCS3_ADCDAT2L_MASK 0x0c
+#define PCF50633_ADCS3_ADCDAT2L_SHIFT 2
+#define PCF50633_ASCS3_REF_MASK 0x70
+
+
+struct pcf50633;
+
+#define PCF50633_MAX_ADC_FIFO_DEPTH 8
+
+struct pcf50633_adc_request;
+
+struct pcf50633_adc {
+ struct platform_device *pdev;
+
+ /* Private stuff */
+ struct pcf50633_adc_request *queue[PCF50633_MAX_ADC_FIFO_DEPTH];
+ int queue_head;
+ int queue_tail;
+ struct mutex queue_mutex;
+};
+
+#ifdef CONFIG_MFD_PCF50633_ADC
+extern int
+pcf50633_adc_async_read(struct pcf50633 *pcf, int mux, int avg,
+ void (*callback)(struct pcf50633 *, void *, int),
+ void *callback_param);
+extern int
+pcf50633_adc_sync_read(struct pcf50633 *pcf, int mux, int avg);
+#else
+int
+pcf50633_adc_async_read(struct pcf50633 *pcf, int mux, int avg,
+ void (*callback)(struct pcf50633 *, void *, int),
+ void *callback_param)
+{
+ return -ENODEV;
+}
+
+int
+pcf50633_adc_sync_read(struct pcf50633 *pcf, int mux, int avg)
+{
+ return -ENODEV;
+}
+#endif /* CONFIG_PCF50633_ADC */
+
+#endif /* __LINUX_PCF50633_ADC_H */
diff --git a/include/linux/mfd/pcf50633/core.h b/include/linux/mfd/pcf50633/core.h
new file mode 100644
index 0000000..fcd392f
--- /dev/null
+++ b/include/linux/mfd/pcf50633/core.h
@@ -0,0 +1,201 @@
+#ifndef __LINUX_MFD_PCF50633_CORE_H
+#define __LINUX_MFD_PCF50633_CORE_H
+
+#include <linux/i2c.h>
+#include <linux/workqueue.h>
+#include <linux/regulator/driver.h>
+#include <linux/regulator/machine.h>
+
+#include <linux/mfd/pcf50633/pmic.h>
+#include <linux/mfd/pcf50633/gpio.h>
+#include <linux/mfd/pcf50633/input.h>
+#include <linux/mfd/pcf50633/mbc.h>
+#include <linux/mfd/pcf50633/rtc.h>
+#include <linux/mfd/pcf50633/adc.h>
+
+enum pcf50633_suspend_state {
+ PCF50633_SS_RUNNING,
+ PCF50633_SS_STARTING_SUSPEND,
+ PCF50633_SS_COMPLETED_SUSPEND,
+ PCF50633_SS_STARTING_RESUME,
+ PCF50633_SS_COMPLETED_RESUME,
+};
+
+struct pcf50633;
+
+struct pcf50633_platform_data {
+ struct regulator_init_data reg_init_data[PCF50633_NUM_REGULATORS];
+
+ /* Callbacks */
+ void (*init)(struct pcf50633 *);
+ void (*probe_done)(struct pcf50633 *);
+ void (*mbc_event_callback)(struct pcf50633 *, int);
+ void (*regulator_registered)(struct pcf50633 *, int);
+
+ u8 resumers[5];
+
+ /* Runtime data - filled by driver afer probe */
+ struct pcf50633 *pcf;
+};
+
+struct pcf50633_irq {
+ void (*handler)(struct pcf50633 *, int, void *);
+ void *data;
+};
+
+int pcf50633_irq_mask(struct pcf50633 *pcf, int irq);
+int pcf50633_irq_unmask(struct pcf50633 *pcf, int irq);
+
+int pcf50633_read_block(struct pcf50633 *, u8 reg,
+ int nr_regs, u8 *data);
+int pcf50633_write_block(struct pcf50633 *pcf, u8 reg,
+ int nr_regs, u8 *data);
+u8 pcf50633_reg_read(struct pcf50633 *, u8 reg);
+int pcf50633_reg_write(struct pcf50633 *pcf, u8 reg, u8 val);
+
+int pcf50633_reg_set_bit_mask(struct pcf50633 *pcf, u8 reg, u8 mask, u8 val);
+int pcf50633_reg_clear_bits(struct pcf50633 *pcf, u8 reg, u8 bits);
+
+/* Interrupt registers */
+
+#define PCF50633_REG_INT1 0x02
+#define PCF50633_REG_INT2 0x03
+#define PCF50633_REG_INT3 0x04
+#define PCF50633_REG_INT4 0x05
+#define PCF50633_REG_INT5 0x06
+
+#define PCF50633_REG_INT1M 0x07
+#define PCF50633_REG_INT2M 0x08
+#define PCF50633_REG_INT3M 0x09
+#define PCF50633_REG_INT4M 0x0a
+#define PCF50633_REG_INT5M 0x0b
+
+enum {
+ /* Chip IRQs */
+ PCF50633_IRQ_ADPINS = 0,
+ PCF50633_IRQ_ADPREM,
+ PCF50633_IRQ_USBINS,
+ PCF50633_IRQ_USBREM,
+ PCF50633_IRQ_RESERVED1,
+ PCF50633_IRQ_RESERVED2,
+ PCF50633_IRQ_ALARM,
+ PCF50633_IRQ_SECOND,
+ PCF50633_IRQ_ONKEYR,
+ PCF50633_IRQ_ONKEYF,
+ PCF50633_IRQ_EXTON1R,
+ PCF50633_IRQ_EXTON1F,
+ PCF50633_IRQ_EXTON2R,
+ PCF50633_IRQ_EXTON2F,
+ PCF50633_IRQ_EXTON3R,
+ PCF50633_IRQ_EXTON3F,
+ PCF50633_IRQ_BATFULL,
+ PCF50633_IRQ_CHGHALT,
+ PCF50633_IRQ_THLIMON,
+ PCF50633_IRQ_THLIMOFF,
+ PCF50633_IRQ_USBLIMON,
+ PCF50633_IRQ_USBLIMOFF,
+ PCF50633_IRQ_ADCRDY,
+ PCF50633_IRQ_ONKEY1S,
+ PCF50633_IRQ_LOWSYS,
+ PCF50633_IRQ_LOWBAT,
+ PCF50633_IRQ_HIGHTMP,
+ PCF50633_IRQ_AUTOPWRFAIL,
+ PCF50633_IRQ_DWN1PWRFAIL,
+ PCF50633_IRQ_DWN2PWRFAIL,
+ PCF50633_IRQ_LEDPWRFAIL,
+ PCF50633_IRQ_LEDOVP,
+ PCF50633_IRQ_LDO1PWRFAIL,
+ PCF50633_IRQ_LDO2PWRFAIL,
+ PCF50633_IRQ_LDO3PWRFAIL,
+ PCF50633_IRQ_LDO4PWRFAIL,
+ PCF50633_IRQ_LDO5PWRFAIL,
+ PCF50633_IRQ_LDO6PWRFAIL,
+ PCF50633_IRQ_HCLDOPWRFAIL,
+ PCF50633_IRQ_HCLDOOVL,
+
+ /* Soft IRQs */
+ PCF50633_IRQ_CHGRESUME,
+
+ PCF50633_NUM_IRQ,
+};
+
+struct pcf50633 {
+ struct device *dev;
+ struct i2c_client *i2c_client;
+
+ struct pcf50633_platform_data *pdata;
+
+ int irq;
+ struct pcf50633_irq irq_handler[PCF50633_NUM_IRQ];
+
+ struct work_struct irq_work;
+ struct mutex io_mutex;
+
+ u8 suspend_irq_masks[5];
+ int resumers[5];
+
+ struct pcf50633_pmic pmic;
+ struct pcf50633_gpio gpio;
+ struct pcf50633_input input;
+ struct pcf50633_mbc mbc;
+ struct pcf50633_rtc rtc;
+ struct pcf50633_adc adc;
+};
+
+enum pcf50633_reg_int1 {
+ PCF50633_INT1_ADPINS = 0x01, /* Adapter inserted */
+ PCF50633_INT1_ADPREM = 0x02, /* Adapter removed */
+ PCF50633_INT1_USBINS = 0x04, /* USB inserted */
+ PCF50633_INT1_USBREM = 0x08, /* USB removed */
+ /* reserved */
+ PCF50633_INT1_ALARM = 0x40, /* RTC alarm time is reached */
+ PCF50633_INT1_SECOND = 0x80, /* RTC periodic second interrupt */
+};
+
+enum pcf50633_reg_int2 {
+ PCF50633_INT2_ONKEYR = 0x01, /* ONKEY rising edge */
+ PCF50633_INT2_ONKEYF = 0x02, /* ONKEY falling edge */
+ PCF50633_INT2_EXTON1R = 0x04, /* EXTON1 rising edge */
+ PCF50633_INT2_EXTON1F = 0x08, /* EXTON1 falling edge */
+ PCF50633_INT2_EXTON2R = 0x10, /* EXTON2 rising edge */
+ PCF50633_INT2_EXTON2F = 0x20, /* EXTON2 falling edge */
+ PCF50633_INT2_EXTON3R = 0x40, /* EXTON3 rising edge */
+ PCF50633_INT2_EXTON3F = 0x80, /* EXTON3 falling edge */
+};
+
+enum pcf50633_reg_int3 {
+ PCF50633_INT3_BATFULL = 0x01, /* Battery full */
+ PCF50633_INT3_CHGHALT = 0x02, /* Charger halt */
+ PCF50633_INT3_THLIMON = 0x04,
+ PCF50633_INT3_THLIMOFF = 0x08,
+ PCF50633_INT3_USBLIMON = 0x10,
+ PCF50633_INT3_USBLIMOFF = 0x20,
+ PCF50633_INT3_ADCRDY = 0x40, /* ADC result ready */
+ PCF50633_INT3_ONKEY1S = 0x80, /* ONKEY pressed 1 second */
+};
+
+enum pcf50633_reg_int4 {
+ PCF50633_INT4_LOWSYS = 0x01,
+ PCF50633_INT4_LOWBAT = 0x02,
+ PCF50633_INT4_HIGHTMP = 0x04,
+ PCF50633_INT4_AUTOPWRFAIL = 0x08,
+ PCF50633_INT4_DWN1PWRFAIL = 0x10,
+ PCF50633_INT4_DWN2PWRFAIL = 0x20,
+ PCF50633_INT4_LEDPWRFAIL = 0x40,
+ PCF50633_INT4_LEDOVP = 0x80,
+};
+
+enum pcf50633_reg_int5 {
+ PCF50633_INT5_LDO1PWRFAIL = 0x01,
+ PCF50633_INT5_LDO2PWRFAIL = 0x02,
+ PCF50633_INT5_LDO3PWRFAIL = 0x04,
+ PCF50633_INT5_LDO4PWRFAIL = 0x08,
+ PCF50633_INT5_LDO5PWRFAIL = 0x10,
+ PCF50633_INT5_LDO6PWRFAIL = 0x20,
+ PCF50633_INT5_HCLDOPWRFAIL = 0x40,
+ PCF50633_INT5_HCLDOOVL = 0x80,
+};
+
+
+#endif
+
diff --git a/include/linux/mfd/pcf50633/gpio.h b/include/linux/mfd/pcf50633/gpio.h
new file mode 100644
index 0000000..f503801
--- /dev/null
+++ b/include/linux/mfd/pcf50633/gpio.h
@@ -0,0 +1,43 @@
+#ifndef __LINUX_MFD_PCF50633_GPIO_H
+#define __LINUX_MFD_PCF50633_GPIO_H
+
+#include <linux/platform_device.h>
+
+struct pcf50633_gpio {
+ struct platform_device *pdev;
+};
+
+#define PCF50633_GPIO1 1
+#define PCF50633_GPIO2 2
+#define PCF50633_GPIO3 3
+#define PCF50633_GPO 4
+
+#define PCF50633_REG_GPIO1CFG 0x14
+#define PCF50633_REG_GPIO2CFG 0x15
+#define PCF50633_REG_GPIO3CFG 0x16
+#define PCF50633_REG_GPOCFG 0x17
+
+enum pcf50633_reg_gpocfg {
+ PCF50633_GPOCFG_GPOSEL_0 = 0x00,
+ PCF50633_GPOCFG_GPOSEL_LED_NFET = 0x01,
+ PCF50633_GPOCFG_GPOSEL_SYSxOK = 0x02,
+ PCF50633_GPOCFG_GPOSEL_CLK32K = 0x03,
+ PCF50633_GPOCFG_GPOSEL_ADAPUSB = 0x04,
+ PCF50633_GPOCFG_GPOSEL_USBxOK = 0x05,
+ PCF50633_GPOCFG_GPOSEL_ACTPH4 = 0x06,
+ PCF50633_GPOCFG_GPOSEL_1 = 0x07,
+ PCF50633_GPOCFG_GPOSEL_INVERSE = 0x08,
+};
+#define PCF50633_GPOCFG_GPOSEL_MASK 0x07
+
+struct pcf50633;
+
+extern void
+pcf50633_gpio_set(struct pcf50633 *pcf, int gpio, int on);
+
+extern int
+pcf50633_gpio_get(struct pcf50633 *pcf, int gpio);
+
+
+#endif
+
diff --git a/include/linux/mfd/pcf50633/input.h b/include/linux/mfd/pcf50633/input.h
new file mode 100644
index 0000000..5f8d78f
--- /dev/null
+++ b/include/linux/mfd/pcf50633/input.h
@@ -0,0 +1,17 @@
+#ifndef __LINUX_MFD_PCF50633_INPUT_H
+#define __LINUX_MFD_PCF50633_INPUT_H
+
+#include <linux/platform_device.h>
+#include <linux/input.h>
+
+#define PCF50633_OOCSTAT_ONKEY 0x01
+#define PCF50633_REG_OOCSTAT 0x12
+#define PCF50633_REG_OOCMODE 0x10
+
+struct pcf50633_input {
+ struct input_dev *input_dev;
+ struct platform_device *pdev;
+};
+
+#endif
+
diff --git a/include/linux/mfd/pcf50633/led.h b/include/linux/mfd/pcf50633/led.h
new file mode 100644
index 0000000..2f866b2
--- /dev/null
+++ b/include/linux/mfd/pcf50633/led.h
@@ -0,0 +1,12 @@
+#ifndef __LINUX_MFD_PCF50633_LED_H
+#define __LINUX_MFD_PCF50633_LED_H
+
+#include <linux/platform_device.h>
+
+#define PCF50633_REG_LEDOUT 0x28
+#define PCF50633_REG_LEDENA 0x29
+#define PCF50633_REG_LEDCTL 0x2a
+#define PCF50633_REG_LEDDIM 0x2b
+
+#endif
+
diff --git a/include/linux/mfd/pcf50633/mbc.h b/include/linux/mfd/pcf50633/mbc.h
new file mode 100644
index 0000000..816f8b6
--- /dev/null
+++ b/include/linux/mfd/pcf50633/mbc.h
@@ -0,0 +1,120 @@
+#ifndef __LINUX_MFD_PCF50633_MBC_H
+#define __LINUX_MFD_PCF50633_MBC_H
+
+#include <linux/platform_device.h>
+#include <linux/workqueue.h>
+
+#define PCF50633_REG_MBCC1 0x43
+#define PCF50633_REG_MBCC2 0x44
+#define PCF50633_REG_MBCC3 0x45
+#define PCF50633_REG_MBCC4 0x46
+#define PCF50633_REG_MBCC5 0x47
+#define PCF50633_REG_MBCC6 0x48
+#define PCF50633_REG_MBCC7 0x49
+#define PCF50633_REG_MBCC8 0x4a
+#define PCF50633_REG_MBCS1 0x4b
+#define PCF50633_REG_MBCS2 0x4c
+#define PCF50633_REG_MBCS3 0x4d
+
+enum pcf50633_reg_mbcc1 {
+ PCF50633_MBCC1_CHGENA = 0x01, /* Charger enable */
+ PCF50633_MBCC1_AUTOSTOP = 0x02,
+ PCF50633_MBCC1_AUTORES = 0x04, /* automatic resume */
+ PCF50633_MBCC1_RESUME = 0x08, /* explicit resume cmd */
+ PCF50633_MBCC1_RESTART = 0x10, /* restart charging */
+ PCF50633_MBCC1_PREWDTIME_60M = 0x20, /* max. precharging time */
+ PCF50633_MBCC1_WDTIME_1H = 0x00,
+ PCF50633_MBCC1_WDTIME_2H = 0x40,
+ PCF50633_MBCC1_WDTIME_4H = 0x80,
+ PCF50633_MBCC1_WDTIME_6H = 0xc0,
+};
+#define PCF50633_MBCC1_WDTIME_MASK 0xc0
+
+enum pcf50633_reg_mbcc2 {
+ PCF50633_MBCC2_VBATCOND_2V7 = 0x00,
+ PCF50633_MBCC2_VBATCOND_2V85 = 0x01,
+ PCF50633_MBCC2_VBATCOND_3V0 = 0x02,
+ PCF50633_MBCC2_VBATCOND_3V15 = 0x03,
+ PCF50633_MBCC2_VMAX_4V = 0x00,
+ PCF50633_MBCC2_VMAX_4V20 = 0x28,
+ PCF50633_MBCC2_VRESDEBTIME_64S = 0x80, /* debounce time (32/64sec) */
+};
+
+enum pcf50633_reg_mbcc7 {
+ PCF50633_MBCC7_USB_100mA = 0x00,
+ PCF50633_MBCC7_USB_500mA = 0x01,
+ PCF50633_MBCC7_USB_1000mA = 0x02,
+ PCF50633_MBCC7_USB_SUSPEND = 0x03,
+ PCF50633_MBCC7_BATTEMP_EN = 0x04,
+ PCF50633_MBCC7_BATSYSIMAX_1A6 = 0x00,
+ PCF50633_MBCC7_BATSYSIMAX_1A8 = 0x40,
+ PCF50633_MBCC7_BATSYSIMAX_2A0 = 0x80,
+ PCF50633_MBCC7_BATSYSIMAX_2A2 = 0xc0,
+};
+#define PCF50633_MBCC7_USB_MASK 0x03
+
+enum pcf50633_reg_mbcc8 {
+ PCF50633_MBCC8_USBENASUS = 0x10,
+};
+
+enum pcf50633_reg_mbcs1 {
+ PCF50633_MBCS1_USBPRES = 0x01,
+ PCF50633_MBCS1_USBOK = 0x02,
+ PCF50633_MBCS1_ADAPTPRES = 0x04,
+ PCF50633_MBCS1_ADAPTOK = 0x08,
+ PCF50633_MBCS1_TBAT_OK = 0x00,
+ PCF50633_MBCS1_TBAT_ABOVE = 0x10,
+ PCF50633_MBCS1_TBAT_BELOW = 0x20,
+ PCF50633_MBCS1_TBAT_UNDEF = 0x30,
+ PCF50633_MBCS1_PREWDTEXP = 0x40,
+ PCF50633_MBCS1_WDTEXP = 0x80,
+};
+
+enum pcf50633_reg_mbcs2_mbcmod {
+ PCF50633_MBCS2_MBC_PLAY = 0x00,
+ PCF50633_MBCS2_MBC_USB_PRE = 0x01,
+ PCF50633_MBCS2_MBC_USB_PRE_WAIT = 0x02,
+ PCF50633_MBCS2_MBC_USB_FAST = 0x03,
+ PCF50633_MBCS2_MBC_USB_FAST_WAIT= 0x04,
+ PCF50633_MBCS2_MBC_USB_SUSPEND = 0x05,
+ PCF50633_MBCS2_MBC_ADP_PRE = 0x06,
+ PCF50633_MBCS2_MBC_ADP_PRE_WAIT = 0x07,
+ PCF50633_MBCS2_MBC_ADP_FAST = 0x08,
+ PCF50633_MBCS2_MBC_ADP_FAST_WAIT= 0x09,
+ PCF50633_MBCS2_MBC_BAT_FULL = 0x0a,
+ PCF50633_MBCS2_MBC_HALT = 0x0b,
+};
+#define PCF50633_MBCS2_MBC_MASK 0x0f
+enum pcf50633_reg_mbcs2_chgstat {
+ PCF50633_MBCS2_CHGS_NONE = 0x00,
+ PCF50633_MBCS2_CHGS_ADAPTER = 0x10,
+ PCF50633_MBCS2_CHGS_USB = 0x20,
+ PCF50633_MBCS2_CHGS_BOTH = 0x30,
+};
+#define PCF50633_MBCS2_RESSTAT_AUTO 0x40
+
+enum pcf50633_reg_mbcs3 {
+ PCF50633_MBCS3_USBLIM_PLAY = 0x01,
+ PCF50633_MBCS3_USBLIM_CGH = 0x02,
+ PCF50633_MBCS3_TLIM_PLAY = 0x04,
+ PCF50633_MBCS3_TLIM_CHG = 0x08,
+ PCF50633_MBCS3_ILIM = 0x10, /* 1: Ibat > Icutoff */
+ PCF50633_MBCS3_VLIM = 0x20, /* 1: Vbat == Vmax */
+ PCF50633_MBCS3_VBATSTAT = 0x40, /* 1: Vbat > Vbatcond */
+ PCF50633_MBCS3_VRES = 0x80, /* 1: Vbat > Vth(RES) */
+};
+
+#define PCF50633_MBCC2_VBATCOND_MASK 0x03
+#define PCF50633_MBCC2_VMAX_MASK 0x3c
+
+void pcf50633_mbc_usb_curlim_set(struct pcf50633 *pcf, int ma);
+
+struct pcf50633_mbc {
+ int charger_active;
+ int charger_online;
+
+ struct delayed_work charger_work;
+ struct platform_device *pdev;
+};
+#endif
+
diff --git a/include/linux/mfd/pcf50633/pmic.h b/include/linux/mfd/pcf50633/pmic.h
new file mode 100644
index 0000000..5277954
--- /dev/null
+++ b/include/linux/mfd/pcf50633/pmic.h
@@ -0,0 +1,73 @@
+#ifndef __LINUX_MFD_PCF50633_PMIC_H
+#define __LINUX_MFD_PCF50633_PMIC_H
+
+#include <linux/platform_device.h>
+
+#define PCF50633_REG_AUTOOUT 0x1a
+#define PCF50633_REG_AUTOENA 0x1b
+#define PCF50633_REG_AUTOCTL 0x1c
+#define PCF50633_REG_AUTOMXC 0x1d
+#define PCF50633_REG_DOWN1OUT 0x1e
+#define PCF50633_REG_DOWN1ENA 0x1f
+#define PCF50633_REG_DOWN1CTL 0x20
+#define PCF50633_REG_DOWN1MXC 0x21
+#define PCF50633_REG_DOWN2OUT 0x22
+#define PCF50633_REG_DOWN2ENA 0x23
+#define PCF50633_REG_DOWN2CTL 0x24
+#define PCF50633_REG_DOWN2MXC 0x25
+#define PCF50633_REG_MEMLDOOUT 0x26
+#define PCF50633_REG_MEMLDOENA 0x27
+#define PCF50633_REG_LDO1OUT 0x2d
+#define PCF50633_REG_LDO1ENA 0x2e
+#define PCF50633_REG_LDO2OUT 0x2f
+#define PCF50633_REG_LDO2ENA 0x30
+#define PCF50633_REG_LDO3OUT 0x31
+#define PCF50633_REG_LDO3ENA 0x32
+#define PCF50633_REG_LDO4OUT 0x33
+#define PCF50633_REG_LDO4ENA 0x34
+#define PCF50633_REG_LDO5OUT 0x35
+#define PCF50633_REG_LDO5ENA 0x36
+#define PCF50633_REG_LDO6OUT 0x37
+#define PCF50633_REG_LDO6ENA 0x38
+#define PCF50633_REG_HCLDOOUT 0x39
+#define PCF50633_REG_HCLDOENA 0x3a
+#define PCF50633_REG_HCLDOOVL 0x40
+
+enum pcf50633_regulator_enable {
+ PCF50633_REGULATOR_ON = 0x01,
+ PCF50633_REGULATOR_ON_GPIO1 = 0x02,
+ PCF50633_REGULATOR_ON_GPIO2 = 0x04,
+ PCF50633_REGULATOR_ON_GPIO3 = 0x08,
+};
+#define PCF50633_REGULATOR_ON_MASK 0x0f
+
+enum pcf50633_regulator_phase {
+ PCF50633_REGULATOR_ACTPH1 = 0x00,
+ PCF50633_REGULATOR_ACTPH2 = 0x10,
+ PCF50633_REGULATOR_ACTPH3 = 0x20,
+ PCF50633_REGULATOR_ACTPH4 = 0x30,
+};
+#define PCF50633_REGULATOR_ACTPH_MASK 0x30
+
+
+enum pcf50633_regulator_id {
+ PCF50633_REGULATOR_AUTO,
+ PCF50633_REGULATOR_DOWN1,
+ PCF50633_REGULATOR_DOWN2,
+ PCF50633_REGULATOR_LDO1,
+ PCF50633_REGULATOR_LDO2,
+ PCF50633_REGULATOR_LDO3,
+ PCF50633_REGULATOR_LDO4,
+ PCF50633_REGULATOR_LDO5,
+ PCF50633_REGULATOR_LDO6,
+ PCF50633_REGULATOR_HCLDO,
+ PCF50633_REGULATOR_MEMLDO,
+
+ PCF50633_NUM_REGULATORS
+};
+
+struct pcf50633_pmic {
+ struct platform_device *pdev[PCF50633_NUM_REGULATORS];
+};
+#endif
+
diff --git a/include/linux/mfd/pcf50633/rtc.h b/include/linux/mfd/pcf50633/rtc.h
new file mode 100644
index 0000000..0919590
--- /dev/null
+++ b/include/linux/mfd/pcf50633/rtc.h
@@ -0,0 +1,33 @@
+#ifndef __LINUX_MFD_PCF50633_RTC_H
+#define __LINUX_MFD_PCF50633_RTC_H
+
+#include <linux/rtc.h>
+#include <linux/platform_device.h>
+
+#define PCF50633_REG_RTCSC 0x59 /* Second */
+#define PCF50633_REG_RTCMN 0x5a /* Minute */
+#define PCF50633_REG_RTCHR 0x5b /* Hour */
+#define PCF50633_REG_RTCWD 0x5c /* Weekday */
+#define PCF50633_REG_RTCDT 0x5d /* Day */
+#define PCF50633_REG_RTCMT 0x5e /* Month */
+#define PCF50633_REG_RTCYR 0x5f /* Year */
+#define PCF50633_REG_RTCSCA 0x60 /* Alarm Second */
+#define PCF50633_REG_RTCMNA 0x61 /* Alarm Minute */
+#define PCF50633_REG_RTCHRA 0x62 /* Alarm Hour */
+#define PCF50633_REG_RTCWDA 0x63 /* Alarm Weekday */
+#define PCF50633_REG_RTCDTA 0x64 /* Alarm Day */
+#define PCF50633_REG_RTCMTA 0x65 /* Alarm Month */
+#define PCF50633_REG_RTCYRA 0x66 /* Alarm Year */
+
+#define PCF50633_F_RTC_SECOND (1 << PCF50633_FIDX_RTC_SECOND)
+
+struct pcf50633_rtc {
+ int alarm_enabled;
+ int second_enabled;
+
+ struct rtc_device *rtc_dev;
+ struct platform_device *pdev;
+};
+
+#endif
+
More information about the openmoko-kernel
mailing list