xref: /freebsd/sys/dev/scc/scc_bfe_macio.c (revision 718cf2ccb9956613756ab15d7a0e28f2c8e91cab)
1ffc08b21SMarcel Moolenaar /*-
2*718cf2ccSPedro F. Giffuni  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
3*718cf2ccSPedro 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/cdefs.h>
30ffc08b21SMarcel Moolenaar __FBSDID("$FreeBSD$");
31ffc08b21SMarcel Moolenaar 
32ffc08b21SMarcel Moolenaar #include <sys/param.h>
33ffc08b21SMarcel Moolenaar #include <sys/systm.h>
34ffc08b21SMarcel Moolenaar #include <sys/bus.h>
35ffc08b21SMarcel Moolenaar #include <sys/conf.h>
36ffc08b21SMarcel Moolenaar #include <sys/kernel.h>
37ffc08b21SMarcel Moolenaar #include <sys/module.h>
38ffc08b21SMarcel Moolenaar 
39ffc08b21SMarcel Moolenaar #include <dev/ofw/ofw_bus.h>
40ffc08b21SMarcel Moolenaar 
41ffc08b21SMarcel Moolenaar #include <machine/bus.h>
42ffc08b21SMarcel Moolenaar #include <sys/rman.h>
43ffc08b21SMarcel Moolenaar #include <machine/resource.h>
44ffc08b21SMarcel Moolenaar 
45ffc08b21SMarcel Moolenaar #include <dev/scc/scc_bfe.h>
46ffc08b21SMarcel Moolenaar 
47ffc08b21SMarcel Moolenaar #define	MACIO_REGSHFT	4
48ffc08b21SMarcel Moolenaar #define	MACIO_RCLK	230400
49ffc08b21SMarcel Moolenaar 
50ffc08b21SMarcel Moolenaar static int
51ffc08b21SMarcel Moolenaar scc_macio_probe(device_t dev)
52ffc08b21SMarcel Moolenaar {
53ffc08b21SMarcel Moolenaar 	struct scc_softc *sc;
54ffc08b21SMarcel Moolenaar 	const char *nm;
55ffc08b21SMarcel Moolenaar 
56ffc08b21SMarcel Moolenaar 	sc = device_get_softc(dev);
57ffc08b21SMarcel Moolenaar 	nm = ofw_bus_get_name(dev);
58ffc08b21SMarcel Moolenaar 	if (!strcmp(nm, "escc")) {
59ffc08b21SMarcel Moolenaar 		device_set_desc(dev, "Zilog Z8530 dual channel SCC");
60ffc08b21SMarcel Moolenaar 		sc->sc_class = &scc_z8530_class;
61cad72a80SMarcel Moolenaar 		return (scc_bfe_probe(dev, MACIO_REGSHFT, MACIO_RCLK, 0));
62ffc08b21SMarcel Moolenaar 	}
63ffc08b21SMarcel Moolenaar 	return (ENXIO);
64ffc08b21SMarcel Moolenaar }
65ffc08b21SMarcel Moolenaar 
666239f9e5SMarcel Moolenaar static int
676239f9e5SMarcel Moolenaar scc_macio_attach(device_t dev)
686239f9e5SMarcel Moolenaar {
696239f9e5SMarcel Moolenaar 
706239f9e5SMarcel Moolenaar 	return (scc_bfe_attach(dev, 3));
716239f9e5SMarcel Moolenaar }
726239f9e5SMarcel Moolenaar 
73ffc08b21SMarcel Moolenaar static device_method_t scc_macio_methods[] = {
74ffc08b21SMarcel Moolenaar 	/* Device interface */
75ffc08b21SMarcel Moolenaar 	DEVMETHOD(device_probe,		scc_macio_probe),
766239f9e5SMarcel Moolenaar 	DEVMETHOD(device_attach,	scc_macio_attach),
77ffc08b21SMarcel Moolenaar 	DEVMETHOD(device_detach,	scc_bfe_detach),
78ffc08b21SMarcel Moolenaar 
79ffc08b21SMarcel Moolenaar 	DEVMETHOD(bus_alloc_resource,	scc_bus_alloc_resource),
80ffc08b21SMarcel Moolenaar 	DEVMETHOD(bus_release_resource,	scc_bus_release_resource),
81ffc08b21SMarcel Moolenaar 	DEVMETHOD(bus_get_resource,	scc_bus_get_resource),
82ffc08b21SMarcel Moolenaar 	DEVMETHOD(bus_read_ivar,	scc_bus_read_ivar),
83ffc08b21SMarcel Moolenaar 	DEVMETHOD(bus_setup_intr,	scc_bus_setup_intr),
84ffc08b21SMarcel Moolenaar 	DEVMETHOD(bus_teardown_intr,	scc_bus_teardown_intr),
854b7ec270SMarius Strobl 
864b7ec270SMarius Strobl 	DEVMETHOD_END
87ffc08b21SMarcel Moolenaar };
88ffc08b21SMarcel Moolenaar 
89ffc08b21SMarcel Moolenaar static driver_t scc_macio_driver = {
90ffc08b21SMarcel Moolenaar 	scc_driver_name,
91ffc08b21SMarcel Moolenaar 	scc_macio_methods,
92ffc08b21SMarcel Moolenaar 	sizeof(struct scc_softc),
93ffc08b21SMarcel Moolenaar };
94ffc08b21SMarcel Moolenaar 
9571bda3ebSMarius Strobl DRIVER_MODULE(scc, macio, scc_macio_driver, scc_devclass, NULL, NULL);
96