xref: /freebsd/sys/dev/gpio/intel/intelgpio.h (revision 5349a46babc03453b0e6679bf867272e7ef7ea22)
1 /*-
2  * SPDX-License-Identifier: BSD-2-Clause
3  *
4  * Copyright (c) 2026 Beckhoff Automation GmbH & Co. KG
5  */
6 
7 #ifndef _DEV_GPIO_INTEL_INTELGPIO_H_
8 #define _DEV_GPIO_INTEL_INTELGPIO_H_
9 
10 #include <sys/param.h>
11 #include <sys/bus.h>
12 #include <sys/gpio.h>
13 #include <sys/kernel.h>
14 
15 #include <contrib/dev/acpica/include/acpi.h>
16 
17 #define INTELGPIO_PADBAR_REG	      0x00c
18 #define INTELGPIO_PAD_SIZE	      16
19 
20 #define INTELGPIO_PADCFG0_GPIOTXSTATE (1 << 0)
21 #define INTELGPIO_PADCFG0_GPIORXSTATE (1 << 1)
22 #define INTELGPIO_PADCFG0_GPIOTXDIS   (1 << 8)
23 #define INTELGPIO_PADCFG0_GPIORXDIS   (1 << 9)
24 #define INTELGPIO_PADCFG0_PMODE_MASK  (0x7 << 10)
25 #define INTELGPIO_PADCFG0_PMODE_GPIO  0
26 
27 #define INTELGPIO_GPIO_NOMAP	      (-1)
28 #define INTELGPIO_MAX_COMMUNITIES     8
29 
30 struct intelgpio_padgroup {
31 	int first_pad;
32 	int npads;
33 	int gpio_base;
34 	const char *name;
35 };
36 
37 struct intelgpio_community {
38 	int ngroups;
39 	const struct intelgpio_padgroup *groups;
40 };
41 
42 struct intelgpio_platform {
43 	const struct intelgpio_community *communities;
44 	int ncommunities;
45 	char **hids;
46 	const char *desc;
47 };
48 
49 struct intelgpio_softc {
50 	device_t sc_dev;
51 	device_t sc_busdev;
52 	struct mtx sc_mtx;
53 	const struct intelgpio_platform *sc_plat;
54 
55 	struct resource *sc_mem_res[INTELGPIO_MAX_COMMUNITIES];
56 	uint32_t sc_padbar[INTELGPIO_MAX_COMMUNITIES];
57 };
58 
59 DECLARE_CLASS(intelgpio_driver);
60 
61 int intelgpio_probe(device_t dev, const struct intelgpio_platform *plat);
62 int intelgpio_attach(device_t dev, const struct intelgpio_platform *plat);
63 
64 #endif /* _DEV_GPIO_INTEL_INTELGPIO_H_ */
65