xref: /freebsd/sys/dev/scc/scc_bfe_macio.c (revision fdafd315ad0d0f28a11b9fb4476a9ab059c62b92)
1ffc08b21SMarcel Moolenaar /*-
2*4d846d26SWarner Losh  * SPDX-License-Identifier: BSD-2-Clause
3718cf2ccSPedro F. Giffuni  *
4ffc08b21SMarcel Moolenaar  * Copyright (c) 2006 Marcel Moolenaar
5ffc08b21SMarcel Moolenaar  * All rights reserved.
6ffc08b21SMarcel Moolenaar  *
7ffc08b21SMarcel Moolenaar  * Redistribution and use in source and binary forms, with or without
8ffc08b21SMarcel Moolenaar  * modification, are permitted provided that the following conditions
9ffc08b21SMarcel Moolenaar  * are met:
10ffc08b21SMarcel Moolenaar  *
11ffc08b21SMarcel Moolenaar  * 1. Redistributions of source code must retain the above copyright
12ffc08b21SMarcel Moolenaar  *    notice, this list of conditions and the following disclaimer.
13ffc08b21SMarcel Moolenaar  * 2. Redistributions in binary form must reproduce the above copyright
14ffc08b21SMarcel Moolenaar  *    notice, this list of conditions and the following disclaimer in the
15ffc08b21SMarcel Moolenaar  *    documentation and/or other materials provided with the distribution.
16ffc08b21SMarcel Moolenaar  *
17ffc08b21SMarcel Moolenaar  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18ffc08b21SMarcel Moolenaar  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19ffc08b21SMarcel Moolenaar  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20ffc08b21SMarcel Moolenaar  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21ffc08b21SMarcel Moolenaar  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22ffc08b21SMarcel Moolenaar  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23ffc08b21SMarcel Moolenaar  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24ffc08b21SMarcel Moolenaar  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25ffc08b21SMarcel Moolenaar  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26ffc08b21SMarcel Moolenaar  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27ffc08b21SMarcel Moolenaar  */
28ffc08b21SMarcel Moolenaar 
29ffc08b21SMarcel Moolenaar #include <sys/param.h>
30ffc08b21SMarcel Moolenaar #include <sys/systm.h>
31ffc08b21SMarcel Moolenaar #include <sys/bus.h>
32ffc08b21SMarcel Moolenaar #include <sys/conf.h>
33ffc08b21SMarcel Moolenaar #include <sys/kernel.h>
34ffc08b21SMarcel Moolenaar #include <sys/module.h>
35ffc08b21SMarcel Moolenaar 
36ffc08b21SMarcel Moolenaar #include <dev/ofw/ofw_bus.h>
37ffc08b21SMarcel Moolenaar 
38ffc08b21SMarcel Moolenaar #include <machine/bus.h>
39ffc08b21SMarcel Moolenaar #include <sys/rman.h>
40ffc08b21SMarcel Moolenaar #include <machine/resource.h>
41ffc08b21SMarcel Moolenaar 
42ffc08b21SMarcel Moolenaar #include <dev/scc/scc_bfe.h>
43ffc08b21SMarcel Moolenaar 
44ffc08b21SMarcel Moolenaar #define	MACIO_REGSHFT	4
45ffc08b21SMarcel Moolenaar #define	MACIO_RCLK	230400
46ffc08b21SMarcel Moolenaar 
47ffc08b21SMarcel Moolenaar static int
scc_macio_probe(device_t dev)48ffc08b21SMarcel Moolenaar scc_macio_probe(device_t dev)
49ffc08b21SMarcel Moolenaar {
50ffc08b21SMarcel Moolenaar 	struct scc_softc *sc;
51ffc08b21SMarcel Moolenaar 	const char *nm;
52ffc08b21SMarcel Moolenaar 
53ffc08b21SMarcel Moolenaar 	sc = device_get_softc(dev);
54ffc08b21SMarcel Moolenaar 	nm = ofw_bus_get_name(dev);
55a4ec123cSBrandon Bergren 	/* Attach to modern escc (channel shift 4 bits) */
56ffc08b21SMarcel Moolenaar 	if (!strcmp(nm, "escc")) {
57ffc08b21SMarcel Moolenaar 		device_set_desc(dev, "Zilog Z8530 dual channel SCC");
58a4ec123cSBrandon Bergren 		sc->sc_class = &scc_z8530_escc_class;
59cad72a80SMarcel Moolenaar 		return (scc_bfe_probe(dev, MACIO_REGSHFT, MACIO_RCLK, 0));
60ffc08b21SMarcel Moolenaar 	}
61ffc08b21SMarcel Moolenaar 	return (ENXIO);
62ffc08b21SMarcel Moolenaar }
63ffc08b21SMarcel Moolenaar 
646239f9e5SMarcel Moolenaar static int
scc_macio_attach(device_t dev)656239f9e5SMarcel Moolenaar scc_macio_attach(device_t dev)
666239f9e5SMarcel Moolenaar {
676239f9e5SMarcel Moolenaar 
686239f9e5SMarcel Moolenaar 	return (scc_bfe_attach(dev, 3));
696239f9e5SMarcel Moolenaar }
706239f9e5SMarcel Moolenaar 
71ffc08b21SMarcel Moolenaar static device_method_t scc_macio_methods[] = {
72ffc08b21SMarcel Moolenaar 	/* Device interface */
73ffc08b21SMarcel Moolenaar 	DEVMETHOD(device_probe,		scc_macio_probe),
746239f9e5SMarcel Moolenaar 	DEVMETHOD(device_attach,	scc_macio_attach),
75ffc08b21SMarcel Moolenaar 	DEVMETHOD(device_detach,	scc_bfe_detach),
76ffc08b21SMarcel Moolenaar 
77ffc08b21SMarcel Moolenaar 	DEVMETHOD(bus_alloc_resource,	scc_bus_alloc_resource),
78ffc08b21SMarcel Moolenaar 	DEVMETHOD(bus_release_resource,	scc_bus_release_resource),
79ffc08b21SMarcel Moolenaar 	DEVMETHOD(bus_get_resource,	scc_bus_get_resource),
80ffc08b21SMarcel Moolenaar 	DEVMETHOD(bus_read_ivar,	scc_bus_read_ivar),
81ffc08b21SMarcel Moolenaar 	DEVMETHOD(bus_setup_intr,	scc_bus_setup_intr),
82ffc08b21SMarcel Moolenaar 	DEVMETHOD(bus_teardown_intr,	scc_bus_teardown_intr),
834b7ec270SMarius Strobl 
844b7ec270SMarius Strobl 	DEVMETHOD_END
85ffc08b21SMarcel Moolenaar };
86ffc08b21SMarcel Moolenaar 
87ffc08b21SMarcel Moolenaar static driver_t scc_macio_driver = {
88ffc08b21SMarcel Moolenaar 	scc_driver_name,
89ffc08b21SMarcel Moolenaar 	scc_macio_methods,
90ffc08b21SMarcel Moolenaar 	sizeof(struct scc_softc),
91ffc08b21SMarcel Moolenaar };
92ffc08b21SMarcel Moolenaar 
9376979b62SJohn Baldwin DRIVER_MODULE(scc, macio, scc_macio_driver, NULL, NULL);
94