18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * Copyright (C) 2019 STMicroelectronics
48c2ecf20Sopenharmony_ci * Author(s): Amelie Delaunay <amelie.delaunay@st.com>.
58c2ecf20Sopenharmony_ci */
68c2ecf20Sopenharmony_ci
78c2ecf20Sopenharmony_ci#ifndef MFD_STMFX_H
88c2ecf20Sopenharmony_ci#define MFD_STMFX_H
98c2ecf20Sopenharmony_ci
108c2ecf20Sopenharmony_ci#include <linux/regmap.h>
118c2ecf20Sopenharmony_ci
128c2ecf20Sopenharmony_ci/* General */
138c2ecf20Sopenharmony_ci#define STMFX_REG_CHIP_ID		0x00 /* R */
148c2ecf20Sopenharmony_ci#define STMFX_REG_FW_VERSION_MSB	0x01 /* R */
158c2ecf20Sopenharmony_ci#define STMFX_REG_FW_VERSION_LSB	0x02 /* R */
168c2ecf20Sopenharmony_ci#define STMFX_REG_SYS_CTRL		0x40 /* RW */
178c2ecf20Sopenharmony_ci/* IRQ output management */
188c2ecf20Sopenharmony_ci#define STMFX_REG_IRQ_OUT_PIN		0x41 /* RW */
198c2ecf20Sopenharmony_ci#define STMFX_REG_IRQ_SRC_EN		0x42 /* RW */
208c2ecf20Sopenharmony_ci#define STMFX_REG_IRQ_PENDING		0x08 /* R */
218c2ecf20Sopenharmony_ci#define STMFX_REG_IRQ_ACK		0x44 /* RW */
228c2ecf20Sopenharmony_ci/* GPIO management */
238c2ecf20Sopenharmony_ci#define STMFX_REG_IRQ_GPI_PENDING1	0x0C /* R */
248c2ecf20Sopenharmony_ci#define STMFX_REG_IRQ_GPI_PENDING2	0x0D /* R */
258c2ecf20Sopenharmony_ci#define STMFX_REG_IRQ_GPI_PENDING3	0x0E /* R */
268c2ecf20Sopenharmony_ci#define STMFX_REG_GPIO_STATE1		0x10 /* R */
278c2ecf20Sopenharmony_ci#define STMFX_REG_GPIO_STATE2		0x11 /* R */
288c2ecf20Sopenharmony_ci#define STMFX_REG_GPIO_STATE3		0x12 /* R */
298c2ecf20Sopenharmony_ci#define STMFX_REG_IRQ_GPI_SRC1		0x48 /* RW */
308c2ecf20Sopenharmony_ci#define STMFX_REG_IRQ_GPI_SRC2		0x49 /* RW */
318c2ecf20Sopenharmony_ci#define STMFX_REG_IRQ_GPI_SRC3		0x4A /* RW */
328c2ecf20Sopenharmony_ci#define STMFX_REG_IRQ_GPI_EVT1		0x4C /* RW */
338c2ecf20Sopenharmony_ci#define STMFX_REG_IRQ_GPI_EVT2		0x4D /* RW */
348c2ecf20Sopenharmony_ci#define STMFX_REG_IRQ_GPI_EVT3		0x4E /* RW */
358c2ecf20Sopenharmony_ci#define STMFX_REG_IRQ_GPI_TYPE1		0x50 /* RW */
368c2ecf20Sopenharmony_ci#define STMFX_REG_IRQ_GPI_TYPE2		0x51 /* RW */
378c2ecf20Sopenharmony_ci#define STMFX_REG_IRQ_GPI_TYPE3		0x52 /* RW */
388c2ecf20Sopenharmony_ci#define STMFX_REG_IRQ_GPI_ACK1		0x54 /* RW */
398c2ecf20Sopenharmony_ci#define STMFX_REG_IRQ_GPI_ACK2		0x55 /* RW */
408c2ecf20Sopenharmony_ci#define STMFX_REG_IRQ_GPI_ACK3		0x56 /* RW */
418c2ecf20Sopenharmony_ci#define STMFX_REG_GPIO_DIR1		0x60 /* RW */
428c2ecf20Sopenharmony_ci#define STMFX_REG_GPIO_DIR2		0x61 /* RW */
438c2ecf20Sopenharmony_ci#define STMFX_REG_GPIO_DIR3		0x62 /* RW */
448c2ecf20Sopenharmony_ci#define STMFX_REG_GPIO_TYPE1		0x64 /* RW */
458c2ecf20Sopenharmony_ci#define STMFX_REG_GPIO_TYPE2		0x65 /* RW */
468c2ecf20Sopenharmony_ci#define STMFX_REG_GPIO_TYPE3		0x66 /* RW */
478c2ecf20Sopenharmony_ci#define STMFX_REG_GPIO_PUPD1		0x68 /* RW */
488c2ecf20Sopenharmony_ci#define STMFX_REG_GPIO_PUPD2		0x69 /* RW */
498c2ecf20Sopenharmony_ci#define STMFX_REG_GPIO_PUPD3		0x6A /* RW */
508c2ecf20Sopenharmony_ci#define STMFX_REG_GPO_SET1		0x6C /* RW */
518c2ecf20Sopenharmony_ci#define STMFX_REG_GPO_SET2		0x6D /* RW */
528c2ecf20Sopenharmony_ci#define STMFX_REG_GPO_SET3		0x6E /* RW */
538c2ecf20Sopenharmony_ci#define STMFX_REG_GPO_CLR1		0x70 /* RW */
548c2ecf20Sopenharmony_ci#define STMFX_REG_GPO_CLR2		0x71 /* RW */
558c2ecf20Sopenharmony_ci#define STMFX_REG_GPO_CLR3		0x72 /* RW */
568c2ecf20Sopenharmony_ci
578c2ecf20Sopenharmony_ci#define STMFX_REG_MAX			0xB0
588c2ecf20Sopenharmony_ci
598c2ecf20Sopenharmony_ci/* MFX boot time is around 10ms, so after reset, we have to wait this delay */
608c2ecf20Sopenharmony_ci#define STMFX_BOOT_TIME_MS 10
618c2ecf20Sopenharmony_ci
628c2ecf20Sopenharmony_ci/* STMFX_REG_CHIP_ID bitfields */
638c2ecf20Sopenharmony_ci#define STMFX_REG_CHIP_ID_MASK		GENMASK(7, 0)
648c2ecf20Sopenharmony_ci
658c2ecf20Sopenharmony_ci/* STMFX_REG_SYS_CTRL bitfields */
668c2ecf20Sopenharmony_ci#define STMFX_REG_SYS_CTRL_GPIO_EN	BIT(0)
678c2ecf20Sopenharmony_ci#define STMFX_REG_SYS_CTRL_TS_EN	BIT(1)
688c2ecf20Sopenharmony_ci#define STMFX_REG_SYS_CTRL_IDD_EN	BIT(2)
698c2ecf20Sopenharmony_ci#define STMFX_REG_SYS_CTRL_ALTGPIO_EN	BIT(3)
708c2ecf20Sopenharmony_ci#define STMFX_REG_SYS_CTRL_SWRST	BIT(7)
718c2ecf20Sopenharmony_ci
728c2ecf20Sopenharmony_ci/* STMFX_REG_IRQ_OUT_PIN bitfields */
738c2ecf20Sopenharmony_ci#define STMFX_REG_IRQ_OUT_PIN_TYPE	BIT(0) /* 0-OD 1-PP */
748c2ecf20Sopenharmony_ci#define STMFX_REG_IRQ_OUT_PIN_POL	BIT(1) /* 0-active LOW 1-active HIGH */
758c2ecf20Sopenharmony_ci
768c2ecf20Sopenharmony_ci/* STMFX_REG_IRQ_(SRC_EN/PENDING/ACK) bit shift */
778c2ecf20Sopenharmony_cienum stmfx_irqs {
788c2ecf20Sopenharmony_ci	STMFX_REG_IRQ_SRC_EN_GPIO = 0,
798c2ecf20Sopenharmony_ci	STMFX_REG_IRQ_SRC_EN_IDD,
808c2ecf20Sopenharmony_ci	STMFX_REG_IRQ_SRC_EN_ERROR,
818c2ecf20Sopenharmony_ci	STMFX_REG_IRQ_SRC_EN_TS_DET,
828c2ecf20Sopenharmony_ci	STMFX_REG_IRQ_SRC_EN_TS_NE,
838c2ecf20Sopenharmony_ci	STMFX_REG_IRQ_SRC_EN_TS_TH,
848c2ecf20Sopenharmony_ci	STMFX_REG_IRQ_SRC_EN_TS_FULL,
858c2ecf20Sopenharmony_ci	STMFX_REG_IRQ_SRC_EN_TS_OVF,
868c2ecf20Sopenharmony_ci	STMFX_REG_IRQ_SRC_MAX,
878c2ecf20Sopenharmony_ci};
888c2ecf20Sopenharmony_ci
898c2ecf20Sopenharmony_cienum stmfx_functions {
908c2ecf20Sopenharmony_ci	STMFX_FUNC_GPIO		= BIT(0), /* GPIO[15:0] */
918c2ecf20Sopenharmony_ci	STMFX_FUNC_ALTGPIO_LOW	= BIT(1), /* aGPIO[3:0] */
928c2ecf20Sopenharmony_ci	STMFX_FUNC_ALTGPIO_HIGH = BIT(2), /* aGPIO[7:4] */
938c2ecf20Sopenharmony_ci	STMFX_FUNC_TS		= BIT(3),
948c2ecf20Sopenharmony_ci	STMFX_FUNC_IDD		= BIT(4),
958c2ecf20Sopenharmony_ci};
968c2ecf20Sopenharmony_ci
978c2ecf20Sopenharmony_ci/**
988c2ecf20Sopenharmony_ci * struct stmfx_ddata - STMFX MFD structure
998c2ecf20Sopenharmony_ci * @device:		device reference used for logs
1008c2ecf20Sopenharmony_ci * @map:		register map
1018c2ecf20Sopenharmony_ci * @vdd:		STMFX power supply
1028c2ecf20Sopenharmony_ci * @irq_domain:		IRQ domain
1038c2ecf20Sopenharmony_ci * @lock:		IRQ bus lock
1048c2ecf20Sopenharmony_ci * @irq_src:		cache of IRQ_SRC_EN register for bus_lock
1058c2ecf20Sopenharmony_ci * @bkp_sysctrl:	backup of SYS_CTRL register for suspend/resume
1068c2ecf20Sopenharmony_ci * @bkp_irqoutpin:	backup of IRQ_OUT_PIN register for suspend/resume
1078c2ecf20Sopenharmony_ci */
1088c2ecf20Sopenharmony_cistruct stmfx {
1098c2ecf20Sopenharmony_ci	struct device *dev;
1108c2ecf20Sopenharmony_ci	struct regmap *map;
1118c2ecf20Sopenharmony_ci	struct regulator *vdd;
1128c2ecf20Sopenharmony_ci	int irq;
1138c2ecf20Sopenharmony_ci	struct irq_domain *irq_domain;
1148c2ecf20Sopenharmony_ci	struct mutex lock; /* IRQ bus lock */
1158c2ecf20Sopenharmony_ci	u8 irq_src;
1168c2ecf20Sopenharmony_ci#ifdef CONFIG_PM
1178c2ecf20Sopenharmony_ci	u8 bkp_sysctrl;
1188c2ecf20Sopenharmony_ci	u8 bkp_irqoutpin;
1198c2ecf20Sopenharmony_ci#endif
1208c2ecf20Sopenharmony_ci};
1218c2ecf20Sopenharmony_ci
1228c2ecf20Sopenharmony_ciint stmfx_function_enable(struct stmfx *stmfx, u32 func);
1238c2ecf20Sopenharmony_ciint stmfx_function_disable(struct stmfx *stmfx, u32 func);
1248c2ecf20Sopenharmony_ci#endif
125