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