2018-11-06 20:11:42 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2016-07-26 05:59:38 +08:00
|
|
|
/*
|
|
|
|
* Intel Whiskey Cove PMIC GPIO Driver
|
|
|
|
*
|
|
|
|
* This driver is written based on gpio-crystalcove.c
|
|
|
|
*
|
|
|
|
* Copyright (C) 2016 Intel Corporation. All rights reserved.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/bitops.h>
|
|
|
|
#include <linux/gpio/driver.h>
|
2018-09-04 19:26:25 +08:00
|
|
|
#include <linux/interrupt.h>
|
2016-07-26 05:59:38 +08:00
|
|
|
#include <linux/mfd/intel_soc_pmic.h>
|
2018-09-04 19:26:25 +08:00
|
|
|
#include <linux/module.h>
|
2016-07-26 05:59:38 +08:00
|
|
|
#include <linux/platform_device.h>
|
|
|
|
#include <linux/regmap.h>
|
|
|
|
#include <linux/seq_file.h>
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Whiskey Cove PMIC has 13 physical GPIO pins divided into 3 banks:
|
2019-01-30 02:40:58 +08:00
|
|
|
* Bank 0: Pin 0 - 6
|
|
|
|
* Bank 1: Pin 7 - 10
|
|
|
|
* Bank 2: Pin 11 - 12
|
2016-07-26 05:59:38 +08:00
|
|
|
* Each pin has one output control register and one input control register.
|
|
|
|
*/
|
|
|
|
#define BANK0_NR_PINS 7
|
|
|
|
#define BANK1_NR_PINS 4
|
|
|
|
#define BANK2_NR_PINS 2
|
|
|
|
#define WCOVE_GPIO_NUM (BANK0_NR_PINS + BANK1_NR_PINS + BANK2_NR_PINS)
|
|
|
|
#define WCOVE_VGPIO_NUM 94
|
|
|
|
/* GPIO output control registers (one per pin): 0x4e44 - 0x4e50 */
|
|
|
|
#define GPIO_OUT_CTRL_BASE 0x4e44
|
|
|
|
/* GPIO input control registers (one per pin): 0x4e51 - 0x4e5d */
|
|
|
|
#define GPIO_IN_CTRL_BASE 0x4e51
|
|
|
|
|
|
|
|
/*
|
|
|
|
* GPIO interrupts are organized in two groups:
|
|
|
|
* Group 0: Bank 0 pins (Pin 0 - 6)
|
|
|
|
* Group 1: Bank 1 and Bank 2 pins (Pin 7 - 12)
|
|
|
|
* Each group has two registers (one bit per pin): status and mask.
|
|
|
|
*/
|
|
|
|
#define GROUP0_NR_IRQS 7
|
|
|
|
#define GROUP1_NR_IRQS 6
|
|
|
|
#define IRQ_MASK_BASE 0x4e19
|
|
|
|
#define IRQ_STATUS_BASE 0x4e0b
|
2017-04-25 03:15:04 +08:00
|
|
|
#define GPIO_IRQ0_MASK GENMASK(6, 0)
|
|
|
|
#define GPIO_IRQ1_MASK GENMASK(5, 0)
|
2016-07-26 05:59:38 +08:00
|
|
|
#define UPDATE_IRQ_TYPE BIT(0)
|
|
|
|
#define UPDATE_IRQ_MASK BIT(1)
|
|
|
|
|
|
|
|
#define CTLI_INTCNT_DIS (0 << 1)
|
|
|
|
#define CTLI_INTCNT_NE (1 << 1)
|
|
|
|
#define CTLI_INTCNT_PE (2 << 1)
|
|
|
|
#define CTLI_INTCNT_BE (3 << 1)
|
|
|
|
|
|
|
|
#define CTLO_DIR_IN (0 << 5)
|
|
|
|
#define CTLO_DIR_OUT (1 << 5)
|
|
|
|
|
|
|
|
#define CTLO_DRV_MASK (1 << 4)
|
|
|
|
#define CTLO_DRV_OD (0 << 4)
|
|
|
|
#define CTLO_DRV_CMOS (1 << 4)
|
|
|
|
|
|
|
|
#define CTLO_DRV_REN (1 << 3)
|
|
|
|
|
|
|
|
#define CTLO_RVAL_2KDOWN (0 << 1)
|
|
|
|
#define CTLO_RVAL_2KUP (1 << 1)
|
|
|
|
#define CTLO_RVAL_50KDOWN (2 << 1)
|
|
|
|
#define CTLO_RVAL_50KUP (3 << 1)
|
|
|
|
|
2019-01-30 02:40:58 +08:00
|
|
|
#define CTLO_INPUT_SET (CTLO_DRV_CMOS | CTLO_DRV_REN | CTLO_RVAL_2KUP)
|
|
|
|
#define CTLO_OUTPUT_SET (CTLO_DIR_OUT | CTLO_INPUT_SET)
|
2016-07-26 05:59:38 +08:00
|
|
|
|
|
|
|
enum ctrl_register {
|
|
|
|
CTRL_IN,
|
|
|
|
CTRL_OUT,
|
2020-10-14 22:13:23 +08:00
|
|
|
IRQ_STATUS,
|
|
|
|
IRQ_MASK,
|
2016-07-26 05:59:38 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* struct wcove_gpio - Whiskey Cove GPIO controller
|
|
|
|
* @buslock: for bus lock/sync and unlock.
|
|
|
|
* @chip: the abstract gpio_chip structure.
|
|
|
|
* @dev: the gpio device
|
|
|
|
* @regmap: the regmap from the parent device.
|
|
|
|
* @regmap_irq_chip: the regmap of the gpio irq chip.
|
|
|
|
* @update: pending IRQ setting update, to be written to the chip upon unlock.
|
|
|
|
* @intcnt: the Interrupt Detect value to be written.
|
|
|
|
* @set_irq_mask: true if the IRQ mask needs to be set, false to clear.
|
|
|
|
*/
|
|
|
|
struct wcove_gpio {
|
|
|
|
struct mutex buslock;
|
|
|
|
struct gpio_chip chip;
|
|
|
|
struct device *dev;
|
|
|
|
struct regmap *regmap;
|
|
|
|
struct regmap_irq_chip_data *regmap_irq_chip;
|
|
|
|
int update;
|
|
|
|
int intcnt;
|
|
|
|
bool set_irq_mask;
|
|
|
|
};
|
|
|
|
|
2021-05-20 18:00:01 +08:00
|
|
|
static inline int to_reg(int gpio, enum ctrl_register type)
|
2016-07-26 05:59:38 +08:00
|
|
|
{
|
2021-05-20 18:00:01 +08:00
|
|
|
unsigned int reg = type == CTRL_IN ? GPIO_IN_CTRL_BASE : GPIO_OUT_CTRL_BASE;
|
2016-07-26 05:59:38 +08:00
|
|
|
|
2017-06-27 01:37:04 +08:00
|
|
|
if (gpio >= WCOVE_GPIO_NUM)
|
|
|
|
return -EOPNOTSUPP;
|
2016-07-26 05:59:38 +08:00
|
|
|
|
2021-05-20 18:00:01 +08:00
|
|
|
return reg + gpio;
|
2016-07-26 05:59:38 +08:00
|
|
|
}
|
|
|
|
|
2020-10-14 22:13:23 +08:00
|
|
|
static inline int to_ireg(int gpio, enum ctrl_register type, unsigned int *mask)
|
2016-07-26 05:59:38 +08:00
|
|
|
{
|
2020-10-14 22:13:23 +08:00
|
|
|
unsigned int reg = type == IRQ_STATUS ? IRQ_STATUS_BASE : IRQ_MASK_BASE;
|
2016-07-26 05:59:38 +08:00
|
|
|
|
|
|
|
if (gpio < GROUP0_NR_IRQS) {
|
2020-10-14 22:13:23 +08:00
|
|
|
reg += 0;
|
|
|
|
*mask = BIT(gpio);
|
2016-07-26 05:59:38 +08:00
|
|
|
} else {
|
2020-10-14 22:13:23 +08:00
|
|
|
reg += 1;
|
|
|
|
*mask = BIT(gpio - GROUP0_NR_IRQS);
|
2016-07-26 05:59:38 +08:00
|
|
|
}
|
|
|
|
|
2020-10-14 22:13:23 +08:00
|
|
|
return reg;
|
|
|
|
}
|
|
|
|
|
2021-05-20 17:46:05 +08:00
|
|
|
static void wcove_update_irq_mask(struct wcove_gpio *wg, irq_hw_number_t gpio)
|
2020-10-14 22:13:23 +08:00
|
|
|
{
|
|
|
|
unsigned int mask, reg = to_ireg(gpio, IRQ_MASK, &mask);
|
|
|
|
|
2016-07-26 05:59:38 +08:00
|
|
|
if (wg->set_irq_mask)
|
2021-01-30 00:24:28 +08:00
|
|
|
regmap_set_bits(wg->regmap, reg, mask);
|
2016-07-26 05:59:38 +08:00
|
|
|
else
|
2021-01-30 00:24:28 +08:00
|
|
|
regmap_clear_bits(wg->regmap, reg, mask);
|
2016-07-26 05:59:38 +08:00
|
|
|
}
|
|
|
|
|
2021-05-20 17:46:05 +08:00
|
|
|
static void wcove_update_irq_ctrl(struct wcove_gpio *wg, irq_hw_number_t gpio)
|
2016-07-26 05:59:38 +08:00
|
|
|
{
|
2017-06-27 01:37:04 +08:00
|
|
|
int reg = to_reg(gpio, CTRL_IN);
|
|
|
|
|
2016-07-26 05:59:38 +08:00
|
|
|
regmap_update_bits(wg->regmap, reg, CTLI_INTCNT_BE, wg->intcnt);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int wcove_gpio_dir_in(struct gpio_chip *chip, unsigned int gpio)
|
|
|
|
{
|
|
|
|
struct wcove_gpio *wg = gpiochip_get_data(chip);
|
2017-06-27 01:37:04 +08:00
|
|
|
int reg = to_reg(gpio, CTRL_OUT);
|
|
|
|
|
|
|
|
if (reg < 0)
|
|
|
|
return 0;
|
2016-07-26 05:59:38 +08:00
|
|
|
|
2017-06-27 01:37:04 +08:00
|
|
|
return regmap_write(wg->regmap, reg, CTLO_INPUT_SET);
|
2016-07-26 05:59:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int wcove_gpio_dir_out(struct gpio_chip *chip, unsigned int gpio,
|
|
|
|
int value)
|
|
|
|
{
|
|
|
|
struct wcove_gpio *wg = gpiochip_get_data(chip);
|
2017-06-27 01:37:04 +08:00
|
|
|
int reg = to_reg(gpio, CTRL_OUT);
|
2016-07-26 05:59:38 +08:00
|
|
|
|
2017-06-27 01:37:04 +08:00
|
|
|
if (reg < 0)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return regmap_write(wg->regmap, reg, CTLO_OUTPUT_SET | value);
|
2016-07-26 05:59:38 +08:00
|
|
|
}
|
|
|
|
|
2016-08-16 02:03:23 +08:00
|
|
|
static int wcove_gpio_get_direction(struct gpio_chip *chip, unsigned int gpio)
|
|
|
|
{
|
|
|
|
struct wcove_gpio *wg = gpiochip_get_data(chip);
|
|
|
|
unsigned int val;
|
2017-06-27 01:37:04 +08:00
|
|
|
int ret, reg = to_reg(gpio, CTRL_OUT);
|
|
|
|
|
|
|
|
if (reg < 0)
|
2019-11-06 16:54:12 +08:00
|
|
|
return GPIO_LINE_DIRECTION_OUT;
|
2016-08-16 02:03:23 +08:00
|
|
|
|
2017-06-27 01:37:04 +08:00
|
|
|
ret = regmap_read(wg->regmap, reg, &val);
|
2016-08-16 02:03:23 +08:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
2019-11-06 16:54:12 +08:00
|
|
|
if (val & CTLO_DIR_OUT)
|
|
|
|
return GPIO_LINE_DIRECTION_OUT;
|
|
|
|
|
|
|
|
return GPIO_LINE_DIRECTION_IN;
|
2016-08-16 02:03:23 +08:00
|
|
|
}
|
|
|
|
|
2016-07-26 05:59:38 +08:00
|
|
|
static int wcove_gpio_get(struct gpio_chip *chip, unsigned int gpio)
|
|
|
|
{
|
|
|
|
struct wcove_gpio *wg = gpiochip_get_data(chip);
|
|
|
|
unsigned int val;
|
2017-06-27 01:37:04 +08:00
|
|
|
int ret, reg = to_reg(gpio, CTRL_IN);
|
|
|
|
|
|
|
|
if (reg < 0)
|
|
|
|
return 0;
|
2016-07-26 05:59:38 +08:00
|
|
|
|
2017-06-27 01:37:04 +08:00
|
|
|
ret = regmap_read(wg->regmap, reg, &val);
|
2016-07-26 05:59:38 +08:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
return val & 0x1;
|
|
|
|
}
|
|
|
|
|
2019-01-30 02:40:58 +08:00
|
|
|
static void wcove_gpio_set(struct gpio_chip *chip, unsigned int gpio, int value)
|
2016-07-26 05:59:38 +08:00
|
|
|
{
|
|
|
|
struct wcove_gpio *wg = gpiochip_get_data(chip);
|
2017-06-27 01:37:04 +08:00
|
|
|
int reg = to_reg(gpio, CTRL_OUT);
|
|
|
|
|
|
|
|
if (reg < 0)
|
|
|
|
return;
|
2016-07-26 05:59:38 +08:00
|
|
|
|
|
|
|
if (value)
|
2021-01-30 00:24:28 +08:00
|
|
|
regmap_set_bits(wg->regmap, reg, 1);
|
2016-07-26 05:59:38 +08:00
|
|
|
else
|
2021-01-30 00:24:28 +08:00
|
|
|
regmap_clear_bits(wg->regmap, reg, 1);
|
2016-07-26 05:59:38 +08:00
|
|
|
}
|
|
|
|
|
2017-01-23 20:34:34 +08:00
|
|
|
static int wcove_gpio_set_config(struct gpio_chip *chip, unsigned int gpio,
|
|
|
|
unsigned long config)
|
2016-07-26 05:59:38 +08:00
|
|
|
{
|
|
|
|
struct wcove_gpio *wg = gpiochip_get_data(chip);
|
2017-06-27 01:37:04 +08:00
|
|
|
int reg = to_reg(gpio, CTRL_OUT);
|
|
|
|
|
|
|
|
if (reg < 0)
|
|
|
|
return 0;
|
2016-07-26 05:59:38 +08:00
|
|
|
|
2017-01-23 20:34:34 +08:00
|
|
|
switch (pinconf_to_config_param(config)) {
|
|
|
|
case PIN_CONFIG_DRIVE_OPEN_DRAIN:
|
2017-06-27 01:37:04 +08:00
|
|
|
return regmap_update_bits(wg->regmap, reg, CTLO_DRV_MASK,
|
|
|
|
CTLO_DRV_OD);
|
2017-01-23 20:34:34 +08:00
|
|
|
case PIN_CONFIG_DRIVE_PUSH_PULL:
|
2017-06-27 01:37:04 +08:00
|
|
|
return regmap_update_bits(wg->regmap, reg, CTLO_DRV_MASK,
|
|
|
|
CTLO_DRV_CMOS);
|
2016-07-26 05:59:38 +08:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return -ENOTSUPP;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int wcove_irq_type(struct irq_data *data, unsigned int type)
|
|
|
|
{
|
|
|
|
struct gpio_chip *chip = irq_data_get_irq_chip_data(data);
|
|
|
|
struct wcove_gpio *wg = gpiochip_get_data(chip);
|
2021-05-20 17:46:05 +08:00
|
|
|
irq_hw_number_t gpio = irqd_to_hwirq(data);
|
2016-07-26 05:59:38 +08:00
|
|
|
|
2021-05-20 17:46:05 +08:00
|
|
|
if (gpio >= WCOVE_GPIO_NUM)
|
2017-06-27 01:37:04 +08:00
|
|
|
return 0;
|
|
|
|
|
2016-07-26 05:59:38 +08:00
|
|
|
switch (type) {
|
|
|
|
case IRQ_TYPE_NONE:
|
|
|
|
wg->intcnt = CTLI_INTCNT_DIS;
|
|
|
|
break;
|
|
|
|
case IRQ_TYPE_EDGE_BOTH:
|
|
|
|
wg->intcnt = CTLI_INTCNT_BE;
|
|
|
|
break;
|
|
|
|
case IRQ_TYPE_EDGE_RISING:
|
|
|
|
wg->intcnt = CTLI_INTCNT_PE;
|
|
|
|
break;
|
|
|
|
case IRQ_TYPE_EDGE_FALLING:
|
|
|
|
wg->intcnt = CTLI_INTCNT_NE;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
wg->update |= UPDATE_IRQ_TYPE;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void wcove_bus_lock(struct irq_data *data)
|
|
|
|
{
|
|
|
|
struct gpio_chip *chip = irq_data_get_irq_chip_data(data);
|
|
|
|
struct wcove_gpio *wg = gpiochip_get_data(chip);
|
|
|
|
|
|
|
|
mutex_lock(&wg->buslock);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void wcove_bus_sync_unlock(struct irq_data *data)
|
|
|
|
{
|
|
|
|
struct gpio_chip *chip = irq_data_get_irq_chip_data(data);
|
|
|
|
struct wcove_gpio *wg = gpiochip_get_data(chip);
|
2021-05-20 17:46:05 +08:00
|
|
|
irq_hw_number_t gpio = irqd_to_hwirq(data);
|
2016-07-26 05:59:38 +08:00
|
|
|
|
|
|
|
if (wg->update & UPDATE_IRQ_TYPE)
|
|
|
|
wcove_update_irq_ctrl(wg, gpio);
|
|
|
|
if (wg->update & UPDATE_IRQ_MASK)
|
|
|
|
wcove_update_irq_mask(wg, gpio);
|
|
|
|
wg->update = 0;
|
|
|
|
|
|
|
|
mutex_unlock(&wg->buslock);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void wcove_irq_unmask(struct irq_data *data)
|
|
|
|
{
|
|
|
|
struct gpio_chip *chip = irq_data_get_irq_chip_data(data);
|
|
|
|
struct wcove_gpio *wg = gpiochip_get_data(chip);
|
2021-05-20 17:46:05 +08:00
|
|
|
irq_hw_number_t gpio = irqd_to_hwirq(data);
|
2016-07-26 05:59:38 +08:00
|
|
|
|
2021-05-20 17:46:05 +08:00
|
|
|
if (gpio >= WCOVE_GPIO_NUM)
|
2017-06-27 01:37:04 +08:00
|
|
|
return;
|
|
|
|
|
2022-05-13 01:39:21 +08:00
|
|
|
gpiochip_enable_irq(chip, gpio);
|
|
|
|
|
2016-07-26 05:59:38 +08:00
|
|
|
wg->set_irq_mask = false;
|
|
|
|
wg->update |= UPDATE_IRQ_MASK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void wcove_irq_mask(struct irq_data *data)
|
|
|
|
{
|
|
|
|
struct gpio_chip *chip = irq_data_get_irq_chip_data(data);
|
|
|
|
struct wcove_gpio *wg = gpiochip_get_data(chip);
|
2021-05-20 17:46:05 +08:00
|
|
|
irq_hw_number_t gpio = irqd_to_hwirq(data);
|
2016-07-26 05:59:38 +08:00
|
|
|
|
2021-05-20 17:46:05 +08:00
|
|
|
if (gpio >= WCOVE_GPIO_NUM)
|
2017-06-27 01:37:04 +08:00
|
|
|
return;
|
|
|
|
|
2016-07-26 05:59:38 +08:00
|
|
|
wg->set_irq_mask = true;
|
|
|
|
wg->update |= UPDATE_IRQ_MASK;
|
2022-05-13 01:39:21 +08:00
|
|
|
|
|
|
|
gpiochip_disable_irq(chip, gpio);
|
2016-07-26 05:59:38 +08:00
|
|
|
}
|
|
|
|
|
2022-05-13 01:39:21 +08:00
|
|
|
static const struct irq_chip wcove_irqchip = {
|
2016-07-26 05:59:38 +08:00
|
|
|
.name = "Whiskey Cove",
|
|
|
|
.irq_mask = wcove_irq_mask,
|
|
|
|
.irq_unmask = wcove_irq_unmask,
|
|
|
|
.irq_set_type = wcove_irq_type,
|
|
|
|
.irq_bus_lock = wcove_bus_lock,
|
|
|
|
.irq_bus_sync_unlock = wcove_bus_sync_unlock,
|
2022-05-13 01:39:21 +08:00
|
|
|
.flags = IRQCHIP_IMMUTABLE,
|
|
|
|
GPIOCHIP_IRQ_RESOURCE_HELPERS,
|
2016-07-26 05:59:38 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
static irqreturn_t wcove_gpio_irq_handler(int irq, void *data)
|
|
|
|
{
|
|
|
|
struct wcove_gpio *wg = (struct wcove_gpio *)data;
|
2020-10-14 22:13:23 +08:00
|
|
|
unsigned int virq, gpio;
|
2019-01-29 22:40:50 +08:00
|
|
|
unsigned long pending;
|
2016-07-26 05:59:38 +08:00
|
|
|
u8 p[2];
|
|
|
|
|
|
|
|
if (regmap_bulk_read(wg->regmap, IRQ_STATUS_BASE, p, 2)) {
|
|
|
|
dev_err(wg->dev, "Failed to read irq status register\n");
|
|
|
|
return IRQ_NONE;
|
|
|
|
}
|
|
|
|
|
2017-04-25 03:15:04 +08:00
|
|
|
pending = (p[0] & GPIO_IRQ0_MASK) | ((p[1] & GPIO_IRQ1_MASK) << 7);
|
2016-07-26 05:59:38 +08:00
|
|
|
if (!pending)
|
|
|
|
return IRQ_NONE;
|
|
|
|
|
|
|
|
/* Iterate until no interrupt is pending */
|
|
|
|
while (pending) {
|
|
|
|
/* One iteration is for all pending bits */
|
2019-01-29 22:40:50 +08:00
|
|
|
for_each_set_bit(gpio, &pending, WCOVE_GPIO_NUM) {
|
2020-10-14 22:13:23 +08:00
|
|
|
unsigned int mask, reg = to_ireg(gpio, IRQ_STATUS, &mask);
|
|
|
|
|
2017-11-08 02:15:47 +08:00
|
|
|
virq = irq_find_mapping(wg->chip.irq.domain, gpio);
|
2016-07-26 05:59:38 +08:00
|
|
|
handle_nested_irq(virq);
|
2020-10-14 22:13:23 +08:00
|
|
|
regmap_set_bits(wg->regmap, reg, mask);
|
2016-07-26 05:59:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Next iteration */
|
|
|
|
if (regmap_bulk_read(wg->regmap, IRQ_STATUS_BASE, p, 2)) {
|
|
|
|
dev_err(wg->dev, "Failed to read irq status\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2017-04-25 03:15:04 +08:00
|
|
|
pending = (p[0] & GPIO_IRQ0_MASK) | ((p[1] & GPIO_IRQ1_MASK) << 7);
|
2016-07-26 05:59:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return IRQ_HANDLED;
|
|
|
|
}
|
|
|
|
|
2021-05-20 20:17:15 +08:00
|
|
|
static void wcove_gpio_dbg_show(struct seq_file *s, struct gpio_chip *chip)
|
2016-07-26 05:59:38 +08:00
|
|
|
{
|
|
|
|
unsigned int ctlo, ctli, irq_mask, irq_status;
|
|
|
|
struct wcove_gpio *wg = gpiochip_get_data(chip);
|
2020-10-14 22:13:23 +08:00
|
|
|
int gpio, mask, ret = 0;
|
2016-07-26 05:59:38 +08:00
|
|
|
|
|
|
|
for (gpio = 0; gpio < WCOVE_GPIO_NUM; gpio++) {
|
|
|
|
ret += regmap_read(wg->regmap, to_reg(gpio, CTRL_OUT), &ctlo);
|
|
|
|
ret += regmap_read(wg->regmap, to_reg(gpio, CTRL_IN), &ctli);
|
2021-05-20 20:17:15 +08:00
|
|
|
if (ret) {
|
|
|
|
dev_err(wg->dev, "Failed to read registers: CTRL out/in\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2020-10-14 22:13:23 +08:00
|
|
|
ret += regmap_read(wg->regmap, to_ireg(gpio, IRQ_MASK, &mask), &irq_mask);
|
|
|
|
ret += regmap_read(wg->regmap, to_ireg(gpio, IRQ_STATUS, &mask), &irq_status);
|
2016-07-26 05:59:38 +08:00
|
|
|
if (ret) {
|
2021-05-20 20:17:15 +08:00
|
|
|
dev_err(wg->dev, "Failed to read registers: IRQ status/mask\n");
|
2016-07-26 05:59:38 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
seq_printf(s, " gpio-%-2d %s %s %s %s ctlo=%2x,%s %s\n",
|
|
|
|
gpio, ctlo & CTLO_DIR_OUT ? "out" : "in ",
|
|
|
|
ctli & 0x1 ? "hi" : "lo",
|
|
|
|
ctli & CTLI_INTCNT_NE ? "fall" : " ",
|
|
|
|
ctli & CTLI_INTCNT_PE ? "rise" : " ",
|
|
|
|
ctlo,
|
2020-10-14 22:13:23 +08:00
|
|
|
irq_mask & mask ? "mask " : "unmask",
|
|
|
|
irq_status & mask ? "pending" : " ");
|
2016-07-26 05:59:38 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int wcove_gpio_probe(struct platform_device *pdev)
|
|
|
|
{
|
|
|
|
struct intel_soc_pmic *pmic;
|
|
|
|
struct wcove_gpio *wg;
|
|
|
|
int virq, ret, irq;
|
|
|
|
struct device *dev;
|
2020-07-17 23:19:55 +08:00
|
|
|
struct gpio_irq_chip *girq;
|
2016-07-26 05:59:38 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* This gpio platform device is created by a mfd device (see
|
|
|
|
* drivers/mfd/intel_soc_pmic_bxtwc.c for details). Information
|
|
|
|
* shared by all sub-devices created by the mfd device, the regmap
|
|
|
|
* pointer for instance, is stored as driver data of the mfd device
|
|
|
|
* driver.
|
|
|
|
*/
|
|
|
|
pmic = dev_get_drvdata(pdev->dev.parent);
|
|
|
|
if (!pmic)
|
|
|
|
return -ENODEV;
|
|
|
|
|
|
|
|
irq = platform_get_irq(pdev, 0);
|
|
|
|
if (irq < 0)
|
|
|
|
return irq;
|
|
|
|
|
|
|
|
dev = &pdev->dev;
|
|
|
|
|
|
|
|
wg = devm_kzalloc(dev, sizeof(*wg), GFP_KERNEL);
|
|
|
|
if (!wg)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
2017-06-06 03:08:03 +08:00
|
|
|
wg->regmap_irq_chip = pmic->irq_chip_data;
|
2016-07-26 05:59:38 +08:00
|
|
|
|
|
|
|
platform_set_drvdata(pdev, wg);
|
|
|
|
|
|
|
|
mutex_init(&wg->buslock);
|
|
|
|
wg->chip.label = KBUILD_MODNAME;
|
|
|
|
wg->chip.direction_input = wcove_gpio_dir_in;
|
|
|
|
wg->chip.direction_output = wcove_gpio_dir_out;
|
2016-08-16 02:03:23 +08:00
|
|
|
wg->chip.get_direction = wcove_gpio_get_direction;
|
2016-07-26 05:59:38 +08:00
|
|
|
wg->chip.get = wcove_gpio_get;
|
|
|
|
wg->chip.set = wcove_gpio_set;
|
2021-01-08 17:24:13 +08:00
|
|
|
wg->chip.set_config = wcove_gpio_set_config;
|
2016-07-26 05:59:38 +08:00
|
|
|
wg->chip.base = -1;
|
|
|
|
wg->chip.ngpio = WCOVE_VGPIO_NUM;
|
|
|
|
wg->chip.can_sleep = true;
|
|
|
|
wg->chip.parent = pdev->dev.parent;
|
|
|
|
wg->chip.dbg_show = wcove_gpio_dbg_show;
|
|
|
|
wg->dev = dev;
|
|
|
|
wg->regmap = pmic->regmap;
|
|
|
|
|
|
|
|
virq = regmap_irq_get_virq(wg->regmap_irq_chip, irq);
|
|
|
|
if (virq < 0) {
|
|
|
|
dev_err(dev, "Failed to get virq by irq %d\n", irq);
|
|
|
|
return virq;
|
|
|
|
}
|
|
|
|
|
2020-07-17 23:19:55 +08:00
|
|
|
girq = &wg->chip.irq;
|
2022-05-13 01:39:21 +08:00
|
|
|
gpio_irq_chip_set_chip(girq, &wcove_irqchip);
|
2020-07-17 23:19:55 +08:00
|
|
|
/* This will let us handle the parent IRQ in the driver */
|
|
|
|
girq->parent_handler = NULL;
|
|
|
|
girq->num_parents = 0;
|
|
|
|
girq->parents = NULL;
|
|
|
|
girq->default_type = IRQ_TYPE_NONE;
|
|
|
|
girq->handler = handle_simple_irq;
|
|
|
|
girq->threaded = true;
|
|
|
|
|
2020-07-28 20:55:04 +08:00
|
|
|
ret = devm_request_threaded_irq(dev, virq, NULL, wcove_gpio_irq_handler,
|
|
|
|
IRQF_ONESHOT, pdev->name, wg);
|
|
|
|
if (ret) {
|
|
|
|
dev_err(dev, "Failed to request irq %d\n", virq);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2020-07-17 23:19:55 +08:00
|
|
|
ret = devm_gpiochip_add_data(dev, &wg->chip, wg);
|
|
|
|
if (ret) {
|
|
|
|
dev_err(dev, "Failed to add gpiochip: %d\n", ret);
|
|
|
|
return ret;
|
|
|
|
}
|
2016-11-24 20:27:54 +08:00
|
|
|
|
2017-06-06 03:08:03 +08:00
|
|
|
/* Enable GPIO0 interrupts */
|
2021-01-30 00:24:28 +08:00
|
|
|
ret = regmap_clear_bits(wg->regmap, IRQ_MASK_BASE + 0, GPIO_IRQ0_MASK);
|
2017-06-06 03:08:03 +08:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
/* Enable GPIO1 interrupts */
|
2021-01-30 00:24:28 +08:00
|
|
|
ret = regmap_clear_bits(wg->regmap, IRQ_MASK_BASE + 1, GPIO_IRQ1_MASK);
|
2017-06-06 03:08:03 +08:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
2016-07-26 05:59:38 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Whiskey Cove PMIC itself is a analog device(but with digital control
|
|
|
|
* interface) providing power management support for other devices in
|
|
|
|
* the accompanied SoC, so we have no .pm for Whiskey Cove GPIO driver.
|
|
|
|
*/
|
|
|
|
static struct platform_driver wcove_gpio_driver = {
|
|
|
|
.driver = {
|
|
|
|
.name = "bxt_wcove_gpio",
|
|
|
|
},
|
|
|
|
.probe = wcove_gpio_probe,
|
|
|
|
};
|
|
|
|
|
|
|
|
module_platform_driver(wcove_gpio_driver);
|
|
|
|
|
|
|
|
MODULE_AUTHOR("Ajay Thomas <ajay.thomas.david.rajamanickam@intel.com>");
|
|
|
|
MODULE_AUTHOR("Bin Gao <bin.gao@intel.com>");
|
|
|
|
MODULE_DESCRIPTION("Intel Whiskey Cove GPIO Driver");
|
|
|
|
MODULE_LICENSE("GPL v2");
|
|
|
|
MODULE_ALIAS("platform:bxt_wcove_gpio");
|