mem-hotplug: avoid multiple zones sharing same boot strapping boot_pageset
[safe/jmp/linux-2.6] / drivers / mfd / ab3100-core.c
index 8ff10cb..e4ca590 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2007-2009 ST-Ericsson
+ * Copyright (C) 2007-2010 ST-Ericsson
  * License terms: GNU General Public License (GPL) version 2
  * Low-level core for exclusive access to the AB3100 IC on the I2C bus
  * and some basic chip-configuration.
 #include <linux/mutex.h>
 #include <linux/list.h>
 #include <linux/notifier.h>
+#include <linux/slab.h>
 #include <linux/err.h>
 #include <linux/platform_device.h>
 #include <linux/device.h>
 #include <linux/interrupt.h>
-#include <linux/workqueue.h>
+#include <linux/random.h>
 #include <linux/debugfs.h>
 #include <linux/seq_file.h>
 #include <linux/uaccess.h>
@@ -58,8 +59,6 @@
  * The AB3100 is usually assigned address 0x48 (7-bit)
  * The chip is defined in the platform i2c_board_data section.
  */
-static unsigned short normal_i2c[] = { 0x48, I2C_CLIENT_END };
-I2C_CLIENT_INSMOD_1(ab3100);
 
 u8 ab3100_get_chip_type(struct ab3100 *ab3100)
 {
@@ -77,7 +76,7 @@ u8 ab3100_get_chip_type(struct ab3100 *ab3100)
 }
 EXPORT_SYMBOL(ab3100_get_chip_type);
 
-int ab3100_set_register(struct ab3100 *ab3100, u8 reg, u8 regval)
+int ab3100_set_register_interruptible(struct ab3100 *ab3100, u8 reg, u8 regval)
 {
        u8 regandval[2] = {reg, regval};
        int err;
@@ -107,9 +106,10 @@ int ab3100_set_register(struct ab3100 *ab3100, u8 reg, u8 regval)
                err = 0;
        }
        mutex_unlock(&ab3100->access_mutex);
-       return 0;
+       return err;
 }
-EXPORT_SYMBOL(ab3100_set_register);
+EXPORT_SYMBOL(ab3100_set_register_interruptible);
+
 
 /*
  * The test registers exist at an I2C bus address up one
@@ -118,7 +118,7 @@ EXPORT_SYMBOL(ab3100_set_register);
  * anyway. It's currently only used from this file so declare
  * it static and do not export.
  */
-static int ab3100_set_test_register(struct ab3100 *ab3100,
+static int ab3100_set_test_register_interruptible(struct ab3100 *ab3100,
                                    u8 reg, u8 regval)
 {
        u8 regandval[2] = {reg, regval};
@@ -148,7 +148,8 @@ static int ab3100_set_test_register(struct ab3100 *ab3100,
        return err;
 }
 
-int ab3100_get_register(struct ab3100 *ab3100, u8 reg, u8 *regval)
+
+int ab3100_get_register_interruptible(struct ab3100 *ab3100, u8 reg, u8 *regval)
 {
        int err;
 
@@ -202,9 +203,10 @@ int ab3100_get_register(struct ab3100 *ab3100, u8 reg, u8 *regval)
        mutex_unlock(&ab3100->access_mutex);
        return err;
 }
-EXPORT_SYMBOL(ab3100_get_register);
+EXPORT_SYMBOL(ab3100_get_register_interruptible);
 
-int ab3100_get_register_page(struct ab3100 *ab3100,
+
+int ab3100_get_register_page_interruptible(struct ab3100 *ab3100,
                             u8 first_reg, u8 *regvals, u8 numregs)
 {
        int err;
@@ -258,9 +260,10 @@ int ab3100_get_register_page(struct ab3100 *ab3100,
        mutex_unlock(&ab3100->access_mutex);
        return err;
 }
-EXPORT_SYMBOL(ab3100_get_register_page);
+EXPORT_SYMBOL(ab3100_get_register_page_interruptible);
+
 
-int ab3100_mask_and_set_register(struct ab3100 *ab3100,
+int ab3100_mask_and_set_register_interruptible(struct ab3100 *ab3100,
                                 u8 reg, u8 andmask, u8 ormask)
 {
        u8 regandval[2] = {reg, 0};
@@ -328,7 +331,8 @@ int ab3100_mask_and_set_register(struct ab3100 *ab3100,
        mutex_unlock(&ab3100->access_mutex);
        return err;
 }
-EXPORT_SYMBOL(ab3100_mask_and_set_register);
+EXPORT_SYMBOL(ab3100_mask_and_set_register_interruptible);
+
 
 /*
  * Register a simple callback for handling any AB3100 events.
@@ -363,18 +367,23 @@ int ab3100_event_registers_startup_state_get(struct ab3100 *ab3100,
 }
 EXPORT_SYMBOL(ab3100_event_registers_startup_state_get);
 
-/* Interrupt handling worker */
-static void ab3100_work(struct work_struct *work)
+/*
+ * This is a threaded interrupt handler so we can make some
+ * I2C calls etc.
+ */
+static irqreturn_t ab3100_irq_handler(int irq, void *data)
 {
-       struct ab3100 *ab3100 = container_of(work, struct ab3100, work);
+       struct ab3100 *ab3100 = data;
        u8 event_regs[3];
        u32 fatevent;
        int err;
 
-       err = ab3100_get_register_page(ab3100, AB3100_EVENTA1,
+       add_interrupt_randomness(irq);
+
+       err = ab3100_get_register_page_interruptible(ab3100, AB3100_EVENTA1,
                                       event_regs, 3);
        if (err)
-               goto err_event_wq;
+               goto err_event;
 
        fatevent = (event_regs[0] << 16) |
                (event_regs[1] << 8) |
@@ -396,29 +405,11 @@ static void ab3100_work(struct work_struct *work)
        dev_dbg(ab3100->dev,
                "IRQ Event: 0x%08x\n", fatevent);
 
-       /* By now the IRQ should be acked and deasserted so enable it again */
-       enable_irq(ab3100->i2c_client->irq);
-       return;
+       return IRQ_HANDLED;
 
- err_event_wq:
+ err_event:
        dev_dbg(ab3100->dev,
-               "error in event workqueue\n");
-       /* Enable the IRQ anyway, what choice do we have? */
-       enable_irq(ab3100->i2c_client->irq);
-       return;
-}
-
-static irqreturn_t ab3100_irq_handler(int irq, void *data)
-{
-       struct ab3100 *ab3100 = data;
-       /*
-        * Disable the IRQ and dispatch a worker to handle the
-        * event. Since the chip resides on I2C this is slow
-        * stuff and we will re-enable the interrupts once th
-        * worker has finished.
-        */
-       disable_irq(ab3100->i2c_client->irq);
-       schedule_work(&ab3100->work);
+               "error reading event status\n");
        return IRQ_HANDLED;
 }
 
@@ -435,7 +426,7 @@ static int ab3100_registers_print(struct seq_file *s, void *p)
        seq_printf(s, "AB3100 registers:\n");
 
        for (reg = 0; reg < 0xff; reg++) {
-               ab3100_get_register(ab3100, reg, &value);
+               ab3100_get_register_interruptible(ab3100, reg, &value);
                seq_printf(s, "[0x%x]:  0x%x\n", reg, value);
        }
        return 0;
@@ -515,7 +506,7 @@ static ssize_t ab3100_get_set_reg(struct file *file,
                u8 reg = (u8) user_reg;
                u8 regvalue;
 
-               ab3100_get_register(ab3100, reg, &regvalue);
+               ab3100_get_register_interruptible(ab3100, reg, &regvalue);
 
                dev_info(ab3100->dev,
                         "debug read AB3100 reg[0x%02x]: 0x%02x\n",
@@ -547,8 +538,8 @@ static ssize_t ab3100_get_set_reg(struct file *file,
                        return -EINVAL;
 
                value = (u8) user_value;
-               ab3100_set_register(ab3100, reg, value);
-               ab3100_get_register(ab3100, reg, &regvalue);
+               ab3100_set_register_interruptible(ab3100, reg, value);
+               ab3100_get_register_interruptible(ab3100, reg, &regvalue);
 
                dev_info(ab3100->dev,
                         "debug write reg[0x%02x] with 0x%02x, "
@@ -643,7 +634,7 @@ struct ab3100_init_setting {
        u8 setting;
 };
 
-static const struct ab3100_init_setting __initdata
+static const struct ab3100_init_setting __initconst
 ab3100_init_settings[] = {
        {
                .abreg = AB3100_MCA,
@@ -662,7 +653,7 @@ ab3100_init_settings[] = {
                .setting = 0x01
        }, {
                .abreg = AB3100_IMRB1,
-               .setting = 0xFF
+               .setting = 0xBF
        }, {
                .abreg = AB3100_IMRB2,
                .setting = 0xFF
@@ -696,7 +687,7 @@ static int __init ab3100_setup(struct ab3100 *ab3100)
        int i;
 
        for (i = 0; i < ARRAY_SIZE(ab3100_init_settings); i++) {
-               err = ab3100_set_register(ab3100,
+               err = ab3100_set_register_interruptible(ab3100,
                                          ab3100_init_settings[i].abreg,
                                          ab3100_init_settings[i].setting);
                if (err)
@@ -705,14 +696,14 @@ static int __init ab3100_setup(struct ab3100 *ab3100)
 
        /*
         * Special trick to make the AB3100 use the 32kHz clock (RTC)
-        * bit 3 in test registe 0x02 is a special, undocumented test
+        * bit 3 in test register 0x02 is a special, undocumented test
         * register bit that only exist in AB3100 P1E
         */
        if (ab3100->chip_id == 0xc4) {
                dev_warn(ab3100->dev,
                         "AB3100 P1E variant detected, "
                         "forcing chip to 32KHz\n");
-               err = ab3100_set_test_register(ab3100, 0x02, 0x08);
+               err = ab3100_set_test_register_interruptible(ab3100, 0x02, 0x08);
        }
 
  exit_no_setup:
@@ -733,10 +724,7 @@ static struct platform_device ab3100_##devname##_device = {        \
        .id             = -1,                                   \
 }
 
-/*
- * This lists all the subdevices and corresponding register
- * ranges.
- */
+/* This lists all the subdevices */
 AB3100_DEVICE(dac, "ab3100-dac");
 AB3100_DEVICE(leds, "ab3100-leds");
 AB3100_DEVICE(power, "ab3100-power");
@@ -833,6 +821,8 @@ static int __init ab3100_probe(struct i2c_client *client,
                        const struct i2c_device_id *id)
 {
        struct ab3100 *ab3100;
+       struct ab3100_platform_data *ab3100_plf_data =
+               client->dev.platform_data;
        int err;
        int i;
 
@@ -852,8 +842,8 @@ static int __init ab3100_probe(struct i2c_client *client,
        i2c_set_clientdata(client, ab3100);
 
        /* Read chip ID register */
-       err = ab3100_get_register(ab3100, AB3100_CID,
-                                 &ab3100->chip_id);
+       err = ab3100_get_register_interruptible(ab3100, AB3100_CID,
+                                               &ab3100->chip_id);
        if (err) {
                dev_err(&client->dev,
                        "could not communicate with the AB3100 analog "
@@ -896,19 +886,15 @@ static int __init ab3100_probe(struct i2c_client *client,
                goto exit_no_testreg_client;
        }
 
-       strlcpy(ab3100->testreg_client->name, id->name,
-               sizeof(ab3100->testreg_client->name));
-
        err = ab3100_setup(ab3100);
        if (err)
                goto exit_no_setup;
 
-       INIT_WORK(&ab3100->work, ab3100_work);
-
+       err = request_threaded_irq(client->irq, NULL, ab3100_irq_handler,
+                               IRQF_ONESHOT, "ab3100-core", ab3100);
        /* This real unpredictable IRQ is of course sampled for entropy */
-       err = request_irq(client->irq, ab3100_irq_handler,
-                         IRQF_DISABLED | IRQF_SAMPLE_RANDOM,
-                         "AB3100 IRQ", ab3100);
+       rand_initialize_irq(client->irq);
+
        if (err)
                goto exit_no_irq;
 
@@ -916,6 +902,8 @@ static int __init ab3100_probe(struct i2c_client *client,
        for (i = 0; i < ARRAY_SIZE(ab3100_platform_devs); i++) {
                ab3100_platform_devs[i]->dev.parent =
                        &client->dev;
+               ab3100_platform_devs[i]->dev.platform_data =
+                       ab3100_plf_data;
                platform_set_drvdata(ab3100_platform_devs[i], ab3100);
        }
 
@@ -958,7 +946,7 @@ static int __exit ab3100_remove(struct i2c_client *client)
 }
 
 static const struct i2c_device_id ab3100_id[] = {
-       { "ab3100", ab3100 },
+       { "ab3100", 0 },
        { }
 };
 MODULE_DEVICE_TABLE(i2c, ab3100_id);