Merge https://gitlab.denx.de/u-boot/custodians/u-boot-mpc85xx
[oweals/u-boot.git] / drivers / input / twl6030.c
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * TWL6030 input
4  *
5  * Copyright (C) 2016 Paul Kocialkowski <contact@paulk.fr>
6  */
7
8 #include <twl6030.h>
9
10 int twl6030_input_power_button(void)
11 {
12         u8 value;
13
14         twl6030_i2c_read_u8(TWL6030_CHIP_PM, TWL6030_STS_HW_CONDITIONS, &value);
15
16         /* Power button is active low. */
17         if (value & TWL6030_STS_HW_CONDITIONS_PWRON)
18                 return 0;
19
20         return 1;
21 }
22
23 int twl6030_input_charger(void)
24 {
25         u8 value;
26
27         twl6030_i2c_read_u8(TWL6030_CHIP_CHARGER, TWL6030_CONTROLLER_STAT1,
28                 &value);
29
30         if (value & TWL6030_CONTROLLER_STAT1_VAC_DET)
31                 return 1;
32
33         return 0;
34 }
35
36 int twl6030_input_usb(void)
37 {
38         u8 value;
39
40         twl6030_i2c_read_u8(TWL6030_CHIP_CHARGER, TWL6030_CONTROLLER_STAT1,
41                 &value);
42
43         if (value & TWL6030_CONTROLLER_STAT1_VBUS_DET)
44                 return 1;
45
46         return 0;
47 }