Bridle API 4.1.99
A Zephyr based application framework
Loading...
Searching...
No Matches
sc16is75x.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2024 TiaC Systems
3 * SPDX-License-Identifier: Apache-2.0
4 */
5
11#ifndef ZEPHYR_INCLUDE_DRIVERS_MFD_SC16IS75X_H_
12#define ZEPHYR_INCLUDE_DRIVERS_MFD_SC16IS75X_H_
13
14#ifdef __cplusplus
15extern "C" {
16#endif
17
18#include <stddef.h>
19#include <stdint.h>
20
21#include <zephyr/kernel.h>
22#include <zephyr/device.h>
23#include <zephyr/drivers/gpio.h>
24
25#include <zephyr/sys/util_macro.h>
26
27/*
28 * SC16IS75X register bit/field access operations
29 */
30
31#define FIELD_POS(field) field##_POS
32#define FIELD_SIZE(field) field##_SIZE
33
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))
37
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)))
43
44#define GET_FIELD_POS(field) \
45 _GET_FIELD_POS_(FIELD_POS(field))
46#define _GET_FIELD_POS_(f_ops) f_ops
47
48#define GET_FIELD_SZ(field) \
49 _GET_FIELD_SZ_(FIELD_SIZE(field))
50#define _GET_FIELD_SZ_(f_ops) f_ops
51
52/*
53 * General registers
54 */
55
56/* Receive Holding Register (RHR), read only */
57#define SC16IS75X_REG_RHR 0x00
58
59/* Transmit Holding Register (THR), write only */
60#define SC16IS75X_REG_THR 0x00
61
62/* Interrupt Enable Register (IER) */
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
72
73/* FIFO Control Register (FCR), write only */
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
78 /* reserved 3 */
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
89
90/* Interrupt Identification Register (IIR), read only */
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
106
107/* Line Control Register (LCR) */
108#define SC16IS75X_REG_LCR 0x03
109
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 /* 0xBF */
131
132/* Modem Control Register (MCR) */
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
137 /* reserved 3 */
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
142
143/* Line Status Register (LSR), read only */
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
153
154/* Modem Status Register (MSR), read only */
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
164
165/* Scratchpad Register (SPR) */
166#define SC16IS75X_REG_SPR 0x07
167
168/* Transmission Control Register (TCR) */
169#define SC16IS75X_REG_TCR 0x06
170
171/* Trigger Level Register (TLR) */
172#define SC16IS75X_REG_TLR 0x07
173
174/* Transmitter FIFO Level register (TXLVL), read only */
175#define SC16IS75X_REG_TXLVL 0x08
176#define SC16IS75X_BIT_TXLVL_SP_POS 0
177#define SC16IS75X_BIT_TXLVL_SP_SIZE 7
178
179/* Receiver FIFO Level register (RXLVL), read only */
180#define SC16IS75X_REG_RXLVL 0x09
181#define SC16IS75X_BIT_RXLVL_CH_POS 0
182#define SC16IS75X_BIT_RXLVL_CH_SIZE 7
183
184/* Programmable I/O pins Direction register (IODir), all channels */
185#define SC16IS75X_REG_IODIR 0x0A
186
187/* Programmable I/O pins State register (IOState), all channels */
188#define SC16IS75X_REG_IOSTATE 0x0B
189
190/* Programmable I/O Interrupt Enable register (IOIntEna), all channels */
191#define SC16IS75X_REG_IOINTENA 0x0C
192
193/* Programmable I/O Control register (IOControl), all channels */
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
199 /* reserved 4:7 */
200
201/* Extra Features Control Register (EFCR) */
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
206 /* reserved 3 */
207#define SC16IS75X_BIT_EFCR_RTSCON 4
208#define SC16IS75X_BIT_EFCR_RTSINVER 5
209 /* reserved 6 */
210#define SC16IS75X_BIT_EFCR_IRDA 7
211
212/*
213 * Special registers
214 */
215
216/* Division registers (DLL, DLH) */
217#define SC16IS75X_REG_DLL 0x00
218#define SC16IS75X_REG_DLH 0x01
219
220/*
221 * Enhanced registers
222 */
223
224/* Enhanced Features Register (EFR) */
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
238
239/* Xon1 Special Character Register (XON1) */
240#define SC16IS75X_REG_XON1 0x04
241
242/* Xoff2 Special Character Register (XOFF2) */
243#define SC16IS75X_REG_XON2 0x05
244
245/* Xon1 Special Character Register (XON1) */
246#define SC16IS75X_REG_XOFF1 0x06
247
248/* Xoff2 Special Character Register (XOFF2) */
249#define SC16IS75X_REG_XOFF2 0x07
250
265#define SC16IS75X_FIFO_CAPACITY 64
266
268#define SC16IS75X_IO_NUM_PINS_MAX 8
269
271#define SC16IS75X_UART_CHANNELS_MAX 2
272
283int mfd_sc16is75x_read_register(const struct device *dev,
284 const uint8_t channel,
285 const uint8_t reg, uint8_t *value);
286
287#define READ_SC16IS75X_REG(dev, reg, val) \
288 mfd_sc16is75x_read_register((dev), 0, SC16IS75X_REG_##reg, (val));
289
290#define READ_SC16IS75X_CHREG(dev, ch, reg, val) \
291 mfd_sc16is75x_read_register((dev), (ch), SC16IS75X_REG_##reg, (val));
292
303int mfd_sc16is75x_write_register(const struct device *dev,
304 const uint8_t channel,
305 const uint8_t reg, const uint8_t value);
306
307#define WRITE_SC16IS75X_REG(dev, reg, val) \
308 mfd_sc16is75x_write_register((dev), 0, SC16IS75X_REG_##reg, (val));
309
310#define WRITE_SC16IS75X_CHREG(dev, ch, reg, val) \
311 mfd_sc16is75x_write_register((dev), (ch), SC16IS75X_REG_##reg, (val));
312
324int mfd_sc16is75x_set_register_bit(const struct device *dev,
325 const uint8_t channel, const uint8_t reg,
326 const uint8_t bit, const bool value);
327
328#define SETBIT_SC16IS75X_REG(dev, reg, bit, val) \
329 mfd_sc16is75x_set_register_bit((dev), 0, SC16IS75X_REG_##reg, \
330 (bit), (val));
331
332#define SETBIT_SC16IS75X_CHREG(dev, ch, reg, bit, val) \
333 mfd_sc16is75x_set_register_bit((dev), (ch), SC16IS75X_REG_##reg, \
334 (bit), (val));
335
346int mfd_sc16is75x_read_fifo(const struct device *dev, const uint8_t channel,
347 uint8_t *buf, const size_t len);
348
359int mfd_sc16is75x_write_fifo(const struct device *dev, const uint8_t channel,
360 const uint8_t *buf, const size_t len);
361
362#ifdef CONFIG_MFD_SC16IS75X_ASYNC
363
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);
378
379#define READ_SC16IS75X_CHREG_SIGNAL(dev, ch, reg, val, signal) \
380 mfd_sc16is75x_read_register_signal((dev), (ch), SC16IS75X_REG_##reg, \
381 (val), (signal));
382
383#endif /* CONFIG_MFD_SC16IS75X_ASYNC */
384
385#ifdef CONFIG_MFD_SC16IS75X_INTERRUPTS
386
396enum mfd_sc16is75x_event {
397 /* channel 0 (A) */
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,
406 /* channel 1 (B) */
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,
415 /* must be last entry */
416 SC16IS75X_EVENT_MAX
417};
418
427int mfd_sc16is75x_add_callback(const struct device *dev,
428 struct gpio_callback *callback);
429
438int mfd_sc16is75x_remove_callback(const struct device *dev,
439 struct gpio_callback *callback);
440
441
442#endif /* CONFIG_MFD_SC16IS75X_INTERRUPTS */
443
446#ifdef __cplusplus
447}
448#endif
449
450#endif /* ZEPHYR_INCLUDE_DRIVERS_MFD_SC16IS75X_H_ */
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