/*
  * drivers/i2c/chips/lm8323.c
  *
- * Copyright (C) 2007 Nokia Corporation
+ * Copyright (C) 2007-2009 Nokia Corporation
  *
  * Written by Daniel Stone <daniel.stone@nokia.com>
  *            Timo O. Karjalainen <timo.o.karjalainen@nokia.com>
  *
+ * Updated by Felipe Balbi <felipe.balbi@nokia.com>
+ *
  * 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 (version 2 of the License only).
        int                     brightness;
        int                     desired_brightness;
        int                     running;
+       /* pwm lock */
        struct mutex            lock;
        struct work_struct      work;
        struct led_classdev     cdev;
 };
 
 struct lm8323_chip {
+       /* device lock */
        struct mutex            lock;
        struct i2c_client       *client;
        struct work_struct      work;
        struct input_dev        *idev;
-       unsigned                kp_enabled : 1;
-       unsigned                pm_suspend : 1;
+       unsigned                kp_enabled:1;
+       unsigned                pm_suspend:1;
        unsigned                keys_down;
        char                    phys[32];
        s16                     keymap[LM8323_KEYMAP_SIZE];
                if (error & ERR_FIFOOVER)
                        dev_vdbg(&lm->client->dev, "fifo overflow!\n");
                if (error & ERR_KEYOVR)
-                       dev_vdbg(&lm->client->dev, "more than two keys pressed\n");
+                       dev_vdbg(&lm->client->dev,
+                                       "more than two keys pressed\n");
                if (error & ERR_CMDUNK)
-                       dev_vdbg(&lm->client->dev, "unknown command submitted\n");
+                       dev_vdbg(&lm->client->dev,
+                                       "unknown command submitted\n");
                if (error & ERR_BADPAR)
                        dev_vdbg(&lm->client->dev, "bad command parameter\n");
        }
        if ((pwm->fade_time / steps) > (32768 / 512)) {
                div512 = 1;
                hz = 32768 / 512;
-       }
-       else {
+       } else {
                div512 = 0;
                hz = 32768 / 16;
        }
        int ret;
        int time;
 
-       ret = sscanf(buf, "%d", &time);
+       ret = strict_strtoul(buf, 10, &time);
        /* Numbers only, please. */
        if (ret)
                return -EINVAL;
        int ret;
        int i;
 
-       i = sscanf(buf, "%d", &ret);
+       ret = strict_strtoul(buf, 10, &i);
 
        mutex_lock(&lm->lock);
        lm->kp_enabled = !i;
                goto fail2;
        }
 
-       dev_vdbg(&client->dev, "Keypad size: %d x %d\n", lm->size_x, lm->size_y);
+       dev_vdbg(&client->dev, "Keypad size: %d x %d\n",
+                       lm->size_x, lm->size_y);
 
        lm->debounce_time = pdata->debounce_time;
        lm->active_time = pdata->active_time;
        INIT_WORK(&lm->work, lm8323_work);
 
        err = request_irq(client->irq, lm8323_irq,
-                         IRQF_TRIGGER_FALLING | IRQF_DISABLED |
-                         IRQF_SAMPLE_RANDOM, "lm8323", lm);
+                         IRQF_TRIGGER_FALLING | IRQF_DISABLED,
+                         "lm8323", lm);
        if (err) {
                dev_err(&client->dev, "could not get IRQ %d\n", client->irq);
                goto fail6;
        }
 
-       set_irq_wake(client->irq, 1);
+       device_init_wakeup(&client->dev, 1);
+       enable_irq_wake(client->irq);
 
        lm->kp_enabled = 1;
        err = device_create_file(&client->dev, &dev_attr_disable_kp);
        idev->evbit[0] = BIT(EV_KEY);
        for (i = 0; i < LM8323_KEYMAP_SIZE; i++) {
                if (pdata->keymap[i] > 0)
-                       set_bit(pdata->keymap[i], idev->keybit);
+                       __set_bit(pdata->keymap[i], idev->keybit);
 
                lm->keymap[i] = pdata->keymap[i];
        }
 
        if (pdata->repeat)
-               set_bit(EV_REP, idev->evbit);
+               __set_bit(EV_REP, idev->evbit);
 
        lm->idev = idev;
        err = input_register_device(idev);
 {
        struct lm8323_chip *lm = i2c_get_clientdata(client);
 
+       disable_irq_wake(client->irq);
        free_irq(client->irq, lm);
        cancel_work_sync(&lm->work);
        input_unregister_device(lm->idev);
        return 0;
 }
 
+#ifdef CONFIG_PM
 /*
  * We don't need to explicitly suspend the chip, as it already switches off
  * when there's no activity.
 
        return 0;
 }
+#else
+#define lm8323_suspend NULL
+#define lm8323_resume  NULL
+#endif
 
 static const struct i2c_device_id lm8323_id[] = {
        { "lm8323", 0 },
 }
 module_exit(lm8323_exit);
 
-MODULE_AUTHOR("Timo O. Karjalainen <timo.o.karjalainen@nokia.com>, Daniel Stone");
+MODULE_AUTHOR("Timo O. Karjalainen <timo.o.karjalainen@nokia.com>");
+MODULE_AUTHOR("Daniel Stone");
+MODULE_AUTHOR("Felipe Balbi <felipe.balbi@nokia.com>");
 MODULE_DESCRIPTION("LM8323 keypad driver");
 MODULE_LICENSE("GPL");
 
 
 /*
- * include/lm8323.h
+ * lm8323.h - Configuration for LM8323 keypad driver.
  *
- * Configuration for LM8323 keypad driver.
+ * 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 (version 2 of the License only).
+ *
+ * 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
  */
 
 #ifndef __LINUX_LM8323_H
 
        int size_x;
        int size_y;
-       int repeat : 1;
+       int repeat:1;
        const s16 *keymap;
 
        char *pwm1_name; /* Device name for PWM1. */