18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */ 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * Analog Devices ADP5588 I/O Expander and QWERTY Keypad Controller 48c2ecf20Sopenharmony_ci * 58c2ecf20Sopenharmony_ci * Copyright 2009-2010 Analog Devices Inc. 68c2ecf20Sopenharmony_ci */ 78c2ecf20Sopenharmony_ci 88c2ecf20Sopenharmony_ci#ifndef _ADP5588_H 98c2ecf20Sopenharmony_ci#define _ADP5588_H 108c2ecf20Sopenharmony_ci 118c2ecf20Sopenharmony_ci#define DEV_ID 0x00 /* Device ID */ 128c2ecf20Sopenharmony_ci#define CFG 0x01 /* Configuration Register1 */ 138c2ecf20Sopenharmony_ci#define INT_STAT 0x02 /* Interrupt Status Register */ 148c2ecf20Sopenharmony_ci#define KEY_LCK_EC_STAT 0x03 /* Key Lock and Event Counter Register */ 158c2ecf20Sopenharmony_ci#define Key_EVENTA 0x04 /* Key Event Register A */ 168c2ecf20Sopenharmony_ci#define Key_EVENTB 0x05 /* Key Event Register B */ 178c2ecf20Sopenharmony_ci#define Key_EVENTC 0x06 /* Key Event Register C */ 188c2ecf20Sopenharmony_ci#define Key_EVENTD 0x07 /* Key Event Register D */ 198c2ecf20Sopenharmony_ci#define Key_EVENTE 0x08 /* Key Event Register E */ 208c2ecf20Sopenharmony_ci#define Key_EVENTF 0x09 /* Key Event Register F */ 218c2ecf20Sopenharmony_ci#define Key_EVENTG 0x0A /* Key Event Register G */ 228c2ecf20Sopenharmony_ci#define Key_EVENTH 0x0B /* Key Event Register H */ 238c2ecf20Sopenharmony_ci#define Key_EVENTI 0x0C /* Key Event Register I */ 248c2ecf20Sopenharmony_ci#define Key_EVENTJ 0x0D /* Key Event Register J */ 258c2ecf20Sopenharmony_ci#define KP_LCK_TMR 0x0E /* Keypad Lock1 to Lock2 Timer */ 268c2ecf20Sopenharmony_ci#define UNLOCK1 0x0F /* Unlock Key1 */ 278c2ecf20Sopenharmony_ci#define UNLOCK2 0x10 /* Unlock Key2 */ 288c2ecf20Sopenharmony_ci#define GPIO_INT_STAT1 0x11 /* GPIO Interrupt Status */ 298c2ecf20Sopenharmony_ci#define GPIO_INT_STAT2 0x12 /* GPIO Interrupt Status */ 308c2ecf20Sopenharmony_ci#define GPIO_INT_STAT3 0x13 /* GPIO Interrupt Status */ 318c2ecf20Sopenharmony_ci#define GPIO_DAT_STAT1 0x14 /* GPIO Data Status, Read twice to clear */ 328c2ecf20Sopenharmony_ci#define GPIO_DAT_STAT2 0x15 /* GPIO Data Status, Read twice to clear */ 338c2ecf20Sopenharmony_ci#define GPIO_DAT_STAT3 0x16 /* GPIO Data Status, Read twice to clear */ 348c2ecf20Sopenharmony_ci#define GPIO_DAT_OUT1 0x17 /* GPIO DATA OUT */ 358c2ecf20Sopenharmony_ci#define GPIO_DAT_OUT2 0x18 /* GPIO DATA OUT */ 368c2ecf20Sopenharmony_ci#define GPIO_DAT_OUT3 0x19 /* GPIO DATA OUT */ 378c2ecf20Sopenharmony_ci#define GPIO_INT_EN1 0x1A /* GPIO Interrupt Enable */ 388c2ecf20Sopenharmony_ci#define GPIO_INT_EN2 0x1B /* GPIO Interrupt Enable */ 398c2ecf20Sopenharmony_ci#define GPIO_INT_EN3 0x1C /* GPIO Interrupt Enable */ 408c2ecf20Sopenharmony_ci#define KP_GPIO1 0x1D /* Keypad or GPIO Selection */ 418c2ecf20Sopenharmony_ci#define KP_GPIO2 0x1E /* Keypad or GPIO Selection */ 428c2ecf20Sopenharmony_ci#define KP_GPIO3 0x1F /* Keypad or GPIO Selection */ 438c2ecf20Sopenharmony_ci#define GPI_EM1 0x20 /* GPI Event Mode 1 */ 448c2ecf20Sopenharmony_ci#define GPI_EM2 0x21 /* GPI Event Mode 2 */ 458c2ecf20Sopenharmony_ci#define GPI_EM3 0x22 /* GPI Event Mode 3 */ 468c2ecf20Sopenharmony_ci#define GPIO_DIR1 0x23 /* GPIO Data Direction */ 478c2ecf20Sopenharmony_ci#define GPIO_DIR2 0x24 /* GPIO Data Direction */ 488c2ecf20Sopenharmony_ci#define GPIO_DIR3 0x25 /* GPIO Data Direction */ 498c2ecf20Sopenharmony_ci#define GPIO_INT_LVL1 0x26 /* GPIO Edge/Level Detect */ 508c2ecf20Sopenharmony_ci#define GPIO_INT_LVL2 0x27 /* GPIO Edge/Level Detect */ 518c2ecf20Sopenharmony_ci#define GPIO_INT_LVL3 0x28 /* GPIO Edge/Level Detect */ 528c2ecf20Sopenharmony_ci#define Debounce_DIS1 0x29 /* Debounce Disable */ 538c2ecf20Sopenharmony_ci#define Debounce_DIS2 0x2A /* Debounce Disable */ 548c2ecf20Sopenharmony_ci#define Debounce_DIS3 0x2B /* Debounce Disable */ 558c2ecf20Sopenharmony_ci#define GPIO_PULL1 0x2C /* GPIO Pull Disable */ 568c2ecf20Sopenharmony_ci#define GPIO_PULL2 0x2D /* GPIO Pull Disable */ 578c2ecf20Sopenharmony_ci#define GPIO_PULL3 0x2E /* GPIO Pull Disable */ 588c2ecf20Sopenharmony_ci#define CMP_CFG_STAT 0x30 /* Comparator Configuration and Status Register */ 598c2ecf20Sopenharmony_ci#define CMP_CONFG_SENS1 0x31 /* Sensor1 Comparator Configuration Register */ 608c2ecf20Sopenharmony_ci#define CMP_CONFG_SENS2 0x32 /* L2 Light Sensor Reference Level, Output Falling for Sensor 1 */ 618c2ecf20Sopenharmony_ci#define CMP1_LVL2_TRIP 0x33 /* L2 Light Sensor Hysteresis (Active when Output Rising) for Sensor 1 */ 628c2ecf20Sopenharmony_ci#define CMP1_LVL2_HYS 0x34 /* L3 Light Sensor Reference Level, Output Falling For Sensor 1 */ 638c2ecf20Sopenharmony_ci#define CMP1_LVL3_TRIP 0x35 /* L3 Light Sensor Hysteresis (Active when Output Rising) For Sensor 1 */ 648c2ecf20Sopenharmony_ci#define CMP1_LVL3_HYS 0x36 /* Sensor 2 Comparator Configuration Register */ 658c2ecf20Sopenharmony_ci#define CMP2_LVL2_TRIP 0x37 /* L2 Light Sensor Reference Level, Output Falling for Sensor 2 */ 668c2ecf20Sopenharmony_ci#define CMP2_LVL2_HYS 0x38 /* L2 Light Sensor Hysteresis (Active when Output Rising) for Sensor 2 */ 678c2ecf20Sopenharmony_ci#define CMP2_LVL3_TRIP 0x39 /* L3 Light Sensor Reference Level, Output Falling For Sensor 2 */ 688c2ecf20Sopenharmony_ci#define CMP2_LVL3_HYS 0x3A /* L3 Light Sensor Hysteresis (Active when Output Rising) For Sensor 2 */ 698c2ecf20Sopenharmony_ci#define CMP1_ADC_DAT_R1 0x3B /* Comparator 1 ADC data Register1 */ 708c2ecf20Sopenharmony_ci#define CMP1_ADC_DAT_R2 0x3C /* Comparator 1 ADC data Register2 */ 718c2ecf20Sopenharmony_ci#define CMP2_ADC_DAT_R1 0x3D /* Comparator 2 ADC data Register1 */ 728c2ecf20Sopenharmony_ci#define CMP2_ADC_DAT_R2 0x3E /* Comparator 2 ADC data Register2 */ 738c2ecf20Sopenharmony_ci 748c2ecf20Sopenharmony_ci#define ADP5588_DEVICE_ID_MASK 0xF 758c2ecf20Sopenharmony_ci 768c2ecf20Sopenharmony_ci /* Configuration Register1 */ 778c2ecf20Sopenharmony_ci#define ADP5588_AUTO_INC (1 << 7) 788c2ecf20Sopenharmony_ci#define ADP5588_GPIEM_CFG (1 << 6) 798c2ecf20Sopenharmony_ci#define ADP5588_OVR_FLOW_M (1 << 5) 808c2ecf20Sopenharmony_ci#define ADP5588_INT_CFG (1 << 4) 818c2ecf20Sopenharmony_ci#define ADP5588_OVR_FLOW_IEN (1 << 3) 828c2ecf20Sopenharmony_ci#define ADP5588_K_LCK_IM (1 << 2) 838c2ecf20Sopenharmony_ci#define ADP5588_GPI_IEN (1 << 1) 848c2ecf20Sopenharmony_ci#define ADP5588_KE_IEN (1 << 0) 858c2ecf20Sopenharmony_ci 868c2ecf20Sopenharmony_ci/* Interrupt Status Register */ 878c2ecf20Sopenharmony_ci#define ADP5588_CMP2_INT (1 << 5) 888c2ecf20Sopenharmony_ci#define ADP5588_CMP1_INT (1 << 4) 898c2ecf20Sopenharmony_ci#define ADP5588_OVR_FLOW_INT (1 << 3) 908c2ecf20Sopenharmony_ci#define ADP5588_K_LCK_INT (1 << 2) 918c2ecf20Sopenharmony_ci#define ADP5588_GPI_INT (1 << 1) 928c2ecf20Sopenharmony_ci#define ADP5588_KE_INT (1 << 0) 938c2ecf20Sopenharmony_ci 948c2ecf20Sopenharmony_ci/* Key Lock and Event Counter Register */ 958c2ecf20Sopenharmony_ci#define ADP5588_K_LCK_EN (1 << 6) 968c2ecf20Sopenharmony_ci#define ADP5588_LCK21 0x30 978c2ecf20Sopenharmony_ci#define ADP5588_KEC 0xF 988c2ecf20Sopenharmony_ci 998c2ecf20Sopenharmony_ci#define ADP5588_MAXGPIO 18 1008c2ecf20Sopenharmony_ci#define ADP5588_BANK(offs) ((offs) >> 3) 1018c2ecf20Sopenharmony_ci#define ADP5588_BIT(offs) (1u << ((offs) & 0x7)) 1028c2ecf20Sopenharmony_ci 1038c2ecf20Sopenharmony_ci/* Put one of these structures in i2c_board_info platform_data */ 1048c2ecf20Sopenharmony_ci 1058c2ecf20Sopenharmony_ci#define ADP5588_KEYMAPSIZE 80 1068c2ecf20Sopenharmony_ci 1078c2ecf20Sopenharmony_ci#define GPI_PIN_ROW0 97 1088c2ecf20Sopenharmony_ci#define GPI_PIN_ROW1 98 1098c2ecf20Sopenharmony_ci#define GPI_PIN_ROW2 99 1108c2ecf20Sopenharmony_ci#define GPI_PIN_ROW3 100 1118c2ecf20Sopenharmony_ci#define GPI_PIN_ROW4 101 1128c2ecf20Sopenharmony_ci#define GPI_PIN_ROW5 102 1138c2ecf20Sopenharmony_ci#define GPI_PIN_ROW6 103 1148c2ecf20Sopenharmony_ci#define GPI_PIN_ROW7 104 1158c2ecf20Sopenharmony_ci#define GPI_PIN_COL0 105 1168c2ecf20Sopenharmony_ci#define GPI_PIN_COL1 106 1178c2ecf20Sopenharmony_ci#define GPI_PIN_COL2 107 1188c2ecf20Sopenharmony_ci#define GPI_PIN_COL3 108 1198c2ecf20Sopenharmony_ci#define GPI_PIN_COL4 109 1208c2ecf20Sopenharmony_ci#define GPI_PIN_COL5 110 1218c2ecf20Sopenharmony_ci#define GPI_PIN_COL6 111 1228c2ecf20Sopenharmony_ci#define GPI_PIN_COL7 112 1238c2ecf20Sopenharmony_ci#define GPI_PIN_COL8 113 1248c2ecf20Sopenharmony_ci#define GPI_PIN_COL9 114 1258c2ecf20Sopenharmony_ci 1268c2ecf20Sopenharmony_ci#define GPI_PIN_ROW_BASE GPI_PIN_ROW0 1278c2ecf20Sopenharmony_ci#define GPI_PIN_ROW_END GPI_PIN_ROW7 1288c2ecf20Sopenharmony_ci#define GPI_PIN_COL_BASE GPI_PIN_COL0 1298c2ecf20Sopenharmony_ci#define GPI_PIN_COL_END GPI_PIN_COL9 1308c2ecf20Sopenharmony_ci 1318c2ecf20Sopenharmony_ci#define GPI_PIN_BASE GPI_PIN_ROW_BASE 1328c2ecf20Sopenharmony_ci#define GPI_PIN_END GPI_PIN_COL_END 1338c2ecf20Sopenharmony_ci 1348c2ecf20Sopenharmony_ci#define ADP5588_GPIMAPSIZE_MAX (GPI_PIN_END - GPI_PIN_BASE + 1) 1358c2ecf20Sopenharmony_ci 1368c2ecf20Sopenharmony_cistruct adp5588_gpi_map { 1378c2ecf20Sopenharmony_ci unsigned short pin; 1388c2ecf20Sopenharmony_ci unsigned short sw_evt; 1398c2ecf20Sopenharmony_ci}; 1408c2ecf20Sopenharmony_ci 1418c2ecf20Sopenharmony_cistruct adp5588_kpad_platform_data { 1428c2ecf20Sopenharmony_ci int rows; /* Number of rows */ 1438c2ecf20Sopenharmony_ci int cols; /* Number of columns */ 1448c2ecf20Sopenharmony_ci const unsigned short *keymap; /* Pointer to keymap */ 1458c2ecf20Sopenharmony_ci unsigned short keymapsize; /* Keymap size */ 1468c2ecf20Sopenharmony_ci unsigned repeat:1; /* Enable key repeat */ 1478c2ecf20Sopenharmony_ci unsigned en_keylock:1; /* Enable Key Lock feature */ 1488c2ecf20Sopenharmony_ci unsigned short unlock_key1; /* Unlock Key 1 */ 1498c2ecf20Sopenharmony_ci unsigned short unlock_key2; /* Unlock Key 2 */ 1508c2ecf20Sopenharmony_ci const struct adp5588_gpi_map *gpimap; 1518c2ecf20Sopenharmony_ci unsigned short gpimapsize; 1528c2ecf20Sopenharmony_ci const struct adp5588_gpio_platform_data *gpio_data; 1538c2ecf20Sopenharmony_ci}; 1548c2ecf20Sopenharmony_ci 1558c2ecf20Sopenharmony_cistruct i2c_client; /* forward declaration */ 1568c2ecf20Sopenharmony_ci 1578c2ecf20Sopenharmony_cistruct adp5588_gpio_platform_data { 1588c2ecf20Sopenharmony_ci int gpio_start; /* GPIO Chip base # */ 1598c2ecf20Sopenharmony_ci const char *const *names; 1608c2ecf20Sopenharmony_ci unsigned irq_base; /* interrupt base # */ 1618c2ecf20Sopenharmony_ci unsigned pullup_dis_mask; /* Pull-Up Disable Mask */ 1628c2ecf20Sopenharmony_ci int (*setup)(struct i2c_client *client, 1638c2ecf20Sopenharmony_ci unsigned gpio, unsigned ngpio, 1648c2ecf20Sopenharmony_ci void *context); 1658c2ecf20Sopenharmony_ci int (*teardown)(struct i2c_client *client, 1668c2ecf20Sopenharmony_ci unsigned gpio, unsigned ngpio, 1678c2ecf20Sopenharmony_ci void *context); 1688c2ecf20Sopenharmony_ci void *context; 1698c2ecf20Sopenharmony_ci}; 1708c2ecf20Sopenharmony_ci 1718c2ecf20Sopenharmony_ci#endif 172