1 // SPDX-License-Identifier: GPL-2.0+
5 * Copyright (C) 2015 Paul Kocialkowski <contact@paulk.fr>
10 int twl4030_input_power_button(void)
14 twl4030_i2c_read_u8(TWL4030_CHIP_PM_MASTER,
15 TWL4030_PM_MASTER_STS_HW_CONDITIONS, &data);
17 if (data & TWL4030_PM_MASTER_STS_HW_CONDITIONS_PWON)
23 int twl4030_input_charger(void)
27 twl4030_i2c_read_u8(TWL4030_CHIP_PM_MASTER,
28 TWL4030_PM_MASTER_STS_HW_CONDITIONS, &data);
30 if (data & TWL4030_PM_MASTER_STS_HW_CONDITIONS_CHG)
36 int twl4030_input_usb(void)
40 twl4030_i2c_read_u8(TWL4030_CHIP_PM_MASTER,
41 TWL4030_PM_MASTER_STS_HW_CONDITIONS, &data);
43 if (data & TWL4030_PM_MASTER_STS_HW_CONDITIONS_USB ||
44 data & TWL4030_PM_MASTER_STS_HW_CONDITIONS_VBUS)
50 int twl4030_keypad_scan(unsigned char *matrix)
55 twl4030_i2c_read_u8(TWL4030_CHIP_KEYPAD,
56 TWL4030_KEYPAD_KEYP_CTRL_REG, &data);
58 data |= TWL4030_KEYPAD_CTRL_SOFT_NRST | TWL4030_KEYPAD_CTRL_KBD_ON;
59 data &= ~TWL4030_KEYPAD_CTRL_SOFTMODEN;
61 twl4030_i2c_write_u8(TWL4030_CHIP_KEYPAD,
62 TWL4030_KEYPAD_KEYP_CTRL_REG, data);
64 for (c = 0; c < 8; c++) {
65 data = 0xff & ~(1 << c);
66 twl4030_i2c_write_u8(TWL4030_CHIP_KEYPAD,
67 TWL4030_KEYPAD_KBC_REG, data);
70 twl4030_i2c_read_u8(TWL4030_CHIP_KEYPAD,
71 TWL4030_KEYPAD_KBR_REG, &data);
73 for (r = 0; r < 8; r++)
74 matrix[c * 8 + r] = !(data & (1 << r));
77 data = 0xff & ~(TWL4030_KEYPAD_CTRL_SOFT_NRST);
78 twl4030_i2c_write_u8(TWL4030_CHIP_KEYPAD,
79 TWL4030_KEYPAD_KEYP_CTRL_REG, data);
84 int twl4030_keypad_key(unsigned char *matrix, u8 c, u8 r)
86 return matrix[c * 8 + r];