162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
262306a36Sopenharmony_ci/*
362306a36Sopenharmony_ci * Copyright (C) 2014-2018 MediaTek Inc.
462306a36Sopenharmony_ci *
562306a36Sopenharmony_ci * Author: Maoguang Meng <maoguang.meng@mediatek.com>
662306a36Sopenharmony_ci *	   Sean Wang <sean.wang@mediatek.com>
762306a36Sopenharmony_ci *
862306a36Sopenharmony_ci */
962306a36Sopenharmony_ci#ifndef __MTK_EINT_H
1062306a36Sopenharmony_ci#define __MTK_EINT_H
1162306a36Sopenharmony_ci
1262306a36Sopenharmony_ci#include <linux/irqdomain.h>
1362306a36Sopenharmony_ci
1462306a36Sopenharmony_cistruct mtk_eint_regs {
1562306a36Sopenharmony_ci	unsigned int	stat;
1662306a36Sopenharmony_ci	unsigned int	ack;
1762306a36Sopenharmony_ci	unsigned int	mask;
1862306a36Sopenharmony_ci	unsigned int	mask_set;
1962306a36Sopenharmony_ci	unsigned int	mask_clr;
2062306a36Sopenharmony_ci	unsigned int	sens;
2162306a36Sopenharmony_ci	unsigned int	sens_set;
2262306a36Sopenharmony_ci	unsigned int	sens_clr;
2362306a36Sopenharmony_ci	unsigned int	soft;
2462306a36Sopenharmony_ci	unsigned int	soft_set;
2562306a36Sopenharmony_ci	unsigned int	soft_clr;
2662306a36Sopenharmony_ci	unsigned int	pol;
2762306a36Sopenharmony_ci	unsigned int	pol_set;
2862306a36Sopenharmony_ci	unsigned int	pol_clr;
2962306a36Sopenharmony_ci	unsigned int	dom_en;
3062306a36Sopenharmony_ci	unsigned int	dbnc_ctrl;
3162306a36Sopenharmony_ci	unsigned int	dbnc_set;
3262306a36Sopenharmony_ci	unsigned int	dbnc_clr;
3362306a36Sopenharmony_ci};
3462306a36Sopenharmony_ci
3562306a36Sopenharmony_cistruct mtk_eint_hw {
3662306a36Sopenharmony_ci	u8		port_mask;
3762306a36Sopenharmony_ci	u8		ports;
3862306a36Sopenharmony_ci	unsigned int	ap_num;
3962306a36Sopenharmony_ci	unsigned int	db_cnt;
4062306a36Sopenharmony_ci	const unsigned int *db_time;
4162306a36Sopenharmony_ci};
4262306a36Sopenharmony_ci
4362306a36Sopenharmony_ciextern const unsigned int debounce_time_mt2701[];
4462306a36Sopenharmony_ciextern const unsigned int debounce_time_mt6765[];
4562306a36Sopenharmony_ciextern const unsigned int debounce_time_mt6795[];
4662306a36Sopenharmony_ci
4762306a36Sopenharmony_cistruct mtk_eint;
4862306a36Sopenharmony_ci
4962306a36Sopenharmony_cistruct mtk_eint_xt {
5062306a36Sopenharmony_ci	int (*get_gpio_n)(void *data, unsigned long eint_n,
5162306a36Sopenharmony_ci			  unsigned int *gpio_n,
5262306a36Sopenharmony_ci			  struct gpio_chip **gpio_chip);
5362306a36Sopenharmony_ci	int (*get_gpio_state)(void *data, unsigned long eint_n);
5462306a36Sopenharmony_ci	int (*set_gpio_as_eint)(void *data, unsigned long eint_n);
5562306a36Sopenharmony_ci};
5662306a36Sopenharmony_ci
5762306a36Sopenharmony_cistruct mtk_eint {
5862306a36Sopenharmony_ci	struct device *dev;
5962306a36Sopenharmony_ci	void __iomem *base;
6062306a36Sopenharmony_ci	struct irq_domain *domain;
6162306a36Sopenharmony_ci	int irq;
6262306a36Sopenharmony_ci
6362306a36Sopenharmony_ci	int *dual_edge;
6462306a36Sopenharmony_ci	u32 *wake_mask;
6562306a36Sopenharmony_ci	u32 *cur_mask;
6662306a36Sopenharmony_ci
6762306a36Sopenharmony_ci	/* Used to fit into various EINT device */
6862306a36Sopenharmony_ci	const struct mtk_eint_hw *hw;
6962306a36Sopenharmony_ci	const struct mtk_eint_regs *regs;
7062306a36Sopenharmony_ci	u16 num_db_time;
7162306a36Sopenharmony_ci
7262306a36Sopenharmony_ci	/* Used to fit into various pinctrl device */
7362306a36Sopenharmony_ci	void *pctl;
7462306a36Sopenharmony_ci	const struct mtk_eint_xt *gpio_xlate;
7562306a36Sopenharmony_ci};
7662306a36Sopenharmony_ci
7762306a36Sopenharmony_ci#if IS_ENABLED(CONFIG_EINT_MTK)
7862306a36Sopenharmony_ciint mtk_eint_do_init(struct mtk_eint *eint);
7962306a36Sopenharmony_ciint mtk_eint_do_suspend(struct mtk_eint *eint);
8062306a36Sopenharmony_ciint mtk_eint_do_resume(struct mtk_eint *eint);
8162306a36Sopenharmony_ciint mtk_eint_set_debounce(struct mtk_eint *eint, unsigned long eint_n,
8262306a36Sopenharmony_ci			  unsigned int debounce);
8362306a36Sopenharmony_ciint mtk_eint_find_irq(struct mtk_eint *eint, unsigned long eint_n);
8462306a36Sopenharmony_ci
8562306a36Sopenharmony_ci#else
8662306a36Sopenharmony_cistatic inline int mtk_eint_do_init(struct mtk_eint *eint)
8762306a36Sopenharmony_ci{
8862306a36Sopenharmony_ci	return -EOPNOTSUPP;
8962306a36Sopenharmony_ci}
9062306a36Sopenharmony_ci
9162306a36Sopenharmony_cistatic inline int mtk_eint_do_suspend(struct mtk_eint *eint)
9262306a36Sopenharmony_ci{
9362306a36Sopenharmony_ci	return -EOPNOTSUPP;
9462306a36Sopenharmony_ci}
9562306a36Sopenharmony_ci
9662306a36Sopenharmony_cistatic inline int mtk_eint_do_resume(struct mtk_eint *eint)
9762306a36Sopenharmony_ci{
9862306a36Sopenharmony_ci	return -EOPNOTSUPP;
9962306a36Sopenharmony_ci}
10062306a36Sopenharmony_ci
10162306a36Sopenharmony_cistatic inline int mtk_eint_set_debounce(struct mtk_eint *eint, unsigned long eint_n,
10262306a36Sopenharmony_ci			  unsigned int debounce)
10362306a36Sopenharmony_ci{
10462306a36Sopenharmony_ci	return -EOPNOTSUPP;
10562306a36Sopenharmony_ci}
10662306a36Sopenharmony_ci
10762306a36Sopenharmony_cistatic inline int mtk_eint_find_irq(struct mtk_eint *eint, unsigned long eint_n)
10862306a36Sopenharmony_ci{
10962306a36Sopenharmony_ci	return -EOPNOTSUPP;
11062306a36Sopenharmony_ci}
11162306a36Sopenharmony_ci#endif
11262306a36Sopenharmony_ci#endif /* __MTK_EINT_H */
113