wsbellmux.c revision 1.1.6.2 1 1.1.6.2 jdolecek /* $NetBSD: wsbellmux.c,v 1.1.6.2 2017/12/03 11:37:37 jdolecek Exp $ */
2 1.1.6.2 jdolecek /*-
3 1.1.6.2 jdolecek * Copyright (c) 2017 Nathanial Sloss <nathanialsloss (at) yahoo.com.au>
4 1.1.6.2 jdolecek * All rights reserved.
5 1.1.6.2 jdolecek *
6 1.1.6.2 jdolecek * Redistribution and use in source and binary forms, with or without
7 1.1.6.2 jdolecek * modification, are permitted provided that the following conditions
8 1.1.6.2 jdolecek * are met:
9 1.1.6.2 jdolecek * 1. Redistributions of source code must retain the above copyright
10 1.1.6.2 jdolecek * notice, this list of conditions and the following disclaimer.
11 1.1.6.2 jdolecek * 2. Redistributions in binary form must reproduce the above copyright
12 1.1.6.2 jdolecek * notice, this list of conditions and the following disclaimer in the
13 1.1.6.2 jdolecek * documentation and/or other materials provided with the distribution.
14 1.1.6.2 jdolecek *
15 1.1.6.2 jdolecek * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
16 1.1.6.2 jdolecek * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
17 1.1.6.2 jdolecek * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18 1.1.6.2 jdolecek * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
19 1.1.6.2 jdolecek * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20 1.1.6.2 jdolecek * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21 1.1.6.2 jdolecek * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22 1.1.6.2 jdolecek * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23 1.1.6.2 jdolecek * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24 1.1.6.2 jdolecek * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25 1.1.6.2 jdolecek * POSSIBILITY OF SUCH DAMAGE.
26 1.1.6.2 jdolecek */
27 1.1.6.2 jdolecek
28 1.1.6.2 jdolecek #include <sys/cdefs.h>
29 1.1.6.2 jdolecek __KERNEL_RCSID(0, "$NetBSD: wsbellmux.c,v 1.1.6.2 2017/12/03 11:37:37 jdolecek Exp $");
30 1.1.6.2 jdolecek
31 1.1.6.2 jdolecek #include <sys/param.h>
32 1.1.6.2 jdolecek #include <sys/conf.h>
33 1.1.6.2 jdolecek #include <sys/types.h>
34 1.1.6.2 jdolecek #include <sys/device.h>
35 1.1.6.2 jdolecek #include <sys/errno.h>
36 1.1.6.2 jdolecek #include <sys/selinfo.h>
37 1.1.6.2 jdolecek
38 1.1.6.2 jdolecek #include "wsmux.h"
39 1.1.6.2 jdolecek
40 1.1.6.2 jdolecek #include <dev/wscons/wsconsio.h>
41 1.1.6.2 jdolecek #include <dev/wscons/wsbellvar.h>
42 1.1.6.2 jdolecek
43 1.1.6.2 jdolecek /*
44 1.1.6.2 jdolecek * Print function (for parent devices).
45 1.1.6.2 jdolecek */
46 1.1.6.2 jdolecek int
47 1.1.6.2 jdolecek wsbelldevprint(void *aux, const char *pnp)
48 1.1.6.2 jdolecek {
49 1.1.6.2 jdolecek
50 1.1.6.2 jdolecek if (pnp)
51 1.1.6.2 jdolecek aprint_normal("wsbell at %s", pnp);
52 1.1.6.2 jdolecek return (UNCONF);
53 1.1.6.2 jdolecek }
54 1.1.6.2 jdolecek
55 1.1.6.2 jdolecek #if NWSMUX > 0
56 1.1.6.2 jdolecek int
57 1.1.6.2 jdolecek wsbell_add_mux(int unit, struct wsmux_softc *muxsc)
58 1.1.6.2 jdolecek {
59 1.1.6.2 jdolecek struct wsbell_softc *sc;
60 1.1.6.2 jdolecek device_t wsbelldev;
61 1.1.6.2 jdolecek cfdriver_t wsbellcd;
62 1.1.6.2 jdolecek
63 1.1.6.2 jdolecek wsbelldev = device_find_by_driver_unit("wsbell", unit);
64 1.1.6.2 jdolecek if (wsbelldev == NULL)
65 1.1.6.2 jdolecek return ENXIO;
66 1.1.6.2 jdolecek wsbellcd = device_cfdriver(wsbelldev);
67 1.1.6.2 jdolecek if (wsbellcd == NULL)
68 1.1.6.2 jdolecek return ENXIO;
69 1.1.6.2 jdolecek
70 1.1.6.2 jdolecek sc = device_lookup_private(wsbellcd, unit);
71 1.1.6.2 jdolecek if (sc == NULL)
72 1.1.6.2 jdolecek return ENXIO;
73 1.1.6.2 jdolecek
74 1.1.6.2 jdolecek if (sc->sc_base.me_parent != NULL || sc->sc_base.me_evp != NULL)
75 1.1.6.2 jdolecek return (EBUSY);
76 1.1.6.2 jdolecek
77 1.1.6.2 jdolecek return (wsmux_attach_sc(muxsc, &sc->sc_base));
78 1.1.6.2 jdolecek }
79 1.1.6.2 jdolecek #endif
80