1fda8d26eSThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-only */ 29d2e1736SMichael Hennerich /* 33f48e735SMichael Hennerich * Analog Devices ADP5589/ADP5585 I/O Expander and QWERTY Keypad Controller 49d2e1736SMichael Hennerich * 59d2e1736SMichael Hennerich * Copyright 2010-2011 Analog Devices Inc. 69d2e1736SMichael Hennerich */ 79d2e1736SMichael Hennerich 89d2e1736SMichael Hennerich #ifndef _ADP5589_H 99d2e1736SMichael Hennerich #define _ADP5589_H 109d2e1736SMichael Hennerich 113f48e735SMichael Hennerich /* 123f48e735SMichael Hennerich * ADP5589 specific GPI and Keymap defines 133f48e735SMichael Hennerich */ 149d2e1736SMichael Hennerich 159d2e1736SMichael Hennerich #define ADP5589_KEYMAPSIZE 88 169d2e1736SMichael Hennerich 179d2e1736SMichael Hennerich #define ADP5589_GPI_PIN_ROW0 97 189d2e1736SMichael Hennerich #define ADP5589_GPI_PIN_ROW1 98 199d2e1736SMichael Hennerich #define ADP5589_GPI_PIN_ROW2 99 209d2e1736SMichael Hennerich #define ADP5589_GPI_PIN_ROW3 100 219d2e1736SMichael Hennerich #define ADP5589_GPI_PIN_ROW4 101 229d2e1736SMichael Hennerich #define ADP5589_GPI_PIN_ROW5 102 239d2e1736SMichael Hennerich #define ADP5589_GPI_PIN_ROW6 103 249d2e1736SMichael Hennerich #define ADP5589_GPI_PIN_ROW7 104 259d2e1736SMichael Hennerich #define ADP5589_GPI_PIN_COL0 105 269d2e1736SMichael Hennerich #define ADP5589_GPI_PIN_COL1 106 279d2e1736SMichael Hennerich #define ADP5589_GPI_PIN_COL2 107 289d2e1736SMichael Hennerich #define ADP5589_GPI_PIN_COL3 108 299d2e1736SMichael Hennerich #define ADP5589_GPI_PIN_COL4 109 309d2e1736SMichael Hennerich #define ADP5589_GPI_PIN_COL5 110 319d2e1736SMichael Hennerich #define ADP5589_GPI_PIN_COL6 111 329d2e1736SMichael Hennerich #define ADP5589_GPI_PIN_COL7 112 339d2e1736SMichael Hennerich #define ADP5589_GPI_PIN_COL8 113 349d2e1736SMichael Hennerich #define ADP5589_GPI_PIN_COL9 114 359d2e1736SMichael Hennerich #define ADP5589_GPI_PIN_COL10 115 369d2e1736SMichael Hennerich #define GPI_LOGIC1 116 379d2e1736SMichael Hennerich #define GPI_LOGIC2 117 389d2e1736SMichael Hennerich 399d2e1736SMichael Hennerich #define ADP5589_GPI_PIN_ROW_BASE ADP5589_GPI_PIN_ROW0 409d2e1736SMichael Hennerich #define ADP5589_GPI_PIN_ROW_END ADP5589_GPI_PIN_ROW7 419d2e1736SMichael Hennerich #define ADP5589_GPI_PIN_COL_BASE ADP5589_GPI_PIN_COL0 429d2e1736SMichael Hennerich #define ADP5589_GPI_PIN_COL_END ADP5589_GPI_PIN_COL10 439d2e1736SMichael Hennerich 449d2e1736SMichael Hennerich #define ADP5589_GPI_PIN_BASE ADP5589_GPI_PIN_ROW_BASE 459d2e1736SMichael Hennerich #define ADP5589_GPI_PIN_END ADP5589_GPI_PIN_COL_END 469d2e1736SMichael Hennerich 479d2e1736SMichael Hennerich #define ADP5589_GPIMAPSIZE_MAX (ADP5589_GPI_PIN_END - ADP5589_GPI_PIN_BASE + 1) 489d2e1736SMichael Hennerich 493f48e735SMichael Hennerich /* 503f48e735SMichael Hennerich * ADP5585 specific GPI and Keymap defines 513f48e735SMichael Hennerich */ 523f48e735SMichael Hennerich 533f48e735SMichael Hennerich #define ADP5585_KEYMAPSIZE 30 543f48e735SMichael Hennerich 553f48e735SMichael Hennerich #define ADP5585_GPI_PIN_ROW0 37 563f48e735SMichael Hennerich #define ADP5585_GPI_PIN_ROW1 38 573f48e735SMichael Hennerich #define ADP5585_GPI_PIN_ROW2 39 583f48e735SMichael Hennerich #define ADP5585_GPI_PIN_ROW3 40 593f48e735SMichael Hennerich #define ADP5585_GPI_PIN_ROW4 41 603f48e735SMichael Hennerich #define ADP5585_GPI_PIN_ROW5 42 613f48e735SMichael Hennerich #define ADP5585_GPI_PIN_COL0 43 623f48e735SMichael Hennerich #define ADP5585_GPI_PIN_COL1 44 633f48e735SMichael Hennerich #define ADP5585_GPI_PIN_COL2 45 643f48e735SMichael Hennerich #define ADP5585_GPI_PIN_COL3 46 653f48e735SMichael Hennerich #define ADP5585_GPI_PIN_COL4 47 663f48e735SMichael Hennerich #define GPI_LOGIC 48 673f48e735SMichael Hennerich 683f48e735SMichael Hennerich #define ADP5585_GPI_PIN_ROW_BASE ADP5585_GPI_PIN_ROW0 693f48e735SMichael Hennerich #define ADP5585_GPI_PIN_ROW_END ADP5585_GPI_PIN_ROW5 703f48e735SMichael Hennerich #define ADP5585_GPI_PIN_COL_BASE ADP5585_GPI_PIN_COL0 713f48e735SMichael Hennerich #define ADP5585_GPI_PIN_COL_END ADP5585_GPI_PIN_COL4 723f48e735SMichael Hennerich 733f48e735SMichael Hennerich #define ADP5585_GPI_PIN_BASE ADP5585_GPI_PIN_ROW_BASE 743f48e735SMichael Hennerich #define ADP5585_GPI_PIN_END ADP5585_GPI_PIN_COL_END 753f48e735SMichael Hennerich 763f48e735SMichael Hennerich #define ADP5585_GPIMAPSIZE_MAX (ADP5585_GPI_PIN_END - ADP5585_GPI_PIN_BASE + 1) 773f48e735SMichael Hennerich 789d2e1736SMichael Hennerich struct adp5589_gpi_map { 799d2e1736SMichael Hennerich unsigned short pin; 809d2e1736SMichael Hennerich unsigned short sw_evt; 819d2e1736SMichael Hennerich }; 829d2e1736SMichael Hennerich 839d2e1736SMichael Hennerich /* scan_cycle_time */ 849d2e1736SMichael Hennerich #define ADP5589_SCAN_CYCLE_10ms 0 859d2e1736SMichael Hennerich #define ADP5589_SCAN_CYCLE_20ms 1 869d2e1736SMichael Hennerich #define ADP5589_SCAN_CYCLE_30ms 2 879d2e1736SMichael Hennerich #define ADP5589_SCAN_CYCLE_40ms 3 889d2e1736SMichael Hennerich 899d2e1736SMichael Hennerich /* RESET_CFG */ 909d2e1736SMichael Hennerich #define RESET_PULSE_WIDTH_500us 0 919d2e1736SMichael Hennerich #define RESET_PULSE_WIDTH_1ms 1 929d2e1736SMichael Hennerich #define RESET_PULSE_WIDTH_2ms 2 939d2e1736SMichael Hennerich #define RESET_PULSE_WIDTH_10ms 3 949d2e1736SMichael Hennerich 959d2e1736SMichael Hennerich #define RESET_TRIG_TIME_0ms (0 << 2) 969d2e1736SMichael Hennerich #define RESET_TRIG_TIME_1000ms (1 << 2) 979d2e1736SMichael Hennerich #define RESET_TRIG_TIME_1500ms (2 << 2) 989d2e1736SMichael Hennerich #define RESET_TRIG_TIME_2000ms (3 << 2) 999d2e1736SMichael Hennerich #define RESET_TRIG_TIME_2500ms (4 << 2) 1009d2e1736SMichael Hennerich #define RESET_TRIG_TIME_3000ms (5 << 2) 1019d2e1736SMichael Hennerich #define RESET_TRIG_TIME_3500ms (6 << 2) 1029d2e1736SMichael Hennerich #define RESET_TRIG_TIME_4000ms (7 << 2) 1039d2e1736SMichael Hennerich 1049d2e1736SMichael Hennerich #define RESET_PASSTHRU_EN (1 << 5) 1059d2e1736SMichael Hennerich #define RESET1_POL_HIGH (1 << 6) 1069d2e1736SMichael Hennerich #define RESET1_POL_LOW (0 << 6) 1079d2e1736SMichael Hennerich #define RESET2_POL_HIGH (1 << 7) 1089d2e1736SMichael Hennerich #define RESET2_POL_LOW (0 << 7) 1099d2e1736SMichael Hennerich 1103f48e735SMichael Hennerich /* ADP5589 Mask Bits: 1119d2e1736SMichael Hennerich * C C C C C C C C C C C | R R R R R R R R 1129d2e1736SMichael Hennerich * 1 9 8 7 6 5 4 3 2 1 0 | 7 6 5 4 3 2 1 0 1139d2e1736SMichael Hennerich * 0 1149d2e1736SMichael Hennerich * ---------------- BIT ------------------ 1159d2e1736SMichael Hennerich * 1 1 1 1 1 1 1 1 1 0 0 | 0 0 0 0 0 0 0 0 1169d2e1736SMichael Hennerich * 8 7 6 5 4 3 2 1 0 9 8 | 7 6 5 4 3 2 1 0 1179d2e1736SMichael Hennerich */ 1189d2e1736SMichael Hennerich 1199d2e1736SMichael Hennerich #define ADP_ROW(x) (1 << (x)) 1209d2e1736SMichael Hennerich #define ADP_COL(x) (1 << (x + 8)) 1213f48e735SMichael Hennerich #define ADP5589_ROW_MASK 0xFF 1223f48e735SMichael Hennerich #define ADP5589_COL_MASK 0xFF 1233f48e735SMichael Hennerich #define ADP5589_COL_SHIFT 8 1243f48e735SMichael Hennerich #define ADP5589_MAX_ROW_NUM 7 1253f48e735SMichael Hennerich #define ADP5589_MAX_COL_NUM 10 1263f48e735SMichael Hennerich 1273f48e735SMichael Hennerich /* ADP5585 Mask Bits: 1283f48e735SMichael Hennerich * C C C C C | R R R R R R 1293f48e735SMichael Hennerich * 4 3 2 1 0 | 5 4 3 2 1 0 1303f48e735SMichael Hennerich * 1313f48e735SMichael Hennerich * ---- BIT -- ----------- 1323f48e735SMichael Hennerich * 1 0 0 0 0 | 0 0 0 0 0 0 1333f48e735SMichael Hennerich * 0 9 8 7 6 | 5 4 3 2 1 0 1343f48e735SMichael Hennerich */ 1353f48e735SMichael Hennerich 1363f48e735SMichael Hennerich #define ADP5585_ROW_MASK 0x3F 1373f48e735SMichael Hennerich #define ADP5585_COL_MASK 0x1F 1383f48e735SMichael Hennerich #define ADP5585_ROW_SHIFT 0 1393f48e735SMichael Hennerich #define ADP5585_COL_SHIFT 6 1403f48e735SMichael Hennerich #define ADP5585_MAX_ROW_NUM 5 1413f48e735SMichael Hennerich #define ADP5585_MAX_COL_NUM 4 1423f48e735SMichael Hennerich 1433f48e735SMichael Hennerich #define ADP5585_ROW(x) (1 << ((x) & ADP5585_ROW_MASK)) 1443f48e735SMichael Hennerich #define ADP5585_COL(x) (1 << (((x) & ADP5585_COL_MASK) + ADP5585_COL_SHIFT)) 1453f48e735SMichael Hennerich 1463f48e735SMichael Hennerich /* Put one of these structures in i2c_board_info platform_data */ 1479d2e1736SMichael Hennerich 1489d2e1736SMichael Hennerich struct adp5589_kpad_platform_data { 1499d2e1736SMichael Hennerich unsigned keypad_en_mask; /* Keypad (Rows/Columns) enable mask */ 1509d2e1736SMichael Hennerich const unsigned short *keymap; /* Pointer to keymap */ 1519d2e1736SMichael Hennerich unsigned short keymapsize; /* Keymap size */ 1529d2e1736SMichael Hennerich bool repeat; /* Enable key repeat */ 1533f48e735SMichael Hennerich bool en_keylock; /* Enable key lock feature (ADP5589 only)*/ 1543f48e735SMichael Hennerich unsigned char unlock_key1; /* Unlock Key 1 (ADP5589 only) */ 1553f48e735SMichael Hennerich unsigned char unlock_key2; /* Unlock Key 2 (ADP5589 only) */ 1563f48e735SMichael Hennerich unsigned char unlock_timer; /* Time in seconds [0..7] between the two unlock keys 0=disable (ADP5589 only) */ 1579d2e1736SMichael Hennerich unsigned char scan_cycle_time; /* Time between consecutive scan cycles */ 1589d2e1736SMichael Hennerich unsigned char reset_cfg; /* Reset config */ 1599d2e1736SMichael Hennerich unsigned short reset1_key_1; /* Reset Key 1 */ 1609d2e1736SMichael Hennerich unsigned short reset1_key_2; /* Reset Key 2 */ 1619d2e1736SMichael Hennerich unsigned short reset1_key_3; /* Reset Key 3 */ 1629d2e1736SMichael Hennerich unsigned short reset2_key_1; /* Reset Key 1 */ 1639d2e1736SMichael Hennerich unsigned short reset2_key_2; /* Reset Key 2 */ 1649d2e1736SMichael Hennerich unsigned debounce_dis_mask; /* Disable debounce mask */ 1659d2e1736SMichael Hennerich unsigned pull_dis_mask; /* Disable all pull resistors mask */ 1669d2e1736SMichael Hennerich unsigned pullup_en_100k; /* Pull-Up 100k Enable Mask */ 1679d2e1736SMichael Hennerich unsigned pullup_en_300k; /* Pull-Up 300k Enable Mask */ 1689d2e1736SMichael Hennerich unsigned pulldown_en_300k; /* Pull-Down 300k Enable Mask */ 1699d2e1736SMichael Hennerich const struct adp5589_gpi_map *gpimap; 1709d2e1736SMichael Hennerich unsigned short gpimapsize; 1719d2e1736SMichael Hennerich const struct adp5589_gpio_platform_data *gpio_data; 1729d2e1736SMichael Hennerich }; 1739d2e1736SMichael Hennerich 1749d2e1736SMichael Hennerich struct i2c_client; /* forward declaration */ 1759d2e1736SMichael Hennerich 1769d2e1736SMichael Hennerich struct adp5589_gpio_platform_data { 1779d2e1736SMichael Hennerich int gpio_start; /* GPIO Chip base # */ 1789d2e1736SMichael Hennerich }; 1799d2e1736SMichael Hennerich 1809d2e1736SMichael Hennerich #endif 181