Zephyr API
4.4.99
A Scalable Open Source RTOS
Toggle main menu visibility
Loading...
Searching...
No Matches
mctp_i2c_gpio_controller.h
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2025 Intel Corporation
3
*
4
* SPDX-License-Identifier: Apache-2.0
5
*
6
*/
7
8
#ifndef ZEPHYR_MCTP_I2C_GPIO_CONTROLLER_H_
9
#define ZEPHYR_MCTP_I2C_GPIO_CONTROLLER_H_
10
11
#include <
stdint.h
>
12
#include <
zephyr/kernel.h
>
13
#include <
zephyr/device.h
>
14
#include <
zephyr/drivers/i2c.h
>
15
#include <
zephyr/drivers/gpio.h
>
16
#include <
zephyr/sys/mpsc_lockfree.h
>
17
#include <
zephyr/rtio/rtio.h
>
18
#include <
zephyr/pmci/mctp/mctp_i2c_gpio_common.h
>
19
20
#include <libmctp.h>
21
#include <stdatomic.h>
22
24
25
struct
mctp_binding_i2c_gpio_controller
;
26
27
struct
mctp_i2c_gpio_controller_cb {
28
struct
mpsc_node q;
29
struct
gpio_callback callback;
30
struct
mctp_binding_i2c_gpio_controller *binding;
31
uint8_t
index;
32
};
33
35
39
struct
mctp_binding_i2c_gpio_controller
{
41
struct
mctp_binding binding;
42
const
struct
device
*i2c;
43
44
uint8_t
rx_buf_len;
45
uint8_t
rx_buf[MCTP_I2C_GPIO_MAX_PKT_SIZE];
46
uint8_t
tx_buf[MCTP_I2C_GPIO_MAX_PKT_SIZE];
47
48
struct
mctp_pktbuf *rx_pkt;
49
50
/* Avoid needing a thread or work queue task by using RTIO */
51
struct
k_sem
*tx_lock;
52
struct
rtio
*r_tx;
53
54
/* Mapping of endpoints to i2c targets with gpios */
55
size_t
num_endpoints;
56
const
uint8_t
*endpoint_ids;
57
const
struct
rtio_iodev
**endpoint_iodevs;
58
const
struct
gpio_dt_spec
*endpoint_gpios;
59
struct
mctp_i2c_gpio_controller_cb *endpoint_gpio_cbs;
60
61
/* Ongoing request from a particular gpio */
62
struct
k_spinlock
rx_lock;
63
struct
rtio
*r_rx;
64
struct
mpsc
rx_q;
65
struct
mctp_i2c_gpio_controller_cb *inflight_rx;
66
67
uint8_t
tx_storage[MCTP_PKTBUF_SIZE(MCTP_I2C_GPIO_MAX_PKT_SIZE)] PKTBUF_STORAGE_ALIGN;
68
70
};
71
73
int
mctp_i2c_gpio_controller_start(
struct
mctp_binding *binding);
74
int
mctp_i2c_gpio_controller_tx(
struct
mctp_binding *binding,
struct
mctp_pktbuf *pkt);
75
76
#define MCTP_I2C_GPIO_CONTROLLER_IODEV_NAME(_idx, _name) _name##_idx
77
78
#define MCTP_I2C_GPIO_CONTROLLER_IODEV_DEFINE(_node_id, addrs, _idx, _name) \
79
I2C_IODEV_DEFINE(MCTP_I2C_GPIO_CONTROLLER_IODEV_NAME(_idx, _name), \
80
DT_PHANDLE(_node_id, i2c), \
81
DT_PROP_BY_IDX(_node_id, addrs, _idx));
82
83
84
#define MCTP_I2C_GPIO_CONTROLLER_DEFINE_GPIOS(_node_id, _name) \
85
const struct gpio_dt_spec _name##_endpoint_gpios[] = { \
86
DT_FOREACH_PROP_ELEM_SEP(_node_id, endpoint_gpios, GPIO_DT_SPEC_GET_BY_IDX, (,)) \
87
}
88
89
#define MCTP_I2C_GPIO_CONTROLLER_DEFINE_IDS(_node_id, _name) \
90
const uint8_t _name##_endpoint_ids[] = DT_PROP(_node_id, endpoint_ids);
91
92
#define MCTP_I2C_GPIO_CONTROLLER_DEFINE_GPIO_CBS(_node_id, _name) \
93
struct mctp_i2c_gpio_controller_cb \
94
_name##_endpoint_gpio_cbs[DT_PROP_LEN(_node_id, endpoint_ids)]
95
96
97
#define MCTP_I2C_GPIO_CONTROLLER_DEFINE_IODEVS(_node_id, _name) \
98
DT_FOREACH_PROP_ELEM_VARGS(_node_id, endpoint_addrs, \
99
MCTP_I2C_GPIO_CONTROLLER_IODEV_DEFINE, _name) \
100
const struct rtio_iodev *_name##_endpoint_iodevs[] = { \
101
LISTIFY(DT_PROP_LEN(_node_id, endpoint_ids), &MCTP_I2C_GPIO_CONTROLLER_IODEV_NAME, \
102
(,), _name) \
103
}
104
106
129
#define MCTP_I2C_GPIO_CONTROLLER_DT_DEFINE(_name, _node_id) \
130
RTIO_DEFINE(_name##_rtio_tx, 5, 5); \
131
RTIO_DEFINE(_name##_rtio_rx, 5, 5); \
132
MCTP_I2C_GPIO_CONTROLLER_DEFINE_IODEVS(_node_id, _name); \
133
MCTP_I2C_GPIO_CONTROLLER_DEFINE_GPIOS(_node_id, _name); \
134
MCTP_I2C_GPIO_CONTROLLER_DEFINE_IDS(_node_id, _name); \
135
MCTP_I2C_GPIO_CONTROLLER_DEFINE_GPIO_CBS(_node_id, _name); \
136
K_SEM_DEFINE(_name##_tx_lock, 1, 1); \
137
struct mctp_binding_i2c_gpio_controller _name = { \
138
.binding = { \
139
.name = STRINGIFY(_name), .version = 1, \
140
.start = mctp_i2c_gpio_controller_start, \
141
.tx = mctp_i2c_gpio_controller_tx, \
142
.pkt_size = MCTP_I2C_GPIO_MAX_PKT_SIZE, \
143
.tx_storage = _name.tx_storage, \
144
}, \
145
.i2c = DEVICE_DT_GET(DT_PHANDLE(_node_id, i2c)), \
146
.num_endpoints = DT_PROP_LEN(_node_id, endpoint_ids), \
147
.endpoint_ids = _name##_endpoint_ids, \
148
.endpoint_gpios = _name##_endpoint_gpios, \
149
.endpoint_gpio_cbs = _name##_endpoint_gpio_cbs, \
150
.endpoint_iodevs = _name##_endpoint_iodevs, \
151
.r_tx = &_name##_rtio_tx, \
152
.r_rx = &_name##_rtio_rx, \
153
.tx_lock = &_name##_tx_lock, \
154
};
155
156
#endif
/* ZEPHYR_MCTP_I2C_GPIO_CONTROLLER_H_ */
device.h
gpio.h
Main header file for GPIO driver API.
i2c.h
Main header file for I2C (Inter-Integrated Circuit) driver API.
kernel.h
Public kernel APIs.
mctp_i2c_gpio_common.h
mpsc_lockfree.h
A wait-free intrusive multi producer single consumer (MPSC) queue using a singly linked list.
rtio.h
Real-Time IO device API for moving bytes with low effort.
stdint.h
uint8_t
__UINT8_TYPE__ uint8_t
Definition
stdint.h:88
device
Runtime device structure (in ROM) per driver instance.
Definition
device.h:513
gpio_dt_spec
Container for GPIO pin information specified in devicetree.
Definition
gpio.h:296
k_sem
Semaphore structure.
Definition
kernel.h:3723
k_spinlock
Kernel Spin Lock.
Definition
spinlock.h:45
mctp_binding_i2c_gpio_controller
An MCTP binding for Zephyr's I2C interface using GPIO.
Definition
mctp_i2c_gpio_controller.h:39
mpsc
MPSC Queue.
Definition
mpsc_lockfree.h:86
rtio_iodev
An IO device with a function table for submitting requests.
Definition
iodev.h:48
rtio
An RTIO context containing what can be viewed as a pair of queues.
Definition
rtio.h:70
zephyr
pmci
mctp
mctp_i2c_gpio_controller.h
Generated on
for Zephyr API by
1.17.0