xref: /freebsd/sys/dev/gpio/intel/tglhgpio.c (revision c2bd655dc3f9c09e3063321e160cb3d367ef2c79)
1 /*-
2  * SPDX-License-Identifier: BSD-2-Clause
3  *
4  * Copyright (c) 2026 Beckhoff Automation GmbH & Co. KG
5  */
6 
7 #include <sys/param.h>
8 #include <sys/systm.h>
9 #include <sys/bus.h>
10 #include <sys/gpio.h>
11 #include <sys/kernel.h>
12 #include <sys/module.h>
13 
14 #include <contrib/dev/acpica/include/acpi.h>
15 
16 #include <dev/acpica/acpivar.h>
17 #include <dev/gpio/gpiobusvar.h>
18 
19 #include "intelgpio.h"
20 
21 #include "gpio_if.h"
22 #include "opt_acpi.h"
23 
24 /* Community 0: GPP_A, GPP_R, GPP_B, vGPIO_0 */
25 static const struct intelgpio_padgroup tglh_com0_groups[] = {
26 	{ .first_pad = 0, .npads = 25, .gpio_base = 0, .name = "GPP_A" },
27 	{ .first_pad = 25, .npads = 20, .gpio_base = 32, .name = "GPP_R" },
28 	{ .first_pad = 45, .npads = 26, .gpio_base = 64, .name = "GPP_B" },
29 	{ .first_pad = 71, .npads = 8, .gpio_base = 96, .name = "vGPIO_0" },
30 };
31 
32 /* Community 1: GPP_D, GPP_C, GPP_S, GPP_G, vGPIO */
33 static const struct intelgpio_padgroup tglh_com1_groups[] = {
34 	{ .first_pad = 79, .npads = 26, .gpio_base = 128, .name = "GPP_D" },
35 	{ .first_pad = 105, .npads = 24, .gpio_base = 160, .name = "GPP_C" },
36 	{ .first_pad = 129, .npads = 8, .gpio_base = 192, .name = "GPP_S" },
37 	{ .first_pad = 137, .npads = 17, .gpio_base = 224, .name = "GPP_G" },
38 	{ .first_pad = 154, .npads = 27, .gpio_base = 256, .name = "vGPIO" },
39 };
40 
41 /* Community 3: GPP_E, GPP_F */
42 static const struct intelgpio_padgroup tglh_com3_groups[] = {
43 	{ .first_pad = 181, .npads = 13, .gpio_base = 288, .name = "GPP_E" },
44 	{ .first_pad = 194, .npads = 24, .gpio_base = 320, .name = "GPP_F" },
45 };
46 
47 /* Community 4: GPP_H, GPP_J, GPP_K */
48 static const struct intelgpio_padgroup tglh_com4_groups[] = {
49 	{ .first_pad = 218, .npads = 24, .gpio_base = 352, .name = "GPP_H" },
50 	{ .first_pad = 242, .npads = 10, .gpio_base = 384, .name = "GPP_J" },
51 	{ .first_pad = 252, .npads = 15, .gpio_base = 416, .name = "GPP_K" },
52 };
53 
54 /* Community 5: GPP_I, JTAG */
55 static const struct intelgpio_padgroup tglh_com5_groups[] = {
56 	{ .first_pad = 267, .npads = 15, .gpio_base = 448, .name = "GPP_I" },
57 	{ .first_pad = 282,
58 	    .npads = 9,
59 	    .gpio_base = INTELGPIO_GPIO_NOMAP,
60 	    .name = "JTAG" },
61 };
62 
63 static const struct intelgpio_community tglh_communities[] = {
64 	{ .ngroups = nitems(tglh_com0_groups), .groups = tglh_com0_groups },
65 	{ .ngroups = nitems(tglh_com1_groups), .groups = tglh_com1_groups },
66 	{ .ngroups = nitems(tglh_com3_groups), .groups = tglh_com3_groups },
67 	{ .ngroups = nitems(tglh_com4_groups), .groups = tglh_com4_groups },
68 	{ .ngroups = nitems(tglh_com5_groups), .groups = tglh_com5_groups },
69 };
70 
71 static char *tglh_hids[] = { "INT34C6", NULL };
72 
73 static const struct intelgpio_platform tglh_platform = {
74 	.communities = tglh_communities,
75 	.ncommunities = nitems(tglh_communities),
76 	.hids = tglh_hids,
77 	.desc = "Intel Tiger Lake-H GPIO",
78 };
79 
80 static int
tglh_gpio_probe(device_t dev)81 tglh_gpio_probe(device_t dev)
82 {
83 	return (intelgpio_probe(dev, &tglh_platform));
84 }
85 
86 static int
tglh_gpio_attach(device_t dev)87 tglh_gpio_attach(device_t dev)
88 {
89 	return (intelgpio_attach(dev, &tglh_platform));
90 }
91 
92 static device_method_t tglh_methods[] = {
93 	DEVMETHOD(device_probe, tglh_gpio_probe),
94 	DEVMETHOD(device_attach, tglh_gpio_attach),
95 
96 	DEVMETHOD_END
97 };
98 
99 DEFINE_CLASS_1(gpio, tglh_driver, tglh_methods,
100     sizeof(struct intelgpio_softc), intelgpio_driver);
101 
102 DRIVER_MODULE(tglhgpio, acpi, tglh_driver, NULL, NULL);
103 MODULE_DEPEND(tglhgpio, acpi, 1, 1, 1);
104 MODULE_DEPEND(tglhgpio, gpiobus, 1, 1, 1);
105 MODULE_VERSION(tglhgpio, 1);
106 ACPI_PNP_INFO(tglh_hids);
107