blob: dc5868c0ab9ac446ccb50cb87dbd9bf58074081d [file] [log] [blame]
Paul Kocialkowskif266dae2015-07-20 15:17:08 +02001/*
2 * TWL4030 input
3 *
4 * Copyright (C) 2015 Paul Kocialkowski <contact@paulk.fr>
5 *
6 * SPDX-License-Identifier: GPL-2.0+
7 */
8
9#include <twl4030.h>
10
11int twl4030_input_power_button(void)
12{
13 u8 data;
14
15 twl4030_i2c_read_u8(TWL4030_CHIP_PM_MASTER,
16 TWL4030_PM_MASTER_STS_HW_CONDITIONS, &data);
17
18 if (data & TWL4030_PM_MASTER_STS_HW_CONDITIONS_PWON)
19 return 1;
20
21 return 0;
22}
23
24int twl4030_input_charger(void)
25{
26 u8 data;
27
28 twl4030_i2c_read_u8(TWL4030_CHIP_PM_MASTER,
29 TWL4030_PM_MASTER_STS_HW_CONDITIONS, &data);
30
31 if (data & TWL4030_PM_MASTER_STS_HW_CONDITIONS_CHG)
32 return 1;
33
34 return 0;
35}
36
37int twl4030_input_usb(void)
38{
39 u8 data;
40
41 twl4030_i2c_read_u8(TWL4030_CHIP_PM_MASTER,
42 TWL4030_PM_MASTER_STS_HW_CONDITIONS, &data);
43
44 if (data & TWL4030_PM_MASTER_STS_HW_CONDITIONS_USB ||
45 data & TWL4030_PM_MASTER_STS_HW_CONDITIONS_VBUS)
46 return 1;
47
48 return 0;
49}
Paul Kocialkowski9397fbe2015-07-20 15:17:09 +020050
51int twl4030_keypad_scan(unsigned char *matrix)
52{
53 u8 data;
54 u8 c, r;
55
56 twl4030_i2c_read_u8(TWL4030_CHIP_KEYPAD,
57 TWL4030_KEYPAD_KEYP_CTRL_REG, &data);
58
59 data |= TWL4030_KEYPAD_CTRL_SOFT_NRST | TWL4030_KEYPAD_CTRL_KBD_ON;
60 data &= ~TWL4030_KEYPAD_CTRL_SOFTMODEN;
61
62 twl4030_i2c_write_u8(TWL4030_CHIP_KEYPAD,
63 TWL4030_KEYPAD_KEYP_CTRL_REG, data);
64
65 for (c = 0; c < 8; c++) {
66 data = 0xff & ~(1 << c);
67 twl4030_i2c_write_u8(TWL4030_CHIP_KEYPAD,
68 TWL4030_KEYPAD_KBC_REG, data);
69
70 data = 0xff;
71 twl4030_i2c_read_u8(TWL4030_CHIP_KEYPAD,
72 TWL4030_KEYPAD_KBR_REG, &data);
73
74 for (r = 0; r < 8; r++)
75 matrix[c * 8 + r] = !(data & (1 << r));
76 }
77
78 data = 0xff & ~(TWL4030_KEYPAD_CTRL_SOFT_NRST);
79 twl4030_i2c_write_u8(TWL4030_CHIP_KEYPAD,
80 TWL4030_KEYPAD_KEYP_CTRL_REG, data);
81
82 return 0;
83}
84
85int twl4030_keypad_key(unsigned char *matrix, u8 c, u8 r)
86{
87 return matrix[c * 8 + r];
88}