1 // SPDX-License-Identifier: GPL-2.0
3 // Copyright (C) 2018 BayLibre SAS
4 // Author: Bartosz Golaszewski <bgolaszewski@baylibre.com>
6 // ONKEY driver for MAXIM 77650/77651 charger/power-supply.
9 #include <linux/input.h>
10 #include <linux/interrupt.h>
11 #include <linux/mfd/max77650.h>
12 #include <linux/module.h>
13 #include <linux/platform_device.h>
14 #include <linux/regmap.h>
16 #define MAX77650_ONKEY_MODE_MASK BIT(3)
17 #define MAX77650_ONKEY_MODE_PUSH 0x00
18 #define MAX77650_ONKEY_MODE_SLIDE BIT(3)
20 struct max77650_onkey
{
21 struct input_dev
*input
;
25 static irqreturn_t
max77650_onkey_falling(int irq
, void *data
)
27 struct max77650_onkey
*onkey
= data
;
29 input_report_key(onkey
->input
, onkey
->code
, 0);
30 input_sync(onkey
->input
);
35 static irqreturn_t
max77650_onkey_rising(int irq
, void *data
)
37 struct max77650_onkey
*onkey
= data
;
39 input_report_key(onkey
->input
, onkey
->code
, 1);
40 input_sync(onkey
->input
);
45 static int max77650_onkey_probe(struct platform_device
*pdev
)
47 int irq_r
, irq_f
, error
, mode
;
48 struct max77650_onkey
*onkey
;
49 struct device
*dev
, *parent
;
56 map
= dev_get_regmap(parent
, NULL
);
60 onkey
= devm_kzalloc(dev
, sizeof(*onkey
), GFP_KERNEL
);
64 error
= device_property_read_u32(dev
, "linux,code", &onkey
->code
);
66 onkey
->code
= KEY_POWER
;
68 if (device_property_read_bool(dev
, "maxim,onkey-slide")) {
69 mode
= MAX77650_ONKEY_MODE_SLIDE
;
72 mode
= MAX77650_ONKEY_MODE_PUSH
;
76 error
= regmap_update_bits(map
, MAX77650_REG_CNFG_GLBL
,
77 MAX77650_ONKEY_MODE_MASK
, mode
);
81 irq_f
= platform_get_irq_byname(pdev
, "nEN_F");
85 irq_r
= platform_get_irq_byname(pdev
, "nEN_R");
89 onkey
->input
= devm_input_allocate_device(dev
);
93 onkey
->input
->name
= "max77650_onkey";
94 onkey
->input
->phys
= "max77650_onkey/input0";
95 onkey
->input
->id
.bustype
= BUS_I2C
;
96 input_set_capability(onkey
->input
, type
, onkey
->code
);
98 error
= devm_request_any_context_irq(dev
, irq_f
, max77650_onkey_falling
,
99 IRQF_ONESHOT
, "onkey-down", onkey
);
103 error
= devm_request_any_context_irq(dev
, irq_r
, max77650_onkey_rising
,
104 IRQF_ONESHOT
, "onkey-up", onkey
);
108 return input_register_device(onkey
->input
);
111 static const struct of_device_id max77650_onkey_of_match
[] = {
112 { .compatible
= "maxim,max77650-onkey" },
115 MODULE_DEVICE_TABLE(of
, max77650_onkey_of_match
);
117 static struct platform_driver max77650_onkey_driver
= {
119 .name
= "max77650-onkey",
120 .of_match_table
= max77650_onkey_of_match
,
122 .probe
= max77650_onkey_probe
,
124 module_platform_driver(max77650_onkey_driver
);
126 MODULE_DESCRIPTION("MAXIM 77650/77651 ONKEY driver");
127 MODULE_AUTHOR("Bartosz Golaszewski <bgolaszewski@baylibre.com>");
128 MODULE_LICENSE("GPL v2");
129 MODULE_ALIAS("platform:max77650-onkey");