1157299Smarcel/*-
2157299Smarcel * Copyright (c) 2004-2006 Marcel Moolenaar
3157299Smarcel * All rights reserved.
4157299Smarcel *
5157299Smarcel * Redistribution and use in source and binary forms, with or without
6157299Smarcel * modification, are permitted provided that the following conditions
7157299Smarcel * are met:
8157299Smarcel *
9157299Smarcel * 1. Redistributions of source code must retain the above copyright
10157299Smarcel *    notice, this list of conditions and the following disclaimer.
11157299Smarcel * 2. Redistributions in binary form must reproduce the above copyright
12157299Smarcel *    notice, this list of conditions and the following disclaimer in the
13157299Smarcel *    documentation and/or other materials provided with the distribution.
14157299Smarcel *
15157299Smarcel * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16157299Smarcel * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17157299Smarcel * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18157299Smarcel * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19157299Smarcel * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20157299Smarcel * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21157299Smarcel * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22157299Smarcel * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23157299Smarcel * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24157299Smarcel * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25157299Smarcel *
26157299Smarcel * $FreeBSD$
27157299Smarcel */
28157299Smarcel
29157299Smarcel#ifndef _DEV_SCC_BFE_H_
30157299Smarcel#define _DEV_SCC_BFE_H_
31157299Smarcel
32157299Smarcel#include <sys/serial.h>
33157299Smarcel
34157299Smarcel/*
35157299Smarcel * Bus access structure. This structure holds the minimum information needed
36157299Smarcel * to access the SCC. The rclk field, although not important to actually
37157299Smarcel * access the SCC, is important for baudrate programming, delay loops and
38157299Smarcel * other timing related computations.
39157299Smarcel */
40157299Smarcelstruct scc_bas {
41157299Smarcel	bus_space_tag_t	bst;
42157299Smarcel	bus_space_handle_t bsh;
43157299Smarcel	u_int		range;
44157299Smarcel	u_int		rclk;
45157299Smarcel	u_int		regshft;
46157299Smarcel};
47157299Smarcel
48157299Smarcel#define	scc_regofs(bas, reg)		((reg) << (bas)->regshft)
49157299Smarcel
50157299Smarcel#define	scc_getreg(bas, reg)		\
51157299Smarcel	bus_space_read_1((bas)->bst, (bas)->bsh, scc_regofs(bas, reg))
52157299Smarcel#define	scc_setreg(bas, reg, value)	\
53157299Smarcel	bus_space_write_1((bas)->bst, (bas)->bsh, scc_regofs(bas, reg), value)
54157299Smarcel
55157299Smarcel#define	scc_barrier(bas)		\
56157299Smarcel	bus_space_barrier((bas)->bst, (bas)->bsh, 0, (bas)->range,	\
57157299Smarcel	    BUS_SPACE_BARRIER_READ|BUS_SPACE_BARRIER_WRITE)
58157299Smarcel
59157299Smarcel/*
60157299Smarcel * SCC mode (child) and channel control structures.
61157299Smarcel */
62157299Smarcel
63157299Smarcel#define	SCC_NMODES	3
64157299Smarcel#define	SCC_ISRCCNT	5
65157299Smarcel
66157299Smarcelstruct scc_chan;
67157299Smarcel
68157299Smarcelstruct scc_mode {
69157299Smarcel	struct scc_chan	*m_chan;
70157299Smarcel	device_t	m_dev;
71157299Smarcel
72157299Smarcel	u_int		m_mode;
73157299Smarcel	int		m_attached:1;
74157299Smarcel	int		m_fastintr:1;
75157299Smarcel	int		m_hasintr:1;
76157299Smarcel	int		m_probed:1;
77157299Smarcel	int		m_sysdev:1;
78157299Smarcel
79166901Spiso	driver_filter_t	*ih;
80157299Smarcel	serdev_intr_t	*ih_src[SCC_ISRCCNT];
81157299Smarcel	void		*ih_arg;
82157299Smarcel};
83157299Smarcel
84157299Smarcelstruct scc_chan {
85157299Smarcel	struct resource ch_rres;
86157299Smarcel	struct resource_list ch_rlist;
87157299Smarcel
88157492Smarcel	struct resource *ch_ires;	/* Interrupt resource. */
89157492Smarcel	void		*ch_icookie;
90157492Smarcel	int		ch_irid;
91157492Smarcel
92157299Smarcel	struct scc_mode	ch_mode[SCC_NMODES];
93157299Smarcel
94157299Smarcel	u_int		ch_nr;
95167996Smarcel	int		ch_enabled:1;
96157299Smarcel	int		ch_sysdev:1;
97157299Smarcel
98157299Smarcel	uint32_t	ch_ipend;
99157299Smarcel	uint32_t	ch_hwsig;
100157299Smarcel};
101157299Smarcel
102157299Smarcel/*
103157299Smarcel * SCC class & instance (=softc)
104157299Smarcel */
105157299Smarcelstruct scc_class {
106157299Smarcel	KOBJ_CLASS_FIELDS;
107157299Smarcel	u_int		cl_channels;	/* Number of independent channels. */
108157299Smarcel	u_int		cl_class;	/* SCC bus class ID. */
109157299Smarcel	u_int		cl_modes;	/* Supported modes (bitset). */
110157299Smarcel	int		cl_range;
111157299Smarcel};
112157299Smarcel
113176772Srajextern struct scc_class scc_quicc_class;
114157299Smarcelextern struct scc_class scc_sab82532_class;
115157299Smarcelextern struct scc_class scc_z8530_class;
116157299Smarcel
117157299Smarcelstruct scc_softc {
118157299Smarcel	KOBJ_FIELDS;
119157299Smarcel	struct scc_class *sc_class;
120157299Smarcel	struct scc_bas	sc_bas;
121157299Smarcel	device_t	sc_dev;
122157299Smarcel
123157299Smarcel	struct mtx	sc_hwmtx;	/* Spinlock protecting hardware. */
124157299Smarcel
125157299Smarcel	struct resource	*sc_rres;	/* Register resource. */
126157299Smarcel	int		sc_rrid;
127157299Smarcel	int		sc_rtype;	/* SYS_RES_{IOPORT|MEMORY}. */
128157299Smarcel
129157299Smarcel	struct scc_chan	*sc_chan;
130157299Smarcel
131157299Smarcel	int		sc_fastintr:1;
132157299Smarcel	int		sc_leaving:1;
133157299Smarcel	int		sc_polled:1;
134157299Smarcel
135157299Smarcel	uint32_t        sc_hwsig;       /* Signal state. Used by HW driver. */
136157299Smarcel};
137157299Smarcel
138157299Smarcelextern devclass_t scc_devclass;
139253902Smariusextern const char scc_driver_name[];
140157299Smarcel
141178600Smarcelint scc_bfe_attach(device_t dev, u_int ipc);
142157299Smarcelint scc_bfe_detach(device_t dev);
143167822Smarcelint scc_bfe_probe(device_t dev, u_int regshft, u_int rclk, u_int rid);
144157299Smarcel
145157299Smarcelstruct resource *scc_bus_alloc_resource(device_t, device_t, int, int *,
146157299Smarcel    u_long, u_long, u_long, u_int);
147157299Smarcelint scc_bus_get_resource(device_t, device_t, int, int, u_long *, u_long *);
148157299Smarcelint scc_bus_read_ivar(device_t, device_t, int, uintptr_t *);
149157299Smarcelint scc_bus_release_resource(device_t, device_t, int, int, struct resource *);
150157299Smarcelint scc_bus_setup_intr(device_t, device_t, struct resource *, int,
151166901Spiso    driver_filter_t *, void (*)(void *), void *, void **);
152157299Smarcelint scc_bus_teardown_intr(device_t, device_t, struct resource *, void *);
153157299Smarcel
154157299Smarcel#endif /* _DEV_SCC_BFE_H_ */
155