10ba19cfcSBin Gao /* 20ba19cfcSBin Gao * Intel Whiskey Cove PMIC GPIO Driver 30ba19cfcSBin Gao * 40ba19cfcSBin Gao * This driver is written based on gpio-crystalcove.c 50ba19cfcSBin Gao * 60ba19cfcSBin Gao * Copyright (C) 2016 Intel Corporation. All rights reserved. 70ba19cfcSBin Gao * 80ba19cfcSBin Gao * This program is free software; you can redistribute it and/or 90ba19cfcSBin Gao * modify it under the terms of the GNU General Public License version 100ba19cfcSBin Gao * 2 as published by the Free Software Foundation. 110ba19cfcSBin Gao * 120ba19cfcSBin Gao * This program is distributed in the hope that it will be useful, 130ba19cfcSBin Gao * but WITHOUT ANY WARRANTY; without even the implied warranty of 140ba19cfcSBin Gao * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 150ba19cfcSBin Gao * GNU General Public License for more details. 160ba19cfcSBin Gao */ 170ba19cfcSBin Gao 180ba19cfcSBin Gao #include <linux/bitops.h> 190ba19cfcSBin Gao #include <linux/interrupt.h> 200ba19cfcSBin Gao #include <linux/gpio/driver.h> 210ba19cfcSBin Gao #include <linux/mfd/intel_soc_pmic.h> 220ba19cfcSBin Gao #include <linux/platform_device.h> 230ba19cfcSBin Gao #include <linux/regmap.h> 240ba19cfcSBin Gao #include <linux/seq_file.h> 250ba19cfcSBin Gao 260ba19cfcSBin Gao /* 270ba19cfcSBin Gao * Whiskey Cove PMIC has 13 physical GPIO pins divided into 3 banks: 280ba19cfcSBin Gao * Bank 0: Pin 0 - 6 290ba19cfcSBin Gao * Bank 1: Pin 7 - 10 300ba19cfcSBin Gao * Bank 2: Pin 11 -12 310ba19cfcSBin Gao * Each pin has one output control register and one input control register. 320ba19cfcSBin Gao */ 330ba19cfcSBin Gao #define BANK0_NR_PINS 7 340ba19cfcSBin Gao #define BANK1_NR_PINS 4 350ba19cfcSBin Gao #define BANK2_NR_PINS 2 360ba19cfcSBin Gao #define WCOVE_GPIO_NUM (BANK0_NR_PINS + BANK1_NR_PINS + BANK2_NR_PINS) 370ba19cfcSBin Gao #define WCOVE_VGPIO_NUM 94 380ba19cfcSBin Gao /* GPIO output control registers (one per pin): 0x4e44 - 0x4e50 */ 390ba19cfcSBin Gao #define GPIO_OUT_CTRL_BASE 0x4e44 400ba19cfcSBin Gao /* GPIO input control registers (one per pin): 0x4e51 - 0x4e5d */ 410ba19cfcSBin Gao #define GPIO_IN_CTRL_BASE 0x4e51 420ba19cfcSBin Gao 430ba19cfcSBin Gao /* 440ba19cfcSBin Gao * GPIO interrupts are organized in two groups: 450ba19cfcSBin Gao * Group 0: Bank 0 pins (Pin 0 - 6) 460ba19cfcSBin Gao * Group 1: Bank 1 and Bank 2 pins (Pin 7 - 12) 470ba19cfcSBin Gao * Each group has two registers (one bit per pin): status and mask. 480ba19cfcSBin Gao */ 490ba19cfcSBin Gao #define GROUP0_NR_IRQS 7 500ba19cfcSBin Gao #define GROUP1_NR_IRQS 6 510ba19cfcSBin Gao #define IRQ_MASK_BASE 0x4e19 520ba19cfcSBin Gao #define IRQ_STATUS_BASE 0x4e0b 530ba19cfcSBin Gao #define UPDATE_IRQ_TYPE BIT(0) 540ba19cfcSBin Gao #define UPDATE_IRQ_MASK BIT(1) 550ba19cfcSBin Gao 560ba19cfcSBin Gao #define CTLI_INTCNT_DIS (0 << 1) 570ba19cfcSBin Gao #define CTLI_INTCNT_NE (1 << 1) 580ba19cfcSBin Gao #define CTLI_INTCNT_PE (2 << 1) 590ba19cfcSBin Gao #define CTLI_INTCNT_BE (3 << 1) 600ba19cfcSBin Gao 610ba19cfcSBin Gao #define CTLO_DIR_IN (0 << 5) 620ba19cfcSBin Gao #define CTLO_DIR_OUT (1 << 5) 630ba19cfcSBin Gao 640ba19cfcSBin Gao #define CTLO_DRV_MASK (1 << 4) 650ba19cfcSBin Gao #define CTLO_DRV_OD (0 << 4) 660ba19cfcSBin Gao #define CTLO_DRV_CMOS (1 << 4) 670ba19cfcSBin Gao 680ba19cfcSBin Gao #define CTLO_DRV_REN (1 << 3) 690ba19cfcSBin Gao 700ba19cfcSBin Gao #define CTLO_RVAL_2KDOWN (0 << 1) 710ba19cfcSBin Gao #define CTLO_RVAL_2KUP (1 << 1) 720ba19cfcSBin Gao #define CTLO_RVAL_50KDOWN (2 << 1) 730ba19cfcSBin Gao #define CTLO_RVAL_50KUP (3 << 1) 740ba19cfcSBin Gao 750ba19cfcSBin Gao #define CTLO_INPUT_SET (CTLO_DRV_CMOS | CTLO_DRV_REN | CTLO_RVAL_2KUP) 760ba19cfcSBin Gao #define CTLO_OUTPUT_SET (CTLO_DIR_OUT | CTLO_INPUT_SET) 770ba19cfcSBin Gao 780ba19cfcSBin Gao enum ctrl_register { 790ba19cfcSBin Gao CTRL_IN, 800ba19cfcSBin Gao CTRL_OUT, 810ba19cfcSBin Gao }; 820ba19cfcSBin Gao 830ba19cfcSBin Gao /* 840ba19cfcSBin Gao * struct wcove_gpio - Whiskey Cove GPIO controller 850ba19cfcSBin Gao * @buslock: for bus lock/sync and unlock. 860ba19cfcSBin Gao * @chip: the abstract gpio_chip structure. 870ba19cfcSBin Gao * @dev: the gpio device 880ba19cfcSBin Gao * @regmap: the regmap from the parent device. 890ba19cfcSBin Gao * @regmap_irq_chip: the regmap of the gpio irq chip. 900ba19cfcSBin Gao * @update: pending IRQ setting update, to be written to the chip upon unlock. 910ba19cfcSBin Gao * @intcnt: the Interrupt Detect value to be written. 920ba19cfcSBin Gao * @set_irq_mask: true if the IRQ mask needs to be set, false to clear. 930ba19cfcSBin Gao */ 940ba19cfcSBin Gao struct wcove_gpio { 950ba19cfcSBin Gao struct mutex buslock; 960ba19cfcSBin Gao struct gpio_chip chip; 970ba19cfcSBin Gao struct device *dev; 980ba19cfcSBin Gao struct regmap *regmap; 990ba19cfcSBin Gao struct regmap_irq_chip_data *regmap_irq_chip; 1000ba19cfcSBin Gao int update; 1010ba19cfcSBin Gao int intcnt; 1020ba19cfcSBin Gao bool set_irq_mask; 1030ba19cfcSBin Gao }; 1040ba19cfcSBin Gao 1050ba19cfcSBin Gao static inline unsigned int to_reg(int gpio, enum ctrl_register reg_type) 1060ba19cfcSBin Gao { 1070ba19cfcSBin Gao unsigned int reg; 1080ba19cfcSBin Gao int bank; 1090ba19cfcSBin Gao 1100ba19cfcSBin Gao if (gpio < BANK0_NR_PINS) 1110ba19cfcSBin Gao bank = 0; 1120ba19cfcSBin Gao else if (gpio < BANK0_NR_PINS + BANK1_NR_PINS) 1130ba19cfcSBin Gao bank = 1; 1140ba19cfcSBin Gao else 1150ba19cfcSBin Gao bank = 2; 1160ba19cfcSBin Gao 1170ba19cfcSBin Gao if (reg_type == CTRL_IN) 1180ba19cfcSBin Gao reg = GPIO_IN_CTRL_BASE + bank; 1190ba19cfcSBin Gao else 1200ba19cfcSBin Gao reg = GPIO_OUT_CTRL_BASE + bank; 1210ba19cfcSBin Gao 1220ba19cfcSBin Gao return reg; 1230ba19cfcSBin Gao } 1240ba19cfcSBin Gao 1250ba19cfcSBin Gao static void wcove_update_irq_mask(struct wcove_gpio *wg, int gpio) 1260ba19cfcSBin Gao { 1270ba19cfcSBin Gao unsigned int reg, mask; 1280ba19cfcSBin Gao 1290ba19cfcSBin Gao if (gpio < GROUP0_NR_IRQS) { 1300ba19cfcSBin Gao reg = IRQ_MASK_BASE; 1310ba19cfcSBin Gao mask = BIT(gpio % GROUP0_NR_IRQS); 1320ba19cfcSBin Gao } else { 1330ba19cfcSBin Gao reg = IRQ_MASK_BASE + 1; 1340ba19cfcSBin Gao mask = BIT((gpio - GROUP0_NR_IRQS) % GROUP1_NR_IRQS); 1350ba19cfcSBin Gao } 1360ba19cfcSBin Gao 1370ba19cfcSBin Gao if (wg->set_irq_mask) 1380ba19cfcSBin Gao regmap_update_bits(wg->regmap, reg, mask, mask); 1390ba19cfcSBin Gao else 1400ba19cfcSBin Gao regmap_update_bits(wg->regmap, reg, mask, 0); 1410ba19cfcSBin Gao } 1420ba19cfcSBin Gao 1430ba19cfcSBin Gao static void wcove_update_irq_ctrl(struct wcove_gpio *wg, int gpio) 1440ba19cfcSBin Gao { 1450ba19cfcSBin Gao unsigned int reg = to_reg(gpio, CTRL_IN); 1460ba19cfcSBin Gao 1470ba19cfcSBin Gao regmap_update_bits(wg->regmap, reg, CTLI_INTCNT_BE, wg->intcnt); 1480ba19cfcSBin Gao } 1490ba19cfcSBin Gao 1500ba19cfcSBin Gao static int wcove_gpio_dir_in(struct gpio_chip *chip, unsigned int gpio) 1510ba19cfcSBin Gao { 1520ba19cfcSBin Gao struct wcove_gpio *wg = gpiochip_get_data(chip); 1530ba19cfcSBin Gao 1540ba19cfcSBin Gao return regmap_write(wg->regmap, to_reg(gpio, CTRL_OUT), 1550ba19cfcSBin Gao CTLO_INPUT_SET); 1560ba19cfcSBin Gao } 1570ba19cfcSBin Gao 1580ba19cfcSBin Gao static int wcove_gpio_dir_out(struct gpio_chip *chip, unsigned int gpio, 1590ba19cfcSBin Gao int value) 1600ba19cfcSBin Gao { 1610ba19cfcSBin Gao struct wcove_gpio *wg = gpiochip_get_data(chip); 1620ba19cfcSBin Gao 1630ba19cfcSBin Gao return regmap_write(wg->regmap, to_reg(gpio, CTRL_OUT), 1640ba19cfcSBin Gao CTLO_OUTPUT_SET | value); 1650ba19cfcSBin Gao } 1660ba19cfcSBin Gao 167*7d9e59ceSBin Gao static int wcove_gpio_get_direction(struct gpio_chip *chip, unsigned int gpio) 168*7d9e59ceSBin Gao { 169*7d9e59ceSBin Gao struct wcove_gpio *wg = gpiochip_get_data(chip); 170*7d9e59ceSBin Gao unsigned int val; 171*7d9e59ceSBin Gao int ret; 172*7d9e59ceSBin Gao 173*7d9e59ceSBin Gao ret = regmap_read(wg->regmap, to_reg(gpio, CTRL_OUT), &val); 174*7d9e59ceSBin Gao if (ret) 175*7d9e59ceSBin Gao return ret; 176*7d9e59ceSBin Gao 177*7d9e59ceSBin Gao return !(val & CTLO_DIR_OUT); 178*7d9e59ceSBin Gao } 179*7d9e59ceSBin Gao 1800ba19cfcSBin Gao static int wcove_gpio_get(struct gpio_chip *chip, unsigned int gpio) 1810ba19cfcSBin Gao { 1820ba19cfcSBin Gao struct wcove_gpio *wg = gpiochip_get_data(chip); 1830ba19cfcSBin Gao unsigned int val; 1840ba19cfcSBin Gao int ret; 1850ba19cfcSBin Gao 1860ba19cfcSBin Gao ret = regmap_read(wg->regmap, to_reg(gpio, CTRL_IN), &val); 1870ba19cfcSBin Gao if (ret) 1880ba19cfcSBin Gao return ret; 1890ba19cfcSBin Gao 1900ba19cfcSBin Gao return val & 0x1; 1910ba19cfcSBin Gao } 1920ba19cfcSBin Gao 1930ba19cfcSBin Gao static void wcove_gpio_set(struct gpio_chip *chip, 1940ba19cfcSBin Gao unsigned int gpio, int value) 1950ba19cfcSBin Gao { 1960ba19cfcSBin Gao struct wcove_gpio *wg = gpiochip_get_data(chip); 1970ba19cfcSBin Gao 1980ba19cfcSBin Gao if (value) 1990ba19cfcSBin Gao regmap_update_bits(wg->regmap, to_reg(gpio, CTRL_OUT), 1, 1); 2000ba19cfcSBin Gao else 2010ba19cfcSBin Gao regmap_update_bits(wg->regmap, to_reg(gpio, CTRL_OUT), 1, 0); 2020ba19cfcSBin Gao } 2030ba19cfcSBin Gao 2040ba19cfcSBin Gao static int wcove_gpio_set_single_ended(struct gpio_chip *chip, 2050ba19cfcSBin Gao unsigned int gpio, 2060ba19cfcSBin Gao enum single_ended_mode mode) 2070ba19cfcSBin Gao { 2080ba19cfcSBin Gao struct wcove_gpio *wg = gpiochip_get_data(chip); 2090ba19cfcSBin Gao 2100ba19cfcSBin Gao switch (mode) { 2110ba19cfcSBin Gao case LINE_MODE_OPEN_DRAIN: 2120ba19cfcSBin Gao return regmap_update_bits(wg->regmap, to_reg(gpio, CTRL_OUT), 2130ba19cfcSBin Gao CTLO_DRV_MASK, CTLO_DRV_OD); 2140ba19cfcSBin Gao case LINE_MODE_PUSH_PULL: 2150ba19cfcSBin Gao return regmap_update_bits(wg->regmap, to_reg(gpio, CTRL_OUT), 2160ba19cfcSBin Gao CTLO_DRV_MASK, CTLO_DRV_CMOS); 2170ba19cfcSBin Gao default: 2180ba19cfcSBin Gao break; 2190ba19cfcSBin Gao } 2200ba19cfcSBin Gao 2210ba19cfcSBin Gao return -ENOTSUPP; 2220ba19cfcSBin Gao } 2230ba19cfcSBin Gao 2240ba19cfcSBin Gao static int wcove_irq_type(struct irq_data *data, unsigned int type) 2250ba19cfcSBin Gao { 2260ba19cfcSBin Gao struct gpio_chip *chip = irq_data_get_irq_chip_data(data); 2270ba19cfcSBin Gao struct wcove_gpio *wg = gpiochip_get_data(chip); 2280ba19cfcSBin Gao 2290ba19cfcSBin Gao switch (type) { 2300ba19cfcSBin Gao case IRQ_TYPE_NONE: 2310ba19cfcSBin Gao wg->intcnt = CTLI_INTCNT_DIS; 2320ba19cfcSBin Gao break; 2330ba19cfcSBin Gao case IRQ_TYPE_EDGE_BOTH: 2340ba19cfcSBin Gao wg->intcnt = CTLI_INTCNT_BE; 2350ba19cfcSBin Gao break; 2360ba19cfcSBin Gao case IRQ_TYPE_EDGE_RISING: 2370ba19cfcSBin Gao wg->intcnt = CTLI_INTCNT_PE; 2380ba19cfcSBin Gao break; 2390ba19cfcSBin Gao case IRQ_TYPE_EDGE_FALLING: 2400ba19cfcSBin Gao wg->intcnt = CTLI_INTCNT_NE; 2410ba19cfcSBin Gao break; 2420ba19cfcSBin Gao default: 2430ba19cfcSBin Gao return -EINVAL; 2440ba19cfcSBin Gao } 2450ba19cfcSBin Gao 2460ba19cfcSBin Gao wg->update |= UPDATE_IRQ_TYPE; 2470ba19cfcSBin Gao 2480ba19cfcSBin Gao return 0; 2490ba19cfcSBin Gao } 2500ba19cfcSBin Gao 2510ba19cfcSBin Gao static void wcove_bus_lock(struct irq_data *data) 2520ba19cfcSBin Gao { 2530ba19cfcSBin Gao struct gpio_chip *chip = irq_data_get_irq_chip_data(data); 2540ba19cfcSBin Gao struct wcove_gpio *wg = gpiochip_get_data(chip); 2550ba19cfcSBin Gao 2560ba19cfcSBin Gao mutex_lock(&wg->buslock); 2570ba19cfcSBin Gao } 2580ba19cfcSBin Gao 2590ba19cfcSBin Gao static void wcove_bus_sync_unlock(struct irq_data *data) 2600ba19cfcSBin Gao { 2610ba19cfcSBin Gao struct gpio_chip *chip = irq_data_get_irq_chip_data(data); 2620ba19cfcSBin Gao struct wcove_gpio *wg = gpiochip_get_data(chip); 2630ba19cfcSBin Gao int gpio = data->hwirq; 2640ba19cfcSBin Gao 2650ba19cfcSBin Gao if (wg->update & UPDATE_IRQ_TYPE) 2660ba19cfcSBin Gao wcove_update_irq_ctrl(wg, gpio); 2670ba19cfcSBin Gao if (wg->update & UPDATE_IRQ_MASK) 2680ba19cfcSBin Gao wcove_update_irq_mask(wg, gpio); 2690ba19cfcSBin Gao wg->update = 0; 2700ba19cfcSBin Gao 2710ba19cfcSBin Gao mutex_unlock(&wg->buslock); 2720ba19cfcSBin Gao } 2730ba19cfcSBin Gao 2740ba19cfcSBin Gao static void wcove_irq_unmask(struct irq_data *data) 2750ba19cfcSBin Gao { 2760ba19cfcSBin Gao struct gpio_chip *chip = irq_data_get_irq_chip_data(data); 2770ba19cfcSBin Gao struct wcove_gpio *wg = gpiochip_get_data(chip); 2780ba19cfcSBin Gao 2790ba19cfcSBin Gao wg->set_irq_mask = false; 2800ba19cfcSBin Gao wg->update |= UPDATE_IRQ_MASK; 2810ba19cfcSBin Gao } 2820ba19cfcSBin Gao 2830ba19cfcSBin Gao static void wcove_irq_mask(struct irq_data *data) 2840ba19cfcSBin Gao { 2850ba19cfcSBin Gao struct gpio_chip *chip = irq_data_get_irq_chip_data(data); 2860ba19cfcSBin Gao struct wcove_gpio *wg = gpiochip_get_data(chip); 2870ba19cfcSBin Gao 2880ba19cfcSBin Gao wg->set_irq_mask = true; 2890ba19cfcSBin Gao wg->update |= UPDATE_IRQ_MASK; 2900ba19cfcSBin Gao } 2910ba19cfcSBin Gao 2920ba19cfcSBin Gao static struct irq_chip wcove_irqchip = { 2930ba19cfcSBin Gao .name = "Whiskey Cove", 2940ba19cfcSBin Gao .irq_mask = wcove_irq_mask, 2950ba19cfcSBin Gao .irq_unmask = wcove_irq_unmask, 2960ba19cfcSBin Gao .irq_set_type = wcove_irq_type, 2970ba19cfcSBin Gao .irq_bus_lock = wcove_bus_lock, 2980ba19cfcSBin Gao .irq_bus_sync_unlock = wcove_bus_sync_unlock, 2990ba19cfcSBin Gao }; 3000ba19cfcSBin Gao 3010ba19cfcSBin Gao static irqreturn_t wcove_gpio_irq_handler(int irq, void *data) 3020ba19cfcSBin Gao { 3030ba19cfcSBin Gao struct wcove_gpio *wg = (struct wcove_gpio *)data; 3040ba19cfcSBin Gao unsigned int pending, virq, gpio, mask, offset; 3050ba19cfcSBin Gao u8 p[2]; 3060ba19cfcSBin Gao 3070ba19cfcSBin Gao if (regmap_bulk_read(wg->regmap, IRQ_STATUS_BASE, p, 2)) { 3080ba19cfcSBin Gao dev_err(wg->dev, "Failed to read irq status register\n"); 3090ba19cfcSBin Gao return IRQ_NONE; 3100ba19cfcSBin Gao } 3110ba19cfcSBin Gao 3120ba19cfcSBin Gao pending = p[0] | (p[1] << 8); 3130ba19cfcSBin Gao if (!pending) 3140ba19cfcSBin Gao return IRQ_NONE; 3150ba19cfcSBin Gao 3160ba19cfcSBin Gao /* Iterate until no interrupt is pending */ 3170ba19cfcSBin Gao while (pending) { 3180ba19cfcSBin Gao /* One iteration is for all pending bits */ 3190ba19cfcSBin Gao for_each_set_bit(gpio, (const unsigned long *)&pending, 3200ba19cfcSBin Gao GROUP0_NR_IRQS) { 3210ba19cfcSBin Gao offset = (gpio > GROUP0_NR_IRQS) ? 1 : 0; 3220ba19cfcSBin Gao mask = (offset == 1) ? BIT(gpio - GROUP0_NR_IRQS) : 3230ba19cfcSBin Gao BIT(gpio); 3240ba19cfcSBin Gao virq = irq_find_mapping(wg->chip.irqdomain, gpio); 3250ba19cfcSBin Gao handle_nested_irq(virq); 3260ba19cfcSBin Gao regmap_update_bits(wg->regmap, IRQ_STATUS_BASE + offset, 3270ba19cfcSBin Gao mask, mask); 3280ba19cfcSBin Gao } 3290ba19cfcSBin Gao 3300ba19cfcSBin Gao /* Next iteration */ 3310ba19cfcSBin Gao if (regmap_bulk_read(wg->regmap, IRQ_STATUS_BASE, p, 2)) { 3320ba19cfcSBin Gao dev_err(wg->dev, "Failed to read irq status\n"); 3330ba19cfcSBin Gao break; 3340ba19cfcSBin Gao } 3350ba19cfcSBin Gao 3360ba19cfcSBin Gao pending = p[0] | (p[1] << 8); 3370ba19cfcSBin Gao } 3380ba19cfcSBin Gao 3390ba19cfcSBin Gao return IRQ_HANDLED; 3400ba19cfcSBin Gao } 3410ba19cfcSBin Gao 3420ba19cfcSBin Gao static void wcove_gpio_dbg_show(struct seq_file *s, 3430ba19cfcSBin Gao struct gpio_chip *chip) 3440ba19cfcSBin Gao { 3450ba19cfcSBin Gao unsigned int ctlo, ctli, irq_mask, irq_status; 3460ba19cfcSBin Gao struct wcove_gpio *wg = gpiochip_get_data(chip); 3470ba19cfcSBin Gao int gpio, offset, group, ret = 0; 3480ba19cfcSBin Gao 3490ba19cfcSBin Gao for (gpio = 0; gpio < WCOVE_GPIO_NUM; gpio++) { 3500ba19cfcSBin Gao group = gpio < GROUP0_NR_IRQS ? 0 : 1; 3510ba19cfcSBin Gao ret += regmap_read(wg->regmap, to_reg(gpio, CTRL_OUT), &ctlo); 3520ba19cfcSBin Gao ret += regmap_read(wg->regmap, to_reg(gpio, CTRL_IN), &ctli); 3530ba19cfcSBin Gao ret += regmap_read(wg->regmap, IRQ_MASK_BASE + group, 3540ba19cfcSBin Gao &irq_mask); 3550ba19cfcSBin Gao ret += regmap_read(wg->regmap, IRQ_STATUS_BASE + group, 3560ba19cfcSBin Gao &irq_status); 3570ba19cfcSBin Gao if (ret) { 3580ba19cfcSBin Gao pr_err("Failed to read registers: ctrl out/in or irq status/mask\n"); 3590ba19cfcSBin Gao break; 3600ba19cfcSBin Gao } 3610ba19cfcSBin Gao 3620ba19cfcSBin Gao offset = gpio % 8; 3630ba19cfcSBin Gao seq_printf(s, " gpio-%-2d %s %s %s %s ctlo=%2x,%s %s\n", 3640ba19cfcSBin Gao gpio, ctlo & CTLO_DIR_OUT ? "out" : "in ", 3650ba19cfcSBin Gao ctli & 0x1 ? "hi" : "lo", 3660ba19cfcSBin Gao ctli & CTLI_INTCNT_NE ? "fall" : " ", 3670ba19cfcSBin Gao ctli & CTLI_INTCNT_PE ? "rise" : " ", 3680ba19cfcSBin Gao ctlo, 3690ba19cfcSBin Gao irq_mask & BIT(offset) ? "mask " : "unmask", 3700ba19cfcSBin Gao irq_status & BIT(offset) ? "pending" : " "); 3710ba19cfcSBin Gao } 3720ba19cfcSBin Gao } 3730ba19cfcSBin Gao 3740ba19cfcSBin Gao static int wcove_gpio_probe(struct platform_device *pdev) 3750ba19cfcSBin Gao { 3760ba19cfcSBin Gao struct intel_soc_pmic *pmic; 3770ba19cfcSBin Gao struct wcove_gpio *wg; 3780ba19cfcSBin Gao int virq, ret, irq; 3790ba19cfcSBin Gao struct device *dev; 3800ba19cfcSBin Gao 3810ba19cfcSBin Gao /* 3820ba19cfcSBin Gao * This gpio platform device is created by a mfd device (see 3830ba19cfcSBin Gao * drivers/mfd/intel_soc_pmic_bxtwc.c for details). Information 3840ba19cfcSBin Gao * shared by all sub-devices created by the mfd device, the regmap 3850ba19cfcSBin Gao * pointer for instance, is stored as driver data of the mfd device 3860ba19cfcSBin Gao * driver. 3870ba19cfcSBin Gao */ 3880ba19cfcSBin Gao pmic = dev_get_drvdata(pdev->dev.parent); 3890ba19cfcSBin Gao if (!pmic) 3900ba19cfcSBin Gao return -ENODEV; 3910ba19cfcSBin Gao 3920ba19cfcSBin Gao irq = platform_get_irq(pdev, 0); 3930ba19cfcSBin Gao if (irq < 0) 3940ba19cfcSBin Gao return irq; 3950ba19cfcSBin Gao 3960ba19cfcSBin Gao dev = &pdev->dev; 3970ba19cfcSBin Gao 3980ba19cfcSBin Gao wg = devm_kzalloc(dev, sizeof(*wg), GFP_KERNEL); 3990ba19cfcSBin Gao if (!wg) 4000ba19cfcSBin Gao return -ENOMEM; 4010ba19cfcSBin Gao 4020ba19cfcSBin Gao wg->regmap_irq_chip = pmic->irq_chip_data_level2; 4030ba19cfcSBin Gao 4040ba19cfcSBin Gao platform_set_drvdata(pdev, wg); 4050ba19cfcSBin Gao 4060ba19cfcSBin Gao mutex_init(&wg->buslock); 4070ba19cfcSBin Gao wg->chip.label = KBUILD_MODNAME; 4080ba19cfcSBin Gao wg->chip.direction_input = wcove_gpio_dir_in; 4090ba19cfcSBin Gao wg->chip.direction_output = wcove_gpio_dir_out; 410*7d9e59ceSBin Gao wg->chip.get_direction = wcove_gpio_get_direction; 4110ba19cfcSBin Gao wg->chip.get = wcove_gpio_get; 4120ba19cfcSBin Gao wg->chip.set = wcove_gpio_set; 4130ba19cfcSBin Gao wg->chip.set_single_ended = wcove_gpio_set_single_ended, 4140ba19cfcSBin Gao wg->chip.base = -1; 4150ba19cfcSBin Gao wg->chip.ngpio = WCOVE_VGPIO_NUM; 4160ba19cfcSBin Gao wg->chip.can_sleep = true; 4170ba19cfcSBin Gao wg->chip.parent = pdev->dev.parent; 4180ba19cfcSBin Gao wg->chip.dbg_show = wcove_gpio_dbg_show; 4190ba19cfcSBin Gao wg->dev = dev; 4200ba19cfcSBin Gao wg->regmap = pmic->regmap; 4210ba19cfcSBin Gao 4220ba19cfcSBin Gao ret = devm_gpiochip_add_data(dev, &wg->chip, wg); 4230ba19cfcSBin Gao if (ret) { 4240ba19cfcSBin Gao dev_err(dev, "Failed to add gpiochip: %d\n", ret); 4250ba19cfcSBin Gao return ret; 4260ba19cfcSBin Gao } 4270ba19cfcSBin Gao 4280ba19cfcSBin Gao ret = gpiochip_irqchip_add(&wg->chip, &wcove_irqchip, 0, 4290ba19cfcSBin Gao handle_simple_irq, IRQ_TYPE_NONE); 4300ba19cfcSBin Gao if (ret) { 4310ba19cfcSBin Gao dev_err(dev, "Failed to add irqchip: %d\n", ret); 4320ba19cfcSBin Gao return ret; 4330ba19cfcSBin Gao } 4340ba19cfcSBin Gao 4350ba19cfcSBin Gao virq = regmap_irq_get_virq(wg->regmap_irq_chip, irq); 4360ba19cfcSBin Gao if (virq < 0) { 4370ba19cfcSBin Gao dev_err(dev, "Failed to get virq by irq %d\n", irq); 4380ba19cfcSBin Gao return virq; 4390ba19cfcSBin Gao } 4400ba19cfcSBin Gao 4410ba19cfcSBin Gao ret = devm_request_threaded_irq(dev, virq, NULL, 4420ba19cfcSBin Gao wcove_gpio_irq_handler, IRQF_ONESHOT, pdev->name, wg); 4430ba19cfcSBin Gao if (ret) { 4440ba19cfcSBin Gao dev_err(dev, "Failed to request irq %d\n", virq); 4450ba19cfcSBin Gao return ret; 4460ba19cfcSBin Gao } 4470ba19cfcSBin Gao 4480ba19cfcSBin Gao return 0; 4490ba19cfcSBin Gao } 4500ba19cfcSBin Gao 4510ba19cfcSBin Gao /* 4520ba19cfcSBin Gao * Whiskey Cove PMIC itself is a analog device(but with digital control 4530ba19cfcSBin Gao * interface) providing power management support for other devices in 4540ba19cfcSBin Gao * the accompanied SoC, so we have no .pm for Whiskey Cove GPIO driver. 4550ba19cfcSBin Gao */ 4560ba19cfcSBin Gao static struct platform_driver wcove_gpio_driver = { 4570ba19cfcSBin Gao .driver = { 4580ba19cfcSBin Gao .name = "bxt_wcove_gpio", 4590ba19cfcSBin Gao }, 4600ba19cfcSBin Gao .probe = wcove_gpio_probe, 4610ba19cfcSBin Gao }; 4620ba19cfcSBin Gao 4630ba19cfcSBin Gao module_platform_driver(wcove_gpio_driver); 4640ba19cfcSBin Gao 4650ba19cfcSBin Gao MODULE_AUTHOR("Ajay Thomas <ajay.thomas.david.rajamanickam@intel.com>"); 4660ba19cfcSBin Gao MODULE_AUTHOR("Bin Gao <bin.gao@intel.com>"); 4670ba19cfcSBin Gao MODULE_DESCRIPTION("Intel Whiskey Cove GPIO Driver"); 4680ba19cfcSBin Gao MODULE_LICENSE("GPL v2"); 4690ba19cfcSBin Gao MODULE_ALIAS("platform:bxt_wcove_gpio"); 470