xref: /illumos-gate/usr/src/uts/common/sys/gpio/kgpio_provider.h (revision fd71220ba0fafcc9cf5ea0785db206f3f31336e7)
1*fd71220bSRobert Mustacchi /*
2*fd71220bSRobert Mustacchi  * This file and its contents are supplied under the terms of the
3*fd71220bSRobert Mustacchi  * Common Development and Distribution License ("CDDL"), version 1.0.
4*fd71220bSRobert Mustacchi  * You may only use this file in accordance with the terms of version
5*fd71220bSRobert Mustacchi  * 1.0 of the CDDL.
6*fd71220bSRobert Mustacchi  *
7*fd71220bSRobert Mustacchi  * A full copy of the text of the CDDL should have accompanied this
8*fd71220bSRobert Mustacchi  * source.  A copy of the CDDL is also available via the Internet at
9*fd71220bSRobert Mustacchi  * http://www.illumos.org/license/CDDL.
10*fd71220bSRobert Mustacchi  */
11*fd71220bSRobert Mustacchi 
12*fd71220bSRobert Mustacchi /*
13*fd71220bSRobert Mustacchi  * Copyright 2022 Oxide Computer Company
14*fd71220bSRobert Mustacchi  */
15*fd71220bSRobert Mustacchi 
16*fd71220bSRobert Mustacchi #ifndef _SYS_GPIO_KGPIO_PROVIDER_H
17*fd71220bSRobert Mustacchi #define	_SYS_GPIO_KGPIO_PROVIDER_H
18*fd71220bSRobert Mustacchi 
19*fd71220bSRobert Mustacchi /*
20*fd71220bSRobert Mustacchi  * This header describes the private interface between the kernel GPIO framework
21*fd71220bSRobert Mustacchi  * and GPIO providers.
22*fd71220bSRobert Mustacchi  */
23*fd71220bSRobert Mustacchi 
24*fd71220bSRobert Mustacchi #include <sys/nvpair.h>
25*fd71220bSRobert Mustacchi #include <sys/stdint.h>
26*fd71220bSRobert Mustacchi 
27*fd71220bSRobert Mustacchi #include <sys/gpio/dpio.h>
28*fd71220bSRobert Mustacchi #include <sys/gpio/kgpio_attr.h>
29*fd71220bSRobert Mustacchi 
30*fd71220bSRobert Mustacchi #ifdef __cplusplus
31*fd71220bSRobert Mustacchi extern "C" {
32*fd71220bSRobert Mustacchi #endif
33*fd71220bSRobert Mustacchi 
34*fd71220bSRobert Mustacchi 
35*fd71220bSRobert Mustacchi /*
36*fd71220bSRobert Mustacchi  * The remainder of this header is intended for kernel implementations of the
37*fd71220bSRobert Mustacchi  * KGPIO framework.
38*fd71220bSRobert Mustacchi  */
39*fd71220bSRobert Mustacchi #ifdef _KERNEL
40*fd71220bSRobert Mustacchi 
41*fd71220bSRobert Mustacchi typedef int (*kgpio_name2id_f)(void *, const char *, uint32_t *);
42*fd71220bSRobert Mustacchi typedef int (*kgpio_attr_get_f)(void *, uint32_t, nvlist_t *);
43*fd71220bSRobert Mustacchi typedef int (*kgpio_attr_set_f)(void *, uint32_t, nvlist_t *, nvlist_t *);
44*fd71220bSRobert Mustacchi typedef int (*kgpio_dpio_cap_f)(void *, uint32_t, dpio_caps_t *);
45*fd71220bSRobert Mustacchi typedef int (*kgpio_dpio_input_f)(void *, uint32_t, dpio_input_t *);
46*fd71220bSRobert Mustacchi typedef int (*kgpio_dpio_output_get_f)(void *, uint32_t, dpio_output_t *);
47*fd71220bSRobert Mustacchi typedef int (*kgpio_dpio_output_set_f)(void *, uint32_t, dpio_output_t);
48*fd71220bSRobert Mustacchi 
49*fd71220bSRobert Mustacchi typedef struct kgpio_ops {
50*fd71220bSRobert Mustacchi 	kgpio_name2id_f		kgo_name2id;
51*fd71220bSRobert Mustacchi 	kgpio_attr_get_f	kgo_get;
52*fd71220bSRobert Mustacchi 	kgpio_attr_set_f	kgo_set;
53*fd71220bSRobert Mustacchi 	kgpio_dpio_cap_f	kgo_cap;
54*fd71220bSRobert Mustacchi 	kgpio_dpio_input_f	kgo_input;
55*fd71220bSRobert Mustacchi 	kgpio_dpio_output_get_f	kgo_output_state;
56*fd71220bSRobert Mustacchi 	kgpio_dpio_output_set_f	kgo_output;
57*fd71220bSRobert Mustacchi } kgpio_ops_t;
58*fd71220bSRobert Mustacchi 
59*fd71220bSRobert Mustacchi extern int kgpio_register(dev_info_t *, const kgpio_ops_t *, void *, uint32_t);
60*fd71220bSRobert Mustacchi extern int kgpio_unregister(dev_info_t *);
61*fd71220bSRobert Mustacchi 
62*fd71220bSRobert Mustacchi /*
63*fd71220bSRobert Mustacchi  * These are convenience functions for filling in information about an
64*fd71220bSRobert Mustacchi  * attribute.
65*fd71220bSRobert Mustacchi  */
66*fd71220bSRobert Mustacchi extern void kgpio_nvl_attr_fill_u32(nvlist_t *, nvlist_t *, const char *,
67*fd71220bSRobert Mustacchi     uint32_t, uint_t, uint32_t *, kgpio_prot_t);
68*fd71220bSRobert Mustacchi extern void kgpio_nvl_attr_fill_str(nvlist_t *, nvlist_t *, const char *,
69*fd71220bSRobert Mustacchi     const char *, uint_t, char *const *, kgpio_prot_t);
70*fd71220bSRobert Mustacchi 
71*fd71220bSRobert Mustacchi #endif	/* _KERNEL */
72*fd71220bSRobert Mustacchi 
73*fd71220bSRobert Mustacchi #ifdef __cplusplus
74*fd71220bSRobert Mustacchi }
75*fd71220bSRobert Mustacchi #endif
76*fd71220bSRobert Mustacchi 
77*fd71220bSRobert Mustacchi #endif /* _SYS_GPIO_KGPIO_PROVIDER_H */
78