no-OS
All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
no_os_i3c.h
Go to the documentation of this file.
1/***************************************************************************/
39
40#ifndef _NO_OS_I3C_H_
41#define _NO_OS_I3C_H_
42
43#include <stdint.h>
44#include "no_os_util.h"
45#include "no_os_dma.h"
46
47#define NO_OS_I3C_MAX_BUS_NUMBER 3
48#define NO_OS_I3C_MAX_DEV_NUMBER 15
49/* I²C/I3C address are 7-bit (not considering extended 10-bit I²C) */
50#define NO_OS_I3C_I2C_MAX_ADDR 0x7F
51#define NO_OS_I3C_MAX_ADDR NO_OS_I3C_I2C_MAX_ADDR
52#define NO_OS_I3C_BCAST_ADDR 0x7E
53/* 2-bit flags packed in addrslots */
54#define NO_OS_I3C_ADDR_FLAG_SIZE 2
55#define NO_OS_I3C_ADDR_PER_SLOT ((unsigned int)(sizeof(unsigned int)*8 / NO_OS_I3C_ADDR_FLAG_SIZE))
56#define NO_OS_I3C_ADDR_GET_SLOT(x) ((x) / NO_OS_I3C_ADDR_PER_SLOT)
57#define NO_OS_I3C_ADDR_GET_POS(x) (((x) % NO_OS_I3C_ADDR_PER_SLOT) * NO_OS_I3C_ADDR_FLAG_SIZE)
58#define NO_OS_I3C_ADDRSLOTS_SIZE \
59 (NO_OS_I3C_I2C_MAX_ADDR / NO_OS_I3C_ADDR_PER_SLOT) + !!(NO_OS_I3C_I2C_MAX_ADDR % NO_OS_I3C_ADDR_PER_SLOT)
60
61/* I3C CCC (Common Command Codes) related definitions */
62#define NO_OS_I3C_CCC_BCAST 0
63#define NO_OS_I3C_CCC_DIRECT NO_OS_BIT(7)
64
65#define NO_OS_I3C_CCC_ID(id, type) ((id) | (type))
66
67#define NO_OS_I3C_CCC_ADDR(x) ((x) & 0xFF)
68#define NO_OS_I3C_CCC_GET_LEN(x) (((x) >> 8) & 0x0000FF)
69#define NO_OS_I3C_CCC_SET_LEN(x) (((x) << 8) & 0x00FF00)
70#define NO_OS_I3C_CCC_GET_DEF(x) (((x) >> 17) & NO_OS_BIT(0))
71#define NO_OS_I3C_CCC_SET_DEF NO_OS_BIT(17)
72#define NO_OS_I3C_CCC_GET_RNW(x) (((x) >> 16) & NO_OS_BIT(0))
73#define NO_OS_I3C_CCC_SET_RNW(x) (((x) << 16) & NO_OS_BIT(16))
74
79#define NO_OS_I3C_CCC_ENEC_DIRECT 0x80 | NO_OS_I3C_CCC_SET_LEN(1)
80#define NO_OS_I3C_CCC_DISEC_DIRECT 0x81 | NO_OS_I3C_CCC_SET_LEN(1)
81#define NO_OS_I3C_CCC_ENEC_BCAST 0x00 | NO_OS_I3C_CCC_SET_DEF
82#define NO_OS_I3C_CCC_DISEC_BCAST 0x01 | NO_OS_I3C_CCC_SET_DEF
83#define NO_OS_I3C_CCC_ENTAS(as, type) NO_OS_I3C_CCC_ID((0x2 + (as)), (type))
84#define NO_OS_I3C_CCC_RSTDAA(type) NO_OS_I3C_CCC_ID(0x6, (type))
85#define NO_OS_I3C_CCC_SETMWL(type) NO_OS_I3C_CCC_ID(0x9, (type)) | NO_OS_I3C_CCC_SET_LEN(2)
86#define NO_OS_I3C_CCC_SETMRL(type) NO_OS_I3C_CCC_ID(0xa, (type)) | NO_OS_I3C_CCC_SET_LEN(2)
87#define NO_OS_I3C_CCC_SETXTIME_BCAST 0x28 | NO_OS_I3C_CCC_SET_DEF
88#define NO_OS_I3C_CCC_SETXTIME_DIRECT 0x98 | NO_OS_I3C_CCC_SET_DEF
89#define NO_OS_I3C_CCC_RSTACT_BCAST 0x2a | NO_OS_I3C_CCC_SET_DEF
90#define NO_OS_I3C_CCC_RSTACT_DIRECT 0x9a | NO_OS_I3C_CCC_SET_DEF
91#define NO_OS_I3C_CCC_RSTACT_I3C_ONLY 0x1
92#define NO_OS_I3C_CCC_RSTACT_WHOLE_TARGET 0x2
93
94/* Broadcast-only commands */
95#define NO_OS_I3C_CCC_ENTDAA NO_OS_I3C_CCC_ID(0x7, NO_OS_I3C_CCC_BCAST)
96#define NO_OS_I3C_CCC_DEFSLVS NO_OS_I3C_CCC_ID(0x8, NO_OS_I3C_CCC_BCAST)
97#define NO_OS_I3C_CCC_ENTTM NO_OS_I3C_CCC_ID(0xb, NO_OS_I3C_CCC_BCAST)
98#define NO_OS_I3C_CCC_ENTHDR(x) NO_OS_I3C_CCC_ID((0x20 + (x)), NO_OS_I3C_CCC_BCAST)
99#define NO_OS_I3C_CCC_SETAASA NO_OS_I3C_CCC_ID(0x29, NO_OS_I3C_CCC_BCAST)
100
101/* Unicast-only commands */
102#define NO_OS_I3C_CCC_SETDASA NO_OS_I3C_CCC_ID(0x7, NO_OS_I3C_CCC_DIRECT)
103#define NO_OS_I3C_CCC_SETNEWDA NO_OS_I3C_CCC_ID(0x8, NO_OS_I3C_CCC_DIRECT)
104#define NO_OS_I3C_CCC_GETMWL NO_OS_I3C_CCC_ID(0xb, NO_OS_I3C_CCC_DIRECT)
105#define NO_OS_I3C_CCC_GETMRL NO_OS_I3C_CCC_ID(0xc, NO_OS_I3C_CCC_DIRECT)
106#define NO_OS_I3C_CCC_GETPID (NO_OS_I3C_CCC_ID(0xd, NO_OS_I3C_CCC_DIRECT) | NO_OS_I3C_CCC_SET_LEN(6) | NO_OS_I3C_CCC_SET_RNW(1))
107#define NO_OS_I3C_CCC_GETBCR (NO_OS_I3C_CCC_ID(0xe, NO_OS_I3C_CCC_DIRECT) | NO_OS_I3C_CCC_SET_LEN(1) | NO_OS_I3C_CCC_SET_RNW(1))
108#define NO_OS_I3C_CCC_GETDCR (NO_OS_I3C_CCC_ID(0xf, NO_OS_I3C_CCC_DIRECT) | NO_OS_I3C_CCC_SET_LEN(1) | NO_OS_I3C_CCC_SET_RNW(1))
109#define NO_OS_I3C_CCC_GETSTATUS (NO_OS_I3C_CCC_ID(0x10, NO_OS_I3C_CCC_DIRECT) | NO_OS_I3C_CCC_SET_LEN(2) | NO_OS_I3C_CCC_SET_RNW(1))
110#define NO_OS_I3C_CCC_GETACCMST NO_OS_I3C_CCC_ID(0x11, NO_OS_I3C_CCC_DIRECT)
111#define NO_OS_I3C_CCC_SETBRGTGT NO_OS_I3C_CCC_ID(0x13, NO_OS_I3C_CCC_DIRECT)
112#define NO_OS_I3C_CCC_GETMXDS NO_OS_I3C_CCC_ID(0x14, NO_OS_I3C_CCC_DIRECT)
113#define NO_OS_I3C_CCC_GETHDRCAP NO_OS_I3C_CCC_ID(0x15, NO_OS_I3C_CCC_DIRECT)
114#define NO_OS_I3C_CCC_GETXTIME NO_OS_I3C_CCC_ID(0x19, NO_OS_I3C_CCC_DIRECT)
115
116#define NO_OS_I3C_CCC_EVENT_SIR NO_OS_BIT(0)
117#define NO_OS_I3C_CCC_EVENT_MR NO_OS_BIT(1)
118#define NO_OS_I3C_CCC_EVENT_HJ NO_OS_BIT(3)
122#define NO_OS_I3C_IRQ_IBI 0x1
123#define NO_OS_I3C_IRQ_HJ 0x2
124#define NO_OS_I3C_IRQ_CR 0x4
128#define NO_OS_I3C_BCR_IBI_REQUEST_CAPABLE(bcr) !!((bcr) & (1 << 1))
129#define NO_OS_I3C_BCR_IBI_PAYLOAD(bcr) !!((bcr) & (1 << 2))
130#define NO_OS_I3C_BCR_DEVICE_ROLE(bcr) (((bcr) && NO_OS_GENMASK(7,6)) >> 6)
131
153
159 uint32_t ibi_cr_addr;
163 uint32_t ibi_payload;
164};
165
174 uint8_t addr;
175 uint64_t pid;
176};
177
184
191 uint8_t *tx_buff;
193 uint32_t tx_size;
195 uint8_t *rx_buff;
197 uint32_t rx_size;
198};
199
236
243 const uint32_t device_id;
247 const uint8_t num_devs;
251 void *extra;
252};
253
269 uint64_t pid;
271 uint8_t addr;
275 bool is_i3c;
276};
277
284 uint64_t pid;
286 uint8_t addr;
288 bool is_i3c;
294 void *extra;
296 void (*event_callback)(struct no_os_i3c_desc*, uint32_t, uint32_t);
301};
302
311 const struct no_os_i3c_bus_init_param *);
314 const struct no_os_i3c_init_param *);
318 int (*i3c_ops_send_ccc)(struct no_os_i3c_bus_desc *, uint8_t, uint8_t,
319 bool, bool, uint8_t *, uint8_t);
321 int (*i3c_ops_write)(struct no_os_i3c_desc *, uint8_t *, uint8_t);
323 int (*i3c_ops_read)(struct no_os_i3c_desc *, uint8_t *, uint8_t);
325 int (*i3c_ops_write_and_read)(struct no_os_i3c_desc *, uint8_t *, uint8_t,
326 uint8_t *, uint8_t);
335 uint8_t, bool);
338 uint8_t);
341 struct no_os_i3c_msg *,
342 uint32_t,
343 void (*)(void *),
344 void *);
347};
348
349/* Initialize the I3C device. */
350int no_os_i3c_init(struct no_os_i3c_desc **desc,
351 const struct no_os_i3c_init_param *param);
352
353/* Initialize the I3C bus. */
354int no_os_i3c_init_bus(struct no_os_i3c_bus_desc **desc,
355 const struct no_os_i3c_bus_init_param *param);
356
357/* Free the resources allocated by no_os_i3c_init. */
358int no_os_i3c_remove(struct no_os_i3c_desc *desc);
359
360/* Free the resources allocated by no_os_i3c_init_bus + no_os_i3c_init. */
362
363/* Do I3C DAA to assign the dynamic addresses. */
364int no_os_i3c_do_daa(struct no_os_i3c_bus_desc *desc, bool rstdaa);
365
366/* Send CCC on the bus (direct or broadcast). */
368 uint8_t addr, uint32_t ccc, uint8_t *data);
369
370/* Send CCC to a device device. */
372 uint32_t ccc, uint8_t *data);
373
374/* Write data to a device device. */
375int no_os_i3c_write(struct no_os_i3c_desc *desc,
376 uint8_t *data,
377 uint8_t size);
378
379/* Read data from a device device. */
380int no_os_i3c_read(struct no_os_i3c_desc *desc,
381 uint8_t *data,
382 uint8_t size);
383
384/* Write and read data from a device device. */
386 uint8_t *tx_data,
387 uint8_t tx_data_len,
388 uint8_t *rx_data,
389 uint8_t rx_data_len);
390
391/* Configure enabled interrupt. */
393 uint8_t irq, bool en);
394
395/* Wait I3C interrupt. */
397 uint8_t irq);
398
399/* Non-blocking I3C interrupt. */
400int no_os_i3c_call_irq(struct no_os_i3c_bus_desc* desc);
401
402/* Enable I3C non-blocking interrupts. */
403int no_os_i3c_async_irq(struct no_os_i3c_bus_desc *desc, bool en);
404
405/* Get a free address. */
407 uint8_t start_addr);
408
409/* Set status of an address. */
411 uint8_t addr, enum no_os_i3c_slot_status status);
412
413/* Attach event callback. */
415 void (*callback)(struct no_os_i3c_desc*, uint32_t, uint32_t));
416
417/* Detach event callback. */
419
420/*
421 * Transfer a list of messages using DMA.
422 * Non-blocking, invokes a callback after the last message is concluded.
423 */
425 struct no_os_i3c_msg *msgs,
426 uint32_t len,
427 void (*callback)(void *),
428 void *ctx);
429
430/* Abort the ongoing DMA transaction */
431int32_t no_os_i3c_transfer_abort(struct no_os_i3c_desc *desc);
432
433#endif // _NO_OS_I3C_H_
bool
Definition common.h:42
Platform independent function definitions and data types for the DMA API.
#define NO_OS_I3C_ADDRSLOTS_SIZE
Definition no_os_i3c.h:58
int no_os_i3c_do_daa(struct no_os_i3c_bus_desc *desc, bool rstdaa)
Do DAA to assign the dynamic addresses.
Definition no_os_i3c.c:335
uint8_t no_os_i3c_addr_get_free(struct no_os_i3c_bus_desc *desc, uint8_t start_addr)
Get a free address.
Definition no_os_i3c.c:579
int no_os_i3c_init_bus(struct no_os_i3c_bus_desc **desc, const struct no_os_i3c_bus_init_param *param)
Initialize the I3C bus.
Definition no_os_i3c.c:161
int no_os_i3c_wait_irq(struct no_os_i3c_bus_desc *desc, uint8_t irq)
Wait I3C interrupt. Set async_irq on call to false to ensure single entry point.
Definition no_os_i3c.c:526
int no_os_i3c_remove(struct no_os_i3c_desc *desc)
Free the resources allocated by no_os_i3c_init().
Definition no_os_i3c.c:270
void no_os_i3c_attach_callback(struct no_os_i3c_desc *desc, void(*callback)(struct no_os_i3c_desc *, uint32_t, uint32_t))
Attach event callback.
Definition no_os_i3c.c:685
void no_os_i3c_detach_callback(struct no_os_i3c_desc *desc)
Detach event callback.
Definition no_os_i3c.c:695
void no_os_i3c_addr_set_status(struct no_os_i3c_bus_desc *desc, uint8_t addr, enum no_os_i3c_slot_status status)
Set status of an address.
Definition no_os_i3c.c:600
int no_os_i3c_write(struct no_os_i3c_desc *desc, uint8_t *data, uint8_t size)
Write data to device device.
Definition no_os_i3c.c:407
int no_os_i3c_call_irq(struct no_os_i3c_bus_desc *desc)
Non-blocking I3C interrupt. Since a payload is always retrieved with it, also update the no_os_i3c_cc...
Definition no_os_i3c.c:543
int no_os_i3c_async_irq(struct no_os_i3c_bus_desc *desc, bool en)
Enable I3C non-blocking interrupts.
Definition no_os_i3c.c:510
int no_os_i3c_remove_bus(struct no_os_i3c_bus_desc *desc)
Free the resources allocated by no_os_i3c_init_bus. Must remove all devices first,...
Definition no_os_i3c.c:302
int no_os_i3c_init(struct no_os_i3c_desc **desc, const struct no_os_i3c_init_param *param)
Initialize the I3C device. If the bus of the I3C device is not initialized, it will call to init it.
Definition no_os_i3c.c:66
int no_os_i3c_conf_irq(struct no_os_i3c_bus_desc *desc, uint8_t irq, bool en)
Configure I3C interrupts.
Definition no_os_i3c.c:492
int no_os_i3c_send_ccc(struct no_os_i3c_bus_desc *desc, uint8_t addr, uint32_t ccc, uint8_t *data)
Send CCC, either to a device device or broadcast to all.
Definition no_os_i3c.c:354
int no_os_i3c_write_and_read(struct no_os_i3c_desc *desc, uint8_t *tx_data, uint8_t tx_data_len, uint8_t *rx_data, uint8_t rx_data_len)
Read and write the device.
Definition no_os_i3c.c:463
int no_os_i3c_read(struct no_os_i3c_desc *desc, uint8_t *data, uint8_t size)
Read data from device device.
Definition no_os_i3c.c:434
#define NO_OS_I3C_MAX_DEV_NUMBER
Definition no_os_i3c.h:48
no_os_i3c_slot_status
On an I3C bus, addresses are assigned dynamically, and we need to know which addresses are free to us...
Definition no_os_i3c.h:141
@ NO_OS_I3C_ADDR_SLOT_I3C_DEV
Definition no_os_i3c.h:149
@ NO_OS_I3C_ADDR_SLOT_FREE
Definition no_os_i3c.h:143
@ NO_OS_I3C_ADDR_SLOT_I2C_DEV
Definition no_os_i3c.h:147
@ NO_OS_I3C_ADDR_SLOT_RSVD
Definition no_os_i3c.h:145
@ NO_OS_I3C_ADDR_SLOT_STATUS_MASK
Definition no_os_i3c.h:151
int32_t no_os_i3c_transfer_abort(struct no_os_i3c_desc *desc)
Abort the ongoing DMA transaction.
Definition no_os_i3c.c:732
int no_os_i3c_send_direct_ccc(struct no_os_i3c_desc *desc, uint32_t ccc, uint8_t *data)
Send CCC to device device.
Definition no_os_i3c.c:388
int32_t no_os_i3c_transfer_dma_async(struct no_os_i3c_desc *desc, struct no_os_i3c_msg *msgs, uint32_t len, void(*callback)(void *), void *ctx)
Transfer a list of messages using DMA. Non-blocking, invokes a callback after the last message is con...
Definition no_os_i3c.c:710
Header file of utility functions.
Structure holding I3C bus descriptor.
Definition no_os_i3c.h:204
unsigned int addrslots[NO_OS_I3C_ADDRSLOTS_SIZE]
Definition no_os_i3c.h:218
struct no_os_i3c_ccc_info ccc_info
Definition no_os_i3c.h:228
struct no_os_i3c_desc * devs[NO_OS_I3C_MAX_DEV_NUMBER]
Definition no_os_i3c.h:224
uint8_t num_devs
Definition no_os_i3c.h:212
void * extra
Definition no_os_i3c.h:234
const struct no_os_i3c_platform_ops * platform_ops
Definition no_os_i3c.h:232
uint8_t device_id
Definition no_os_i3c.h:208
struct no_os_i3c_daa_lut daa_unknown[NO_OS_I3C_MAX_DEV_NUMBER]
Definition no_os_i3c.h:222
void * mutex
Definition no_os_i3c.h:206
uint8_t num_devs_unknown
Definition no_os_i3c.h:210
struct no_os_i3c_daa_lut daa_candidates[NO_OS_I3C_MAX_DEV_NUMBER]
Definition no_os_i3c.h:220
uint8_t irq_events
Definition no_os_i3c.h:226
bool async_irq
Definition no_os_i3c.h:230
Structure holding the parameters for I3C initialization.
Definition no_os_i3c.h:241
const struct no_os_i3c_init_param ** devs
Definition no_os_i3c.h:249
const struct no_os_i3c_platform_ops * platform_ops
Definition no_os_i3c.h:245
const uint8_t num_devs
Definition no_os_i3c.h:247
void * extra
Definition no_os_i3c.h:251
const uint32_t device_id
Definition no_os_i3c.h:243
Definition no_os_i3c.h:157
uint32_t ibi_payload_len
Definition no_os_i3c.h:161
uint32_t ibi_payload
Definition no_os_i3c.h:163
uint32_t ibi_cr_addr
Definition no_os_i3c.h:159
Stores the PID + DA information to look-up during the DAA. Should be used only for device initializat...
Definition no_os_i3c.h:172
bool is_attached
Definition no_os_i3c.h:173
uint8_t addr
Definition no_os_i3c.h:174
uint64_t pid
Definition no_os_i3c.h:175
Structure holding I3C device descriptor.
Definition no_os_i3c.h:282
void(* event_callback)(struct no_os_i3c_desc *, uint32_t, uint32_t)
Definition no_os_i3c.h:296
uint64_t pid
Definition no_os_i3c.h:284
void * extra
Definition no_os_i3c.h:294
const struct no_os_i3c_platform_ops * platform_ops
Definition no_os_i3c.h:298
bool is_attached
Definition no_os_i3c.h:290
bool is_i3c
Definition no_os_i3c.h:288
struct no_os_i3c_bus_desc * bus
Definition no_os_i3c.h:300
bool is_static
Definition no_os_i3c.h:292
uint8_t addr
Definition no_os_i3c.h:286
Structure holding the parameters for I3C initialization. Works like a device tree,...
Definition no_os_i3c.h:265
bool is_static
Definition no_os_i3c.h:273
struct no_os_i3c_bus_init_param * bus
Definition no_os_i3c.h:267
uint8_t addr
Definition no_os_i3c.h:271
bool is_i3c
Definition no_os_i3c.h:275
uint64_t pid
Definition no_os_i3c.h:269
Item describing an I3C transfer.
Definition no_os_i3c.h:189
uint32_t rx_size
Definition no_os_i3c.h:197
uint32_t tx_size
Definition no_os_i3c.h:193
uint8_t * rx_buff
Definition no_os_i3c.h:195
uint8_t * tx_buff
Definition no_os_i3c.h:191
Structure holding I3C function pointers that point to the platform specific function.
Definition no_os_i3c.h:308
int(* i3c_ops_write_and_read)(struct no_os_i3c_desc *, uint8_t *, uint8_t, uint8_t *, uint8_t)
Definition no_os_i3c.h:325
int(* i3c_ops_init)(struct no_os_i3c_desc *, const struct no_os_i3c_init_param *)
Definition no_os_i3c.h:313
int(* i3c_ops_write)(struct no_os_i3c_desc *, uint8_t *, uint8_t)
Definition no_os_i3c.h:321
int(* i3c_ops_remove_bus)(struct no_os_i3c_bus_desc *)
Definition no_os_i3c.h:328
int(* i3c_ops_remove)(struct no_os_i3c_desc *)
Definition no_os_i3c.h:330
int32_t(* i3c_ops_transfer_abort)(struct no_os_i3c_desc *)
Definition no_os_i3c.h:346
int(* i3c_ops_read)(struct no_os_i3c_desc *, uint8_t *, uint8_t)
Definition no_os_i3c.h:323
int32_t(* i3c_ops_transfer_dma_async)(struct no_os_i3c_desc *, struct no_os_i3c_msg *, uint32_t, void(*)(void *), void *)
Definition no_os_i3c.h:340
int(* i3c_ops_init_bus)(struct no_os_i3c_bus_desc *, const struct no_os_i3c_bus_init_param *)
Definition no_os_i3c.h:310
int(* i3c_ops_is_dev_ready)(struct no_os_i3c_desc *)
Definition no_os_i3c.h:332
int(* i3c_ops_conf_irq)(struct no_os_i3c_bus_desc *, uint8_t, bool)
Definition no_os_i3c.h:334
int(* i3c_ops_get_ccc_info)(struct no_os_i3c_bus_desc *, uint8_t)
Definition no_os_i3c.h:337
int(* i3c_ops_send_ccc)(struct no_os_i3c_bus_desc *, uint8_t, uint8_t, bool, bool, uint8_t *, uint8_t)
Definition no_os_i3c.h:318
int(* i3c_ops_do_daa)(struct no_os_i3c_bus_desc *, bool)
Definition no_os_i3c.h:316