18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * Intel Crystal Cove GPIO Driver 48c2ecf20Sopenharmony_ci * 58c2ecf20Sopenharmony_ci * Copyright (C) 2012, 2014 Intel Corporation. All rights reserved. 68c2ecf20Sopenharmony_ci * 78c2ecf20Sopenharmony_ci * Author: Yang, Bin <bin.yang@intel.com> 88c2ecf20Sopenharmony_ci */ 98c2ecf20Sopenharmony_ci 108c2ecf20Sopenharmony_ci#include <linux/bitops.h> 118c2ecf20Sopenharmony_ci#include <linux/gpio/driver.h> 128c2ecf20Sopenharmony_ci#include <linux/interrupt.h> 138c2ecf20Sopenharmony_ci#include <linux/mfd/intel_soc_pmic.h> 148c2ecf20Sopenharmony_ci#include <linux/module.h> 158c2ecf20Sopenharmony_ci#include <linux/platform_device.h> 168c2ecf20Sopenharmony_ci#include <linux/regmap.h> 178c2ecf20Sopenharmony_ci#include <linux/seq_file.h> 188c2ecf20Sopenharmony_ci 198c2ecf20Sopenharmony_ci#define CRYSTALCOVE_GPIO_NUM 16 208c2ecf20Sopenharmony_ci#define CRYSTALCOVE_VGPIO_NUM 95 218c2ecf20Sopenharmony_ci 228c2ecf20Sopenharmony_ci#define UPDATE_IRQ_TYPE BIT(0) 238c2ecf20Sopenharmony_ci#define UPDATE_IRQ_MASK BIT(1) 248c2ecf20Sopenharmony_ci 258c2ecf20Sopenharmony_ci#define GPIO0IRQ 0x0b 268c2ecf20Sopenharmony_ci#define GPIO1IRQ 0x0c 278c2ecf20Sopenharmony_ci#define MGPIO0IRQS0 0x19 288c2ecf20Sopenharmony_ci#define MGPIO1IRQS0 0x1a 298c2ecf20Sopenharmony_ci#define MGPIO0IRQSX 0x1b 308c2ecf20Sopenharmony_ci#define MGPIO1IRQSX 0x1c 318c2ecf20Sopenharmony_ci#define GPIO0P0CTLO 0x2b 328c2ecf20Sopenharmony_ci#define GPIO0P0CTLI 0x33 338c2ecf20Sopenharmony_ci#define GPIO1P0CTLO 0x3b 348c2ecf20Sopenharmony_ci#define GPIO1P0CTLI 0x43 358c2ecf20Sopenharmony_ci#define GPIOPANELCTL 0x52 368c2ecf20Sopenharmony_ci 378c2ecf20Sopenharmony_ci#define CTLI_INTCNT_DIS (0) 388c2ecf20Sopenharmony_ci#define CTLI_INTCNT_NE (1 << 1) 398c2ecf20Sopenharmony_ci#define CTLI_INTCNT_PE (2 << 1) 408c2ecf20Sopenharmony_ci#define CTLI_INTCNT_BE (3 << 1) 418c2ecf20Sopenharmony_ci 428c2ecf20Sopenharmony_ci#define CTLO_DIR_IN (0) 438c2ecf20Sopenharmony_ci#define CTLO_DIR_OUT (1 << 5) 448c2ecf20Sopenharmony_ci 458c2ecf20Sopenharmony_ci#define CTLO_DRV_CMOS (0) 468c2ecf20Sopenharmony_ci#define CTLO_DRV_OD (1 << 4) 478c2ecf20Sopenharmony_ci 488c2ecf20Sopenharmony_ci#define CTLO_DRV_REN (1 << 3) 498c2ecf20Sopenharmony_ci 508c2ecf20Sopenharmony_ci#define CTLO_RVAL_2KDW (0) 518c2ecf20Sopenharmony_ci#define CTLO_RVAL_2KUP (1 << 1) 528c2ecf20Sopenharmony_ci#define CTLO_RVAL_50KDW (2 << 1) 538c2ecf20Sopenharmony_ci#define CTLO_RVAL_50KUP (3 << 1) 548c2ecf20Sopenharmony_ci 558c2ecf20Sopenharmony_ci#define CTLO_INPUT_SET (CTLO_DRV_CMOS | CTLO_DRV_REN | CTLO_RVAL_2KUP) 568c2ecf20Sopenharmony_ci#define CTLO_OUTPUT_SET (CTLO_DIR_OUT | CTLO_INPUT_SET) 578c2ecf20Sopenharmony_ci 588c2ecf20Sopenharmony_cienum ctrl_register { 598c2ecf20Sopenharmony_ci CTRL_IN, 608c2ecf20Sopenharmony_ci CTRL_OUT, 618c2ecf20Sopenharmony_ci}; 628c2ecf20Sopenharmony_ci 638c2ecf20Sopenharmony_ci/** 648c2ecf20Sopenharmony_ci * struct crystalcove_gpio - Crystal Cove GPIO controller 658c2ecf20Sopenharmony_ci * @buslock: for bus lock/sync and unlock. 668c2ecf20Sopenharmony_ci * @chip: the abstract gpio_chip structure. 678c2ecf20Sopenharmony_ci * @regmap: the regmap from the parent device. 688c2ecf20Sopenharmony_ci * @update: pending IRQ setting update, to be written to the chip upon unlock. 698c2ecf20Sopenharmony_ci * @intcnt_value: the Interrupt Detect value to be written. 708c2ecf20Sopenharmony_ci * @set_irq_mask: true if the IRQ mask needs to be set, false to clear. 718c2ecf20Sopenharmony_ci */ 728c2ecf20Sopenharmony_cistruct crystalcove_gpio { 738c2ecf20Sopenharmony_ci struct mutex buslock; /* irq_bus_lock */ 748c2ecf20Sopenharmony_ci struct gpio_chip chip; 758c2ecf20Sopenharmony_ci struct regmap *regmap; 768c2ecf20Sopenharmony_ci int update; 778c2ecf20Sopenharmony_ci int intcnt_value; 788c2ecf20Sopenharmony_ci bool set_irq_mask; 798c2ecf20Sopenharmony_ci}; 808c2ecf20Sopenharmony_ci 818c2ecf20Sopenharmony_cistatic inline int to_reg(int gpio, enum ctrl_register reg_type) 828c2ecf20Sopenharmony_ci{ 838c2ecf20Sopenharmony_ci int reg; 848c2ecf20Sopenharmony_ci 858c2ecf20Sopenharmony_ci if (gpio >= CRYSTALCOVE_GPIO_NUM) { 868c2ecf20Sopenharmony_ci /* 878c2ecf20Sopenharmony_ci * Virtual GPIO called from ACPI, for now we only support 888c2ecf20Sopenharmony_ci * the panel ctl. 898c2ecf20Sopenharmony_ci */ 908c2ecf20Sopenharmony_ci switch (gpio) { 918c2ecf20Sopenharmony_ci case 0x5e: 928c2ecf20Sopenharmony_ci return GPIOPANELCTL; 938c2ecf20Sopenharmony_ci default: 948c2ecf20Sopenharmony_ci return -EOPNOTSUPP; 958c2ecf20Sopenharmony_ci } 968c2ecf20Sopenharmony_ci } 978c2ecf20Sopenharmony_ci 988c2ecf20Sopenharmony_ci if (reg_type == CTRL_IN) { 998c2ecf20Sopenharmony_ci if (gpio < 8) 1008c2ecf20Sopenharmony_ci reg = GPIO0P0CTLI; 1018c2ecf20Sopenharmony_ci else 1028c2ecf20Sopenharmony_ci reg = GPIO1P0CTLI; 1038c2ecf20Sopenharmony_ci } else { 1048c2ecf20Sopenharmony_ci if (gpio < 8) 1058c2ecf20Sopenharmony_ci reg = GPIO0P0CTLO; 1068c2ecf20Sopenharmony_ci else 1078c2ecf20Sopenharmony_ci reg = GPIO1P0CTLO; 1088c2ecf20Sopenharmony_ci } 1098c2ecf20Sopenharmony_ci 1108c2ecf20Sopenharmony_ci return reg + gpio % 8; 1118c2ecf20Sopenharmony_ci} 1128c2ecf20Sopenharmony_ci 1138c2ecf20Sopenharmony_cistatic void crystalcove_update_irq_mask(struct crystalcove_gpio *cg, 1148c2ecf20Sopenharmony_ci int gpio) 1158c2ecf20Sopenharmony_ci{ 1168c2ecf20Sopenharmony_ci u8 mirqs0 = gpio < 8 ? MGPIO0IRQS0 : MGPIO1IRQS0; 1178c2ecf20Sopenharmony_ci int mask = BIT(gpio % 8); 1188c2ecf20Sopenharmony_ci 1198c2ecf20Sopenharmony_ci if (cg->set_irq_mask) 1208c2ecf20Sopenharmony_ci regmap_update_bits(cg->regmap, mirqs0, mask, mask); 1218c2ecf20Sopenharmony_ci else 1228c2ecf20Sopenharmony_ci regmap_update_bits(cg->regmap, mirqs0, mask, 0); 1238c2ecf20Sopenharmony_ci} 1248c2ecf20Sopenharmony_ci 1258c2ecf20Sopenharmony_cistatic void crystalcove_update_irq_ctrl(struct crystalcove_gpio *cg, int gpio) 1268c2ecf20Sopenharmony_ci{ 1278c2ecf20Sopenharmony_ci int reg = to_reg(gpio, CTRL_IN); 1288c2ecf20Sopenharmony_ci 1298c2ecf20Sopenharmony_ci regmap_update_bits(cg->regmap, reg, CTLI_INTCNT_BE, cg->intcnt_value); 1308c2ecf20Sopenharmony_ci} 1318c2ecf20Sopenharmony_ci 1328c2ecf20Sopenharmony_cistatic int crystalcove_gpio_dir_in(struct gpio_chip *chip, unsigned int gpio) 1338c2ecf20Sopenharmony_ci{ 1348c2ecf20Sopenharmony_ci struct crystalcove_gpio *cg = gpiochip_get_data(chip); 1358c2ecf20Sopenharmony_ci int reg = to_reg(gpio, CTRL_OUT); 1368c2ecf20Sopenharmony_ci 1378c2ecf20Sopenharmony_ci if (reg < 0) 1388c2ecf20Sopenharmony_ci return 0; 1398c2ecf20Sopenharmony_ci 1408c2ecf20Sopenharmony_ci return regmap_write(cg->regmap, reg, CTLO_INPUT_SET); 1418c2ecf20Sopenharmony_ci} 1428c2ecf20Sopenharmony_ci 1438c2ecf20Sopenharmony_cistatic int crystalcove_gpio_dir_out(struct gpio_chip *chip, unsigned int gpio, 1448c2ecf20Sopenharmony_ci int value) 1458c2ecf20Sopenharmony_ci{ 1468c2ecf20Sopenharmony_ci struct crystalcove_gpio *cg = gpiochip_get_data(chip); 1478c2ecf20Sopenharmony_ci int reg = to_reg(gpio, CTRL_OUT); 1488c2ecf20Sopenharmony_ci 1498c2ecf20Sopenharmony_ci if (reg < 0) 1508c2ecf20Sopenharmony_ci return 0; 1518c2ecf20Sopenharmony_ci 1528c2ecf20Sopenharmony_ci return regmap_write(cg->regmap, reg, CTLO_OUTPUT_SET | value); 1538c2ecf20Sopenharmony_ci} 1548c2ecf20Sopenharmony_ci 1558c2ecf20Sopenharmony_cistatic int crystalcove_gpio_get(struct gpio_chip *chip, unsigned int gpio) 1568c2ecf20Sopenharmony_ci{ 1578c2ecf20Sopenharmony_ci struct crystalcove_gpio *cg = gpiochip_get_data(chip); 1588c2ecf20Sopenharmony_ci unsigned int val; 1598c2ecf20Sopenharmony_ci int ret, reg = to_reg(gpio, CTRL_IN); 1608c2ecf20Sopenharmony_ci 1618c2ecf20Sopenharmony_ci if (reg < 0) 1628c2ecf20Sopenharmony_ci return 0; 1638c2ecf20Sopenharmony_ci 1648c2ecf20Sopenharmony_ci ret = regmap_read(cg->regmap, reg, &val); 1658c2ecf20Sopenharmony_ci if (ret) 1668c2ecf20Sopenharmony_ci return ret; 1678c2ecf20Sopenharmony_ci 1688c2ecf20Sopenharmony_ci return val & 0x1; 1698c2ecf20Sopenharmony_ci} 1708c2ecf20Sopenharmony_ci 1718c2ecf20Sopenharmony_cistatic void crystalcove_gpio_set(struct gpio_chip *chip, 1728c2ecf20Sopenharmony_ci unsigned int gpio, int value) 1738c2ecf20Sopenharmony_ci{ 1748c2ecf20Sopenharmony_ci struct crystalcove_gpio *cg = gpiochip_get_data(chip); 1758c2ecf20Sopenharmony_ci int reg = to_reg(gpio, CTRL_OUT); 1768c2ecf20Sopenharmony_ci 1778c2ecf20Sopenharmony_ci if (reg < 0) 1788c2ecf20Sopenharmony_ci return; 1798c2ecf20Sopenharmony_ci 1808c2ecf20Sopenharmony_ci if (value) 1818c2ecf20Sopenharmony_ci regmap_update_bits(cg->regmap, reg, 1, 1); 1828c2ecf20Sopenharmony_ci else 1838c2ecf20Sopenharmony_ci regmap_update_bits(cg->regmap, reg, 1, 0); 1848c2ecf20Sopenharmony_ci} 1858c2ecf20Sopenharmony_ci 1868c2ecf20Sopenharmony_cistatic int crystalcove_irq_type(struct irq_data *data, unsigned int type) 1878c2ecf20Sopenharmony_ci{ 1888c2ecf20Sopenharmony_ci struct crystalcove_gpio *cg = 1898c2ecf20Sopenharmony_ci gpiochip_get_data(irq_data_get_irq_chip_data(data)); 1908c2ecf20Sopenharmony_ci 1918c2ecf20Sopenharmony_ci if (data->hwirq >= CRYSTALCOVE_GPIO_NUM) 1928c2ecf20Sopenharmony_ci return 0; 1938c2ecf20Sopenharmony_ci 1948c2ecf20Sopenharmony_ci switch (type) { 1958c2ecf20Sopenharmony_ci case IRQ_TYPE_NONE: 1968c2ecf20Sopenharmony_ci cg->intcnt_value = CTLI_INTCNT_DIS; 1978c2ecf20Sopenharmony_ci break; 1988c2ecf20Sopenharmony_ci case IRQ_TYPE_EDGE_BOTH: 1998c2ecf20Sopenharmony_ci cg->intcnt_value = CTLI_INTCNT_BE; 2008c2ecf20Sopenharmony_ci break; 2018c2ecf20Sopenharmony_ci case IRQ_TYPE_EDGE_RISING: 2028c2ecf20Sopenharmony_ci cg->intcnt_value = CTLI_INTCNT_PE; 2038c2ecf20Sopenharmony_ci break; 2048c2ecf20Sopenharmony_ci case IRQ_TYPE_EDGE_FALLING: 2058c2ecf20Sopenharmony_ci cg->intcnt_value = CTLI_INTCNT_NE; 2068c2ecf20Sopenharmony_ci break; 2078c2ecf20Sopenharmony_ci default: 2088c2ecf20Sopenharmony_ci return -EINVAL; 2098c2ecf20Sopenharmony_ci } 2108c2ecf20Sopenharmony_ci 2118c2ecf20Sopenharmony_ci cg->update |= UPDATE_IRQ_TYPE; 2128c2ecf20Sopenharmony_ci 2138c2ecf20Sopenharmony_ci return 0; 2148c2ecf20Sopenharmony_ci} 2158c2ecf20Sopenharmony_ci 2168c2ecf20Sopenharmony_cistatic void crystalcove_bus_lock(struct irq_data *data) 2178c2ecf20Sopenharmony_ci{ 2188c2ecf20Sopenharmony_ci struct crystalcove_gpio *cg = 2198c2ecf20Sopenharmony_ci gpiochip_get_data(irq_data_get_irq_chip_data(data)); 2208c2ecf20Sopenharmony_ci 2218c2ecf20Sopenharmony_ci mutex_lock(&cg->buslock); 2228c2ecf20Sopenharmony_ci} 2238c2ecf20Sopenharmony_ci 2248c2ecf20Sopenharmony_cistatic void crystalcove_bus_sync_unlock(struct irq_data *data) 2258c2ecf20Sopenharmony_ci{ 2268c2ecf20Sopenharmony_ci struct crystalcove_gpio *cg = 2278c2ecf20Sopenharmony_ci gpiochip_get_data(irq_data_get_irq_chip_data(data)); 2288c2ecf20Sopenharmony_ci int gpio = data->hwirq; 2298c2ecf20Sopenharmony_ci 2308c2ecf20Sopenharmony_ci if (cg->update & UPDATE_IRQ_TYPE) 2318c2ecf20Sopenharmony_ci crystalcove_update_irq_ctrl(cg, gpio); 2328c2ecf20Sopenharmony_ci if (cg->update & UPDATE_IRQ_MASK) 2338c2ecf20Sopenharmony_ci crystalcove_update_irq_mask(cg, gpio); 2348c2ecf20Sopenharmony_ci cg->update = 0; 2358c2ecf20Sopenharmony_ci 2368c2ecf20Sopenharmony_ci mutex_unlock(&cg->buslock); 2378c2ecf20Sopenharmony_ci} 2388c2ecf20Sopenharmony_ci 2398c2ecf20Sopenharmony_cistatic void crystalcove_irq_unmask(struct irq_data *data) 2408c2ecf20Sopenharmony_ci{ 2418c2ecf20Sopenharmony_ci struct crystalcove_gpio *cg = 2428c2ecf20Sopenharmony_ci gpiochip_get_data(irq_data_get_irq_chip_data(data)); 2438c2ecf20Sopenharmony_ci 2448c2ecf20Sopenharmony_ci if (data->hwirq < CRYSTALCOVE_GPIO_NUM) { 2458c2ecf20Sopenharmony_ci cg->set_irq_mask = false; 2468c2ecf20Sopenharmony_ci cg->update |= UPDATE_IRQ_MASK; 2478c2ecf20Sopenharmony_ci } 2488c2ecf20Sopenharmony_ci} 2498c2ecf20Sopenharmony_ci 2508c2ecf20Sopenharmony_cistatic void crystalcove_irq_mask(struct irq_data *data) 2518c2ecf20Sopenharmony_ci{ 2528c2ecf20Sopenharmony_ci struct crystalcove_gpio *cg = 2538c2ecf20Sopenharmony_ci gpiochip_get_data(irq_data_get_irq_chip_data(data)); 2548c2ecf20Sopenharmony_ci 2558c2ecf20Sopenharmony_ci if (data->hwirq < CRYSTALCOVE_GPIO_NUM) { 2568c2ecf20Sopenharmony_ci cg->set_irq_mask = true; 2578c2ecf20Sopenharmony_ci cg->update |= UPDATE_IRQ_MASK; 2588c2ecf20Sopenharmony_ci } 2598c2ecf20Sopenharmony_ci} 2608c2ecf20Sopenharmony_ci 2618c2ecf20Sopenharmony_cistatic struct irq_chip crystalcove_irqchip = { 2628c2ecf20Sopenharmony_ci .name = "Crystal Cove", 2638c2ecf20Sopenharmony_ci .irq_mask = crystalcove_irq_mask, 2648c2ecf20Sopenharmony_ci .irq_unmask = crystalcove_irq_unmask, 2658c2ecf20Sopenharmony_ci .irq_set_type = crystalcove_irq_type, 2668c2ecf20Sopenharmony_ci .irq_bus_lock = crystalcove_bus_lock, 2678c2ecf20Sopenharmony_ci .irq_bus_sync_unlock = crystalcove_bus_sync_unlock, 2688c2ecf20Sopenharmony_ci .flags = IRQCHIP_SKIP_SET_WAKE, 2698c2ecf20Sopenharmony_ci}; 2708c2ecf20Sopenharmony_ci 2718c2ecf20Sopenharmony_cistatic irqreturn_t crystalcove_gpio_irq_handler(int irq, void *data) 2728c2ecf20Sopenharmony_ci{ 2738c2ecf20Sopenharmony_ci struct crystalcove_gpio *cg = data; 2748c2ecf20Sopenharmony_ci unsigned long pending; 2758c2ecf20Sopenharmony_ci unsigned int p0, p1; 2768c2ecf20Sopenharmony_ci int gpio; 2778c2ecf20Sopenharmony_ci unsigned int virq; 2788c2ecf20Sopenharmony_ci 2798c2ecf20Sopenharmony_ci if (regmap_read(cg->regmap, GPIO0IRQ, &p0) || 2808c2ecf20Sopenharmony_ci regmap_read(cg->regmap, GPIO1IRQ, &p1)) 2818c2ecf20Sopenharmony_ci return IRQ_NONE; 2828c2ecf20Sopenharmony_ci 2838c2ecf20Sopenharmony_ci regmap_write(cg->regmap, GPIO0IRQ, p0); 2848c2ecf20Sopenharmony_ci regmap_write(cg->regmap, GPIO1IRQ, p1); 2858c2ecf20Sopenharmony_ci 2868c2ecf20Sopenharmony_ci pending = p0 | p1 << 8; 2878c2ecf20Sopenharmony_ci 2888c2ecf20Sopenharmony_ci for_each_set_bit(gpio, &pending, CRYSTALCOVE_GPIO_NUM) { 2898c2ecf20Sopenharmony_ci virq = irq_find_mapping(cg->chip.irq.domain, gpio); 2908c2ecf20Sopenharmony_ci handle_nested_irq(virq); 2918c2ecf20Sopenharmony_ci } 2928c2ecf20Sopenharmony_ci 2938c2ecf20Sopenharmony_ci return IRQ_HANDLED; 2948c2ecf20Sopenharmony_ci} 2958c2ecf20Sopenharmony_ci 2968c2ecf20Sopenharmony_cistatic void crystalcove_gpio_dbg_show(struct seq_file *s, 2978c2ecf20Sopenharmony_ci struct gpio_chip *chip) 2988c2ecf20Sopenharmony_ci{ 2998c2ecf20Sopenharmony_ci struct crystalcove_gpio *cg = gpiochip_get_data(chip); 3008c2ecf20Sopenharmony_ci int gpio, offset; 3018c2ecf20Sopenharmony_ci unsigned int ctlo, ctli, mirqs0, mirqsx, irq; 3028c2ecf20Sopenharmony_ci 3038c2ecf20Sopenharmony_ci for (gpio = 0; gpio < CRYSTALCOVE_GPIO_NUM; gpio++) { 3048c2ecf20Sopenharmony_ci regmap_read(cg->regmap, to_reg(gpio, CTRL_OUT), &ctlo); 3058c2ecf20Sopenharmony_ci regmap_read(cg->regmap, to_reg(gpio, CTRL_IN), &ctli); 3068c2ecf20Sopenharmony_ci regmap_read(cg->regmap, gpio < 8 ? MGPIO0IRQS0 : MGPIO1IRQS0, 3078c2ecf20Sopenharmony_ci &mirqs0); 3088c2ecf20Sopenharmony_ci regmap_read(cg->regmap, gpio < 8 ? MGPIO0IRQSX : MGPIO1IRQSX, 3098c2ecf20Sopenharmony_ci &mirqsx); 3108c2ecf20Sopenharmony_ci regmap_read(cg->regmap, gpio < 8 ? GPIO0IRQ : GPIO1IRQ, 3118c2ecf20Sopenharmony_ci &irq); 3128c2ecf20Sopenharmony_ci 3138c2ecf20Sopenharmony_ci offset = gpio % 8; 3148c2ecf20Sopenharmony_ci seq_printf(s, " gpio-%-2d %s %s %s %s ctlo=%2x,%s %s %s\n", 3158c2ecf20Sopenharmony_ci gpio, ctlo & CTLO_DIR_OUT ? "out" : "in ", 3168c2ecf20Sopenharmony_ci ctli & 0x1 ? "hi" : "lo", 3178c2ecf20Sopenharmony_ci ctli & CTLI_INTCNT_NE ? "fall" : " ", 3188c2ecf20Sopenharmony_ci ctli & CTLI_INTCNT_PE ? "rise" : " ", 3198c2ecf20Sopenharmony_ci ctlo, 3208c2ecf20Sopenharmony_ci mirqs0 & BIT(offset) ? "s0 mask " : "s0 unmask", 3218c2ecf20Sopenharmony_ci mirqsx & BIT(offset) ? "sx mask " : "sx unmask", 3228c2ecf20Sopenharmony_ci irq & BIT(offset) ? "pending" : " "); 3238c2ecf20Sopenharmony_ci } 3248c2ecf20Sopenharmony_ci} 3258c2ecf20Sopenharmony_ci 3268c2ecf20Sopenharmony_cistatic int crystalcove_gpio_probe(struct platform_device *pdev) 3278c2ecf20Sopenharmony_ci{ 3288c2ecf20Sopenharmony_ci int irq = platform_get_irq(pdev, 0); 3298c2ecf20Sopenharmony_ci struct crystalcove_gpio *cg; 3308c2ecf20Sopenharmony_ci int retval; 3318c2ecf20Sopenharmony_ci struct device *dev = pdev->dev.parent; 3328c2ecf20Sopenharmony_ci struct intel_soc_pmic *pmic = dev_get_drvdata(dev); 3338c2ecf20Sopenharmony_ci struct gpio_irq_chip *girq; 3348c2ecf20Sopenharmony_ci 3358c2ecf20Sopenharmony_ci if (irq < 0) 3368c2ecf20Sopenharmony_ci return irq; 3378c2ecf20Sopenharmony_ci 3388c2ecf20Sopenharmony_ci cg = devm_kzalloc(&pdev->dev, sizeof(*cg), GFP_KERNEL); 3398c2ecf20Sopenharmony_ci if (!cg) 3408c2ecf20Sopenharmony_ci return -ENOMEM; 3418c2ecf20Sopenharmony_ci 3428c2ecf20Sopenharmony_ci platform_set_drvdata(pdev, cg); 3438c2ecf20Sopenharmony_ci 3448c2ecf20Sopenharmony_ci mutex_init(&cg->buslock); 3458c2ecf20Sopenharmony_ci cg->chip.label = KBUILD_MODNAME; 3468c2ecf20Sopenharmony_ci cg->chip.direction_input = crystalcove_gpio_dir_in; 3478c2ecf20Sopenharmony_ci cg->chip.direction_output = crystalcove_gpio_dir_out; 3488c2ecf20Sopenharmony_ci cg->chip.get = crystalcove_gpio_get; 3498c2ecf20Sopenharmony_ci cg->chip.set = crystalcove_gpio_set; 3508c2ecf20Sopenharmony_ci cg->chip.base = -1; 3518c2ecf20Sopenharmony_ci cg->chip.ngpio = CRYSTALCOVE_VGPIO_NUM; 3528c2ecf20Sopenharmony_ci cg->chip.can_sleep = true; 3538c2ecf20Sopenharmony_ci cg->chip.parent = dev; 3548c2ecf20Sopenharmony_ci cg->chip.dbg_show = crystalcove_gpio_dbg_show; 3558c2ecf20Sopenharmony_ci cg->regmap = pmic->regmap; 3568c2ecf20Sopenharmony_ci 3578c2ecf20Sopenharmony_ci girq = &cg->chip.irq; 3588c2ecf20Sopenharmony_ci girq->chip = &crystalcove_irqchip; 3598c2ecf20Sopenharmony_ci /* This will let us handle the parent IRQ in the driver */ 3608c2ecf20Sopenharmony_ci girq->parent_handler = NULL; 3618c2ecf20Sopenharmony_ci girq->num_parents = 0; 3628c2ecf20Sopenharmony_ci girq->parents = NULL; 3638c2ecf20Sopenharmony_ci girq->default_type = IRQ_TYPE_NONE; 3648c2ecf20Sopenharmony_ci girq->handler = handle_simple_irq; 3658c2ecf20Sopenharmony_ci girq->threaded = true; 3668c2ecf20Sopenharmony_ci 3678c2ecf20Sopenharmony_ci retval = devm_request_threaded_irq(&pdev->dev, irq, NULL, 3688c2ecf20Sopenharmony_ci crystalcove_gpio_irq_handler, 3698c2ecf20Sopenharmony_ci IRQF_ONESHOT, KBUILD_MODNAME, cg); 3708c2ecf20Sopenharmony_ci if (retval) { 3718c2ecf20Sopenharmony_ci dev_warn(&pdev->dev, "request irq failed: %d\n", retval); 3728c2ecf20Sopenharmony_ci return retval; 3738c2ecf20Sopenharmony_ci } 3748c2ecf20Sopenharmony_ci 3758c2ecf20Sopenharmony_ci retval = devm_gpiochip_add_data(&pdev->dev, &cg->chip, cg); 3768c2ecf20Sopenharmony_ci if (retval) { 3778c2ecf20Sopenharmony_ci dev_warn(&pdev->dev, "add gpio chip error: %d\n", retval); 3788c2ecf20Sopenharmony_ci return retval; 3798c2ecf20Sopenharmony_ci } 3808c2ecf20Sopenharmony_ci 3818c2ecf20Sopenharmony_ci return 0; 3828c2ecf20Sopenharmony_ci} 3838c2ecf20Sopenharmony_ci 3848c2ecf20Sopenharmony_cistatic struct platform_driver crystalcove_gpio_driver = { 3858c2ecf20Sopenharmony_ci .probe = crystalcove_gpio_probe, 3868c2ecf20Sopenharmony_ci .driver = { 3878c2ecf20Sopenharmony_ci .name = "crystal_cove_gpio", 3888c2ecf20Sopenharmony_ci }, 3898c2ecf20Sopenharmony_ci}; 3908c2ecf20Sopenharmony_cimodule_platform_driver(crystalcove_gpio_driver); 3918c2ecf20Sopenharmony_ci 3928c2ecf20Sopenharmony_ciMODULE_AUTHOR("Yang, Bin <bin.yang@intel.com>"); 3938c2ecf20Sopenharmony_ciMODULE_DESCRIPTION("Intel Crystal Cove GPIO Driver"); 3948c2ecf20Sopenharmony_ciMODULE_LICENSE("GPL v2"); 395