18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-only 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * PCA953x 4/8/16/24/40 bit I/O ports 48c2ecf20Sopenharmony_ci * 58c2ecf20Sopenharmony_ci * Copyright (C) 2005 Ben Gardner <bgardner@wabtec.com> 68c2ecf20Sopenharmony_ci * Copyright (C) 2007 Marvell International Ltd. 78c2ecf20Sopenharmony_ci * 88c2ecf20Sopenharmony_ci * Derived from drivers/i2c/chips/pca9539.c 98c2ecf20Sopenharmony_ci */ 108c2ecf20Sopenharmony_ci 118c2ecf20Sopenharmony_ci#include <linux/acpi.h> 128c2ecf20Sopenharmony_ci#include <linux/bitmap.h> 138c2ecf20Sopenharmony_ci#include <linux/gpio/driver.h> 148c2ecf20Sopenharmony_ci#include <linux/gpio/consumer.h> 158c2ecf20Sopenharmony_ci#include <linux/i2c.h> 168c2ecf20Sopenharmony_ci#include <linux/init.h> 178c2ecf20Sopenharmony_ci#include <linux/interrupt.h> 188c2ecf20Sopenharmony_ci#include <linux/module.h> 198c2ecf20Sopenharmony_ci#include <linux/of_platform.h> 208c2ecf20Sopenharmony_ci#include <linux/platform_data/pca953x.h> 218c2ecf20Sopenharmony_ci#include <linux/regmap.h> 228c2ecf20Sopenharmony_ci#include <linux/regulator/consumer.h> 238c2ecf20Sopenharmony_ci#include <linux/slab.h> 248c2ecf20Sopenharmony_ci 258c2ecf20Sopenharmony_ci#include <asm/unaligned.h> 268c2ecf20Sopenharmony_ci 278c2ecf20Sopenharmony_ci#define PCA953X_INPUT 0x00 288c2ecf20Sopenharmony_ci#define PCA953X_OUTPUT 0x01 298c2ecf20Sopenharmony_ci#define PCA953X_INVERT 0x02 308c2ecf20Sopenharmony_ci#define PCA953X_DIRECTION 0x03 318c2ecf20Sopenharmony_ci 328c2ecf20Sopenharmony_ci#define REG_ADDR_MASK GENMASK(5, 0) 338c2ecf20Sopenharmony_ci#define REG_ADDR_EXT BIT(6) 348c2ecf20Sopenharmony_ci#define REG_ADDR_AI BIT(7) 358c2ecf20Sopenharmony_ci 368c2ecf20Sopenharmony_ci#define PCA957X_IN 0x00 378c2ecf20Sopenharmony_ci#define PCA957X_INVRT 0x01 388c2ecf20Sopenharmony_ci#define PCA957X_BKEN 0x02 398c2ecf20Sopenharmony_ci#define PCA957X_PUPD 0x03 408c2ecf20Sopenharmony_ci#define PCA957X_CFG 0x04 418c2ecf20Sopenharmony_ci#define PCA957X_OUT 0x05 428c2ecf20Sopenharmony_ci#define PCA957X_MSK 0x06 438c2ecf20Sopenharmony_ci#define PCA957X_INTS 0x07 448c2ecf20Sopenharmony_ci 458c2ecf20Sopenharmony_ci#define PCAL953X_OUT_STRENGTH 0x20 468c2ecf20Sopenharmony_ci#define PCAL953X_IN_LATCH 0x22 478c2ecf20Sopenharmony_ci#define PCAL953X_PULL_EN 0x23 488c2ecf20Sopenharmony_ci#define PCAL953X_PULL_SEL 0x24 498c2ecf20Sopenharmony_ci#define PCAL953X_INT_MASK 0x25 508c2ecf20Sopenharmony_ci#define PCAL953X_INT_STAT 0x26 518c2ecf20Sopenharmony_ci#define PCAL953X_OUT_CONF 0x27 528c2ecf20Sopenharmony_ci 538c2ecf20Sopenharmony_ci#define PCAL6524_INT_EDGE 0x28 548c2ecf20Sopenharmony_ci#define PCAL6524_INT_CLR 0x2a 558c2ecf20Sopenharmony_ci#define PCAL6524_IN_STATUS 0x2b 568c2ecf20Sopenharmony_ci#define PCAL6524_OUT_INDCONF 0x2c 578c2ecf20Sopenharmony_ci#define PCAL6524_DEBOUNCE 0x2d 588c2ecf20Sopenharmony_ci 598c2ecf20Sopenharmony_ci#define PCA_GPIO_MASK GENMASK(7, 0) 608c2ecf20Sopenharmony_ci 618c2ecf20Sopenharmony_ci#define PCAL_GPIO_MASK GENMASK(4, 0) 628c2ecf20Sopenharmony_ci#define PCAL_PINCTRL_MASK GENMASK(6, 5) 638c2ecf20Sopenharmony_ci 648c2ecf20Sopenharmony_ci#define PCA_INT BIT(8) 658c2ecf20Sopenharmony_ci#define PCA_PCAL BIT(9) 668c2ecf20Sopenharmony_ci#define PCA_LATCH_INT (PCA_PCAL | PCA_INT) 678c2ecf20Sopenharmony_ci#define PCA953X_TYPE BIT(12) 688c2ecf20Sopenharmony_ci#define PCA957X_TYPE BIT(13) 698c2ecf20Sopenharmony_ci#define PCA_TYPE_MASK GENMASK(15, 12) 708c2ecf20Sopenharmony_ci 718c2ecf20Sopenharmony_ci#define PCA_CHIP_TYPE(x) ((x) & PCA_TYPE_MASK) 728c2ecf20Sopenharmony_ci 738c2ecf20Sopenharmony_cistatic const struct i2c_device_id pca953x_id[] = { 748c2ecf20Sopenharmony_ci { "pca6416", 16 | PCA953X_TYPE | PCA_INT, }, 758c2ecf20Sopenharmony_ci { "pca9505", 40 | PCA953X_TYPE | PCA_INT, }, 768c2ecf20Sopenharmony_ci { "pca9534", 8 | PCA953X_TYPE | PCA_INT, }, 778c2ecf20Sopenharmony_ci { "pca9535", 16 | PCA953X_TYPE | PCA_INT, }, 788c2ecf20Sopenharmony_ci { "pca9536", 4 | PCA953X_TYPE, }, 798c2ecf20Sopenharmony_ci { "pca9537", 4 | PCA953X_TYPE | PCA_INT, }, 808c2ecf20Sopenharmony_ci { "pca9538", 8 | PCA953X_TYPE | PCA_INT, }, 818c2ecf20Sopenharmony_ci { "pca9539", 16 | PCA953X_TYPE | PCA_INT, }, 828c2ecf20Sopenharmony_ci { "pca9554", 8 | PCA953X_TYPE | PCA_INT, }, 838c2ecf20Sopenharmony_ci { "pca9555", 16 | PCA953X_TYPE | PCA_INT, }, 848c2ecf20Sopenharmony_ci { "pca9556", 8 | PCA953X_TYPE, }, 858c2ecf20Sopenharmony_ci { "pca9557", 8 | PCA953X_TYPE, }, 868c2ecf20Sopenharmony_ci { "pca9574", 8 | PCA957X_TYPE | PCA_INT, }, 878c2ecf20Sopenharmony_ci { "pca9575", 16 | PCA957X_TYPE | PCA_INT, }, 888c2ecf20Sopenharmony_ci { "pca9698", 40 | PCA953X_TYPE, }, 898c2ecf20Sopenharmony_ci 908c2ecf20Sopenharmony_ci { "pcal6416", 16 | PCA953X_TYPE | PCA_LATCH_INT, }, 918c2ecf20Sopenharmony_ci { "pcal6524", 24 | PCA953X_TYPE | PCA_LATCH_INT, }, 928c2ecf20Sopenharmony_ci { "pcal9535", 16 | PCA953X_TYPE | PCA_LATCH_INT, }, 938c2ecf20Sopenharmony_ci { "pcal9554b", 8 | PCA953X_TYPE | PCA_LATCH_INT, }, 948c2ecf20Sopenharmony_ci { "pcal9555a", 16 | PCA953X_TYPE | PCA_LATCH_INT, }, 958c2ecf20Sopenharmony_ci 968c2ecf20Sopenharmony_ci { "max7310", 8 | PCA953X_TYPE, }, 978c2ecf20Sopenharmony_ci { "max7312", 16 | PCA953X_TYPE | PCA_INT, }, 988c2ecf20Sopenharmony_ci { "max7313", 16 | PCA953X_TYPE | PCA_INT, }, 998c2ecf20Sopenharmony_ci { "max7315", 8 | PCA953X_TYPE | PCA_INT, }, 1008c2ecf20Sopenharmony_ci { "max7318", 16 | PCA953X_TYPE | PCA_INT, }, 1018c2ecf20Sopenharmony_ci { "pca6107", 8 | PCA953X_TYPE | PCA_INT, }, 1028c2ecf20Sopenharmony_ci { "tca6408", 8 | PCA953X_TYPE | PCA_INT, }, 1038c2ecf20Sopenharmony_ci { "tca6416", 16 | PCA953X_TYPE | PCA_INT, }, 1048c2ecf20Sopenharmony_ci { "tca6424", 24 | PCA953X_TYPE | PCA_INT, }, 1058c2ecf20Sopenharmony_ci { "tca9539", 16 | PCA953X_TYPE | PCA_INT, }, 1068c2ecf20Sopenharmony_ci { "tca9554", 8 | PCA953X_TYPE | PCA_INT, }, 1078c2ecf20Sopenharmony_ci { "xra1202", 8 | PCA953X_TYPE }, 1088c2ecf20Sopenharmony_ci { } 1098c2ecf20Sopenharmony_ci}; 1108c2ecf20Sopenharmony_ciMODULE_DEVICE_TABLE(i2c, pca953x_id); 1118c2ecf20Sopenharmony_ci 1128c2ecf20Sopenharmony_ci#ifdef CONFIG_GPIO_PCA953X_IRQ 1138c2ecf20Sopenharmony_ci 1148c2ecf20Sopenharmony_ci#include <linux/dmi.h> 1158c2ecf20Sopenharmony_ci 1168c2ecf20Sopenharmony_cistatic const struct acpi_gpio_params pca953x_irq_gpios = { 0, 0, true }; 1178c2ecf20Sopenharmony_ci 1188c2ecf20Sopenharmony_cistatic const struct acpi_gpio_mapping pca953x_acpi_irq_gpios[] = { 1198c2ecf20Sopenharmony_ci { "irq-gpios", &pca953x_irq_gpios, 1, ACPI_GPIO_QUIRK_ABSOLUTE_NUMBER }, 1208c2ecf20Sopenharmony_ci { } 1218c2ecf20Sopenharmony_ci}; 1228c2ecf20Sopenharmony_ci 1238c2ecf20Sopenharmony_cistatic int pca953x_acpi_get_irq(struct device *dev) 1248c2ecf20Sopenharmony_ci{ 1258c2ecf20Sopenharmony_ci int ret; 1268c2ecf20Sopenharmony_ci 1278c2ecf20Sopenharmony_ci ret = devm_acpi_dev_add_driver_gpios(dev, pca953x_acpi_irq_gpios); 1288c2ecf20Sopenharmony_ci if (ret) 1298c2ecf20Sopenharmony_ci dev_warn(dev, "can't add GPIO ACPI mapping\n"); 1308c2ecf20Sopenharmony_ci 1318c2ecf20Sopenharmony_ci ret = acpi_dev_gpio_irq_get_by(ACPI_COMPANION(dev), "irq-gpios", 0); 1328c2ecf20Sopenharmony_ci if (ret < 0) 1338c2ecf20Sopenharmony_ci return ret; 1348c2ecf20Sopenharmony_ci 1358c2ecf20Sopenharmony_ci dev_info(dev, "ACPI interrupt quirk (IRQ %d)\n", ret); 1368c2ecf20Sopenharmony_ci return ret; 1378c2ecf20Sopenharmony_ci} 1388c2ecf20Sopenharmony_ci 1398c2ecf20Sopenharmony_cistatic const struct dmi_system_id pca953x_dmi_acpi_irq_info[] = { 1408c2ecf20Sopenharmony_ci { 1418c2ecf20Sopenharmony_ci /* 1428c2ecf20Sopenharmony_ci * On Intel Galileo Gen 2 board the IRQ pin of one of 1438c2ecf20Sopenharmony_ci * the I²C GPIO expanders, which has GpioInt() resource, 1448c2ecf20Sopenharmony_ci * is provided as an absolute number instead of being 1458c2ecf20Sopenharmony_ci * relative. Since first controller (gpio-sch.c) and 1468c2ecf20Sopenharmony_ci * second (gpio-dwapb.c) are at the fixed bases, we may 1478c2ecf20Sopenharmony_ci * safely refer to the number in the global space to get 1488c2ecf20Sopenharmony_ci * an IRQ out of it. 1498c2ecf20Sopenharmony_ci */ 1508c2ecf20Sopenharmony_ci .matches = { 1518c2ecf20Sopenharmony_ci DMI_EXACT_MATCH(DMI_BOARD_NAME, "GalileoGen2"), 1528c2ecf20Sopenharmony_ci }, 1538c2ecf20Sopenharmony_ci }, 1548c2ecf20Sopenharmony_ci {} 1558c2ecf20Sopenharmony_ci}; 1568c2ecf20Sopenharmony_ci#endif 1578c2ecf20Sopenharmony_ci 1588c2ecf20Sopenharmony_cistatic const struct acpi_device_id pca953x_acpi_ids[] = { 1598c2ecf20Sopenharmony_ci { "INT3491", 16 | PCA953X_TYPE | PCA_LATCH_INT, }, 1608c2ecf20Sopenharmony_ci { } 1618c2ecf20Sopenharmony_ci}; 1628c2ecf20Sopenharmony_ciMODULE_DEVICE_TABLE(acpi, pca953x_acpi_ids); 1638c2ecf20Sopenharmony_ci 1648c2ecf20Sopenharmony_ci#define MAX_BANK 5 1658c2ecf20Sopenharmony_ci#define BANK_SZ 8 1668c2ecf20Sopenharmony_ci#define MAX_LINE (MAX_BANK * BANK_SZ) 1678c2ecf20Sopenharmony_ci 1688c2ecf20Sopenharmony_ci#define NBANK(chip) DIV_ROUND_UP(chip->gpio_chip.ngpio, BANK_SZ) 1698c2ecf20Sopenharmony_ci 1708c2ecf20Sopenharmony_cistruct pca953x_reg_config { 1718c2ecf20Sopenharmony_ci int direction; 1728c2ecf20Sopenharmony_ci int output; 1738c2ecf20Sopenharmony_ci int input; 1748c2ecf20Sopenharmony_ci int invert; 1758c2ecf20Sopenharmony_ci}; 1768c2ecf20Sopenharmony_ci 1778c2ecf20Sopenharmony_cistatic const struct pca953x_reg_config pca953x_regs = { 1788c2ecf20Sopenharmony_ci .direction = PCA953X_DIRECTION, 1798c2ecf20Sopenharmony_ci .output = PCA953X_OUTPUT, 1808c2ecf20Sopenharmony_ci .input = PCA953X_INPUT, 1818c2ecf20Sopenharmony_ci .invert = PCA953X_INVERT, 1828c2ecf20Sopenharmony_ci}; 1838c2ecf20Sopenharmony_ci 1848c2ecf20Sopenharmony_cistatic const struct pca953x_reg_config pca957x_regs = { 1858c2ecf20Sopenharmony_ci .direction = PCA957X_CFG, 1868c2ecf20Sopenharmony_ci .output = PCA957X_OUT, 1878c2ecf20Sopenharmony_ci .input = PCA957X_IN, 1888c2ecf20Sopenharmony_ci .invert = PCA957X_INVRT, 1898c2ecf20Sopenharmony_ci}; 1908c2ecf20Sopenharmony_ci 1918c2ecf20Sopenharmony_cistruct pca953x_chip { 1928c2ecf20Sopenharmony_ci unsigned gpio_start; 1938c2ecf20Sopenharmony_ci struct mutex i2c_lock; 1948c2ecf20Sopenharmony_ci struct regmap *regmap; 1958c2ecf20Sopenharmony_ci 1968c2ecf20Sopenharmony_ci#ifdef CONFIG_GPIO_PCA953X_IRQ 1978c2ecf20Sopenharmony_ci struct mutex irq_lock; 1988c2ecf20Sopenharmony_ci DECLARE_BITMAP(irq_mask, MAX_LINE); 1998c2ecf20Sopenharmony_ci DECLARE_BITMAP(irq_stat, MAX_LINE); 2008c2ecf20Sopenharmony_ci DECLARE_BITMAP(irq_trig_raise, MAX_LINE); 2018c2ecf20Sopenharmony_ci DECLARE_BITMAP(irq_trig_fall, MAX_LINE); 2028c2ecf20Sopenharmony_ci struct irq_chip irq_chip; 2038c2ecf20Sopenharmony_ci#endif 2048c2ecf20Sopenharmony_ci atomic_t wakeup_path; 2058c2ecf20Sopenharmony_ci 2068c2ecf20Sopenharmony_ci struct i2c_client *client; 2078c2ecf20Sopenharmony_ci struct gpio_chip gpio_chip; 2088c2ecf20Sopenharmony_ci const char *const *names; 2098c2ecf20Sopenharmony_ci unsigned long driver_data; 2108c2ecf20Sopenharmony_ci struct regulator *regulator; 2118c2ecf20Sopenharmony_ci 2128c2ecf20Sopenharmony_ci const struct pca953x_reg_config *regs; 2138c2ecf20Sopenharmony_ci}; 2148c2ecf20Sopenharmony_ci 2158c2ecf20Sopenharmony_cistatic int pca953x_bank_shift(struct pca953x_chip *chip) 2168c2ecf20Sopenharmony_ci{ 2178c2ecf20Sopenharmony_ci return fls((chip->gpio_chip.ngpio - 1) / BANK_SZ); 2188c2ecf20Sopenharmony_ci} 2198c2ecf20Sopenharmony_ci 2208c2ecf20Sopenharmony_ci#define PCA953x_BANK_INPUT BIT(0) 2218c2ecf20Sopenharmony_ci#define PCA953x_BANK_OUTPUT BIT(1) 2228c2ecf20Sopenharmony_ci#define PCA953x_BANK_POLARITY BIT(2) 2238c2ecf20Sopenharmony_ci#define PCA953x_BANK_CONFIG BIT(3) 2248c2ecf20Sopenharmony_ci 2258c2ecf20Sopenharmony_ci#define PCA957x_BANK_INPUT BIT(0) 2268c2ecf20Sopenharmony_ci#define PCA957x_BANK_POLARITY BIT(1) 2278c2ecf20Sopenharmony_ci#define PCA957x_BANK_BUSHOLD BIT(2) 2288c2ecf20Sopenharmony_ci#define PCA957x_BANK_CONFIG BIT(4) 2298c2ecf20Sopenharmony_ci#define PCA957x_BANK_OUTPUT BIT(5) 2308c2ecf20Sopenharmony_ci 2318c2ecf20Sopenharmony_ci#define PCAL9xxx_BANK_IN_LATCH BIT(8 + 2) 2328c2ecf20Sopenharmony_ci#define PCAL9xxx_BANK_PULL_EN BIT(8 + 3) 2338c2ecf20Sopenharmony_ci#define PCAL9xxx_BANK_PULL_SEL BIT(8 + 4) 2348c2ecf20Sopenharmony_ci#define PCAL9xxx_BANK_IRQ_MASK BIT(8 + 5) 2358c2ecf20Sopenharmony_ci#define PCAL9xxx_BANK_IRQ_STAT BIT(8 + 6) 2368c2ecf20Sopenharmony_ci 2378c2ecf20Sopenharmony_ci/* 2388c2ecf20Sopenharmony_ci * We care about the following registers: 2398c2ecf20Sopenharmony_ci * - Standard set, below 0x40, each port can be replicated up to 8 times 2408c2ecf20Sopenharmony_ci * - PCA953x standard 2418c2ecf20Sopenharmony_ci * Input port 0x00 + 0 * bank_size R 2428c2ecf20Sopenharmony_ci * Output port 0x00 + 1 * bank_size RW 2438c2ecf20Sopenharmony_ci * Polarity Inversion port 0x00 + 2 * bank_size RW 2448c2ecf20Sopenharmony_ci * Configuration port 0x00 + 3 * bank_size RW 2458c2ecf20Sopenharmony_ci * - PCA957x with mixed up registers 2468c2ecf20Sopenharmony_ci * Input port 0x00 + 0 * bank_size R 2478c2ecf20Sopenharmony_ci * Polarity Inversion port 0x00 + 1 * bank_size RW 2488c2ecf20Sopenharmony_ci * Bus hold port 0x00 + 2 * bank_size RW 2498c2ecf20Sopenharmony_ci * Configuration port 0x00 + 4 * bank_size RW 2508c2ecf20Sopenharmony_ci * Output port 0x00 + 5 * bank_size RW 2518c2ecf20Sopenharmony_ci * 2528c2ecf20Sopenharmony_ci * - Extended set, above 0x40, often chip specific. 2538c2ecf20Sopenharmony_ci * - PCAL6524/PCAL9555A with custom PCAL IRQ handling: 2548c2ecf20Sopenharmony_ci * Input latch register 0x40 + 2 * bank_size RW 2558c2ecf20Sopenharmony_ci * Pull-up/pull-down enable reg 0x40 + 3 * bank_size RW 2568c2ecf20Sopenharmony_ci * Pull-up/pull-down select reg 0x40 + 4 * bank_size RW 2578c2ecf20Sopenharmony_ci * Interrupt mask register 0x40 + 5 * bank_size RW 2588c2ecf20Sopenharmony_ci * Interrupt status register 0x40 + 6 * bank_size R 2598c2ecf20Sopenharmony_ci * 2608c2ecf20Sopenharmony_ci * - Registers with bit 0x80 set, the AI bit 2618c2ecf20Sopenharmony_ci * The bit is cleared and the registers fall into one of the 2628c2ecf20Sopenharmony_ci * categories above. 2638c2ecf20Sopenharmony_ci */ 2648c2ecf20Sopenharmony_ci 2658c2ecf20Sopenharmony_cistatic bool pca953x_check_register(struct pca953x_chip *chip, unsigned int reg, 2668c2ecf20Sopenharmony_ci u32 checkbank) 2678c2ecf20Sopenharmony_ci{ 2688c2ecf20Sopenharmony_ci int bank_shift = pca953x_bank_shift(chip); 2698c2ecf20Sopenharmony_ci int bank = (reg & REG_ADDR_MASK) >> bank_shift; 2708c2ecf20Sopenharmony_ci int offset = reg & (BIT(bank_shift) - 1); 2718c2ecf20Sopenharmony_ci 2728c2ecf20Sopenharmony_ci /* Special PCAL extended register check. */ 2738c2ecf20Sopenharmony_ci if (reg & REG_ADDR_EXT) { 2748c2ecf20Sopenharmony_ci if (!(chip->driver_data & PCA_PCAL)) 2758c2ecf20Sopenharmony_ci return false; 2768c2ecf20Sopenharmony_ci bank += 8; 2778c2ecf20Sopenharmony_ci } 2788c2ecf20Sopenharmony_ci 2798c2ecf20Sopenharmony_ci /* Register is not in the matching bank. */ 2808c2ecf20Sopenharmony_ci if (!(BIT(bank) & checkbank)) 2818c2ecf20Sopenharmony_ci return false; 2828c2ecf20Sopenharmony_ci 2838c2ecf20Sopenharmony_ci /* Register is not within allowed range of bank. */ 2848c2ecf20Sopenharmony_ci if (offset >= NBANK(chip)) 2858c2ecf20Sopenharmony_ci return false; 2868c2ecf20Sopenharmony_ci 2878c2ecf20Sopenharmony_ci return true; 2888c2ecf20Sopenharmony_ci} 2898c2ecf20Sopenharmony_ci 2908c2ecf20Sopenharmony_cistatic bool pca953x_readable_register(struct device *dev, unsigned int reg) 2918c2ecf20Sopenharmony_ci{ 2928c2ecf20Sopenharmony_ci struct pca953x_chip *chip = dev_get_drvdata(dev); 2938c2ecf20Sopenharmony_ci u32 bank; 2948c2ecf20Sopenharmony_ci 2958c2ecf20Sopenharmony_ci if (PCA_CHIP_TYPE(chip->driver_data) == PCA953X_TYPE) { 2968c2ecf20Sopenharmony_ci bank = PCA953x_BANK_INPUT | PCA953x_BANK_OUTPUT | 2978c2ecf20Sopenharmony_ci PCA953x_BANK_POLARITY | PCA953x_BANK_CONFIG; 2988c2ecf20Sopenharmony_ci } else { 2998c2ecf20Sopenharmony_ci bank = PCA957x_BANK_INPUT | PCA957x_BANK_OUTPUT | 3008c2ecf20Sopenharmony_ci PCA957x_BANK_POLARITY | PCA957x_BANK_CONFIG | 3018c2ecf20Sopenharmony_ci PCA957x_BANK_BUSHOLD; 3028c2ecf20Sopenharmony_ci } 3038c2ecf20Sopenharmony_ci 3048c2ecf20Sopenharmony_ci if (chip->driver_data & PCA_PCAL) { 3058c2ecf20Sopenharmony_ci bank |= PCAL9xxx_BANK_IN_LATCH | PCAL9xxx_BANK_PULL_EN | 3068c2ecf20Sopenharmony_ci PCAL9xxx_BANK_PULL_SEL | PCAL9xxx_BANK_IRQ_MASK | 3078c2ecf20Sopenharmony_ci PCAL9xxx_BANK_IRQ_STAT; 3088c2ecf20Sopenharmony_ci } 3098c2ecf20Sopenharmony_ci 3108c2ecf20Sopenharmony_ci return pca953x_check_register(chip, reg, bank); 3118c2ecf20Sopenharmony_ci} 3128c2ecf20Sopenharmony_ci 3138c2ecf20Sopenharmony_cistatic bool pca953x_writeable_register(struct device *dev, unsigned int reg) 3148c2ecf20Sopenharmony_ci{ 3158c2ecf20Sopenharmony_ci struct pca953x_chip *chip = dev_get_drvdata(dev); 3168c2ecf20Sopenharmony_ci u32 bank; 3178c2ecf20Sopenharmony_ci 3188c2ecf20Sopenharmony_ci if (PCA_CHIP_TYPE(chip->driver_data) == PCA953X_TYPE) { 3198c2ecf20Sopenharmony_ci bank = PCA953x_BANK_OUTPUT | PCA953x_BANK_POLARITY | 3208c2ecf20Sopenharmony_ci PCA953x_BANK_CONFIG; 3218c2ecf20Sopenharmony_ci } else { 3228c2ecf20Sopenharmony_ci bank = PCA957x_BANK_OUTPUT | PCA957x_BANK_POLARITY | 3238c2ecf20Sopenharmony_ci PCA957x_BANK_CONFIG | PCA957x_BANK_BUSHOLD; 3248c2ecf20Sopenharmony_ci } 3258c2ecf20Sopenharmony_ci 3268c2ecf20Sopenharmony_ci if (chip->driver_data & PCA_PCAL) 3278c2ecf20Sopenharmony_ci bank |= PCAL9xxx_BANK_IN_LATCH | PCAL9xxx_BANK_PULL_EN | 3288c2ecf20Sopenharmony_ci PCAL9xxx_BANK_PULL_SEL | PCAL9xxx_BANK_IRQ_MASK; 3298c2ecf20Sopenharmony_ci 3308c2ecf20Sopenharmony_ci return pca953x_check_register(chip, reg, bank); 3318c2ecf20Sopenharmony_ci} 3328c2ecf20Sopenharmony_ci 3338c2ecf20Sopenharmony_cistatic bool pca953x_volatile_register(struct device *dev, unsigned int reg) 3348c2ecf20Sopenharmony_ci{ 3358c2ecf20Sopenharmony_ci struct pca953x_chip *chip = dev_get_drvdata(dev); 3368c2ecf20Sopenharmony_ci u32 bank; 3378c2ecf20Sopenharmony_ci 3388c2ecf20Sopenharmony_ci if (PCA_CHIP_TYPE(chip->driver_data) == PCA953X_TYPE) 3398c2ecf20Sopenharmony_ci bank = PCA953x_BANK_INPUT; 3408c2ecf20Sopenharmony_ci else 3418c2ecf20Sopenharmony_ci bank = PCA957x_BANK_INPUT; 3428c2ecf20Sopenharmony_ci 3438c2ecf20Sopenharmony_ci if (chip->driver_data & PCA_PCAL) 3448c2ecf20Sopenharmony_ci bank |= PCAL9xxx_BANK_IRQ_STAT; 3458c2ecf20Sopenharmony_ci 3468c2ecf20Sopenharmony_ci return pca953x_check_register(chip, reg, bank); 3478c2ecf20Sopenharmony_ci} 3488c2ecf20Sopenharmony_ci 3498c2ecf20Sopenharmony_cistatic const struct regmap_config pca953x_i2c_regmap = { 3508c2ecf20Sopenharmony_ci .reg_bits = 8, 3518c2ecf20Sopenharmony_ci .val_bits = 8, 3528c2ecf20Sopenharmony_ci 3538c2ecf20Sopenharmony_ci .use_single_read = true, 3548c2ecf20Sopenharmony_ci .use_single_write = true, 3558c2ecf20Sopenharmony_ci 3568c2ecf20Sopenharmony_ci .readable_reg = pca953x_readable_register, 3578c2ecf20Sopenharmony_ci .writeable_reg = pca953x_writeable_register, 3588c2ecf20Sopenharmony_ci .volatile_reg = pca953x_volatile_register, 3598c2ecf20Sopenharmony_ci 3608c2ecf20Sopenharmony_ci .disable_locking = true, 3618c2ecf20Sopenharmony_ci .cache_type = REGCACHE_RBTREE, 3628c2ecf20Sopenharmony_ci .max_register = 0x7f, 3638c2ecf20Sopenharmony_ci}; 3648c2ecf20Sopenharmony_ci 3658c2ecf20Sopenharmony_cistatic const struct regmap_config pca953x_ai_i2c_regmap = { 3668c2ecf20Sopenharmony_ci .reg_bits = 8, 3678c2ecf20Sopenharmony_ci .val_bits = 8, 3688c2ecf20Sopenharmony_ci 3698c2ecf20Sopenharmony_ci .read_flag_mask = REG_ADDR_AI, 3708c2ecf20Sopenharmony_ci .write_flag_mask = REG_ADDR_AI, 3718c2ecf20Sopenharmony_ci 3728c2ecf20Sopenharmony_ci .readable_reg = pca953x_readable_register, 3738c2ecf20Sopenharmony_ci .writeable_reg = pca953x_writeable_register, 3748c2ecf20Sopenharmony_ci .volatile_reg = pca953x_volatile_register, 3758c2ecf20Sopenharmony_ci 3768c2ecf20Sopenharmony_ci .disable_locking = true, 3778c2ecf20Sopenharmony_ci .cache_type = REGCACHE_RBTREE, 3788c2ecf20Sopenharmony_ci .max_register = 0x7f, 3798c2ecf20Sopenharmony_ci}; 3808c2ecf20Sopenharmony_ci 3818c2ecf20Sopenharmony_cistatic u8 pca953x_recalc_addr(struct pca953x_chip *chip, int reg, int off) 3828c2ecf20Sopenharmony_ci{ 3838c2ecf20Sopenharmony_ci int bank_shift = pca953x_bank_shift(chip); 3848c2ecf20Sopenharmony_ci int addr = (reg & PCAL_GPIO_MASK) << bank_shift; 3858c2ecf20Sopenharmony_ci int pinctrl = (reg & PCAL_PINCTRL_MASK) << 1; 3868c2ecf20Sopenharmony_ci u8 regaddr = pinctrl | addr | (off / BANK_SZ); 3878c2ecf20Sopenharmony_ci 3888c2ecf20Sopenharmony_ci return regaddr; 3898c2ecf20Sopenharmony_ci} 3908c2ecf20Sopenharmony_ci 3918c2ecf20Sopenharmony_cistatic int pca953x_write_regs(struct pca953x_chip *chip, int reg, unsigned long *val) 3928c2ecf20Sopenharmony_ci{ 3938c2ecf20Sopenharmony_ci u8 regaddr = pca953x_recalc_addr(chip, reg, 0); 3948c2ecf20Sopenharmony_ci u8 value[MAX_BANK]; 3958c2ecf20Sopenharmony_ci int i, ret; 3968c2ecf20Sopenharmony_ci 3978c2ecf20Sopenharmony_ci for (i = 0; i < NBANK(chip); i++) 3988c2ecf20Sopenharmony_ci value[i] = bitmap_get_value8(val, i * BANK_SZ); 3998c2ecf20Sopenharmony_ci 4008c2ecf20Sopenharmony_ci ret = regmap_bulk_write(chip->regmap, regaddr, value, NBANK(chip)); 4018c2ecf20Sopenharmony_ci if (ret < 0) { 4028c2ecf20Sopenharmony_ci dev_err(&chip->client->dev, "failed writing register\n"); 4038c2ecf20Sopenharmony_ci return ret; 4048c2ecf20Sopenharmony_ci } 4058c2ecf20Sopenharmony_ci 4068c2ecf20Sopenharmony_ci return 0; 4078c2ecf20Sopenharmony_ci} 4088c2ecf20Sopenharmony_ci 4098c2ecf20Sopenharmony_cistatic int pca953x_read_regs(struct pca953x_chip *chip, int reg, unsigned long *val) 4108c2ecf20Sopenharmony_ci{ 4118c2ecf20Sopenharmony_ci u8 regaddr = pca953x_recalc_addr(chip, reg, 0); 4128c2ecf20Sopenharmony_ci u8 value[MAX_BANK]; 4138c2ecf20Sopenharmony_ci int i, ret; 4148c2ecf20Sopenharmony_ci 4158c2ecf20Sopenharmony_ci ret = regmap_bulk_read(chip->regmap, regaddr, value, NBANK(chip)); 4168c2ecf20Sopenharmony_ci if (ret < 0) { 4178c2ecf20Sopenharmony_ci dev_err(&chip->client->dev, "failed reading register\n"); 4188c2ecf20Sopenharmony_ci return ret; 4198c2ecf20Sopenharmony_ci } 4208c2ecf20Sopenharmony_ci 4218c2ecf20Sopenharmony_ci for (i = 0; i < NBANK(chip); i++) 4228c2ecf20Sopenharmony_ci bitmap_set_value8(val, value[i], i * BANK_SZ); 4238c2ecf20Sopenharmony_ci 4248c2ecf20Sopenharmony_ci return 0; 4258c2ecf20Sopenharmony_ci} 4268c2ecf20Sopenharmony_ci 4278c2ecf20Sopenharmony_cistatic int pca953x_gpio_direction_input(struct gpio_chip *gc, unsigned off) 4288c2ecf20Sopenharmony_ci{ 4298c2ecf20Sopenharmony_ci struct pca953x_chip *chip = gpiochip_get_data(gc); 4308c2ecf20Sopenharmony_ci u8 dirreg = pca953x_recalc_addr(chip, chip->regs->direction, off); 4318c2ecf20Sopenharmony_ci u8 bit = BIT(off % BANK_SZ); 4328c2ecf20Sopenharmony_ci int ret; 4338c2ecf20Sopenharmony_ci 4348c2ecf20Sopenharmony_ci mutex_lock(&chip->i2c_lock); 4358c2ecf20Sopenharmony_ci ret = regmap_write_bits(chip->regmap, dirreg, bit, bit); 4368c2ecf20Sopenharmony_ci mutex_unlock(&chip->i2c_lock); 4378c2ecf20Sopenharmony_ci return ret; 4388c2ecf20Sopenharmony_ci} 4398c2ecf20Sopenharmony_ci 4408c2ecf20Sopenharmony_cistatic int pca953x_gpio_direction_output(struct gpio_chip *gc, 4418c2ecf20Sopenharmony_ci unsigned off, int val) 4428c2ecf20Sopenharmony_ci{ 4438c2ecf20Sopenharmony_ci struct pca953x_chip *chip = gpiochip_get_data(gc); 4448c2ecf20Sopenharmony_ci u8 dirreg = pca953x_recalc_addr(chip, chip->regs->direction, off); 4458c2ecf20Sopenharmony_ci u8 outreg = pca953x_recalc_addr(chip, chip->regs->output, off); 4468c2ecf20Sopenharmony_ci u8 bit = BIT(off % BANK_SZ); 4478c2ecf20Sopenharmony_ci int ret; 4488c2ecf20Sopenharmony_ci 4498c2ecf20Sopenharmony_ci mutex_lock(&chip->i2c_lock); 4508c2ecf20Sopenharmony_ci /* set output level */ 4518c2ecf20Sopenharmony_ci ret = regmap_write_bits(chip->regmap, outreg, bit, val ? bit : 0); 4528c2ecf20Sopenharmony_ci if (ret) 4538c2ecf20Sopenharmony_ci goto exit; 4548c2ecf20Sopenharmony_ci 4558c2ecf20Sopenharmony_ci /* then direction */ 4568c2ecf20Sopenharmony_ci ret = regmap_write_bits(chip->regmap, dirreg, bit, 0); 4578c2ecf20Sopenharmony_ciexit: 4588c2ecf20Sopenharmony_ci mutex_unlock(&chip->i2c_lock); 4598c2ecf20Sopenharmony_ci return ret; 4608c2ecf20Sopenharmony_ci} 4618c2ecf20Sopenharmony_ci 4628c2ecf20Sopenharmony_cistatic int pca953x_gpio_get_value(struct gpio_chip *gc, unsigned off) 4638c2ecf20Sopenharmony_ci{ 4648c2ecf20Sopenharmony_ci struct pca953x_chip *chip = gpiochip_get_data(gc); 4658c2ecf20Sopenharmony_ci u8 inreg = pca953x_recalc_addr(chip, chip->regs->input, off); 4668c2ecf20Sopenharmony_ci u8 bit = BIT(off % BANK_SZ); 4678c2ecf20Sopenharmony_ci u32 reg_val; 4688c2ecf20Sopenharmony_ci int ret; 4698c2ecf20Sopenharmony_ci 4708c2ecf20Sopenharmony_ci mutex_lock(&chip->i2c_lock); 4718c2ecf20Sopenharmony_ci ret = regmap_read(chip->regmap, inreg, ®_val); 4728c2ecf20Sopenharmony_ci mutex_unlock(&chip->i2c_lock); 4738c2ecf20Sopenharmony_ci if (ret < 0) 4748c2ecf20Sopenharmony_ci return ret; 4758c2ecf20Sopenharmony_ci 4768c2ecf20Sopenharmony_ci return !!(reg_val & bit); 4778c2ecf20Sopenharmony_ci} 4788c2ecf20Sopenharmony_ci 4798c2ecf20Sopenharmony_cistatic void pca953x_gpio_set_value(struct gpio_chip *gc, unsigned off, int val) 4808c2ecf20Sopenharmony_ci{ 4818c2ecf20Sopenharmony_ci struct pca953x_chip *chip = gpiochip_get_data(gc); 4828c2ecf20Sopenharmony_ci u8 outreg = pca953x_recalc_addr(chip, chip->regs->output, off); 4838c2ecf20Sopenharmony_ci u8 bit = BIT(off % BANK_SZ); 4848c2ecf20Sopenharmony_ci 4858c2ecf20Sopenharmony_ci mutex_lock(&chip->i2c_lock); 4868c2ecf20Sopenharmony_ci regmap_write_bits(chip->regmap, outreg, bit, val ? bit : 0); 4878c2ecf20Sopenharmony_ci mutex_unlock(&chip->i2c_lock); 4888c2ecf20Sopenharmony_ci} 4898c2ecf20Sopenharmony_ci 4908c2ecf20Sopenharmony_cistatic int pca953x_gpio_get_direction(struct gpio_chip *gc, unsigned off) 4918c2ecf20Sopenharmony_ci{ 4928c2ecf20Sopenharmony_ci struct pca953x_chip *chip = gpiochip_get_data(gc); 4938c2ecf20Sopenharmony_ci u8 dirreg = pca953x_recalc_addr(chip, chip->regs->direction, off); 4948c2ecf20Sopenharmony_ci u8 bit = BIT(off % BANK_SZ); 4958c2ecf20Sopenharmony_ci u32 reg_val; 4968c2ecf20Sopenharmony_ci int ret; 4978c2ecf20Sopenharmony_ci 4988c2ecf20Sopenharmony_ci mutex_lock(&chip->i2c_lock); 4998c2ecf20Sopenharmony_ci ret = regmap_read(chip->regmap, dirreg, ®_val); 5008c2ecf20Sopenharmony_ci mutex_unlock(&chip->i2c_lock); 5018c2ecf20Sopenharmony_ci if (ret < 0) 5028c2ecf20Sopenharmony_ci return ret; 5038c2ecf20Sopenharmony_ci 5048c2ecf20Sopenharmony_ci if (reg_val & bit) 5058c2ecf20Sopenharmony_ci return GPIO_LINE_DIRECTION_IN; 5068c2ecf20Sopenharmony_ci 5078c2ecf20Sopenharmony_ci return GPIO_LINE_DIRECTION_OUT; 5088c2ecf20Sopenharmony_ci} 5098c2ecf20Sopenharmony_ci 5108c2ecf20Sopenharmony_cistatic int pca953x_gpio_get_multiple(struct gpio_chip *gc, 5118c2ecf20Sopenharmony_ci unsigned long *mask, unsigned long *bits) 5128c2ecf20Sopenharmony_ci{ 5138c2ecf20Sopenharmony_ci struct pca953x_chip *chip = gpiochip_get_data(gc); 5148c2ecf20Sopenharmony_ci DECLARE_BITMAP(reg_val, MAX_LINE); 5158c2ecf20Sopenharmony_ci int ret; 5168c2ecf20Sopenharmony_ci 5178c2ecf20Sopenharmony_ci mutex_lock(&chip->i2c_lock); 5188c2ecf20Sopenharmony_ci ret = pca953x_read_regs(chip, chip->regs->input, reg_val); 5198c2ecf20Sopenharmony_ci mutex_unlock(&chip->i2c_lock); 5208c2ecf20Sopenharmony_ci if (ret) 5218c2ecf20Sopenharmony_ci return ret; 5228c2ecf20Sopenharmony_ci 5238c2ecf20Sopenharmony_ci bitmap_replace(bits, bits, reg_val, mask, gc->ngpio); 5248c2ecf20Sopenharmony_ci return 0; 5258c2ecf20Sopenharmony_ci} 5268c2ecf20Sopenharmony_ci 5278c2ecf20Sopenharmony_cistatic void pca953x_gpio_set_multiple(struct gpio_chip *gc, 5288c2ecf20Sopenharmony_ci unsigned long *mask, unsigned long *bits) 5298c2ecf20Sopenharmony_ci{ 5308c2ecf20Sopenharmony_ci struct pca953x_chip *chip = gpiochip_get_data(gc); 5318c2ecf20Sopenharmony_ci DECLARE_BITMAP(reg_val, MAX_LINE); 5328c2ecf20Sopenharmony_ci int ret; 5338c2ecf20Sopenharmony_ci 5348c2ecf20Sopenharmony_ci mutex_lock(&chip->i2c_lock); 5358c2ecf20Sopenharmony_ci ret = pca953x_read_regs(chip, chip->regs->output, reg_val); 5368c2ecf20Sopenharmony_ci if (ret) 5378c2ecf20Sopenharmony_ci goto exit; 5388c2ecf20Sopenharmony_ci 5398c2ecf20Sopenharmony_ci bitmap_replace(reg_val, reg_val, bits, mask, gc->ngpio); 5408c2ecf20Sopenharmony_ci 5418c2ecf20Sopenharmony_ci pca953x_write_regs(chip, chip->regs->output, reg_val); 5428c2ecf20Sopenharmony_ciexit: 5438c2ecf20Sopenharmony_ci mutex_unlock(&chip->i2c_lock); 5448c2ecf20Sopenharmony_ci} 5458c2ecf20Sopenharmony_ci 5468c2ecf20Sopenharmony_cistatic int pca953x_gpio_set_pull_up_down(struct pca953x_chip *chip, 5478c2ecf20Sopenharmony_ci unsigned int offset, 5488c2ecf20Sopenharmony_ci unsigned long config) 5498c2ecf20Sopenharmony_ci{ 5508c2ecf20Sopenharmony_ci u8 pull_en_reg = pca953x_recalc_addr(chip, PCAL953X_PULL_EN, offset); 5518c2ecf20Sopenharmony_ci u8 pull_sel_reg = pca953x_recalc_addr(chip, PCAL953X_PULL_SEL, offset); 5528c2ecf20Sopenharmony_ci u8 bit = BIT(offset % BANK_SZ); 5538c2ecf20Sopenharmony_ci int ret; 5548c2ecf20Sopenharmony_ci 5558c2ecf20Sopenharmony_ci /* 5568c2ecf20Sopenharmony_ci * pull-up/pull-down configuration requires PCAL extended 5578c2ecf20Sopenharmony_ci * registers 5588c2ecf20Sopenharmony_ci */ 5598c2ecf20Sopenharmony_ci if (!(chip->driver_data & PCA_PCAL)) 5608c2ecf20Sopenharmony_ci return -ENOTSUPP; 5618c2ecf20Sopenharmony_ci 5628c2ecf20Sopenharmony_ci mutex_lock(&chip->i2c_lock); 5638c2ecf20Sopenharmony_ci 5648c2ecf20Sopenharmony_ci /* Configure pull-up/pull-down */ 5658c2ecf20Sopenharmony_ci if (config == PIN_CONFIG_BIAS_PULL_UP) 5668c2ecf20Sopenharmony_ci ret = regmap_write_bits(chip->regmap, pull_sel_reg, bit, bit); 5678c2ecf20Sopenharmony_ci else if (config == PIN_CONFIG_BIAS_PULL_DOWN) 5688c2ecf20Sopenharmony_ci ret = regmap_write_bits(chip->regmap, pull_sel_reg, bit, 0); 5698c2ecf20Sopenharmony_ci else 5708c2ecf20Sopenharmony_ci ret = 0; 5718c2ecf20Sopenharmony_ci if (ret) 5728c2ecf20Sopenharmony_ci goto exit; 5738c2ecf20Sopenharmony_ci 5748c2ecf20Sopenharmony_ci /* Disable/Enable pull-up/pull-down */ 5758c2ecf20Sopenharmony_ci if (config == PIN_CONFIG_BIAS_DISABLE) 5768c2ecf20Sopenharmony_ci ret = regmap_write_bits(chip->regmap, pull_en_reg, bit, 0); 5778c2ecf20Sopenharmony_ci else 5788c2ecf20Sopenharmony_ci ret = regmap_write_bits(chip->regmap, pull_en_reg, bit, bit); 5798c2ecf20Sopenharmony_ci 5808c2ecf20Sopenharmony_ciexit: 5818c2ecf20Sopenharmony_ci mutex_unlock(&chip->i2c_lock); 5828c2ecf20Sopenharmony_ci return ret; 5838c2ecf20Sopenharmony_ci} 5848c2ecf20Sopenharmony_ci 5858c2ecf20Sopenharmony_cistatic int pca953x_gpio_set_config(struct gpio_chip *gc, unsigned int offset, 5868c2ecf20Sopenharmony_ci unsigned long config) 5878c2ecf20Sopenharmony_ci{ 5888c2ecf20Sopenharmony_ci struct pca953x_chip *chip = gpiochip_get_data(gc); 5898c2ecf20Sopenharmony_ci 5908c2ecf20Sopenharmony_ci switch (pinconf_to_config_param(config)) { 5918c2ecf20Sopenharmony_ci case PIN_CONFIG_BIAS_PULL_UP: 5928c2ecf20Sopenharmony_ci case PIN_CONFIG_BIAS_PULL_PIN_DEFAULT: 5938c2ecf20Sopenharmony_ci case PIN_CONFIG_BIAS_PULL_DOWN: 5948c2ecf20Sopenharmony_ci case PIN_CONFIG_BIAS_DISABLE: 5958c2ecf20Sopenharmony_ci return pca953x_gpio_set_pull_up_down(chip, offset, config); 5968c2ecf20Sopenharmony_ci default: 5978c2ecf20Sopenharmony_ci return -ENOTSUPP; 5988c2ecf20Sopenharmony_ci } 5998c2ecf20Sopenharmony_ci} 6008c2ecf20Sopenharmony_ci 6018c2ecf20Sopenharmony_cistatic void pca953x_setup_gpio(struct pca953x_chip *chip, int gpios) 6028c2ecf20Sopenharmony_ci{ 6038c2ecf20Sopenharmony_ci struct gpio_chip *gc; 6048c2ecf20Sopenharmony_ci 6058c2ecf20Sopenharmony_ci gc = &chip->gpio_chip; 6068c2ecf20Sopenharmony_ci 6078c2ecf20Sopenharmony_ci gc->direction_input = pca953x_gpio_direction_input; 6088c2ecf20Sopenharmony_ci gc->direction_output = pca953x_gpio_direction_output; 6098c2ecf20Sopenharmony_ci gc->get = pca953x_gpio_get_value; 6108c2ecf20Sopenharmony_ci gc->set = pca953x_gpio_set_value; 6118c2ecf20Sopenharmony_ci gc->get_direction = pca953x_gpio_get_direction; 6128c2ecf20Sopenharmony_ci gc->get_multiple = pca953x_gpio_get_multiple; 6138c2ecf20Sopenharmony_ci gc->set_multiple = pca953x_gpio_set_multiple; 6148c2ecf20Sopenharmony_ci gc->set_config = pca953x_gpio_set_config; 6158c2ecf20Sopenharmony_ci gc->can_sleep = true; 6168c2ecf20Sopenharmony_ci 6178c2ecf20Sopenharmony_ci gc->base = chip->gpio_start; 6188c2ecf20Sopenharmony_ci gc->ngpio = gpios; 6198c2ecf20Sopenharmony_ci gc->label = dev_name(&chip->client->dev); 6208c2ecf20Sopenharmony_ci gc->parent = &chip->client->dev; 6218c2ecf20Sopenharmony_ci gc->owner = THIS_MODULE; 6228c2ecf20Sopenharmony_ci gc->names = chip->names; 6238c2ecf20Sopenharmony_ci} 6248c2ecf20Sopenharmony_ci 6258c2ecf20Sopenharmony_ci#ifdef CONFIG_GPIO_PCA953X_IRQ 6268c2ecf20Sopenharmony_cistatic void pca953x_irq_mask(struct irq_data *d) 6278c2ecf20Sopenharmony_ci{ 6288c2ecf20Sopenharmony_ci struct gpio_chip *gc = irq_data_get_irq_chip_data(d); 6298c2ecf20Sopenharmony_ci struct pca953x_chip *chip = gpiochip_get_data(gc); 6308c2ecf20Sopenharmony_ci irq_hw_number_t hwirq = irqd_to_hwirq(d); 6318c2ecf20Sopenharmony_ci 6328c2ecf20Sopenharmony_ci clear_bit(hwirq, chip->irq_mask); 6338c2ecf20Sopenharmony_ci} 6348c2ecf20Sopenharmony_ci 6358c2ecf20Sopenharmony_cistatic void pca953x_irq_unmask(struct irq_data *d) 6368c2ecf20Sopenharmony_ci{ 6378c2ecf20Sopenharmony_ci struct gpio_chip *gc = irq_data_get_irq_chip_data(d); 6388c2ecf20Sopenharmony_ci struct pca953x_chip *chip = gpiochip_get_data(gc); 6398c2ecf20Sopenharmony_ci irq_hw_number_t hwirq = irqd_to_hwirq(d); 6408c2ecf20Sopenharmony_ci 6418c2ecf20Sopenharmony_ci set_bit(hwirq, chip->irq_mask); 6428c2ecf20Sopenharmony_ci} 6438c2ecf20Sopenharmony_ci 6448c2ecf20Sopenharmony_cistatic int pca953x_irq_set_wake(struct irq_data *d, unsigned int on) 6458c2ecf20Sopenharmony_ci{ 6468c2ecf20Sopenharmony_ci struct gpio_chip *gc = irq_data_get_irq_chip_data(d); 6478c2ecf20Sopenharmony_ci struct pca953x_chip *chip = gpiochip_get_data(gc); 6488c2ecf20Sopenharmony_ci 6498c2ecf20Sopenharmony_ci if (on) 6508c2ecf20Sopenharmony_ci atomic_inc(&chip->wakeup_path); 6518c2ecf20Sopenharmony_ci else 6528c2ecf20Sopenharmony_ci atomic_dec(&chip->wakeup_path); 6538c2ecf20Sopenharmony_ci 6548c2ecf20Sopenharmony_ci return irq_set_irq_wake(chip->client->irq, on); 6558c2ecf20Sopenharmony_ci} 6568c2ecf20Sopenharmony_ci 6578c2ecf20Sopenharmony_cistatic void pca953x_irq_bus_lock(struct irq_data *d) 6588c2ecf20Sopenharmony_ci{ 6598c2ecf20Sopenharmony_ci struct gpio_chip *gc = irq_data_get_irq_chip_data(d); 6608c2ecf20Sopenharmony_ci struct pca953x_chip *chip = gpiochip_get_data(gc); 6618c2ecf20Sopenharmony_ci 6628c2ecf20Sopenharmony_ci mutex_lock(&chip->irq_lock); 6638c2ecf20Sopenharmony_ci} 6648c2ecf20Sopenharmony_ci 6658c2ecf20Sopenharmony_cistatic void pca953x_irq_bus_sync_unlock(struct irq_data *d) 6668c2ecf20Sopenharmony_ci{ 6678c2ecf20Sopenharmony_ci struct gpio_chip *gc = irq_data_get_irq_chip_data(d); 6688c2ecf20Sopenharmony_ci struct pca953x_chip *chip = gpiochip_get_data(gc); 6698c2ecf20Sopenharmony_ci DECLARE_BITMAP(irq_mask, MAX_LINE); 6708c2ecf20Sopenharmony_ci DECLARE_BITMAP(reg_direction, MAX_LINE); 6718c2ecf20Sopenharmony_ci int level; 6728c2ecf20Sopenharmony_ci 6738c2ecf20Sopenharmony_ci if (chip->driver_data & PCA_PCAL) { 6748c2ecf20Sopenharmony_ci /* Enable latch on interrupt-enabled inputs */ 6758c2ecf20Sopenharmony_ci pca953x_write_regs(chip, PCAL953X_IN_LATCH, chip->irq_mask); 6768c2ecf20Sopenharmony_ci 6778c2ecf20Sopenharmony_ci bitmap_complement(irq_mask, chip->irq_mask, gc->ngpio); 6788c2ecf20Sopenharmony_ci 6798c2ecf20Sopenharmony_ci /* Unmask enabled interrupts */ 6808c2ecf20Sopenharmony_ci pca953x_write_regs(chip, PCAL953X_INT_MASK, irq_mask); 6818c2ecf20Sopenharmony_ci } 6828c2ecf20Sopenharmony_ci 6838c2ecf20Sopenharmony_ci /* Switch direction to input if needed */ 6848c2ecf20Sopenharmony_ci pca953x_read_regs(chip, chip->regs->direction, reg_direction); 6858c2ecf20Sopenharmony_ci 6868c2ecf20Sopenharmony_ci bitmap_or(irq_mask, chip->irq_trig_fall, chip->irq_trig_raise, gc->ngpio); 6878c2ecf20Sopenharmony_ci bitmap_complement(reg_direction, reg_direction, gc->ngpio); 6888c2ecf20Sopenharmony_ci bitmap_and(irq_mask, irq_mask, reg_direction, gc->ngpio); 6898c2ecf20Sopenharmony_ci 6908c2ecf20Sopenharmony_ci /* Look for any newly setup interrupt */ 6918c2ecf20Sopenharmony_ci for_each_set_bit(level, irq_mask, gc->ngpio) 6928c2ecf20Sopenharmony_ci pca953x_gpio_direction_input(&chip->gpio_chip, level); 6938c2ecf20Sopenharmony_ci 6948c2ecf20Sopenharmony_ci mutex_unlock(&chip->irq_lock); 6958c2ecf20Sopenharmony_ci} 6968c2ecf20Sopenharmony_ci 6978c2ecf20Sopenharmony_cistatic int pca953x_irq_set_type(struct irq_data *d, unsigned int type) 6988c2ecf20Sopenharmony_ci{ 6998c2ecf20Sopenharmony_ci struct gpio_chip *gc = irq_data_get_irq_chip_data(d); 7008c2ecf20Sopenharmony_ci struct pca953x_chip *chip = gpiochip_get_data(gc); 7018c2ecf20Sopenharmony_ci irq_hw_number_t hwirq = irqd_to_hwirq(d); 7028c2ecf20Sopenharmony_ci 7038c2ecf20Sopenharmony_ci if (!(type & IRQ_TYPE_EDGE_BOTH)) { 7048c2ecf20Sopenharmony_ci dev_err(&chip->client->dev, "irq %d: unsupported type %d\n", 7058c2ecf20Sopenharmony_ci d->irq, type); 7068c2ecf20Sopenharmony_ci return -EINVAL; 7078c2ecf20Sopenharmony_ci } 7088c2ecf20Sopenharmony_ci 7098c2ecf20Sopenharmony_ci assign_bit(hwirq, chip->irq_trig_fall, type & IRQ_TYPE_EDGE_FALLING); 7108c2ecf20Sopenharmony_ci assign_bit(hwirq, chip->irq_trig_raise, type & IRQ_TYPE_EDGE_RISING); 7118c2ecf20Sopenharmony_ci 7128c2ecf20Sopenharmony_ci return 0; 7138c2ecf20Sopenharmony_ci} 7148c2ecf20Sopenharmony_ci 7158c2ecf20Sopenharmony_cistatic void pca953x_irq_shutdown(struct irq_data *d) 7168c2ecf20Sopenharmony_ci{ 7178c2ecf20Sopenharmony_ci struct gpio_chip *gc = irq_data_get_irq_chip_data(d); 7188c2ecf20Sopenharmony_ci struct pca953x_chip *chip = gpiochip_get_data(gc); 7198c2ecf20Sopenharmony_ci irq_hw_number_t hwirq = irqd_to_hwirq(d); 7208c2ecf20Sopenharmony_ci 7218c2ecf20Sopenharmony_ci clear_bit(hwirq, chip->irq_trig_raise); 7228c2ecf20Sopenharmony_ci clear_bit(hwirq, chip->irq_trig_fall); 7238c2ecf20Sopenharmony_ci} 7248c2ecf20Sopenharmony_ci 7258c2ecf20Sopenharmony_cistatic bool pca953x_irq_pending(struct pca953x_chip *chip, unsigned long *pending) 7268c2ecf20Sopenharmony_ci{ 7278c2ecf20Sopenharmony_ci struct gpio_chip *gc = &chip->gpio_chip; 7288c2ecf20Sopenharmony_ci DECLARE_BITMAP(reg_direction, MAX_LINE); 7298c2ecf20Sopenharmony_ci DECLARE_BITMAP(old_stat, MAX_LINE); 7308c2ecf20Sopenharmony_ci DECLARE_BITMAP(cur_stat, MAX_LINE); 7318c2ecf20Sopenharmony_ci DECLARE_BITMAP(new_stat, MAX_LINE); 7328c2ecf20Sopenharmony_ci DECLARE_BITMAP(trigger, MAX_LINE); 7338c2ecf20Sopenharmony_ci int ret; 7348c2ecf20Sopenharmony_ci 7358c2ecf20Sopenharmony_ci if (chip->driver_data & PCA_PCAL) { 7368c2ecf20Sopenharmony_ci /* Read the current interrupt status from the device */ 7378c2ecf20Sopenharmony_ci ret = pca953x_read_regs(chip, PCAL953X_INT_STAT, trigger); 7388c2ecf20Sopenharmony_ci if (ret) 7398c2ecf20Sopenharmony_ci return false; 7408c2ecf20Sopenharmony_ci 7418c2ecf20Sopenharmony_ci /* Check latched inputs and clear interrupt status */ 7428c2ecf20Sopenharmony_ci ret = pca953x_read_regs(chip, chip->regs->input, cur_stat); 7438c2ecf20Sopenharmony_ci if (ret) 7448c2ecf20Sopenharmony_ci return false; 7458c2ecf20Sopenharmony_ci 7468c2ecf20Sopenharmony_ci /* Apply filter for rising/falling edge selection */ 7478c2ecf20Sopenharmony_ci bitmap_replace(new_stat, chip->irq_trig_fall, chip->irq_trig_raise, cur_stat, gc->ngpio); 7488c2ecf20Sopenharmony_ci 7498c2ecf20Sopenharmony_ci bitmap_and(pending, new_stat, trigger, gc->ngpio); 7508c2ecf20Sopenharmony_ci 7518c2ecf20Sopenharmony_ci return !bitmap_empty(pending, gc->ngpio); 7528c2ecf20Sopenharmony_ci } 7538c2ecf20Sopenharmony_ci 7548c2ecf20Sopenharmony_ci ret = pca953x_read_regs(chip, chip->regs->input, cur_stat); 7558c2ecf20Sopenharmony_ci if (ret) 7568c2ecf20Sopenharmony_ci return false; 7578c2ecf20Sopenharmony_ci 7588c2ecf20Sopenharmony_ci /* Remove output pins from the equation */ 7598c2ecf20Sopenharmony_ci pca953x_read_regs(chip, chip->regs->direction, reg_direction); 7608c2ecf20Sopenharmony_ci 7618c2ecf20Sopenharmony_ci bitmap_copy(old_stat, chip->irq_stat, gc->ngpio); 7628c2ecf20Sopenharmony_ci 7638c2ecf20Sopenharmony_ci bitmap_and(new_stat, cur_stat, reg_direction, gc->ngpio); 7648c2ecf20Sopenharmony_ci bitmap_xor(cur_stat, new_stat, old_stat, gc->ngpio); 7658c2ecf20Sopenharmony_ci bitmap_and(trigger, cur_stat, chip->irq_mask, gc->ngpio); 7668c2ecf20Sopenharmony_ci 7678c2ecf20Sopenharmony_ci bitmap_copy(chip->irq_stat, new_stat, gc->ngpio); 7688c2ecf20Sopenharmony_ci 7698c2ecf20Sopenharmony_ci if (bitmap_empty(trigger, gc->ngpio)) 7708c2ecf20Sopenharmony_ci return false; 7718c2ecf20Sopenharmony_ci 7728c2ecf20Sopenharmony_ci bitmap_and(cur_stat, chip->irq_trig_fall, old_stat, gc->ngpio); 7738c2ecf20Sopenharmony_ci bitmap_and(old_stat, chip->irq_trig_raise, new_stat, gc->ngpio); 7748c2ecf20Sopenharmony_ci bitmap_or(new_stat, old_stat, cur_stat, gc->ngpio); 7758c2ecf20Sopenharmony_ci bitmap_and(pending, new_stat, trigger, gc->ngpio); 7768c2ecf20Sopenharmony_ci 7778c2ecf20Sopenharmony_ci return !bitmap_empty(pending, gc->ngpio); 7788c2ecf20Sopenharmony_ci} 7798c2ecf20Sopenharmony_ci 7808c2ecf20Sopenharmony_cistatic irqreturn_t pca953x_irq_handler(int irq, void *devid) 7818c2ecf20Sopenharmony_ci{ 7828c2ecf20Sopenharmony_ci struct pca953x_chip *chip = devid; 7838c2ecf20Sopenharmony_ci struct gpio_chip *gc = &chip->gpio_chip; 7848c2ecf20Sopenharmony_ci DECLARE_BITMAP(pending, MAX_LINE); 7858c2ecf20Sopenharmony_ci int level; 7868c2ecf20Sopenharmony_ci bool ret; 7878c2ecf20Sopenharmony_ci 7888c2ecf20Sopenharmony_ci bitmap_zero(pending, MAX_LINE); 7898c2ecf20Sopenharmony_ci 7908c2ecf20Sopenharmony_ci mutex_lock(&chip->i2c_lock); 7918c2ecf20Sopenharmony_ci ret = pca953x_irq_pending(chip, pending); 7928c2ecf20Sopenharmony_ci mutex_unlock(&chip->i2c_lock); 7938c2ecf20Sopenharmony_ci 7948c2ecf20Sopenharmony_ci if (ret) { 7958c2ecf20Sopenharmony_ci ret = 0; 7968c2ecf20Sopenharmony_ci 7978c2ecf20Sopenharmony_ci for_each_set_bit(level, pending, gc->ngpio) { 7988c2ecf20Sopenharmony_ci int nested_irq = irq_find_mapping(gc->irq.domain, level); 7998c2ecf20Sopenharmony_ci 8008c2ecf20Sopenharmony_ci if (unlikely(nested_irq <= 0)) { 8018c2ecf20Sopenharmony_ci dev_warn_ratelimited(gc->parent, "unmapped interrupt %d\n", level); 8028c2ecf20Sopenharmony_ci continue; 8038c2ecf20Sopenharmony_ci } 8048c2ecf20Sopenharmony_ci 8058c2ecf20Sopenharmony_ci handle_nested_irq(nested_irq); 8068c2ecf20Sopenharmony_ci ret = 1; 8078c2ecf20Sopenharmony_ci } 8088c2ecf20Sopenharmony_ci } 8098c2ecf20Sopenharmony_ci 8108c2ecf20Sopenharmony_ci return IRQ_RETVAL(ret); 8118c2ecf20Sopenharmony_ci} 8128c2ecf20Sopenharmony_ci 8138c2ecf20Sopenharmony_cistatic int pca953x_irq_setup(struct pca953x_chip *chip, int irq_base) 8148c2ecf20Sopenharmony_ci{ 8158c2ecf20Sopenharmony_ci struct i2c_client *client = chip->client; 8168c2ecf20Sopenharmony_ci struct irq_chip *irq_chip = &chip->irq_chip; 8178c2ecf20Sopenharmony_ci DECLARE_BITMAP(reg_direction, MAX_LINE); 8188c2ecf20Sopenharmony_ci DECLARE_BITMAP(irq_stat, MAX_LINE); 8198c2ecf20Sopenharmony_ci struct gpio_irq_chip *girq; 8208c2ecf20Sopenharmony_ci int ret; 8218c2ecf20Sopenharmony_ci 8228c2ecf20Sopenharmony_ci if (dmi_first_match(pca953x_dmi_acpi_irq_info)) { 8238c2ecf20Sopenharmony_ci ret = pca953x_acpi_get_irq(&client->dev); 8248c2ecf20Sopenharmony_ci if (ret > 0) 8258c2ecf20Sopenharmony_ci client->irq = ret; 8268c2ecf20Sopenharmony_ci } 8278c2ecf20Sopenharmony_ci 8288c2ecf20Sopenharmony_ci if (!client->irq) 8298c2ecf20Sopenharmony_ci return 0; 8308c2ecf20Sopenharmony_ci 8318c2ecf20Sopenharmony_ci if (irq_base == -1) 8328c2ecf20Sopenharmony_ci return 0; 8338c2ecf20Sopenharmony_ci 8348c2ecf20Sopenharmony_ci if (!(chip->driver_data & PCA_INT)) 8358c2ecf20Sopenharmony_ci return 0; 8368c2ecf20Sopenharmony_ci 8378c2ecf20Sopenharmony_ci ret = pca953x_read_regs(chip, chip->regs->input, irq_stat); 8388c2ecf20Sopenharmony_ci if (ret) 8398c2ecf20Sopenharmony_ci return ret; 8408c2ecf20Sopenharmony_ci 8418c2ecf20Sopenharmony_ci /* 8428c2ecf20Sopenharmony_ci * There is no way to know which GPIO line generated the 8438c2ecf20Sopenharmony_ci * interrupt. We have to rely on the previous read for 8448c2ecf20Sopenharmony_ci * this purpose. 8458c2ecf20Sopenharmony_ci */ 8468c2ecf20Sopenharmony_ci pca953x_read_regs(chip, chip->regs->direction, reg_direction); 8478c2ecf20Sopenharmony_ci bitmap_and(chip->irq_stat, irq_stat, reg_direction, chip->gpio_chip.ngpio); 8488c2ecf20Sopenharmony_ci mutex_init(&chip->irq_lock); 8498c2ecf20Sopenharmony_ci 8508c2ecf20Sopenharmony_ci irq_chip->name = dev_name(&client->dev); 8518c2ecf20Sopenharmony_ci irq_chip->irq_mask = pca953x_irq_mask; 8528c2ecf20Sopenharmony_ci irq_chip->irq_unmask = pca953x_irq_unmask; 8538c2ecf20Sopenharmony_ci irq_chip->irq_set_wake = pca953x_irq_set_wake; 8548c2ecf20Sopenharmony_ci irq_chip->irq_bus_lock = pca953x_irq_bus_lock; 8558c2ecf20Sopenharmony_ci irq_chip->irq_bus_sync_unlock = pca953x_irq_bus_sync_unlock; 8568c2ecf20Sopenharmony_ci irq_chip->irq_set_type = pca953x_irq_set_type; 8578c2ecf20Sopenharmony_ci irq_chip->irq_shutdown = pca953x_irq_shutdown; 8588c2ecf20Sopenharmony_ci 8598c2ecf20Sopenharmony_ci girq = &chip->gpio_chip.irq; 8608c2ecf20Sopenharmony_ci girq->chip = irq_chip; 8618c2ecf20Sopenharmony_ci /* This will let us handle the parent IRQ in the driver */ 8628c2ecf20Sopenharmony_ci girq->parent_handler = NULL; 8638c2ecf20Sopenharmony_ci girq->num_parents = 0; 8648c2ecf20Sopenharmony_ci girq->parents = NULL; 8658c2ecf20Sopenharmony_ci girq->default_type = IRQ_TYPE_NONE; 8668c2ecf20Sopenharmony_ci girq->handler = handle_simple_irq; 8678c2ecf20Sopenharmony_ci girq->threaded = true; 8688c2ecf20Sopenharmony_ci girq->first = irq_base; /* FIXME: get rid of this */ 8698c2ecf20Sopenharmony_ci 8708c2ecf20Sopenharmony_ci ret = devm_request_threaded_irq(&client->dev, client->irq, 8718c2ecf20Sopenharmony_ci NULL, pca953x_irq_handler, 8728c2ecf20Sopenharmony_ci IRQF_ONESHOT | IRQF_SHARED, 8738c2ecf20Sopenharmony_ci dev_name(&client->dev), chip); 8748c2ecf20Sopenharmony_ci if (ret) { 8758c2ecf20Sopenharmony_ci dev_err(&client->dev, "failed to request irq %d\n", 8768c2ecf20Sopenharmony_ci client->irq); 8778c2ecf20Sopenharmony_ci return ret; 8788c2ecf20Sopenharmony_ci } 8798c2ecf20Sopenharmony_ci 8808c2ecf20Sopenharmony_ci return 0; 8818c2ecf20Sopenharmony_ci} 8828c2ecf20Sopenharmony_ci 8838c2ecf20Sopenharmony_ci#else /* CONFIG_GPIO_PCA953X_IRQ */ 8848c2ecf20Sopenharmony_cistatic int pca953x_irq_setup(struct pca953x_chip *chip, 8858c2ecf20Sopenharmony_ci int irq_base) 8868c2ecf20Sopenharmony_ci{ 8878c2ecf20Sopenharmony_ci struct i2c_client *client = chip->client; 8888c2ecf20Sopenharmony_ci 8898c2ecf20Sopenharmony_ci if (client->irq && irq_base != -1 && (chip->driver_data & PCA_INT)) 8908c2ecf20Sopenharmony_ci dev_warn(&client->dev, "interrupt support not compiled in\n"); 8918c2ecf20Sopenharmony_ci 8928c2ecf20Sopenharmony_ci return 0; 8938c2ecf20Sopenharmony_ci} 8948c2ecf20Sopenharmony_ci#endif 8958c2ecf20Sopenharmony_ci 8968c2ecf20Sopenharmony_cistatic int device_pca95xx_init(struct pca953x_chip *chip, u32 invert) 8978c2ecf20Sopenharmony_ci{ 8988c2ecf20Sopenharmony_ci DECLARE_BITMAP(val, MAX_LINE); 8998c2ecf20Sopenharmony_ci u8 regaddr; 9008c2ecf20Sopenharmony_ci int ret; 9018c2ecf20Sopenharmony_ci 9028c2ecf20Sopenharmony_ci regaddr = pca953x_recalc_addr(chip, chip->regs->output, 0); 9038c2ecf20Sopenharmony_ci ret = regcache_sync_region(chip->regmap, regaddr, 9048c2ecf20Sopenharmony_ci regaddr + NBANK(chip) - 1); 9058c2ecf20Sopenharmony_ci if (ret) 9068c2ecf20Sopenharmony_ci goto out; 9078c2ecf20Sopenharmony_ci 9088c2ecf20Sopenharmony_ci regaddr = pca953x_recalc_addr(chip, chip->regs->direction, 0); 9098c2ecf20Sopenharmony_ci ret = regcache_sync_region(chip->regmap, regaddr, 9108c2ecf20Sopenharmony_ci regaddr + NBANK(chip) - 1); 9118c2ecf20Sopenharmony_ci if (ret) 9128c2ecf20Sopenharmony_ci goto out; 9138c2ecf20Sopenharmony_ci 9148c2ecf20Sopenharmony_ci /* set platform specific polarity inversion */ 9158c2ecf20Sopenharmony_ci if (invert) 9168c2ecf20Sopenharmony_ci bitmap_fill(val, MAX_LINE); 9178c2ecf20Sopenharmony_ci else 9188c2ecf20Sopenharmony_ci bitmap_zero(val, MAX_LINE); 9198c2ecf20Sopenharmony_ci 9208c2ecf20Sopenharmony_ci ret = pca953x_write_regs(chip, chip->regs->invert, val); 9218c2ecf20Sopenharmony_ciout: 9228c2ecf20Sopenharmony_ci return ret; 9238c2ecf20Sopenharmony_ci} 9248c2ecf20Sopenharmony_ci 9258c2ecf20Sopenharmony_cistatic int device_pca957x_init(struct pca953x_chip *chip, u32 invert) 9268c2ecf20Sopenharmony_ci{ 9278c2ecf20Sopenharmony_ci DECLARE_BITMAP(val, MAX_LINE); 9288c2ecf20Sopenharmony_ci unsigned int i; 9298c2ecf20Sopenharmony_ci int ret; 9308c2ecf20Sopenharmony_ci 9318c2ecf20Sopenharmony_ci ret = device_pca95xx_init(chip, invert); 9328c2ecf20Sopenharmony_ci if (ret) 9338c2ecf20Sopenharmony_ci goto out; 9348c2ecf20Sopenharmony_ci 9358c2ecf20Sopenharmony_ci /* To enable register 6, 7 to control pull up and pull down */ 9368c2ecf20Sopenharmony_ci for (i = 0; i < NBANK(chip); i++) 9378c2ecf20Sopenharmony_ci bitmap_set_value8(val, 0x02, i * BANK_SZ); 9388c2ecf20Sopenharmony_ci 9398c2ecf20Sopenharmony_ci ret = pca953x_write_regs(chip, PCA957X_BKEN, val); 9408c2ecf20Sopenharmony_ci if (ret) 9418c2ecf20Sopenharmony_ci goto out; 9428c2ecf20Sopenharmony_ci 9438c2ecf20Sopenharmony_ci return 0; 9448c2ecf20Sopenharmony_ciout: 9458c2ecf20Sopenharmony_ci return ret; 9468c2ecf20Sopenharmony_ci} 9478c2ecf20Sopenharmony_ci 9488c2ecf20Sopenharmony_cistatic int pca953x_probe(struct i2c_client *client, 9498c2ecf20Sopenharmony_ci const struct i2c_device_id *i2c_id) 9508c2ecf20Sopenharmony_ci{ 9518c2ecf20Sopenharmony_ci struct pca953x_platform_data *pdata; 9528c2ecf20Sopenharmony_ci struct pca953x_chip *chip; 9538c2ecf20Sopenharmony_ci int irq_base = 0; 9548c2ecf20Sopenharmony_ci int ret; 9558c2ecf20Sopenharmony_ci u32 invert = 0; 9568c2ecf20Sopenharmony_ci struct regulator *reg; 9578c2ecf20Sopenharmony_ci const struct regmap_config *regmap_config; 9588c2ecf20Sopenharmony_ci 9598c2ecf20Sopenharmony_ci chip = devm_kzalloc(&client->dev, sizeof(*chip), GFP_KERNEL); 9608c2ecf20Sopenharmony_ci if (chip == NULL) 9618c2ecf20Sopenharmony_ci return -ENOMEM; 9628c2ecf20Sopenharmony_ci 9638c2ecf20Sopenharmony_ci pdata = dev_get_platdata(&client->dev); 9648c2ecf20Sopenharmony_ci if (pdata) { 9658c2ecf20Sopenharmony_ci irq_base = pdata->irq_base; 9668c2ecf20Sopenharmony_ci chip->gpio_start = pdata->gpio_base; 9678c2ecf20Sopenharmony_ci invert = pdata->invert; 9688c2ecf20Sopenharmony_ci chip->names = pdata->names; 9698c2ecf20Sopenharmony_ci } else { 9708c2ecf20Sopenharmony_ci struct gpio_desc *reset_gpio; 9718c2ecf20Sopenharmony_ci 9728c2ecf20Sopenharmony_ci chip->gpio_start = -1; 9738c2ecf20Sopenharmony_ci irq_base = 0; 9748c2ecf20Sopenharmony_ci 9758c2ecf20Sopenharmony_ci /* 9768c2ecf20Sopenharmony_ci * See if we need to de-assert a reset pin. 9778c2ecf20Sopenharmony_ci * 9788c2ecf20Sopenharmony_ci * There is no known ACPI-enabled platforms that are 9798c2ecf20Sopenharmony_ci * using "reset" GPIO. Otherwise any of those platform 9808c2ecf20Sopenharmony_ci * must use _DSD method with corresponding property. 9818c2ecf20Sopenharmony_ci */ 9828c2ecf20Sopenharmony_ci reset_gpio = devm_gpiod_get_optional(&client->dev, "reset", 9838c2ecf20Sopenharmony_ci GPIOD_OUT_LOW); 9848c2ecf20Sopenharmony_ci if (IS_ERR(reset_gpio)) 9858c2ecf20Sopenharmony_ci return PTR_ERR(reset_gpio); 9868c2ecf20Sopenharmony_ci } 9878c2ecf20Sopenharmony_ci 9888c2ecf20Sopenharmony_ci chip->client = client; 9898c2ecf20Sopenharmony_ci 9908c2ecf20Sopenharmony_ci reg = devm_regulator_get(&client->dev, "vcc"); 9918c2ecf20Sopenharmony_ci if (IS_ERR(reg)) 9928c2ecf20Sopenharmony_ci return dev_err_probe(&client->dev, PTR_ERR(reg), "reg get err\n"); 9938c2ecf20Sopenharmony_ci 9948c2ecf20Sopenharmony_ci ret = regulator_enable(reg); 9958c2ecf20Sopenharmony_ci if (ret) { 9968c2ecf20Sopenharmony_ci dev_err(&client->dev, "reg en err: %d\n", ret); 9978c2ecf20Sopenharmony_ci return ret; 9988c2ecf20Sopenharmony_ci } 9998c2ecf20Sopenharmony_ci chip->regulator = reg; 10008c2ecf20Sopenharmony_ci 10018c2ecf20Sopenharmony_ci if (i2c_id) { 10028c2ecf20Sopenharmony_ci chip->driver_data = i2c_id->driver_data; 10038c2ecf20Sopenharmony_ci } else { 10048c2ecf20Sopenharmony_ci const void *match; 10058c2ecf20Sopenharmony_ci 10068c2ecf20Sopenharmony_ci match = device_get_match_data(&client->dev); 10078c2ecf20Sopenharmony_ci if (!match) { 10088c2ecf20Sopenharmony_ci ret = -ENODEV; 10098c2ecf20Sopenharmony_ci goto err_exit; 10108c2ecf20Sopenharmony_ci } 10118c2ecf20Sopenharmony_ci 10128c2ecf20Sopenharmony_ci chip->driver_data = (uintptr_t)match; 10138c2ecf20Sopenharmony_ci } 10148c2ecf20Sopenharmony_ci 10158c2ecf20Sopenharmony_ci i2c_set_clientdata(client, chip); 10168c2ecf20Sopenharmony_ci 10178c2ecf20Sopenharmony_ci pca953x_setup_gpio(chip, chip->driver_data & PCA_GPIO_MASK); 10188c2ecf20Sopenharmony_ci 10198c2ecf20Sopenharmony_ci if (NBANK(chip) > 2 || PCA_CHIP_TYPE(chip->driver_data) == PCA957X_TYPE) { 10208c2ecf20Sopenharmony_ci dev_info(&client->dev, "using AI\n"); 10218c2ecf20Sopenharmony_ci regmap_config = &pca953x_ai_i2c_regmap; 10228c2ecf20Sopenharmony_ci } else { 10238c2ecf20Sopenharmony_ci dev_info(&client->dev, "using no AI\n"); 10248c2ecf20Sopenharmony_ci regmap_config = &pca953x_i2c_regmap; 10258c2ecf20Sopenharmony_ci } 10268c2ecf20Sopenharmony_ci 10278c2ecf20Sopenharmony_ci chip->regmap = devm_regmap_init_i2c(client, regmap_config); 10288c2ecf20Sopenharmony_ci if (IS_ERR(chip->regmap)) { 10298c2ecf20Sopenharmony_ci ret = PTR_ERR(chip->regmap); 10308c2ecf20Sopenharmony_ci goto err_exit; 10318c2ecf20Sopenharmony_ci } 10328c2ecf20Sopenharmony_ci 10338c2ecf20Sopenharmony_ci regcache_mark_dirty(chip->regmap); 10348c2ecf20Sopenharmony_ci 10358c2ecf20Sopenharmony_ci mutex_init(&chip->i2c_lock); 10368c2ecf20Sopenharmony_ci /* 10378c2ecf20Sopenharmony_ci * In case we have an i2c-mux controlled by a GPIO provided by an 10388c2ecf20Sopenharmony_ci * expander using the same driver higher on the device tree, read the 10398c2ecf20Sopenharmony_ci * i2c adapter nesting depth and use the retrieved value as lockdep 10408c2ecf20Sopenharmony_ci * subclass for chip->i2c_lock. 10418c2ecf20Sopenharmony_ci * 10428c2ecf20Sopenharmony_ci * REVISIT: This solution is not complete. It protects us from lockdep 10438c2ecf20Sopenharmony_ci * false positives when the expander controlling the i2c-mux is on 10448c2ecf20Sopenharmony_ci * a different level on the device tree, but not when it's on the same 10458c2ecf20Sopenharmony_ci * level on a different branch (in which case the subclass number 10468c2ecf20Sopenharmony_ci * would be the same). 10478c2ecf20Sopenharmony_ci * 10488c2ecf20Sopenharmony_ci * TODO: Once a correct solution is developed, a similar fix should be 10498c2ecf20Sopenharmony_ci * applied to all other i2c-controlled GPIO expanders (and potentially 10508c2ecf20Sopenharmony_ci * regmap-i2c). 10518c2ecf20Sopenharmony_ci */ 10528c2ecf20Sopenharmony_ci lockdep_set_subclass(&chip->i2c_lock, 10538c2ecf20Sopenharmony_ci i2c_adapter_depth(client->adapter)); 10548c2ecf20Sopenharmony_ci 10558c2ecf20Sopenharmony_ci /* initialize cached registers from their original values. 10568c2ecf20Sopenharmony_ci * we can't share this chip with another i2c master. 10578c2ecf20Sopenharmony_ci */ 10588c2ecf20Sopenharmony_ci 10598c2ecf20Sopenharmony_ci if (PCA_CHIP_TYPE(chip->driver_data) == PCA953X_TYPE) { 10608c2ecf20Sopenharmony_ci chip->regs = &pca953x_regs; 10618c2ecf20Sopenharmony_ci ret = device_pca95xx_init(chip, invert); 10628c2ecf20Sopenharmony_ci } else { 10638c2ecf20Sopenharmony_ci chip->regs = &pca957x_regs; 10648c2ecf20Sopenharmony_ci ret = device_pca957x_init(chip, invert); 10658c2ecf20Sopenharmony_ci } 10668c2ecf20Sopenharmony_ci if (ret) 10678c2ecf20Sopenharmony_ci goto err_exit; 10688c2ecf20Sopenharmony_ci 10698c2ecf20Sopenharmony_ci ret = pca953x_irq_setup(chip, irq_base); 10708c2ecf20Sopenharmony_ci if (ret) 10718c2ecf20Sopenharmony_ci goto err_exit; 10728c2ecf20Sopenharmony_ci 10738c2ecf20Sopenharmony_ci ret = devm_gpiochip_add_data(&client->dev, &chip->gpio_chip, chip); 10748c2ecf20Sopenharmony_ci if (ret) 10758c2ecf20Sopenharmony_ci goto err_exit; 10768c2ecf20Sopenharmony_ci 10778c2ecf20Sopenharmony_ci if (pdata && pdata->setup) { 10788c2ecf20Sopenharmony_ci ret = pdata->setup(client, chip->gpio_chip.base, 10798c2ecf20Sopenharmony_ci chip->gpio_chip.ngpio, pdata->context); 10808c2ecf20Sopenharmony_ci if (ret < 0) 10818c2ecf20Sopenharmony_ci dev_warn(&client->dev, "setup failed, %d\n", ret); 10828c2ecf20Sopenharmony_ci } 10838c2ecf20Sopenharmony_ci 10848c2ecf20Sopenharmony_ci return 0; 10858c2ecf20Sopenharmony_ci 10868c2ecf20Sopenharmony_cierr_exit: 10878c2ecf20Sopenharmony_ci regulator_disable(chip->regulator); 10888c2ecf20Sopenharmony_ci return ret; 10898c2ecf20Sopenharmony_ci} 10908c2ecf20Sopenharmony_ci 10918c2ecf20Sopenharmony_cistatic int pca953x_remove(struct i2c_client *client) 10928c2ecf20Sopenharmony_ci{ 10938c2ecf20Sopenharmony_ci struct pca953x_platform_data *pdata = dev_get_platdata(&client->dev); 10948c2ecf20Sopenharmony_ci struct pca953x_chip *chip = i2c_get_clientdata(client); 10958c2ecf20Sopenharmony_ci int ret; 10968c2ecf20Sopenharmony_ci 10978c2ecf20Sopenharmony_ci if (pdata && pdata->teardown) { 10988c2ecf20Sopenharmony_ci ret = pdata->teardown(client, chip->gpio_chip.base, 10998c2ecf20Sopenharmony_ci chip->gpio_chip.ngpio, pdata->context); 11008c2ecf20Sopenharmony_ci if (ret < 0) 11018c2ecf20Sopenharmony_ci dev_err(&client->dev, "teardown failed, %d\n", ret); 11028c2ecf20Sopenharmony_ci } else { 11038c2ecf20Sopenharmony_ci ret = 0; 11048c2ecf20Sopenharmony_ci } 11058c2ecf20Sopenharmony_ci 11068c2ecf20Sopenharmony_ci regulator_disable(chip->regulator); 11078c2ecf20Sopenharmony_ci 11088c2ecf20Sopenharmony_ci return ret; 11098c2ecf20Sopenharmony_ci} 11108c2ecf20Sopenharmony_ci 11118c2ecf20Sopenharmony_ci#ifdef CONFIG_PM_SLEEP 11128c2ecf20Sopenharmony_cistatic int pca953x_regcache_sync(struct device *dev) 11138c2ecf20Sopenharmony_ci{ 11148c2ecf20Sopenharmony_ci struct pca953x_chip *chip = dev_get_drvdata(dev); 11158c2ecf20Sopenharmony_ci int ret; 11168c2ecf20Sopenharmony_ci u8 regaddr; 11178c2ecf20Sopenharmony_ci 11188c2ecf20Sopenharmony_ci /* 11198c2ecf20Sopenharmony_ci * The ordering between direction and output is important, 11208c2ecf20Sopenharmony_ci * sync these registers first and only then sync the rest. 11218c2ecf20Sopenharmony_ci */ 11228c2ecf20Sopenharmony_ci regaddr = pca953x_recalc_addr(chip, chip->regs->direction, 0); 11238c2ecf20Sopenharmony_ci ret = regcache_sync_region(chip->regmap, regaddr, regaddr + NBANK(chip) - 1); 11248c2ecf20Sopenharmony_ci if (ret) { 11258c2ecf20Sopenharmony_ci dev_err(dev, "Failed to sync GPIO dir registers: %d\n", ret); 11268c2ecf20Sopenharmony_ci return ret; 11278c2ecf20Sopenharmony_ci } 11288c2ecf20Sopenharmony_ci 11298c2ecf20Sopenharmony_ci regaddr = pca953x_recalc_addr(chip, chip->regs->output, 0); 11308c2ecf20Sopenharmony_ci ret = regcache_sync_region(chip->regmap, regaddr, regaddr + NBANK(chip) - 1); 11318c2ecf20Sopenharmony_ci if (ret) { 11328c2ecf20Sopenharmony_ci dev_err(dev, "Failed to sync GPIO out registers: %d\n", ret); 11338c2ecf20Sopenharmony_ci return ret; 11348c2ecf20Sopenharmony_ci } 11358c2ecf20Sopenharmony_ci 11368c2ecf20Sopenharmony_ci#ifdef CONFIG_GPIO_PCA953X_IRQ 11378c2ecf20Sopenharmony_ci if (chip->driver_data & PCA_PCAL) { 11388c2ecf20Sopenharmony_ci regaddr = pca953x_recalc_addr(chip, PCAL953X_IN_LATCH, 0); 11398c2ecf20Sopenharmony_ci ret = regcache_sync_region(chip->regmap, regaddr, 11408c2ecf20Sopenharmony_ci regaddr + NBANK(chip) - 1); 11418c2ecf20Sopenharmony_ci if (ret) { 11428c2ecf20Sopenharmony_ci dev_err(dev, "Failed to sync INT latch registers: %d\n", 11438c2ecf20Sopenharmony_ci ret); 11448c2ecf20Sopenharmony_ci return ret; 11458c2ecf20Sopenharmony_ci } 11468c2ecf20Sopenharmony_ci 11478c2ecf20Sopenharmony_ci regaddr = pca953x_recalc_addr(chip, PCAL953X_INT_MASK, 0); 11488c2ecf20Sopenharmony_ci ret = regcache_sync_region(chip->regmap, regaddr, 11498c2ecf20Sopenharmony_ci regaddr + NBANK(chip) - 1); 11508c2ecf20Sopenharmony_ci if (ret) { 11518c2ecf20Sopenharmony_ci dev_err(dev, "Failed to sync INT mask registers: %d\n", 11528c2ecf20Sopenharmony_ci ret); 11538c2ecf20Sopenharmony_ci return ret; 11548c2ecf20Sopenharmony_ci } 11558c2ecf20Sopenharmony_ci } 11568c2ecf20Sopenharmony_ci#endif 11578c2ecf20Sopenharmony_ci 11588c2ecf20Sopenharmony_ci return 0; 11598c2ecf20Sopenharmony_ci} 11608c2ecf20Sopenharmony_ci 11618c2ecf20Sopenharmony_cistatic int pca953x_suspend(struct device *dev) 11628c2ecf20Sopenharmony_ci{ 11638c2ecf20Sopenharmony_ci struct pca953x_chip *chip = dev_get_drvdata(dev); 11648c2ecf20Sopenharmony_ci 11658c2ecf20Sopenharmony_ci mutex_lock(&chip->i2c_lock); 11668c2ecf20Sopenharmony_ci regcache_cache_only(chip->regmap, true); 11678c2ecf20Sopenharmony_ci mutex_unlock(&chip->i2c_lock); 11688c2ecf20Sopenharmony_ci 11698c2ecf20Sopenharmony_ci if (atomic_read(&chip->wakeup_path)) 11708c2ecf20Sopenharmony_ci device_set_wakeup_path(dev); 11718c2ecf20Sopenharmony_ci else 11728c2ecf20Sopenharmony_ci regulator_disable(chip->regulator); 11738c2ecf20Sopenharmony_ci 11748c2ecf20Sopenharmony_ci return 0; 11758c2ecf20Sopenharmony_ci} 11768c2ecf20Sopenharmony_ci 11778c2ecf20Sopenharmony_cistatic int pca953x_resume(struct device *dev) 11788c2ecf20Sopenharmony_ci{ 11798c2ecf20Sopenharmony_ci struct pca953x_chip *chip = dev_get_drvdata(dev); 11808c2ecf20Sopenharmony_ci int ret; 11818c2ecf20Sopenharmony_ci 11828c2ecf20Sopenharmony_ci if (!atomic_read(&chip->wakeup_path)) { 11838c2ecf20Sopenharmony_ci ret = regulator_enable(chip->regulator); 11848c2ecf20Sopenharmony_ci if (ret) { 11858c2ecf20Sopenharmony_ci dev_err(dev, "Failed to enable regulator: %d\n", ret); 11868c2ecf20Sopenharmony_ci return 0; 11878c2ecf20Sopenharmony_ci } 11888c2ecf20Sopenharmony_ci } 11898c2ecf20Sopenharmony_ci 11908c2ecf20Sopenharmony_ci mutex_lock(&chip->i2c_lock); 11918c2ecf20Sopenharmony_ci regcache_cache_only(chip->regmap, false); 11928c2ecf20Sopenharmony_ci regcache_mark_dirty(chip->regmap); 11938c2ecf20Sopenharmony_ci ret = pca953x_regcache_sync(dev); 11948c2ecf20Sopenharmony_ci if (ret) { 11958c2ecf20Sopenharmony_ci mutex_unlock(&chip->i2c_lock); 11968c2ecf20Sopenharmony_ci return ret; 11978c2ecf20Sopenharmony_ci } 11988c2ecf20Sopenharmony_ci 11998c2ecf20Sopenharmony_ci ret = regcache_sync(chip->regmap); 12008c2ecf20Sopenharmony_ci mutex_unlock(&chip->i2c_lock); 12018c2ecf20Sopenharmony_ci if (ret) { 12028c2ecf20Sopenharmony_ci dev_err(dev, "Failed to restore register map: %d\n", ret); 12038c2ecf20Sopenharmony_ci return ret; 12048c2ecf20Sopenharmony_ci } 12058c2ecf20Sopenharmony_ci 12068c2ecf20Sopenharmony_ci return 0; 12078c2ecf20Sopenharmony_ci} 12088c2ecf20Sopenharmony_ci#endif 12098c2ecf20Sopenharmony_ci 12108c2ecf20Sopenharmony_ci/* convenience to stop overlong match-table lines */ 12118c2ecf20Sopenharmony_ci#define OF_953X(__nrgpio, __int) (void *)(__nrgpio | PCA953X_TYPE | __int) 12128c2ecf20Sopenharmony_ci#define OF_957X(__nrgpio, __int) (void *)(__nrgpio | PCA957X_TYPE | __int) 12138c2ecf20Sopenharmony_ci 12148c2ecf20Sopenharmony_cistatic const struct of_device_id pca953x_dt_ids[] = { 12158c2ecf20Sopenharmony_ci { .compatible = "nxp,pca6416", .data = OF_953X(16, PCA_INT), }, 12168c2ecf20Sopenharmony_ci { .compatible = "nxp,pca9505", .data = OF_953X(40, PCA_INT), }, 12178c2ecf20Sopenharmony_ci { .compatible = "nxp,pca9534", .data = OF_953X( 8, PCA_INT), }, 12188c2ecf20Sopenharmony_ci { .compatible = "nxp,pca9535", .data = OF_953X(16, PCA_INT), }, 12198c2ecf20Sopenharmony_ci { .compatible = "nxp,pca9536", .data = OF_953X( 4, 0), }, 12208c2ecf20Sopenharmony_ci { .compatible = "nxp,pca9537", .data = OF_953X( 4, PCA_INT), }, 12218c2ecf20Sopenharmony_ci { .compatible = "nxp,pca9538", .data = OF_953X( 8, PCA_INT), }, 12228c2ecf20Sopenharmony_ci { .compatible = "nxp,pca9539", .data = OF_953X(16, PCA_INT), }, 12238c2ecf20Sopenharmony_ci { .compatible = "nxp,pca9554", .data = OF_953X( 8, PCA_INT), }, 12248c2ecf20Sopenharmony_ci { .compatible = "nxp,pca9555", .data = OF_953X(16, PCA_INT), }, 12258c2ecf20Sopenharmony_ci { .compatible = "nxp,pca9556", .data = OF_953X( 8, 0), }, 12268c2ecf20Sopenharmony_ci { .compatible = "nxp,pca9557", .data = OF_953X( 8, 0), }, 12278c2ecf20Sopenharmony_ci { .compatible = "nxp,pca9574", .data = OF_957X( 8, PCA_INT), }, 12288c2ecf20Sopenharmony_ci { .compatible = "nxp,pca9575", .data = OF_957X(16, PCA_INT), }, 12298c2ecf20Sopenharmony_ci { .compatible = "nxp,pca9698", .data = OF_953X(40, 0), }, 12308c2ecf20Sopenharmony_ci 12318c2ecf20Sopenharmony_ci { .compatible = "nxp,pcal6416", .data = OF_953X(16, PCA_LATCH_INT), }, 12328c2ecf20Sopenharmony_ci { .compatible = "nxp,pcal6524", .data = OF_953X(24, PCA_LATCH_INT), }, 12338c2ecf20Sopenharmony_ci { .compatible = "nxp,pcal9535", .data = OF_953X(16, PCA_LATCH_INT), }, 12348c2ecf20Sopenharmony_ci { .compatible = "nxp,pcal9554b", .data = OF_953X( 8, PCA_LATCH_INT), }, 12358c2ecf20Sopenharmony_ci { .compatible = "nxp,pcal9555a", .data = OF_953X(16, PCA_LATCH_INT), }, 12368c2ecf20Sopenharmony_ci 12378c2ecf20Sopenharmony_ci { .compatible = "maxim,max7310", .data = OF_953X( 8, 0), }, 12388c2ecf20Sopenharmony_ci { .compatible = "maxim,max7312", .data = OF_953X(16, PCA_INT), }, 12398c2ecf20Sopenharmony_ci { .compatible = "maxim,max7313", .data = OF_953X(16, PCA_INT), }, 12408c2ecf20Sopenharmony_ci { .compatible = "maxim,max7315", .data = OF_953X( 8, PCA_INT), }, 12418c2ecf20Sopenharmony_ci { .compatible = "maxim,max7318", .data = OF_953X(16, PCA_INT), }, 12428c2ecf20Sopenharmony_ci 12438c2ecf20Sopenharmony_ci { .compatible = "ti,pca6107", .data = OF_953X( 8, PCA_INT), }, 12448c2ecf20Sopenharmony_ci { .compatible = "ti,pca9536", .data = OF_953X( 4, 0), }, 12458c2ecf20Sopenharmony_ci { .compatible = "ti,tca6408", .data = OF_953X( 8, PCA_INT), }, 12468c2ecf20Sopenharmony_ci { .compatible = "ti,tca6416", .data = OF_953X(16, PCA_INT), }, 12478c2ecf20Sopenharmony_ci { .compatible = "ti,tca6424", .data = OF_953X(24, PCA_INT), }, 12488c2ecf20Sopenharmony_ci { .compatible = "ti,tca9539", .data = OF_953X(16, PCA_INT), }, 12498c2ecf20Sopenharmony_ci 12508c2ecf20Sopenharmony_ci { .compatible = "onnn,cat9554", .data = OF_953X( 8, PCA_INT), }, 12518c2ecf20Sopenharmony_ci { .compatible = "onnn,pca9654", .data = OF_953X( 8, PCA_INT), }, 12528c2ecf20Sopenharmony_ci { .compatible = "onnn,pca9655", .data = OF_953X(16, PCA_INT), }, 12538c2ecf20Sopenharmony_ci 12548c2ecf20Sopenharmony_ci { .compatible = "exar,xra1202", .data = OF_953X( 8, 0), }, 12558c2ecf20Sopenharmony_ci { } 12568c2ecf20Sopenharmony_ci}; 12578c2ecf20Sopenharmony_ci 12588c2ecf20Sopenharmony_ciMODULE_DEVICE_TABLE(of, pca953x_dt_ids); 12598c2ecf20Sopenharmony_ci 12608c2ecf20Sopenharmony_cistatic SIMPLE_DEV_PM_OPS(pca953x_pm_ops, pca953x_suspend, pca953x_resume); 12618c2ecf20Sopenharmony_ci 12628c2ecf20Sopenharmony_cistatic struct i2c_driver pca953x_driver = { 12638c2ecf20Sopenharmony_ci .driver = { 12648c2ecf20Sopenharmony_ci .name = "pca953x", 12658c2ecf20Sopenharmony_ci .pm = &pca953x_pm_ops, 12668c2ecf20Sopenharmony_ci .of_match_table = pca953x_dt_ids, 12678c2ecf20Sopenharmony_ci .acpi_match_table = pca953x_acpi_ids, 12688c2ecf20Sopenharmony_ci }, 12698c2ecf20Sopenharmony_ci .probe = pca953x_probe, 12708c2ecf20Sopenharmony_ci .remove = pca953x_remove, 12718c2ecf20Sopenharmony_ci .id_table = pca953x_id, 12728c2ecf20Sopenharmony_ci}; 12738c2ecf20Sopenharmony_ci 12748c2ecf20Sopenharmony_cistatic int __init pca953x_init(void) 12758c2ecf20Sopenharmony_ci{ 12768c2ecf20Sopenharmony_ci return i2c_add_driver(&pca953x_driver); 12778c2ecf20Sopenharmony_ci} 12788c2ecf20Sopenharmony_ci/* register after i2c postcore initcall and before 12798c2ecf20Sopenharmony_ci * subsys initcalls that may rely on these GPIOs 12808c2ecf20Sopenharmony_ci */ 12818c2ecf20Sopenharmony_cisubsys_initcall(pca953x_init); 12828c2ecf20Sopenharmony_ci 12838c2ecf20Sopenharmony_cistatic void __exit pca953x_exit(void) 12848c2ecf20Sopenharmony_ci{ 12858c2ecf20Sopenharmony_ci i2c_del_driver(&pca953x_driver); 12868c2ecf20Sopenharmony_ci} 12878c2ecf20Sopenharmony_cimodule_exit(pca953x_exit); 12888c2ecf20Sopenharmony_ci 12898c2ecf20Sopenharmony_ciMODULE_AUTHOR("eric miao <eric.miao@marvell.com>"); 12908c2ecf20Sopenharmony_ciMODULE_DESCRIPTION("GPIO expander driver for PCA953x"); 12918c2ecf20Sopenharmony_ciMODULE_LICENSE("GPL"); 1292