--- v4
+++ v2
@@ -1,88 +1,148 @@
-Use devres functionality to simplify resource freeing, dev.parent will
-be set by devm_input_allocate_device().
+As preparation for mc13783-pwrbutton OF support, convert the members of
+mc13xxx_buttons_platform_data to arrays to allow index access within
+the next commit.
Signed-off-by: Alexander Kurz <akurz@blala.de>
---
- drivers/input/misc/mc13783-pwrbutton.c | 28 ++++++++------------------
- 1 file changed, 8 insertions(+), 20 deletions(-)
+ drivers/input/misc/mc13783-pwrbutton.c | 54 +++++++++++++-------------
+ include/linux/mfd/mc13xxx.h | 8 +---
+ 2 files changed, 29 insertions(+), 33 deletions(-)
diff --git a/drivers/input/misc/mc13783-pwrbutton.c b/drivers/input/misc/mc13783-pwrbutton.c
-index b83d762ae2e9..82434ea9cca5 100644
+index 9fd84b8d163d..ace9f286fd24 100644
--- a/drivers/input/misc/mc13783-pwrbutton.c
+++ b/drivers/input/misc/mc13783-pwrbutton.c
-@@ -21,6 +21,7 @@
+@@ -127,24 +127,24 @@ static int mc13783_pwrbutton_probe(struct platform_device *pdev)
+ if (!priv)
+ return -ENOMEM;
- #include <linux/module.h>
- #include <linux/kernel.h>
-+#include <linux/device.h>
- #include <linux/errno.h>
- #include <linux/input.h>
- #include <linux/interrupt.h>
-@@ -102,18 +103,13 @@ static int mc13783_pwrbutton_probe(struct platform_device *pdev)
- return -ENODEV;
- }
+- reg |= (pdata->b1on_flags & 0x3) << MC13783_POWER_CONTROL_2_ON1BDBNC;
+- reg |= (pdata->b2on_flags & 0x3) << MC13783_POWER_CONTROL_2_ON2BDBNC;
+- reg |= (pdata->b3on_flags & 0x3) << MC13783_POWER_CONTROL_2_ON3BDBNC;
++ reg |= (pdata->b_on_flags[0] & 0x3) << MC13783_POWER_CONTROL_2_ON1BDBNC;
++ reg |= (pdata->b_on_flags[1] & 0x3) << MC13783_POWER_CONTROL_2_ON2BDBNC;
++ reg |= (pdata->b_on_flags[2] & 0x3) << MC13783_POWER_CONTROL_2_ON3BDBNC;
-- pwr = input_allocate_device();
-- if (!pwr) {
-- dev_dbg(&pdev->dev, "Can't allocate power button\n");
-+ pwr = devm_input_allocate_device(&pdev->dev);
-+ if (!pwr)
- return -ENOMEM;
-- }
+ priv->pwr = pwr;
+ priv->mc13783 = mc13783;
-- priv = kzalloc(sizeof(*priv), GFP_KERNEL);
-- if (!priv) {
-- err = -ENOMEM;
-- dev_dbg(&pdev->dev, "Can't allocate power button\n");
-- goto free_input_dev;
-- }
-+ priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
-+ if (!priv)
-+ return -ENOMEM;
+ mc13xxx_lock(mc13783);
- reg |= (pdata->b1on_flags & 0x3) << MC13783_POWER_CONTROL_2_ON1BDBNC;
- reg |= (pdata->b2on_flags & 0x3) << MC13783_POWER_CONTROL_2_ON2BDBNC;
-@@ -139,7 +135,7 @@ static int mc13783_pwrbutton_probe(struct platform_device *pdev)
- button_irq, "b1on", priv);
- if (err) {
- dev_dbg(&pdev->dev, "Can't request irq\n");
-- goto free_priv;
-+ goto free_mc13xxx_lock;
+- if (pdata->b1on_flags & MC13783_BUTTON_ENABLE) {
+- priv->keymap[0] = pdata->b1on_key;
+- if (pdata->b1on_key != KEY_RESERVED)
+- __set_bit(pdata->b1on_key, pwr->keybit);
++ if (pdata->b_on_flags[0] & MC13783_BUTTON_ENABLE) {
++ priv->keymap[0] = pdata->b_on_key[0];
++ if (pdata->b_on_key[0] != KEY_RESERVED)
++ __set_bit(pdata->b_on_key[0], pwr->keybit);
+
+- if (pdata->b1on_flags & MC13783_BUTTON_POL_INVERT)
++ if (pdata->b_on_flags[0] & MC13783_BUTTON_POL_INVERT)
+ priv->flags |= MC13783_PWRB_B1_POL_INVERT;
+
+- if (pdata->b1on_flags & MC13783_BUTTON_RESET_EN)
++ if (pdata->b_on_flags[0] & MC13783_BUTTON_RESET_EN)
+ reg |= MC13783_POWER_CONTROL_2_ON1BRSTEN;
+
+ err = mc13xxx_irq_request(mc13783, MC13783_IRQ_ONOFD1,
+@@ -155,15 +155,15 @@ static int mc13783_pwrbutton_probe(struct platform_device *pdev)
}
}
-@@ -187,7 +183,6 @@ static int mc13783_pwrbutton_probe(struct platform_device *pdev)
+- if (pdata->b2on_flags & MC13783_BUTTON_ENABLE) {
+- priv->keymap[1] = pdata->b2on_key;
+- if (pdata->b2on_key != KEY_RESERVED)
+- __set_bit(pdata->b2on_key, pwr->keybit);
++ if (pdata->b_on_flags[1] & MC13783_BUTTON_ENABLE) {
++ priv->keymap[1] = pdata->b_on_key[1];
++ if (pdata->b_on_key[1] != KEY_RESERVED)
++ __set_bit(pdata->b_on_key[1], pwr->keybit);
- pwr->name = "mc13783_pwrbutton";
- pwr->phys = "mc13783_pwrbutton/input0";
-- pwr->dev.parent = &pdev->dev;
+- if (pdata->b2on_flags & MC13783_BUTTON_POL_INVERT)
++ if (pdata->b_on_flags[1] & MC13783_BUTTON_POL_INVERT)
+ priv->flags |= MC13783_PWRB_B2_POL_INVERT;
- pwr->keycode = priv->keymap;
- pwr->keycodemax = ARRAY_SIZE(priv->keymap);
-@@ -218,12 +213,8 @@ static int mc13783_pwrbutton_probe(struct platform_device *pdev)
- if (pdata->b1on_flags & MC13783_BUTTON_ENABLE)
+- if (pdata->b2on_flags & MC13783_BUTTON_RESET_EN)
++ if (pdata->b_on_flags[1] & MC13783_BUTTON_RESET_EN)
+ reg |= MC13783_POWER_CONTROL_2_ON2BRSTEN;
+
+ err = mc13xxx_irq_request(mc13783, MC13783_IRQ_ONOFD2,
+@@ -174,15 +174,15 @@ static int mc13783_pwrbutton_probe(struct platform_device *pdev)
+ }
+ }
+
+- if (pdata->b3on_flags & MC13783_BUTTON_ENABLE) {
+- priv->keymap[2] = pdata->b3on_key;
+- if (pdata->b3on_key != KEY_RESERVED)
+- __set_bit(pdata->b3on_key, pwr->keybit);
++ if (pdata->b_on_flags[2] & MC13783_BUTTON_ENABLE) {
++ priv->keymap[2] = pdata->b_on_key[2];
++ if (pdata->b_on_key[2] != KEY_RESERVED)
++ __set_bit(pdata->b_on_key[2], pwr->keybit);
+
+- if (pdata->b3on_flags & MC13783_BUTTON_POL_INVERT)
++ if (pdata->b_on_flags[2] & MC13783_BUTTON_POL_INVERT)
+ priv->flags |= MC13783_PWRB_B3_POL_INVERT;
+
+- if (pdata->b3on_flags & MC13783_BUTTON_RESET_EN)
++ if (pdata->b_on_flags[2] & MC13783_BUTTON_RESET_EN)
+ reg |= MC13783_POWER_CONTROL_2_ON3BRSTEN;
+
+ err = mc13xxx_irq_request(mc13783, MC13783_IRQ_ONOFD3,
+@@ -218,15 +218,15 @@ static int mc13783_pwrbutton_probe(struct platform_device *pdev)
+ free_irq:
+ mc13xxx_lock(mc13783);
+
+- if (pdata->b3on_flags & MC13783_BUTTON_ENABLE)
++ if (pdata->b_on_flags[2] & MC13783_BUTTON_ENABLE)
+ mc13xxx_irq_free(mc13783, MC13783_IRQ_ONOFD3, priv);
+
+ free_irq_b2:
+- if (pdata->b2on_flags & MC13783_BUTTON_ENABLE)
++ if (pdata->b_on_flags[1] & MC13783_BUTTON_ENABLE)
+ mc13xxx_irq_free(mc13783, MC13783_IRQ_ONOFD2, priv);
+
+ free_irq_b1:
+- if (pdata->b1on_flags & MC13783_BUTTON_ENABLE)
++ if (pdata->b_on_flags[0] & MC13783_BUTTON_ENABLE)
mc13xxx_irq_free(mc13783, MC13783_IRQ_ONOFD1, priv);
--free_priv:
-+free_mc13xxx_lock:
- mc13xxx_unlock(mc13783);
-- kfree(priv);
--
--free_input_dev:
-- input_free_device(pwr);
+ free_mc13xxx_lock:
+@@ -244,11 +244,11 @@ static void mc13783_pwrbutton_remove(struct platform_device *pdev)
- return err;
- }
-@@ -245,9 +236,6 @@ static void mc13783_pwrbutton_remove(struct platform_device *pdev)
+ mc13xxx_lock(priv->mc13783);
+
+- if (pdata->b3on_flags & MC13783_BUTTON_ENABLE)
++ if (pdata->b_on_flags[2] & MC13783_BUTTON_ENABLE)
+ mc13xxx_irq_free(priv->mc13783, MC13783_IRQ_ONOFD3, priv);
+- if (pdata->b2on_flags & MC13783_BUTTON_ENABLE)
++ if (pdata->b_on_flags[1] & MC13783_BUTTON_ENABLE)
+ mc13xxx_irq_free(priv->mc13783, MC13783_IRQ_ONOFD2, priv);
+- if (pdata->b1on_flags & MC13783_BUTTON_ENABLE)
++ if (pdata->b_on_flags[0] & MC13783_BUTTON_ENABLE)
mc13xxx_irq_free(priv->mc13783, MC13783_IRQ_ONOFD1, priv);
mc13xxx_unlock(priv->mc13783);
--
-- input_unregister_device(priv->pwr);
-- kfree(priv);
- }
+diff --git a/include/linux/mfd/mc13xxx.h b/include/linux/mfd/mc13xxx.h
+index f372926d5894..0393083af28a 100644
+--- a/include/linux/mfd/mc13xxx.h
++++ b/include/linux/mfd/mc13xxx.h
+@@ -187,12 +187,8 @@ struct mc13xxx_leds_platform_data {
+ #define MC13783_BUTTON_RESET_EN (1 << 4)
- static struct platform_driver mc13783_pwrbutton_driver = {
+ struct mc13xxx_buttons_platform_data {
+- int b1on_flags;
+- unsigned short b1on_key;
+- int b2on_flags;
+- unsigned short b2on_key;
+- int b3on_flags;
+- unsigned short b3on_key;
++ int b_on_flags[3];
++ unsigned int b_on_key[3];
+ };
+
+ #define MC13783_TS_ATO_FIRST false
--
2.39.5