Commit 461484c27e1d72980eae4826eb9788a156cdf00e
Committed by
Tom Rini
1 parent
d6a2042dbc
Exists in
v2017.01-smarct4x
and in
29 other branches
input: TWL6030 input support for power button, USB and charger
This adds support for detecting a few inputs exported by the TWL6030. Currently-supported inputs are the power button, USB and charger presence. Signed-off-by: Paul Kocialkowski <contact@paulk.fr>
Showing 3 changed files with 70 additions and 0 deletions Side-by-side Diff
drivers/input/Makefile
... | ... | @@ -10,6 +10,7 @@ |
10 | 10 | obj-$(CONFIG_I8042_KEYB) += i8042.o |
11 | 11 | obj-$(CONFIG_TEGRA_KEYBOARD) += tegra-kbc.o |
12 | 12 | obj-$(CONFIG_TWL4030_INPUT) += twl4030.o |
13 | +obj-$(CONFIG_TWL6030_INPUT) += twl6030.o | |
13 | 14 | obj-$(CONFIG_CROS_EC_KEYB) += cros_ec_keyb.o |
14 | 15 | ifdef CONFIG_PS2KBD |
15 | 16 | obj-y += keyboard.o pc_keyb.o |
drivers/input/twl6030.c
1 | +/* | |
2 | + * TWL6030 input | |
3 | + * | |
4 | + * Copyright (C) 2016 Paul Kocialkowski <contact@paulk.fr> | |
5 | + * | |
6 | + * SPDX-License-Identifier: GPL-2.0+ | |
7 | + */ | |
8 | + | |
9 | +#include <twl6030.h> | |
10 | + | |
11 | +int twl6030_input_power_button(void) | |
12 | +{ | |
13 | + u8 value; | |
14 | + | |
15 | + twl6030_i2c_read_u8(TWL6030_CHIP_PM, TWL6030_STS_HW_CONDITIONS, &value); | |
16 | + | |
17 | + /* Power button is active low. */ | |
18 | + if (value & TWL6030_STS_HW_CONDITIONS_PWRON) | |
19 | + return 0; | |
20 | + | |
21 | + return 1; | |
22 | +} | |
23 | + | |
24 | +int twl6030_input_charger(void) | |
25 | +{ | |
26 | + u8 value; | |
27 | + | |
28 | + twl6030_i2c_read_u8(TWL6030_CHIP_CHARGER, TWL6030_CONTROLLER_STAT1, | |
29 | + &value); | |
30 | + | |
31 | + if (value & TWL6030_CONTROLLER_STAT1_VAC_DET) | |
32 | + return 1; | |
33 | + | |
34 | + return 0; | |
35 | +} | |
36 | + | |
37 | +int twl6030_input_usb(void) | |
38 | +{ | |
39 | + u8 value; | |
40 | + | |
41 | + twl6030_i2c_read_u8(TWL6030_CHIP_CHARGER, TWL6030_CONTROLLER_STAT1, | |
42 | + &value); | |
43 | + | |
44 | + if (value & TWL6030_CONTROLLER_STAT1_VBUS_DET) | |
45 | + return 1; | |
46 | + | |
47 | + return 0; | |
48 | +} |
include/twl6030.h
... | ... | @@ -20,6 +20,10 @@ |
20 | 20 | #define TWL6030_CHIP_PWM 0x49 |
21 | 21 | |
22 | 22 | /* Slave Address 0x48 */ |
23 | +#define TWL6030_STS_HW_CONDITIONS 0x21 | |
24 | + | |
25 | +#define TWL6030_STS_HW_CONDITIONS_PWRON (1 << 0) | |
26 | + | |
23 | 27 | #define TWL6030_PHOENIX_DEV_ON 0x25 |
24 | 28 | |
25 | 29 | #define TWL6030_PHOENIX_APP_DEVOFF (1 << 0) |
... | ... | @@ -59,6 +63,11 @@ |
59 | 63 | |
60 | 64 | /* Slave Address 0x49 */ |
61 | 65 | |
66 | +#define TWL6030_CONTROLLER_STAT1 0xE3 | |
67 | + | |
68 | +#define TWL6030_CONTROLLER_STAT1_VAC_DET (1 << 3) | |
69 | +#define TWL6030_CONTROLLER_STAT1_VBUS_DET (1 << 2) | |
70 | + | |
62 | 71 | /* Battery CHARGER REGISTERS */ |
63 | 72 | #define CONTROLLER_INT_MASK 0xE0 |
64 | 73 | #define CONTROLLER_CTRL1 0xE1 |
... | ... | @@ -188,6 +197,10 @@ |
188 | 197 | return i2c_read(chip_no, reg, 1, val, 1); |
189 | 198 | } |
190 | 199 | |
200 | +/* | |
201 | + * Power | |
202 | + */ | |
203 | + | |
191 | 204 | void twl6030_power_off(void); |
192 | 205 | void twl6030_init_battery_charging(void); |
193 | 206 | void twl6030_usb_device_settings(void); |
... | ... | @@ -196,6 +209,14 @@ |
196 | 209 | int twl6030_get_battery_voltage(void); |
197 | 210 | int twl6030_get_battery_current(void); |
198 | 211 | void twl6030_power_mmc_init(int dev_index); |
212 | + | |
213 | +/* | |
214 | + * Input | |
215 | + */ | |
216 | + | |
217 | +int twl6030_input_power_button(void); | |
218 | +int twl6030_input_charger(void); | |
219 | +int twl6030_input_usb(void); | |
199 | 220 | |
200 | 221 | #endif /* TWL6030_H */ |