Skip to content

Commit 8974c24

Browse files
yperesscarlescufi
authored andcommitted
rtio: Add default i2c submit handler
Use the RTIO work queue to fake the i2c submit calls for drivers which haven't yet implemented the API. Applications can change the size of the work queue pool depending on how much traffic they have on the buses. Signed-off-by: Yuval Peress <peress@google.com>
1 parent bec9952 commit 8974c24

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+811
-31
lines changed

doc/services/rtio/index.rst

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,20 @@ There is a small cost to each RTIO context and iodev. This cost could be weighed
212212
against using a thread for each concurrent I/O operation or custom queues and
213213
threads per peripheral. RTIO is much lower cost than that.
214214

215+
Supported Buses
216+
***************
217+
218+
To check if your bus supports RTIO natively, you can check the driver API implementation, if the
219+
driver implements the ``iodev_submit`` function of the bus API, then RTIO is supported. If the
220+
driver doesn't support the RTIO APIs, it will set the submit function to
221+
``i2c_iodev_submit_fallback``.
222+
223+
I2C buses have a default implementation which allows apps to leverage the RTIO work queue while
224+
vendors implement the submit function. With this queue, any I2C bus driver that does not implement
225+
the ``iodev_submit`` function will defer to a work item which will perform a blocking I2C
226+
transaction. To change the pool size, set a different value to
227+
:kconfig:option`CONFIG_RTIO_WORKQ_POOL_ITEMS`.
228+
215229
API Reference
216230
*************
217231

drivers/i2c/CMakeLists.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@ zephyr_library()
66

77
zephyr_library_sources(i2c_common.c)
88

9-
zephyr_library_sources_ifdef(CONFIG_I2C_RTIO i2c_rtio.c)
9+
zephyr_library_sources_ifdef(CONFIG_I2C_RTIO
10+
i2c_rtio.c
11+
i2c_rtio_default.c
12+
)
1013
zephyr_library_sources_ifdef(CONFIG_I2C_SHELL i2c_shell.c)
1114
zephyr_library_sources_ifdef(CONFIG_I2C_BITBANG i2c_bitbang.c)
1215
zephyr_library_sources_ifdef(CONFIG_I2C_TELINK_B91 i2c_b91.c)

drivers/i2c/Kconfig

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,16 +54,11 @@ config I2C_CALLBACK
5454
help
5555
API and implementations of i2c_transfer_cb.
5656

57-
config HAS_I2C_RTIO
58-
bool
59-
help
60-
This option must be selected by I2C controller drivers that optionally implement the RTIO
61-
interface.
62-
6357
config I2C_RTIO
6458
bool "I2C RTIO API"
65-
depends on HAS_I2C_RTIO
59+
select EXPERIMENTAL
6660
select RTIO
61+
select RTIO_WORKQ
6762
help
6863
API and implementations of I2C for RTIO
6964

@@ -177,7 +172,6 @@ config I2C_MCUX_LPI2C
177172
default y
178173
depends on DT_HAS_NXP_IMX_LPI2C_ENABLED
179174
depends on CLOCK_CONTROL
180-
select HAS_I2C_RTIO
181175
select PINCTRL
182176
help
183177
Enable the mcux LPI2C driver.

drivers/i2c/Kconfig.nrfx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ if I2C_NRFX
1717
config I2C_NRFX_TWI
1818
def_bool y
1919
depends on DT_HAS_NORDIC_NRF_TWI_ENABLED
20-
select HAS_I2C_RTIO
2120
select NRFX_TWI0 if HAS_HW_NRF_TWI0
2221
select NRFX_TWI1 if HAS_HW_NRF_TWI1
2322

drivers/i2c/Kconfig.sam_twihs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,5 @@ config I2C_SAM_TWIHS
77
bool "Atmel SAM (TWIHS) I2C driver"
88
default y
99
depends on DT_HAS_ATMEL_SAM_I2C_TWIHS_ENABLED
10-
select HAS_I2C_RTIO
1110
help
1211
Enable Atmel SAM MCU Family (TWIHS) I2C bus driver.

drivers/i2c/gpio_i2c_switch.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@ static int gpio_i2c_switch_transfer(const struct device *dev, struct i2c_msg *ms
6767
static const struct i2c_driver_api gpio_i2c_switch_api_funcs = {
6868
.configure = gpio_i2c_switch_configure,
6969
.transfer = gpio_i2c_switch_transfer,
70+
#ifdef CONFIG_I2C_RTIO
71+
.iodev_submit = i2c_iodev_submit_fallback,
72+
#endif
7073
};
7174

7275
static int gpio_i2c_switch_init(const struct device *dev)

drivers/i2c/i2c_ambiq.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,9 @@ static int i2c_ambiq_init(const struct device *dev)
275275
static const struct i2c_driver_api i2c_ambiq_driver_api = {
276276
.configure = i2c_ambiq_configure,
277277
.transfer = i2c_ambiq_transfer,
278+
#ifdef CONFIG_I2C_RTIO
279+
.iodev_submit = i2c_iodev_submit_fallback,
280+
#endif
278281
};
279282

280283
#ifdef CONFIG_PM_DEVICE

drivers/i2c/i2c_andes_atciic100.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -733,13 +733,14 @@ static void i2c_atciic100_irq_handler(void *arg)
733733
}
734734

735735
static const struct i2c_driver_api i2c_atciic100_driver = {
736-
.configure = (i2c_api_configure_t)i2c_atciic100_configure,
737-
.transfer = (i2c_api_full_io_t)i2c_atciic100_transfer,
736+
.configure = (i2c_api_configure_t)i2c_atciic100_configure,
737+
.transfer = (i2c_api_full_io_t)i2c_atciic100_transfer,
738738
#if defined(CONFIG_I2C_TARGET)
739-
.target_register =
740-
(i2c_api_target_register_t)i2c_atciic100_target_register,
741-
.target_unregister =
742-
(i2c_api_target_unregister_t)i2c_atciic100_target_unregister
739+
.target_register = (i2c_api_target_register_t)i2c_atciic100_target_register,
740+
.target_unregister = (i2c_api_target_unregister_t)i2c_atciic100_target_unregister,
741+
#endif
742+
#ifdef CONFIG_I2C_RTIO
743+
.iodev_submit = i2c_iodev_submit_fallback,
743744
#endif
744745
};
745746

drivers/i2c/i2c_b91.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,9 @@ static int i2c_b91_init(const struct device *dev)
150150
static const struct i2c_driver_api i2c_b91_api = {
151151
.configure = i2c_b91_configure,
152152
.transfer = i2c_b91_transfer,
153+
#ifdef CONFIG_I2C_RTIO
154+
.iodev_submit = i2c_iodev_submit_fallback,
155+
#endif
153156
};
154157

155158
BUILD_ASSERT(DT_NUM_INST_STATUS_OKAY(DT_DRV_COMPAT) <= 1,

drivers/i2c/i2c_bcm_iproc.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -923,6 +923,9 @@ static const struct i2c_driver_api iproc_i2c_driver_api = {
923923
.target_register = iproc_i2c_target_register,
924924
.target_unregister = iproc_i2c_target_unregister,
925925
#endif
926+
#ifdef CONFIG_I2C_RTIO
927+
.iodev_submit = i2c_iodev_submit_fallback,
928+
#endif
926929
};
927930

928931
#define IPROC_I2C_DEVICE_INIT(n) \

0 commit comments

Comments
 (0)