input: mc13783: Prepare driver to support MC13892 and OF
Subsystems (7)
PATCH 1/3 input: mc13783: Prepare driver to support MC13892 and OF
This patch is a preparation mc13xxx powerbutton driver to support MC13892 and support the probe through the DT.
--- arch/arm/mach-imx/mach-mx31moboard.c | 9 +- drivers/input/misc/mc13783-pwrbutton.c | 361 ++++++++++++++------------------- include/linux/mfd/mc13xxx.h | 28 +-- 3 files changed, 173 insertions(+), 225 deletions(-)
arch/arm/mach-imx/mach-mx31moboard.c +6 -3
@@ -276,9 +276,12 @@ static struct mc13xxx_leds_platform_data moboard_leds = { };static struct mc13xxx_buttons_platform_data moboard_buttons = { - .b1on_flags =MC13783_BUTTON_DBNC_750MS |MC13783_BUTTON_ENABLE | -MC13783_BUTTON_POL_INVERT , - .b1on_key =KEY_POWER , + .buttons[0 ] = { + .keycode =KEY_POWER , + .flags =MC13XXX_BUTTON_ENABLE | +MC13XXX_BUTTON_DBNC_750MS | +MC13XXX_BUTTON_POL_INVERT , + }, };static struct mc13xxx_codec_platform_data moboard_codec = {
drivers/input/misc/mc13783-pwrbutton.c +152 -209
400 lines not on this page · raw message
include/linux/mfd/mc13xxx.h +15 -13
@@ -142,20 +142,22 @@ struct mc13xxx_leds_platform_data {u32 led_control[MAX_LED_CONTROL_REGS ]; }; +#define MAX13XXX_NUM_BUTTONS 3 + +struct mc13xxx_button { +u16 keycode; +unsigned int flags; +#define MC13XXX_BUTTON_DBNC_0MS 0 +#define MC13XXX_BUTTON_DBNC_30MS 1 +#define MC13XXX_BUTTON_DBNC_150MS 2 +#define MC13XXX_BUTTON_DBNC_750MS 3 +#define MC13XXX_BUTTON_ENABLE (1 << 2) +#define MC13XXX_BUTTON_POL_INVERT (1 << 3) +#define MC13XXX_BUTTON_RESET_EN (1 << 4) +}; +struct mc13xxx_buttons_platform_data { -#define MC13783_BUTTON_DBNC_0MS 0 -#define MC13783_BUTTON_DBNC_30MS 1 -#define MC13783_BUTTON_DBNC_150MS 2 -#define MC13783_BUTTON_DBNC_750MS 3 -#define MC13783_BUTTON_ENABLE (1 << 2) -#define MC13783_BUTTON_POL_INVERT (1 << 3) -#define MC13783_BUTTON_RESET_EN (1 << 4) -int b1on_flags; -unsigned short b1on_key; -int b2on_flags; -unsigned short b2on_key; -int b3on_flags; -unsigned short b3on_key; +struct mc13xxx_button buttons[MAX13XXX_NUM_BUTTONS ]; };struct mc13xxx_ts_platform_data {
Signature · 1 line
1.8.1.5
PATCH 2/3 input: mc13783: Add MC13892 support
--- drivers/input/misc/Kconfig | 6 +++--- drivers/input/misc/mc13783-pwrbutton.c | 10 +++++++++- include/linux/mfd/mc13892.h | 4 ++++ 3 files changed, 16 insertions(+), 4 deletions(-)
drivers/input/misc/Kconfig +3 -3
@@ -167,10 +167,10 @@ config INPUT_MAX8997_HAPTIC module will be called max8997-haptic. config INPUT_MC13783_PWRBUTTON - tristate "MC13783 ON buttons" - depends on MFD_MC13783 + tristate "MC13783/MC13892 ON buttons" + depends on MFD_MC13XXX help - Support the ON buttons of MC13783 PMIC as an input device + Support the ON buttons of MC13783/MC13892 PMIC as an input device reporting power button status. To compile this driver as a module, choose M here: the module
drivers/input/misc/mc13783-pwrbutton.c +9 -1
@@ -26,6 +26,7 @@#include <linux/input.h> #include <linux/platform_device.h> #include <linux/mfd/mc13783.h> +#include <linux/mfd/mc13892.h> struct mc13xxx_button_def {unsigned int irq;
@@ -194,8 +195,15 @@ static const struct mc13xxx_pwrb_devtype mc13783_pwrb_devtype = { .btn_def[2] = { MC13783_IRQ_ONOFD3, BIT(5) } }; +static const struct mc13xxx_pwrb_devtype mc13892_pwrb_devtype = { + .btn_def[0 ] = {MC13892_IRQ_ONOFD1 ,BIT (3 ) }, + .btn_def[1 ] = {MC13892_IRQ_ONOFD2 ,BIT (4 ) }, + .btn_def[2 ] = {MC13892_IRQ_ONOFD3 ,BIT (2 ) } +}; +static const struct platform_device_id mc13xxx_pwrbutton_id_table[] = { {"mc13783-pwrbutton" , (kernel_ulong_t)&mc13783_pwrb_devtype }, + {"mc13892-pwrbutton" , (kernel_ulong_t)&mc13892_pwrb_devtype }, { } };MODULE_DEVICE_TABLE (platform, mc13xxx_pwrbutton_id_table);
@@ -209,6 +217,6 @@ static struct platform_driver mc13xxx_pwrbutton_driver = { };module_platform_driver_probe (mc13xxx_pwrbutton_driver, mc13xxx_pwrbutton_probe); -MODULE_DESCRIPTION ("MC13783 Power Button" ); +MODULE_DESCRIPTION ("MC13XXX Power Button" );MODULE_LICENSE ("GPL v2" );MODULE_AUTHOR ("Philippe Retornaz" );
include/linux/mfd/mc13892.h +4 -0
@@ -36,4 +36,8 @@#define MC13892_PWGT2SPI 22#define MC13892_VCOINCELL 23 +#define MC13892_IRQ_ONOFD3 26 +#define MC13892_IRQ_ONOFD1 27 +#define MC13892_IRQ_ONOFD2 28 +#endif
Signature · 1 line
1.8.1.5
PATCH 3/3 input: mc13783: Add DT probe support
In reply to Alexander ShiyanPatch adds DT support for MC13783/MC13892 PMICs.
--- Documentation/devicetree/bindings/mfd/mc13xxx.txt | 12 +++++ drivers/input/misc/mc13783-pwrbutton.c | 59 ++++++++++++++++++----- 2 files changed, 58 insertions(+), 13 deletions(-)
Documentation/devicetree/bindings/mfd/mc13xxx.txt +12 -0
@@ -10,6 +10,11 @@ Optional properties: - fsl,mc13xxx-uses-touch : Indicate the touchscreen controller is being used Sub-nodes: +- buttons : Contain power button nodes. Each button should be declared as + "btn<num>" and contain code in "linux,code" property. Optional properties: + active-high : Change active button level from 0 to 1. + enable-reset: Performs hadware reset through PMIC. + debounce : Debounce value which will be taken from PMIC datasheet. - regulators : Contain the regulator nodes. The regulators are bound using their names as listed below with their registers and bits for enabling.
@@ -89,6 +94,13 @@ ecspi at 70010000 { /* ECSPI1 */ interrupt-parent = <&gpio0>; interrupts = <8>; + buttons { + btn1 { + linux,code = <0x1f>; + debounce = <1>; + }; + }; + regulators { sw1_reg: mc13892__sw1 { regulator-min-microvolt = <600000>;
drivers/input/misc/mc13783-pwrbutton.c +46 -13
94 lines not on this page · raw message
Signature · 1 line
1.8.1.5
Re: [PATCH 3/3] input: mc13783: Add DT probe support
Hi,
Quoted 13 lines · Alexander Shiyan
Patch adds DT support for MC13783/MC13892 PMICs.
Signed-off-by Alexander Shiyan <[email protected]>--- Documentation/devicetree/bindings/mfd/mc13xxx.txt | 12 +++++ drivers/input/misc/mc13783-pwrbutton.c | 59 ++++++++++++++++++----- 2 files changed, 58 insertions(+), 13 deletions(-)Documentation/devicetree/bindings/mfd/mc13xxx.txt +0
-0
Documentation/devicetree/bindings/mfd/mc13xxx.txt Optional properties: · line 14
Quoted 5 lines
Documentation/devicetree/bindings/mfd/mc13xxx.txt +2
-0@@ -10,6 +10,11 @@ Optional properties: - fsl,mc13xxx-uses-touch : Indicate the touchscreen controller is being used Sub-nodes: +- buttons : Contain power button nodes. Each button should be declared as + "btn<num>" and contain code in "linux,code" property. Optional properties:
gpio_keys also defines button node bindings. Why don't you use the same name format (button@<num>)?
Quoted 86 lines
Documentation/devicetree/bindings/mfd/mc13xxx.txt +10
-0+ active-high : Change active button level from 0 to 1. + enable-reset: Performs hadware reset through PMIC. + debounce : Debounce value which will be taken from PMIC datasheet. - regulators : Contain the regulator nodes. The regulators are bound using their names as listed below with their registers and bits for enabling.@@ -89,6 +94,13 @@ ecspi@70010000 { /* ECSPI1 */ interrupt-parent = <&gpio0>; interrupts = <8>; + buttons { + btn1 { + linux,code = <0x1f>; + debounce = <1>; + }; + }; + regulators { sw1_reg: mc13892__sw1 { regulator-min-microvolt = <600000>;drivers/input/misc/mc13783-pwrbutton.c +20
-13@@ -24,6 +24,7 @@#include <linux/kernel.h> #include <linux/errno.h> #include <linux/input.h> +#include <linux/of.h> #include <linux/platform_device.h> #include <linux/mfd/mc13783.h> #include <linux/mfd/mc13892.h> @@ -121,21 +122,28 @@ static int __init mc13xxx_pwrbutton_probe(struct platform_device *pdev)struct mc13xxx *mc13xxx =dev_get_drvdata (pdev->dev.parent);struct mc13xxx_pwrb_devtype *devtype = (struct mc13xxx_pwrb_devtype *)pdev->id_entry->driver_data; +struct device_node *parent, *child;struct mc13xxx_pwrb *priv;int i, reg =0 , ret = -EINVAL ; -if (!pdata) { +of_node_get (pdev->dev.parent->of_node); + parent =of_find_node_by_name (pdev->dev.parent->of_node,"buttons" ); +if (!pdata && !parent) {dev_err (&pdev->dev,"Missing platform data\n" );return -ENODEV ; } priv =devm_kzalloc (&pdev->dev,sizeof (*priv),GFP_KERNEL ); -if (!priv) -return -ENOMEM ; +if (!priv) { + ret = -ENOMEM ; + goto out_node_put; + } priv->input =devm_input_allocate_device (&pdev->dev); -if (!priv->input) -return -ENOMEM ; +if (!priv->input) { + ret = -ENOMEM ; + goto out_node_put; + } priv->mc13xxx = mc13xxx; priv->devtype = devtype;@@ -143,15 +151,36 @@ static int __init mc13xxx_pwrbutton_probe(struct platform_device *pdev)for (i =0 ; i <MAX13XXX_NUM_BUTTONS ; i++) {u16 code, invert, reset, debounce; +const __be32 *prop; +char childname[5 ]; -if (!(pdata->buttons[i].flags &MC13XXX_BUTTON_ENABLE )) -continue ; - code = pdata->buttons[i].keycode; - invert = !!(pdata->buttons[i].flags & -MC13XXX_BUTTON_POL_INVERT ); - reset = !!(pdata->buttons[i].flags & -MC13XXX_BUTTON_RESET_EN ); - debounce = pdata->buttons[i].flags; +if (parent) { +sprintf (childname,"btn%i" , i +1 ); + child =of_get_child_by_name (parent, childname); +if (!child) +continue ;
drivers/input/misc/mc13783-pwrbutton.c static int __init mc13xxx_pwrbutton_probe(struct platform_device *pdev) · line 171
Quoted 10 lines
drivers/input/misc/mc13783-pwrbutton.c +10
-0+ prop =of_get_property (child,"linux,code" ,NULL ); +if (prop) + code =be32_to_cpu (*prop) &0xffff ; +else { +dev_err (&pdev->dev, +"Button %i: Missing key code\n" , i +1 ); +continue ; + } + invert = !!of_get_property (child,"active-high" ,NULL ); + reset = !!of_get_property (child,"enable-reset" ,NULL );
You can use of_property_read_bool here.
Regards,
Markus
Quoted 30 lines
drivers/input/misc/mc13783-pwrbutton.c +16
-0+ prop =of_get_property (child,"debounce" ,NULL ); + debounce = prop ?be32_to_cpu (*prop) :0 ; + }else { +if (!(pdata->buttons[i].flags &MC13XXX_BUTTON_ENABLE )) +continue ; + code = pdata->buttons[i].keycode; + invert = !!(pdata->buttons[i].flags & +MC13XXX_BUTTON_POL_INVERT ); + reset = !!(pdata->buttons[i].flags & +MC13XXX_BUTTON_RESET_EN ); + debounce = pdata->buttons[i].flags; + } priv->btn_code[i] = code;if (code !=KEY_RESERVED )@@ -186,6 +215,10 @@ static int __init mc13xxx_pwrbutton_probe(struct platform_device *pdev)if (ret)dev_err (&pdev->dev,"Can't register input device: %i\n" , ret); +out_node_put: +if (parent) +of_node_put (parent); +return ret; }Signature · 1 line
1.8.1.5