summaryrefslogtreecommitdiffstats
path: root/sys/dev/sx/sx_util.h
blob: 582e73be1bb1bb4738dab4a5aab669138e9cae00 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
/*
 * Device driver for Specialix I/O8+ multiport serial card.
 *
 * Copyright 2003 Frank Mayhar <frank@exit.com>
 *
 * Derived from the "si" driver by Peter Wemm <peter@netplex.com.au>, using
 * lots of information from the Linux "specialix" driver by Roger Wolff
 * <R.E.Wolff@BitWizard.nl> and from the Intel CD1865 "Intelligent Eight-
 * Channel Communications Controller" datasheet.  Roger was also nice
 * enough to answer numerous questions about stuff specific to the I/O8+
 * not covered by the CD1865 datasheet.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notices, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notices, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY ``AS IS'' AND ANY EXPRESS OR IMPLIED
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
 * NO EVENT SHALL THE AUTHORS BE LIABLE.
 *
 * $FreeBSD$
 */


/* Utility functions and macros for the Specialix I/O8+ driver. */

/*
 * sx_cd1865_out()
 *	Write a CD1865 register on the card.
 */
static __inline void
sx_cd1865_out(
	struct sx_softc *sc,
	unsigned int reg,
	unsigned char val)
{
	bus_space_write_1(sc->sc_st, sc->sc_sh, SX_ADDR_REG, reg);
	bus_space_write_1(sc->sc_st, sc->sc_sh, SX_DATA_REG, val);
}

/*
 * sx_cd1865_in()
 *	Read a register from the card.
 */
static __inline unsigned char
sx_cd1865_in(
	struct sx_softc *sc,
	unsigned int reg)
{
	bus_space_write_1(sc->sc_st, sc->sc_sh, SX_ADDR_REG, reg);
	return(bus_space_read_1(sc->sc_st, sc->sc_sh, SX_DATA_REG));
}

/*
 * sx_cd1865_bis()
 *	Set bits in a CD1865 register.
 */
static __inline void
sx_cd1865_bis(
	struct sx_softc *sc,
	unsigned int reg,
	unsigned char bits)
{
	register unsigned char rval;

	rval = sx_cd1865_in(sc, reg);
	rval |= bits;
	sx_cd1865_out(sc, reg, rval);
}

/*
 * sx_cd1865_bic()
 *	Clear bits in a CD1865 register.
 */
static __inline void
sx_cd1865_bic(
	struct sx_softc *sc,
	unsigned int reg,
	unsigned char bits)
{
	register unsigned char rval;

	rval = sx_cd1865_in(sc, reg);
	rval &= ~bits;
	sx_cd1865_out(sc, reg, rval);
}

/*
 * sx_cd1865_wait_CCR()
 *	Spin waiting for the board Channel Command Register to clear.
 *
 * Description:
 *	The CD1865 processor clears the Channel Command Register to
 *	indicate that it has completed the last command.  This routine
 *	waits for the CCR to become zero by watching the register,
 *	delaying ten microseconds between each check.  We time out after
 *	ten milliseconds (or SX_CCR_TIMEOUT microseconds).
 */
static __inline void
sx_cd1865_wait_CCR(
	struct sx_softc *sc,
	unsigned int ei_flag)
{
	unsigned int to = SX_CCR_TIMEOUT/10;

	while (to-- > 0) {
		if (sx_cd1865_in(sc, CD1865_CCR|ei_flag) == 0)
			return;
		DELAY(10);
	}
	printf("sx: Timeout waiting for CCR to clear.\n");
}

/*
 * sx_cd1865_etcmode()
 *	Set or clear embedded transmit command mode on a CD1865 port.
 *
 * Description:
 *	We can use commands embedded in the transmit data stream to do
 *	things like start and stop breaks or insert time delays.  We normally
 *	run with embedded commands disabled; this routine selects the channel
 *	we're dealing with and enables or disables embedded commands depending
 *	on the flag passed to it.  The caller must remember this state and
 *	escape any NULs it sends while embedded commands are enabled.
 *	Should be called at spltty().  Disables interrupts for the duration
 *	of the routine.
 */
static __inline void
sx_cd1865_etcmode(
	struct sx_softc *sc,
	unsigned int ei_flag,
	int chan,
	int mode)
{
	sx_cd1865_out(sc, CD1865_CAR|ei_flag, chan); /* Select channel.       */
	if (mode) {			/* Enable embedded commands?          */
		sx_cd1865_bis(sc, CD1865_COR2|ei_flag, CD1865_COR2_ETC);
	}
	else {
		sx_cd1865_bic(sc, CD1865_COR2|ei_flag, CD1865_COR2_ETC);
	}
	/*
	 * Wait for the CCR to clear, ding the card, let it know stuff
	 * changed, then wait for CCR to clear again.
	 */
	sx_cd1865_wait_CCR(sc, ei_flag);
	sx_cd1865_out(sc, CD1865_CCR|ei_flag, CD1865_CCR_CORCHG2);
	sx_cd1865_wait_CCR(sc, ei_flag);
}

int sx_probe_io8(device_t dev);
int sx_init_cd1865(struct sx_softc *sc, int unit);
struct sx_port *sx_int_port(struct sx_softc *sc, int unit);
OpenPOWER on IntegriCloud