]> pilppa.com Git - linux-2.6-omap-h63xx.git/commitdiff
i2c: move twl4030-pwrbutton to child registration style
authorFelipe Balbi <me@felipebalbi.com>
Thu, 19 Feb 2009 13:29:56 +0000 (13:29 +0000)
committerTony Lindgren <tony@atomide.com>
Fri, 27 Feb 2009 18:42:46 +0000 (10:42 -0800)
This patch is *compile tested only*. It moves twl4030-pwrbutton
to a platform_driver so it can be registered as a child of
twl4030-core.c.

Cc: David Brownell <dbrownell@users.sourceforge.net>
Cc: Samuel Ortiz <sameo@openedhand.com>
Signed-off-by: Felipe Balbi <me@felipebalbi.com>
Signed-off-by: Tony Lindgren <tony@atomide.com>
drivers/i2c/chips/twl4030-pwrbutton.c
drivers/mfd/twl4030-core.c

index 1d9cb901696854ca6b87abd9318db10bdff28714..b0a9c9fda742446400dc427982155854d0fcba7f 100644 (file)
 #include <linux/errno.h>
 #include <linux/input.h>
 #include <linux/interrupt.h>
+#include <linux/platform_device.h>
 #include <linux/i2c/twl4030.h>
 
-
-#define PWR_PWRON_IRQ (1<<0)
+#define PWR_PWRON_IRQ (1 << 0)
 
 #define STS_HW_CONDITIONS 0xf
 
-
-/* FIXME have this constant delivered to us as part of the
- * twl4030-core setup ...
- */
-#define TWL4030_PWRIRQ_PWRBTN  (TWL4030_PWR_IRQ_BASE + 0)
-
 static struct input_dev *powerbutton_dev;
+static struct device *dbg_dev;
 
 static irqreturn_t powerbutton_irq(int irq, void *dev_id)
 {
@@ -61,29 +56,32 @@ static irqreturn_t powerbutton_irq(int irq, void *dev_id)
                input_report_key(powerbutton_dev, KEY_POWER,
                                 value & PWR_PWRON_IRQ);
        } else {
-               pr_err("twl4030: i2c error %d while reading TWL4030"
+               dev_err(dbg_dev, "twl4030: i2c error %d while reading TWL4030"
                        " PM_MASTER STS_HW_CONDITIONS register\n", err);
        }
 
        return IRQ_HANDLED;
 }
 
-static int __init twl4030_pwrbutton_init(void)
+static int __devinit twl4030_pwrbutton_probe(struct platform_device *pdev)
 {
        int err = 0;
+       int irq = platform_get_irq(pdev, 0);
+
+       dbg_dev = &pdev->dev;
 
        /* PWRBTN == PWRON */
-       err = request_irq(TWL4030_PWRIRQ_PWRBTN, powerbutton_irq,
+       err = request_irq(irq, powerbutton_irq,
                        IRQF_TRIGGER_FALLING | IRQF_TRIGGER_RISING,
-                       "PwrButton", NULL);
+                       "twl4030-pwrbutton", NULL);
        if (err < 0) {
-               pr_debug("Can't get IRQ for power button: %d\n", err);
+               dev_dbg(&pdev->dev, "Can't get IRQ for power button: %d\n", err);
                goto out;
        }
 
        powerbutton_dev = input_allocate_device();
        if (!powerbutton_dev) {
-               pr_debug("Can't allocate power button\n");
+               dev_dbg(&pdev->dev, "Can't allocate power button\n");
                err = -ENOMEM;
                goto free_irq_and_out;
        }
@@ -94,11 +92,11 @@ static int __init twl4030_pwrbutton_init(void)
 
        err = input_register_device(powerbutton_dev);
        if (err) {
-               pr_debug("Can't register power button: %d\n", err);
+               dev_dbg(&pdev->dev, "Can't register power button: %d\n", err);
                goto free_input_dev;
        }
 
-       printk(KERN_INFO "triton2 power button driver initialized\n");
+       dev_info(&pdev->dev, "triton2 power button driver initialized\n");
 
        return 0;
 
@@ -110,13 +108,36 @@ free_irq_and_out:
 out:
        return err;
 }
-module_init(twl4030_pwrbutton_init);
 
-static void __exit twl4030_pwrbutton_exit(void)
+static int __devexit twl4030_pwrbutton_remove(struct platform_device *pdev)
 {
-       free_irq(TWL4030_PWRIRQ_PWRBTN, NULL);
+       int irq = platform_get_irq(pdev, 0);
+
+       free_irq(irq, NULL);
        input_unregister_device(powerbutton_dev);
        input_free_device(powerbutton_dev);
+
+       return 0;
+}
+
+struct platform_driver twl4030_pwrbutton_driver = {
+       .probe          = twl4030_pwrbutton_probe,
+       .remove         = twl4030_pwrbutton_remove,
+       .driver         = {
+               .name   = "twl4030-pwrbutton",
+               .owner  = THIS_MODULE,
+       },
+};
+
+static int __init twl4030_pwrbutton_init(void)
+{
+       return platform_driver_register(&twl4030_pwrbutton_driver);
+}
+module_init(twl4030_pwrbutton_init);
+
+static void __exit twl4030_pwrbutton_exit(void)
+{
+       platform_driver_unregister(&twl4030_pwrbutton_driver);
 }
 module_exit(twl4030_pwrbutton_exit);
 
index 8b479b2e5ecc87573921e1334a7716a619886673..347b3788e2e86331e85ee26d27ff73d13355fe69 100644 (file)
 #define twl_has_usb()  false
 #endif
 
+#if defined(CONFIG_TWL4030_PWRBUTTON) || defined(CONFIG_TWL4030_PWBUTTON_MODULE)
+#define twl_has_pwrbutton()    true
+#else
+#define twl_has_pwrbutton()    false
+#endif
 
 /* Triton Core internal information (BEGIN) */
 
@@ -534,6 +539,13 @@ add_children(struct twl4030_platform_data *pdata, unsigned long features)
                usb_transceiver = child;
        }
 
+       if (twl_has_pwrbutton()) {
+               child = add_child(1, "twl4030_pwrbutton",
+                               NULL, 0, true, pdata->irq_base + 8 + 0, 0);
+               if (IS_ERR(child))
+                       return PTR_ERR(child);
+       }
+
        if (twl_has_regulator()) {
                /*
                child = add_regulator(TWL4030_REG_VPLL1, pdata->vpll1);