106252adeSAmelie Delaunay /* SPDX-License-Identifier: GPL-2.0 */ 206252adeSAmelie Delaunay /* 306252adeSAmelie Delaunay * Copyright (C) 2019 STMicroelectronics 406252adeSAmelie Delaunay * Author(s): Amelie Delaunay <amelie.delaunay@st.com>. 506252adeSAmelie Delaunay */ 606252adeSAmelie Delaunay 706252adeSAmelie Delaunay #ifndef MFD_STMFX_H 8b1c83bd8SNathan Chancellor #define MFD_STMFX_H 906252adeSAmelie Delaunay 1006252adeSAmelie Delaunay #include <linux/regmap.h> 1106252adeSAmelie Delaunay 1206252adeSAmelie Delaunay /* General */ 1306252adeSAmelie Delaunay #define STMFX_REG_CHIP_ID 0x00 /* R */ 1406252adeSAmelie Delaunay #define STMFX_REG_FW_VERSION_MSB 0x01 /* R */ 1506252adeSAmelie Delaunay #define STMFX_REG_FW_VERSION_LSB 0x02 /* R */ 1606252adeSAmelie Delaunay #define STMFX_REG_SYS_CTRL 0x40 /* RW */ 1706252adeSAmelie Delaunay /* IRQ output management */ 1806252adeSAmelie Delaunay #define STMFX_REG_IRQ_OUT_PIN 0x41 /* RW */ 1906252adeSAmelie Delaunay #define STMFX_REG_IRQ_SRC_EN 0x42 /* RW */ 2006252adeSAmelie Delaunay #define STMFX_REG_IRQ_PENDING 0x08 /* R */ 2106252adeSAmelie Delaunay #define STMFX_REG_IRQ_ACK 0x44 /* RW */ 2206252adeSAmelie Delaunay /* GPIO management */ 2306252adeSAmelie Delaunay #define STMFX_REG_IRQ_GPI_PENDING1 0x0C /* R */ 2406252adeSAmelie Delaunay #define STMFX_REG_IRQ_GPI_PENDING2 0x0D /* R */ 2506252adeSAmelie Delaunay #define STMFX_REG_IRQ_GPI_PENDING3 0x0E /* R */ 2606252adeSAmelie Delaunay #define STMFX_REG_GPIO_STATE1 0x10 /* R */ 2706252adeSAmelie Delaunay #define STMFX_REG_GPIO_STATE2 0x11 /* R */ 2806252adeSAmelie Delaunay #define STMFX_REG_GPIO_STATE3 0x12 /* R */ 2906252adeSAmelie Delaunay #define STMFX_REG_IRQ_GPI_SRC1 0x48 /* RW */ 3006252adeSAmelie Delaunay #define STMFX_REG_IRQ_GPI_SRC2 0x49 /* RW */ 3106252adeSAmelie Delaunay #define STMFX_REG_IRQ_GPI_SRC3 0x4A /* RW */ 3206252adeSAmelie Delaunay #define STMFX_REG_IRQ_GPI_EVT1 0x4C /* RW */ 3306252adeSAmelie Delaunay #define STMFX_REG_IRQ_GPI_EVT2 0x4D /* RW */ 3406252adeSAmelie Delaunay #define STMFX_REG_IRQ_GPI_EVT3 0x4E /* RW */ 3506252adeSAmelie Delaunay #define STMFX_REG_IRQ_GPI_TYPE1 0x50 /* RW */ 3606252adeSAmelie Delaunay #define STMFX_REG_IRQ_GPI_TYPE2 0x51 /* RW */ 3706252adeSAmelie Delaunay #define STMFX_REG_IRQ_GPI_TYPE3 0x52 /* RW */ 3806252adeSAmelie Delaunay #define STMFX_REG_IRQ_GPI_ACK1 0x54 /* RW */ 3906252adeSAmelie Delaunay #define STMFX_REG_IRQ_GPI_ACK2 0x55 /* RW */ 4006252adeSAmelie Delaunay #define STMFX_REG_IRQ_GPI_ACK3 0x56 /* RW */ 4106252adeSAmelie Delaunay #define STMFX_REG_GPIO_DIR1 0x60 /* RW */ 4206252adeSAmelie Delaunay #define STMFX_REG_GPIO_DIR2 0x61 /* RW */ 4306252adeSAmelie Delaunay #define STMFX_REG_GPIO_DIR3 0x62 /* RW */ 4406252adeSAmelie Delaunay #define STMFX_REG_GPIO_TYPE1 0x64 /* RW */ 4506252adeSAmelie Delaunay #define STMFX_REG_GPIO_TYPE2 0x65 /* RW */ 4606252adeSAmelie Delaunay #define STMFX_REG_GPIO_TYPE3 0x66 /* RW */ 4706252adeSAmelie Delaunay #define STMFX_REG_GPIO_PUPD1 0x68 /* RW */ 4806252adeSAmelie Delaunay #define STMFX_REG_GPIO_PUPD2 0x69 /* RW */ 4906252adeSAmelie Delaunay #define STMFX_REG_GPIO_PUPD3 0x6A /* RW */ 5006252adeSAmelie Delaunay #define STMFX_REG_GPO_SET1 0x6C /* RW */ 5106252adeSAmelie Delaunay #define STMFX_REG_GPO_SET2 0x6D /* RW */ 5206252adeSAmelie Delaunay #define STMFX_REG_GPO_SET3 0x6E /* RW */ 5306252adeSAmelie Delaunay #define STMFX_REG_GPO_CLR1 0x70 /* RW */ 5406252adeSAmelie Delaunay #define STMFX_REG_GPO_CLR2 0x71 /* RW */ 5506252adeSAmelie Delaunay #define STMFX_REG_GPO_CLR3 0x72 /* RW */ 5606252adeSAmelie Delaunay 5706252adeSAmelie Delaunay #define STMFX_REG_MAX 0xB0 5806252adeSAmelie Delaunay 5906252adeSAmelie Delaunay /* MFX boot time is around 10ms, so after reset, we have to wait this delay */ 6006252adeSAmelie Delaunay #define STMFX_BOOT_TIME_MS 10 6106252adeSAmelie Delaunay 6206252adeSAmelie Delaunay /* STMFX_REG_CHIP_ID bitfields */ 6306252adeSAmelie Delaunay #define STMFX_REG_CHIP_ID_MASK GENMASK(7, 0) 6406252adeSAmelie Delaunay 6506252adeSAmelie Delaunay /* STMFX_REG_SYS_CTRL bitfields */ 6606252adeSAmelie Delaunay #define STMFX_REG_SYS_CTRL_GPIO_EN BIT(0) 6706252adeSAmelie Delaunay #define STMFX_REG_SYS_CTRL_TS_EN BIT(1) 6806252adeSAmelie Delaunay #define STMFX_REG_SYS_CTRL_IDD_EN BIT(2) 6906252adeSAmelie Delaunay #define STMFX_REG_SYS_CTRL_ALTGPIO_EN BIT(3) 7006252adeSAmelie Delaunay #define STMFX_REG_SYS_CTRL_SWRST BIT(7) 7106252adeSAmelie Delaunay 7206252adeSAmelie Delaunay /* STMFX_REG_IRQ_OUT_PIN bitfields */ 7306252adeSAmelie Delaunay #define STMFX_REG_IRQ_OUT_PIN_TYPE BIT(0) /* 0-OD 1-PP */ 7406252adeSAmelie Delaunay #define STMFX_REG_IRQ_OUT_PIN_POL BIT(1) /* 0-active LOW 1-active HIGH */ 7506252adeSAmelie Delaunay 7606252adeSAmelie Delaunay /* STMFX_REG_IRQ_(SRC_EN/PENDING/ACK) bit shift */ 7706252adeSAmelie Delaunay enum stmfx_irqs { 7806252adeSAmelie Delaunay STMFX_REG_IRQ_SRC_EN_GPIO = 0, 7906252adeSAmelie Delaunay STMFX_REG_IRQ_SRC_EN_IDD, 8006252adeSAmelie Delaunay STMFX_REG_IRQ_SRC_EN_ERROR, 8106252adeSAmelie Delaunay STMFX_REG_IRQ_SRC_EN_TS_DET, 8206252adeSAmelie Delaunay STMFX_REG_IRQ_SRC_EN_TS_NE, 8306252adeSAmelie Delaunay STMFX_REG_IRQ_SRC_EN_TS_TH, 8406252adeSAmelie Delaunay STMFX_REG_IRQ_SRC_EN_TS_FULL, 8506252adeSAmelie Delaunay STMFX_REG_IRQ_SRC_EN_TS_OVF, 8606252adeSAmelie Delaunay STMFX_REG_IRQ_SRC_MAX, 8706252adeSAmelie Delaunay }; 8806252adeSAmelie Delaunay 8906252adeSAmelie Delaunay enum stmfx_functions { 9006252adeSAmelie Delaunay STMFX_FUNC_GPIO = BIT(0), /* GPIO[15:0] */ 9106252adeSAmelie Delaunay STMFX_FUNC_ALTGPIO_LOW = BIT(1), /* aGPIO[3:0] */ 9206252adeSAmelie Delaunay STMFX_FUNC_ALTGPIO_HIGH = BIT(2), /* aGPIO[7:4] */ 9306252adeSAmelie Delaunay STMFX_FUNC_TS = BIT(3), 9406252adeSAmelie Delaunay STMFX_FUNC_IDD = BIT(4), 9506252adeSAmelie Delaunay }; 9606252adeSAmelie Delaunay 9706252adeSAmelie Delaunay /** 9806252adeSAmelie Delaunay * struct stmfx_ddata - STMFX MFD structure 9906252adeSAmelie Delaunay * @device: device reference used for logs 10006252adeSAmelie Delaunay * @map: register map 10106252adeSAmelie Delaunay * @vdd: STMFX power supply 10206252adeSAmelie Delaunay * @irq_domain: IRQ domain 10306252adeSAmelie Delaunay * @lock: IRQ bus lock 10406252adeSAmelie Delaunay * @irq_src: cache of IRQ_SRC_EN register for bus_lock 10506252adeSAmelie Delaunay * @bkp_sysctrl: backup of SYS_CTRL register for suspend/resume 10606252adeSAmelie Delaunay * @bkp_irqoutpin: backup of IRQ_OUT_PIN register for suspend/resume 10706252adeSAmelie Delaunay */ 10806252adeSAmelie Delaunay struct stmfx { 10906252adeSAmelie Delaunay struct device *dev; 11006252adeSAmelie Delaunay struct regmap *map; 11106252adeSAmelie Delaunay struct regulator *vdd; 11297eda5dcSAmelie Delaunay int irq; 11306252adeSAmelie Delaunay struct irq_domain *irq_domain; 11406252adeSAmelie Delaunay struct mutex lock; /* IRQ bus lock */ 11506252adeSAmelie Delaunay u8 irq_src; 11606252adeSAmelie Delaunay u8 bkp_sysctrl; 11706252adeSAmelie Delaunay u8 bkp_irqoutpin; 11806252adeSAmelie Delaunay }; 11906252adeSAmelie Delaunay 12006252adeSAmelie Delaunay int stmfx_function_enable(struct stmfx *stmfx, u32 func); 12106252adeSAmelie Delaunay int stmfx_function_disable(struct stmfx *stmfx, u32 func); 12206252adeSAmelie Delaunay #endif 123