aboutsummaryrefslogtreecommitdiff
path: root/drivers/mfd
diff options
context:
space:
mode:
authormerging other branches <null@invalid>2008-11-26 16:07:01 +0000
committerAndy Green <agreen@pads.home.warmcat.com>2008-11-26 16:07:01 +0000
commit6d2c293d6578048e7b71e0c44897144f15f350ae (patch)
treecba36be2a06ee7bfa0aab1a3c7d36bd67ea37402 /drivers/mfd
parent524f4a1dfe71a8b353a244140164e09828abb68c (diff)
MERGE-via-balaji-tracking-hist-MERGE-via-stable-tracking-hist-MERGE-via-mokopatches-tracking-via-master-s3c-hsmmc-clean
balaji-tracking-hist top was efb2d57c0e0ed62324d79d6c5793fe797c157266
Diffstat (limited to 'drivers/mfd')
-rw-r--r--drivers/mfd/Kconfig23
-rw-r--r--drivers/mfd/Makefile5
-rw-r--r--drivers/mfd/pcf50606-adc.c239
-rw-r--r--drivers/mfd/pcf50606-core.c580
-rw-r--r--drivers/mfd/pcf50606-gpo.c128
-rw-r--r--drivers/mfd/pcf50633-adc.c6
-rw-r--r--drivers/mfd/pcf50633-core.c22
-rw-r--r--drivers/mfd/pcf50633-gpio.c6
8 files changed, 992 insertions, 17 deletions
diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig
index 6509719237d..1ab10dba8c8 100644
--- a/drivers/mfd/Kconfig
+++ b/drivers/mfd/Kconfig
@@ -177,6 +177,29 @@ config PCF50633_GPIO
Say yes here if you want to include support GPIO for pins on
the PCF50633 chip.
+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 c515325b4b2..f6a769c8eff 100644
--- a/drivers/mfd/Makefile
+++ b/drivers/mfd/Makefile
@@ -37,3 +37,8 @@ obj-$(CONFIG_PMIC_DA903X) += da903x.o
obj-$(CONFIG_MFD_PCF50633) += pcf50633-core.o
obj-$(CONFIG_PCF50633_ADC) += pcf50633-adc.o
obj-$(CONFIG_PCF50633_GPIO) += pcf50633-gpio.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..68e099ad61c
--- /dev/null
+++ b/drivers/mfd/pcf50606-adc.c
@@ -0,0 +1,239 @@
+/* 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 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.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ */
+
+#include <linux/mfd/pcf50606/core.h>
+#include <linux/mfd/pcf50606/adc.h>
+
+struct pcf50606_adc_request {
+ int mux;
+ int avg;
+ int result;
+ void (*callback)(struct pcf50606 *, void *, int);
+ void *callback_param;
+
+ /* Used in case of sync requests */
+ struct completion completion;
+
+};
+
+static void adc_read_setup(struct pcf50606 *pcf,
+ int channel, int avg)
+{
+ 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)
+{
+ 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 pcf50606 *pcf, struct pcf50606_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) & (PCF50606_MAX_ADC_FIFO_DEPTH - 1);
+
+ mutex_unlock(&pcf->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, int avg)
+{
+
+ struct pcf50606_adc_request *req;
+ int result;
+
+ /* req is freed when the result is ready, in pcf50606_work*/
+ req = kzalloc(sizeof(*req), GFP_KERNEL);
+ if (!req)
+ return -ENOMEM;
+
+ req->mux = mux;
+ req->avg = avg;
+ req->callback = pcf50606_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_GPL(pcf50606_adc_sync_read);
+
+int pcf50606_adc_async_read(struct pcf50606 *pcf, int mux, int avg,
+ 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->avg = avg;
+ 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_info(pcf->dev, "adc result = %d\n", ret);
+
+ return ret;
+}
+
+static void pcf50606_adc_irq(struct pcf50606 *pcf, int irq, void *unused)
+{
+ struct pcf50606_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) &
+ (PCF50606_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 pcf50606_adc_probe(struct platform_device *pdev)
+{
+ struct pcf50606 *pcf;
+
+ pcf = platform_get_drvdata(pdev);
+
+ /* Set up IRQ handlers */
+ pcf->irq_handler[PCF50606_IRQ_ADCRDY].handler = pcf50606_adc_irq;
+
+ mutex_init(&pcf->adc.queue_mutex);
+ return 0;
+}
+
+static int __devexit pcf50606_adc_remove(struct platform_device *pdev)
+{
+ struct pcf50606 *pcf;
+
+ pcf = platform_get_drvdata(pdev);
+ pcf->irq_handler[PCF50606_IRQ_ADCRDY].handler = NULL;
+
+ 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..47a8aa11954
--- /dev/null
+++ b/drivers/mfd/pcf50606-core.c
@@ -0,0 +1,580 @@
+/* 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.
+ *
+ * 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/i2c.h>
+#include <linux/irq.h>
+#include <linux/device.h>
+#include <linux/module.h>
+#include <linux/reboot.h>
+#include <linux/interrupt.h>
+#include <linux/workqueue.h>
+#include <linux/platform_device.h>
+
+#include <linux/mfd/pcf50606/core.h>
+
+/* 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 = i2c_smbus_read_i2c_block_data(pcf->i2c_client, 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 = i2c_smbus_write_i2c_block_data(pcf->i2c_client, 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)
+{
+ int ret;
+
+ mutex_lock(&pcf->lock);
+ ret = i2c_smbus_read_byte_data(pcf->i2c_client, reg);
+ mutex_unlock(&pcf->lock);
+
+ return ret;
+}
+EXPORT_SYMBOL_GPL(pcf50606_reg_read);
+
+int pcf50606_reg_write(struct pcf50606 *pcf, u8 reg, u8 val)
+{
+ int ret;
+ mutex_lock(&pcf->lock);
+ ret = i2c_smbus_write_byte_data(pcf->i2c_client, reg, 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);
+
+ tmp = i2c_smbus_read_byte_data(pcf->i2c_client, reg);
+ tmp &= ~mask;
+ tmp |= val;
+ ret = i2c_smbus_write_byte_data(pcf->i2c_client, reg, tmp);
+
+ 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);
+
+ tmp = i2c_smbus_read_byte_data(pcf->i2c_client, reg);
+ tmp &= ~val;
+ ret = i2c_smbus_write_byte_data(pcf->i2c_client, reg, tmp);
+
+ mutex_unlock(&pcf->lock);
+
+ return ret;
+}
+EXPORT_SYMBOL_GPL(pcf50606_reg_clear_bits);
+
+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%02x%02x\n",
+ pcf->resume_reason[0],
+ pcf->resume_reason[1],
+ pcf->resume_reason[2],
+ pcf->resume_reason[3],
+ pcf->resume_reason[4]);
+
+ return n;
+}
+static DEVICE_ATTR(resume_reason, 0400, show_resume_reason, NULL);
+
+static struct attribute *pcf_sysfs_entries[] = {
+ &dev_attr_resume_reason.attr,
+ NULL,
+};
+
+static struct attribute_group pcf_attr_group = {
+ .name = NULL, /* put in device directory */
+ .attrs = pcf_sysfs_entries,
+};
+
+
+static int pcf50606_irq_mask_set(struct pcf50606 *pcf, int irq, int mask)
+{
+ u8 reg, bits, tmp;
+ int ret = 0, idx;
+
+ idx = irq / 8;
+ reg = PCF50606_REG_INT1M + idx;
+ bits = 1 << (irq % 8);
+
+ mutex_lock(&pcf->lock);
+
+ if (mask) {
+ tmp = i2c_smbus_read_byte_data(pcf->i2c_client, reg);
+ tmp |= bits;
+ ret = i2c_smbus_write_byte_data(pcf->i2c_client, reg, tmp);
+
+ pcf->mask_regs[idx] &= ~bits;
+ pcf->mask_regs[idx] |= bits;
+ } else {
+ tmp = i2c_smbus_read_byte_data(pcf->i2c_client, reg);
+ tmp &= ~bits;
+ ret = i2c_smbus_write_byte_data(pcf->i2c_client, reg, tmp);
+
+ pcf->mask_regs[idx] &= ~bits;
+ }
+
+ mutex_unlock(&pcf->lock);
+
+ return 0;
+}
+
+int pcf50606_irq_mask(struct pcf50606 *pcf, int irq)
+{
+ dev_info(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_info(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(pcf, irq,
+ pcf->irq_handler[irq].data);
+}
+
+#define PCF50606_ONKEY1S_TIMEOUT 8
+
+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,
+ 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;
+ }
+
+ /* We immediately read the usb and adapter status. We thus make sure
+ * only of CHGINS/CHGRM 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_info(pcf->dev, "INT1=0x%02x INT2=0x%02x INT3=0x%02x",
+ 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 any input events to
+ * userspace now */
+ pcf_int[0] &= ~(PCF50606_INT1_SECOND | PCF50606_INT1_ALARM);
+ }
+
+ /* Unset masked interrupts */
+ for (i = 0; i < ARRAY_SIZE(pcf_int); i++)
+ pcf_int[i] &= ~pcf->mask_regs[i];
+
+ for (i = 0; i < ARRAY_SIZE(pcf_int); i++)
+ for (j = 0; j < 8 ; j++)
+ if (pcf_int[i] & (1 << j))
+ pcf50606_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 pcf50606_irq(int irq, void *data)
+{
+ struct pcf50606 *pcf = data;
+
+ get_device(pcf->dev);
+ 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;
+ 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 pcf50606_suspend(struct device *dev, pm_message_t state)
+{
+ struct pcf50606 *pcf;
+ int ret, i;
+ u8 res[3];
+
+ 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);
+
+ /* 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");
+
+ /* Set interrupt masks. So that only those sources we want to wake
+ * us up can
+ */
+ for (i = 0; i < ARRAY_SIZE(res); i++)
+ res[i] = ~pcf->pdata->resumers[i];
+
+ pcf50606_write_block(pcf, PCF50606_REG_INT1M,
+ ARRAY_SIZE(res), &res[0]);
+
+ pcf->is_suspended = 1;
+
+ return 0;
+}
+
+static int pcf50606_resume(struct device *dev)
+{
+ struct pcf50606 *pcf;
+
+ pcf = dev_get_drvdata(dev);
+
+ /* Write the saved mask registers */
+ pcf50606_write_block(pcf, PCF50606_REG_INT1M,
+ ARRAY_SIZE(pcf->suspend_irq_masks),
+ pcf->suspend_irq_masks);
+
+ /* Clear any pending interrupts and set resume reason if any */
+ pcf50606_irq_worker(&pcf->irq_work);
+
+ enable_irq(pcf->irq);
+
+ 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;
+ int i, ret = 0;
+ int version, variant;
+ u8 mbcs1;
+
+ pdata = client->dev.platform_data;
+
+ pcf = kzalloc(sizeof(*pcf), GFP_KERNEL);
+ if (!pcf)
+ return -ENOMEM;
+
+ pcf->pdata = pdata;
+ pdata->pcf = pcf;
+
+ mutex_init(&pcf->lock);
+
+ i2c_set_clientdata(client, pcf);
+ pcf->dev = &client->dev;
+ pcf->i2c_client = client;
+
+ INIT_WORK(&pcf->irq_work, pcf50606_irq_worker);
+
+ version = pcf50606_reg_read(pcf, 0);
+ if (version < 0) {
+ dev_err(pcf->dev, "Unable to probe pcf50606\n");
+ kfree(pcf);
+ return -ENODEV;
+ }
+
+ variant = pcf50606_reg_read(pcf, 1);
+ if (version < 0) {
+ dev_err(pcf->dev, "Unable to probe pcf50606\n");
+ kfree(pcf);
+ return -ENODEV;
+ }
+
+ dev_info(pcf->dev, "Probed device version %d variant %d\n",
+ version, variant);
+
+ /* Enable all inteerupts except RTC SECOND */
+ pcf->mask_regs[0] = 0x80;
+ pcf50606_reg_write(pcf, PCF50606_REG_INT1M, 0x80);
+
+ pcf50606_reg_write(pcf, PCF50606_REG_INT2M, 0x00);
+ pcf50606_reg_write(pcf, PCF50606_REG_INT3M, 0x00);
+
+ 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\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, pcf50606_irq,
+ IRQF_TRIGGER_FALLING, "pcf50606", 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 = pcf50606_reg_read(pcf, PCF50606_REG_MBCS1);
+
+ if (mbcs1 & (0x01 << 4)) /* Charger present ? */
+ pcf50606_irq_call_handler(pcf, PCF50606_IRQ_CHGINS);
+
+ ret = sysfs_create_group(&client->dev.kobj, &pcf_attr_group);
+ if (ret)
+ dev_err(pcf->dev, "error creating sysfs entries\n");
+
+ if (pdata->probe_done)
+ pdata->probe_done(pcf);
+
+ return 0;
+
+err:
+ kfree(pcf);
+ return ret;
+}
+
+static int pcf50606_remove(struct i2c_client *client)
+{
+ struct pcf50606 *pcf = i2c_get_clientdata(client);
+
+ free_irq(pcf->irq, pcf);
+ kfree(pcf);
+
+ return 0;
+}
+
+static struct i2c_device_id pcf50606_id_table[] = {
+ {"pcf50606", 0x73},
+};
+
+static struct i2c_driver pcf50606_driver = {
+ .driver = {
+ .name = "pcf50606",
+ .suspend = pcf50606_suspend,
+ .resume = pcf50606_resume,
+ },
+ .id_table = pcf50606_id_table,
+ .probe = pcf50606_probe,
+ .remove = pcf50606_remove,
+};
+
+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..28b6d77ad80
--- /dev/null
+++ b/drivers/mfd/pcf50606-gpo.c
@@ -0,0 +1,128 @@
+/* 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 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.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ */
+
+#include <linux/mfd/pcf50606/core.h>
+#include <linux/mfd/pcf50606/gpo.h>
+#include <linux/mfd/pcf50606/pmic.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/mfd/pcf50633-adc.c b/drivers/mfd/pcf50633-adc.c
index 39bdbae67da..ebd3792e778 100644
--- a/drivers/mfd/pcf50633-adc.c
+++ b/drivers/mfd/pcf50633-adc.c
@@ -5,7 +5,7 @@
* All rights reserved.
*
* Broken down from monstrous PCF50633 driver mainly by
- * Harald Welte and Andy Green
+ * 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
@@ -133,7 +133,7 @@ int pcf50633_adc_sync_read(struct pcf50633 *pcf, int mux, int avg)
return result;
}
-EXPORT_SYMBOL(pcf50633_adc_sync_read);
+EXPORT_SYMBOL_GPL(pcf50633_adc_sync_read);
int pcf50633_adc_async_read(struct pcf50633 *pcf, int mux, int avg,
void (*callback)(struct pcf50633 *, void *, int),
@@ -155,7 +155,7 @@ int pcf50633_adc_async_read(struct pcf50633 *pcf, int mux, int avg,
return 0;
}
-EXPORT_SYMBOL(pcf50633_adc_async_read);
+EXPORT_SYMBOL_GPL(pcf50633_adc_async_read);
static int adc_result(struct pcf50633 *pcf)
{
diff --git a/drivers/mfd/pcf50633-core.c b/drivers/mfd/pcf50633-core.c
index 6d66b526bc2..dd6a7949182 100644
--- a/drivers/mfd/pcf50633-core.c
+++ b/drivers/mfd/pcf50633-core.c
@@ -48,7 +48,7 @@ int pcf50633_read_block(struct pcf50633 *pcf , u8 reg,
return ret;
}
-EXPORT_SYMBOL(pcf50633_read_block);
+EXPORT_SYMBOL_GPL(pcf50633_read_block);
/* Write a block of upto 32 regs */
int pcf50633_write_block(struct pcf50633 *pcf , u8 reg,
@@ -63,7 +63,7 @@ int pcf50633_write_block(struct pcf50633 *pcf , u8 reg,
return ret;
}
-EXPORT_SYMBOL(pcf50633_write_block);
+EXPORT_SYMBOL_GPL(pcf50633_write_block);
u8 pcf50633_reg_read(struct pcf50633 *pcf, u8 reg)
{
@@ -75,7 +75,7 @@ u8 pcf50633_reg_read(struct pcf50633 *pcf, u8 reg)
return ret;
}
-EXPORT_SYMBOL(pcf50633_reg_read);
+EXPORT_SYMBOL_GPL(pcf50633_reg_read);
int pcf50633_reg_write(struct pcf50633 *pcf, u8 reg, u8 val)
{
@@ -86,7 +86,7 @@ int pcf50633_reg_write(struct pcf50633 *pcf, u8 reg, u8 val)
return ret;
}
-EXPORT_SYMBOL(pcf50633_reg_write);
+EXPORT_SYMBOL_GPL(pcf50633_reg_write);
int pcf50633_reg_set_bit_mask(struct pcf50633 *pcf, u8 reg, u8 mask, u8 val)
{
@@ -106,7 +106,7 @@ int pcf50633_reg_set_bit_mask(struct pcf50633 *pcf, u8 reg, u8 mask, u8 val)
return ret;
}
-EXPORT_SYMBOL(pcf50633_reg_set_bit_mask);
+EXPORT_SYMBOL_GPL(pcf50633_reg_set_bit_mask);
int pcf50633_reg_clear_bits(struct pcf50633 *pcf, u8 reg, u8 val)
{
@@ -123,7 +123,7 @@ int pcf50633_reg_clear_bits(struct pcf50633 *pcf, u8 reg, u8 val)
return ret;
}
-EXPORT_SYMBOL(pcf50633_reg_clear_bits);
+EXPORT_SYMBOL_GPL(pcf50633_reg_clear_bits);
/* sysfs attributes */
static ssize_t show_dump_regs(struct device *dev, struct device_attribute *attr,
@@ -226,7 +226,7 @@ int pcf50633_irq_mask(struct pcf50633 *pcf, int irq)
return pcf50633_irq_mask_set(pcf, irq, 1);
}
-EXPORT_SYMBOL(pcf50633_irq_mask);
+EXPORT_SYMBOL_GPL(pcf50633_irq_mask);
int pcf50633_irq_unmask(struct pcf50633 *pcf, int irq)
{
@@ -234,7 +234,7 @@ int pcf50633_irq_unmask(struct pcf50633 *pcf, int irq)
return pcf50633_irq_mask_set(pcf, irq, 0);
}
-EXPORT_SYMBOL(pcf50633_irq_unmask);
+EXPORT_SYMBOL_GPL(pcf50633_irq_unmask);
int pcf50633_irq_mask_get(struct pcf50633 *pcf, int irq)
{
@@ -245,7 +245,7 @@ int pcf50633_irq_mask_get(struct pcf50633 *pcf, int irq)
return pcf->mask_regs[reg] & bits;
}
-EXPORT_SYMBOL(pcf50633_irq_mask_get);
+EXPORT_SYMBOL_GPL(pcf50633_irq_mask_get);
static void pcf50633_irq_call_handler(struct pcf50633 *pcf,
int irq)
@@ -485,7 +485,7 @@ static int pcf50633_probe(struct i2c_client *client,
pcf->pdata = pdata;
pdata->pcf = pcf;
-
+
mutex_init(&pcf->lock);
i2c_set_clientdata(client, pcf);
@@ -502,7 +502,7 @@ static int pcf50633_probe(struct i2c_client *client,
}
variant = pcf50633_reg_read(pcf, 1);
- if (version < 0) {
+ if (variant < 0) {
dev_err(pcf->dev, "Unable to probe pcf50633\n");
kfree(pcf);
return -ENODEV;
diff --git a/drivers/mfd/pcf50633-gpio.c b/drivers/mfd/pcf50633-gpio.c
index a5b978c4e3c..a7117fa6282 100644
--- a/drivers/mfd/pcf50633-gpio.c
+++ b/drivers/mfd/pcf50633-gpio.c
@@ -5,7 +5,7 @@
* All rights reserved.
*
* Broken down from monstrous PCF50633 driver mainly by
- * Harald Welte and Andy Green
+ * 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
@@ -30,7 +30,7 @@
void pcf50633_gpio_set(struct pcf50633 *pcf, int gpio, int val)
{
u8 reg;
-
+
reg = gpio - PCF50633_GPIO1 + PCF50633_REG_GPIO1CFG;
pcf50633_reg_set_bit_mask(pcf, reg, 0x07, val);
@@ -91,7 +91,7 @@ void pcf50633_gpio_power_supply_set(struct pcf50633 *pcf,
/* the *ENA register is always one after the *OUT register */
reg = pcf50633_regulator_registers[regulator] + 1;
-
+
val = (!!on << (gpio - PCF50633_GPIO1));
pcf50633_reg_set_bit_mask(pcf, reg, val, val);