11#ifndef ZEPHYR_INCLUDE_DRIVERS_MFD_SC16IS75X_H_
12#define ZEPHYR_INCLUDE_DRIVERS_MFD_SC16IS75X_H_
21#include <zephyr/kernel.h>
22#include <zephyr/device.h>
23#include <zephyr/drivers/gpio.h>
25#include <zephyr/sys/util_macro.h>
31#define FIELD_POS(field) field##_POS
32#define FIELD_SIZE(field) field##_SIZE
34#define GET_FIELD(reg, field) \
35 _GET_FIELD_(reg, FIELD_POS(field), FIELD_SIZE(field))
36#define _GET_FIELD_(reg, f_pos, f_size) (((reg) >> (f_pos)) & ((1 << (f_size)) - 1))
38#define SET_FIELD(reg, field, value) \
39 _SET_FIELD_(reg, FIELD_POS(field), FIELD_SIZE(field), value)
40#define _SET_FIELD_(reg, f_pos, f_size, value) \
41 ((reg) = ((reg) & (~(((1 << (f_size)) - 1) << (f_pos)))) \
42 | ((value) << (f_pos)))
44#define GET_FIELD_POS(field) \
45 _GET_FIELD_POS_(FIELD_POS(field))
46#define _GET_FIELD_POS_(f_ops) f_ops
48#define GET_FIELD_SZ(field) \
49 _GET_FIELD_SZ_(FIELD_SIZE(field))
50#define _GET_FIELD_SZ_(f_ops) f_ops
57#define SC16IS75X_REG_RHR 0x00
60#define SC16IS75X_REG_THR 0x00
63#define SC16IS75X_REG_IER 0x01
64#define SC16IS75X_BIT_IER_RXHSENA 0
65#define SC16IS75X_BIT_IER_TXHSENA 1
66#define SC16IS75X_BIT_IER_RXLSENA 2
67#define SC16IS75X_BIT_IER_MSENA 3
68#define SC16IS75X_BIT_IER_SLEEPENA 4
69#define SC16IS75X_BIT_IER_XOFFENA 5
70#define SC16IS75X_BIT_IER_RTSENA 6
71#define SC16IS75X_BIT_IER_CTSENA 7
74#define SC16IS75X_REG_FCR 0x02
75#define SC16IS75X_BIT_FCR_FIFOENA 0
76#define SC16IS75X_BIT_FCR_RXFIFORST 1
77#define SC16IS75X_BIT_FCR_TXFIFORST 2
79#define SC16IS75X_BIT_FCR_TXFIFOTRIG 4
80#define SC16IS75X_TXFIFOTRIG_8SP 0b00
81#define SC16IS75X_TXFIFOTRIG_16SP 0b01
82#define SC16IS75X_TXFIFOTRIG_32SP 0b10
83#define SC16IS75X_TXFIFOTRIG_56SP 0b11
84#define SC16IS75X_BIT_FCR_RXFIFOTRIG 6
85#define SC16IS75X_RXFIFOTRIG_8CH 0b00
86#define SC16IS75X_RXFIFOTRIG_16CH 0b01
87#define SC16IS75X_RXFIFOTRIG_56CH 0b10
88#define SC16IS75X_RXFIFOTRIG_60CH 0b11
91#define SC16IS75X_REG_IIR 0x02
92#define SC16IS75X_BIT_IIR_PENDING 0
93#define SC16IS75X_BIT_IIR_TYPE_POS 1
94#define SC16IS75X_BIT_IIR_TYPE_SIZE 5
95#define SC16IS75X_INT_RXLSE 0b00011
96#define SC16IS75X_INT_RXTO 0b00110
97#define SC16IS75X_INT_RHRI 0b00010
98#define SC16IS75X_INT_THRI 0b00001
99#define SC16IS75X_INT_MSI 0b00000
100#define SC16IS75X_INT_IO 0b11000
101#define SC16IS75X_INT_XOFF 0b01000
102#define SC16IS75X_INT_HWFL 0b10000
103#define SC16IS75X_BIT_IIR_MIRROR_FIFOENA_POS 6
104#define SC16IS75X_BIT_IIR_MIRROR_FIFOENA_SIZE 2
105#define SC16IS75X_INT_FIFOENA 0b11
108#define SC16IS75X_REG_LCR 0x03
110#define SC16IS75X_BIT_LCR_WORD_LEN_POS 0
111#define SC16IS75X_BIT_LCR_WORD_LEN_SIZE 2
112#define SC16IS75X_WORD_LEN_5 0b00
113#define SC16IS75X_WORD_LEN_6 0b01
114#define SC16IS75X_WORD_LEN_7 0b10
115#define SC16IS75X_WORD_LEN_8 0b11
116#define SC16IS75X_BIT_LCR_STOP_LEN_POS 2
117#define SC16IS75X_BIT_LCR_STOP_LEN_SIZE 1
118#define SC16IS75X_STOP_LEN_1 0b0
119#define SC16IS75X_STOP_LEN_1_5 0b1
120#define SC16IS75X_STOP_LEN_2 0b1
121#define SC16IS75X_BIT_LCR_PARITY_POS 3
122#define SC16IS75X_BIT_LCR_PARITY_SIZE 3
123#define SC16IS75X_PARITY_NONE 0b000
124#define SC16IS75X_PARITY_ODD 0b001
125#define SC16IS75X_PARITY_EVEN 0b011
126#define SC16IS75X_PARITY_MARK 0b101
127#define SC16IS75X_PARITY_SPACE 0b111
128#define SC16IS75X_BIT_LCR_TX_LINE_BREAK 6
129#define SC16IS75X_BIT_LCR_DLENA 7
130#define SC16IS75X_BIT_LCR_ACCESS_EFR 0b10111111
133#define SC16IS75X_REG_MCR 0x04
134#define SC16IS75X_BIT_MCR_DTR 0
135#define SC16IS75X_BIT_MCR_RTS 1
136#define SC16IS75X_BIT_MCR_TCRTLRENA 2
138#define SC16IS75X_BIT_MCR_LOOPBACK 4
139#define SC16IS75X_BIT_MCR_XONANY 5
140#define SC16IS75X_BIT_MCR_IRDAENA 6
141#define SC16IS75X_BIT_MCR_CLKDIV 7
144#define SC16IS75X_REG_LSR 0x05
145#define SC16IS75X_BIT_LSR_RX_DATA 0
146#define SC16IS75X_BIT_LSR_RX_OVERRUN 1
147#define SC16IS75X_BIT_LSR_RX_PARITY 2
148#define SC16IS75X_BIT_LSR_RX_FRAMING 3
149#define SC16IS75X_BIT_LSR_RX_LINE_BREAK 4
150#define SC16IS75X_BIT_LSR_THREMPTY 5
151#define SC16IS75X_BIT_LSR_THRTSREMPTY 6
152#define SC16IS75X_BIT_LSR_RX_FIFO 7
155#define SC16IS75X_REG_MSR 0x06
156#define SC16IS75X_BIT_MSR_CTS_CHANGED 0
157#define SC16IS75X_BIT_MSR_DSR_CHANGED 1
158#define SC16IS75X_BIT_MSR_RI_CHANGED 2
159#define SC16IS75X_BIT_MSR_CD_CHANGED 3
160#define SC16IS75X_BIT_MSR_CTS 4
161#define SC16IS75X_BIT_MSR_DSR 5
162#define SC16IS75X_BIT_MSR_RI 6
163#define SC16IS75X_BIT_MSR_CD 7
166#define SC16IS75X_REG_SPR 0x07
169#define SC16IS75X_REG_TCR 0x06
172#define SC16IS75X_REG_TLR 0x07
175#define SC16IS75X_REG_TXLVL 0x08
176#define SC16IS75X_BIT_TXLVL_SP_POS 0
177#define SC16IS75X_BIT_TXLVL_SP_SIZE 7
180#define SC16IS75X_REG_RXLVL 0x09
181#define SC16IS75X_BIT_RXLVL_CH_POS 0
182#define SC16IS75X_BIT_RXLVL_CH_SIZE 7
185#define SC16IS75X_REG_IODIR 0x0A
188#define SC16IS75X_REG_IOSTATE 0x0B
191#define SC16IS75X_REG_IOINTENA 0x0C
194#define SC16IS75X_REG_IOCONTROL 0x0E
195#define SC16IS75X_BIT_IOCONTROL_IOLATCH 0
196#define SC16IS75X_BIT_IOCONTROL_MODEM_PINS_A 1
197#define SC16IS75X_BIT_IOCONTROL_MODEM_PINS_B 2
198#define SC16IS75X_BIT_IOCONTROL_SRESET 3
202#define SC16IS75X_REG_EFCR 0x0F
203#define SC16IS75X_BIT_EFCR_RS485 0
204#define SC16IS75X_BIT_EFCR_RXDISABLE 1
205#define SC16IS75X_BIT_EFCR_TXDISABLE 2
207#define SC16IS75X_BIT_EFCR_RTSCON 4
208#define SC16IS75X_BIT_EFCR_RTSINVER 5
210#define SC16IS75X_BIT_EFCR_IRDA 7
217#define SC16IS75X_REG_DLL 0x00
218#define SC16IS75X_REG_DLH 0x01
225#define SC16IS75X_REG_EFR 0x02
226#define SC16IS75X_BIT_EFR_RX_SWFLOWCTRL_POS 0
227#define SC16IS75X_BIT_EFR_RX_SWFLOWCTRL_SIZE 2
228#define SC16IS75X_BIT_EFR_TX_SWFLOWCTRL_POS 2
229#define SC16IS75X_BIT_EFR_TX_SWFLOWCTRL_SIZE 2
230#define SC16IS75X_SWFLOWCTRL_NONE 0b00
231#define SC16IS75X_SWFLOWCTRL_XONOFF1 0b10
232#define SC16IS75X_SWFLOWCTRL_XONOFF2 0b01
233#define SC16IS75X_SWFLOWCTRL_XONOFF12 0b11
234#define SC16IS75X_BIT_EFR_EFENA 4
235#define SC16IS75X_BIT_EFR_XOFF2ENA 5
236#define SC16IS75X_BIT_EFR_RTSENA 6
237#define SC16IS75X_BIT_EFR_CTSENA 7
240#define SC16IS75X_REG_XON1 0x04
243#define SC16IS75X_REG_XON2 0x05
246#define SC16IS75X_REG_XOFF1 0x06
249#define SC16IS75X_REG_XOFF2 0x07
265#define SC16IS75X_FIFO_CAPACITY 64
268#define SC16IS75X_IO_NUM_PINS_MAX 8
271#define SC16IS75X_UART_CHANNELS_MAX 2
284 const uint8_t channel,
285 const uint8_t reg, uint8_t *value);
287#define READ_SC16IS75X_REG(dev, reg, val) \
288 mfd_sc16is75x_read_register((dev), 0, SC16IS75X_REG_##reg, (val));
290#define READ_SC16IS75X_CHREG(dev, ch, reg, val) \
291 mfd_sc16is75x_read_register((dev), (ch), SC16IS75X_REG_##reg, (val));
304 const uint8_t channel,
305 const uint8_t reg,
const uint8_t value);
307#define WRITE_SC16IS75X_REG(dev, reg, val) \
308 mfd_sc16is75x_write_register((dev), 0, SC16IS75X_REG_##reg, (val));
310#define WRITE_SC16IS75X_CHREG(dev, ch, reg, val) \
311 mfd_sc16is75x_write_register((dev), (ch), SC16IS75X_REG_##reg, (val));
325 const uint8_t channel,
const uint8_t reg,
326 const uint8_t bit,
const bool value);
328#define SETBIT_SC16IS75X_REG(dev, reg, bit, val) \
329 mfd_sc16is75x_set_register_bit((dev), 0, SC16IS75X_REG_##reg, \
332#define SETBIT_SC16IS75X_CHREG(dev, ch, reg, bit, val) \
333 mfd_sc16is75x_set_register_bit((dev), (ch), SC16IS75X_REG_##reg, \
347 uint8_t *buf,
const size_t len);
360 const uint8_t *buf,
const size_t len);
362#ifdef CONFIG_MFD_SC16IS75X_ASYNC
374int mfd_sc16is75x_read_register_signal(
const struct device *dev,
375 const uint8_t channel,
376 const uint8_t reg, uint8_t *value,
377 struct k_poll_signal *signal);
379#define READ_SC16IS75X_CHREG_SIGNAL(dev, ch, reg, val, signal) \
380 mfd_sc16is75x_read_register_signal((dev), (ch), SC16IS75X_REG_##reg, \
385#ifdef CONFIG_MFD_SC16IS75X_INTERRUPTS
396enum mfd_sc16is75x_event {
398 SC16IS75X_EVENT_UART0_RXLSE,
399 SC16IS75X_EVENT_UART0_RXTO,
400 SC16IS75X_EVENT_UART0_RHRI,
401 SC16IS75X_EVENT_UART0_THRI,
402 SC16IS75X_EVENT_UART0_MSI,
403 SC16IS75X_EVENT_IO0_STATE,
404 SC16IS75X_EVENT_UART0_XOFF,
405 SC16IS75X_EVENT_UART0_HWFL,
407 SC16IS75X_EVENT_UART1_RXLSE,
408 SC16IS75X_EVENT_UART1_RXTO,
409 SC16IS75X_EVENT_UART1_RHRI,
410 SC16IS75X_EVENT_UART1_THRI,
411 SC16IS75X_EVENT_UART1_MSI,
412 SC16IS75X_EVENT_IO1_STATE,
413 SC16IS75X_EVENT_UART1_XOFF,
414 SC16IS75X_EVENT_UART1_HWFL,
427int mfd_sc16is75x_add_callback(
const struct device *dev,
428 struct gpio_callback *callback);
438int mfd_sc16is75x_remove_callback(
const struct device *dev,
439 struct gpio_callback *callback);
int mfd_sc16is75x_set_register_bit(const struct device *dev, const uint8_t channel, const uint8_t reg, const uint8_t bit, const bool value)
Enable or disable a bit in an internal register.
Definition mfd_sc16is75x.c:101
int mfd_sc16is75x_write_register(const struct device *dev, const uint8_t channel, const uint8_t reg, const uint8_t value)
Write to an internal register.
Definition mfd_sc16is75x.c:95
int mfd_sc16is75x_read_fifo(const struct device *dev, const uint8_t channel, uint8_t *buf, const size_t len)
Read data from FIFO.
Definition mfd_sc16is75x.c:131
int mfd_sc16is75x_read_register(const struct device *dev, const uint8_t channel, const uint8_t reg, uint8_t *value)
Read from an internal register.
Definition mfd_sc16is75x.c:89
int mfd_sc16is75x_write_fifo(const struct device *dev, const uint8_t channel, const uint8_t *buf, const size_t len)
Write data to FIFO.
Definition mfd_sc16is75x.c:137