sc16is7xxvar.h revision 1.1 1 /* $NetBSD: sc16is7xxvar.h,v 1.1 2025/10/24 23:16:11 brad Exp $ */
2
3 /*
4 * Copyright (c) 2025 Brad Spencer <brad (at) anduin.eldar.org>
5 *
6 * Permission to use, copy, modify, and distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
9 *
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 */
18
19 #ifndef _DEV_IC_SC16IS7XXVAR_H_
20 #define _DEV_IC_SC16IS7XXVAR_H_
21
22 #include <sys/tty.h>
23 #include <sys/bus.h>
24 #include <sys/pool.h>
25
26 #include <sys/gpio.h>
27 #include <dev/gpio/gpiovar.h>
28
29 #include <dev/ic/comreg.h>
30 #include <dev/ic/comvar.h> /* for com_regs */
31
32 #ifndef SC16IS7XX_DEFAULT_FREQUENCY
33 #define SC16IS7XX_DEFAULT_FREQUENCY 14745600
34 #endif
35
36 #ifndef SC16IS7XX_DEFAULT_POLL
37 #define SC16IS7XX_DEFAULT_POLL 50
38 #endif
39
40 #define SC16IS7XX_NPINS 8
41
42 #define SC16IS7XX_TYPE_STRINGLEN 40
43
44 struct sc16is7xx_sc;
45
46 struct sc16is7xx_accessfuncs {
47 int (*read_reg)(struct sc16is7xx_sc *, uint8_t, int, uint8_t *,
48 size_t);
49 int (*write_reg)(struct sc16is7xx_sc *, uint8_t, int, uint8_t *,
50 size_t);
51 void (*copy_handles)(struct sc16is7xx_sc *, struct com_regs *);
52 uint8_t(*com_read_1)(struct com_regs *, u_int);
53 void (*com_write_1)(struct com_regs *, u_int, uint8_t);
54 void (*com_write_multi_1)(struct com_regs *, u_int, const uint8_t *, bus_size_t);
55 };
56
57 struct sc16is7xx_sc {
58 device_t sc_dev;
59 struct sysctllog *sc_sc16is7xx_log;
60
61 int sc_num_channels;
62
63 const struct sc16is7xx_accessfuncs *sc_funcs;
64 const struct sc16is7xx_accessfuncs *sc_com_funcs;
65
66 device_t sc_ttydevchannel[2];
67 device_t sc_gpio_dev;
68 struct gpio_chipset_tag sc_gpio_gc;
69 gpio_pin_t sc_gpio_pins[SC16IS7XX_NPINS];
70
71 int sc_frequency;
72
73 bool sc_thread_run;
74 struct lwp *sc_thread;
75 int sc_poll;
76
77 int sc_phandle;
78 struct workqueue *sc_wq;
79 pool_cache_t sc_wk_pool;
80 void *sc_ih;
81 void *sc_sih;
82 };
83
84 extern const struct device_compatible_entry sc16is7xx_compat_data[];
85
86 struct sc16is7xx_tty_attach_args {
87 int aa_channel;
88 };
89
90 void sc16is7xx_attach(struct sc16is7xx_sc *);
91 int sc16is7xx_detach(struct sc16is7xx_sc *, int);
92
93 #endif
94