Zephyr API Documentation 3.7.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
mspi.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2024, Ambiq Micro Inc. <www.ambiq.com>
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
14#ifndef ZEPHYR_INCLUDE_MSPI_H_
15#define ZEPHYR_INCLUDE_MSPI_H_
16
17#include <errno.h>
18
19#include <zephyr/sys/__assert.h>
20#include <zephyr/types.h>
21#include <zephyr/kernel.h>
22#include <zephyr/device.h>
23#include <zephyr/drivers/gpio.h>
24
25#ifdef __cplusplus
26extern "C" {
27#endif
28
43
51
74
91
101
109
117
129
141
149
157
181
189
202
207
208};
209
221
247
253 const struct device *bus;
256};
257
299
315
329
360
378
412
436
446
456
464typedef void (*mspi_callback_handler_t)(struct mspi_callback_context *mspi_cb_ctx, ...);
465
471typedef int (*mspi_api_config)(const struct mspi_dt_spec *spec);
472
473typedef int (*mspi_api_dev_config)(const struct device *controller,
474 const struct mspi_dev_id *dev_id,
475 const enum mspi_dev_cfg_mask param_mask,
476 const struct mspi_dev_cfg *cfg);
477
478typedef int (*mspi_api_get_channel_status)(const struct device *controller, uint8_t ch);
479
480typedef int (*mspi_api_transceive)(const struct device *controller,
481 const struct mspi_dev_id *dev_id,
482 const struct mspi_xfer *req);
483
484typedef int (*mspi_api_register_callback)(const struct device *controller,
485 const struct mspi_dev_id *dev_id,
486 const enum mspi_bus_event evt_type,
488 struct mspi_callback_context *ctx);
489
490typedef int (*mspi_api_xip_config)(const struct device *controller,
491 const struct mspi_dev_id *dev_id,
492 const struct mspi_xip_cfg *xip_cfg);
493
494typedef int (*mspi_api_scramble_config)(const struct device *controller,
495 const struct mspi_dev_id *dev_id,
496 const struct mspi_scramble_cfg *scramble_cfg);
497
498typedef int (*mspi_api_timing_config)(const struct device *controller,
499 const struct mspi_dev_id *dev_id, const uint32_t param_mask,
500 void *timing_cfg);
501
512
539__syscall int mspi_config(const struct mspi_dt_spec *spec);
540
541static inline int z_impl_mspi_config(const struct mspi_dt_spec *spec)
542{
543 const struct mspi_driver_api *api = (const struct mspi_driver_api *)spec->bus->api;
544
545 return api->config(spec);
546}
547
575__syscall int mspi_dev_config(const struct device *controller,
576 const struct mspi_dev_id *dev_id,
577 const enum mspi_dev_cfg_mask param_mask,
578 const struct mspi_dev_cfg *cfg);
579
580static inline int z_impl_mspi_dev_config(const struct device *controller,
581 const struct mspi_dev_id *dev_id,
582 const enum mspi_dev_cfg_mask param_mask,
583 const struct mspi_dev_cfg *cfg)
584{
585 const struct mspi_driver_api *api = (const struct mspi_driver_api *)controller->api;
586
587 return api->dev_config(controller, dev_id, param_mask, cfg);
588}
589
601__syscall int mspi_get_channel_status(const struct device *controller, uint8_t ch);
602
603static inline int z_impl_mspi_get_channel_status(const struct device *controller, uint8_t ch)
604{
605 const struct mspi_driver_api *api = (const struct mspi_driver_api *)controller->api;
606
607 return api->get_channel_status(controller, ch);
608}
609
641__syscall int mspi_transceive(const struct device *controller,
642 const struct mspi_dev_id *dev_id,
643 const struct mspi_xfer *req);
644
645static inline int z_impl_mspi_transceive(const struct device *controller,
646 const struct mspi_dev_id *dev_id,
647 const struct mspi_xfer *req)
648{
649 const struct mspi_driver_api *api = (const struct mspi_driver_api *)controller->api;
650
651 if (!api->transceive) {
652 return -ENOTSUP;
653 }
654
655 return api->transceive(controller, dev_id, req);
656}
657
679__syscall int mspi_xip_config(const struct device *controller,
680 const struct mspi_dev_id *dev_id,
681 const struct mspi_xip_cfg *cfg);
682
683static inline int z_impl_mspi_xip_config(const struct device *controller,
684 const struct mspi_dev_id *dev_id,
685 const struct mspi_xip_cfg *cfg)
686{
687 const struct mspi_driver_api *api = (const struct mspi_driver_api *)controller->api;
688
689 if (!api->xip_config) {
690 return -ENOTSUP;
691 }
692
693 return api->xip_config(controller, dev_id, cfg);
694}
695
711__syscall int mspi_scramble_config(const struct device *controller,
712 const struct mspi_dev_id *dev_id,
713 const struct mspi_scramble_cfg *cfg);
714
715static inline int z_impl_mspi_scramble_config(const struct device *controller,
716 const struct mspi_dev_id *dev_id,
717 const struct mspi_scramble_cfg *cfg)
718{
719 const struct mspi_driver_api *api = (const struct mspi_driver_api *)controller->api;
720
721 if (!api->scramble_config) {
722 return -ENOTSUP;
723 }
724
725 return api->scramble_config(controller, dev_id, cfg);
726}
727
744__syscall int mspi_timing_config(const struct device *controller,
745 const struct mspi_dev_id *dev_id,
746 const uint32_t param_mask, void *cfg);
747
748static inline int z_impl_mspi_timing_config(const struct device *controller,
749 const struct mspi_dev_id *dev_id,
750 const uint32_t param_mask, void *cfg)
751{
752 const struct mspi_driver_api *api = (const struct mspi_driver_api *)controller->api;
753
754 if (!api->timing_config) {
755 return -ENOTSUP;
756 }
757
758 return api->timing_config(controller, dev_id, param_mask, cfg);
759}
760
783static inline int mspi_register_callback(const struct device *controller,
784 const struct mspi_dev_id *dev_id,
785 const enum mspi_bus_event evt_type,
787 struct mspi_callback_context *ctx)
788{
789 const struct mspi_driver_api *api = (const struct mspi_driver_api *)controller->api;
790
791 if (!api->register_callback) {
792 return -ENOTSUP;
793 }
794
795 return api->register_callback(controller, dev_id, evt_type, cb, ctx);
796}
797
800#ifdef __cplusplus
801}
802#endif
803
805
809#include <zephyr/syscalls/mspi.h>
810#endif /* ZEPHYR_INCLUDE_MSPI_H_ */
Public APIs for GPIO drivers.
System error numbers.
void(* mspi_callback_handler_t)(struct mspi_callback_context *mspi_cb_ctx,...)
Define the application callback handler function signature.
Definition mspi.h:464
static int mspi_register_callback(const struct device *controller, const struct mspi_dev_id *dev_id, const enum mspi_bus_event evt_type, mspi_callback_handler_t cb, struct mspi_callback_context *ctx)
Register the mspi callback functions.
Definition mspi.h:783
int mspi_config(const struct mspi_dt_spec *spec)
Configure a MSPI controller.
int mspi_get_channel_status(const struct device *controller, uint8_t ch)
Query to see if it a channel is ready.
mspi_timing_param
Stub for timing parameter.
Definition mspi.h:199
int mspi_dev_config(const struct device *controller, const struct mspi_dev_id *dev_id, const enum mspi_dev_cfg_mask param_mask, const struct mspi_dev_cfg *cfg)
Configure a MSPI controller with device specific parameters.
int mspi_xip_config(const struct device *controller, const struct mspi_dev_id *dev_id, const struct mspi_xip_cfg *cfg)
Configure a MSPI XIP settings.
int mspi_scramble_config(const struct device *controller, const struct mspi_dev_id *dev_id, const struct mspi_scramble_cfg *cfg)
Configure a MSPI scrambling settings.
int mspi_timing_config(const struct device *controller, const struct mspi_dev_id *dev_id, const uint32_t param_mask, void *cfg)
Configure a MSPI timing settings.
@ MSPI_TIMING_PARAM_DUMMY
Definition mspi.h:200
mspi_xip_permit
MSPI XIP access permissions.
Definition mspi.h:185
int(* mspi_api_scramble_config)(const struct device *controller, const struct mspi_dev_id *dev_id, const struct mspi_scramble_cfg *scramble_cfg)
Definition mspi.h:494
mspi_xfer_mode
MSPI transfer modes.
Definition mspi.h:145
int(* mspi_api_transceive)(const struct device *controller, const struct mspi_dev_id *dev_id, const struct mspi_xfer *req)
Definition mspi.h:480
mspi_duplex
MSPI duplex mode.
Definition mspi.h:47
mspi_ce_polarity
MSPI chip enable polarity.
Definition mspi.h:113
int(* mspi_api_config)(const struct mspi_dt_spec *spec)
MSPI driver API definition and system call entry points.
Definition mspi.h:471
mspi_endian
MSPI Endian.
Definition mspi.h:105
mspi_op_mode
MSPI operational mode.
Definition mspi.h:39
int(* mspi_api_timing_config)(const struct device *controller, const struct mspi_dev_id *dev_id, const uint32_t param_mask, void *timing_cfg)
Definition mspi.h:498
mspi_xfer_direction
MSPI transfer directions.
Definition mspi.h:153
mspi_bus_event
MSPI bus event.
Definition mspi.h:123
mspi_cpp_mode
MSPI Polarity & Phase Modes.
Definition mspi.h:95
mspi_dev_cfg_mask
MSPI controller device specific configuration mask.
Definition mspi.h:161
int(* mspi_api_dev_config)(const struct device *controller, const struct mspi_dev_id *dev_id, const enum mspi_dev_cfg_mask param_mask, const struct mspi_dev_cfg *cfg)
Definition mspi.h:473
int(* mspi_api_xip_config)(const struct device *controller, const struct mspi_dev_id *dev_id, const struct mspi_xip_cfg *xip_cfg)
Definition mspi.h:490
mspi_io_mode
MSPI I/O mode capabilities Postfix like 1_4_4 stands for the number of lines used for command,...
Definition mspi.h:58
mspi_data_rate
MSPI data rate capabilities SINGLE stands for single data rate for all phases.
Definition mspi.h:84
mspi_bus_event_cb_mask
MSPI bus event callback mask This is a preliminary list same as mspi_bus_event.
Definition mspi.h:135
int(* mspi_api_register_callback)(const struct device *controller, const struct mspi_dev_id *dev_id, const enum mspi_bus_event evt_type, mspi_callback_handler_t cb, struct mspi_callback_context *ctx)
Definition mspi.h:484
int(* mspi_api_get_channel_status)(const struct device *controller, uint8_t ch)
Definition mspi.h:478
@ MSPI_XIP_READ_WRITE
Definition mspi.h:186
@ MSPI_XIP_READ_ONLY
Definition mspi.h:187
@ MSPI_DMA
Definition mspi.h:147
@ MSPI_PIO
Definition mspi.h:146
@ MSPI_FULL_DUPLEX
Definition mspi.h:49
@ MSPI_HALF_DUPLEX
Definition mspi.h:48
@ MSPI_CE_ACTIVE_HIGH
Definition mspi.h:115
@ MSPI_CE_ACTIVE_LOW
Definition mspi.h:114
@ MSPI_XFER_BIG_ENDIAN
Definition mspi.h:107
@ MSPI_XFER_LITTLE_ENDIAN
Definition mspi.h:106
@ MSPI_OP_MODE_PERIPHERAL
Definition mspi.h:41
@ MSPI_OP_MODE_CONTROLLER
Definition mspi.h:40
@ MSPI_RX
Definition mspi.h:154
@ MSPI_TX
Definition mspi.h:155
@ MSPI_BUS_EVENT_MAX
Definition mspi.h:127
@ MSPI_BUS_XFER_COMPLETE
Definition mspi.h:126
@ MSPI_BUS_ERROR
Definition mspi.h:125
@ MSPI_BUS_RESET
Definition mspi.h:124
@ MSPI_CPP_MODE_3
Definition mspi.h:99
@ MSPI_CPP_MODE_1
Definition mspi.h:97
@ MSPI_CPP_MODE_2
Definition mspi.h:98
@ MSPI_CPP_MODE_0
Definition mspi.h:96
@ MSPI_DEVICE_CONFIG_CPP
Definition mspi.h:167
@ MSPI_DEVICE_CONFIG_DATA_RATE
Definition mspi.h:166
@ MSPI_DEVICE_CONFIG_RX_DUMMY
Definition mspi.h:171
@ MSPI_DEVICE_CONFIG_FREQUENCY
Definition mspi.h:164
@ MSPI_DEVICE_CONFIG_CMD_LEN
Definition mspi.h:175
@ MSPI_DEVICE_CONFIG_CE_NUM
Definition mspi.h:163
@ MSPI_DEVICE_CONFIG_IO_MODE
Definition mspi.h:165
@ MSPI_DEVICE_CONFIG_CE_POL
Definition mspi.h:169
@ MSPI_DEVICE_CONFIG_DQS
Definition mspi.h:170
@ MSPI_DEVICE_CONFIG_TX_DUMMY
Definition mspi.h:172
@ MSPI_DEVICE_CONFIG_ALL
Definition mspi.h:179
@ MSPI_DEVICE_CONFIG_WRITE_CMD
Definition mspi.h:174
@ MSPI_DEVICE_CONFIG_ADDR_LEN
Definition mspi.h:176
@ MSPI_DEVICE_CONFIG_ENDIAN
Definition mspi.h:168
@ MSPI_DEVICE_CONFIG_NONE
Definition mspi.h:162
@ MSPI_DEVICE_CONFIG_BREAK_TIME
Definition mspi.h:178
@ MSPI_DEVICE_CONFIG_MEM_BOUND
Definition mspi.h:177
@ MSPI_DEVICE_CONFIG_READ_CMD
Definition mspi.h:173
@ MSPI_IO_MODE_HEX
Definition mspi.h:69
@ MSPI_IO_MODE_QUAD_1_4_4
Definition mspi.h:65
@ MSPI_IO_MODE_OCTAL_1_8_8
Definition mspi.h:68
@ MSPI_IO_MODE_HEX_8_16_16
Definition mspi.h:71
@ MSPI_IO_MODE_SINGLE
Definition mspi.h:59
@ MSPI_IO_MODE_DUAL_1_1_2
Definition mspi.h:61
@ MSPI_IO_MODE_DUAL
Definition mspi.h:60
@ MSPI_IO_MODE_MAX
Definition mspi.h:72
@ MSPI_IO_MODE_DUAL_1_2_2
Definition mspi.h:62
@ MSPI_IO_MODE_QUAD_1_1_4
Definition mspi.h:64
@ MSPI_IO_MODE_OCTAL_1_1_8
Definition mspi.h:67
@ MSPI_IO_MODE_OCTAL
Definition mspi.h:66
@ MSPI_IO_MODE_HEX_8_8_16
Definition mspi.h:70
@ MSPI_IO_MODE_QUAD
Definition mspi.h:63
@ MSPI_DATA_RATE_SINGLE
Definition mspi.h:85
@ MSPI_DATA_RATE_S_S_D
Definition mspi.h:86
@ MSPI_DATA_RATE_MAX
Definition mspi.h:89
@ MSPI_DATA_RATE_S_D_D
Definition mspi.h:87
@ MSPI_DATA_RATE_DUAL
Definition mspi.h:88
@ MSPI_BUS_ERROR_CB
Definition mspi.h:138
@ MSPI_BUS_RESET_CB
Definition mspi.h:137
@ MSPI_BUS_XFER_COMPLETE_CB
Definition mspi.h:139
@ MSPI_BUS_NO_CB
Definition mspi.h:136
int mspi_transceive(const struct device *controller, const struct mspi_dev_id *dev_id, const struct mspi_xfer *req)
Transfer request over MSPI.
#define BIT(n)
Unsigned integer with bit position n set (signed in assembly language).
Definition util_macro.h:44
#define BIT_MASK(n)
Bit mask with bits 0 through n-1 (inclusive) set, or 0 if n is 0.
Definition util_macro.h:68
#define ENOTSUP
Unsupported value.
Definition errno.h:114
Public kernel APIs.
__UINT32_TYPE__ uint32_t
Definition stdint.h:90
__UINT8_TYPE__ uint8_t
Definition stdint.h:88
__UINT16_TYPE__ uint16_t
Definition stdint.h:89
Runtime device structure (in ROM) per driver instance.
Definition device.h:403
const void * api
Address of the API structure exposed by the device instance.
Definition device.h:409
Container for GPIO pin information specified in devicetree.
Definition gpio.h:288
MSPI callback context.
Definition mspi.h:450
struct mspi_event mspi_evt
MSPI event
Definition mspi.h:452
void * ctx
user defined context
Definition mspi.h:454
MSPI Chip Select control structure.
Definition mspi.h:345
struct gpio_dt_spec gpio
GPIO devicetree specification of CE GPIO.
Definition mspi.h:352
uint32_t delay
Delay to wait.
Definition mspi.h:358
MSPI controller configuration.
Definition mspi.h:225
bool sw_multi_periph
Software managed multi peripheral enable.
Definition mspi.h:235
uint32_t num_ce_gpios
GPIO chip-select line numbers (optional)
Definition mspi.h:239
bool dqs_support
DQS support flag.
Definition mspi.h:233
struct gpio_dt_spec * ce_group
GPIO chip select lines (optional)
Definition mspi.h:237
enum mspi_duplex duplex
Configure duplex mode.
Definition mspi.h:231
uint32_t num_periph
Peripheral number from 0 to host controller peripheral limit.
Definition mspi.h:241
uint32_t max_freq
Maximum supported frequency in MHz.
Definition mspi.h:243
enum mspi_op_mode op_mode
Configure operation mode.
Definition mspi.h:229
uint8_t channel_num
mspi channel number
Definition mspi.h:227
bool re_init
Whether to re-initialize controller.
Definition mspi.h:245
MSPI controller device specific configuration.
Definition mspi.h:261
uint8_t cmd_length
Configure command length
Definition mspi.h:291
enum mspi_data_rate data_rate
Configure data rate.
Definition mspi.h:269
enum mspi_endian endian
Configure transfer endian.
Definition mspi.h:273
enum mspi_cpp_mode cpp
Configure clock polarity and phase.
Definition mspi.h:271
uint32_t mem_boundary
Configure memory boundary
Definition mspi.h:295
uint32_t time_to_break
Configure the time to break up a transfer into 2.
Definition mspi.h:297
uint8_t addr_length
Configure address length
Definition mspi.h:293
uint32_t freq
Configure frequency.
Definition mspi.h:265
uint16_t tx_dummy
Configure number of clock cycles between addr and data in TX direction.
Definition mspi.h:285
uint16_t rx_dummy
Configure number of clock cycles between addr and data in RX direction.
Definition mspi.h:281
enum mspi_ce_polarity ce_polarity
Configure chip enable polarity.
Definition mspi.h:275
uint8_t ce_num
Configure CE0 or CE1 or more.
Definition mspi.h:263
uint32_t read_cmd
Configure read command
Definition mspi.h:287
uint32_t write_cmd
Configure write command
Definition mspi.h:289
enum mspi_io_mode io_mode
Configure I/O mode.
Definition mspi.h:267
bool dqs_enable
Configure DQS mode.
Definition mspi.h:277
MSPI device ID The controller can identify its devices and determine whether the access is allowed in...
Definition mspi.h:215
uint16_t dev_idx
device index on DT
Definition mspi.h:219
struct gpio_dt_spec ce
device gpio ce
Definition mspi.h:217
Definition mspi.h:502
mspi_api_config config
Definition mspi.h:503
mspi_api_register_callback register_callback
Definition mspi.h:507
mspi_api_dev_config dev_config
Definition mspi.h:504
mspi_api_get_channel_status get_channel_status
Definition mspi.h:505
mspi_api_timing_config timing_config
Definition mspi.h:510
mspi_api_scramble_config scramble_config
Definition mspi.h:509
mspi_api_transceive transceive
Definition mspi.h:506
mspi_api_xip_config xip_config
Definition mspi.h:508
MSPI DT information.
Definition mspi.h:251
struct mspi_cfg config
MSPI hardware specific configuration.
Definition mspi.h:255
const struct device * bus
MSPI bus.
Definition mspi.h:253
MSPI event data.
Definition mspi.h:424
const struct mspi_xfer_packet * packet
Pointer to a transfer packet.
Definition mspi.h:430
uint32_t status
MSPI event status.
Definition mspi.h:432
uint32_t packet_idx
Packet index.
Definition mspi.h:434
const struct mspi_dev_id * dev_id
Pointer to the peripheral device ID.
Definition mspi.h:428
const struct device * controller
Pointer to the bus controller.
Definition mspi.h:426
MSPI event.
Definition mspi.h:440
enum mspi_bus_event evt_type
Event type.
Definition mspi.h:442
struct mspi_event_data evt_data
Data associated to the event.
Definition mspi.h:444
MSPI controller scramble configuration.
Definition mspi.h:319
bool enable
scramble enable
Definition mspi.h:321
uint32_t size
scramble region size
Definition mspi.h:327
uint32_t address_offset
scramble region start address = hardware default + address offset
Definition mspi.h:325
Stub for struct timing_cfg.
Definition mspi.h:206
MSPI peripheral xfer packet format.
Definition mspi.h:364
uint32_t num_bytes
Number of bytes to transfer
Definition mspi.h:374
uint32_t address
Transfer Address
Definition mspi.h:372
uint8_t * data_buf
Data Buffer
Definition mspi.h:376
uint32_t cmd
Transfer command
Definition mspi.h:370
enum mspi_bus_event_cb_mask cb_mask
Bus event callback masks
Definition mspi.h:368
enum mspi_xfer_direction dir
Direction (Transmit/Receive)
Definition mspi.h:366
MSPI peripheral xfer format This includes transfer related settings that may require configuring the ...
Definition mspi.h:384
bool hold_ce
Hold CE active after xfer
Definition mspi.h:398
uint8_t cmd_length
Configure command length
Definition mspi.h:394
uint32_t num_packet
Number of transfer packets
Definition mspi.h:408
const struct mspi_xfer_packet * packets
Transfer packets
Definition mspi.h:406
uint8_t priority
Priority 0 = Low (best effort) 1 = High (service immediately)
Definition mspi.h:404
uint16_t rx_dummy
Configure RX dummy cycles
Definition mspi.h:392
bool async
Async or sync transfer
Definition mspi.h:386
uint8_t addr_length
Configure address length
Definition mspi.h:396
uint16_t tx_dummy
Configure TX dummy cycles
Definition mspi.h:390
struct mspi_ce_control ce_sw_ctrl
Software CE control
Definition mspi.h:400
enum mspi_xfer_mode xfer_mode
Transfer Mode
Definition mspi.h:388
uint32_t timeout
Transfer timeout value
Definition mspi.h:410
MSPI controller XIP configuration.
Definition mspi.h:303
enum mspi_xip_permit permission
XIP access permission.
Definition mspi.h:313
bool enable
XIP enable.
Definition mspi.h:305
uint32_t address_offset
XIP region start address = hardware default + address offset.
Definition mspi.h:309
uint32_t size
XIP region size.
Definition mspi.h:311